/* ══════════════════════════════════════════════════════════
   CFO Pilot UI — 共用設計系統 (Tokens + Responsive 基礎)
   v1 — 2026-04
   ══════════════════════════════════════════════════════════ */

:root {
  /* ── New brand palette (CFO Pilot by Kalok&Partners) ── */
  --cfo-navy:  #071E41;   /* primary dark / headers */
  --cfo-blue:  #2563EB;   /* secondary / links */
  --cfo-teal:  #14B8A6;   /* primary accent */
  --cfo-teal-bright: #2DD4BF; /* accents on dark surfaces */
  --cfo-slate: #64748B;   /* neutral secondary */
  --cfo-cloud: #F6F9FC;   /* light surface tint */
  --cfo-yellow:#FACC15;   /* highlight accent (use sparingly) */
  --cfo-gradient: linear-gradient(135deg, #14B8A6 0%, #2563EB 100%); /* CTA */

  /* Brand colors (legacy var names → remapped to new palette) */
  --cfo-green: #14B8A6;          /* was green, now teal (primary accent) */
  --cfo-green-2: #2563EB;        /* was bright green, now blue (gradient end) */
  --cfo-green-soft: rgba(20,184,166,.10);
  --cfo-green-line: rgba(20,184,166,.22);
  --cfo-gold: #64748B;           /* was gold, now slate (neutral) */
  --cfo-gold-2: #94A3B8;
  --cfo-gold-soft: rgba(100,116,139,.10);
  --cfo-gold-line: rgba(100,116,139,.28);
  --cfo-ink: #102338;
  --cfo-header-a: #071E41;
  --cfo-header-b: #14B8A6;

  /* Surface colors */
  --cfo-bg:        #f4f6f9;
  --cfo-surface:   #ffffff;
  --cfo-surface-2: #fbfcfd;
  --cfo-border:    #dfe6ee;
  --cfo-border-2:  #c7d2df;

  /* Text colors */
  --cfo-text:      #102338;
  --cfo-text-sub:  #5f7389;
  --cfo-text-dim:  #8ba0b5;

  /* Status colors */
  --cfo-up:   #1d7a52;
  --cfo-down: #b14146;
  --cfo-warn: #64748B;
  --cfo-info: #1e5da0;

  /* Spacing scale (4px base) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 28px; --sp-8: 32px;

  /* Typography scale */
  --fs-xs: 10px; --fs-sm: 11px; --fs-base: 12px;
  --fs-md: 13px; --fs-lg: 14px; --fs-xl: 16px;
  --fs-2xl: 20px; --fs-3xl: 24px;

  /* Radii */
  --rad-xs: 3px; --rad-sm: 6px; --rad-md: 8px;
  --rad-lg: 12px; --rad-xl: 16px; --rad-pill: 999px;

  /* Shadows */
  --sh-sm:  0 1px 2px rgba(17,35,56,.06);
  --sh-md:  0 2px 12px rgba(26,38,53,.08);
  --sh-lg:  0 8px 24px rgba(11,37,64,.14);
  --sh-xl:  0 14px 40px rgba(11,37,64,.18);

  /* Brand font stack */
  --ff-base: "Inter", "PingFang TC", "PingFang SC",
             "Microsoft JhengHei", "Microsoft YaHei",
             system-ui, -apple-system, sans-serif;
  --ff-mono: "SF Mono", "Roboto Mono", "Menlo", monospace;

  /* Layout */
  --topbar-h: 56px;
  --topbar-h-mobile: 52px;
  --content-max: 1460px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ────────────────── Base reset (non-destructive) ────────────────── */
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--ff-base); }

/* Smoother fonts on retina */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Touch target minimum on mobile */
@media (max-width: 768px) {
  button, a, select, input, .topbar-app-btn, .topbar-admin-btn, .topbar-solid-btn {
    min-height: 36px;
  }
}

/* ──────── 全站表單控制項一致化（修 iOS Safari select 原生外觀 + 大小不一）──────── */
input, select, textarea, button { box-sizing: border-box; }
/* select：去掉瀏覽器/iOS 原生外觀，改用統一的自訂箭頭，與 input 同高同圓角 */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235f7389' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 11px;
  padding-right: 28px !important;
}
select::-ms-expand { display: none; }
:root[data-cfo-mode="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a9b6c6' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* iPhone：主要表單欄位字級 ≥16px → 不再一聚焦就自動放大、且大小統一；密集表格/明細列維持小字 */
@media (max-width: 768px) {
  .fld input, .fld select, .field input, .field select,
  .form input, .form select, .frow input, .frow select,
  .toolbar input, .toolbar select, .inv-filter input, .inv-filter select,
  .lui-input, .lui-select, input.ad-input, select.ad-select {
    font-size: 16px;
  }
  /* 例外：密集列維持原本小字，不要被撐大 */
  tr.filter-row input, tr.filter-row select,
  tr.jfilter-row input, tr.jfilter-row select,
  .lines input, .lines select { font-size: 12px; }
}

/* ────────────────── Mobile Drawer Pattern ────────────────── */
/* Hamburger 始終固定在右上角 (避開瀏海/safe-area)，所有頁面表現一致 */
.lui-mobile-trigger {
  display: none;
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  z-index: 990;
  background: rgba(11, 37, 64, .82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .14);
  color: #F6F9FC;
  font-size: 18px;
  font-weight: 700;
  border-radius: 10px;
  width: 40px; height: 40px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, transform .12s ease;
  box-shadow: 0 4px 14px rgba(11, 37, 64, .35);
}
.lui-mobile-trigger:hover { background: rgba(11, 37, 64, .92); }
.lui-mobile-trigger:active { transform: scale(0.94); }
.lui-mobile-trigger:focus-visible {
  outline: 2px solid var(--cfo-gold);
  outline-offset: 2px;
}
/* drawer 開啟時 hide trigger，避免疊在 close 按鈕上 */
body.lui-drawer-active .lui-mobile-trigger { opacity: 0; pointer-events: none; }

.lui-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11,37,64,.55);
  backdrop-filter: blur(2px);
  z-index: 999;
  animation: lui-fade-in .2s ease;
}
.lui-drawer-backdrop.open { display: block; }

.lui-drawer {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(320px, 86vw);
  background: linear-gradient(180deg, #071E41 0%, #18496d 100%);
  z-index: 1000;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  box-shadow: -8px 0 24px rgba(0,0,0,.3);
  animation: lui-slide-in .25s cubic-bezier(.22,1,.36,1);
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
.lui-drawer.open { display: flex; }
.lui-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.lui-drawer-brand {
  font-size: 16px;
  font-weight: 800;
  color: #F6F9FC;
  letter-spacing: 3px;
}
.lui-drawer-close {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--rad-sm);
}
.lui-drawer-close:hover { background: rgba(255,255,255,.10); color: #fff; }
.lui-drawer-section {
  font-size: 10.5px;
  letter-spacing: 1.5px;
  color: rgba(244,232,193,.5);
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 8px;
  padding-left: 4px;
}
.lui-drawer-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  color: rgba(255,255,255,.92);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  transition: background .12s, border-color .12s;
}
.lui-drawer-link:hover, .lui-drawer-link.active {
  background: rgba(255,255,255,.18);
  border-color: rgba(255,255,255,.32);
  color: #fff;
}
.lui-drawer-link[disabled], .lui-drawer-link.disabled {
  opacity: .35;
  cursor: not-allowed;
  pointer-events: none;
}
.lui-drawer-meta {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.6);
  font-size: 11px;
  line-height: 1.6;
}
.lui-drawer-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cfo-gold) 0%, #d6b256 100%);
  color: #2f2100;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px;
  flex-shrink: 0;
}
.lui-drawer-logout {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.20);
  border-radius: 8px;
  color: rgba(255,255,255,.92);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s;
}
.lui-drawer-logout:hover {
  background: rgba(177,65,70,.20);
  border-color: rgba(177,65,70,.5);
  color: #ffd9da;
}

/* ────────────────── Mobile breakpoints ────────────────── */
@media (max-width: 768px) {
  .lui-mobile-trigger { display: inline-flex; }
  .lui-hide-mobile { display: none !important; }
  .lui-stack-mobile {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  /* 在 mobile 上隱藏桌面版的 app switcher (改用 hamburger drawer 導航) */
  .topbar-app-switch,
  .topbar-app-switch + .topbar-divider,
  #topbar-app-switch {
    display: none !important;
  }
  /* Topbar title 簡化 */
  .topbar-title-wrap .topbar-subtitle { display: none; }
  /* 把 hamburger trigger 放到 topbar-right 看起來自然 */
  .topbar-right .lui-mobile-trigger {
    margin-left: auto;
    border-color: rgba(255,255,255,.18);
    background: rgba(255,255,255,.10);
  }
}
@media (min-width: 769px) {
  .lui-show-mobile { display: none !important; }
}

