/* =====================================================================
   Ringport 設計系統 ds.css
   shadcn/ui neutral token（oklch）＋ 一個克制的藍作主色 ＋ 通話狀態色。
   純 CSS，無相依。用法見 DS-README.md。
   斷點：>=1024 桌機 / 768-1023 平板 / <768 手機
   z-index 尺度：topbar 20、tabbar 30、scrim 40、sidebar 抽屜 41、menu 60、toasts 100
   ===================================================================== */

/* ---------- 1. Token ---------- */
:root {
  color-scheme: light;
  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) * 0.6);
  --radius-md: calc(var(--radius) * 0.8);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) * 1.4);
  --radius-2xl: calc(var(--radius) * 1.8);

  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.52 0.16 250);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.5 0 0);
  --accent: oklch(0.96 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --destructive-foreground: oklch(0.985 0 0);
  --border: oklch(0.922 0 0);
  --input: oklch(0.9 0 0);
  --input-bg: transparent;
  --ring: oklch(0.6 0.14 250);
  --sidebar: oklch(0.985 0 0);
  --sidebar-foreground: oklch(0.145 0 0);
  --sidebar-accent: oklch(0.955 0 0);
  --sidebar-border: oklch(0.922 0 0);

  /* 通話狀態：通話中=ok、保留/靜音=warn、轉接/改號=info、錄音=rec、離線=off。bg=淡底、fg=文字用深色 */
  --ok: oklch(0.62 0.15 150);   --ok-bg: oklch(0.96 0.04 150);   --ok-fg: oklch(0.42 0.11 150);
  --warn: oklch(0.7 0.15 75);   --warn-bg: oklch(0.97 0.05 85);  --warn-fg: oklch(0.46 0.1 70);
  --info: oklch(0.6 0.1 215);   --info-bg: oklch(0.96 0.03 215); --info-fg: oklch(0.42 0.09 225);
  --rec: oklch(0.577 0.245 27.325); --rec-bg: oklch(0.97 0.02 27); --rec-fg: oklch(0.46 0.19 27);
  --off: var(--muted-foreground);
  /* 實心成功色（按鈕底、接聽鍵）：--success 上放 --success-foreground */
  --success: oklch(0.55 0.14 150); --success-foreground: oklch(0.985 0 0);

  --font-sans: "Inter", "Noto Sans TC", ui-sans-serif, system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px -1px rgb(0 0 0 / 0.08);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  --sb-full: 240px;
  --sb-rail: 64px;
  --sb-w: var(--sb-full);
  --topbar-h: 56px;
  --tabbar-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --background: oklch(0.145 0 0);
    --foreground: oklch(0.985 0 0);
    --card: oklch(0.19 0 0);
    --card-foreground: oklch(0.985 0 0);
    --popover: oklch(0.205 0 0);
    --popover-foreground: oklch(0.985 0 0);
    --primary: oklch(0.72 0.13 250);
    --primary-foreground: oklch(0.16 0.02 250);
    --secondary: oklch(0.269 0 0);
    --secondary-foreground: oklch(0.985 0 0);
    --muted: oklch(0.269 0 0);
    --muted-foreground: oklch(0.72 0 0);
    --accent: oklch(0.269 0 0);
    --accent-foreground: oklch(0.985 0 0);
    --destructive: oklch(0.704 0.191 22.216);
    --destructive-foreground: oklch(0.145 0 0);
    --border: oklch(1 0 0 / 12%);
    --input: oklch(1 0 0 / 22%);
    --input-bg: oklch(1 0 0 / 4%);
    --ring: oklch(0.65 0.12 250);
    --sidebar: oklch(0.18 0 0);
    --sidebar-foreground: oklch(0.985 0 0);
    --sidebar-accent: oklch(0.269 0 0);
    --sidebar-border: oklch(1 0 0 / 12%);
    --ok: oklch(0.75 0.16 150);   --ok-bg: oklch(0.28 0.06 150);   --ok-fg: oklch(0.85 0.13 150);
    --warn: oklch(0.8 0.15 80);   --warn-bg: oklch(0.3 0.06 80);   --warn-fg: oklch(0.87 0.12 85);
    --info: oklch(0.76 0.1 215);  --info-bg: oklch(0.28 0.04 215); --info-fg: oklch(0.85 0.09 215);
    --rec: oklch(0.704 0.191 22.216); --rec-bg: oklch(0.29 0.07 25); --rec-fg: oklch(0.82 0.13 25);
  --success: oklch(0.75 0.16 150); --success-foreground: oklch(0.16 0.03 150);
    --shadow-xs: none;
    --shadow-sm: none;
    --shadow-lg: 0 10px 24px -6px rgb(0 0 0 / 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.19 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.205 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.72 0.13 250);
  --primary-foreground: oklch(0.16 0.02 250);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.72 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --destructive-foreground: oklch(0.145 0 0);
  --border: oklch(1 0 0 / 12%);
  --input: oklch(1 0 0 / 22%);
  --input-bg: oklch(1 0 0 / 4%);
  --ring: oklch(0.65 0.12 250);
  --sidebar: oklch(0.18 0 0);
  --sidebar-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.269 0 0);
  --sidebar-border: oklch(1 0 0 / 12%);
  --ok: oklch(0.75 0.16 150);   --ok-bg: oklch(0.28 0.06 150);   --ok-fg: oklch(0.85 0.13 150);
  --warn: oklch(0.8 0.15 80);   --warn-bg: oklch(0.3 0.06 80);   --warn-fg: oklch(0.87 0.12 85);
  --info: oklch(0.76 0.1 215);  --info-bg: oklch(0.28 0.04 215); --info-fg: oklch(0.85 0.09 215);
  --rec: oklch(0.704 0.191 22.216); --rec-bg: oklch(0.29 0.07 25); --rec-fg: oklch(0.82 0.13 25);
  --success: oklch(0.75 0.16 150); --success-foreground: oklch(0.16 0.03 150);
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow-lg: 0 10px 24px -6px rgb(0 0 0 / 0.6);
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0; background: var(--background); color: var(--foreground);
  font: 400 14px/1.5 var(--font-sans); -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
