/* ============================================================================
   ProComm 統一設計系統 —— theme.css
   ----------------------------------------------------------------------------
   三個產品（A1 客服 / B1 辯論教練 / 校園平台）共用同一套 tokens 同元件。
   改呢個檔案 = 三個產品一齊變。Source of truth 喺 ~/procomm-design/，
   由 scripts/sync-design.sh 複製入各 repo（唔好喺 repo 入面改完唔同步）。

   設計基準（照客戶品牌色 + Stripe 風淺色高級感）：
   - 品牌藍 #116DFF、深藏青文字 #0F1C33（由 procomm.hk 實測抽色）
   - 近無彩色為主，品牌藍只佔版面約 5%（CTA、進行中狀態、focus）
   - 8px 節奏；圓角 10/14/18；陰影兩層（貼邊 + 擴散）
   ============================================================================ */

:root {
  /* ── 顏色 ── */
  --bg:            #f6f8fb;
  --surface:       #ffffff;
  --surface-2:     #fbfcfe;
  --ink:           #0f1c33;
  --ink-2:         #3f4d63;
  --ink-3:         #667489;
  --line:          #e4e9f0;
  --line-2:        #cfd8e3;
  --line-in:       #98a6b8;          /* 表單邊界（非文字 3:1） */

  --brand:         #116dff;
  --brand-ink:     #ffffff;
  --brand-deep:    #0a4fb8;
  --brand-soft:    #eaf2ff;
  --brand-line:    #c3dcff;

  --ok:            #0e7a5f;  --ok-soft:     #e6f5ef;  --ok-line:     #b8e0d2;
  --warn:          #8a5a00;  --warn-soft:   #fdf3e2;  --warn-line:   #efd9ae;
  --danger:        #b42318;  --danger-soft: #fdeceb;  --danger-line: #f3c8c3;
  --info:          #0a4c8c;  --info-soft:   #eaf2ff;  --info-line:   #c3dcff;

  /* ── 圓角 / 間距 / 陰影 ── */
  --r-1: 10px; --r-2: 14px; --r-3: 18px; --r-pill: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
  --shadow-1: 0 1px 2px rgba(15, 28, 51, .06);
  --shadow-2: 0 1px 2px rgba(15, 28, 51, .06), 0 12px 28px -14px rgba(15, 28, 51, .22);
  --shadow-3: 0 2px 4px rgba(15, 28, 51, .06), 0 24px 48px -24px rgba(15, 28, 51, .28);

  --sidebar-w: 240px;
  --topbar-h: 60px;
  --shell-max: 1220px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
               "PingFang TC", "Microsoft JhengHei", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--brand-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 26px; line-height: 1.28; margin: 0 0 6px; font-weight: 700; letter-spacing: -.015em; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 15.5px; margin: 0 0 6px; font-weight: 600; }
p { margin: 0 0 10px; }