/* Body scroll lock when drawer open */
body.lui-drawer-active { overflow: hidden; }

/* ────────────────── Animations ────────────────── */
@keyframes lui-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes lui-slide-in {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

/* ────────────────── Generic responsive overrides ────────────────── */
/* 確保表格 wrapper 在小螢幕能正常水平捲動 */
@media (max-width: 768px) {
  .scroll-wrap, .table-wrap, .fd-table-wrap, .tbl-scroll-outer {
    -webkit-overflow-scrolling: touch;
  }
  /* 把固定寬度的 hero / card 變 flexible */
  .hero, .card, .card-headline {
    border-radius: var(--rad-md);
  }
  /* KPI 一欄一個 */
  .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  /* 雙欄變單欄 */
  .dual-grid { grid-template-columns: 1fr !important; }
  /* 留出 hamburger 占位 (避免內容被擋) */
  .topbar, .topbar-inner {
    padding-right: 56px !important;
  }
  /* Topbar 內容垂直排版 */
  .topbar-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 14px !important;
    padding-right: 56px !important;
  }
  /* 工具列填滿 */
  .filter-toolbar {
    overflow-x: auto;
    flex-wrap: wrap;
    gap: 6px 8px;
  }
  /* 月份 chip 變成可橫向捲動 */
  .hp-trigger {
    min-width: 0 !important;
    width: 100%;
    justify-content: space-between;
  }
  /* Custom multi-select panel: 在手機上取代右下下拉成全螢幕半幅彈出 */
  .ms.open .ms-panel,
  .ms-hdr.open .ms-panel {
    position: fixed !important;
    top: auto !important;
    left: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    width: auto !important;
    max-width: none !important;
    max-height: 70vh;
    z-index: 9999 !important;
    border-radius: var(--rad-lg);
    box-shadow: var(--sh-xl);
  }
  .ms.open .ms-list,
  .ms-hdr.open .ms-list { max-height: 50vh; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr !important; }
}

/* ────────────────── 共用 utility ────────────────── */
.lui-no-scroll { overflow: hidden; }
.lui-text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lui-tap {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ══════════════════════════════════════════════════════════
   Unified Topbar — 三頁共用視覺處理
   每頁的 .topbar 各自有 markup, 但這裡統一外觀
   gradient 用 theme tokens 所以主題切換時會跟著變色
   ══════════════════════════════════════════════════════════ */
.topbar {
  background: linear-gradient(105deg, var(--cfo-header-a) 0%, var(--cfo-header-b) 55%, var(--cfo-green-2) 100%) !important;
  color: #fff;
}
/* 底部金色光帶 — 三頁一致 */
.topbar::after {
  content: "";
  display: block;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, #e7c96e 28%, var(--cfo-gold) 50%, #e7c96e 72%, transparent 100%);
  opacity: .75;
}

/* Brand 統一 — CFO Pilot 現代字標 (Inter) */
.topbar-logo-cn,
.brand-cn {
  color: #F6F9FC;
  font-family: 'Inter', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: -.01em;
}
.topbar-logo-cn .pilot,
.brand-cn .pilot { color: #2DD4BF; font-weight: 600; }
.topbar-logo-en,
.brand-en {
  color: rgba(148, 163, 184, .85);
  letter-spacing: .22em;
  font-weight: 600;
}

/* App switcher 按鈕 hover 樣式統一 */
.topbar-app-btn {
  border: 1px solid rgba(255,255,255,.22) !important;
  background: rgba(255,255,255,.10) !important;
  color: rgba(255,255,255,.92) !important;
  font-weight: 700;
  transition: background .15s ease, border-color .15s ease;
}
.topbar-app-btn:hover {
  background: rgba(255,255,255,.18) !important;
  border-color: rgba(255,255,255,.34) !important;
}
.topbar-app-btn.active {
  background: rgba(255,255,255,.25) !important;
  color: #fff !important;
}

/* Admin / 後台等按鈕同色系 */
.topbar-admin-btn {
  border: 1px solid rgba(255,255,255,.22) !important;
  background: rgba(255,255,255,.10) !important;
  color: rgba(255,255,255,.92) !important;
  text-decoration: none;
}
.topbar-admin-btn:hover {
  background: rgba(255,255,255,.18) !important;
  border-color: rgba(255,255,255,.34) !important;
}

/* ══════════════════════════════════════════════════════════
   Shared Tabs + Filter Bar (finance-dashboard pattern)
   給三個頁面共用 — 店鋪切換 + 檢視/期間/報表 toolbar
   ══════════════════════════════════════════════════════════ */
.lui-store-tabs-bar {
  background: #ffffff;
  border-bottom: 2px solid var(--cfo-border);
  padding: 0 24px;
  display: flex;
  gap: 0;
  overflow-x: auto;
  box-shadow: 0 1px 4px rgba(26,38,53,.06);
  -webkit-overflow-scrolling: touch;
}
.lui-store-tabs-bar::-webkit-scrollbar { height: 0; }
.lui-store-tab {
  padding: 13px 20px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--cfo-text-sub);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all .2s;
  letter-spacing: .2px;
}
.lui-store-tab:hover {
  color: var(--cfo-green);
  background: var(--cfo-green-soft);
}
.lui-store-tab.active {
  color: var(--cfo-green);
  border-bottom-color: var(--cfo-green);
  font-weight: 700;
}
/* 區域分組 separator */
.lui-store-tab-sep {
  width: 1px;
  background: var(--cfo-border);
  margin: 8px 6px;
  flex-shrink: 0;
}
/* 區域 label (一區 / 二區) */
.lui-store-tab-label {
  display: inline-flex;
  align-items: center;
  padding: 0 12px 0 8px;
  color: var(--cfo-text-dim);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Filter bar (filter-bar from finance) */
.lui-filter-bar {
  background: var(--cfo-surface);
  border: 1px solid var(--cfo-border);
  border-radius: var(--rad-lg);
  box-shadow: var(--sh-md);
  padding: 7px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.lui-filter-group {
  display: flex;
  align-items: center;
  gap: 5px;
}
.lui-filter-lbl {
  font-size: 9px;
  font-weight: 800;
  color: var(--cfo-text-dim);
  text-transform: uppercase;
  letter-spacing: .9px;
  white-space: nowrap;
}
.lui-filter-pills {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  align-items: center;
}
.lui-filter-sep {
  width: 1px;
  height: 20px;
  background: var(--cfo-border);
}
.lui-filter-spacer { flex: 1; }
/* fp-btn shared pill */
.lui-fp-btn {
  border: 1px solid var(--cfo-border-2);
  background: var(--cfo-surface);
  color: var(--cfo-text-sub);
  border-radius: 5px;
  padding: 4px 10px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .13s ease;
  white-space: nowrap;
  letter-spacing: .3px;
  line-height: 1.4;
}
.lui-fp-btn.active {
  background: var(--cfo-green);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(20,184,166,.2);
  font-weight: 700;
}
.lui-fp-btn:hover:not(.active):not(:disabled) {
  border-color: var(--cfo-green);
  color: var(--cfo-green);
  background: var(--cfo-green-soft);
}
.lui-fp-btn:disabled { opacity: .45; cursor: not-allowed; }
.lui-fp-btn-ghost {
  background: transparent;
  border-color: var(--cfo-border);
  color: var(--cfo-text-dim);
}
.lui-fp-btn-ghost:hover {
  color: var(--cfo-text-sub);
  background: var(--cfo-bg);
}

/* Period multi-select dropdown */
.lui-period-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--cfo-border-2);
  background: var(--cfo-surface);
  border-radius: 5px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--cfo-text);
  cursor: pointer;
  transition: border-color .12s;
}
.lui-period-trigger:hover { border-color: var(--cfo-green); color: var(--cfo-green); }
.lui-period-trigger .lui-fp-caret { font-size: 9px; opacity: .7; }
.lui-period-wrap { position: relative; }
.lui-period-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  background: var(--cfo-surface);
  border: 1px solid var(--cfo-border-2);
  border-radius: var(--rad-md);
  padding: 10px;
  box-shadow: var(--sh-lg);
  min-width: 280px;
  max-width: 400px;
  display: none;
}
.lui-period-wrap.open .lui-period-dropdown { display: block; }
.lui-period-dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 10.5px;
  color: var(--cfo-text-sub);
  font-weight: 700;
}
.lui-period-dd-clear {
  background: transparent;
  border: none;
  font: inherit;
  font-size: 10.5px;
  color: var(--cfo-info);
  cursor: pointer;
  font-weight: 700;
}
.lui-period-dd-clear:hover { text-decoration: underline; }