img, svg { max-width: 100%; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
::selection { background: color-mix(in oklab, var(--primary) 25%, transparent); }
[hidden] { display: none !important; }
.num, .tnum { font-family: inherit; font-variant-numeric: tabular-nums; letter-spacing: 0; }   /* 電話號碼、數字一律用 .num（一般字體、等寬數字） */
.mono { font-family: var(--font-mono); }   /* 只給代碼、ID，不給電話號碼 */
/* 命中高亮（<mark class="hl">，DS.highlight 產生）：淡底、無底線、無 padding */
mark.hl { padding: 0; background: color-mix(in oklab, var(--primary) 20%, transparent); color: inherit; font-weight: inherit; text-decoration: none; border-radius: 2px; }
.muted { color: var(--muted-foreground); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Tabler icon：<svg class="i"><use href="#ti-phone"/></svg> */
.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 14px; height: 14px; }
.i-lg { width: 20px; height: 20px; }
.i-xl { width: 24px; height: 24px; }
.i-2xl { width: 32px; height: 32px; stroke-width: 1.5; }

/* ---------- 3. 版面骨架 ---------- */
.app { min-height: 100dvh; padding-left: var(--sb-w); transition: padding-left .2s var(--ease); }
.app-body { min-width: 0; display: flex; flex-direction: column; min-height: 100dvh; }
.main { flex: 1; padding: 24px; min-width: 0; }
.page { max-width: 1200px; margin-inline: auto; }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; margin-bottom: 24px; }
.page-header h1 { font-size: 24px; line-height: 32px; font-weight: 600; letter-spacing: -0.01em; }
.page-desc { margin-top: 4px; color: var(--muted-foreground); max-width: 65ch; }
.section-title { font-size: 16px; font-weight: 600; line-height: 24px; }

.grid { display: grid; gap: 16px; }
.grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.span-2 { grid-column: span 2; }

