/* ============================================================
   對數系統 Pro-Max · 共享樣式 (雙主題, 終端級, 零聯網)
   ============================================================ */
:root[data-theme="dark"]{
  --bg:#000; --bg2:#0d0d0d; --card:#121212; --card2:#161616; --hi:#1c1c1c;
  --line:#222; --line2:#2c2c2c;
  --ink:#fff; --mut:#777; --mut2:#9a9a9a;
  --gold:#d4af37; --cash:#34d399; --credit:#fbbf24;
  --cash-bd:rgba(52,211,153,.55); --cash-bg:rgba(52,211,153,.10);
  --credit-bd:rgba(251,191,36,.55); --credit-bg:rgba(251,191,36,.10);
  --feature:linear-gradient(180deg,#1a1a1a,#0d0d0d);
  --shadow:0 1px 0 rgba(255,255,255,.03),0 8px 30px rgba(0,0,0,.6);
  --page:radial-gradient(1200px 600px at 50% -10%,#0e0e0e 0%,#000 60%);
}
:root[data-theme="light"]{
  --bg:#fff; --bg2:#f8f9fa; --card:#f8f9fa; --card2:#f1f3f5; --hi:#eceef1;
  --line:#e5e7eb; --line2:#d1d5db;
  --ink:#111; --mut:#6b7280; --mut2:#4b5563;
  --gold:#b8860b; --cash:#059669; --credit:#b45309;
  --cash-bd:rgba(5,150,105,.45); --cash-bg:rgba(5,150,105,.08);
  --credit-bd:rgba(180,83,9,.40); --credit-bg:rgba(180,83,9,.07);
  --feature:linear-gradient(180deg,#fff,#f1f3f5);
  --shadow:0 1px 2px rgba(16,24,40,.05),0 8px 24px rgba(16,24,40,.06);
  --page:#fff;
}
*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html{ -webkit-text-size-adjust:100%; }
html,body{ margin:0; padding:0; background:var(--bg); }
body{
  color:var(--ink); background:var(--page); min-height:100vh;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang HK","Microsoft JhengHei","Heiti TC","Noto Sans CJK TC",sans-serif;
  font-size:16px; line-height:1.6; -webkit-font-smoothing:antialiased;
  padding:18px 16px calc(40px + env(safe-area-inset-bottom)); max-width:1100px; margin:0 auto; letter-spacing:.2px;
  transition:background .3s,color .3s;
}
input,select,textarea,button{ touch-action:manipulation; font-family:inherit; }
.num{ font-variant-numeric:tabular-nums; font-feature-settings:"tnum"; }
.hide{ display:none !important; }
@media(prefers-reduced-motion:reduce){ *{ transition:none !important; animation:none !important; } }

/* ===== Header ===== */
header.top{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:2px 2px 16px; border-bottom:1px solid var(--line); margin-bottom:20px; flex-wrap:wrap; }
header.top .brand{ font-size:11px; color:var(--mut); letter-spacing:5px; text-transform:uppercase; }
header.top .title{ font-size:25px; font-weight:800; line-height:1.1; margin-top:3px; }
header.top .title .pro{ font-size:11px; color:var(--bg); background:var(--gold); border-radius:5px; padding:2px 7px; vertical-align:middle; margin-left:8px; font-weight:800; letter-spacing:1px; }
header.top .rhs{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.who{ font-size:12px; color:var(--mut2); text-align:right; }
.who b{ color:var(--ink); font-size:14px; }
.role-badge{ display:inline-block; font-size:11px; font-weight:800; padding:2px 8px; border-radius:6px; border:1px solid; }
.role-badge.admin{ color:var(--gold); border-color:var(--gold); }
.role-badge.staff{ color:var(--cash); border-color:var(--cash-bd); }
.live{ font-size:11px; color:var(--mut); display:flex; align-items:center; gap:6px; }
.live .dot{ width:7px; height:7px; border-radius:50%; background:var(--cash); box-shadow:0 0 8px var(--cash); animation:pulse 2s infinite; }
@keyframes pulse{ 0%,100%{opacity:1} 50%{opacity:.35} }

.icon-btn{ display:inline-flex; align-items:center; gap:7px; background:var(--card); border:1px solid var(--line2); color:var(--ink); border-radius:10px; padding:8px 12px; font-size:13px; font-weight:700; cursor:pointer; transition:background .18s,border-color .18s; min-height:40px; }
.icon-btn:hover{ background:var(--hi); border-color:var(--gold); }
.icon-btn:focus-visible{ outline:2px solid var(--gold); outline-offset:2px; }
.icon-btn svg{ width:16px; height:16px; }
.theme-btn .ti-dark{ display:none; } :root[data-theme="dark"] .theme-btn .ti-dark{ display:inline-flex; }
:root[data-theme="dark"] .theme-btn .ti-light{ display:none; }

/* ===== 登入頁 ===== */
.login-wrap{ max-width:420px; margin:8vh auto 0; }
.login-card{ background:var(--card); border:1px solid var(--line); border-radius:20px; padding:30px 26px; box-shadow:var(--shadow); }
.login-card h1{ font-size:26px; font-weight:900; margin:0 0 4px; }
.login-card h1 .pro{ font-size:11px; color:var(--bg); background:var(--gold); border-radius:5px; padding:2px 7px; margin-left:8px; }
.login-card .sub{ color:var(--mut); font-size:13px; margin-bottom:22px; }
.field{ margin-bottom:14px; }
.field label{ display:block; font-size:13px; color:var(--mut2); font-weight:700; margin-bottom:6px; }
.field input{ width:100%; background:var(--bg); border:1px solid var(--line2); border-radius:11px; color:var(--ink); font-size:16px; padding:13px 14px; min-height:50px; transition:border-color .15s; }
.field input:focus{ outline:none; border-color:var(--gold); }
.login-btn{ width:100%; background:var(--gold); color:#000; border:none; border-radius:12px; font-size:17px; font-weight:900; padding:15px; cursor:pointer; min-height:54px; margin-top:6px; transition:opacity .18s,transform .1s; }
:root[data-theme="light"] .login-btn{ color:#fff; }
.login-btn:hover{ opacity:.9; } .login-btn:active{ transform:scale(.98); }
.login-err{ color:var(--credit); font-size:14px; font-weight:700; margin-top:12px; min-height:20px; text-align:center; }
.demo-accs{ margin-top:22px; border-top:1px dashed var(--line2); padding-top:16px; }
.demo-accs .dt{ font-size:12px; color:var(--mut); margin-bottom:8px; letter-spacing:1px; }
.demo-acc{ display:flex; justify-content:space-between; align-items:center; gap:8px; padding:9px 12px; background:var(--card2); border:1px solid var(--line); border-radius:10px; margin-bottom:7px; cursor:pointer; transition:background .15s,border-color .15s; }
.demo-acc:hover{ background:var(--hi); border-color:var(--gold); }
.demo-acc .da-l{ font-size:14px; font-weight:700; } .demo-acc .da-l small{ color:var(--mut2); font-weight:500; margin-left:6px; }
.demo-acc .da-r{ font-size:12px; color:var(--mut); font-family:monospace; }
.demo-acc .role-badge{ font-size:10px; }

/* ===== 區塊 / 卡 ===== */
.block{ margin-bottom:24px; }
.block-h{ display:flex; align-items:center; gap:10px; margin:0 2px 12px; flex-wrap:wrap; }
.block-h .idx{ width:25px; height:25px; border:1px solid var(--line2); border-radius:7px; display:flex; align-items:center; justify-content:center; font-size:12px; color:var(--gold); font-weight:800; }
.block-h h2{ font-size:17px; font-weight:800; margin:0; }
.block-h .hint{ font-size:12px; color:var(--mut); margin-left:auto; }
.card{ background:var(--card); border:1px solid var(--line); border-radius:16px; overflow:hidden; box-shadow:var(--shadow); }

/* ===== 表格 ===== */
table{ width:100%; border-collapse:collapse; }
th{ background:var(--card2); color:var(--mut); font-size:11.5px; font-weight:700; letter-spacing:.5px; text-align:left; padding:11px 12px; border-bottom:1px solid var(--line); white-space:nowrap; }
td{ padding:9px 12px; border-bottom:1px solid var(--line); font-size:15px; vertical-align:middle; }
tr:last-child td{ border-bottom:none; }
.t-right{ text-align:right; } .t-center{ text-align:center; }
input.cell,select.cell{ width:100%; background:var(--bg); border:1px solid var(--line2); border-radius:9px; color:var(--ink); font-size:15px; padding:9px 10px; font-variant-numeric:tabular-nums; transition:border-color .15s; min-height:42px; }
input.cell:focus,select.cell:focus{ outline:none; border-color:var(--gold); }
input.cell.amt{ text-align:right; font-weight:700; }
select.cell{ -webkit-appearance:none; appearance:none; cursor:pointer; padding-right:28px; background-repeat:no-repeat; background-position:right 10px center; 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='%23999' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); }
input.cell::-webkit-outer-spin-button,input.cell::-webkit-inner-spin-button{ -webkit-appearance:none; margin:0; }
input[type=number]{ -moz-appearance:textfield; }

/* 微調器 */
.stepper{ display:flex; align-items:center; gap:6px; justify-content:center; }
.stepper button{ width:40px; height:40px; border:1px solid var(--line2); background:var(--hi); color:var(--ink); border-radius:9px; font-size:20px; font-weight:800; cursor:pointer; transition:background .15s,border-color .15s; line-height:1; }
.stepper button:hover{ background:var(--card2); border-color:var(--gold); }
.stepper button:active{ transform:scale(.92); }
.stepper input{ width:58px; text-align:center; background:var(--bg); border:1px solid var(--line2); border-radius:9px; color:var(--ink); font-size:17px; font-weight:800; padding:8px 4px; font-variant-numeric:tabular-nums; min-height:42px; }
.stepper input:focus{ outline:none; border-color:var(--gold); }
.use{ font-size:20px; font-weight:800; color:var(--gold); } .use small{ font-size:12px; color:var(--mut); font-weight:600; }

/* 狀態 pill */
.pill{ display:inline-flex; align-items:center; gap:6px; border-radius:11px; padding:9px 14px; font-size:14px; font-weight:800; cursor:pointer; transition:background .15s,border-color .15s,transform .1s; white-space:nowrap; min-height:42px; border:1.5px solid; }
.pill:active{ transform:scale(.96); } .pill:focus-visible{ outline:2px solid var(--gold); outline-offset:2px; }
.pill.cash{ background:var(--cash-bg); color:var(--cash); border-color:var(--cash-bd); }
.pill.credit{ background:var(--credit-bg); color:var(--credit); border-color:var(--credit-bd); }
.pill[disabled]{ opacity:.55; cursor:default; }
.flag-tag{ display:inline-block; margin-left:6px; background:var(--credit-bg); color:var(--credit); border:1px solid var(--credit-bd); border-radius:7px; padding:1px 7px; font-size:12px; font-weight:800; }

.del{ width:38px; height:38px; border:1px solid var(--line2); background:transparent; color:var(--mut2); border-radius:9px; font-size:15px; cursor:pointer; transition:background .15s,color .15s,border-color .15s; }
.del:hover{ background:var(--credit-bg); color:var(--credit); border-color:var(--credit-bd); }
.add-row,.btn-arc{ width:100%; background:transparent; border:1.5px dashed var(--line2); color:var(--mut2); border-radius:13px; padding:15px; font-size:16px; font-weight:800; cursor:pointer; transition:background .15s,color .15s,border-color .15s; margin-top:12px; }
.add-row:hover,.btn-arc:hover{ background:var(--card2); color:var(--ink); border-color:var(--gold); }
.btn-arc{ border-style:solid; border-color:var(--gold); color:var(--ink); }
.var-row{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:14px 16px; background:var(--card); border:1px solid var(--line); border-radius:14px; margin-top:14px; flex-wrap:wrap; box-shadow:var(--shadow); }
.var-row .vl{ font-size:15px; font-weight:700; } .var-row .vl small{ display:block; color:var(--mut); font-size:12px; font-weight:500; }

/* 巨型財務卡 */
.fin-cards{ display:grid; grid-template-columns:1fr; gap:12px; }
@media(min-width:640px){ .fin-cards{ grid-template-columns:repeat(3,1fr); } }
.fin{ background:var(--card); border:1px solid var(--line); border-radius:16px; padding:20px; box-shadow:var(--shadow); }
.fin.feature{ border-color:var(--gold); background:var(--feature); }
.fin .fl{ font-size:13px; color:var(--mut2); font-weight:700; display:flex; align-items:center; gap:7px; }
.fin .mark{ width:11px; height:11px; border-radius:3px; display:inline-block; border:1.5px solid; }
.fin .mark.cash{ background:var(--cash-bg); border-color:var(--cash-bd); } .fin .mark.credit{ background:var(--credit-bg); border-color:var(--credit-bd); } .fin .mark.gold{ background:var(--gold); border-color:var(--gold); }
.fin .fsub{ font-size:12px; color:var(--mut); margin-top:3px; min-height:16px; }
.fin .fbig{ font-size:40px; font-weight:900; line-height:1.04; margin-top:10px; letter-spacing:-1.5px; }
.fin.green .fbig{ color:var(--cash); } .fin.yellow .fbig{ color:var(--credit); } .fin.feature .fbig{ color:var(--gold); }

/* 司機卡 */
.drv-grid{ display:grid; grid-template-columns:1fr; gap:12px; margin-top:14px; }
@media(min-width:640px){ .drv-grid{ grid-template-columns:repeat(3,1fr); } }
.drv{ background:var(--card); border:1px solid var(--line); border-radius:14px; padding:16px; box-shadow:var(--shadow); }
.drv .dn{ font-size:19px; font-weight:900; display:flex; align-items:baseline; justify-content:space-between; }
.drv .dn .pts{ font-size:12px; color:var(--mut2); font-weight:700; } .drv .dn .pts b{ color:var(--gold); font-size:22px; }
.drv .dl{ display:flex; justify-content:space-between; font-size:14px; padding:8px 0; border-top:1px solid var(--line); margin-top:8px; }
.drv .dl span:first-child{ color:var(--mut2); } .drv .dl span:last-child{ font-weight:800; }
.drv .dl.cash span:last-child{ color:var(--cash); } .drv .dl.credit span:last-child{ color:var(--credit); }

/* Tabs */
.tabs{ display:inline-flex; background:var(--card2); border:1px solid var(--line2); border-radius:12px; padding:4px; gap:4px; flex-wrap:wrap; }
.tabs button{ border:none; background:transparent; color:var(--mut2); font-size:14px; font-weight:800; padding:11px 18px; border-radius:9px; cursor:pointer; transition:background .18s,color .18s; }
.tabs button.on{ background:var(--gold); color:#000; }
:root[data-theme="light"] .tabs button.on{ color:#fff; }
.tabs button:focus-visible{ outline:2px solid var(--gold); outline-offset:2px; }

/* 日選擇器 */
.day-pick{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-bottom:16px; }
.day-pick select{ background:var(--card); border:1px solid var(--line2); color:var(--ink); border-radius:10px; padding:10px 30px 10px 12px; font-size:14px; font-weight:700; min-height:42px; -webkit-appearance:none; appearance:none; cursor:pointer; background-repeat:no-repeat; background-position:right 10px center; 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='%23999' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); }
.day-add{ background:var(--card); border:1px solid var(--gold); color:var(--gold); border-radius:10px; padding:10px 14px; font-size:13px; font-weight:800; cursor:pointer; min-height:42px; transition:background .18s; }
.day-add:hover{ background:var(--hi); }

/* ===== 圖表 ===== */
.charts-grid{ display:grid; grid-template-columns:1fr; gap:14px; margin-top:6px; }
@media(min-width:720px){ .charts-grid{ grid-template-columns:1fr 1fr; } }
.chart-card{ background:var(--card); border:1px solid var(--line); border-radius:16px; padding:18px; box-shadow:var(--shadow); }
.chart-card h3{ font-size:14px; font-weight:800; margin:0 0 14px; color:var(--ink); }
.chart-card h3 small{ color:var(--mut); font-weight:500; font-size:12px; margin-left:6px; }
.ch-track{ stroke:var(--line2); } .ch-grid{ stroke:var(--line); stroke-width:1; }
.ch-svg{ width:180px; height:180px; display:block; } .ch-svg-line{ width:100%; height:auto; }
.ch-donut-wrap{ display:flex; align-items:center; gap:16px; flex-wrap:wrap; }
.ch-center-lbl{ fill:var(--mut2); font-size:11px; font-weight:700; } .ch-center-val{ fill:var(--ink); font-size:20px; font-weight:900; }
.ch-legend{ display:flex; flex-direction:column; gap:7px; } .ch-leg-item{ font-size:13px; color:var(--mut2); display:flex; align-items:center; gap:7px; } .ch-leg-item b{ color:var(--ink); } .ch-leg-item small{ color:var(--mut); }
.ch-dot{ width:11px; height:11px; border-radius:3px; display:inline-block; }
.ch-axis{ fill:var(--mut); font-size:10px; } .ch-line{ stroke-width:2.5; fill:none; } .ch-line-dot{ stroke:var(--bg); stroke-width:1.5; }
/* 圖表配色 class（跟主題）*/
.seg-cash,.bar-cash,.ch-dot.seg-cash{ stroke:var(--cash); } .ch-dot.seg-cash,.bar-cash{ background:var(--cash); } .bar-cash{ fill:var(--cash); }
.seg-credit{ stroke:var(--credit); } .ch-dot.seg-credit,.bar-credit{ background:var(--credit); } .bar-credit{ fill:var(--credit); }
.bar-gold,.ch-dot.bar-gold{ background:var(--gold); } .bar-gold{ fill:var(--gold); }
.line-cash{ stroke:var(--cash); } .ch-dot.line-cash{ background:var(--cash); }
.line-credit{ stroke:var(--credit); } .ch-dot.line-credit{ background:var(--credit); }
.line-gold{ stroke:var(--gold); } .ch-dot.line-gold{ background:var(--gold); }
/* 直條 */
.ch-bars{ display:flex; align-items:flex-end; gap:10px; padding-top:10px; }
.ch-bar-col{ display:flex; flex-direction:column; align-items:center; gap:6px; }
.ch-bar-val{ font-size:13px; font-weight:800; color:var(--ink); }
.ch-bar-track{ width:100%; max-width:60px; display:flex; align-items:flex-end; justify-content:center; }
.ch-bar-fill{ width:36px; border-radius:7px 7px 0 0; transition:height .3s; min-height:3px; }
.bar-cash.ch-bar-fill,.ch-bar-fill.bar-cash{ background:var(--cash); } .ch-bar-fill.bar-credit{ background:var(--credit); } .ch-bar-fill.bar-gold{ background:var(--gold); }
.ch-bar-lbl{ font-size:12px; color:var(--mut2); font-weight:700; }
/* 橫條 */
.ch-hbars{ display:flex; flex-direction:column; gap:10px; }
.ch-hbar-row{ display:flex; align-items:center; gap:10px; font-size:13px; }
.ch-hbar-lbl{ width:54px; color:var(--mut2); font-weight:700; flex:none; }
.ch-hbar-track{ flex:1; height:18px; background:var(--card2); border-radius:6px; overflow:hidden; }
.ch-hbar-fill{ height:100%; border-radius:6px; transition:width .3s; }
.ch-hbar-fill.bar-gold{ background:var(--gold); } .ch-hbar-fill.bar-cash{ background:var(--cash); }
.ch-hbar-val{ width:84px; text-align:right; font-weight:800; color:var(--ink); flex:none; font-variant-numeric:tabular-nums; }

/* 帳號管理 */
.acc-tag{ font-size:12px; color:var(--mut2); font-family:monospace; }
.mini-btn{ background:var(--card2); border:1px solid var(--line2); color:var(--ink); border-radius:8px; padding:7px 11px; font-size:13px; font-weight:700; cursor:pointer; transition:background .15s,border-color .15s; min-height:38px; }
.mini-btn:hover{ background:var(--hi); border-color:var(--gold); }
.mini-btn.danger:hover{ border-color:var(--credit-bd); color:var(--credit); }

/* 底部操作 */
.footbar{ display:flex; gap:10px; margin-top:24px; flex-wrap:wrap; }
.btn{ border:none; border-radius:14px; font-size:17px; font-weight:900; cursor:pointer; transition:opacity .18s,transform .1s,background .18s; min-height:58px; }
.btn-main{ flex:1; min-width:200px; background:var(--gold); color:#000; padding:16px; box-shadow:0 6px 22px rgba(212,175,55,.28); }
:root[data-theme="light"] .btn-main{ color:#fff; }
.btn-main:hover{ opacity:.9; } .btn-main:active{ transform:scale(.98); } .btn-main.done{ background:var(--cash); box-shadow:none; }
.btn-ghost{ background:var(--card); color:var(--mut2); border:1px solid var(--line2); padding:0 18px; font-size:14px; }
.btn-ghost:hover{ background:var(--hi); color:var(--ink); }

/* toast */
.toast{ position:fixed; left:50%; bottom:30px; transform:translateX(-50%) translateY(20px); background:var(--ink); color:var(--bg); font-weight:800; font-size:15px; padding:12px 22px; border-radius:999px; opacity:0; transition:opacity .25s,transform .25s; z-index:40; pointer-events:none; box-shadow:var(--shadow); }
.toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }
#copyArea{ position:absolute; left:-9999px; top:0; }
.empty{ text-align:center; color:var(--mut); padding:26px; font-size:14px; }
#boot-fallback{ background:var(--card); border:1px solid var(--gold); border-radius:14px; color:var(--mut2); padding:18px; font-size:15px; line-height:1.6; margin:18px 0; text-align:center; }
#boot-fallback b{ color:var(--ink); font-size:17px; }

/* ===== 窄螢幕：表格→卡片 ===== */
@media (max-width:680px){
  body{ padding:14px 12px calc(30px + env(safe-area-inset-bottom)); }
  .card[data-stack] thead{ display:none; }
  .card[data-stack] table,.card[data-stack] tbody{ display:block; width:100%; }
  .card[data-stack] tr{ display:block; background:var(--card2); border:1px solid var(--line2); border-radius:14px; padding:6px 4px; margin:10px; }
  .card[data-stack] td{ display:flex; align-items:center; justify-content:space-between; gap:12px; border:none !important; padding:10px 12px; text-align:right; }
  .card[data-stack] td+td{ border-top:1px solid var(--line) !important; }
  .card[data-stack] td::before{ content:attr(data-label); flex:none; text-align:left; color:var(--mut2); font-size:13px; font-weight:700; }
  .card[data-stack] td.stk-name{ background:var(--hi); border-radius:10px; margin:2px 6px 4px; justify-content:flex-start; font-size:18px !important; }
  .card[data-stack] td.stk-name::before{ content:""; }
  .stepper{ justify-content:flex-end; } .stepper button{ width:44px; height:44px; } .stepper input{ width:64px; min-height:44px; }
  .card[data-stack] td .cell{ max-width:62%; margin-left:auto; min-height:46px; }
  .card[data-stack] .pill{ min-height:46px; }
  .card[data-stack] td.del-cell{ justify-content:center; } .card[data-stack] td.del-cell::before{ content:""; }
  .card[data-stack] .del{ width:100%; height:46px; border-style:dashed; }
  .card[data-stack] .del::after{ content:" 刪除呢一筆"; font-size:14px; font-weight:700; }
  .fin .fbig{ font-size:44px; } .tabs{ width:100%; } .tabs button{ flex:1; }
  .btn-main{ min-width:100%; }
}

