/* ITER4-CSP: extracted from index.html inline <style>.
 * Page-specific layout for the ops admin dashboard:
 *   :root tokens, .app shell, sidebar nav, topbar, KPI strip, module cards.
 *
 * ITER4-L2 (KPI polish):
 *   - .kpi-delta — trend chips (↑ +12% / ↓ -3% / flat) coloured by delta sign
 *   - .kpi-pulse — single pulse animation on auto-refresh tick (30s)
 *   - .kpi.is-alert — red ring when KPI crosses threshold (kyc>50 / disputes>20)
 *   See inline-index.js → refreshKpis() for the JS that drives these classes. */
  :root {
    --bg: #DCDFE4;
    --panel: #FFFFFF;
    --t1: #1A1F2B;
    --t2: #5A6577;
    --t3: #98A0AE;
    --border: #E4E7EC;
    --border-l: #EEF0F3;
    --blue: #2563EB;
    --blue-hover: #1D54CC;
    --blue-bg: #EEF3FF;
    --success: #16A34A;
    --warn: #D97706;
    --danger: #DC2626;
    --gold: #C9A961;
    --r-card: 10px;
    --r-btn: 7px;
    --sans: "Inter", "Noto Sans TC", -apple-system, system-ui, sans-serif;
    --serif: "Noto Serif TC", serif;
    --shadow-sm: 0 1px 2px rgba(26, 31, 43, 0.04), 0 1px 3px rgba(26, 31, 43, 0.04);
    --shadow-md: 0 4px 12px rgba(26, 31, 43, 0.07), 0 2px 4px rgba(26, 31, 43, 0.04);
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

  body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--t1);
    font-size: 14px;
    line-height: 1.5;
  }

  /* ---------- Layout shell ---------- */
  .app {
    display: grid;
    grid-template-columns: 244px 1fr;
    min-height: 100vh;
  }

  /* ---------- Sidebar ---------- */
  .sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-l);
  }

  .seal {
    width: 38px;
    height: 38px;
    border-radius: 9px;
        background: #FFFFFF; border: 1.5px solid #E8D9B0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.4), 0 1px 2px rgba(174, 142, 70, 0.35);
  }
  .seal svg {
    width: 25px;
    height: 25px;
    color: #C9A961; /* 真篆書 #ju-seal (currentColor) 白色 on 金方塊 — 非自生成 serif 字 */
  }
  .brand-text { display: flex; flex-direction: column; gap: 1px; }
  .brand-text .zh { font-family: "Noto Sans TC", var(--sans); font-weight: 700; font-size: 15px; letter-spacing: 0.5px; }
  .brand-text .en { font-size: 11px; color: var(--t3); font-weight: 600; letter-spacing: 0.8px; }

  .nav { padding: 14px 12px; flex: 1; }
  .nav-group { margin-bottom: 18px; }
  .nav-group-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.9px;
    color: var(--t3);
    padding: 0 10px 7px;
    text-transform: uppercase;
  }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-btn);
    color: var(--t2);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    transition: background 0.13s ease, color 0.13s ease;
    text-decoration: none;
  }
  .nav-item svg { width: 17px; height: 17px; stroke-width: 2; color: var(--t3); transition: color 0.13s; }
  .nav-item:hover { background: var(--border-l); color: var(--t1); }
  .nav-item:hover svg { color: var(--t2); }
  .nav-item .badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    background: var(--border-l);
    color: var(--t2);
    padding: 1px 7px;
    border-radius: 999px;
    font-family: var(--sans);
  }
  .nav-item.active {
    background: var(--blue-bg);
    color: var(--blue);
    font-weight: 600;
  }
  .nav-item.active svg { color: var(--blue); }
  .nav-item .badge.warn { background: #FEF3E2; color: var(--warn); }
  .nav-item .badge.danger { background: #FDECEC; color: var(--danger); }

  .sidebar-foot {
    padding: 12px 14px 18px;
    border-top: 1px solid var(--border-l);
    font-size: 11.5px;
    color: var(--t3);
    line-height: 1.45;
  }

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

  .topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .crumb { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--t2); }
  .crumb .root { color: var(--t3); }
  .crumb .sep { color: var(--t3); display: flex; }
  .crumb .sep svg { width: 15px; height: 15px; }
  .crumb .here { color: var(--t1); font-weight: 600; }

  .topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
  .icon-btn {
    width: 34px; height: 34px;
    border-radius: var(--r-btn);
    border: 1px solid var(--border);
    background: var(--panel);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--t2);
    transition: background 0.13s, border-color 0.13s;
    position: relative;
  }
  .icon-btn:hover { background: var(--border-l); }
  .icon-btn svg { width: 17px; height: 17px; stroke-width: 2; }
  .icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 999px; background: var(--danger); border: 1.5px solid var(--panel); }

  .admin {
    display: flex; align-items: center; gap: 10px;
    padding-left: 16px; border-left: 1px solid var(--border-l);
  }
  .admin .avatar {
    width: 32px; height: 32px; border-radius: 999px;
    background: linear-gradient(140deg, #3B82F6, #2563EB);
    color: #fff; font-weight: 600; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
  }
  .admin .meta { display: flex; flex-direction: column; line-height: 1.25; }
  .admin .meta .email { font-size: 13px; font-weight: 600; color: var(--t1); }
  .admin .meta .role { font-size: 11px; color: var(--t3); }

  /* ---------- Content ---------- */
  .content { padding: 28px 32px 48px; max-width: 1320px; width: 100%; }

  .page-head { display: flex; align-items: center; gap: 13px; margin-bottom: 4px; }
  .page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.2px; }
  .demo-pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11.5px; font-weight: 600;
    color: var(--warn);
    background: #FEF6EA;
    border: 1px solid #F6E0BD;
    padding: 3px 10px;
    border-radius: 999px;
    letter-spacing: 0.2px;
  }
  .demo-pill .pip { width: 6px; height: 6px; border-radius: 999px; background: var(--warn); }
  .page-sub { color: var(--t2); font-size: 13.5px; margin: 6px 0 24px; }

  /* KPI strip */
  .kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 32px;
  }
  .kpi {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    padding: 18px 18px 16px;
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column;
  }
  .kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
  .kpi-label { font-size: 13px; color: var(--t2); font-weight: 500; }
  .kpi-ico { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
  .kpi-ico svg { width: 16px; height: 16px; stroke-width: 2; }
  .kpi-ico.blue { background: var(--blue-bg); color: var(--blue); }
  .kpi-ico.warn { background: #FEF3E2; color: var(--warn); }
  .kpi-ico.danger { background: #FDECEC; color: var(--danger); }
  .kpi-ico.success { background: #E7F6ED; color: var(--success); }
  .kpi-val { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; line-height: 1.1; }
  .kpi-val .cur { font-size: 16px; font-weight: 600; color: var(--t2); margin-right: 1px; }
  .kpi-foot { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--t3); }
  .delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; }
  .delta svg { width: 13px; height: 13px; stroke-width: 2.4; }
  .delta.up { color: var(--success); }
  .delta.down { color: var(--danger); }
  .delta.flat { color: var(--warn); }

  /* Module sections */
  .section { margin-bottom: 30px; }
  .section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 13px; padding-left: 1px; }
  .section-head .label { font-size: 12px; font-weight: 700; letter-spacing: 0.9px; color: var(--t3); text-transform: uppercase; }
  .section-head .rule { flex: 1; height: 1px; background: var(--border); }

  .mod-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

  .mod-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.16s cubic-bezier(0.22,1,0.36,1), box-shadow 0.16s ease, border-color 0.16s ease;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    position: relative;
  }
  .mod-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: #D7DBE2;
  }
  .mod-card:hover .mod-ico { background: var(--blue-bg); color: var(--blue); border-color: #DCE6FF; }
  .mod-card:hover .mod-arrow { opacity: 1; transform: translateX(0); color: var(--blue); }
  .mod-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 13px; }
  .mod-ico {
    width: 38px; height: 38px;
    border-radius: 9px;
    background: #F6F7F9;
    border: 1px solid var(--border-l);
    display: flex; align-items: center; justify-content: center;
    color: var(--t2);
    transition: background 0.16s, color 0.16s, border-color 0.16s;
  }
  .mod-ico svg { width: 19px; height: 19px; stroke-width: 1.9; }
  .mod-arrow { color: var(--t3); opacity: 0; transform: translateX(-4px); transition: opacity 0.16s, transform 0.16s, color 0.16s; }
  .mod-arrow svg { width: 17px; height: 17px; stroke-width: 2; }
  .mod-name { font-family: "Noto Sans TC", var(--sans); font-size: 15px; font-weight: 700; margin-bottom: 5px; letter-spacing: 0.2px; }
  .mod-name .en { font-family: var(--sans); font-weight: 600; }
  .mod-desc { font-size: 12.5px; color: var(--t2); line-height: 1.5; }
  .mod-tag {
    align-self: flex-start;
    margin-top: 13px;
    font-size: 11px; font-weight: 600;
    padding: 2px 8px; border-radius: 999px;
    font-variant-numeric: tabular-nums;
  }
  .mod-tag.warn { background: #FEF3E2; color: var(--warn); }
  .mod-tag.danger { background: #FDECEC; color: var(--danger); }
  .mod-tag.neutral { background: var(--border-l); color: var(--t2); }
  .mod-tag.success { background: #E7F6ED; color: var(--success); }

  /* ─── ITER4-L2 KPI polish ─────────────────────────────────────────────
     Delta chips: trend indicator beside each KPI ("↑ +12% / ↓ -3% / —").
     Driven by JS post-fetch: computes (today − yesterday)/yesterday.
     Sign decides class: .up / .down / .flat.
     Empty state ("尚未提供") used when yesterday baseline is unavailable. */
  .kpi-delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    margin-left: 7px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.1px;
    line-height: 1.3;
  }
  .kpi-delta.up { background: #E7F6ED; color: var(--success); }
  .kpi-delta.down { background: #FDECEC; color: var(--danger); }
  .kpi-delta.flat { background: var(--border-l); color: var(--t3); }
  .kpi-delta.empty { background: transparent; color: var(--t3); padding-left: 0; padding-right: 0; }

  /* Pulse: subtle scale pop the moment the value refreshes (every 30s).
     Cue to admins that the data is live, not a stale screenshot. */
  @keyframes fjKpiPulse {
    0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.18); }
    50%  { transform: scale(1.04); box-shadow: 0 0 0 6px rgba(37, 99, 235, 0); }
    100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
  }
  .kpi-val.kpi-pulse { animation: fjKpiPulse 0.6s cubic-bezier(0.22, 1, 0.36, 1); }

  /* Threshold colour-code: red ring once KPI exceeds the alert threshold.
     Thresholds defined in inline-index.js (KPI_ALERT_THRESHOLDS). */
  .kpi.is-alert {
    border-color: #F8B4B4;
    background: linear-gradient(180deg, #FFF8F8 0%, var(--panel) 35%);
    box-shadow: var(--shadow-sm), inset 0 0 0 1px #FDD0D0;
  }
  .kpi.is-alert .kpi-label { color: var(--danger); font-weight: 600; }

  /* Refresh tick — small dot beside the KPI label that fades on each tick.
     Honest signal: "this is the live value from N seconds ago". */
  .kpi-live-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--success);
    margin-right: 5px;
    vertical-align: middle;
    opacity: 0;
    transition: opacity 0.5s ease;
  }
  .kpi-live-dot.is-fresh { opacity: 1; }

  /* Reduced motion: respect prefers-reduced-motion — no scale/pulse. */
  @media (prefers-reduced-motion: reduce) {
    .kpi-val.kpi-pulse { animation: none; }
    .kpi-live-dot { transition: none; }
  }

  /* WCAG-compliant visually-hidden — placeholder data-bind sinks that the
     trend computation reads from. Still in the a11y tree (screen readers
     announce the raw number) but invisible to sighted users. */
  .visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