/* Sidebar */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sb-w); z-index: 41;
  display: flex; flex-direction: column;
  background: var(--sidebar); color: var(--sidebar-foreground);
  border-right: 1px solid var(--sidebar-border);
  transition: width .2s var(--ease), transform .2s var(--ease), visibility 0s;
}
.sb-head { display: flex; align-items: center; height: var(--topbar-h); padding: 0 16px; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: var(--radius-md); background: var(--primary); color: var(--primary-foreground); }
.brand-name { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; font-size: 14px; }
.brand-name small { font-size: 11px; font-weight: 400; color: var(--muted-foreground); letter-spacing: 0; }
.sb-nav { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.sb-group { padding: 14px 10px 6px; font-size: 12px; font-weight: 500; color: var(--muted-foreground); white-space: nowrap; }
.sb-group:first-child { padding-top: 6px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; width: 100%;
  border: 0; border-radius: var(--radius-md); background: none; text-align: left; white-space: nowrap;
  color: color-mix(in oklab, var(--sidebar-foreground) 72%, transparent);
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.nav-item .i { width: 18px; height: 18px; }
.nav-item:hover { background: var(--sidebar-accent); color: var(--sidebar-foreground); }
.nav-item[aria-current="page"], .nav-item[aria-current="true"] { background: var(--sidebar-accent); color: var(--sidebar-foreground); font-weight: 500; }
.nav-item[aria-current="page"] .i, .nav-item[aria-current="true"] .i { color: var(--primary); }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--primary); color: var(--primary-foreground); font-size: 11px; font-weight: 600; }
.sb-foot { flex: none; display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--sidebar-border); font-size: 12px; color: var(--muted-foreground); line-height: 1.35; }
.scrim { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / .5); opacity: 0; pointer-events: none; transition: opacity .2s var(--ease); }
.drawer-open .scrim { opacity: 1; pointer-events: auto; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  height: var(--topbar-h); padding: 0 16px; background: var(--background); border-bottom: 1px solid var(--border);
}
.tb-title { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 14px; font-weight: 500; white-space: nowrap; }
.tb-title .crumb { color: var(--muted-foreground); font-weight: 400; }
.tb-title .i { color: var(--muted-foreground); width: 14px; height: 14px; }
.tb-title .cur { overflow: hidden; text-overflow: ellipsis; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.tb-search { flex: 1; max-width: 420px; margin-left: 12px; }
.tb-right .tb-search-m { display: none; }
.avatar-btn { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 999px; background: none; }

/* 搜尋觸發鈕：長得像 input 的 button */
.search-trigger {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 36px; padding: 0 8px 0 12px;
  border: 1px solid var(--input); border-radius: var(--radius-md); background: var(--input-bg); color: var(--muted-foreground);
  box-shadow: var(--shadow-xs); text-align: left; transition: border-color .15s var(--ease), background-color .15s var(--ease), box-shadow .15s var(--ease);
}
.search-trigger span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-trigger:hover { background: var(--accent); }
.search-trigger:focus-visible { outline: 0; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 40%, transparent); }

/* 切換深淺色時短暫加上 150ms 顏色過渡（JS 在 prefers-reduced-motion 時不加 .theme-anim） */
html.theme-anim, html.theme-anim *, html.theme-anim *::before, html.theme-anim *::after {
  transition: background-color .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease), fill .15s var(--ease), stroke .15s var(--ease), box-shadow .15s var(--ease) !important;
}

/* 底部 tab bar（僅手機） */
.tabbar { display: none; }

/* 桌機收合成 icon rail（html[data-sb=rail]）與平板預設 rail 共用的規則 */
@media (min-width: 1024px) {
  html[data-sb="rail"] { --sb-w: var(--sb-rail); }
  html[data-sb="rail"] .sidebar .lbl, html[data-sb="rail"] .sidebar .nav-badge { display: none; }
  html[data-sb="rail"] .sidebar .sb-head { justify-content: center; padding: 0; }
  html[data-sb="rail"] .sidebar .sb-nav { overflow: visible; }
  html[data-sb="rail"] .sidebar .nav-item { justify-content: center; width: 40px; height: 40px; padding: 0; margin-inline: auto; }
  html[data-sb="rail"] .sidebar .sb-group { height: 1px; padding: 0; margin: 8px 12px; font-size: 0; background: var(--sidebar-border); overflow: hidden; }
  html[data-sb="rail"] .sidebar .sb-foot { justify-content: center; padding: 14px 0; }
  html[data-sb="rail"] .sidebar .nav-item[data-tip]:hover::after, html[data-sb="rail"] .sidebar .nav-item[data-tip]:focus-visible::after { content: attr(data-tip); }
}
@media (min-width: 768px) and (max-width: 1023.98px) {
  :root { --sb-w: var(--sb-rail); }
  .sidebar:not(.is-open) .lbl, .sidebar:not(.is-open) .nav-badge { display: none; }
  .sidebar:not(.is-open) .sb-head { justify-content: center; padding: 0; }
  .sidebar:not(.is-open) .sb-nav { overflow: visible; }
  .sidebar:not(.is-open) .nav-item { justify-content: center; width: 40px; height: 40px; padding: 0; margin-inline: auto; }
  .sidebar:not(.is-open) .sb-group { height: 1px; padding: 0; margin: 8px 12px; font-size: 0; background: var(--sidebar-border); overflow: hidden; }
  .sidebar:not(.is-open) .sb-foot { justify-content: center; padding: 14px 0; }
  .sidebar:not(.is-open) .nav-item[data-tip]:hover::after, .sidebar:not(.is-open) .nav-item[data-tip]:focus-visible::after { content: attr(data-tip); }
  .sidebar { width: var(--sb-rail); }
  .sidebar.is-open { width: var(--sb-full); box-shadow: var(--shadow-lg); }
  .main { padding: 24px 20px; }
  .tb-sim, .tb-title .crumb, .tb-title > .i { display: none; }
  .tb-title { flex: none; }
}
.nav-item[data-tip]::after {
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%); z-index: 60; padding: 4px 8px; border-radius: var(--radius-sm);
  background: var(--foreground); color: var(--background); font-size: 12px; font-weight: 500; white-space: nowrap; pointer-events: none;
}

