/* nbaio 共用設計系統：所有服務（accounts、board、之後的新服務）共用這份樣式。
   預設淺色主題、可切換深色（ui/theme.js 設定 <html data-theme>）；左側 sidebar、卡片式版面。
   建置時由各服務的 Containerfile 複製為 /static/base.css（theme.js 一併複製）。
   各服務只在自己的 style.css 放專屬樣式；顏色一律用下面的變數，不要寫死，深色模式才會跟著變。 */
:root {
  color-scheme: light;
  --bg: #f3f5fb;
  --sidebar: #ffffff;
  --panel: #ffffff;
  --panel-2: #f7f8fc;
  --line: #e4e7f0;
  --text: #1d2233;
  --text-2: #4d5469;
  --muted: #7a8197;
  --accent: #2a78d6;          /* 圖表單一系列色（已通過 dataviz 驗證，對淺色底 ≥3:1） */
  --accent-strong: #1f64b8;
  --accent-soft: #e8f1fc;
  --good: #0ca30c;
  --good-ink: #0a7a0a;
  --good-soft: #e7f6e7;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --warn-soft: #fff4dc;
  --crit: #d03b3b;
  --crit-soft: #fdeceb;
  --good-solid: #0a7a0a;       /* 實心按鈕底色（白字） */
  --line-strong: #b9c2d8;      /* hover 時的框線 */
  --line-dashed: #cfd4e2;
  --hover: #eceff6;
  --sunken: #e9ecf5;           /* 分段控制底、停用卡片內的區塊 */
  --faint: #b3b8c7;
  --weekend: #b44a4a;
  --crit-line: #f3c7c5;
  --good-line: #a9d8a9;
  --warn-line: #f1d9a6;
  --warn-faint: #fffaf0;
  --accent-line: #cfe0f7;
  --glow-1: #dfe8fb;           /* 首頁 / 申請頁背景光暈 */
  --glow-2: #e6ecfa;
  --tooltip: #1d2233;
  --shadow-rgb: 29 34 51;
  --shadow: 0 1px 2px rgb(var(--shadow-rgb) / 5%), 0 6px 20px rgb(var(--shadow-rgb) / 6%);
  --radius: 14px;
}

/* 深色：深藍灰而非純黑；accent 調亮以維持對深色底 ≥3:1、白字按鈕 ≥4:1 */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161f;
  --sidebar: #171c27;
  --panel: #1b2130;
  --panel-2: #222939;
  --line: #2e3648;
  --text: #e5e8f0;
  --text-2: #b6bccb;
  --muted: #8b92a6;
  --accent: #3b84de;
  --accent-strong: #7fb2f0;
  --accent-soft: #1d304d;
  --good: #3cb93c;
  --good-ink: #72d072;
  --good-soft: #193323;
  --warn: #fab219;
  --warn-ink: #f0c561;
  --warn-soft: #3a2f16;
  --crit: #ec6461;
  --crit-soft: #3d2024;
  --good-solid: #1f8a2a;
  --line-strong: #4a5570;
  --line-dashed: #44506a;
  --hover: #283043;
  --sunken: #151a25;
  --faint: #576078;
  --weekend: #e98585;
  --crit-line: #6b3236;
  --good-line: #2f6b3a;
  --warn-line: #6e5626;
  --warn-faint: #2a2618;
  --accent-line: #2c4a75;
  --glow-1: #1b2742;
  --glow-2: #19223a;
  --tooltip: #39425a;
  --shadow-rgb: 0 0 0;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 25%);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14.5px/1.55 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
h1 { font-size: 22px; margin: 0 0 2px; letter-spacing: -.01em; }
h2 { font-size: 15.5px; margin: 0 0 2px; }
p { margin: 0; }
a { color: var(--accent-strong); }
svg { fill: currentColor; }

/* ---------- 版面 ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
/* grid 子元素預設 min-width:auto 會被內容（橫向導覽列、長網址）撐開，造成手機版水平溢出 */
.shell > * { min-width: 0; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px; background: var(--sidebar); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #4f6ef7, #2a78d6); color: #fff; font-weight: 800; font-size: 18px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--text-2); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 19px; height: 19px; opacity: .75; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav a.active svg { opacity: 1; }
.count {
  margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--crit); color: #fff; font-size: 12px; font-weight: 700; text-align: center;
}
.side-card { margin-top: auto; padding: 12px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.side-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px 8px 0; border-top: 1px solid var(--line); }
.me-text { min-width: 0; flex: 1; }
.me-text strong, .me-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { color: var(--muted); font-size: 12px; }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
button.icon-btn { border: 0; background: transparent; padding: 0; cursor: pointer; }
/* 沒有側欄的頁面（例如未登入首頁）把主題按鈕放右上角 */
.theme-corner { position: fixed; top: 14px; right: 14px; z-index: 20; }

/* 內容區吃滿側欄右邊的所有寬度（各服務一致；需要限制閱讀寬度的元件自己設 max-width） */
.content { padding: 28px 32px 48px; width: 100%; }
.page { display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; }
.head-actions input { width: 260px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.link { font-size: 13px; text-decoration: none; }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 18px; }

