/*
  共用「FAST」App Shell 設計系統 — 色彩變數、基礎排版、側欄選單、頁首、panel/按鈕/分頁/表格
  等跨頁共用元件。每個使用這套外殼的頁面（FIR Dashboard、Action Tracking…）都連結（`<link>`，
  不是 @import——見下方）這個檔案，只在自己的 style.css 裡放該頁獨有的元件樣式，避免同一套側欄
  ／配色被每個頁面各自複製一份又慢慢長歪（Action Tracking 一開始就是各自為政才變成跟其他頁不一致）。

  這個檔案要用到 Google Fonts 的 Inter 字重，但字型表改由每個頁面自己在 <head> 用 <link> 載入
  （連同 preconnect），不在這裡用 @import——nested @import 會強迫瀏覽器先把這個檔案下載、解析完
  才知道要去抓字型表，變成序列化的瀑布；改成頁面一開始就平行發出所有請求。套用這套外殼的頁面都要
  自己加這兩行：
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" />
  （搭配 preconnect fonts.googleapis.com / fonts.gstatic.com，非必要但建議）。
*/

:root {
  --color-bg: #f6f7f8;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-border-soft: #eef0f2;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-text-soft: #4b5563;

  --color-brand: #189e4f;
  --color-accent: #1a9e4b;
  --color-accent-dark: #127a3a;
  --color-accent-border: #bfe3cc;
  --color-accent-bg: #e7f6ec;

  --color-danger: #d64545;
  --color-danger-dark: #a12626;
  --color-danger-bg: #fdeaea;
  --color-danger-border: #f6cccc;

  --color-warn: #b27e1d;
  --color-warn-dark: #8a6112;
  --color-warn-bg: #f5ebd3;
  --color-warn-border: #e8d38a;

  --color-info: #3d6fb4;
  --color-info-dark: #2c5490;
  --color-info-bg: #e1ebf7;
  --color-info-border: #c3d7ef;

  --color-chip-bg: #f1f3f4;
  --color-row-selected: #f4fbf6;
  --color-row-selected-alt: #eaf7ef;
  --color-hairline: #f3f4f6;
  --color-surface-subtle: #fcfcfd;
  --color-surface-muted: #fafbfb;

  --font-heading: "Inter", "Inter Fallback", system-ui, sans-serif;
  --font-body: "Inter", "Inter Fallback", system-ui, sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
}

/* Dark mode — same variable names, dark values. Toggled by setting data-theme="dark" on
   <html> (see applyTheme() in each page's script.js). */
:root[data-theme="dark"] {
  --color-bg: #0f1115;
  --color-surface: #171a21;
  --color-border: #2a2e37;
  --color-border-soft: #232630;
  --color-text: #e5e7eb;
  --color-text-muted: #9ca3af;
  --color-text-soft: #cbd5e1;

  --color-brand: #2fbd6c;
  --color-accent: #2fbd6c;
  --color-accent-dark: #6fe3a3;
  --color-accent-border: #2f5c42;
  --color-accent-bg: #163523;

  --color-danger: #f16767;
  --color-danger-dark: #ff9a9a;
  --color-danger-bg: #3a1f1f;
  --color-danger-border: #5c2b2b;

  --color-warn: #e0b75e;
  --color-warn-dark: #f0d38f;
  --color-warn-bg: #3a2f19;
  --color-warn-border: #6b5a1f;

  --color-info: #87ade0;
  --color-info-dark: #aecbef;
  --color-info-bg: #1b2a3a;
  --color-info-border: #2c4560;

  --color-chip-bg: #20242e;
  --color-row-selected: #172018;
  --color-row-selected-alt: #17281e;
  --color-hairline: #232630;
  --color-surface-subtle: #1b1e26;
  --color-surface-muted: #1c2029;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body), system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .15s ease, color .15s ease;
}

h1, h2, h3 { font-family: var(--font-heading); font-weight: 700; margin: 0; }