@media (min-width: 640px) { .grid-2, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* 手機：sidebar 變抽屜，改底部 tab bar */
@media (max-width: 767.98px) {
  :root { --sb-w: 0px; --topbar-h: 52px; }
  .app { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
  .main { padding: 16px; }
  .sidebar { width: min(300px, 86vw); transform: translateX(-100%); visibility: hidden; padding-top: var(--safe-t); transition: transform .2s var(--ease), visibility 0s .2s; }
  .sidebar.is-open { transform: none; visibility: visible; box-shadow: var(--shadow-lg); transition: transform .2s var(--ease), visibility 0s; }
  .nav-item { height: 44px; }
  .sb-nav .nav-item .i { width: 20px; height: 20px; }
  .topbar { padding: var(--safe-t) 12px 0; height: calc(var(--topbar-h) + var(--safe-t)); }
  .tb-toggle, .tb-search, .tb-sim, .tb-bell, .tb-title .crumb, .tb-title > .i { display: none !important; }
  .tb-right .tb-search-m { display: inline-flex; }
  .tb-right .tb-theme, .tb-right .tb-search-m { width: 44px; height: 44px; }
  .avatar-btn { width: 44px; height: 44px; }
  .tb-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
  .page-header h1 { font-size: 22px; line-height: 28px; }
  /* topbar 已顯示頁名時，頁面 h1 加 .page-title：視覺隱藏、保留給讀屏 */
  .page-title { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .sb-foot { display: none; }   /* 手機的「純模擬」提示在頭像選單，這裡不重複 */
  .hide-mobile { display: none !important; }
  .span-2 { grid-column: auto; }
  .tabbar {
    display: grid; grid-template-columns: repeat(var(--tabs, 5), minmax(0, 1fr)); position: fixed; inset: auto 0 0 0; z-index: 30;
    padding-bottom: var(--safe-b); background: var(--background); border-top: 1px solid var(--border);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: var(--tabbar-h); padding: 6px 2px;
    border: 0; background: none; font-size: 11px; font-weight: 500; color: var(--muted-foreground); white-space: nowrap; -webkit-tap-highlight-color: transparent;
  }
  .tabbar .i { width: 22px; height: 22px; }
  .tabbar [aria-current] { color: var(--primary); }
}
@media (min-width: 768px) { .show-mobile { display: none !important; } }

/* ---------- 4. 元件 ---------- */
/* Button */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius-md); font-size: 14px; font-weight: 500; line-height: 1; white-space: nowrap;
  user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), transform .1s var(--ease), color .15s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 0; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 40%, transparent); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: color-mix(in oklab, var(--primary) 88%, var(--foreground)); }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover { background: color-mix(in oklab, var(--secondary) 80%, var(--foreground)); }
