/* 共用元件樣式。色彩／字級／間距一律吃 shared/tokens.css 的變數，不在這裡另外定義 token。
   Phase 3（改版）：按鈕從藥丸形改一般圓角矩形，其餘結構沿用舊版、只換色票與形狀。 */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.5;
}

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

header.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 20px;
  row-gap: 10px;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

header.app-header h1 {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0;
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-logo {
  height: 30px;
  width: auto;
  display: block;
}

@media (prefers-color-scheme: dark) {
  .brand-logo {
    filter: invert(1) brightness(1.1);
  }
}
:root[data-theme="dark"] .brand-logo {
  filter: invert(1) brightness(1.1);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-sub {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.pill {
  font-size: 12px;
  color: var(--ink-soft);
}

/* ---- 跨頁導覽（見 shared/nav.js）：header 裡顯示這個帳號能去的其他頁面 + 登出 ---- */
.app-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.nav-link {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  color: var(--ink-soft);
  text-decoration: none;
  border: 1px solid transparent;
  white-space: nowrap;
}
.nav-link:hover { background: var(--accent-tint); color: var(--accent-strong); }
.nav-link.active { background: var(--active-fill); color: var(--active-ink); font-weight: 600; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (max-width: 720px) {
  header.app-header { flex-wrap: wrap; row-gap: 10px; }
  .app-nav { order: 3; width: 100%; }
}

/* ---- 密碼欄位：預設遮蔽，按「顯示」才亮出來，見 shared/aftersales-ui.js ---- */
.pw-wrap { display: inline-flex; align-items: center; gap: 6px; }
.pw-text { font-family: ui-monospace, monospace; letter-spacing: 0.05em; }

/* ---- 按鈕：一般圓角矩形，不用藥丸形——清晰乾淨優先，跟徽章/狀態標籤（膠囊）區分開來 ---- */
button {
  position: relative;
  overflow: hidden;
  font: inherit;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--ink);
  padding: 10px 18px;
  transition: box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}

button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 0.15s var(--ease);
  pointer-events: none;
}

button:hover:not(:disabled)::after { opacity: 0.06; }
button:active:not(:disabled)::after { opacity: 0.1; }

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus);
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}

button.primary:hover:not(:disabled) {
  box-shadow: var(--shadow-md);
}

/* tonal：次要 CTA，淺色填底，不用外框搶焦點 */
button.tonal {
  background: var(--accent-tint);
  color: var(--accent-strong);
  border-color: transparent;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  margin: 14px 0 5px;
}

input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 11px 13px;
  border-radius: var(--radius-field);
  border: 1px solid var(--border);
  background: var(--surface-card-2);
  color: var(--ink);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: inset 0 0 0 1px var(--focus);
}

.row {
  display: flex;
  gap: 12px;
}
.row > * { flex: 1; }

.gate {
  text-align: center;
  padding: 80px 16px;
}

.page-loading {
  text-align: center;
  padding: 80px 16px;
  color: var(--ink-soft);
  font-size: 14px;
}

/* chip：膠囊形標籤，跟一般按鈕（圓角矩形）刻意做形狀區分——這是狀態/分類，不是可點動作 */
.status-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-card-2);
  color: var(--accent-strong);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--surface-card-2);
}
/* 表格標題列滾動時固定在頂端，長列表也不用一直往上找欄位對照 */
.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 3;
}
tbody tr {
  transition: background 0.15s var(--ease);
}
tbody tr:hover {
  background: var(--accent-tint);
}
/* 即時訂閱期間新進來的訂單：柔和高亮＋「新」角標，處理後消失（不沿用舊版綠色，改用 accent 系） */
tr.is-new, .card.is-new {
  background: var(--accent-tint);
}
.new-badge {
  display: inline-block;
  background: var(--accent-strong);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
}

.kanban {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.kanban .col h3 { font-size: 13px; color: var(--ink-soft); margin: 0 0 8px; }
.kanban .order-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}

.hint {
  font-size: 12px;
  color: var(--ink-faint);
  margin-top: 4px;
}

.error { color: var(--danger); font-size: 13px; }
.save-status.error { color: var(--danger); }

.req { color: var(--danger); margin-left: 2px; }
.field-error { color: var(--danger); font-size: 12px; margin: 4px 0 0; min-height: 0; }
.field-error:empty { display: none; }
input.invalid, select.invalid { border-color: var(--danger); }

a { color: var(--link); }
a.mailto-btn {
  display: inline-block;
  margin-top: 8px;
  text-decoration: none;
}