/* <button> elements don't inherit text color from the UA stylesheet by default (falls back
   to opaque black) — without this, any button-based card/row without its own explicit color
   renders unreadable black text once the surface behind it goes dark in dark mode. */
button { font: inherit; color: inherit; }

a { color: var(--color-accent-dark); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 6px; }
::-webkit-scrollbar-track { background: var(--color-bg); }

[hidden] { display: none !important; }

/* ── App shell ── */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

/* ── Sidebar ── */
.sidebar {
  width: 214px; flex: none; background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  transition: width .15s ease; overflow: hidden;
}
.sidebar.is-collapsed { width: 60px; }
.sidebar-brand {
  height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-border-soft);
}
.sidebar.is-collapsed .sidebar-brand { padding: 0 8px; justify-content: space-between; }
.sidebar-toggle-btn {
  margin-left: auto; flex: none; width: 24px; height: 24px; border: 0; background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
}
.sidebar-toggle-btn:hover { background: var(--color-bg); }
.sidebar-toggle-btn svg { transition: transform .15s ease; }
.sidebar.is-collapsed .sidebar-toggle-btn { margin-left: 0; }
.sidebar.is-collapsed .sidebar-toggle-btn svg { transform: rotate(180deg); }
.sidebar-brand-mark {
  width: 26px; height: 26px; background: var(--color-accent); border-radius: 7px;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.sidebar-brand-name {
  font-family: var(--font-heading); font-weight: 700; font-size: 17px; letter-spacing: .04em;
}
.sidebar-section-label {
  padding: 14px var(--space-4) 6px; font-size: 9.5px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--color-text-muted);
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 var(--space-2); }
.nav-item {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; text-align: left;
  border: 0; border-radius: var(--radius-md); cursor: default; background: transparent;
  padding: 9px 10px; color: var(--color-text-soft); text-decoration: none;
}
.nav-item.is-active {
  background: var(--color-row-selected-alt); color: var(--color-accent-dark);
  box-shadow: inset 2px 0 0 var(--color-accent);
}
/* Most nav items are non-functional placeholders (cursor:default above signals that); the
   few backed by a real page are rendered as <a href> — restore link affordances for those,
   with enough specificity to beat the UA :link/:visited color. */
a.nav-item:link, a.nav-item:visited { color: var(--color-text-soft); }
a.nav-item { cursor: pointer; }
a.nav-item:hover { background: var(--color-bg); }
/* Shared "no function yet" treatment for any control that's a visual placeholder only — a sidebar
   entry with no page behind it, an icon/button not wired to a real action. `grayscale` strips
   whatever accent color the control would otherwise have (so it doesn't need per-component color
   overrides), dimmed further with opacity, and the cursor stays the OS default rather than a
   pointer so it doesn't invite a click that does nothing. */