.btn-outline { background: var(--input-bg); border-color: var(--input); box-shadow: var(--shadow-xs); }
.btn-outline:hover { background: var(--accent); }
.btn-ghost { background: none; color: inherit; }
.btn-ghost:hover { background: var(--accent); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-destructive:hover { background: color-mix(in oklab, var(--destructive) 88%, var(--foreground)); }
.btn-link { height: auto; padding: 0; border-color: transparent; border-radius: var(--radius-sm); background: none; box-shadow: none; color: var(--primary); }
.btn-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.btn-success { background: var(--success); color: var(--success-foreground); }
.btn-success:hover { background: color-mix(in oklab, var(--success) 88%, var(--foreground)); }
/* 開關狀態（aria-pressed=true）：accent 色調底＋細邊，不整塊反白 */
.btn:not(.btn-primary):not(.btn-destructive):not(.btn-success)[aria-pressed="true"], .icon-btn[aria-pressed="true"] { background: color-mix(in oklab, var(--primary) 14%, var(--background)); border-color: color-mix(in oklab, var(--primary) 40%, transparent); color: var(--primary); }
.btn:not(.btn-primary):not(.btn-destructive):not(.btn-success)[aria-pressed="true"]:hover, .icon-btn[aria-pressed="true"]:hover { background: color-mix(in oklab, var(--primary) 20%, var(--background)); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 40px; padding: 0 24px; }
.btn-icon, .icon-btn { width: 36px; padding: 0; }
.icon-btn { display: inline-grid; place-items: center; height: 36px; border: 1px solid transparent; border-radius: var(--radius-md); background: none; color: var(--muted-foreground); transition: background-color .15s var(--ease), color .15s var(--ease); }
.icon-btn:hover { background: var(--accent); color: var(--foreground); }
.icon-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.btn-icon.btn-sm { width: 32px; }

/* Input / Select / Field */
.input, .select, .textarea {
  display: block; width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--input); border-radius: var(--radius-md);
  background: var(--input-bg); color: var(--foreground); font-size: 14px; box-shadow: var(--shadow-xs);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.textarea { height: auto; min-height: 80px; padding: 8px 12px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--muted-foreground); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 0; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 40%, transparent); }
.input:disabled, .select:disabled, .textarea:disabled { opacity: .5; cursor: not-allowed; }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--destructive); box-shadow: 0 0 0 3px color-mix(in oklab, var(--destructive) 20%, transparent); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6l6 -6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.select option { color: #111; background: #fff; }
.field { display: grid; gap: 6px; }
.label { font-size: 14px; font-weight: 500; line-height: 1.2; }
.hint { font-size: 12px; color: var(--muted-foreground); }
.field-error { font-size: 12px; color: var(--destructive); }
.input-icon { position: relative; }
.input-icon > .i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-foreground); pointer-events: none; }
.input-icon > .input { padding-left: 36px; }
.switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 36px; height: 20px; margin: 0; border-radius: 999px;
  background: var(--input); cursor: pointer; transition: background-color .15s var(--ease);
}
.switch::before { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--background); box-shadow: var(--shadow-xs); transition: transform .15s var(--ease); }
.switch:checked { background: var(--primary); }
.switch:checked::before { transform: translateX(16px); background: var(--primary-foreground); }
.switch:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* Card */
.card { background: var(--card); color: var(--card-foreground); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); }
.card-header { display: grid; gap: 4px; padding: 20px 24px 0; }
.card-title { font-size: 16px; font-weight: 600; line-height: 1.3; letter-spacing: -0.005em; }
.card-desc { font-size: 14px; color: var(--muted-foreground); }
.card-content { padding: 20px 24px; }
.card-header + .card-content { padding-top: 16px; }
.card-footer { display: flex; align-items: center; gap: 8px; padding: 0 24px 20px; }
.card-link { display: block; transition: border-color .15s var(--ease), transform .15s var(--ease), box-shadow .15s var(--ease); }
.card-link:hover { border-color: color-mix(in oklab, var(--ring) 70%, var(--border)); transform: translateY(-1px); }
.card-link:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* Spotlight：滑鼠位置帶一圈柔光（ds.js 自動綁定 .spot） */
.spot { position: relative; overflow: hidden; isolation: isolate; }
.spot::before { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: 0; transition: opacity .25s var(--ease);
  background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 50%), color-mix(in oklab, var(--foreground) 7%, transparent), transparent 70%); }
.spot:hover::before { opacity: 1; }
@media (hover: none) { .spot::before { display: none; } }