/* Mobile adjustments */
@media (max-width: 768px) {
  .lui-store-tabs-bar { padding: 0 12px; }
  .lui-store-tab { padding: 11px 14px; font-size: 12px; }
  .lui-filter-bar { padding: 8px 10px; gap: 6px; border-radius: 12px; }
  .lui-filter-lbl { font-size: 8.5px; letter-spacing: .6px; }
  .lui-filter-sep { display: none; }
}

/* ════════════════════ Component Library ════════════════════ */

/* ──────── Focus ring (a11y) ──────── */
:where(button, a, [role="button"], input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--cfo-green);
  outline-offset: 2px;
  border-radius: var(--rad-sm);
}

/* ──────── Buttons ──────── */
.lui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--rad-md);
  background: transparent;
  color: var(--cfo-text);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: .15px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease,
              transform .08s ease, box-shadow .15s ease;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  user-select: none;
}
.lui-btn:disabled, .lui-btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}
.lui-btn:active:not(:disabled) { transform: translateY(1px); }
.lui-btn-sm  { padding: 5px 10px; font-size: var(--fs-sm); }
.lui-btn-lg  { padding: 11px 18px; font-size: var(--fs-lg); }

/* Variants */
.lui-btn-primary {
  background: var(--cfo-gradient);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(20, 184, 166, .18);
}
.lui-btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #0EA5A0 0%, #1D4FD8 100%);
  box-shadow: 0 6px 16px rgba(37, 99, 235, .28);
}
.lui-btn-secondary {
  background: var(--cfo-surface);
  color: var(--cfo-text);
  border-color: var(--cfo-border-2);
}
.lui-btn-secondary:hover:not(:disabled) {
  background: var(--cfo-surface-2);
  border-color: var(--cfo-text-sub);
}
.lui-btn-ghost {
  color: var(--cfo-text-sub);
}
.lui-btn-ghost:hover:not(:disabled) {
  background: var(--cfo-green-soft);
  color: var(--cfo-green);
}
.lui-btn-danger {
  background: var(--cfo-down);
  color: #fff;
}
.lui-btn-danger:hover:not(:disabled) {
  background: #9b3a3f;
  box-shadow: 0 4px 12px rgba(177, 65, 70, .25);
}
.lui-btn-link {
  color: var(--cfo-info);
  text-decoration: underline;
  padding: 4px 6px;
}
.lui-btn-link:hover { color: var(--cfo-green); }

/* ──────── Cards ──────── */
.lui-card {
  background: var(--cfo-surface);
  border: 1px solid var(--cfo-border);
  border-radius: var(--rad-lg);
  box-shadow: var(--sh-md);
  overflow: hidden;
}
.lui-card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--cfo-border);
  background: linear-gradient(180deg, #fff 0%, var(--cfo-surface-2) 100%);
}
.lui-card-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--cfo-text);
}
.lui-card-sub {
  margin-top: 2px;
  font-size: var(--fs-sm);
  color: var(--cfo-text-sub);
}
.lui-card-body { padding: 16px 18px; }

/* ──────── Empty state ──────── */
.lui-empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--cfo-text-dim);
  border: 1px dashed var(--cfo-border-2);
  border-radius: var(--rad-lg);
  background: linear-gradient(180deg, #fcfdff 0%, var(--cfo-bg) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.lui-empty-icon {
  font-size: 30px;
  opacity: .55;
}
.lui-empty-title {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--cfo-text-sub);
}
.lui-empty-desc {
  font-size: var(--fs-sm);
  color: var(--cfo-text-dim);
  line-height: 1.55;
}

/* ──────── Skeleton loader ──────── */
.lui-skeleton {
  display: block;
  background: linear-gradient(
    90deg,
    var(--cfo-bg) 0%,
    rgba(220, 230, 238, .5) 50%,
    var(--cfo-bg) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--rad-sm);
  animation: lui-skeleton-shine 1.5s linear infinite;
  height: 14px;
}
.lui-skeleton-block { height: 80px; border-radius: var(--rad-md); }
.lui-skeleton-circle { border-radius: 50%; aspect-ratio: 1; }
@keyframes lui-skeleton-shine {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ──────── Badges (status pills) ──────── */
.lui-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--rad-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  background: var(--cfo-bg);
  color: var(--cfo-text-sub);
  border: 1px solid var(--cfo-border);
}
.lui-badge-success { background: rgba(29,122,82,.10); color: var(--cfo-up); border-color: rgba(29,122,82,.22); }
.lui-badge-danger  { background: rgba(177,65,70,.10); color: var(--cfo-down); border-color: rgba(177,65,70,.22); }
.lui-badge-warn    { background: rgba(100,116,139,.12); color: var(--cfo-gold); border-color: rgba(100,116,139,.28); }
.lui-badge-info    { background: rgba(30,93,160,.10); color: var(--cfo-info); border-color: rgba(30,93,160,.22); }

/* ──────── Inputs / selects (base) ──────── */
.lui-input, .lui-select {
  display: inline-block;
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: var(--fs-md);
  color: var(--cfo-text);
  background: var(--cfo-surface);
  border: 1px solid var(--cfo-border-2);
  border-radius: var(--rad-md);
  transition: border-color .12s, box-shadow .12s;
}
.lui-input::placeholder { color: var(--cfo-text-dim); }
.lui-input:hover, .lui-select:hover { border-color: var(--cfo-text-sub); }
.lui-input:focus, .lui-select:focus {
  outline: none;
  border-color: var(--cfo-green);
  box-shadow: 0 0 0 3px var(--cfo-green-soft);
}
.lui-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--cfo-text-sub);
  margin-bottom: 4px;
  letter-spacing: .2px;
}
.lui-field { margin-bottom: 12px; }
.lui-help {
  margin-top: 4px;
  font-size: var(--fs-xs);
  color: var(--cfo-text-dim);
  line-height: 1.5;
}
.lui-error {
  margin-top: 4px;
  font-size: var(--fs-sm);
  color: var(--cfo-down);
  font-weight: 600;
}

/* Password show/hide */
.lui-input-group {
  position: relative;
}
.lui-input-group .lui-input { padding-right: 44px; }
.lui-input-group .lui-input-action {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--cfo-text-sub);
  font-size: 14px;
  padding: 6px 8px;
  border-radius: var(--rad-sm);
  cursor: pointer;
}
.lui-input-group .lui-input-action:hover {
  background: var(--cfo-bg);
  color: var(--cfo-text);
}

