:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #475467;
  --text-3: #8a94a6;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --accent-text: #1d4ed8;
  --ok: #16a34a;     --ok-soft: #e7f6ec;     --ok-text: #15803d;
  --warn: #d97706;   --warn-soft: #fff4e0;   --warn-text: #b45309;
  --bad: #dc2626;    --bad-soft: #fdecec;    --bad-text: #b91c1c;
  --mute-soft: #eef0f3; --mute-text: #5b6577;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.18);
  --radius: 12px;
  --radius-sm: 8px;
  /* chart series (validated: CVD ΔE 29.9 / normal 38.5, contrast ≥3:1 on light & dark surfaces) */
  --series-1: #2563eb;
  --series-2: #eb6834;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --surface: #151b23; --surface-2: #1c232d; --border: #262f3b; --border-strong: #354152;
    --text: #e6eaf0; --text-2: #a9b3c1; --text-3: #6f7a8a;
    --accent: #4b8bff; --accent-soft: #16233b; --accent-text: #8fb6ff;
    --ok: #22c55e; --ok-soft: #10261a; --ok-text: #6ee7a0;
    --warn: #f59e0b; --warn-soft: #2a1f0b; --warn-text: #fbbf5c;
    --bad: #ef4444; --bad-soft: #2c1414; --bad-text: #fca5a5;
    --mute-soft: #1f2631; --mute-text: #a3adbb;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
    --series-1: #4b8bff; --series-2: #d95926;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #151b23; --surface-2: #1c232d; --border: #262f3b; --border-strong: #354152;
  --text: #e6eaf0; --text-2: #a9b3c1; --text-3: #6f7a8a;
  --accent: #4b8bff; --accent-soft: #16233b; --accent-text: #8fb6ff;
  --ok: #22c55e; --ok-soft: #10261a; --ok-text: #6ee7a0;
  --warn: #f59e0b; --warn-soft: #2a1f0b; --warn-text: #fbbf5c;
  --bad: #ef4444; --bad-soft: #2c1414; --bad-text: #fca5a5;
  --mute-soft: #1f2631; --mute-text: #a3adbb;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  --series-1: #4b8bff; --series-2: #d95926;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.55 "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand b { font-weight: 600; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 20px; height: 20px; stroke: #fff; stroke-width: 2.6; fill: none; stroke-linecap: round; }
.nav { display: flex; gap: 2px; margin-left: 8px; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.user-chip {
  margin-left: auto; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 4px 12px 4px 4px; display: flex; align-items: center; gap: 8px;
  cursor: pointer; max-width: 220px; color: var(--text-2);
}
.user-chip .av { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-weight: 600; font-size: 12px; flex: none; }
.user-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabbar { display: none; }
@media (max-width: 760px) {
  .nav { display: none; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text-3); padding: 4px 0; }
  .tabbar a:hover { text-decoration: none; }
  .tabbar svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a.active { color: var(--accent); }
  .user-chip { padding: 4px; } .user-chip span:last-child { display: none; }
}
@media (min-width: 761px) { body { padding-bottom: 40px; } }

/* ---------- layout ---------- */
.container { max-width: 1240px; margin: 0 auto; padding: 20px 16px; }
.loading, .empty { color: var(--text-3); text-align: center; padding: 48px 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 2px 0 0; color: var(--text-2); }
.crumb { font-size: 13px; color: var(--text-3); margin-bottom: 4px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; }
.grid { display: grid; gap: 12px; }
.section { margin-top: 24px; }
.section > h2 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: 1.3fr repeat(4, 1fr); gap: 12px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, 1fr); } .kpi.main { grid-column: 1 / -1; } }
.kpi { padding: 16px; display: flex; flex-direction: column; gap: 8px; color: var(--text); }
a.kpi:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi .lbl { color: var(--text-2); font-size: 13px; font-weight: 500; }
.kpi .val { font-size: 28px; font-weight: 600; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 14px; color: var(--text-3); font-weight: 500; }
.kpi .sub { color: var(--text-3); font-size: 12.5px; }
.kpi.main { flex-direction: row; align-items: center; gap: 16px; }
.ring { --p: 0; width: 84px; height: 84px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0); display: grid; place-items: center; }
.ring::before { content: ""; grid-area: 1/1; width: calc(100% - 16px); height: calc(100% - 16px); border-radius: 50%; background: var(--surface); }
.ring span { grid-area: 1/1; font-weight: 600; font-size: 18px; font-variant-numeric: tabular-nums; z-index: 1; }