.is-placeholder { filter: grayscale(1); opacity: .5; cursor: default; }
.nav-item-icon { width: 18px; flex: none; display: flex; align-items: center; justify-content: center; }
.nav-item-icon svg { display: block; }
.nav-item-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.nav-item-label { font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.nav-item-sub { font-size: 10.5px; line-height: 1.25; color: var(--color-text-muted); }

.sidebar.is-collapsed .sidebar-brand-name,
.sidebar.is-collapsed .sidebar-section-label,
.sidebar.is-collapsed .nav-item-body,
.sidebar.is-collapsed .sidebar-user > span:last-child,
.sidebar.is-collapsed .btn-signout span.label { display: none; }
.sidebar.is-collapsed .nav-item { justify-content: center; padding: 9px; }
.sidebar.is-collapsed .sidebar-user { justify-content: center; }
.sidebar.is-collapsed .btn-signout { justify-content: center; }

.sidebar-footer {
  margin-top: auto; padding: 14px var(--space-4); border-top: 1px solid var(--color-border-soft);
  display: flex; flex-direction: column; gap: 10px;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--color-border-soft);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.sidebar-user-name { font-size: 12px; font-weight: 600; display: block; }
.sidebar-user-email { font-size: 10.5px; color: var(--color-text-muted); display: block; }
.btn-signout {
  display: flex; align-items: center; gap: 8px; border: 0; background: transparent;
  cursor: pointer; font-size: 12px; color: var(--color-text-muted); padding: 0;
}

/* ── Main column ── */
.main-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* The page header (primary tabs + page title/tabs) stays pinned to the top while the page scrolls. */
.app-header { position: sticky; top: 0; z-index: 40; background: var(--color-surface); }

.primary-tabs {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border); display: flex; gap: var(--space-6); padding: 0 var(--space-6);
}
.primary-tabs button {
  border: 0; border-bottom: 2px solid transparent; background: transparent; cursor: pointer;
  margin-bottom: -1px; padding: 14px 2px; font-family: var(--font-heading); font-weight: 700;
  font-size: 15px; color: var(--color-text-muted);
}
.primary-tabs button.is-active { color: var(--color-accent-dark); border-bottom-color: var(--color-accent); }

.app-footer {
  margin-top: auto; padding: var(--space-5) var(--space-6); text-align: center;
  font-size: 11.5px; color: var(--color-text-muted); border-top: 1px solid var(--color-border);
}

.page-head {
  background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  padding: var(--space-5) var(--space-6) var(--space-2);
}
.page-head-row { display: flex; align-items: flex-start; gap: var(--space-5); flex-wrap: wrap; }
.page-head-title { font-size: 25px; letter-spacing: .01em; }
.page-head-subtitle { margin: 4px 0 0; font-size: 13px; color: var(--color-text-muted); }
.page-head-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.btn-icon {
  width: 32px; height: 32px; border: 1px solid var(--color-border); background: var(--color-surface);
  border-radius: var(--radius-md); cursor: pointer; display: flex; align-items: center;
  justify-content: center; color: var(--color-text-muted);
}
.btn-icon:hover { background: var(--color-bg); }
.theme-toggle-btn svg { display: block; }
.btn-outline {
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text-soft);
  border-radius: 7px; cursor: pointer; font-size: 11.5px; padding: 6px 12px;
}
.btn-outline:hover { background: var(--color-bg); }
.btn-outline-sm {
  border: 1px solid var(--color-accent-border); background: var(--color-surface); color: var(--color-accent-dark);
  border-radius: 7px; cursor: pointer; font-size: 11.5px; font-weight: 600; padding: 7px 13px; white-space: nowrap;
}
.btn-outline-sm:hover { background: var(--color-row-selected-alt); }
.btn-primary-sm {
  border: 1px solid var(--color-accent); background: var(--color-accent); color: #fff;
  border-radius: 7px; cursor: pointer; font-size: 11.5px; font-weight: 600; padding: 7px 13px; white-space: nowrap;
}
.btn-primary-sm:hover { background: var(--color-accent-dark); border-color: var(--color-accent-dark); }
/* `font: inherit` + `padding: 0` strip the browser's default <button> styling (padding, UA font)
   so a <button class="link-btn"> lines up with a <label class="link-btn">/<a class="link-btn">
   sitting next to it, instead of sitting a few px lower/taller from its own default padding. */
.link-btn { border: 0; background: transparent; cursor: pointer; padding: 0; font: inherit; font-size: 11.5px; font-weight: 600; color: var(--color-accent-dark); }