/* ──────── Toast notifications ──────── */
.lui-toast-host {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(560px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  pointer-events: none;
}
.lui-toast {
  pointer-events: auto;
  width: 100%;
  min-width: 0;
  max-width: none;
  padding: 10px 14px;
  background: var(--cfo-surface);
  border: 1px solid var(--cfo-border);
  border-left: 3px solid var(--cfo-text-sub);
  border-radius: var(--rad-md);
  box-shadow: var(--sh-lg);
  font-size: var(--fs-md);
  color: var(--cfo-text);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: lui-toast-in .25s cubic-bezier(.22,1,.36,1);
}
.lui-toast-success { border-left-color: var(--cfo-up); }
.lui-toast-danger  { border-left-color: var(--cfo-down); }
.lui-toast-warn    { border-left-color: var(--cfo-gold); }
.lui-toast-info    { border-left-color: var(--cfo-info); }
.lui-toast-icon {
  flex-shrink: 0;
  font-size: 16px;
  line-height: 1.2;
}
.lui-toast-body { flex: 1; line-height: 1.4; }
.lui-toast-title { font-weight: 700; }
.lui-toast-msg { color: var(--cfo-text-sub); font-size: var(--fs-sm); margin-top: 2px; }
.lui-toast-close {
  background: transparent;
  border: none;
  color: var(--cfo-text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.lui-toast.fade-out {
  animation: lui-toast-out .25s ease forwards;
}
@keyframes lui-toast-in {
  from { transform: translateY(-8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes lui-toast-out {
  to { transform: translateY(-8px); opacity: 0; }
}
@media (max-width: 768px) {
  .lui-toast-host {
    top: 50%;
    bottom: auto;
    left: 50%;
    right: auto;
    width: calc(100vw - 24px);
  }
  .lui-toast { max-width: none; }
}

/* ──────── Modal / dialog ──────── */
.lui-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 37, 64, .55);
  backdrop-filter: blur(2px);
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: lui-fade-in .2s ease;
}
.lui-modal {
  background: var(--cfo-surface);
  border-radius: var(--rad-lg);
  box-shadow: var(--sh-xl);
  max-width: 100%;
  width: 480px;
  max-height: 90vh;
  overflow: auto;
  animation: lui-modal-in .25s cubic-bezier(.22,1,.36,1);
}
.lui-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--cfo-border);
}
.lui-modal-title {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--cfo-text);
  margin: 0;
}
.lui-modal-close {
  background: transparent;
  border: none;
  color: var(--cfo-text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--rad-sm);
}
.lui-modal-close:hover { background: var(--cfo-bg); color: var(--cfo-text); }
.lui-modal-body { padding: 18px 20px; }
.lui-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--cfo-border);
  background: var(--cfo-surface-2);
}
@keyframes lui-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ──────── Settings modal pieces ──────── */
.lui-theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}
.lui-density-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.lui-theme-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 2px solid var(--cfo-border);
  border-radius: var(--rad-md);
  cursor: pointer;
  background: var(--cfo-surface);
  transition: border-color .15s, background .15s, box-shadow .15s;
  user-select: none;
}
.lui-theme-card:hover {
  background: var(--cfo-surface-2);
  border-color: var(--cfo-text-sub);
}
.lui-theme-card.active {
  border-color: var(--cfo-green);
  background: var(--cfo-green-soft);
  box-shadow: 0 0 0 1px var(--cfo-green);
}
.lui-theme-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.lui-theme-swatch {
  display: inline-block;
  width: 24px; height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.lui-theme-label {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--cfo-text);
}
.lui-density-icon {
  font-size: 22px;
  flex-shrink: 0;
}

/* ──────── Drawer secondary action ──────── */
.lui-drawer-action {
  flex: 0 0 auto;
  padding: 9px 12px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.20);
  border-radius: 8px;
  color: rgba(255,255,255,.92);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s;
}
.lui-drawer-action:hover {
  background: rgba(255,255,255,.18);
  border-color: rgba(255,255,255,.32);
}

/* ──────── Keyboard shortcut help ──────── */
.lui-shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lui-shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--cfo-border);
  font-size: var(--fs-md);
}
.lui-shortcut-row:last-child { border-bottom: none; }
.lui-shortcut-row span { color: var(--cfo-text-sub); }
.lui-kbd {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
  background: var(--cfo-surface);
  color: var(--cfo-text);
  border: 1px solid var(--cfo-border-2);
  border-bottom-width: 2px;
  border-radius: var(--rad-sm);
  min-width: 36px;
  justify-content: center;
}
.lui-kbd-sm { padding: 1px 6px; font-size: 10px; min-width: 28px; }

/* ──────── Command Palette (cmd+K) ──────── */
.lui-cmdk-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--cfo-border);
}
.lui-cmdk-input {
  flex: 1;
  border: none;
  outline: none;
  font: inherit;
  font-size: 16px;
  background: transparent;
  color: var(--cfo-text);
}
.lui-cmdk-input::placeholder { color: var(--cfo-text-dim); }
.lui-cmdk-list {
  max-height: 50vh;
  overflow-y: auto;
  padding: 8px;
}
.lui-cmdk-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--rad-md);
  text-align: left;
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--cfo-text);
  cursor: pointer;
  transition: background .12s;
}
.lui-cmdk-item:hover:not(.disabled),
.lui-cmdk-item.active:not(.disabled) {
  background: var(--cfo-green-soft);
  color: var(--cfo-green);
}
.lui-cmdk-item.disabled {
  color: var(--cfo-text-dim);
  cursor: not-allowed;
}

/* ──────── Density: compact mode ──────── */
body.lui-density-compact .lui-card-body { padding: 12px 14px; }
body.lui-density-compact .lui-card-head { padding: 10px 14px; }
body.lui-density-compact .filter-toolbar { padding: 6px 10px; gap: 5px 8px; }
body.lui-density-compact table { font-size: 11px; }
body.lui-density-compact table th,
body.lui-density-compact table td { padding: 3px 6px; }
body.lui-density-compact .kpi-grid { gap: 6px; }
body.lui-density-compact .lui-btn { padding: 6px 11px; font-size: var(--fs-base); }

/* ──────── Print (tables) ──────── */
@media print {
  .topbar, .lui-mobile-trigger, .lui-drawer, .lui-drawer-backdrop,
  .lui-toast-host, .filter-toolbar, .ft-actions { display: none !important; }
  body { background: #fff !important; }
  .lui-card, table { box-shadow: none !important; border-color: #ccc !important; }
}

/* ══════════════════════════════════════════════════════════
   🌙 DARK MODE — 全域覆蓋層
   各 dashboard / admin 頁面有大量 inline <style> 寫死 #fff、#1a2635 等,
   這層強制把常見的 light surface / text / border 翻成深色 token。
   有些情況用 !important 是無奈但必要 — inline page styles 沒有別的 hook。
   ══════════════════════════════════════════════════════════ */

/* Step 1: alias 各 dashboard 自定義的 local CSS vars 到深色 palette。
   attr selector specificity (0,1,1) > 普通 :root (0,0,1), 所以會勝出。 */
:root[data-cfo-mode="dark"] {
  --bg:               #0f141a;
  --card:             #1a232e;
  --ink:              #e8eef5;
  --text:             #e8eef5;
  --sub:              #a3b3c4;
  --text-sub:         #a3b3c4;
  --muted:            #6f8094;
  --text-dim:         #6f8094;
  --border:           #2c3845;
  --border-md:        #3a4856;
  --border-strong:    #455365;
  --line:             #2c3845;
  --line-strong:      #3a4856;
  --green:            #2DD4BF;
  --green-lt:         #62d3ad;
  --green-dim:        rgba(77,192,151,.16);
  --green-line:       rgba(77,192,151,.32);
  --header-a:         #0a0e14;
  --header-b:         #141b24;
  --gold:             #94A3B8;
  --gold-lt:          #e3c66e;
  --gold-dim:         rgba(148,163,184,.14);
  --gold-line:        rgba(148,163,184,.32);
  --blue:             #5a9bf0;
  --red:              #e07a82;
  --err:              #e07a82;
  --ok:               #2DD4BF;
  --warn:             #e3b454;
  --shadow:           0 2px 8px rgba(0,0,0,.40);
  --shadow-lg:        0 6px 22px rgba(0,0,0,.50);
  --mtd-color:        #62d3ad;
  --daily-color:      #5a9bf0;
}
/* midnight 主題微調 — 用更深的綠 */
:root[data-cfo-theme="midnight"] {
  --bg:               #0a1a14;
  --card:             #13261f;
  --ink:              #e6f0ea;
  --text:             #e6f0ea;
  --header-a:         #06120d;
  --header-b:         #0e1d16;
}
/* mono (高對比) — 純黑白 + 強邊 */
:root[data-cfo-theme="mono"] {
  --bg:               #ffffff;
  --card:             #ffffff;
  --ink:              #000000;
  --text:             #000000;
  --sub:              #222222;
  --muted:            #555555;
  --border:           #000000;
  --border-md:        #000000;
  --line:             #000000;
  --green:            #000000;
  --header-a:         #000000;
  --header-b:         #000000;
}


:root[data-cfo-mode="dark"] body {
  background: var(--cfo-bg) !important;
  color: var(--cfo-text) !important;
}

/* 頁面容器 / shell — 強制深底 */
:root[data-cfo-mode="dark"] .page,
:root[data-cfo-mode="dark"] .page-shell,
:root[data-cfo-mode="dark"] .page-content,
:root[data-cfo-mode="dark"] .container,
:root[data-cfo-mode="dark"] .layout,
:root[data-cfo-mode="dark"] .ad-main,
:root[data-cfo-mode="dark"] main {
  background: var(--cfo-bg) !important;
  color: var(--cfo-text) !important;
}

/* 卡片 / 面板 / 區塊 — 統一深色 surface */
:root[data-cfo-mode="dark"] .card,
:root[data-cfo-mode="dark"] .panel,
:root[data-cfo-mode="dark"] .lui-card,
:root[data-cfo-mode="dark"] .ad-table-wrap,
:root[data-cfo-mode="dark"] .ad-kpi,
:root[data-cfo-mode="dark"] .ad-link-card,
:root[data-cfo-mode="dark"] .stat-card,
:root[data-cfo-mode="dark"] .metric-card,
:root[data-cfo-mode="dark"] .kpi-card,
:root[data-cfo-mode="dark"] .kpi-block,
:root[data-cfo-mode="dark"] .store-card,
:root[data-cfo-mode="dark"] .mapping-card,
:root[data-cfo-mode="dark"] .period-box,
:root[data-cfo-mode="dark"] .result-item,
:root[data-cfo-mode="dark"] .summary-card,
:root[data-cfo-mode="dark"] .section-card,
:root[data-cfo-mode="dark"] .panel-card,
:root[data-cfo-mode="dark"] .info-card,
:root[data-cfo-mode="dark"] .toolbar,
:root[data-cfo-mode="dark"] .ops-data-controls {
  background: var(--cfo-surface) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.40) !important;
}
:root[data-cfo-mode="dark"] .card-head,
:root[data-cfo-mode="dark"] .panel-head,
:root[data-cfo-mode="dark"] .lui-card-head,
:root[data-cfo-mode="dark"] .ad-table-head {
  background: linear-gradient(180deg, var(--cfo-surface), var(--cfo-surface-2)) !important;
  border-color: var(--cfo-border) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] .card-body,
:root[data-cfo-mode="dark"] .lui-card-body { color: var(--cfo-text); }
:root[data-cfo-mode="dark"] .card-head h2,
:root[data-cfo-mode="dark"] .card-head h3,
:root[data-cfo-mode="dark"] .ad-page-title,
:root[data-cfo-mode="dark"] h1,
:root[data-cfo-mode="dark"] h2,
:root[data-cfo-mode="dark"] h3,
:root[data-cfo-mode="dark"] h4 { color: var(--cfo-text) !important; }
:root[data-cfo-mode="dark"] .card-head p,
:root[data-cfo-mode="dark"] .ad-page-sub,
:root[data-cfo-mode="dark"] .helper,
:root[data-cfo-mode="dark"] .mini,
:root[data-cfo-mode="dark"] .muted,
:root[data-cfo-mode="dark"] .lui-help { color: var(--cfo-text-sub) !important; }

/* 表格 — 深底 + 亮文字 */
:root[data-cfo-mode="dark"] table,
:root[data-cfo-mode="dark"] thead,
:root[data-cfo-mode="dark"] tbody {
  background: transparent !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] thead th {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text-sub) !important;
  border-color: var(--cfo-border) !important;
}
:root[data-cfo-mode="dark"] tbody tr { border-color: var(--cfo-border) !important; }
:root[data-cfo-mode="dark"] tbody tr:hover { background: rgba(255,255,255,.03) !important; }
:root[data-cfo-mode="dark"] tbody tr.modified { background: rgba(100,116,139,.10) !important; }
:root[data-cfo-mode="dark"] td,
:root[data-cfo-mode="dark"] th { border-color: var(--cfo-border) !important; }
:root[data-cfo-mode="dark"] td.acc-no,
:root[data-cfo-mode="dark"] td.mono,
:root[data-cfo-mode="dark"] .mono { color: var(--cfo-text-sub) !important; }

