:root {
  --bg: #f6f5f9; --surface: #ffffff; --surface-2: #f0eef5; --line: #e2dfea;
  --ink: #1f1a2b; --ink-2: #5b5468; --ink-3: #8a8396;
  --brand: #6b2c91; --brand-ink: #ffffff; --brand-soft: #efe6f6;
  --ok: #1f7a4d; --ok-soft: #e3f4ea; --warn: #9a6200; --warn-soft: #fdf1dc;
  --bad: #b3261e; --bad-soft: #fbe5e3; --info: #1d5fa8; --info-soft: #e3eefb;
  --radius: 10px; --shadow: 0 1px 2px rgba(20, 10, 40, .06), 0 4px 16px rgba(20, 10, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15121b; --surface: #1e1a26; --surface-2: #272231; --line: #352f40;
    --ink: #eeeaf4; --ink-2: #b9b2c6; --ink-3: #8a8396;
    --brand: #b98ad9; --brand-ink: #1a1022; --brand-soft: #2e2240;
    --ok: #6fcf9b; --ok-soft: #173326; --warn: #f0b955; --warn-soft: #3a2c12;
    --bad: #f08a80; --bad-soft: #3d1c1a; --info: #8ab8f0; --info-soft: #182a40;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.55 "IBM Plex Sans Thai", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 18px; margin-bottom: 12px; }
h3 { font-size: 15px; margin-bottom: 8px; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, .kpi b { font-variant-numeric: tabular-nums; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 20px; background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-size: 26px; }
.top h1 { font-size: 18px; }
.top .sub { margin: 0; opacity: .85; font-size: 13px; }
.who { font-size: 13px; text-align: right; opacity: .95; }
.who .role { display: inline-block; padding: 1px 8px; border-radius: 99px; background: rgba(255,255,255,.18); margin-left: 6px; }

.tabs {
  display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.tabs button {
  border: 0; background: none; padding: 12px 14px; cursor: pointer; white-space: nowrap;
  color: var(--ink-2); border-bottom: 3px solid transparent; font-weight: 500;
}
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.tabs button[hidden] { display: none; }

main { max-width: 1320px; margin: 0 auto; padding: 20px 16px 60px; }
.tab { display: none; } .tab.on { display: block; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 12px; }
.grid > * { min-width: 0; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi span { color: var(--ink-2); font-size: 13px; display: block; }
.kpi b { font-size: 26px; font-weight: 700; display: block; line-height: 1.2; }
.kpi small { color: var(--ink-3); font-size: 12px; }
.kpi.accent { border-left: 4px solid var(--brand); }
.two { grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
@media (max-width: 520px) { .two { grid-template-columns: 1fr; } }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1 1 220px; }
input[type=text], input[type=search], input[type=date], input[type=number], input[type=email], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-height: 36px; max-width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer; min-height: 36px; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 3px 10px; min-height: 28px; font-size: 13px; }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; color: var(--ink-2); position: sticky; top: 0; white-space: nowrap; font-size: 13px; }
td.n, th.n { text-align: right; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tr.click { cursor: pointer; }
tfoot td { font-weight: 700; background: var(--surface-2); }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }

.bar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.bar i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.s0 { background: #c9c2d6; } .s1 { background: #8fb3e3; } .s2 { background: #e7b65a; } .s3 { background: #b98ad9; } .s4 { background: #4fb683; } .s5 { background: #1f7a4d; } .s6 { background: #d9817a; }

.steps { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 3px; margin: 8px 0 4px; }
.steps i { height: 8px; border-radius: 3px; background: var(--surface-2); }
.steps i.done { background: var(--ok); } .steps i.late { background: var(--bad); } .steps i.now { background: var(--warn); }
.proc-card .meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--ink-2); }

.drawer { position: fixed; inset: 0; background: rgba(15, 8, 25, .45); z-index: 20; display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer-panel { background: var(--surface); width: min(640px, 100%); height: 100%; overflow-y: auto; padding: 20px; position: relative; }
.drawer .x { position: absolute; right: 12px; top: 10px; border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--ink-2); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: 14px; margin-bottom: 12px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; word-break: break-word; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--ink-2); }
.form .full { grid-column: 1 / -1; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 8px; z-index: 30; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--info-soft); color: var(--info); margin-bottom: 12px; font-size: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 8px; font-size: 13px; }
.empty { padding: 30px; text-align: center; color: var(--ink-3); }
@media (max-width: 640px) {
  .top { padding: 12px 16px; } .who { text-align: left; }
  main { padding: 16px; } .kv { grid-template-columns: 1fr; } .kv dt { margin-top: 6px; }
}