.notice { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--crit); border-radius: var(--radius); padding: 20px 24px; box-shadow: var(--shadow); }
.notice h2 { font-size: 18px; margin-bottom: 8px; }
.notice p + p { margin-top: 12px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--text-2); }
.kpi.alert { border-color: var(--crit-line); background: linear-gradient(0deg, var(--panel), var(--crit-soft)); }

/* ---------- 圖表 ---------- */
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--accent); }
.chart .bar.dim { opacity: .45; }
.chart .hit { fill: transparent; cursor: crosshair; }
.hbars { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .track { height: 10px; border-radius: 0 4px 4px 0; background: var(--panel-2); }
.hbar .fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 3px; }
.hbar .num { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.spark { display: block; width: 100%; height: 34px; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: var(--accent-soft); }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; padding: 6px 10px; border-radius: 8px;
  background: var(--tooltip); color: #fff; font-size: 12.5px; box-shadow: 0 6px 20px rgb(0 0 0 / 18%); white-space: nowrap;
}

/* ---------- 卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card.inactive { background: var(--panel-2); }
.card.inactive .card-top, .card.inactive .stats, .card.inactive .spark-wrap { opacity: .6; }
.card.inactive .stat { background: var(--sunken); }
.card-top { display: flex; align-items: center; gap: 12px; }
.card-top .who { min-width: 0; flex: 1; }
.card-top .who strong { display: block; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-top .who span { color: var(--muted); font-size: 13px; }
.avatar {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: 16px; background: #6a7bd8;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.fields { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.note { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-2); border-left: 3px solid var(--line); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.stat .label { font-size: 11.5px; color: var(--muted); }
.stat .value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .value.small-text { font-size: 13px; font-weight: 600; line-height: 1.9; }
.spark-wrap .label { font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.card-actions .spacer { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px dashed var(--line-dashed); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 2px 10px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.chip.on { border-style: solid; border-color: transparent; background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.chip.static { cursor: default; }
.tag { display: inline-block; border-radius: 6px; padding: 1px 8px; background: var(--panel-2); color: var(--text-2); font-size: 12px; }

.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge::before { font-size: 11px; }
.badge.good { color: var(--good-ink); background: var(--good-soft); }
.badge.good::before { content: "✓"; }
.badge.warn { color: var(--warn-ink); background: var(--warn-soft); }
.badge.warn::before { content: "●"; color: var(--warn); }
.badge.crit { color: var(--crit); background: var(--crit-soft); }
.badge.crit::before { content: "✕"; }
.badge.off { color: var(--muted); background: var(--panel-2); }
.badge.off::before { content: "–"; }
.badge.info { color: var(--accent-strong); background: var(--accent-soft); }
.badge.info::before { content: "…"; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow small { color: var(--muted); }

.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--sunken); border-radius: 10px; align-self: flex-start; }
.segmented button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font: inherit; color: var(--text-2); cursor: pointer; }
.segmented button.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgb(0 0 0 / 10%); }
.empty { padding: 40px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- 表單元件 ---------- */
input, button, textarea { font: inherit; }
input[type=search], input:not([type]), input[type=email], textarea, dialog input {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel); color: var(--text);
}
textarea { resize: vertical; }
input:focus-visible, button:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; font-weight: 500;
}
.btn:hover { border-color: var(--line-strong); background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.good { background: var(--good-solid); border-color: var(--good-solid); color: #fff; }
.btn.danger { color: var(--crit); }
.btn.danger:hover { border-color: var(--crit); background: var(--crit-soft); }
dialog .btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }

dialog {
  width: min(480px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); color: var(--text); padding: 22px 24px; box-shadow: 0 24px 60px rgb(var(--shadow-rgb) / 22%);
}
dialog::backdrop { background: rgb(var(--shadow-rgb) / 35%); }
dialog h2 { font-size: 18px; margin-bottom: 14px; }
dialog label { display: block; margin-bottom: 12px; font-size: 13.5px; color: var(--text-2); }
dialog label input, dialog label textarea { margin-top: 4px; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-size: 13.5px; color: var(--text-2); margin-bottom: 6px; }
.checks { display: flex; gap: 16px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text) !important; margin: 0 !important; font-size: 13.5px; }
.check input { width: auto; margin: 0; }
.hint { font-size: 13px; color: var(--muted); }
.error { color: var(--crit); font-size: 13.5px; min-height: 1em; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.sessions { list-style: none; padding: 0; margin: 0; max-height: 300px; overflow: auto; }
.sessions li { padding: 10px 0; border-bottom: 1px solid var(--line); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60;
  padding: 10px 18px; border-radius: 10px; color: #fff; background: var(--tooltip);
  box-shadow: 0 8px 30px rgb(0 0 0 / 20%); max-width: calc(100vw - 32px);
}
.toast.err { background: var(--crit); }

/* ---------- 響應式 ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { flex: 1; min-width: 0; }
  .nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; min-width: 0; }
  .nav a { white-space: nowrap; }
  .side-card { display: none; }
  .me { margin-left: auto; border-top: 0; padding: 0; }
  .me-text { display: none; }
  .content { padding: 20px 16px 40px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .head-actions { width: 100%; }
  .head-actions input { width: auto; flex: 1; }
  .cards { grid-template-columns: 1fr; }
}