.small { font-size: 13px; }
.micro { font-size: 12px; }
.muted { color: var(--ink-3); }
.lead { color: var(--ink-2); font-size: 14.5px; }
.sub { color: var(--ink-3); font-size: 12.5px; margin-top: 2px; line-height: 1.45; }
.hint { font-size: 12.5px; color: var(--ink-3); margin: 6px 0 0; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.num, .num-col { text-align: right; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.c { display: inline-flex; align-items: center; }

/* ── 版面 ── */
.wrap { max-width: var(--shell-max); margin: 0 auto; padding: 0 24px; min-width: 0; }
/* ⚠️ flex／grid 子項要 min-width:0，唔係手機版會被 nowrap 內容（.subnav、表格）撐爆全頁。 */
.narrow { max-width: 460px; margin: 48px auto; }
/* ⚠️ 一定要用 .app-shell 呢個名，唔可以用 .shell：
   A1 客服後台嘅 <main class="shell"> 係**內容容器**（側欄喺外面），
   一旦套咗兩欄 grid，頁面每個直接子元素會被輪流塞入 240px 側欄位 → 全頁 Z 形亂版（真踩過）。 */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.main { padding: 28px 32px 56px; min-width: 0; }
.two { display: grid; grid-template-columns: 1fr 320px; gap: 24px; align-items: start; }
.dash-two { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.pagehead { margin: 4px 0 20px; }
.crumb { font-size: 12.5px; color: var(--ink-3); margin-bottom: 8px; }
.divider { height: 1px; background: var(--line); margin: 20px 0; border: 0; }
.spacer { flex: 1 1 auto; }

/* ── 側欄 + 頂欄（SaaS 後台）── */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand, .brand {
  display: flex; align-items: baseline; gap: 8px; padding: 4px 10px 18px;
  font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: -.01em;
}
.brand:hover { text-decoration: none; }
.brandtext { font-weight: 700; }
.brandname { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.logo { display: flex; align-items: center; justify-content: center; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-1);
  color: var(--ink-2); font-weight: 500; font-size: 14px; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.cur, .nav a.active { background: var(--brand-soft); color: var(--brand-deep); font-weight: 600; }
.nav .group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3); padding: 16px 12px 6px;
}
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 24px; min-height: var(--topbar-h);
  position: sticky; top: 0; z-index: 30;
}
.bar { display: flex; align-items: center; gap: 16px; min-height: var(--topbar-h); }
.baritem { display: flex; align-items: center; gap: 8px; }
.whotext, .who { color: var(--ink-2); font-size: 13.5px; }
.who { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.who-name { font-weight: 600; color: var(--ink); }
.logout { color: var(--ink-3); font-size: 13px; }
.topright { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.searchbar { display: flex; gap: 8px; }
.searchbar input { min-width: 240px; }
.calwrap { display: flex; gap: 8px; align-items: center; }

/* 淺色底嘅語言切換 */
.langswitch { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-pill); overflow: hidden; }
.langswitch a { padding: 3px 10px; font-size: 12px; font-weight: 600; color: var(--ink-3); }
.langswitch a.on { background: var(--brand-soft); color: var(--brand-deep); }
.langswitch a:hover { text-decoration: none; background: var(--surface-2); }

/* ── 卡片 ── */
.card, .mcard, .stat, .panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2);
  padding: 20px 22px; box-shadow: var(--shadow-1);
}
.card { margin: 16px 0; }
.mcard { display: flex; flex-direction: column; }
.note, .empty {
  background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: var(--r-1);
  padding: 14px 16px; color: var(--ink-3); font-size: 13.5px;
}
.empty { text-align: center; padding: 28px 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.group { margin-top: 26px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { flex: 1 1 200px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── 數字卡 ── */
.kpis, .stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); padding: 14px 18px; min-width: 132px; box-shadow: var(--shadow-1); }
.kpi.wide { min-width: 260px; flex: 1 1 260px; }
.k-label, .stat-label { display: block; font-size: 12.5px; color: var(--ink-3); font-weight: 500; }
.k-value { display: block; font-size: 24px; font-weight: 700; margin-top: 2px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.k-of { font-size: 13px; font-weight: 600; color: var(--ink-3); }
.stat-value { display: block; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-meter, .prog { height: 6px; background: #e8eef6; border-radius: var(--r-pill); overflow: hidden; margin: 8px 0 4px; }
.bar-meter > i, .prog > i { display: block; height: 100%; background: var(--brand); }

/* ── 按鈕 ── */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: var(--r-1); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-in); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow-1); }
.btn.primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn.lg { padding: 12px 20px; font-size: 15px; }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.on { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand-deep); }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }
.linkish { background: none; border: 0; color: var(--ink-3); font: inherit; font-size: 13px; cursor: pointer; padding: 0; text-decoration: underline; }
.links { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline { display: inline; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; }
.addnew { display: inline-flex; gap: 6px; align-items: center; color: var(--brand-deep); font-weight: 600; font-size: 13.5px; }

/* ── 表單 ── */
label, .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 12px 0 5px; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line-in); border-radius: var(--r-1);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 14px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
}
input::placeholder { color: #98a6b8; }
.field { display: block; }
.fieldset { border: 0; padding: 0; margin: 0; }
.check { display: inline-flex; gap: 8px; align-items: center; font-weight: 500; margin: 8px 0; }
.pick { display: inline-flex; gap: 6px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 68px; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  font: inherit; font-size: 12.5px; padding: 4px 9px; cursor: pointer; color: var(--ink-3);
}
.submitbar, .actions, .send { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; }

/* ── 標籤／徽章 ── */
.chip, .pill, .badge, .tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
  border-radius: var(--r-pill); padding: 2px 10px; font-size: 12.5px; font-weight: 600;
}
.chip.on, .badge.on, .tag-approved, .pill.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.pill.warn, .tag-pending { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.pill.todo { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.pill.danger, .tag-suspended { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.badge.info, .pill.info { background: var(--info-soft); border-color: var(--info-line); color: var(--info); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0 6px; }
.chips.tight { gap: 6px; margin: 0; }
.chip-x { border: 0; background: transparent; color: currentColor; cursor: pointer; font-size: 11px; line-height: 1; padding: 3px 5px; border-radius: var(--r-pill); }
.chip-x:hover { background: rgba(15, 28, 51, .08); }
.count { font-size: 11.5px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); border-radius: var(--r-pill); padding: 1px 8px; }
.eyebrow { font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--brand-deep); }
.status, .state { font-size: 12.5px; font-weight: 600; }
.when { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }

/* ── 表格 ── */
.tablewrap, .table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3);
  border-bottom: 1px solid var(--line); padding: 10px 12px; white-space: nowrap;
  position: sticky; top: 0; background: var(--surface);
}
.table td { border-bottom: 1px solid #eef2f7; padding: 11px 12px; vertical-align: middle; font-size: 13.5px; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .act, .act-col { text-align: right; white-space: nowrap; }
.table .act form, .act form { display: inline-flex; gap: 6px; align-items: center; }
.code { font-family: var(--font-mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.reveal summary { cursor: pointer; color: var(--ink-3); }
.reveal summary::marker { color: var(--ink-3); }
.reveal span { font-weight: 700; color: var(--ink); }

/* ── 提示條 / toast ── */
.alert {
  display: flex; align-items: center; gap: 10px; border-radius: var(--r-2); padding: 12px 16px;
  border: 1px solid var(--line); background: var(--surface); margin: 16px 0;
}
.alert.info { background: var(--info-soft); border-color: var(--info-line); color: var(--info); }
.alert.warn, .alertbar { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.alertbar { display: flex; align-items: center; gap: 10px; border-radius: var(--r-2); padding: 12px 16px; margin: 16px 0; flex-wrap: wrap; font-size: 13.5px; }
.alertbar .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.alertbar .btn { margin-left: auto; }
.banner { border-radius: var(--r-2); padding: 12px 16px; margin: 16px 0; font-size: 13.5px; }
.banner.info { background: var(--info-soft); border: 1px solid var(--info-line); color: var(--info); }
.countwarn { color: var(--warn); font-weight: 700; }

.toasts { position: fixed; top: 16px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(440px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--r-1);
  padding: 12px 14px; font-size: 13.5px; box-shadow: var(--shadow-3); animation: toast-in .18s ease-out;
}
.toast.ok { background: var(--ok-soft); border-left-color: var(--ok); }
.toast.error { background: var(--danger-soft); border-left-color: var(--danger); color: var(--danger); }
.toast.fade { opacity: 0; transition: opacity .5s; }
.toast-msg { flex: 1 1 auto; line-height: 1.45; }
.toast-x { background: none; border: 0; cursor: pointer; color: inherit; opacity: .7; font-size: 13px; padding: 0 2px; }
@keyframes toast-in { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }
.flash, .flash_message { border-radius: var(--r-1); padding: 11px 14px; margin-bottom: 8px; font-size: 13.5px; border: 1px solid var(--line); background: var(--surface); }
.flash.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.flash.error, .flash-error { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.suggestions { margin: 8px 0 0; }

/* ── 教材檢視 / 播放 ── */
.viewer { margin: 16px 0; }
.player { position: relative; border-radius: var(--r-2); overflow: hidden; background: #0b1220; }
.player video { width: 100%; max-height: 70vh; display: block; background: #000; }
.pdfview { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--surface); }
.wm-layer {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden; user-select: none;
  display: flex; flex-wrap: wrap; align-content: center; justify-content: center;
  gap: 54px 90px; transform: rotate(-22deg) scale(1.35);
  opacity: .16; font-size: 13px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
.pdfview ~ .wm-layer, .player:has(.pdfview) .wm-layer { color: #0f1c33; text-shadow: none; opacity: .11; }
.mkind { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--brand-deep); }
.mcard-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.mcard .desc { color: var(--ink-3); font-size: 13.5px; margin: 4px 0 8px; }
.mcard .meta, .meta { display: flex; gap: 12px; color: var(--ink-3); font-size: 12.5px; margin: 6px 0 12px; flex-wrap: wrap; }
.mcard.stretch { position: relative; }
.mcard.stretch h3 a.title::after { content: ''; position: absolute; inset: 0; }
.mcard h3 a.title { color: var(--ink); }
.stretch { position: relative; }

/* ── 分區導航（長頁）── */
.subnav {
  position: sticky; top: var(--topbar-h); z-index: 30; display: flex; gap: 16px; align-items: center;
  padding: 10px 2px; margin: 8px 0 4px; background: var(--bg); border-bottom: 1px solid var(--line);
  overflow-x: auto; white-space: nowrap;
}
.subnav a { color: var(--ink-2); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.subnav a:hover { color: var(--brand-deep); text-decoration: none; }
.seg, .ev-seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-1); overflow: hidden; }
.seg a, .ev-seg a { padding: 6px 12px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg a:last-child { border-right: 0; }
.seg a.on, .ev-seg a.active { background: var(--brand-soft); color: var(--brand-deep); }
.filters, .toolbar3 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-3); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.kvs { display: flex; flex-direction: column; gap: 6px; }

/* ── 分類色（活動／比賽模組沿用）── */
.cat { font-size: 12px; font-weight: 600; }
.urgent { color: var(--danger); font-weight: 600; }
.good { color: var(--ok); font-weight: 600; }
.err { color: var(--danger); font-weight: 600; }
.paused { color: var(--warn); font-weight: 600; }
.busy { color: var(--ink-3); }

/* ── 手機 ── */
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; flex-wrap: wrap; overflow-x: auto; }
  .nav .group-label { display: none; }
  .two, .dash-two, .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .wrap { padding: 0 16px; min-width: 0; }
  /* ⚠️ 手機版：flex／grid 子項同 nowrap 容器一定要可以縮，唔係全頁橫向溢出。
     真踩過：校園職員台 390px 溢出 413px（main.wrap 被 .subnav 撐到 803px）。 */
  .subnav, .kpis, .stats, .card, .tablewrap { min-width: 0; }
  .subnav { max-width: 100%; }
  .main { padding: 18px 16px 48px; }
  h1 { font-size: 22px; }
  .bar, .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px 10px; }
  .brand-sub { display: none; }
  .who, .topright { margin-left: 0; width: 100%; justify-content: space-between; }
  .card, .mcard, .kpi { padding: 16px; }
  .toasts { left: 12px; right: 12px; top: 12px; max-width: none; }
  .wm-layer { gap: 32px 52px; font-size: 11px; }
  .table { min-width: 560px; }
  .tablewrap, .card { overflow-x: auto; }
}