/* Inputs / selects / textareas */
:root[data-cfo-mode="dark"] input,
:root[data-cfo-mode="dark"] select,
:root[data-cfo-mode="dark"] textarea,
:root[data-cfo-mode="dark"] .lui-input,
:root[data-cfo-mode="dark"] .lui-select,
:root[data-cfo-mode="dark"] .filter-input,
:root[data-cfo-mode="dark"] .field input,
:root[data-cfo-mode="dark"] .field select {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
}
:root[data-cfo-mode="dark"] input::placeholder,
:root[data-cfo-mode="dark"] textarea::placeholder { color: var(--cfo-text-dim) !important; }
:root[data-cfo-mode="dark"] input:focus,
:root[data-cfo-mode="dark"] select:focus,
:root[data-cfo-mode="dark"] textarea:focus {
  border-color: var(--cfo-green) !important;
  box-shadow: 0 0 0 3px var(--cfo-green-soft) !important;
  background: var(--cfo-surface) !important;
}

/* 按鈕 — 二級/ghost 預設深底 */
:root[data-cfo-mode="dark"] .lui-btn-secondary,
:root[data-cfo-mode="dark"] button.btn:not(.btn-primary):not(.btn-danger),
:root[data-cfo-mode="dark"] .ghost-btn {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
}
:root[data-cfo-mode="dark"] .lui-btn-secondary:hover,
:root[data-cfo-mode="dark"] button.btn:not(.btn-primary):not(.btn-danger):hover,
:root[data-cfo-mode="dark"] .ghost-btn:hover {
  background: var(--cfo-border) !important;
  border-color: var(--cfo-border-2) !important;
}
:root[data-cfo-mode="dark"] .lui-btn-ghost { color: var(--cfo-text-sub) !important; }
:root[data-cfo-mode="dark"] .lui-btn-ghost:hover {
  background: var(--cfo-green-soft) !important;
  color: var(--cfo-green) !important;
}

/* Modal / overlay */
:root[data-cfo-mode="dark"] .lui-modal,
:root[data-cfo-mode="dark"] .lui-modal-head,
:root[data-cfo-mode="dark"] .lui-modal-foot,
:root[data-cfo-mode="dark"] .lui-modal-body {
  background: var(--cfo-surface) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
}
:root[data-cfo-mode="dark"] .lui-modal-backdrop { background: rgba(0,0,0,.60); }
:root[data-cfo-mode="dark"] .lui-modal-title { color: var(--cfo-text) !important; }
:root[data-cfo-mode="dark"] .lui-modal-close { color: var(--cfo-text-sub) !important; }
:root[data-cfo-mode="dark"] .lui-modal-close:hover { background: var(--cfo-surface-2) !important; }

/* Toast — 加深底 */
:root[data-cfo-mode="dark"] .lui-toast {
  background: var(--cfo-surface) !important;
  color: var(--cfo-text) !important;
  border: 1px solid var(--cfo-border);
}

/* Badge / pill / chip — 加深底 */
:root[data-cfo-mode="dark"] .lui-badge,
:root[data-cfo-mode="dark"] .badge,
:root[data-cfo-mode="dark"] .chip,
:root[data-cfo-mode="dark"] .pill,
:root[data-cfo-mode="dark"] .file-pill,
:root[data-cfo-mode="dark"] .file-chip {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text-sub) !important;
  border-color: var(--cfo-border) !important;
}

/* Status / scope-tabs (財務後台/科目對照常用) */
:root[data-cfo-mode="dark"] .status { background: var(--cfo-surface-2) !important; color: var(--cfo-text-sub) !important; }
:root[data-cfo-mode="dark"] .status.ok { background: var(--cfo-green-soft) !important; color: var(--cfo-green) !important; }
:root[data-cfo-mode="dark"] .status.error { background: rgba(224,122,130,.16) !important; color: var(--cfo-down) !important; }
:root[data-cfo-mode="dark"] .scope-tab { color: var(--cfo-text-sub) !important; }
:root[data-cfo-mode="dark"] .scope-tab.active { color: var(--cfo-green) !important; background: var(--cfo-green-soft) !important; }

/* Sub-card 變淡的部分 (admin sub-pages 常用 #f7f9fb thead 等) */
:root[data-cfo-mode="dark"] [style*="background:#f"],
:root[data-cfo-mode="dark"] [style*="background: #f"],
:root[data-cfo-mode="dark"] [style*="background:#e"],
:root[data-cfo-mode="dark"] [style*="background: #e"] {
  /* 這些都是淺色 hex inline style — 強制蓋掉 */
  background: var(--cfo-surface-2) !important;
}

/* code / pre — 深底 */
:root[data-cfo-mode="dark"] code,
:root[data-cfo-mode="dark"] pre,
:root[data-cfo-mode="dark"] kbd,
:root[data-cfo-mode="dark"] .lui-kbd {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
}

