/* 顧店管理台 V-02：設計 token 對齊 Mac 版 GDTokens.swift（淺深皆抽樣自 0.9.1/0.9.2 截圖）。
   圖示用 Lucide（app/static/icons.svg）。
   顏色一律走 CSS 變數；模板不寫死 hex。 */
:root {
  /* 品牌（Mac 主色＝藍 gdAccent；綠 gdGreen 只給 logo／成功語意） */
  --brand: #326AD3;
  --link: #285FC4;
  --brand-hover: #2F63C9;
  --brand-soft: #E7EEF8;   /* gdInfoBg */
  --brand-accent: #5AC463; /* gdGreen：logo 小面積 */
  --selected: #EAF1FD;     /* gdSelectedBlueBg：列表選中 */
  /* 中性（Mac 動態色淺色值） */
  --bg: #F7F7F7;        /* gdBgWindow */
  --surface: #FFFFFF;   /* gdSurface */
  --sidebar: #F0EFEE;   /* gdBgSidebar */
  --sidebar-hover: #E9E8E6;
  --sidebar-selected: #DEDDDC; /* gdSidebarSelected */
  --line: #E9E9E9;      /* gdBorder */
  --line-soft: #DEDEDE; /* gdToolbarLine */
  --field-bg: #F6F6F6;  /* gdFieldBg */
  --control: #EBEBEB;   /* gdControlGrey */
  --ink: #1D1D1F;       /* gdPrimary */
  --muted: #6B6B6B;     /* gdSecondary */
  --subtle: #9A9A9A;    /* gdTertiary */
  /* 狀態（Mac 語意色） */
  --success: #3E9B51; --success-soft: #E3EFE3; /* gdGreenSoftBg；文字壓深確保對比 */
  --warning: #C9712E; --warning-soft: #F6EDE4; /* gdWarnBg */
  --danger: #E84B46;  --danger-soft: #F5EBEC;  /* gdRed/gdRedSoftBg */
  --info: #3775E6;    --info-soft: #E7EEF8;
  --purple: #8B5CF6;  --purple-soft: #ECEAF7;  /* gdPurpleSoftBg */
  /* 形狀（GDRadius：control 6、card 14） */
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --shadow: 0 4px 12px rgba(16,24,40,.08);
  --font: -apple-system, "SF Pro TC", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Mac 深色值（gdDyn dark 參數） */
    --bg: #242424; --surface: #383838; --sidebar: #292827;
    --sidebar-hover: #32312F; --sidebar-selected: #3A3937;
    --line: #454545; --line-soft: #3A3A39;
    --field-bg: #2F2F2F; --control: #3A3A3A;
    --ink: #FFFFFF; --muted: #B4B4B4; --subtle: #AEAEAE;
    --link: #94BAFF;
    --brand-soft: #2A3542; --selected: #26313F;
    --success: #7CD98A; --success-soft: #26382A;
    --warning: #F5A868; --warning-soft: #3A332C;
    --danger: #F07A76;  --danger-soft: #3A2C2D;
    --info: #7EA4EC;    --info-soft: #2A3542;
    --purple: #B794F6;  --purple-soft: #2F2D3C;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 4px 12px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #242424; --surface: #383838; --sidebar: #292827;
  --sidebar-hover: #32312F; --sidebar-selected: #3A3937;
  --line: #454545; --line-soft: #3A3A39;
  --field-bg: #2F2F2F; --control: #3A3A3A;
  --ink: #FFFFFF; --muted: #B4B4B4; --subtle: #AEAEAE;
  --link: #94BAFF;
  --brand-soft: #2A3542; --selected: #26313F;
  --success: #7CD98A; --success-soft: #26382A;
  --warning: #F5A868; --warning-soft: #3A332C;
  --danger: #F07A76;  --danger-soft: #3A2C2D;
  --info: #7EA4EC;    --info-soft: #2A3542;
  --purple: #B794F6;  --purple-soft: #2F2D3C;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 4px 12px rgba(0,0,0,.5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 14px; line-height: 1.5; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); }
a { color: var(--link); }
h2 { font-size: 22px; font-weight: 700; margin: 0 0 8px; letter-spacing: -.2px; }
h3 { font-size: 14px; font-weight: 600; margin: 20px 0 8px; }
h4 { font-size: 13px; font-weight: 600; margin: 16px 0 6px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.subtle { color: var(--subtle); font-size: 11px; }
.mt16 { margin-top: 16px; }
/* 圖示 */
.icon { width: 16px; height: 16px; flex-shrink: 0; vertical-align: -3px; }
.icon-sm { width: 14px; height: 14px; }
/* ===== 骨架（Mac：側欄 224pt） ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; background: var(--sidebar); border-right: 1px solid var(--line);
  padding: 14px 10px; flex-shrink: 0; display: flex; flex-direction: column;
}
.logo { display: flex; align-items: center; gap: 10px; margin: 2px 4px 14px; font-size: 17px; font-weight: 700; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand-accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; flex-shrink: 0;
}
.sidebar select {
  width: 100%; padding: 7px 10px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); font: inherit; font-size: 12px; color: var(--ink); cursor: pointer;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 8px; border-radius: var(--r-sm);
  text-decoration: none; color: var(--ink); font-weight: 500; font-size: 13px;
}
.sidebar nav a:hover { background: var(--sidebar-hover); }
.sidebar nav a.active { background: var(--sidebar-selected); font-weight: 600; }
/* 側欄彩色圖示磚（Mac GDTile：同色漸層、上緣較亮） */
.nav-tile {
  width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
}
.nav-tile .icon { width: 14px; height: 14px; }
.t-blue   { background: linear-gradient(180deg, #6BA6F8, #3C86F6); }
.t-green  { background: linear-gradient(180deg, #85D68B, #5AC563); }
.t-red    { background: linear-gradient(180deg, #F07A75, #EA4B45); }
.t-brown  { background: linear-gradient(180deg, #C2A186, #A58163); }
.t-orange { background: linear-gradient(180deg, #F5B578, #EF9343); }
.t-purple { background: linear-gradient(180deg, #8A83F0, #5F56EC); }
.t-teal   { background: linear-gradient(180deg, #7FD1DC, #57C0CE); }
.t-indigo { background: linear-gradient(180deg, #8B83F0, #6056ED); }
.t-grey   { background: linear-gradient(180deg, #A8A8AD, #8E8E93); }
.t-pink   { background: linear-gradient(180deg, #F291B0, #E56A93); }
.t-cyan   { background: linear-gradient(180deg, #79C7F0, #4FA8E8); }
.t-gold   { background: linear-gradient(180deg, #F0C978, #E0A93F); }
.sidebar .nav-badge { margin-left: auto; }
.side-user {
  border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px;
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
}
.side-user .who { flex: 1; min-width: 0; }
.side-user .role { display: block; font-size: 11px; color: var(--subtle); }
.link-btn {
  border: none; background: none; color: var(--muted); padding: 6px;
  cursor: pointer; font: inherit; display: inline-flex; align-items: center; gap: 6px;
}
.theme-toggle {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: var(--r-sm); padding: 6px; cursor: pointer; display: inline-flex;
}
.content { flex: 1; padding: 24px; min-width: 0; }
/* 頁首：標題＋說明＋右側操作 */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 200px; }
.page-head .titles p { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.page-head .actions { display: flex; gap: 8px; align-items: center; }
/* 頁首 40pt 彩色磚（Mac 頁首；搭配 .t-blue 等漸層色） */
.page-tile {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.page-tile .icon { width: 20px; height: 20px; }
/* toast（flash） */
.toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.flash, .toast {
  background: var(--info-soft); border: 1px solid var(--info); color: var(--ink);
  padding: 10px 14px; border-radius: var(--r); box-shadow: var(--shadow);
  max-width: 360px; opacity: 1; transition: opacity .4s;
}
.flash.fade, .toast.fade { opacity: 0; }
/* banner（頁內常駐警告） */
.banner { padding: 10px 14px; border-radius: var(--r); margin: 0 0 12px; font-size: 13px; border: 1px solid; }
.banner-error, .banner.danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.banner.danger a { color: var(--danger); }
.banner.warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.banner.info { background: var(--info-soft); border-color: var(--info); color: var(--info); }
.banner.success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
/* ===== 按鈕 ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); text-decoration: none;
  cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-secondary { background: var(--surface); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn[disabled], .btn.htmx-request { opacity: .55; cursor: wait; }
.inline, form.inline, .inline-form { display: inline; margin: 0; }
/* ===== 表格 ===== */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; vertical-align: top; }
.table th { white-space: nowrap; }
.table-keyvalues { table-layout: fixed; }
.table-keyvalues th { width: 42%; white-space: normal; overflow-wrap: anywhere; }
.table-keyvalues td { overflow-wrap: anywhere; }
.table-wrap { max-width: 100%; overflow-x: auto; margin-bottom: 12px; }
.table-wrap .table { min-width: 680px; }
.table-wrap .table-accounts { min-width: 1120px; }
.table-accounts th:first-child { min-width: 190px; }
.cell-content { min-width: 0; overflow-wrap: anywhere; }
.cell-content .btn, .cell-content form { margin-bottom: 4px; }
.cell-content code { overflow-wrap: anywhere; }
.table tr:last-child td { border-bottom: none; }
.table th { color: var(--muted); font-weight: 600; background: var(--sidebar); }
.table tbody tr:hover, .table tr:hover td { background: var(--selected); }
/* ===== pill／badge（狀態一律用 pill） ===== */
.pill, .badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.pill.success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.pill.warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.pill.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.pill.info { background: var(--info-soft); border-color: transparent; color: var(--info); }
.pill.brand, .badge.unread { background: var(--brand); border-color: transparent; color: #fff; }
.badge.ok { background: var(--success-soft); border-color: transparent; color: var(--success); }
.badge.bad { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
/* ===== 表單 ===== */
label { display: block; margin-bottom: 12px; color: var(--ink); font-weight: 500; }
label .hint, .hint { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; }
form input[type=text], form input[type=email], form input[type=password],
form input[type=url], form input[type=number], form input[type=time],
form input[type=search], form textarea, form select {
  display: block; margin-top: 4px; width: 100%; max-width: 520px;
  height: 38px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--r-sm); font: inherit; background: var(--surface); color: var(--ink);
}
form input[type=time] { max-width: 160px; }
form textarea { height: auto; }
form input:focus, form textarea:focus, form select:focus, .sidebar select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
form input.invalid, form textarea.invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; margin-top: 2px; }
.content > form { max-width: 560px; }
/* toggle switch（開關類設定不用裸 checkbox） */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 12px; position: relative; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 22px; border-radius: 11px; background: var(--line);
  position: relative; transition: background .15s; flex-shrink: 0;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: left .15s; box-shadow: var(--shadow-sm);
}
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { left: 18px; }
/* ===== 卡片 ===== */
.cards { display: flex; gap: 12px; flex-wrap: wrap; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px 20px; min-width: 140px; flex: 1; box-shadow: var(--shadow-sm);
}
.card .num { font-size: 28px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 13px; margin-top: 2px; }
a.card { text-decoration: none; color: var(--ink); }
a.card:hover { border-color: var(--brand); }
/* ===== 空狀態 ===== */
.empty {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r-lg);
  padding: 32px; text-align: center; color: var(--muted);
}
.empty .icon { width: 40px; height: 40px; color: var(--subtle); margin-bottom: 8px; }
.empty a, .empty .btn { margin-top: 12px; }
/* ===== 總覽 ===== */
.overview-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-top: 16px; }
.health, .trend {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px; box-shadow: var(--shadow-sm);
}
.health h3, .trend h3 { margin: 0 0 10px; }
.health ul { list-style: none; margin: 0; padding: 0; }
.health li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.health li:last-child { border-bottom: none; }
.health .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--subtle); flex-shrink: 0; }
.health .dot.ok { background: var(--success); }
.health .dot.bad { background: var(--danger); }
.health .dot.warn { background: var(--warning); }
.health .what { flex: 1; }
.health .when { color: var(--muted); font-size: 12px; }
.trend svg { width: 100%; height: auto; display: block; }
.trend .axis { fill: var(--muted); font-size: 10px; }
.warn { color: var(--danger); font-weight: 600; }
/* ===== 收件匣 ===== */
/* ===== 總覽健康區塊（M-27） ===== */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow-sm); }
.pager { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; font-size: 13px; }
.card .num.warn { color: var(--danger); }

.inbox { display: flex; gap: 16px; height: calc(100vh - 48px); }
.inbox-list {
  width: 330px; flex-shrink: 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow-y: auto; box-shadow: var(--shadow-sm);
}
.inbox-search { padding: 10px; border-bottom: 1px solid var(--line); }
.inbox-search input { width: 100%; height: 34px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); font: inherit; background: var(--bg); color: var(--ink); }
.inbox-thread {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); display: flex; flex-direction: column;
  overflow: hidden; position: relative; min-width: 0; box-shadow: var(--shadow-sm);
}
/* 空狀態：撐滿整個右側面板並置中（圖示在上、文字在下） */
.inbox-thread > .empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.jump-latest {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 1;
  background: var(--brand); color: #fff; border: none; border-radius: 999px;
  padding: 6px 14px; font-size: 13px; cursor: pointer; box-shadow: var(--shadow);
}
.thread-back { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.tabs .tab { flex: 1; text-align: center; padding: 9px 4px; text-decoration: none; color: var(--muted); font-size: 13px; }
.tabs .tab.active { color: var(--brand); font-weight: 700; border-bottom: 2px solid var(--brand); background: var(--brand-soft); }
.conv-row {
  display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--ink);
}
.conv-row:hover { background: var(--bg); }
.conv-row.selected { background: var(--selected); }
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 1px solid var(--line); background: var(--surface); }
.avatar-fallback { display: flex; align-items: center; justify-content: center; background: var(--brand); color: #fff; font-weight: 700; font-size: 15px; }
.avatar-sm { width: 26px; height: 26px; font-size: 12px; }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.conv-preview { color: var(--muted); font-size: 13px; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.handoff-row { display: block; }
.handoff-row .conv-name { color: var(--ink); text-decoration: none; font-weight: 600; }
.handoff-row .conv-name:hover { color: var(--brand); text-decoration: underline; }
.handoff-actions { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.load-more { display: block; width: 100%; text-align: center; padding: 10px; color: var(--brand); background: none; border: none; border-bottom: 1px solid var(--line); cursor: pointer; font: inherit; }
.thread-head { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.thread-head .spacer { flex: 1; }
.thread-main { flex: 1; display: flex; min-height: 0; position: relative; }
.thread-body { flex: 1; overflow-y: auto; padding: 16px; }
.thread-side { width: 250px; flex-shrink: 0; border-left: 1px solid var(--line); padding: 14px; overflow-y: auto; background: var(--sidebar); }
.thread-side .cust-name { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.thread-side .cust-facts { color: var(--muted); font-size: 12px; margin: 2px 0; }
.thread-side form { margin-top: 10px; max-width: none; }
.thread-side textarea { height: 64px; max-width: none; }
.thread-foot { border-top: 1px solid var(--line); padding: 10px 16px; }
.thread-foot form { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; }
.thread-foot form > textarea { grid-column: 1 / -1; width: 100%; min-width: 0; min-height: 76px; }
.thread-foot .pause-ai-label { min-width: 0; flex-wrap: wrap; }
.thread-foot .pause-ai-label input { flex-shrink: 0; }
.thread-foot textarea { flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: var(--r); font: inherit; resize: vertical; max-width: none; margin-top: 0; height: auto; }
.quick-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.quick-bar button {
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.quick-bar button:hover { border-color: var(--brand); color: var(--brand); }
/* 泡泡 */
.bubble { max-width: 68%; margin-bottom: 10px; padding: 8px 12px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); width: fit-content; }
.bubble.in { margin-right: auto; }
.bubble.out { margin-left: auto; background: var(--success-soft); border-color: transparent; }
.bubble.out.ai { background: var(--brand-soft); }
.bubble.sys { max-width: 80%; margin: 6px auto; background: transparent; border: none; text-align: center; color: var(--muted); font-size: 12px; padding: 2px; }
.day-sep { text-align: center; color: var(--subtle); font-size: 12px; margin: 14px 0 10px; }
.src-tag { font-size: 11px; color: var(--muted); display: block; margin-bottom: 2px; }
.bubble-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.send-fail { color: var(--danger); font-weight: 600; }
.thumb { max-width: 240px; max-height: 240px; border-radius: var(--r-sm); display: block; margin-bottom: 4px; cursor: zoom-in; }
.media-player { max-width: 320px; width: 100%; display: block; margin-bottom: 4px; }
.sticker-img { width: 120px; height: 120px; object-fit: contain; }
.pause-ai-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin: 6px 0; font-weight: 400; }
.pause-ai-label input { margin: 0; }
/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 100; }
.lightbox img, .lightbox video { max-width: 92vw; max-height: 92vh; border-radius: var(--r); }
.lightbox-close { position: absolute; right: 16px; top: 16px; min-height: 44px; }
.customer-close { display: none; margin: 0 0 12px auto; }
.side-toggle { display: none; }
.nav-backdrop { display: none; }
.form-section { max-width: 760px; padding: 20px; margin: 16px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); scroll-margin-top: 16px; }
.form-section h3 { margin-top: 0; font-size: 17px; }
.settings-fields { padding: 0; margin: 0; border: 0; min-width: 0; }
.section-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.form-row { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.menu-button-card { margin: 12px 0; padding: 16px; border: 1px solid var(--line); border-radius: var(--r); }
.menu-button-card legend { padding: 0 6px; font-weight: 600; }
.menu-image-preview { max-width: 100%; border-radius: var(--r); margin: 12px 0; }
.value-row { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,2fr) auto; gap: 8px; margin-bottom: 10px; align-items: end; }
.value-row label { margin: 0; }
.structured-values { margin-bottom: 16px; }
.wh-url, .uid-mono, .content code { overflow-wrap: anywhere; word-break: break-word; }
/* ===== 帳號頁 ===== */
.bot-cell { display: flex; align-items: center; gap: 10px; }
.bot-name { font-weight: 600; }
.bot-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.quota-text { font-variant-numeric: tabular-nums; }
.quota-bar { height: 5px; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.quota-bar span { display: block; height: 100%; background: var(--success); }
.quota-note { color: var(--muted); font-size: 11px; margin-top: 2px; }
.wh-url { word-break: break-all; }
.notify-ids { word-break: break-all; }
/* ===== 登入頁 ===== */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, var(--brand-soft) 0%, transparent 60%), var(--bg); }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow); padding: 36px 32px 32px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-brand .logo-mark { width: 38px; height: 38px; font-size: 19px; }
.login-brand .brand-name { font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.error {
  background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger);
  padding: 9px 12px; border-radius: var(--r-sm); font-size: 14px; margin-bottom: 16px;
}
.login-card .btn-primary { width: 100%; height: 42px; margin-top: 4px; justify-content: center; }
.login-foot { margin-top: 18px; color: var(--subtle); font-size: 12px; text-align: center; }
/* ===== 錯誤頁 ===== */
.error-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.error-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 32px 36px; max-width: 440px; text-align: center; box-shadow: var(--shadow); }
.error-code { font-size: 44px; font-weight: 700; color: var(--brand); }
.error-msg { color: var(--muted); margin: 12px 0 20px; }
.error-actions { display: flex; gap: 10px; justify-content: center; }
/* ===== 手機（V-01／F-05：單欄＋返回；側欄收合） ===== */
@media (max-width: 900px) {
  .overview-cols { grid-template-columns: 1fr; }
}
/* 視窗偏窄時顧客資訊側欄收合成標題列按鈕（F-08），避免訊息區被擠窄跑版（需 ≥250 側欄＋訊息空間） */
@media (max-width: 1150px) {
  .thread-side { display: none; }
  .thread-side.show { display: block; position: absolute; inset: 0; width: auto; z-index: 5; }
  .customer-close { display: flex; }
  .side-toggle { display: inline-flex; }
}
@media (max-width: 1100px) {
  .has-thread .inbox-list { display: none; }
  .has-thread .thread-back { display: inline-flex; }
  .inbox:not(.has-thread) .inbox-list { width: 100%; }
  .inbox:not(.has-thread) .inbox-thread { display: none; }
}
@media (max-width: 1023px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--line); padding: 10px 12px; display: grid; grid-template-columns: auto minmax(0,1fr) 44px; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 32; }
  .sidebar .logo { margin: 0; gap: 6px; }
  .sidebar > form { min-width: 0; grid-column: 2; grid-row: 1; }
  .sidebar select { margin: 0; height: 44px; font-size: 14px; }
  .nav-toggle {
    display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
    background: var(--surface); color: var(--ink); border-radius: var(--r-sm);
    padding: 8px 10px; font-size: 0; cursor: pointer; width: 44px; height: 44px; justify-content: center; grid-column: 3; grid-row: 1;
  }
  .sidebar nav { display: none; }
  .sidebar.nav-open nav { display: flex; position: fixed; top: 65px; bottom: 75px; left: 0; width: min(340px,90vw); padding: 12px; overflow-y: auto; background: var(--sidebar); z-index: 31; }
  .sidebar .side-user { display: none; }
  .sidebar.nav-open .side-user { display: flex; position: fixed; bottom: 0; left: 0; width: min(340px,90vw); height: 75px; padding: 12px; background: var(--sidebar); z-index: 31; }
  body.nav-open { overflow: hidden; }
  .nav-backdrop { display: block; position: fixed; inset: 65px 0 0; border: 0; background: rgba(0,0,0,.45); z-index: 30; }
  .content { padding: 14px; }
  .form-section { scroll-margin-top: 84px; }
  .inbox { height: calc(100dvh - 94px); min-height: 280px; gap: 10px; }
  .inbox-list { width: 100%; max-height: none; }
  .thread-head, .thread-foot { padding: 10px; }
  .thread-body { padding: 12px; }
  .btn, .btn-sm, .quick-bar button { min-height: 44px; height: auto; padding-top: 8px; padding-bottom: 8px; }
  form input[type=text], form input[type=email], form input[type=password], form input[type=url], form input[type=number], form input[type=time], form input[type=search], form textarea, form select, .inbox-search input, .thread-foot textarea { font-size: 16px; }
  .bubble { max-width: 86%; }
  .bubble-text { overflow-wrap: anywhere; }
  .thumb, .media-player { max-width: 100%; }
  .cards .card { min-width: 40%; }
}
@media (max-width: 1023px) {
  .table-wrap { overflow: visible; }
  .table-wrap .table-cards { min-width: 0; display: block; border: 0; background: transparent; box-shadow: none; }
  .table-cards tbody { display: grid; gap: 12px; }
  .table-cards tr { display: block; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
  .table-cards tr.table-head { display: none; }
  .table-cards td { display: grid; grid-template-columns: 82px minmax(0,1fr); gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: normal !important; max-width: none !important; overflow: visible !important; }
  .table-cards td::before { content: attr(data-label); color: var(--muted); font-size: 13px; }
  .table-cards td[colspan] { display: block; }
  .table-cards td[colspan]::before { display: none; }
  .cell-content { overflow-wrap: anywhere; }
  .cell-content .btn { margin: 2px 2px 2px 0; }
  .table-accounts th:first-child { min-width: 0; }
  .form-section { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .value-row { grid-template-columns: minmax(0,1fr) auto; }
  .value-row label:first-child { grid-column: 1 / -1; }
  .quick-bar { flex-wrap: nowrap; overflow-x: auto; }
  .quick-bar button { flex-shrink: 0; }
}
@media (min-width: 1024px) {
  .nav-toggle { display: none; }
  .sidebar { position: sticky; top: 0; height: 100dvh; align-self: flex-start; }
  .sidebar nav { overflow-y: auto; min-height: 0; }
  .sidebar > .logo, .sidebar > form, .side-user { flex-shrink: 0; }
}

/* ===== UID 複製鍵（顧客詳情，Mac 同風格） ===== */
.uid-line { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; color: var(--muted); }
.uid-mono { font-family: var(--font-mono); font-size: 11px; color: var(--subtle); }
.uid-copy {
  background: none; border: none; cursor: pointer; color: var(--subtle);
  font-size: 11px; padding: 0 2px; border-radius: 3px; line-height: 1;
}
.uid-copy:hover { color: var(--ink); background: var(--line); }
.cust-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; color: var(--muted); font-size: 13px; margin-top: 4px; }

/* S29：通路標籤（LINE／FB／IG） */
.badge-channel { font-size: 11px; padding: 1px 6px; vertical-align: middle; letter-spacing: .02em; }