/* ---- 表格 / 看板 / 分頁補充 ---- */
.table-scroll {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 190px);
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(255, 255, 255, 0)),
    linear-gradient(to left, var(--surface) 30%, rgba(255, 255, 255, 0)) 100% 0,
    linear-gradient(to right, rgba(11, 37, 69, 0.12), rgba(255, 255, 255, 0)),
    linear-gradient(to left, rgba(11, 37, 69, 0.12), rgba(255, 255, 255, 0)) 100% 0;
  background-repeat: no-repeat;
  background-color: var(--surface);
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}
th.nowrap, td.nowrap { white-space: nowrap; }

a.link-cell {
  display: inline-block;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  color: var(--link);
}

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { max-width: 340px; flex: 1 1 200px; }
.toolbar select { max-width: 180px; width: auto; flex: 0 0 auto; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

button.small { font-size: 12px; padding: 5px 12px; }
.kanban .more-btn { width: 100%; font-size: 12px; padding: 6px; margin-top: 2px; }
.muted { color: var(--ink-faint); }

/* ---- 手機 RWD：窄螢幕時多欄輸入列疊成一欄，才不會擠成一團 ---- */
@media (max-width: 560px) {
  .row { flex-direction: column; gap: 0; }
  .wrap { padding: 16px 12px 48px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input { max-width: 100%; }
  .toolbar select { max-width: 100%; flex: 1 1 100%; }
  .tabs { flex-wrap: wrap; }
}

/* ---- Toast 通知（取代 alert()）---- */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: var(--surface);
  padding: 10px 18px;
  border-radius: var(--radius-btn);
  font-size: 13px;
  max-width: 90vw;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
}
.app-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.app-toast-error { background: var(--danger); color: #fff; }

/* ---- 確認對話框（取代 confirm()）---- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 37, 69, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  padding: 16px;
}
.confirm-box {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.confirm-box p { margin: 0 0 16px; font-size: 14px; white-space: pre-line; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Sidebar Shell（E 後台／採購後台用，見 shared/nav.js 的 mountSidebar）---- */
.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}
.app-sidebar {
  background: var(--surface-sidebar);
  color: var(--surface-sidebar-ink-soft);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}
.app-sidebar .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; padding: 0 2px; }
.app-sidebar .brand-logo { height: 24px; width: auto; display: block; filter: invert(1) brightness(1.3); }
.app-sidebar .brand-text h1 { font-size: 14px; margin: 0; color: var(--surface-sidebar-ink); font-weight: 700; letter-spacing: -0.01em; }
.app-sidebar .brand-text p { font-size: 10.5px; margin: 2px 0 0; color: var(--surface-sidebar-ink-soft); letter-spacing: 0.03em; }
.sidebar-sections { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-btn);
  border: none;
  background: transparent;
  color: var(--surface-sidebar-ink-soft);
  text-decoration: none;
  font-size: 13px;
  font: inherit;
  cursor: pointer;
}
.sidebar-link svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; }
.sidebar-link:hover { background: var(--hover-tint); color: var(--surface-sidebar-ink); }
.sidebar-link.active { background: var(--active-fill); color: var(--active-ink); font-weight: 600; }
.sidebar-link.active:hover { background: var(--active-fill); }
.sidebar-section-label { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--surface-sidebar-ink-soft); opacity: 0.7; margin: 18px 0 6px 10px; }
.sidebar-cross-links { margin-top: 4px; }
/* 角色色：訂單後台管理＝藍灰、採購後台＝琥珀、售後服務版＝鼠尾草綠。icon 上色＋淡底，hover 帶出同色 */
.sidebar-link[data-tone] { --tone: #5E503F; --tone-bg: rgba(94, 80, 63, 0.12); }
.sidebar-link[data-tone="admin"] { --tone: #3E6A8A; --tone-bg: rgba(62, 106, 138, 0.14); }
.sidebar-link[data-tone="procurement"] { --tone: #A8741A; --tone-bg: rgba(168, 116, 26, 0.15); }
.sidebar-link[data-tone="aftersales"] { --tone: #4F7F67; --tone-bg: rgba(79, 127, 103, 0.15); }
.sidebar-link[data-tone] svg { box-sizing: content-box; padding: 5px; width: 16px; height: 16px; border-radius: 8px; color: var(--tone); background: var(--tone-bg); margin: -5px 0; }
/* 外部內部工具（另開分頁）：右側一個小箭頭，跟站內連結區分開 */
.sidebar-link.is-external .ext-mark { width: 12px; height: 12px; margin-left: auto; opacity: .5; }
.sidebar-link.is-external:hover .ext-mark { opacity: .9; }
.sidebar-link[data-tone]:hover { background: var(--tone-bg); color: var(--surface-sidebar-ink); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sidebar-link[data-tone="admin"] { --tone: #8FB8D6; }
  :root:not([data-theme="light"]) .sidebar-link[data-tone="procurement"] { --tone: #E0B060; }
  :root:not([data-theme="light"]) .sidebar-link[data-tone="aftersales"] { --tone: #8FC4A8; }
}
.app-main { padding: 28px 32px 80px; }
.section-panel { display: none; }
.section-panel.active { display: block; }

/* ---- Sidebar 底部 Account menu：姓名／角色一行 + 展開才看得到登出，不佔版面 ---- */
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); position: relative; }
.account-trigger {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 8px; border-radius: var(--radius-btn); border: none; background: transparent;
  color: var(--surface-sidebar-ink); font: inherit; cursor: pointer; text-align: left;
}
.account-row { display: flex; align-items: center; gap: 4px; }
.guide-link { flex-shrink: 0; width: 34px; height: 34px; border-radius: var(--radius-btn); display: flex; align-items: center; justify-content: center; color: var(--surface-sidebar-ink-soft); }
.guide-link svg { width: 18px; height: 18px; stroke: currentColor; }
.guide-link:hover { background: var(--hover-tint); color: var(--surface-sidebar-ink); }
.account-trigger:hover { background: var(--hover-tint); }
.account-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--active-fill); color: var(--active-ink);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.account-trigger .who { min-width: 0; flex: 1; }
.account-trigger .name { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-trigger .role { font-size: 10.5px; color: var(--surface-sidebar-ink-soft); }
.account-trigger .chev { color: var(--surface-sidebar-ink-soft); flex-shrink: 0; width: 14px; height: 14px; transition: transform 0.15s var(--ease); }
.account-menu.open .account-trigger .chev { transform: rotate(180deg); }
.account-panel {
  display: none;
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px);
  background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-md); padding: 8px; z-index: 20;
}
.account-menu.open .account-panel { display: block; }
.account-panel .email { font-size: 11px; color: var(--ink-faint); padding: 6px 8px 8px; word-break: break-all; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.account-panel button { width: 100%; text-align: left; }

/* ---- 簡單的 Page Header（取代大型深色 Banner），見業務前台 Dashboard ---- */
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-header h2 { font-size: 21px; font-weight: 800; color: var(--ink); margin: 0; }
.page-header p { font-size: 13px; color: var(--ink-soft); margin: 4px 0 0; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { position: static; height: auto; }
  .app-main { padding: 20px 16px 60px; }
}

/* ---- Overview 統計 tile（E 後台跨角色總覽）---- */
.overview-groups { display: flex; flex-direction: column; gap: 18px; }
.overview-group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-faint); margin-bottom: 8px; }
.overview-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.overview-tile { background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.overview-tile .n { font-family: var(--font-mono, monospace); font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.overview-tile .l { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.overview-tile.flag { border-color: var(--warning); }
.overview-tile.flag .n { color: var(--warning); }
/* 連去別的內部工具的 tile（例：會員經營→續約追蹤）：沒有數字，只當入口 */
a.overview-tile { display: block; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
a.overview-tile:hover { border-color: var(--active-ink, var(--border)); box-shadow: var(--shadow-md, var(--shadow-sm)); }
a.overview-tile .n { font-size: 20px; }

/* ---- Order Detail Drawer（E 後台／採購後台）---- */
.drawer {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  background: var(--surface-card);
  padding: 20px 22px;
  margin-top: 14px;
  box-shadow: var(--shadow-md);
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.drawer h4 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent-strong); margin: 18px 0 8px; }
.drawer h4:first-of-type { margin-top: 4px; }
.drawer-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-size: 13px; }
.drawer-kv .k { color: var(--ink-faint); }
.field-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-soft); cursor: pointer; user-select: none; }

/* ---- 會員經營｜關懷進度三步驟（見 shared/member-care-ui.js）：
   灰＝未到期、黃＝該發還沒發（可點標記）、綠＝已發送（可點復原）、虛線＝缺開通日/到期日算不出來 ---- */
.care-steps { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.care-step {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-card-2);
  color: var(--ink-soft);
  white-space: nowrap;
}
button.care-step { cursor: pointer; }
.care-step--upcoming { opacity: 0.7; }
.care-step--due { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.care-step--sent { background: var(--success-bg); color: var(--success); border-color: transparent; }
.care-step--unknown { border-style: dashed; color: var(--ink-faint); }
.care-send-picker { display: inline-flex; gap: 6px; align-items: center; }
.care-send-picker select { width: auto; padding: 5px 8px; }

/* ---- 錯落淡入（reveal）：進入畫面時依 --i 順序 fade + 上移，見 shared/motion.js ---- */
.reveal {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.5s var(--ease) calc(var(--i, 0) * 60ms),
              transform 0.5s var(--ease) calc(var(--i, 0) * 60ms);
}
.js-on .reveal:not(.in) {
  opacity: 0;
  transform: translateY(16px);
}
@media (prefers-reduced-motion: reduce) {
  .reveal, .js-on .reveal:not(.in) {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}