/* ══ Finance-dashboard PL 表 row 樣式 (dark mode) ══
   核心問題:table.table-mgt 用 nth-child(odd/even) 條紋寫死 #ffffff / #f3f9f4,
   蓋掉個別 row class 的 bg。dark mode 必須覆蓋 nth-child 本身。 */
:root[data-cfo-mode="dark"] table.table-mgt tbody tr:nth-child(odd) td,
:root[data-cfo-mode="dark"] table.table-mgt tbody tr:nth-child(odd) td:first-child {
  background: var(--cfo-surface) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] table.table-mgt tbody tr:nth-child(even) td,
:root[data-cfo-mode="dark"] table.table-mgt tbody tr:nth-child(even) td:first-child {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] table.table-mgt tbody tr td {
  border-bottom-color: var(--cfo-border) !important;
}
/* row-total / row-net / row-highlight / row-section 在 MGT 的色相覆蓋
   (因 background 已 inherit nth-child stripe, 只需翻文字色) */
:root[data-cfo-mode="dark"] table.table-mgt tr.row-section td,
:root[data-cfo-mode="dark"] table.table-mgt tr.row-total td,
:root[data-cfo-mode="dark"] table.table-mgt tr.row-net td,
:root[data-cfo-mode="dark"] table.table-mgt tr.row-highlight td,
:root[data-cfo-mode="dark"] table.table-mgt tr[data-row-level="0"] td {
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] table.table-mgt tr.row-adj td {
  background: rgba(148,163,184,.06) !important;
  color: #94A3B8 !important;
}

/* ══ 統一所有 level-0 / 強調 row 字級 + 字重 (像 收入/費用 那樣) ══
   這是 light + dark 都套用 — user 要求字體一致 */
table.table-mgt tr.row-section td,
table.table-mgt tr.row-total td,
table.table-mgt tr.row-net td,
table.table-mgt tr.row-highlight td,
table.table-mgt tr[data-row-level="0"] td {
  font-size: 14px !important;
  font-weight: 700 !important;
}
/* 但避開特殊明細列(如金額顯示),只把第一格(科目名)拉粗 */
table.table-mgt tr[data-row-level="0"] td:first-child {
  font-weight: 700 !important;
}
/* level=1 子行 — 一般粗細,字級稍小 */
table.table-mgt tr[data-row-level="1"] td {
  font-size: 13px !important;
  font-weight: 500 !important;
}
/* level=2/3 細項 — 最小,常規 */
table.table-mgt tr[data-row-level="2"] td,
table.table-mgt tr[data-row-level="3"] td {
  font-size: 12.5px !important;
  font-weight: 500 !important;
}

/* ══ 健康色 — dark mode 下亮版本(原色 #0d5c57/#64748B/#8b3b46 太暗) ══
   inline style 寫死要用 !important 才能蓋 */
:root[data-cfo-mode="dark"] .jpm-kpi[data-health="good"] .kpi-top-strip,
:root[data-cfo-mode="dark"] .jpm-kpi[data-health="good"] .kpi-health-dot {
  background: #2DD4BF !important;
  box-shadow: 0 0 0 2px var(--cfo-surface), 0 0 0 4px rgba(77,192,151,.45) !important;
}
:root[data-cfo-mode="dark"] .jpm-kpi[data-health="warn"] .kpi-top-strip,
:root[data-cfo-mode="dark"] .jpm-kpi[data-health="warn"] .kpi-health-dot {
  background: #e3b454 !important;
  box-shadow: 0 0 0 2px var(--cfo-surface), 0 0 0 4px rgba(227,180,84,.45) !important;
}
:root[data-cfo-mode="dark"] .jpm-kpi[data-health="bad"] .kpi-top-strip,
:root[data-cfo-mode="dark"] .jpm-kpi[data-health="bad"] .kpi-health-dot {
  background: #e07a82 !important;
  box-shadow: 0 0 0 2px var(--cfo-surface), 0 0 0 4px rgba(224,122,130,.45) !important;
}
:root[data-cfo-mode="dark"] .jpm-kpi[data-health="neutral"] .kpi-top-strip,
:root[data-cfo-mode="dark"] .jpm-kpi[data-health="neutral"] .kpi-health-dot {
  background: var(--cfo-text-dim) !important;
  box-shadow: 0 0 0 2px var(--cfo-surface), 0 0 0 4px rgba(163,179,196,.30) !important;
}
/* 加強整張卡的左邊條反光感 (頂部 strip 已是健康色,這裡加陰影使色更明顯) */
:root[data-cfo-mode="dark"] .jpm-kpi { position: relative; }
:root[data-cfo-mode="dark"] .jpm-kpi[data-health]:not([data-health="neutral"]) {
  border-color: var(--cfo-border-2) !important;
}

/* 一般非 mgt 表的 row 樣式 — 套基本 surface */
:root[data-cfo-mode="dark"] tr.row-section td:not(table.table-mgt tr.row-section td) {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] tr.row-section td:first-child,
:root[data-cfo-mode="dark"] table.table-mgt tr.row-section td:first-child {
  background: linear-gradient(90deg, rgba(77,192,151,.10), var(--cfo-surface-2)) !important;
  border-left-color: var(--cfo-green) !important;
}
:root[data-cfo-mode="dark"] tr.row-total td {
  background: linear-gradient(90deg, rgba(90,155,240,.10), var(--cfo-surface-2)) !important;
  color: #b3d4ff !important;
}
:root[data-cfo-mode="dark"] tr.row-total td:first-child {
  background: linear-gradient(90deg, rgba(90,155,240,.18), rgba(90,155,240,.04)) !important;
  border-left-color: #5a9bf0 !important;
}
:root[data-cfo-mode="dark"] tr.row-net td {
  background: linear-gradient(90deg, rgba(148,163,184,.12), var(--cfo-surface-2)) !important;
  color: #e3c66e !important;
}
:root[data-cfo-mode="dark"] tr.row-net td:first-child {
  background: linear-gradient(90deg, rgba(148,163,184,.20), rgba(148,163,184,.05)) !important;
  border-left-color: #94A3B8 !important;
}
:root[data-cfo-mode="dark"] tr.row-highlight td {
  background: rgba(77,192,151,.08) !important;
  color: #62d3ad !important;
}
:root[data-cfo-mode="dark"] tr.row-highlight td:first-child {
  border-left-color: var(--cfo-green) !important;
}
:root[data-cfo-mode="dark"] tr.row-child td {
  background: var(--cfo-surface) !important;
}
:root[data-cfo-mode="dark"] tr.row-detail.row-child:hover td {
  box-shadow: inset 0 0 0 9999px rgba(77,192,151,.06) !important;
}
/* sticky 第一欄 (科目名稱) 深底 */
:root[data-cfo-mode="dark"] table th:first-child,
:root[data-cfo-mode="dark"] table td:first-child {
  background: var(--cfo-surface) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] table.table-mgt th:first-child,
:root[data-cfo-mode="dark"] table thead th:first-child { background: var(--cfo-surface-2) !important; }

/* ══ PL 科目字體大小統一 (覆蓋原本 row-section 14.5px 跳級的不一致) ══ */
table.table-mgt tr.row-section td,
table.table-mgt tr.row-detail td,
table.table-mgt tr.row-total td,
table.table-mgt tr.row-net td,
table.table-mgt tr.row-highlight td,
table.table-mgt tr.row-child td {
  font-size: 13px !important;
}
table.table-mgt tr.row-section td { font-weight: 700 !important; }
table.table-mgt tr.row-detail td  { font-weight: 500 !important; }
table.table-mgt tr.row-total td,
table.table-mgt tr.row-net td,
table.table-mgt tr.row-highlight td { font-weight: 700 !important; }
/* level 0 群組標題 (營運指標 / 損益) 字稍大 */
table.table-mgt tr.row-section[data-row-level="0"] td { font-size: 14px !important; }

/* ══ 彙總分析 — KPI 卡 .jpm-kpi (dark mode) ══ */
:root[data-cfo-mode="dark"] .jpm-kpi {
  background: var(--cfo-surface) !important;
  border-color: var(--cfo-border) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.40) !important;
}
:root[data-cfo-mode="dark"] .jpm-kpi .kpi-label { color: var(--cfo-text-sub) !important; }
:root[data-cfo-mode="dark"] .jpm-kpi .kpi-value { color: var(--cfo-text) !important; }
:root[data-cfo-mode="dark"] .jpm-kpi .kpi-extra { color: var(--cfo-text-dim) !important; }
:root[data-cfo-mode="dark"] .jpm-kpi .kpi-delta-row { border-top-color: var(--cfo-border) !important; }
:root[data-cfo-mode="dark"] .jpm-kpi .kpi-delta-empty { color: var(--cfo-text-dim) !important; }
/* 健康 dot 的白色 ring 改成 surface */
:root[data-cfo-mode="dark"] .jpm-kpi .kpi-health-dot {
  box-shadow: 0 0 0 2px var(--cfo-surface), 0 0 0 3px currentColor !important;
}

