/* public/style.css — 微壤管理後台
   設計原則：
   1. 中性色為主、品牌深青綠只用在重點（主要按鈕、選中的選單、階段），大面積不上色，看久不累
   2. 8px 間距系統；桌機 14px 字（資訊密度），手機輸入框 16px（iOS 不自動放大）
   3. 狀態色只有三種意義：橘＝要注意（待確認、逾期）、綠＝完成／生效、灰＝歷史
   4. 寬 ≥ 960px：側欄＋表格；以下：上標題列＋底部分頁＋卡片 */

:root {
  --bg: #f3f5f5;
  --surface: #ffffff;
  --surface-2: #f8fafa;
  --ink: #172124;
  --ink-2: #4a5759;
  --muted: #7b8789;
  --line: #e2e7e7;
  --line-2: #eef1f1;
  --brand: #173f45;
  --brand-hover: #0f2f34;
  --brand-ink: #ffffff;
  --brand-soft: #e5efef;
  --brand-text: #1d5960;
  --accent: #2f7a4f;
  --accent-soft: #e5f2ea;
  --warn: #a35c00;
  --warn-soft: #fdf0dc;
  --ok: #18794e;
  --ok-soft: #e3f4ea;
  --danger: #c23a3a;
  --danger-soft: #fbe9e9;
  --shadow-sm: 0 1px 2px rgba(16, 32, 36, .05);
  --shadow-md: 0 4px 16px rgba(16, 32, 36, .08), 0 1px 3px rgba(16, 32, 36, .06);
  --shadow-lg: 0 24px 48px rgba(16, 32, 36, .18);
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --sidebar-w: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1213; --surface: #161b1c; --surface-2: #1b2122; --ink: #e9eeee; --ink-2: #b3bfc0; --muted: #808c8d;
    --line: #283133; --line-2: #1f2729;
    --brand: #6fb6bd; --brand-hover: #8cc8ce; --brand-ink: #0b1517; --brand-soft: #1a2f31; --brand-text: #8cc8ce;
    --accent: #6cc28f; --accent-soft: #19301f; --warn: #f0b24a; --warn-soft: #33270f;
    --ok: #5cc98a; --ok-soft: #142d1d; --danger: #ef7b7b; --danger-soft: #3a1b1b;
    --shadow-sm: none; --shadow-md: 0 4px 16px rgba(0,0,0,.4); --shadow-lg: 0 24px 48px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1213; --surface: #161b1c; --surface-2: #1b2122; --ink: #e9eeee; --ink-2: #b3bfc0; --muted: #808c8d;
  --line: #283133; --line-2: #1f2729;
  --brand: #6fb6bd; --brand-hover: #8cc8ce; --brand-ink: #0b1517; --brand-soft: #1a2f31; --brand-text: #8cc8ce;
  --accent: #6cc28f; --accent-soft: #19301f; --warn: #f0b24a; --warn-soft: #33270f;
  --ok: #5cc98a; --ok-soft: #142d1d; --danger: #ef7b7b; --danger-soft: #3a1b1b;
  --shadow-sm: none; --shadow-md: 0 4px 16px rgba(0,0,0,.4); --shadow-lg: 0 24px 48px rgba(0,0,0,.6);
  color-scheme: dark;
}

/* ---------- 基礎 ---------- */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: .01em; }
.ic { flex: 0 0 auto; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
kbd {
  font: 600 11px/1 ui-monospace, Consolas, monospace; color: var(--muted);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 3px 6px; background: var(--surface);
}

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn .ic { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.quiet { background: transparent; color: var(--brand-text); padding: 0 8px; }
.btn.quiet:hover { background: var(--brand-soft); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--line); }
.btn.danger.armed { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: progress; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }

/* ---------- 版面骨架 ---------- */
.shell { min-height: 100dvh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 20;
  display: flex; flex-direction: column; gap: 8px; padding: 16px 12px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; border-bottom: 1px solid var(--line-2); margin-bottom: 8px; }
.brand img { border-radius: 7px; }
.brand-name { font-weight: 700; font-size: 15px; color: var(--ink); line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 550; text-decoration: none;
}
.nav a .ic { width: 20px; height: 20px; color: var(--muted); }
.nav a:hover { background: var(--line-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); }
.nav a[aria-current="page"] .ic { color: var(--brand-text); }
.badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--brand); color: var(--brand-ink); font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums;
}
.badge.warn { background: var(--warn); color: #fff; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line-2); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.me { display: flex; align-items: center; gap: 10px; padding: 0 6px; min-width: 0; }
.avatar {
  flex: 0 0 32px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-text); font-weight: 700; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
}
.me-text { min-width: 0; }
.me-name { font-weight: 600; font-size: 13px; }
.me-mail { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .btn { width: 100%; }
/* 外觀切換 */
.theme-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; background: var(--line-2); border-radius: 8px; }
.theme-switch button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
  border: 0; border-radius: 6px; background: transparent; color: var(--muted);
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
}
.theme-switch button .ic { width: 16px; height: 16px; }
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-checked="true"] { background: var(--surface); color: var(--brand-text); box-shadow: var(--shadow-sm); }
.topbar-right { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }

.main { margin-left: var(--sidebar-w); min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 32px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar h1 { font-size: 20px; }
.page-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.content { padding: 8px 32px 48px; max-width: 1280px; }

/* ---------- 面板 ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.panel.flush { overflow: hidden; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.panel-head h2 { font-size: 15px; }
.panel-note { font-size: 12px; color: var(--muted); }
/* minmax(0,1fr)：不然不換行的長標題會把欄位撐寬，手機出現橫向捲動 */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid-2 .panel { margin-bottom: 0; }

/* ---------- 指標卡 ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi {
  display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  font: inherit; color: inherit; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.kpi:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); box-shadow: var(--shadow-md); }
.kpi.static { cursor: default; }
.kpi.static:hover { border-color: var(--line); box-shadow: var(--shadow-sm); }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 550; }
.kpi-label .ic { width: 16px; height: 16px; }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi-value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.kpi-hint { font-size: 12px; color: var(--muted); }
.kpi.attention .kpi-value { color: var(--warn); }
a.kpi { text-decoration: none; }
.kpi-src { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.kpi-value .cur { font-size: 13px; margin: 0 4px 0 0; }
.kpi-value.neg { color: var(--danger); }
.kpi-value.stale { color: var(--muted); }
.kpi-warn { font-size: 12px; font-weight: 600; color: var(--warn); }
.kpi-stale { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.kpi-stale .ic { width: 14px; height: 14px; }
.kpi.mine .kpi-value { color: var(--accent); }

/* ---------- 漏斗 ---------- */
.funnel { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; padding: 14px 20px 20px; }
.funnel-step {
  display: flex; flex-direction: column; gap: 8px; padding: 12px; text-align: left;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2);
  font: inherit; color: inherit; cursor: pointer; transition: border-color .15s, background-color .15s;
}
.funnel-step:hover { border-color: var(--brand); background: var(--brand-soft); }
.funnel-step .n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.funnel-step .l { font-size: 12px; color: var(--ink-2); font-weight: 550; }
.funnel-bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.funnel-bar i { display: block; height: 100%; background: var(--brand); border-radius: 2px; }
.funnel-extra { grid-column: 1 / -1; display: flex; gap: 16px; font-size: 12px; color: var(--muted); padding-top: 4px; }
.funnel-extra button { font: inherit; color: var(--ink-2); background: none; border: 0; padding: 0; cursor: pointer; }
.funnel-extra button:hover { color: var(--brand-text); text-decoration: underline; }