/* Badge：default/secondary/outline/destructive + 通話狀態 */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--radius-md); font-size: 12px; font-weight: 500; line-height: 1; white-space: nowrap; }
.badge .i { width: 12px; height: 12px; }
.badge-default { background: var(--primary); color: var(--primary-foreground); }
.badge-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.badge-outline { border-color: var(--border); color: var(--foreground); }
.badge-destructive { background: var(--rec-bg); color: var(--rec-fg); }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-rec { background: var(--rec-bg); color: var(--rec-fg); }
.badge-off { background: var(--muted); color: var(--muted-foreground); }
.badge-success { background: var(--ok-bg); color: var(--ok-fg); }
.badge-ok-outline, .badge-success-outline { border-color: color-mix(in oklab, var(--ok) 55%, transparent); background: none; color: var(--ok-fg); }
/* 人員狀態（DS.agentStatus）：待命=綠、通話中=藍、整理中=黃、休息=灰、離線=灰淡空心 */
.badge-ready { background: var(--ok-bg); color: var(--ok-fg); }
.badge-talk { background: color-mix(in oklab, var(--primary) 14%, transparent); color: var(--primary); }
.badge-wrap { background: var(--warn-bg); color: var(--warn-fg); }
.badge-break { background: var(--muted); color: var(--muted-foreground); }
.badge-offline { border-color: var(--border); background: none; color: var(--muted-foreground); }
.dot { width: 6px; height: 6px; flex: none; border-radius: 50%; background: currentColor; }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); } .dot-info { background: var(--info); } .dot-off { background: var(--off); }
.dot-ready { background: var(--ok); } .dot-talk { background: var(--primary); } .dot-wrap { background: var(--warn); } .dot-break { background: var(--muted-foreground); }
.dot-offline { background: none; box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--muted-foreground) 55%, transparent); }
.dot-rec { width: 8px; height: 8px; border-radius: 50%; background: var(--rec); animation: ds-rec 1.6s infinite; }
@keyframes ds-rec { 0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--rec) 50%, transparent); } 70%, 100% { box-shadow: 0 0 0 8px transparent; } }

/* Tabs（segmented） */
.tabs { display: inline-flex; align-items: center; gap: 2px; height: 36px; padding: 3px; background: var(--muted); border-radius: var(--radius-lg); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs-full { display: flex; width: 100%; }
.tabs-full .tab { flex: 1; }
.tab { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 100%; padding: 0 12px; border: 0; border-radius: var(--radius-md); background: none; color: var(--muted-foreground); font-size: 14px; font-weight: 500; white-space: nowrap; transition: background-color .15s var(--ease), color .15s var(--ease), box-shadow .15s var(--ease); }
.tab:hover { color: var(--foreground); }
.tab[aria-selected="true"] { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }
:root[data-theme="dark"] .tab[aria-selected="true"] { background: var(--accent); box-shadow: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tab[aria-selected="true"] { background: var(--accent); box-shadow: none; } }

/* Table；.table-responsive 在手機轉卡片列表（td 加 data-label，主欄加 data-primary） */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { height: 40px; padding: 0 12px; text-align: left; font-size: 13px; font-weight: 500; color: var(--muted-foreground); white-space: nowrap; border-bottom: 1px solid var(--border); background: color-mix(in oklab, var(--muted) 40%, transparent); }
.table td { height: 48px; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in oklab, var(--muted) 50%, transparent); }
.table .tr, .table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 767.98px) {
  .table-responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-responsive, .table-responsive tbody, .table-responsive tr, .table-responsive td { display: block; width: 100%; }
  .table-wrap:has(.table-responsive) { border: 0; background: none; overflow: visible; }
  .table-responsive tbody { display: grid; gap: 12px; }
  .table-responsive tr { border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); box-shadow: var(--shadow-sm); padding: 4px 16px; }
  .table-responsive tbody tr:hover { background: var(--card); }
  .table-responsive td { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; height: auto; padding: 10px 0; text-align: right; }
  .table-responsive td::before { content: attr(data-label); flex: none; font-size: 13px; color: var(--muted-foreground); text-align: left; }
  .table-responsive td[data-primary] { font-weight: 600; font-size: 15px; justify-content: flex-start; text-align: left; }
  .table-responsive td[data-primary]::before { display: none; }
  .table-responsive tbody tr:last-child td { border-bottom: 1px solid var(--border); }
  .table-responsive tr td:last-child { border-bottom: 0; }
}

/* Dialog：<dialog class="dialog"> + showModal()；手機變底部 sheet */
.dialog { width: min(32rem, calc(100% - 2rem)); max-width: none; max-height: calc(100dvh - 2rem); margin: auto; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--background); color: var(--foreground); box-shadow: var(--shadow-lg); overflow: auto; }
.dialog::backdrop { background: rgb(0 0 0 / .5); }
.dialog[open] { animation: ds-pop .15s var(--ease); display: grid; gap: 16px; }
.dialog-title { font-size: 18px; font-weight: 600; line-height: 1.3; padding-right: 28px; }
.dialog-desc { color: var(--muted-foreground); }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.dialog-close { position: absolute; top: 12px; right: 12px; width: 28px; height: 28px; opacity: .7; }
.dialog-close:hover { opacity: 1; }
@keyframes ds-pop { from { opacity: 0; transform: scale(.96); } }
@keyframes ds-sheet { from { transform: translateY(24px); opacity: 0; } }
@media (max-width: 767.98px) {
  .dialog { width: 100%; margin: auto 0 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; border-bottom: 0; padding-bottom: calc(24px + var(--safe-b)); }
  .dialog[open] { animation-name: ds-sheet; }
  .dialog-footer .btn { flex: 1; }
}