/* ══ 「分析摘要」內聯 callout 卡 (dark mode) ══ */
:root[data-cfo-mode="dark"] [style*="background:#f8fafb"],
:root[data-cfo-mode="dark"] [style*="background: #f8fafb"],
:root[data-cfo-mode="dark"] [style*="background:#f7f9fc"],
:root[data-cfo-mode="dark"] [style*="background: #f7f9fc"],
:root[data-cfo-mode="dark"] [style*="background:#fafcff"],
:root[data-cfo-mode="dark"] [style*="background: #fafcff"] {
  background: var(--cfo-surface-2) !important;
  border-color: var(--cfo-border) !important;
  color: var(--cfo-text) !important;
}
/* 分析摘要 等小卡內的 b 標題 / 死寫 #1a2635 / #0b2540 / #163c68 / #6f5a16 / #071E41 / #0f1b2d / #304055 / #5a7087 / #3a4a5c 文字 */
:root[data-cfo-mode="dark"] [style*="color:#1a2635"],
:root[data-cfo-mode="dark"] [style*="color: #1a2635"],
:root[data-cfo-mode="dark"] [style*="color:#0b2540"],
:root[data-cfo-mode="dark"] [style*="color: #0b2540"],
:root[data-cfo-mode="dark"] [style*="color:#163c68"],
:root[data-cfo-mode="dark"] [style*="color: #163c68"],
:root[data-cfo-mode="dark"] [style*="color:#6f5a16"],
:root[data-cfo-mode="dark"] [style*="color: #6f5a16"],
:root[data-cfo-mode="dark"] [style*="color:#071E41"],
:root[data-cfo-mode="dark"] [style*="color: #071E41"],
:root[data-cfo-mode="dark"] [style*="color:#0f1b2d"],
:root[data-cfo-mode="dark"] [style*="color: #0f1b2d"],
:root[data-cfo-mode="dark"] [style*="color:#304055"],
:root[data-cfo-mode="dark"] [style*="color: #304055"],
:root[data-cfo-mode="dark"] [style*="color:#3a4a5c"],
:root[data-cfo-mode="dark"] [style*="color: #3a4a5c"],
:root[data-cfo-mode="dark"] [style*="color:#5a7087"],
:root[data-cfo-mode="dark"] [style*="color: #5a7087"],
:root[data-cfo-mode="dark"] [style*="color:#2a3f55"],
:root[data-cfo-mode="dark"] [style*="color: #2a3f55"] {
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] [style*="color:#c0cbd6"],
:root[data-cfo-mode="dark"] [style*="color: #c0cbd6"] { color: var(--cfo-text-dim) !important; }

/* secHdr (彙總分析的 1/2/3/4 圓圈標題) 背景色 */
:root[data-cfo-mode="dark"] h3 [style*="background:var(--green)"],
:root[data-cfo-mode="dark"] h3 [style*="background: var(--green)"] {
  background: var(--cfo-green) !important;
  color: #0f141a !important;
}

/* 卡片內金色 tag (含税/不含税) — dark 增加亮度 */
:root[data-cfo-mode="dark"] [style*="background:rgba(20,184,166"],
:root[data-cfo-mode="dark"] [style*="background: rgba(20,184,166"] {
  background: rgba(148,163,184,.20) !important;
  color: #e3c66e !important;
}

/* ══ 按鈕 hover 邊框動畫加強 (dark mode) ══ */
:root[data-cfo-mode="dark"] button:hover:not(:disabled):not([class*="lui-btn-primary"]):not([class*="lui-btn-danger"]):not(.btn-primary):not(.btn-danger):not(.solid-btn):not(.lap-top-icon-btn):not(.lap-side-link):not(.ad-subnav-link),
:root[data-cfo-mode="dark"] .lui-btn-secondary:hover:not(:disabled),
:root[data-cfo-mode="dark"] .lui-btn-ghost:hover:not(:disabled),
:root[data-cfo-mode="dark"] .ghost-btn:hover:not(:disabled),
:root[data-cfo-mode="dark"] .btn:hover:not(.btn-primary):not(.btn-danger):not(:disabled) {
  border-color: var(--cfo-green) !important;
  background: rgba(77,192,151,.10) !important;
  box-shadow: 0 0 0 1px rgba(77,192,151,.32), 0 2px 8px rgba(77,192,151,.16) !important;
  color: var(--cfo-green) !important;
  transition: all .18s ease !important;
}

/* Persona card / perm group / 灰底分區 */
:root[data-cfo-mode="dark"] .ad-perm-group,
:root[data-cfo-mode="dark"] .ad-persona,
:root[data-cfo-mode="dark"] .up-tile {
  background: var(--cfo-surface-2) !important;
  border-color: var(--cfo-border) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] .up-tile-file {
  background: var(--cfo-surface) !important;
  border-color: var(--cfo-border-2) !important;
  color: var(--cfo-text) !important;
}

/* 分隔線 */
:root[data-cfo-mode="dark"] hr { border-color: var(--cfo-border) !important; }

/* Settings modal — theme card / density card */
:root[data-cfo-mode="dark"] .lui-theme-card {
  background: var(--cfo-surface-2) !important;
  border-color: var(--cfo-border) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] .lui-theme-card.active {
  border-color: var(--cfo-green) !important;
  background: var(--cfo-green-soft) !important;
}

/* Drawer (mobile menu) */
:root[data-cfo-mode="dark"] .lui-drawer {
  /* drawer 本來就是深色, 不用蓋 */
}

/* Iframe inline pages — 父頁是 dark, iframe 內就交給該頁自己處理 (透過 ?embed=1 + sessionStorage 同步)
   目前 iframe 不會自動繼承 dark mode — 已知限制 */

/* ══════════════════════════════════════════════════════════
   🌙 DARK MODE — 深度 sweep (處理各 dashboard 寫死的 #fff)
   wildcard class selector + 元件型 selector 同時用,確保覆蓋
   ══════════════════════════════════════════════════════════ */

/* Step 2 — class wildcard 通殺常見命名 */
:root[data-cfo-mode="dark"] [class*="-card"],
:root[data-cfo-mode="dark"] [class*="card-"],
:root[data-cfo-mode="dark"] [class*="-block"],
:root[data-cfo-mode="dark"] [class*="-panel"],
:root[data-cfo-mode="dark"] [class*="-table"],
:root[data-cfo-mode="dark"] [class*="-cell"],
:root[data-cfo-mode="dark"] [class*="-tile"],
:root[data-cfo-mode="dark"] [class*="-box"],
:root[data-cfo-mode="dark"] [class*="-frame"],
:root[data-cfo-mode="dark"] [class*="-wrap"]:not([class*="iframe"]):not(.lap-side):not(.las-side),
:root[data-cfo-mode="dark"] [class*="hero"],
:root[data-cfo-mode="dark"] [class*="metric"],
:root[data-cfo-mode="dark"] [class*="kpi"],
:root[data-cfo-mode="dark"] [class*="summary"],
:root[data-cfo-mode="dark"] [class*="overview"],
:root[data-cfo-mode="dark"] [class*="store"],
:root[data-cfo-mode="dark"] [class*="branch"],
:root[data-cfo-mode="dark"] [class*="weather"],
:root[data-cfo-mode="dark"] [class*="executive"],
:root[data-cfo-mode="dark"] [class*="approval"],
:root[data-cfo-mode="dark"] [class*="luohu"],
:root[data-cfo-mode="dark"] [class*="cctv"],
:root[data-cfo-mode="dark"] [class*="chart"],
:root[data-cfo-mode="dark"] [class*="trend"],
:root[data-cfo-mode="dark"] [class*="compare"],
:root[data-cfo-mode="dark"] [class*="summary"],
:root[data-cfo-mode="dark"] [class*="forecast"],
:root[data-cfo-mode="dark"] [class*="budget"],
:root[data-cfo-mode="dark"] [class*="conv"],
:root[data-cfo-mode="dark"] [class*="payment"],
:root[data-cfo-mode="dark"] [class*="session"],
:root[data-cfo-mode="dark"] [class*="dept"],
:root[data-cfo-mode="dark"] [class*="category"],
:root[data-cfo-mode="dark"] [class*="filter"],
:root[data-cfo-mode="dark"] [class*="report"],
:root[data-cfo-mode="dark"] [class*="period"],
:root[data-cfo-mode="dark"] [class*="scope"],
:root[data-cfo-mode="dark"] [class*="entry"]:not(input) {
  background: var(--cfo-surface) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
}