/* ---------- 待辦與動態 ---------- */
.todo, .feed, .timeline { list-style: none; margin: 0; padding: 8px 8px 12px; }
.todo li { border-radius: var(--r); }
.todo-item {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 10px 12px; text-align: left;
  background: none; border: 0; border-radius: var(--r); font: inherit; color: inherit; cursor: pointer;
}
.todo-item:hover { background: var(--surface-2); }
.todo-ic {
  flex: 0 0 32px; width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.todo-ic .ic { width: 18px; height: 18px; }
.todo-ic.case { background: var(--accent-soft); color: var(--accent); }
.todo-ic.decision { background: var(--warn-soft); color: var(--warn); }
.todo-main { display: block; flex: 1; min-width: 0; }
.todo-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.todo-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.todo-side { flex: 0 0 auto; font-size: 12px; color: var(--muted); padding-top: 2px; }
.todo-side.due { color: var(--warn); font-weight: 600; }

.feed li { display: flex; gap: 12px; padding: 10px 12px; }
.feed .avatar { flex-basis: 28px; width: 28px; height: 28px; font-size: 12px; }
.feed-main { flex: 1; min-width: 0; font-size: 13px; color: var(--ink-2); }
.feed-main b { color: var(--ink); font-weight: 600; }
.feed-main .target { color: var(--ink); font-weight: 600; cursor: pointer; }
.feed-main .target:hover { color: var(--brand-text); text-decoration: underline; }
.feed-change { margin-top: 2px; }
.feed-reason { margin-top: 4px; padding: 4px 8px; background: var(--surface-2); border-left: 2px solid var(--line); border-radius: 0 4px 4px 0; font-size: 12px; }
.feed-time { flex: 0 0 auto; font-size: 12px; color: var(--muted); }

/* ---------- 工具列 ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-note { margin: 0; font-size: 12px; color: var(--muted); }
.search {
  flex: 1 1 260px; max-width: 420px; position: relative; display: flex; align-items: center;
}
.search-ic { position: absolute; left: 10px; color: var(--muted); pointer-events: none; }
.search-ic .ic { width: 18px; height: 18px; }
.search input { padding-left: 36px; padding-right: 36px; }
.search kbd { position: absolute; right: 10px; }
.seg { display: inline-flex; padding: 3px; background: var(--line-2); border-radius: 8px; gap: 2px; }
.seg button {
  height: 30px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent;
  color: var(--ink-2); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.toolbar select { width: auto; min-width: 140px; }

/* ---------- 表單 ---------- */
label { display: block; font-size: 13px; color: var(--ink-2); font-weight: 550; margin-bottom: 6px; }
.req { font-weight: 600; font-size: 11px; color: var(--warn); margin-left: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 7px 10px; min-height: 36px;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
textarea { resize: vertical; line-height: 1.5; }
.field { margin-bottom: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.help { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
fieldset { border: 0; margin: 0 0 8px; padding: 0; }
/* legend 用 float 脫離 fieldset 邊框，否則會壓在上方分隔線上 */
legend { float: left; width: 100%; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .06em; margin-bottom: 12px; padding: 0; }
legend + * { clear: both; }
fieldset + fieldset { border-top: 1px solid var(--line-2); padding-top: 18px; }
.callout { background: var(--brand-soft); border-radius: var(--r); padding: 12px; }
.callout.warn { background: var(--warn-soft); color: var(--ink); font-size: 13px; margin-bottom: 14px; }
.callout blockquote { margin: 8px 0; padding-left: 10px; border-left: 3px solid var(--warn); white-space: pre-wrap; color: var(--ink-2); }
.err { color: var(--danger); font-size: 13px; min-height: 0; }
.err:empty { display: none; }

/* ---------- 標籤 ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--line-2); color: var(--ink-2);
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.tag.plain::before { display: none; }
.tag.stage { background: var(--brand-soft); color: var(--brand-text); }
.tag.won { background: var(--ok-soft); color: var(--ok); }
.tag.lost, .tag.muted { background: var(--line-2); color: var(--muted); }
.tag.hold, .tag.pending { background: var(--warn-soft); color: var(--warn); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.person { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.person .avatar { flex-basis: 22px; width: 22px; height: 22px; font-size: 11px; }
.person.me { color: var(--accent); font-weight: 600; }
.person.me .avatar { background: var(--accent-soft); color: var(--accent); }
.due { color: var(--warn); font-weight: 600; }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap;
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line);
  user-select: none;
}
.table th[data-sort] { cursor: pointer; }
.table th[data-sort]:hover { color: var(--ink); }
.table th .ic { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-left: 2px; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr { cursor: pointer; transition: background-color .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-title { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: 12px; color: var(--muted); }
.cell-next { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.cell-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.table-foot { font-size: 12px; color: var(--muted); margin: -6px 4px 0; }

/* 案件卡片（手機） */
.case-cards { list-style: none; margin: 0; padding: 0; }
.case-card { padding: 14px 16px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.case-card:last-child { border-bottom: 0; }
.case-card:active { background: var(--surface-2); }
.case-card-top { display: flex; justify-content: space-between; gap: 10px; }
.case-card .tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 6px; }
.case-card .next { font-size: 13px; color: var(--ink-2); }
.case-card .foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }

/* ---------- 決議 ---------- */
.decisions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.decision {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  padding: 16px 20px; border-left: 3px solid var(--line); scroll-margin-top: 90px;
}
.decision.pending { border-left-color: var(--warn); }
.decision.ok { border-left-color: var(--ok); }
.decision.history { opacity: .72; }
.decision.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent); } 100% { box-shadow: var(--shadow-sm); } }
.decision-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.decision-content { margin: 10px 0; font-size: 15px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.decision.history .decision-content { color: var(--ink-2); }
.decision-chain { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.decision-chain .ic { width: 14px; height: 14px; color: var(--muted); }
.decision-chain button { font: inherit; color: var(--brand-text); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.decision-chain button:hover { text-decoration: underline; }
.decision-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--line-2); }
.confirms { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.confirms span { display: inline-flex; align-items: center; gap: 4px; }
.confirms .ic { width: 14px; height: 14px; }
.confirms .yes { color: var(--ok); font-weight: 600; }
.decision-actions { display: flex; gap: 8px; }

/* ---------- 空狀態與骨架 ---------- */
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty .ic { width: 36px; height: 36px; margin: 0 auto 8px; opacity: .5; }
.empty-sm { padding: 18px 12px; text-align: center; color: var(--muted); font-size: 13px; }
.skeleton { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--line-2), var(--line), var(--line-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- 抽屜與對話框 ---------- */
dialog { padding: 0; border: 0; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: rgba(10, 20, 22, .42); }
dialog > form { display: flex; flex-direction: column; height: 100%; max-height: inherit; }
.drawer {
  position: fixed; inset: 0 0 0 auto; margin: 0; width: min(520px, 100vw); height: 100dvh; max-height: 100dvh; max-width: 100vw;
  box-shadow: var(--shadow-lg); border-left: 1px solid var(--line);
}
.modal { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 24px 12px; }
.drawer-kicker { margin: 0 0 2px; font-size: 12px; color: var(--muted); font-weight: 600; }
.drawer-head h2 { font-size: 18px; overflow-wrap: anywhere; }
.drawer-tabs { display: flex; gap: 20px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.drawer-tabs button {
  height: 38px; padding: 0; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
}
.drawer-tabs button[aria-selected="true"] { color: var(--brand-text); border-bottom-color: var(--brand); }
.drawer-body, .modal-body { flex: 1; overflow-y: auto; padding: 20px 24px; overscroll-behavior: contain; }
.drawer-foot { border-top: 1px solid var(--line); padding: 12px 24px calc(12px + env(safe-area-inset-bottom)); background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.drawer-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (prefers-reduced-motion: no-preference) {
  .drawer[open] { animation: slide-in .22s cubic-bezier(.2, .8, .2, 1); }
  .modal[open] { animation: pop-in .18s ease-out; }
  @keyframes slide-in { from { transform: translateX(32px); opacity: 0; } to { transform: none; opacity: 1; } }
  @keyframes pop-in { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* 時間軸（案件紀錄） */
.timeline { padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .t-head { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.timeline .t-head b { color: var(--ink); font-weight: 600; }
.timeline .t-body { margin-top: 2px; font-size: 13px; }
.timeline .t-body s { color: var(--muted); }
.timeline .t-reason { margin-top: 4px; font-size: 12px; color: var(--ink-2); background: var(--surface-2); border-radius: 4px; padding: 4px 8px; }

/* ---------- 通知 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  display: flex; align-items: center; gap: 8px;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: var(--r);
  font-size: 13px; font-weight: 550; box-shadow: var(--shadow-lg); max-width: calc(100vw - 32px);
}

/* ---------- 登入 ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-md); padding: 36px 32px; text-align: center;
}
.login-logo { border-radius: 14px; margin-bottom: 14px; }
.login h1 { font-size: 20px; margin-bottom: 6px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.login .gbtn { display: flex; justify-content: center; min-height: 44px; }
.login-foot { font-size: 12px; margin: 20px 0 0 !important; }

/* ---------- 底部分頁（手機） ---------- */
.tabbar { display: none; }
.mobile-only { display: none !important; }

/* ---------- 響應式 ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .funnel { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 959px) {
  body { font-size: 15px; }
  .sidebar { display: none; }
  .main { margin-left: 0; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 18px; }
  .page-sub { display: none; }
  .content { padding: 4px 16px 24px; }
  .desktop-only { display: none !important; }
  .mobile-only { display: block !important; }
  img.mobile-only { display: block !important; border-radius: 6px; }
  .icon-btn.mobile-only { display: inline-flex !important; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .case-card .person { font-size: 13px; }
  .kpis { gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 24px; }
  .kpi-hint { display: none; }
  .funnel { grid-template-columns: repeat(3, 1fr); padding: 12px 16px 16px; }
  .panel-head { padding: 14px 16px 0; }
  .toolbar .search { flex-basis: 100%; max-width: none; }
  .toolbar .seg { flex: 1; }
  .toolbar .seg button { flex: 1; padding: 0 6px; }
  .toolbar select { flex: 1; }
  /* iOS：輸入框 16px 才不會自動放大 */
  input, select, textarea { font-size: 16px; min-height: 44px; padding: 9px 12px; }
  .btn { height: 42px; }
  .btn.sm { height: 34px; }
  .drawer { width: 100vw; border-left: 0; }
  .drawer-head, .drawer-body, .modal-body { padding-left: 16px; padding-right: 16px; }
  .drawer-tabs { padding: 0 16px; }
  .drawer-foot { padding-left: 16px; padding-right: 16px; }
  .drawer-actions .btn { flex: 1; }
  .decision { padding: 14px 16px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

  .tabbar {
    display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; inset: auto 0 0 0; z-index: 20;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    height: 58px; color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none;
  }
  .tabbar a .ic { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--brand-text); }
  .tabbar .dot { position: absolute; top: 9px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); box-sizing: content-box; }
  .tabbar .dot.warn { background: var(--warn); }
}
@media (max-width: 420px) {
  .row { grid-template-columns: 1fr; gap: 0; }
  .funnel { grid-template-columns: repeat(2, 1fr); }
}