/* Kbd / Avatar / Separator / Alert */
.kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--muted); color: var(--muted-foreground); font: 500 11px/1 var(--font-mono); }
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--secondary); color: var(--secondary-foreground); border: 1px solid var(--border); font-size: 13px; font-weight: 600; overflow: hidden; }
.avatar-sm { width: 24px; height: 24px; font-size: 11px; }
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }
.separator { height: 1px; border: 0; margin: 0; background: var(--border); }
.alert { display: flex; gap: 12px; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); }
.alert > .i { margin-top: 2px; color: var(--muted-foreground); }
.alert-title { font-weight: 500; }
.alert-desc { color: var(--muted-foreground); }
.alert-info { border-color: color-mix(in oklab, var(--info) 35%, var(--border)); background: var(--info-bg); }
.alert-info > .i { color: var(--info-fg); }

/* Stat tile：標籤＋大數字＋說明。數字加 data-count="1284" 會進場滾動 */
.stat { display: grid; gap: 4px; padding: 20px 24px; }
.stat-label { font-size: 13px; color: var(--muted-foreground); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 30px; line-height: 36px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-meta { font-size: 12px; color: var(--muted-foreground); }

/* Empty state / Skeleton */
.empty { display: grid; justify-items: center; gap: 8px; padding: 40px 24px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 4px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--muted); color: var(--muted-foreground); }
.empty-title { font-size: 16px; font-weight: 600; }
.empty-desc { max-width: 40ch; color: var(--muted-foreground); }
.empty .btn { margin-top: 8px; }
.skeleton { display: block; height: 16px; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--muted), color-mix(in oklab, var(--muted) 50%, var(--background)), var(--muted)); background-size: 200% 100%; animation: ds-shimmer 1.3s linear infinite; }
.skeleton-circle { width: 32px; height: 32px; border-radius: 50%; }
.skeleton-block { height: 80px; border-radius: var(--radius-lg); }
@keyframes ds-shimmer { to { background-position: -200% 0; } }

/* Menu（DS.menu）*/
.menu { position: fixed; z-index: 60; min-width: 200px; max-width: calc(100vw - 16px); padding: 4px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--popover); color: var(--popover-foreground); box-shadow: var(--shadow-lg); animation: ds-pop .12s var(--ease); }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; padding: 6px 8px; border: 0; border-radius: var(--radius-sm); background: none; text-align: left; font-size: 14px; }
.menu-item:hover, .menu-item:focus-visible { outline: 0; background: var(--accent); }
.menu-item[disabled] { opacity: .5; pointer-events: none; }
.menu-item .check { margin-left: auto; color: var(--primary); }
.menu-heading { padding: 6px 8px; font-size: 12px; font-weight: 500; color: var(--muted-foreground); }
.menu-sep { height: 1px; margin: 4px -4px; background: var(--border); }
@media (max-width: 767.98px) { .menu-item { min-height: 44px; } }

/* Toast：桌機右上（topbar 下方，避開右下的來電卡）、手機在 tab bar 上方置中 */
.toasts { --toast-dy: -12px; position: fixed; inset: calc(var(--topbar-h) + 12px) 16px auto auto; margin: 0; padding: 0; border: 0; background: none; overflow: visible; width: auto; max-width: none; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; color: inherit; pointer-events: none; z-index: 100; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; width: min(356px, calc(100vw - 32px)); padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--popover); color: var(--popover-foreground); box-shadow: var(--shadow-lg); animation: ds-toast-in .2s var(--ease); transition: opacity .2s var(--ease), transform .2s var(--ease); }
.toast.is-out { opacity: 0; transform: translateY(calc(var(--toast-dy) * .66)); }
.toast > .i { margin-top: 2px; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 500; }
.toast-msg { color: var(--muted-foreground); }
.toast-title + .toast-msg { margin-top: 2px; }
.toast-msg:only-child { color: var(--popover-foreground); }
.toast[data-type="success"] > .i { color: var(--ok); }
.toast[data-type="error"] > .i { color: var(--destructive); }
.toast[data-type="warning"] > .i { color: var(--warn); }
.toast[data-type="info"] > .i { color: var(--info); }
@keyframes ds-toast-in { from { opacity: 0; transform: translateY(var(--toast-dy, -12px)); } }
@media (max-width: 767.98px) { .toasts { --toast-dy: 12px; inset: auto 0 calc(var(--tabbar-h) + var(--safe-b) + 12px) 0; align-items: center; } }