.statusbar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.statusbar button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 12px; cursor: pointer; display: flex; gap: 6px; align-items: center; color: var(--text-2); }
.statusbar button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.statusbar b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- progress ---------- */
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .3s; }
.bar.ok > i { background: var(--ok); }
.bar.lg { height: 10px; }
.pbox { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pbox .t { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--mute-soft); color: var(--mute-text); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill.blue { background: var(--accent-soft); color: var(--accent-text); }
.pill.green { background: var(--ok-soft); color: var(--ok-text); }
.pill.red { background: var(--bad-soft); color: var(--bad-text); }
.pill.amber { background: var(--warn-soft); color: var(--warn-text); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); font-size: 12px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad-text); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.input, select.input, textarea.input {
  height: 36px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); min-width: 0;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; min-height: 80px; width: 100%; }
.input:focus, .btn:focus-visible, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; border-color: var(--accent); }
select.input.sm, .input.sm { height: 30px; font-size: 13px; padding: 0 8px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .fields { grid-template-columns: 1fr; } }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; stroke: var(--text-3); fill: none; stroke-width: 2; }
.search .input { padding-left: 32px; width: 220px; }
@media (max-width: 560px) { .search, .search .input { width: 100%; } }

/* ---------- site list ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.slist-head, .srow { display: grid; grid-template-columns: minmax(170px, 1.5fr) 120px 1fr 1fr 110px 110px; gap: 16px; align-items: center; padding: 10px 16px; }
.slist-head { font-size: 12px; color: var(--text-3); font-weight: 500; border-bottom: 1px solid var(--border); }
.srow { border-bottom: 1px solid var(--border); color: var(--text); }
.slist-head[hidden] { display: none; }
.srow > * { min-width: 0; } /* let long blocker text ellipsize instead of widening the page */
.srow:last-child { border-bottom: 0; }
.srow:hover { background: var(--surface-2); text-decoration: none; }
.srow .nm { font-weight: 600; }
.srow .nm small { display: block; font-weight: 400; color: var(--text-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow .blk { color: var(--bad-text); }
.srow .overall { font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
@media (max-width: 900px) {
  .slist-head { display: none; }
  .srow { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; }
  .srow .c-sw, .srow .c-ap { grid-column: span 1; }
  .srow .c-plan { display: none; }
}

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.li { display: flex; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.li:last-child { border-bottom: 0; }
.li .meta { font-size: 12px; color: var(--text-3); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- site page ---------- */
.site-top { display: grid; grid-template-columns: 1.1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .site-top { grid-template-columns: 1fr; } }
.type-bars { display: grid; gap: 12px; }
.type-bars .pbox .t b { color: var(--text); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); } .kv dd { margin: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 24px 0 0; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 14px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--accent-text); border-bottom-color: var(--accent); }
.tabs .count { color: var(--text-3); font-size: 12px; margin-left: 4px; }
.tab-body { margin-top: 12px; }

/* device table */
/* header is NOT sticky: .table-wrap scrolls horizontally, so a sticky offset would push it over the first row */
.dtable { width: 100%; border-collapse: collapse; }
.dtable th { text-align: left; font-size: 12px; color: var(--text-2); font-weight: 600; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.dtable td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.dtable tbody tr:not(.group):hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.dtable tr:last-child td { border-bottom: 0; }
.dtable tr.sel td, .dtable tr.sel:hover td { background: var(--accent-soft); }
.dtable tr.group td { background: var(--bg); font-size: 12.5px; font-weight: 600; color: var(--text); padding: 8px 12px; border-top: 1px solid var(--border); }
.dtable tr.group .gcount { color: var(--text-3); font-weight: 400; margin-left: 6px; }
.dtable .chk { width: 40px; }
.dtable input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.dtable .nm { font-weight: 600; line-height: 1.35; word-break: break-word; }
.dtable .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.dtable .kv2 { display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; font-size: 12.5px; }
.dtable .kv2 span { color: var(--text-3); font-size: 11.5px; }
.dtable .note { color: var(--text-2); font-size: 12.5px; max-width: 260px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.dtable .who { font-size: 11.5px; color: var(--text-3); margin-top: 2px; white-space: nowrap; }

/* stage summary chips */
.stage-sum { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.stage-sum .chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); color: var(--text-3); }
.stage-sum .chip b { font-variant-numeric: tabular-nums; }
.stage-sum .chip.has { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.stage-sum .chip.has.mid { color: var(--accent-text); background: var(--accent-soft); border-color: transparent; }
.stage-sum .chip.has.done { color: var(--ok-text); background: var(--ok-soft); border-color: transparent; }
.stage-sel { height: 30px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); padding: 0 6px; font-size: 13px; max-width: 190px; }
.stage-sel.done { background: var(--ok-soft); border-color: transparent; color: var(--ok-text); }
.stage-sel.mid { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.table-wrap { overflow-x: auto; }
@media (max-width: 760px) {
  .dtable .h-sm { display: none; }
  .dtable td { padding: 10px 8px; }
}
.bulkbar { position: sticky; bottom: 76px; z-index: 5; margin-top: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--text); color: var(--bg); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow-lg); }
@media (min-width: 761px) { .bulkbar { bottom: 16px; } }
.bulkbar .stage-sel { background: var(--surface); color: var(--text); }

/* photo dots */
.pdots { display: inline-flex; gap: 4px; cursor: pointer; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); align-items: center; }
.pdots:hover { border-color: var(--accent); }
.pdots i { width: 9px; height: 9px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border-strong); }
.pdots i.on { background: var(--ok); border-color: var(--ok); }
.pdots svg { width: 14px; height: 14px; stroke: var(--text-3); fill: none; stroke-width: 2; margin-right: 2px; }

.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .slots { grid-template-columns: 1fr; } }
.slot { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; background: var(--surface); }
.slot .ph { aspect-ratio: 4/3; background: var(--surface-2); display: grid; place-items: center; color: var(--text-3); position: relative; }
.slot .ph img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.slot .ph svg { width: 36px; height: 36px; stroke: currentColor; fill: none; stroke-width: 1.5; }
.slot .ph .ok { position: absolute; top: 8px; right: 8px; }
.slot .sl-b { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.slot .sl-b .row .btn { flex: 1; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50; display: grid; place-items: center; padding: 16px; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.modal.wide { width: min(980px, 100%); }
.modal-h { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-h h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.modal-b { padding: 16px; overflow: auto; }
.modal-f { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
@media (max-width: 560px) {
  .modal-bg { padding: 0; place-items: end stretch; }
  .modal, .modal.wide { width: 100%; border-radius: 16px 16px 0 0; max-height: 92dvh; }
}
@keyframes fade { from { opacity: 0; } }

/* camera */
.cam { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; color: #fff; }
.cam video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.cam-top { display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
.cam-top .t { flex: 1; min-width: 0; }
.cam-top .t b { display: block; font-size: 16px; }
.cam-top .t span { font-size: 12px; opacity: .75; }
.cam-steps { display: flex; gap: 6px; padding: 0 14px 10px; }
.cam-steps span { flex: 1; text-align: center; font-size: 12px; padding: 4px; border-radius: 6px; background: rgba(255,255,255,.12); }
.cam-steps span.on { background: #fff; color: #000; font-weight: 600; }
.cam-steps span.done { background: rgba(34,197,94,.35); }
.cam-bot { display: flex; align-items: center; justify-content: space-around; padding: 16px 14px calc(20px + env(safe-area-inset-bottom)); }
.cam .cbtn { background: rgba(255,255,255,.14); border: 0; color: #fff; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.cam .cbtn svg { width: 22px; height: 22px; stroke: #fff; fill: none; stroke-width: 2; }
.cam .shutter { width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff; background: transparent; cursor: pointer; padding: 4px; }
.cam .shutter i { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.cam .shutter:active i { transform: scale(.88); }
.cam .shutter:disabled { opacity: .4; }
.cam .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.cam .status { text-align: center; font-size: 13px; min-height: 20px; opacity: .85; }

.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.92); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 92vh; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.cal-head h2 { min-width: 160px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal .dow { font-size: 12px; color: var(--text-3); padding: 8px; text-align: center; border-bottom: 1px solid var(--border); font-weight: 500; }
.cal .day { min-height: 112px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; min-width: 0; }
.cal .day:nth-child(7n) { border-right: 0; }
.cal .day:hover { background: var(--surface-2); }
.cal .day.out { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.cal .day.out .dn { color: var(--text-3); }
.cal .dn { font-size: 12px; font-weight: 500; padding: 2px 4px; font-variant-numeric: tabular-nums; align-self: flex-start; }
.cal .day.today .dn { background: var(--accent); color: #fff; border-radius: 6px; }
.ev { font-size: 12px; line-height: 1.35; padding: 2px 6px; border-radius: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; border-left: 3px solid; }
.ev.planned { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }
.ev.done { background: var(--ok-soft); color: var(--ok-text); border-color: var(--ok); }
.ev.postponed { background: var(--warn-soft); color: var(--warn-text); border-color: var(--warn); }
.ev.cancelled { background: var(--mute-soft); color: var(--mute-text); border-color: var(--text-3); text-decoration: line-through; }
.ev .pc { opacity: .75; margin-left: 4px; font-variant-numeric: tabular-nums; }
.more { font-size: 11px; color: var(--text-3); padding: 0 6px; }
@media (max-width: 760px) {
  .cal .day { min-height: 54px; padding: 2px; }
  .cal .ev { font-size: 0; padding: 0; height: 5px; border-left: 0; border-radius: 3px; }
  .cal .ev.planned { background: var(--accent); } .cal .ev.done { background: var(--ok); } .cal .ev.postponed { background: var(--warn); } .cal .ev.cancelled { background: var(--text-3); }
  .cal .more { font-size: 10px; padding: 0; }
}
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- 3D (three.js) ---------- */
.viz-stage { position: relative; height: 460px; overflow: hidden; touch-action: none;
  background: radial-gradient(ellipse at 50% 35%, color-mix(in srgb, var(--accent) 7%, var(--surface)) 0%, var(--surface) 70%); }
.viz-stage.cal3d { height: 600px; }
.viz-stage.site3d { height: 480px; }
@media (max-width: 760px) { .viz-stage, .viz-stage.site3d { height: 420px; } .viz-stage.cal3d { height: 480px; } }
/* glow style: dark scene regardless of page theme */
.viz-stage.glow { background: #060a14; }
.viz-stage.glow .viz-label { color: #dfe7f5; }
.viz-stage.glow .viz-region, .viz-stage.glow .viz-floor, .viz-stage.glow .viz-ev, .viz-stage.glow .viz-unit { background: rgba(12, 20, 38, .78); border-color: #22314f; }
.viz-stage.glow .viz-day { color: #8fa3c4; }
.viz-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); }
.viz-floor { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--border); }
.viz-floor span, .viz-region span { font-weight: 500; color: var(--text-3); margin-left: 4px; }
.viz-floor.all, .viz-region.all { border-color: var(--ok); }
.viz-floor.all span, .viz-region.all span { color: var(--ok-text); }
.viz-unit { font-size: 10.5px; padding: 1px 6px; border-radius: 5px; background: color-mix(in srgb, var(--surface) 85%, transparent); border: 1px solid var(--border); color: var(--text-2); }
.viz-unit.done { color: var(--ok-text); border-color: var(--ok); }
.viz-unit.progress { color: var(--accent-text); }
.viz-day { font-size: 10.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.viz-day b { font-size: 12px; color: var(--text); }
.viz-day.we { opacity: .7; }
.viz-day.today b { color: #fff; background: var(--accent); padding: 0 5px; border-radius: 5px; }
.legend i.lg-ghost { background: transparent; border: 1.5px dashed var(--text-3); }
.viz-stage .viz-canvas { display: block; cursor: grab; }
.viz-stage .viz-canvas:active { cursor: grabbing; }
/* CSS2DRenderer writes large z-index values on every label; isolate them so the tooltip stays on top */
.viz-labels { position: absolute; inset: 0; pointer-events: none; z-index: 1; isolation: isolate; }
.viz-label { font: 500 11px/1.3 "IBM Plex Sans Thai", system-ui, sans-serif; color: var(--text); white-space: nowrap; user-select: none; }
.viz-name { color: var(--text-2); font-size: 10.5px; }
.viz-pct { font-weight: 600; font-size: 11.5px; padding: 1px 6px; border-radius: 6px; background: color-mix(in srgb, var(--surface) 85%, transparent); font-variant-numeric: tabular-nums; }
.viz-pct.blocked { color: var(--bad-text); }
.viz-pct.done { color: var(--ok-text); }
.viz-region { font-weight: 600; font-size: 12.5px; color: var(--text); padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.viz-dow { color: var(--text-3); font-weight: 600; font-size: 12px; }
.viz-dn { color: var(--text-2); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.viz-dn.out { color: var(--text-3); opacity: .6; }
.viz-dn.today { color: #fff; background: var(--accent); padding: 0 5px; border-radius: 5px; }
.viz-ev { font-size: 10.5px; padding: 1px 6px; border-radius: 5px; background: color-mix(in srgb, var(--surface) 88%, transparent); border-left: 3px solid var(--accent); }
.viz-ev.done { border-color: var(--ok); } .viz-ev.postponed { border-color: var(--warn); } .viz-ev.cancelled { border-color: var(--text-3); text-decoration: line-through; opacity: .7; }
.viz-ev.tight { font-size: 9.5px; padding: 0 4px; }
.viz-more { color: var(--text-3); font-size: 10px; }
.viz-tip { position: absolute; left: 0; top: 0; z-index: 2; min-width: 180px; max-width: 260px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); pointer-events: none; font-size: 13px; }
.viz-tip.pinned { pointer-events: auto; }
.viz-tip .big { font-size: 22px; font-weight: 600; margin: 2px 0; font-variant-numeric: tabular-nums; }
.viz-hint { padding: 8px 16px; font-size: 12px; color: var(--text-3); border-top: 1px solid var(--border); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 0 12px; height: 30px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.on { background: var(--accent-soft); color: var(--accent-text); }
@media (max-width: 760px) { .hide-sm { display: none !important; } }

/* ---------- 3D expand / collapse ---------- */
.viz-fs { position: absolute; top: 10px; right: 10px; z-index: 3; background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(6px); }
.viz-stage.glow .viz-fs { background: rgba(12, 20, 38, .8); color: #dfe7f5; border-color: #22314f; }
.card.viz-full { position: fixed; inset: 0; z-index: 40; margin: 0; border-radius: 0; border: 0; display: flex; flex-direction: column; animation: fade .15s; }
.card.viz-full .viz-stage { flex: 1; height: auto !important; min-height: 0; }
body.viz-open { overflow: hidden; }
body.viz-open .tabbar { display: none; }

/* ---------- entry animation & skeleton ---------- */
@property --p { syntax: '<number>'; inherits: false; initial-value: 0; }
.ring { transition: --p 1s cubic-bezier(.2, .7, .2, 1); }
.enter > * { animation: fadeUp .4s cubic-bezier(.2, .7, .2, 1) both; }
.enter > *:nth-child(2) { animation-delay: .04s; } .enter > *:nth-child(3) { animation-delay: .08s; }
.enter > *:nth-child(4) { animation-delay: .12s; } .enter > *:nth-child(n+5) { animation-delay: .16s; }
.enter .kpis > * { animation: fadeUp .45s cubic-bezier(.2, .7, .2, 1) both; }
.enter .kpis > *:nth-child(2) { animation-delay: .05s; } .enter .kpis > *:nth-child(3) { animation-delay: .1s; }
.enter .kpis > *:nth-child(4) { animation-delay: .15s; } .enter .kpis > *:nth-child(5) { animation-delay: .2s; }
.enter .bar > i { animation: barIn 1s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } }
@keyframes barIn { from { width: 0; } }
.sk { background: linear-gradient(90deg, var(--surface-2) 0%, color-mix(in srgb, var(--surface-2) 40%, var(--surface)) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.3s linear infinite; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.sk-title { height: 26px; width: 320px; max-width: 70%; margin-bottom: 8px; }
.sk-sub { height: 14px; width: 200px; margin-bottom: 18px; }
.sk-line { height: 12px; width: 70%; } .sk-line.w40 { width: 40%; }
.sk-big { height: 30px; width: 55%; }
.sk-row { height: 38px; margin-bottom: 10px; }
.sk-chart { height: 240px; margin: 16px; }
@media (prefers-reduced-motion: reduce) {
  .enter > *, .enter .kpis > *, .enter .bar > i, .sk { animation: none !important; }
  .ring { transition: none; }
}

/* ---------- site cards ---------- */
.scards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; padding: 16px; }
.scard { position: relative; display: flex; flex-direction: column; gap: 10px; padding: 14px 14px 12px 18px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); overflow: hidden; transition: transform .15s, box-shadow .15s, border-color .15s; }
.scard::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--text-3); }
.scard.st-in_progress::before { background: var(--accent); } .scard.st-blocked::before { background: var(--bad); } .scard.st-done::before { background: var(--ok); }
.scard:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.scard-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.scard-name { font-weight: 600; font-size: 15px; }
.scard-bars { display: grid; gap: 8px; }
.scard-foot { font-size: 12.5px; border-top: 1px solid var(--border); padding-top: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scard-foot .blk { color: var(--bad-text); }
.ring.sm { width: 52px; height: 52px; }
.ring.sm::before { width: calc(100% - 10px); height: calc(100% - 10px); }
.ring.sm span { font-size: 12.5px; }
@media (prefers-reduced-motion: reduce) { .scard { transition: none; } .scard:hover { transform: none; } }

/* ---------- burn-up chart ---------- */
.burn { padding: 4px 16px 12px; }
.burn-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 0 4px; }
.burn-hero .big { font-size: 28px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.burn-status { font-size: 13px; padding: 3px 10px; border-radius: 999px; }
.burn-status.ok { background: var(--ok-soft); color: var(--ok-text); }
.burn-status.warn { background: var(--warn-soft); color: var(--warn-text); }
.legend i.ln { width: 16px; height: 0; border-radius: 0; border-top: 2px solid var(--series-1); background: none; }
.legend i.ln.s2, .burn-tip i.ln.s2 { border-top: 2px dashed var(--series-2); }
.burn-plot { position: relative; }
.burn-plot svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.burn-plot .grid line { stroke: var(--border); stroke-width: 1; }
.burn-plot text { fill: var(--text-3); font: 11px "IBM Plex Sans Thai", system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.burn-plot .total-lbl { fill: var(--text-3); }
.burn-plot .today { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 2 3; }
.burn-plot .today-lbl { fill: var(--text-2); font-weight: 600; }
.burn-plot path { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.burn-plot path.s1 { stroke: var(--series-1); }
.burn-plot path.s2 { stroke: var(--series-2); stroke-dasharray: 6 4; }
.burn-plot path.area { fill: var(--series-1); fill-opacity: .1; stroke: none; }
.burn-plot path.draw.s1 { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.1s .15s cubic-bezier(.3, .6, .2, 1) forwards; }
.burn-plot path.draw.s2 { animation: fadeIn .8s both; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fadeIn { from { opacity: 0; } }
.burn-plot circle { stroke: var(--surface); stroke-width: 2; }
.burn-plot circle.s1 { fill: var(--series-1); } .burn-plot circle.s2 { fill: var(--series-2); }
.burn-plot .end-lbl { fill: var(--text); font-weight: 600; font-size: 12px; }
.burn-plot .cross { stroke: var(--text-3); stroke-width: 1; }
.burn-tip { position: absolute; left: 0; top: 0; pointer-events: none; min-width: 160px; padding: 8px 10px; border-radius: 10px; font-size: 12.5px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.burn-tip .tr { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.burn-tip .tr b { margin-left: auto; font-variant-numeric: tabular-nums; }
.burn-tip i.ln { width: 14px; border-top: 2px solid var(--series-1); }
.burn-tip .neg { color: var(--warn-text); margin-top: 4px; } .burn-tip .pos { color: var(--ok-text); margin-top: 4px; }
.burn-table { margin-top: 6px; font-size: 13px; }
.burn-table summary { cursor: pointer; color: var(--text-2); padding: 6px 0; }
.burn-table .table-wrap { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
@media (prefers-reduced-motion: reduce) { .burn-plot path.draw.s1, .burn-plot path.draw.s2 { animation: none; stroke-dashoffset: 0; } }

/* settings */
.stage-row { display: grid; grid-template-columns: 24px 1fr 90px auto; gap: 8px; align-items: center; padding: 6px 0; }
.stage-row .n { color: var(--text-3); font-size: 12px; text-align: center; }
.pct-in { display: flex; align-items: center; gap: 4px; }
.pct-in .input { width: 64px; text-align: right; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--bad); color: #fff; }
@media (min-width: 761px) { .toast { bottom: 24px; } }

.progress-line { height: 4px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress-line i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
