:root{
    --bg:#FBF6EC;
    --card:#FFFFFF;
    --ink:#3D3529;
    --muted:#8C8171;
    --border:#EDE4D3;
    --green:#8FAE87;
    --green-deep:#5F7E58;
    --blue:#9FC1D6;
    --blue-deep:#4E7C93;
    --purple:#C7B7DD;
    --purple-deep:#7A64A0;
    --peach:#F0C6A6;
    --peach-deep:#B87A45;
    --rose:#E4A2A0;
    --rose-deep:#B85B58;
    --radius:18px;
    --radius-sm:13px;
  }
  *{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
  html,body{ margin:0; padding:0; touch-action:manipulation; }
  body{
    background:var(--bg); color:var(--ink);
    font-family:-apple-system,BlinkMacSystemFont,"PingFang TC","Heiti TC","Microsoft JhengHei",sans-serif;
    padding-top:env(safe-area-inset-top);
    padding-bottom:calc(80px + env(safe-area-inset-bottom));
    overflow-x:hidden;
  }
  input,select,textarea,button{ font-size:16px; font-family:inherit; }
  button{ min-height:44px; cursor:pointer; }
  .app{ max-width:540px; margin:0 auto; padding:14px 14px 20px; }

  /* ---------- Login ---------- */
  #loginScreen{
    min-height:100vh; display:flex; align-items:center; justify-content:center;
    padding:24px; padding-top:calc(24px + env(safe-area-inset-top));
  }
  .login-box{
    background:var(--card); border-radius:24px; padding:32px 26px; width:100%; max-width:380px;
    box-shadow:0 4px 20px rgba(120,100,70,0.12); text-align:center;
  }
  .login-box .emoji{ font-size:40px; margin-bottom:8px; }
  .login-box h1{ font-size:19px; margin:0 0 4px; }
  .login-box p{ font-size:13px; color:var(--muted); margin:0 0 22px; }
  .login-box input{
    width:100%; border:1.5px solid var(--border); border-radius:14px; padding:14px 16px;
    text-align:center; letter-spacing:2px; font-weight:700; margin-bottom:14px; background:#FFFDF8;
  }
  .login-box input:focus{ outline:none; border-color:var(--blue-deep); }
  .btn-primary{
    width:100%; background:var(--green-deep); color:#fff; border:none; border-radius:14px;
    padding:15px; font-size:16px; font-weight:700;
  }
  .btn-primary:active{ opacity:0.85; }

  /* ---------- Header ---------- */
  .topbar{
    background:linear-gradient(135deg,#F3E6D0,#EAD9C3);
    border-radius:var(--radius); padding:16px 18px; margin-bottom:12px;
    display:flex; align-items:center; justify-content:space-between; gap:8px; flex-wrap:wrap;
  }
  .topbar .whoami{ font-size:14px; font-weight:700; }
  .topbar .whoami small{ display:block; font-weight:400; font-size:11.5px; color:var(--muted); margin-top:2px; }
  .topbar .right{ display:flex; align-items:center; gap:10px; }
  #syncStatus{ font-size:11px; color:var(--muted); white-space:nowrap; }
  .btn-logout{ background:none; border:1px solid var(--border); border-radius:20px; padding:6px 12px; font-size:12px; color:var(--muted); min-height:32px; }

  /* ---------- Section ---------- */
  .section{ background:var(--card); border-radius:var(--radius); padding:16px 14px; margin-bottom:12px; border:1px solid var(--border); }
  .section h2{ font-size:15px; margin:0 0 12px; }
  .empty-hint{ text-align:center; color:var(--muted); font-size:13.5px; padding:16px 0; }

  /* ---------- Active summary ---------- */
  .active-line{
    display:flex; justify-content:space-between; align-items:center; padding:9px 12px;
    background:#F7F1E5; border-radius:12px; margin-bottom:8px; font-size:14px;
  }
  .active-line:last-child{ margin-bottom:0; }
  .active-line .an{ font-weight:700; }
  .active-line .at{ font-variant-numeric:tabular-nums; font-weight:700; color:var(--blue-deep); }

  /* ---------- Category cards ---------- */
  .cat-card{ border-radius:var(--radius-sm); border:1px solid var(--border); padding:14px; margin-bottom:11px; position:relative; overflow:hidden; }
  .cat-card:last-child{ margin-bottom:0; }
  .cat-card::before{ content:""; position:absolute; left:0; top:0; bottom:0; width:6px; background:var(--accent,#ccc); }
  .cat-top{ display:flex; align-items:center; gap:8px; margin-bottom:6px; padding-left:6px; }
  .cat-top .cicon{ font-size:20px; }
  .cat-top .cname{ font-weight:700; font-size:15px; flex:1; }
  .cat-status{ font-size:11.5px; padding:3px 10px; border-radius:20px; font-weight:700; }
  .st-none{ background:#F0EEE8; color:var(--muted); }
  .st-run{ background:#E7F0E4; color:var(--green-deep); }
  .st-pause{ background:#FBEADA; color:var(--peach-deep); }
  .cat-sub{ font-size:12px; color:var(--muted); padding-left:6px; margin-bottom:10px; }
  .cat-timer{ font-size:24px; font-weight:800; font-variant-numeric:tabular-nums; padding-left:6px; margin-bottom:10px; color:var(--ink); }
  .cat-extra-input{
    width:100%; border:1.5px solid var(--border); border-radius:10px; padding:10px 12px;
    margin:0 0 10px; background:#FFFDF8;
  }
  .cat-btn-row{ display:flex; gap:8px; padding-left:0; }
  .cbtn{ flex:1; border:none; border-radius:12px; padding:12px 6px; font-weight:700; font-size:14px; color:#fff; }
  .cbtn.start{ background:var(--green-deep); }
  .cbtn.pause{ background:var(--peach-deep); }
  .cbtn.resume{ background:var(--blue-deep); }
  .cbtn.done{ background:var(--rose-deep); }
  .cbtn:active{ opacity:0.85; }

  /* ---------- Timeline ---------- */
  .timeline{ position:relative; padding-left:16px; }
  .timeline::before{ content:""; position:absolute; left:4px; top:4px; bottom:4px; width:2px; background:var(--border); }
  .tl-item{ position:relative; padding-bottom:14px; }
  .tl-item:last-child{ padding-bottom:0; }
  .tl-dot{ position:absolute; left:-16px; top:3px; width:9px; height:9px; border-radius:50%; background:var(--blue-deep); }
  .tl-time{ font-size:12px; color:var(--muted); font-weight:600; }
  .tl-label{ font-size:14px; font-weight:700; }
  .tl-sub{ font-size:12px; color:var(--muted); }

  /* ---------- Filters ---------- */
  .filter-row{ display:flex; gap:8px; flex-wrap:wrap; margin-bottom:14px; }
  .filter-row select, .filter-row input[type=date]{
    flex:1; min-width:110px; border:1.5px solid var(--border); border-radius:10px; padding:10px 8px; background:#FFFDF8;
  }

  /* ---------- Record item ---------- */
  .rec-item{ border:1px solid var(--border); border-radius:12px; padding:12px 13px; margin-bottom:9px; }
  .rec-item:last-child{ margin-bottom:0; }
  .rec-top{ display:flex; justify-content:space-between; font-size:14px; font-weight:700; margin-bottom:4px; }
  .rec-mid{ font-size:12.5px; color:var(--muted); margin-bottom:3px; }
  .rec-bot{ display:flex; justify-content:space-between; font-size:13px; }
  .rec-bot .dur{ font-weight:700; color:var(--green-deep); }
  .rec-status{ font-size:11px; padding:1px 8px; border-radius:10px; }

  /* ---------- KPI ---------- */
  .kpi-grid{ display:grid; grid-template-columns:1fr 1fr; gap:9px; margin-bottom:14px; }
  .kpi-box{ background:#F7F1E5; border-radius:12px; padding:12px; }
  .kpi-box .kl{ font-size:11.5px; color:var(--muted); margin-bottom:4px; }
  .kpi-box .kv{ font-size:18px; font-weight:800; }

  .cat-agg-row{ display:flex; justify-content:space-between; font-size:13.5px; padding:6px 0; border-bottom:1px dashed var(--border); }
  .cat-agg-row:last-child{ border-bottom:none; }

  /* ---------- Nav ---------- */
  .bottom-nav{
    position:fixed; left:0; right:0; bottom:0; background:#fff; border-top:1px solid var(--border);
    display:flex; padding:8px 6px calc(10px + env(safe-area-inset-bottom)); z-index:50;
    box-shadow:0 -2px 10px rgba(120,100,70,0.08);
  }
  .nav-btn{ flex:1; background:none; border:none; display:flex; flex-direction:column; align-items:center; gap:2px; color:var(--muted); font-size:11px; font-weight:600; }
  .nav-btn .ni{ font-size:20px; }
  .nav-btn.active{ color:var(--green-deep); }

  .tab-content{ display:none; }
  .tab-content.active{ display:block; }

  .note-box{ background:#F3ECDD; border-radius:12px; padding:11px 13px; font-size:12px; color:#7A6A4E; line-height:1.6; margin-top:10px; }

  .modal-overlay{ position:fixed; inset:0; background:rgba(60,50,35,0.4); display:flex; align-items:center; justify-content:center; z-index:100; }
  .modal-overlay[hidden]{ display:none; }
  .modal-box{ background:#fff; border-radius:20px; padding:24px 20px; width:90%; max-width:360px; text-align:center; }
  .modal-box p{ font-size:15.5px; font-weight:600; margin:4px 0 18px; }
  .modal-actions{ display:flex; gap:10px; }
  .modal-actions button{ flex:1; border-radius:12px; border:none; font-weight:700; }
  .btn-cancel{ background:#F0EEE8; color:var(--ink); }
  .btn-confirm{ background:var(--rose-deep); color:#fff; }

  .toast{
    position:fixed; bottom:92px; left:50%; transform:translateX(-50%); background:rgba(50,42,30,0.92);
    color:#fff; padding:10px 18px; border-radius:20px; font-size:13px; z-index:200; opacity:0; transition:opacity .25s;
    pointer-events:none; white-space:nowrap; max-width:88vw; overflow:hidden; text-overflow:ellipsis;
  }
  .toast.show{ opacity:1; }

  /* ---------- 新增（Smarty 版） ---------- */
  .alert{ border-radius:12px; padding:10px 12px; font-size:13px; margin-bottom:12px; text-align:left; }
  .alert-error{ background:#FBE5E4; color:#B85B58; }
  .alert-ok{ background:#E7F0E4; color:#5F7E58; }
  .privacy-hint{ font-size:11.5px; color:var(--rose-deep); margin:-4px 0 8px; }
  .cat-guide{ margin:6px 0 8px; font-size:12.5px; color:var(--muted); }
  .cat-guide summary{ cursor:pointer; list-style:none; }
  .cat-guide summary::-webkit-details-marker{ display:none; }
  .cat-guide p{ margin:6px 0 0; line-height:1.55; }
  .bottom-nav a.nav-btn{ text-decoration:none; }

  /* ---------- Batch 1：今日工作與明細 ---------- */
  [hidden]{ display:none !important; }
  .section-hint{ font-size:12px; color:var(--muted); margin:-4px 0 10px; line-height:1.5; }
  .now-card{ border:1.5px solid var(--border); border-left:5px solid var(--accent,var(--green-deep)); border-radius:var(--radius-sm); padding:12px 14px; background:#FFFDF8; }
  .now-top{ display:flex; justify-content:space-between; align-items:center; gap:8px; font-weight:700; font-size:15px; }
  .now-timer{ font-size:34px; font-weight:800; letter-spacing:1px; font-variant-numeric:tabular-nums; margin:6px 0 4px; color:var(--green-deep); }
  .wait-item{ border:1px dashed var(--peach); border-radius:var(--radius-sm); padding:10px 12px; margin-bottom:8px; background:#FFF9F2; }
  .wait-main{ display:flex; justify-content:space-between; font-weight:700; font-size:14px; }
  .wait-time{ font-variant-numeric:tabular-nums; color:var(--peach-deep); }
  .cat-card.is-active{ background:#FFFDF8; }
  .cat-timer{ font-variant-numeric:tabular-nums; }
  .kpi-grid.kpi-3{ grid-template-columns:repeat(3,1fr); }
  .kpi-grid.kpi-3 .kv{ font-size:15px; white-space:nowrap; }
  .rec-status.rs-run{ background:#E7F0E4; color:#5F7E58; }
  .rec-status.rs-pause{ background:#FBEADA; color:#B87A45; }
  .rec-status.rs-done{ background:#EEE7F5; color:#7A64A0; }
  .pending-note{ font-size:12.5px; background:#FBEADA; color:#B87A45; border-radius:10px; padding:8px 10px; margin-bottom:10px; }
  #syncStatus.sync-wait{ color:var(--peach-deep); font-weight:700; }
  #syncStatus.sync-busy{ color:var(--blue-deep); }
  #syncStatus.sync-ok{ color:var(--green-deep); }

  /* ---------- Batch 2：圖表、報表預覽、月報 ---------- */
  .viz-host{ position:relative; transition:opacity .2s; }
  .is-loading .viz-host, .is-loading #mineList, .is-loading #previewTable{ opacity:.5; }
  .viz-donut{ position:relative; display:flex; flex-wrap:wrap; align-items:center; gap:14px 18px; }
  .viz-donut svg{ flex:0 0 auto; margin:0 auto; }
  .viz-seg{ cursor:pointer; transition:opacity .15s; outline:none; }
  .viz-seg:focus-visible{ opacity:1; filter:brightness(1.08); }
  .viz-center-value{ font-size:17px; font-weight:700; fill:var(--ink); }
  .viz-center-label{ font-size:11px; fill:var(--muted); }
  .viz-legend{ flex:1 1 200px; border-collapse:collapse; font-size:13px; }
  .viz-legend td{ padding:6px 4px; border-bottom:1px solid var(--border); }
  .viz-legend tr:last-child td{ border-bottom:none; }
  .viz-legend tr.is-hi td{ background:#FBF6EC; }
  .viz-sw{ width:14px; }
  .viz-swatch{ display:inline-block; width:10px; height:10px; border-radius:2px; vertical-align:middle; }
  .viz-legend-label{ color:var(--ink); }
  .viz-num{ text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; color:var(--ink); }
  .viz-pct{ color:var(--muted); width:44px; }
  .viz-line{ position:relative; }
  .viz-line svg{ display:block; max-width:100%; height:auto; }
  .viz-grid{ stroke:var(--border); stroke-width:1; }
  .viz-tick{ font-size:11px; fill:var(--muted); font-variant-numeric:tabular-nums; }
  .viz-cross{ stroke:var(--muted); stroke-width:1; }
  .viz-hit{ cursor:crosshair; touch-action:pan-y; outline:none; }
  .viz-hit:focus-visible{ stroke:var(--border); stroke-width:1; }
  .viz-tip{ position:absolute; z-index:5; pointer-events:none; background:#FFFFFF; border:1px solid var(--border); border-radius:10px;
            box-shadow:0 4px 14px rgba(120,100,70,.15); padding:6px 10px; white-space:nowrap; }
  .viz-tip-row{ display:flex; align-items:center; gap:7px; }
  .viz-tip-key{ display:inline-block; width:12px; height:2px; border-radius:1px; }
  .viz-tip strong{ font-size:14px; color:var(--ink); }
  .viz-tip-label{ font-size:12px; color:var(--muted); }
  .viz-caption{ font-size:12.5px; color:var(--muted); margin:4px 0 8px; line-height:1.5; }
  .viz-head{ display:flex; justify-content:space-between; align-items:center; gap:8px; flex-wrap:wrap; }
  .viz-head h2{ margin:0; }
  .seg-toggle{ display:inline-flex; background:#F3EDE2; border-radius:10px; padding:3px; }
  .seg-toggle button{ min-height:36px; border:none; background:none; border-radius:8px; padding:4px 11px; font-size:13px; color:var(--muted); }
  .seg-toggle button[aria-pressed="true"]{ background:#FFFFFF; color:var(--ink); font-weight:700; box-shadow:0 1px 3px rgba(0,0,0,.08); }
  .viz-table{ margin-top:8px; font-size:12.5px; color:var(--muted); }
  .viz-table summary{ cursor:pointer; min-height:32px; line-height:32px; }
  .viz-table table{ border-collapse:collapse; margin-top:4px; }
  .viz-table th, .viz-table td{ padding:3px 14px 3px 0; text-align:left; font-variant-numeric:tabular-nums; color:var(--ink); }
  .viz-table th{ color:var(--muted); font-weight:400; }
  .preview-scroll{ overflow-x:auto; -webkit-overflow-scrolling:touch; border:1px solid var(--border); border-radius:10px; }
  .preview-scroll .empty-hint{ padding:14px; }
  table.preview{ border-collapse:collapse; font-size:12px; white-space:nowrap; }
  table.preview th{ background:#F6EFE4; font-weight:700; text-align:left; padding:7px 9px; }
  table.preview td{ padding:6px 9px; border-top:1px solid var(--border); }
  table.preview td.num{ text-align:right; font-variant-numeric:tabular-nums; }
  .report-row-ctl{ display:flex; gap:8px; align-items:stretch; }
  .report-row-ctl input{ flex:1; min-width:0; }
  #btnReport{ width:auto; flex:0 0 auto; padding:12px 18px; }
  #btnReport:disabled{ opacity:.6; }
  .report-row{ display:flex; align-items:center; gap:10px; padding:10px 4px; border-bottom:1px solid var(--border); text-decoration:none; color:var(--ink); min-height:44px; }
  .rr-month{ font-weight:700; }
  .rr-meta{ flex:1; font-size:12px; color:var(--muted); }
  .rr-dl{ font-size:13px; color:var(--blue-deep); font-weight:700; }

  /* ---------- Batch 3：主管總覽 ---------- */
  .kpi-grid.kpi-4{ grid-template-columns:repeat(2,1fr); }
  .kpi-grid.kpi-4 .kv{ font-size:16px; white-space:nowrap; }
  .peak-tiles .kv{ font-size:15px; }
  .filter-bar{ padding-bottom:6px; }
  .filter-bar .filter-row{ display:flex; flex-wrap:wrap; gap:10px; }
  .filter-bar label{ display:flex; flex-direction:column; gap:4px; font-size:12px; color:var(--muted); flex:1 1 150px; }
  .filter-bar input, .filter-bar select{ width:100%; border:1.5px solid var(--border); border-radius:12px; padding:10px 12px; background:#FFFDF8; color:var(--ink); }
  .unlock-form{ display:flex; gap:8px; margin-bottom:10px; }
  .unlock-form input{ flex:1; min-width:0; border:1.5px solid var(--border); border-radius:12px; padding:12px 14px; background:#FFFDF8; }
  .unlock-form .btn-primary{ width:auto; padding:12px 20px; }
  .h2-sub{ font-size:12px; font-weight:400; color:var(--muted); }
  .viz-bars{ display:flex; flex-direction:column; gap:10px; }
  .viz-bar-row{ display:grid; grid-template-columns:minmax(7em, 38%) 1fr auto; align-items:center; gap:8px; }
  .viz-bar-label{ font-size:13px; color:var(--ink); line-height:1.3; min-width:0; }
  .viz-bar-label small{ display:block; font-size:11px; color:var(--muted); }
  .viz-bar-track{ height:16px; }
  .viz-bar{ height:16px; border-radius:0 4px 4px 0; min-width:2px; }
  .viz-bar-value{ font-size:13px; color:var(--ink); font-variant-numeric:tabular-nums; white-space:nowrap; }
  .cov-row{ display:flex; align-items:center; gap:8px; padding:9px 2px; border-bottom:1px solid var(--border); font-size:13px; flex-wrap:wrap; }
  .cov-name{ font-weight:700; }
  .cov-name small{ margin-left:6px; font-size:11px; font-weight:400; color:var(--blue-deep); background:#EAF2F7; border-radius:8px; padding:1px 6px; }
  .cov-meta{ flex:1; color:var(--muted); font-size:12px; }
  .cov-badge{ font-size:12px; border-radius:10px; padding:2px 8px; }
  .cov-badge.ok{ background:#E7F0E4; color:#5F7E58; }
  .cov-badge.miss{ background:#FBEADA; color:#B87A45; }
  table.preview tr.tot td{ background:#FBF6EC; font-weight:700; }
  #btnExport{ margin-bottom:6px; }