/* ---------- 5. 指令面板（DS.commandPalette） ---------- */
.cmd { width: min(560px, calc(100% - 2rem)); max-width: none; max-height: none; margin: 12vh auto auto; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--popover); color: var(--popover-foreground); box-shadow: var(--shadow-lg); overflow: hidden; }
.cmd::backdrop { background: rgb(0 0 0 / .5); }
.cmd[open] { animation: ds-pop .15s var(--ease); }
.cmd-input { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 12px; border-bottom: 1px solid var(--border); color: var(--muted-foreground); }
.cmd-input input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--foreground); font-size: 16px; }
.cmd-input input::placeholder { color: var(--muted-foreground); }
.cmd-back { display: none; }
.cmd-clear { width: 28px; height: 28px; border-radius: 999px; }
.cmd-list { max-height: 360px; overflow: auto; padding: 4px; overscroll-behavior: contain; }
.cmd-group { padding: 10px 8px 4px; font-size: 12px; font-weight: 500; color: var(--muted-foreground); }
.cmd-item { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--muted-foreground); cursor: pointer; }
.cmd-item .cmd-main { flex: 1; min-width: 0; color: var(--foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-item .cmd-sub { flex: none; max-width: 45%; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-item[aria-selected="true"] { background: var(--accent); color: var(--accent-foreground); }
.cmd-del { width: 24px; height: 24px; border-radius: 999px; }
.cmd-empty { display: grid; justify-items: center; gap: 4px; padding: 36px 16px; text-align: center; color: var(--muted-foreground); }
.cmd-empty strong { color: var(--foreground); font-weight: 500; }
.cmd-foot { display: flex; align-items: center; gap: 16px; height: 36px; padding: 0 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted-foreground); }
.cmd-foot .kbd { margin-right: 2px; }
.cmd-count { margin-left: auto; }
/* 手機：M3 search view，全螢幕，上方返回箭頭＋輸入框 */
@media (max-width: 767.98px) {
  .cmd { width: 100%; height: 100dvh; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
  .cmd[open] { display: flex; flex-direction: column; animation: ds-fade .15s var(--ease); }
  .cmd-input { height: calc(56px + var(--safe-t)); padding: var(--safe-t) 4px 0 4px; gap: 4px; }
  .cmd-back { display: inline-grid; width: 44px; height: 44px; }
  .cmd-ico, .cmd-esc, .cmd-foot { display: none; }
  .cmd-clear { width: 44px; height: 44px; }
  .cmd-list { flex: 1; max-height: none; padding: 4px 8px calc(16px + var(--safe-b)); }
  .cmd-item { min-height: 48px; }
  .cmd-del { width: 44px; height: 44px; }
}
@keyframes ds-fade { from { opacity: 0; } }

/* 漂浮層專用玻璃（approximation，非 Apple 官方）。只給之後 softphone 通話控制條／toast 這類浮層 */
.glass { background: var(--popover); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
@supports (backdrop-filter: blur(1px)) {
  .glass { background: color-mix(in oklab, var(--popover) 72%, transparent); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); }
}
@media (prefers-reduced-transparency: reduce) { .glass { background: var(--popover); backdrop-filter: none; -webkit-backdrop-filter: none; } }

/* ---------- 6. 觸控與動態偏好 ---------- */
@media (pointer: coarse), (max-width: 767.98px) {
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; }
  .btn-icon, .icon-btn { width: 44px; min-height: 44px; height: 44px; }
  .input, .select { height: 44px; font-size: 16px; }
  .textarea { font-size: 16px; }
  .tabs { height: 44px; }
  .tab { min-width: 44px; }
  .avatar-btn { width: 44px; height: 44px; }
  .switch { width: 44px; height: 26px; }
  .switch::before { width: 22px; height: 22px; }
  .switch:checked::before { transform: translateX(18px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