.tab-row { display: flex; align-items: center; gap: var(--space-3); margin-top: 16px; flex-wrap: wrap; }
.seg-tabs {
  display: inline-flex; gap: 2px; background: var(--color-chip-bg); border: 1px solid var(--color-border);
  border-radius: 9px; padding: 3px;
}
.seg-tabs button {
  display: inline-flex; align-items: center; gap: 7px; border: 0; border-radius: 7px;
  background: transparent; color: var(--color-text-muted); padding: 7px 15px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.seg-tabs button.is-active { background: var(--color-surface); color: var(--color-text); box-shadow: 0 1px 2px rgba(16,24,40,.1); }
.tab-hint { font-size: 11.5px; color: var(--color-text-muted); }

/* ── Views / panels ── */
.view { padding: var(--space-5) var(--space-6) 56px; display: flex; flex-direction: column; gap: var(--space-5); }
.panel {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-5); display: flex; flex-direction: column; gap: 14px;
}
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.panel-kicker { font-size: 9.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--color-text-muted); display: block; }
.panel-title { margin-top: 2px; font-size: 19px; }
.panel-note { font-size: 11.5px; color: var(--color-text-muted); }

.tag-pill { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 5px; font-size: 10.5px; font-weight: 600; }
.tag-pill.is-bad { background: var(--color-danger-bg); color: var(--color-danger-dark); border: 1px solid var(--color-danger-border); }
.tag-pill.is-good { background: var(--color-accent-bg); color: var(--color-accent-dark); border: 1px solid var(--color-accent-border); }
.tag-pill.is-warn { background: var(--color-warn-bg); color: var(--color-warn-dark); border: 1px solid var(--color-warn-border); }
.tag-pill.is-info { background: var(--color-info-bg); color: var(--color-info-dark); border: 1px solid var(--color-info-border); }
.tag-pill.is-neutral { background: var(--color-chip-bg); color: var(--color-text-muted); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 10px; margin-top: 2px; }
.stat-tile { border: 1px solid var(--color-border-soft); border-radius: var(--radius-md); padding: 10px 12px; background: var(--color-surface-muted); }
.stat-tile-value { font-family: var(--font-heading); font-weight: 700; font-size: 23px; line-height: 1; }
.stat-tile-label { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--color-text-muted); margin-top: 4px; }
.stat-tile-sub { font-size: 11.5px; color: var(--color-text-muted); display: flex; align-items: center; gap: 5px; margin-top: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; display: inline-block; }

/* ── Tables ── */
.table-scroll { overflow-x: auto; }
.data-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.data-table th { text-align: left; padding: 7px 10px; font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--color-text-muted); border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.data-table td { padding: 7px 10px; border-bottom: 1px solid var(--color-hairline); }

/* ── Filter bar ── */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-input, .filter-select {
  border: 1px solid var(--color-border); border-radius: 7px; background: var(--color-surface);
  color: var(--color-text); font: inherit; font-size: 12.5px; padding: 7px 10px;
}
.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--color-accent-border); box-shadow: 0 0 0 2px var(--color-row-selected-alt); }
.filter-input { min-width: 200px; flex: 1 1 200px; }
.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--color-border); border-radius: 7px;
  padding: 7px 11px; font-size: 12.5px; cursor: pointer; background: var(--color-surface); color: var(--color-text-muted); font-weight: 600;
}
.chip-toggle.on { background: var(--color-danger-bg); border-color: transparent; color: var(--color-danger-dark); }

/* Report modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200; background: rgba(17,24,28,.5);
  display: flex; align-items: center; justify-content: center; padding: var(--space-5);
}
.modal {
  width: min(640px, 100%); max-height: 82vh; display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--color-surface); border-radius: var(--radius-lg); padding: var(--space-5);
  box-shadow: 0 12px 32px rgba(17,24,28,.28);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.modal-head h3 { font-family: var(--font-heading); font-size: 17px; }
.modal-close {
  border: 0; background: transparent; cursor: pointer; font-size: 20px; line-height: 1;
  color: var(--color-text-muted); padding: 2px 6px;
}
.modal-close:hover { color: var(--color-text); }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { margin-top: 0; }
}
@media (max-width: 480px) {
  .view, .page-head { padding-left: var(--space-4); padding-right: var(--space-4); }
}
