:root {
  color-scheme: light;
  --bg: #f3f4f6; --surface: #fcfcfb; --surface-2: #eef0f3; --line: #dcdfe4;
  --text: #0b0b0b; --text-2: #52514e; --text-3: #7d7c78;
  --accent: #1c5cab; --accent-ink: #fff; --accent-soft: #e3eefc;
  --seq-1: #184f95; --seq-2: #3987e5; --seq-3: #86b6ef;
  --t1: #2a78d6; --t2: #eb6834; --t3: #1baf7a; --t4: #eda100;
  --t5: #e87ba4; --t6: #008300; --t7: #6250d6; --t8: #e34948;
  --bad: #c62828; --bad-soft: #fdecea; --warn: #9a6200; --warn-soft: #fff4d6; --good: #1b7a3a; --good-soft: #e4f5e9;
  --radius: 12px; --nav-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #252523; --line: #353532;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
    --accent: #5598e7; --accent-ink: #0b0b0b; --accent-soft: #16263d;
    --seq-1: #6da7ec; --seq-2: #256abf; --seq-3: #184f95;
    --t1: #3987e5; --t2: #d95926; --t3: #199e70; --t4: #c98500;
    --t5: #d55181; --t6: #008300; --t7: #9085e9; --t8: #e66767;
    --bad: #ff8a80; --bad-soft: #3a1c1a; --warn: #f2c14e; --warn-soft: #3a2f12; --good: #7bd492; --good-soft: #173222;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); } .small { font-size: 12.5px; }
.bad { color: var(--bad); } .good { color: var(--good); } .warn { color: var(--warn); }

/* layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 52px; }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 2px; }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 6px 14px; border-radius: 8px; color: var(--text-2); font-size: 14px; }
.nav a svg { width: 20px; height: 20px; display: none; }
.nav a.on { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.topbar .spacer { flex: 1; }
main { max-width: 1120px; margin: 0 auto; padding: 16px 16px 40px; }
@media (max-width: 760px) {
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); justify-content: space-around; }
  .nav a { flex: 1; font-size: 11px; padding: 4px 0; border-radius: 0; background: none !important; }
  .nav a svg { display: block; }
  main { padding: 12px 12px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
  .topbar { height: 46px; padding: 0 12px; }
}
.head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.head h1 { flex: 1; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card > h2 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.card > h2 .spacer { flex: 1; }
.grid { display: grid; gap: 12px; }
.grid.kpi { grid-template-columns: repeat(4, 1fr); margin-bottom: 12px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid .card { margin: 0; }
@media (max-width: 900px) { .grid.kpi { grid-template-columns: 1fr 1fr; } .grid.two { grid-template-columns: 1fr; } }
.grid.two { margin-bottom: 12px; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  min-height: 36px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; min-height: 30px; font-size: 13px; }
.btn.icon { padding: 0; width: 36px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 8px 10px; min-height: 40px; font-size: 16px; }
textarea { min-height: 72px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible, .cal-cell:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; }
select.inline { width: auto; min-height: 36px; padding: 4px 8px; font-size: 14px; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 3px; }
label.chk { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
label.chk input { width: 18px; min-height: 18px; height: 18px; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
input[type=date] { min-width: 0; -webkit-appearance: none; appearance: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13.5px; min-height: 32px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* kpi */
.kpi .card { padding: 12px 14px; }
.kpi .lbl { font-size: 12.5px; color: var(--text-2); }
.kpi .val { font-size: 24px; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--text-2); }
@media (max-width: 420px) { .kpi .val { font-size: 20px; } }
.meter { position: relative; height: 10px; background: var(--surface-2); border-radius: 5px; margin: 8px 0 4px; }
.meter i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }
.meter i.fc { background: var(--seq-3); } .meter i.act { background: var(--seq-1); }
.meter b { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.legend i, .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; flex: none; }
.legend i.ln { height: 0; border-top: 2px dashed var(--text-2); border-radius: 0; vertical-align: 3px; width: 14px; }