/* Tab bars — 明確處理 store-tabs / ss-tabs / scope-tabs / period-tabs / report-tabs */
:root[data-cfo-mode="dark"] .store-tabs,
:root[data-cfo-mode="dark"] .ss-tabs,
:root[data-cfo-mode="dark"] .scope-tabs,
:root[data-cfo-mode="dark"] .period-tabs,
:root[data-cfo-mode="dark"] .report-tabs,
:root[data-cfo-mode="dark"] [class*="-tabs"],
:root[data-cfo-mode="dark"] .tab-bar,
:root[data-cfo-mode="dark"] #storeTabBar {
  background: var(--cfo-surface) !important;
  border-color: var(--cfo-border) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] .store-tab,
:root[data-cfo-mode="dark"] .ss-tab,
:root[data-cfo-mode="dark"] [class*="-tab"]:not([class*="-tabs"]) {
  background: transparent !important;
  color: var(--cfo-text-sub) !important;
  border-color: var(--cfo-border) !important;
}
:root[data-cfo-mode="dark"] .store-tab:hover,
:root[data-cfo-mode="dark"] .ss-tab:hover {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] .store-tab.active,
:root[data-cfo-mode="dark"] .ss-tab.active,
:root[data-cfo-mode="dark"] [class*="-tab"].active:not([class*="-tabs"]) {
  background: var(--cfo-green-soft) !important;
  color: var(--cfo-green) !important;
  border-color: var(--cfo-green) !important;
}

/* 寫死的 white gradient 分區頭 (.cctv-head, .chart-head, .card-head 等) */
:root[data-cfo-mode="dark"] [style*="linear-gradient"][style*="#fff"],
:root[data-cfo-mode="dark"] [style*="linear-gradient"][style*="#FFF"],
:root[data-cfo-mode="dark"] [style*="linear-gradient"][style*="#f8fbff"],
:root[data-cfo-mode="dark"] [style*="linear-gradient"][style*="#fbfcfe"] {
  background: var(--cfo-surface-2) !important;
}
/* CCTV / chart head 等 stylesheet-level 漸層 */
:root[data-cfo-mode="dark"] .cctv-head,
:root[data-cfo-mode="dark"] .cctv-frame-wrap,
:root[data-cfo-mode="dark"] .weather-hero-card,
:root[data-cfo-mode="dark"] .hero-card,
:root[data-cfo-mode="dark"] .executive-date-card,
:root[data-cfo-mode="dark"] .store-date-card,
:root[data-cfo-mode="dark"] .table-card,
:root[data-cfo-mode="dark"] .compare-card,
:root[data-cfo-mode="dark"] .chart-card,
:root[data-cfo-mode="dark"] .chart-toolbar,
:root[data-cfo-mode="dark"] .metric-toolbar,
:root[data-cfo-mode="dark"] .diff-toolbar,
:root[data-cfo-mode="dark"] .conv-card,
:root[data-cfo-mode="dark"] .conv-table,
:root[data-cfo-mode="dark"] .calc-card {
  background: var(--cfo-surface) !important;
  border-color: var(--cfo-border) !important;
  color: var(--cfo-text) !important;
}
:root[data-cfo-mode="dark"] .cctv-head {
  background: linear-gradient(180deg, var(--cfo-surface), var(--cfo-surface-2)) !important;
}
:root[data-cfo-mode="dark"] .cctv-frame-wrap {
  background: #000 !important;  /* 監控畫面要黑黑 */
}

/* Finance dashboard 特定 */
:root[data-cfo-mode="dark"] .pl-table,
:root[data-cfo-mode="dark"] .bs-table,
:root[data-cfo-mode="dark"] .expense-table,
:root[data-cfo-mode="dark"] .payroll-table,
:root[data-cfo-mode="dark"] .mgt-table,
:root[data-cfo-mode="dark"] .summary-table,
:root[data-cfo-mode="dark"] .pl-row,
:root[data-cfo-mode="dark"] .pl-section,
:root[data-cfo-mode="dark"] .bs-section,
:root[data-cfo-mode="dark"] .finance-section,
:root[data-cfo-mode="dark"] .acc-row,
:root[data-cfo-mode="dark"] .config-section,
:root[data-cfo-mode="dark"] .filter-bar,
:root[data-cfo-mode="dark"] .filter-toolbar,
:root[data-cfo-mode="dark"] .ft-actions,
:root[data-cfo-mode="dark"] .toolbar-row,
:root[data-cfo-mode="dark"] .mgt-summary,
:root[data-cfo-mode="dark"] .mgt-detail,
:root[data-cfo-mode="dark"] .mgt-cell,
:root[data-cfo-mode="dark"] .pl-cell {
  background: var(--cfo-surface) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
}

/* 任何 inline style 含 #fff/#FFF 的 background — 直接強制蓋 */
:root[data-cfo-mode="dark"] [style*="background:#fff"],
:root[data-cfo-mode="dark"] [style*="background: #fff"],
:root[data-cfo-mode="dark"] [style*="background-color:#fff"],
:root[data-cfo-mode="dark"] [style*="background-color: #fff"],
:root[data-cfo-mode="dark"] [style*="background:white"],
:root[data-cfo-mode="dark"] [style*="background: white"] {
  background: var(--cfo-surface) !important;
}

/* 任何元件,如果是「直接 hex 寫的暖白系列」 */
:root[data-cfo-mode="dark"] [style*="#ffffff"],
:root[data-cfo-mode="dark"] [style*="#FFFFFF"],
:root[data-cfo-mode="dark"] [style*="#fdfdfd"],
:root[data-cfo-mode="dark"] [style*="#fbfcfe"],
:root[data-cfo-mode="dark"] [style*="#fafafa"] {
  background: var(--cfo-surface) !important;
}

/* button 預設淺底 (各 dashboard 的 toolbar 按鈕) — 維持 hover 可見 */
:root[data-cfo-mode="dark"] button:not([class*="lui-btn"]):not([class*="las-"]):not([class*="lap-"]):not(.btn-primary):not(.btn-danger):not(.solid-btn):not(.danger-btn):not(.lat-tab):not(.ad-pill):not(.ad-subnav-link) {
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
}

/* 日期選擇器 / select / native input — webkit 樣式不容易蓋,但盡量 */
:root[data-cfo-mode="dark"] input[type="date"],
:root[data-cfo-mode="dark"] input[type="month"],
:root[data-cfo-mode="dark"] input[type="number"],
:root[data-cfo-mode="dark"] input[type="text"],
:root[data-cfo-mode="dark"] input[type="search"] {
  color-scheme: dark;
  background: var(--cfo-surface-2) !important;
  color: var(--cfo-text) !important;
  border-color: var(--cfo-border) !important;
}

/* 強制所有 hover 行為加深一點 */
:root[data-cfo-mode="dark"] [class*="-card"]:hover,
:root[data-cfo-mode="dark"] [class*="-tile"]:hover,
:root[data-cfo-mode="dark"] [class*="-block"]:hover {
  background: var(--cfo-surface-2) !important;
}

/* 文字小提示 */
:root[data-cfo-mode="dark"] .text-muted,
:root[data-cfo-mode="dark"] .small-muted,
:root[data-cfo-mode="dark"] .hint,
:root[data-cfo-mode="dark"] .desc { color: var(--cfo-text-sub) !important; }

/* 凡是設了 color: #1a... / #102... 的死寫文字一律拉成亮色 */
:root[data-cfo-mode="dark"] [style*="color:#1a"],
:root[data-cfo-mode="dark"] [style*="color: #1a"],
:root[data-cfo-mode="dark"] [style*="color:#10"],
:root[data-cfo-mode="dark"] [style*="color: #10"],
:root[data-cfo-mode="dark"] [style*="color:#0c"],
:root[data-cfo-mode="dark"] [style*="color: #0c"] {
  color: var(--cfo-text) !important;
}