/* column chart */
.chart { position: relative; height: 190px; margin: 6px 0 0 34px; }
.chart .gl { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.chart .gl span { position: absolute; left: -34px; top: -8px; width: 30px; text-align: right; font-size: 11px; color: var(--text-3); }
.chart .cap { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--text-2); z-index: 2; pointer-events: none; }
.chart .cols { position: absolute; inset: 0 0 0 0; display: flex; }
.chart .col { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; padding: 0 2px; min-width: 0; position: relative; }
.chart .col:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.chart .col.now::after { content: ""; position: absolute; bottom: -4px; left: 30%; right: 30%; height: 2px; background: var(--accent); }
.chart .bar { width: 42%; max-width: 20px; border-radius: 4px 4px 0 0; min-height: 0; }
.chart .stack { width: 70%; max-width: 30px; display: flex; flex-direction: column-reverse; gap: 2px; height: 100%; justify-content: flex-start; }
.chart .stack i { display: block; border-radius: 2px; flex: none; }
.chart .stack i:last-child { border-radius: 4px 4px 2px 2px; }
.xlabels { display: flex; margin-left: 34px; font-size: 11px; color: var(--text-3); padding-top: 5px; }
.xlabels span { flex: 1; text-align: center; }
.hatch { background-image: repeating-linear-gradient(45deg, transparent 0 3px, color-mix(in srgb, var(--surface) 70%, transparent) 3px 5px); }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 600; color: var(--text-2); font-size: 12.5px; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
td:last-child, th:last-child { padding-right: 0; }
tr.total td { font-weight: 700; border-bottom: 0; }
tr.now td:first-child { color: var(--accent); font-weight: 700; }
.hbar { display: inline-block; height: 8px; border-radius: 0 4px 4px 0; vertical-align: middle; margin-right: 6px; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; padding-bottom: 0; }
.list li:first-child { padding-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .main .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .acts { display: flex; gap: 6px; flex: none; align-items: center; }
.list .when { width: 64px; flex: none; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.s-lead { background: var(--warn-soft); color: var(--warn); }
.badge.s-done, .badge.s-received { background: var(--good-soft); color: var(--good); }
.badge.s-cancelled { text-decoration: line-through; }
.badge.s-active, .badge.s-confirmed, .badge.s-invoiced { background: var(--accent-soft); color: var(--accent); }
.badge.s-bad { background: var(--bad-soft); color: var(--bad); }
.empty { color: var(--text-3); padding: 14px 0; text-align: center; font-size: 13.5px; }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }
.banner .spacer { flex: 1; }

/* project cards */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.pcard { display: block; color: inherit; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--c);
  border-radius: var(--radius); padding: 12px 14px; }
.pcard:hover { border-color: var(--c); }
.pcard .t { font-weight: 600; margin: 2px 0 2px; }
.pcard .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12.5px; color: var(--text-2); }
.pcard .nums { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; font-size: 12.5px; color: var(--text-2); }
.pcard .nums b { display: block; color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.pcard .meter { height: 6px; margin: 4px 0 0; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cal .dow { background: var(--surface-2); text-align: center; font-size: 12px; color: var(--text-2); padding: 4px 0; }
.cal-cell { background: var(--surface); min-height: 88px; padding: 4px; cursor: pointer; border: 0; text-align: left; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-cell.out { background: var(--bg); cursor: default; }
.cal-cell.we .d { color: var(--text-3); }
.cal-cell .d { font-size: 12.5px; font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; align-items: center; }
.cal-cell.today .d b { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 6px; }
.cal-cell.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell.conflict { background: var(--bad-soft); }
.cal-cell .d .x { color: var(--bad); font-size: 11px; font-weight: 700; }
.ev { font-size: 11.5px; line-height: 1.35; border-radius: 4px; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 16%, var(--surface)); color: var(--text); }
.ev.planned { background: transparent; outline: 1px dashed color-mix(in srgb, var(--c) 60%, transparent); outline-offset: -1px; }
@media (max-width: 760px) {
  .cal-cell { min-height: 58px; padding: 3px; }
  .ev { font-size: 0; height: 6px; padding: 0; border-left: 0; background: var(--c); }
  .ev.planned { background: color-mix(in srgb, var(--c) 35%, var(--surface)); outline: 0; }
  .ev.half { width: 50%; } .ev.PM { margin-left: 50%; }
}

/* dialog / toast / tip / login */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); padding: 0; width: min(520px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 16px; }
dialog h2 { margin-bottom: 12px; }
.dlg-actions { display: flex; gap: 8px; margin-top: 6px; }
.dlg-actions .spacer { flex: 1; }
.err { color: var(--bad); font-size: 13.5px; min-height: 20px; margin: 4px 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 20px); z-index: 50; background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw; }
.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12.5px; padding: 6px 9px; border-radius: 8px; white-space: pre-line; max-width: 240px; font-variant-numeric: tabular-nums; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(360px, 100%); padding: 22px; }
.login h1 { margin-bottom: 4px; } .login p { margin: 0 0 16px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.swatches input { position: absolute; opacity: 0; width: 0; min-height: 0; height: 0; }
.swatches i { display: block; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; border: 3px solid var(--surface); }
.swatches input:checked + i { box-shadow: 0 0 0 2px var(--text); }
.swatches input:focus-visible + i { box-shadow: 0 0 0 2px var(--accent); }
.list .main .work { font-size: 13.5px; overflow-wrap: anywhere; }
[hidden] { display: none !important; }
.meter i.mid { background: var(--seq-2); }
.meter i.fc.hatch { background-color: var(--seq-3); }
/* horizontal stacked bars */
.hrows { display: grid; gap: 8px; }
.hrow { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr) 76px; gap: 10px; align-items: center; font-size: 13.5px; }
.hrow .hl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hrow .ht { display: flex; gap: 2px; height: 16px; }
.hrow .ht i { display: block; border-radius: 2px; min-width: 2px; }
.hrow .ht i:last-child { border-radius: 2px 4px 4px 2px; }
.hrow .hv { text-align: right; color: var(--text-2); }
@media (max-width: 760px) {
  .hrow { grid-template-columns: minmax(0, 1fr) 76px; gap: 2px 10px; }
  .hrow .hl { grid-column: 1 / -1; }
}
h3 .small { margin-left: 2px; }
