/* Layout: left rail nav (stacks to top tabs on phones) + one working pane per page. Tokens below. */
:root {
  --bg: #f2f3ef; --panel: #ffffff; --sunk: #f8f9f6; --ink: #1c2421; --muted: #5d6863; --line: #dde2db;
  --accent: #2c4c86; --accent-soft: #e5ebf5; --dye: #a5443a; --dye-soft: #f6e6e3;
  --ok: #2d7649; --ok-soft: #e3f1e8; --warn: #93650f; --warn-soft: #f6edd8; --bad: #b0352f; --bad-soft: #f8e7e5;
  --font-body: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif;
  --font-display: "Noto Serif Thai", "IBM Plex Sans Thai", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #121614; --panel: #1b201d; --sunk: #171b19; --ink: #e6ebe8; --muted: #9aa49f; --line: #2d3430;
  --accent: #8ea8e4; --accent-soft: #212b3c; --dye: #e48a7f; --dye-soft: #3a2421;
  --ok: #7cc69a; --ok-soft: #1e3226; --warn: #e0b462; --warn-soft: #382f1f; --bad: #ee8a83; --bad-soft: #3a2321; color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #121614; --panel: #1b201d; --sunk: #171b19; --ink: #e6ebe8; --muted: #9aa49f; --line: #2d3430;
  --accent: #8ea8e4; --accent-soft: #212b3c; --dye: #e48a7f; --dye-soft: #3a2421;
  --ok: #7cc69a; --ok-soft: #1e3226; --warn: #e0b462; --warn-soft: #382f1f; --bad: #ee8a83; --bad-soft: #3a2321; color-scheme: dark }
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 14px; line-height: 1.5; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
.app { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: env(safe-area-inset-top, 0px); align-self: start; height: 100vh; padding: 22px 14px 22px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 18px; border-right: 1px solid var(--line); }
.brand { display: grid; gap: 2px; }
.brand b { font-family: var(--font-display); font-size: 1.25rem; letter-spacing: .01em; }
.brand span { color: var(--muted); font-size: .78rem; }
.skein { display: flex; gap: 3px; margin-top: 6px; }
.skein i { width: 18px; height: 6px; border-radius: 3px; }
nav.pages { display: grid; gap: 2px; }
nav.pages a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
nav.pages a:hover { background: var(--sunk); }
nav.pages a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
nav.pages a .n { font-size: .72rem; font-family: var(--font-mono); color: var(--muted); }
nav.pages a .badge { font-size: .7rem; background: var(--dye); color: var(--panel); border-radius: 999px; padding: 0 7px; font-family: var(--font-mono); }
.rail .foot { margin-top: auto; color: var(--muted); font-size: .75rem; display: grid; gap: 4px; }
main { padding-left: 24px; padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 22px 80px; display: grid; gap: 16px; align-content: start; min-width: 0; max-width: 1320px; }
h1 { font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; margin: 0; text-wrap: balance; }
h2 { font-size: 1.02rem; font-weight: 600; margin: 0; text-wrap: balance; }
h3 { font-size: .9rem; font-weight: 600; margin: 0; }
.lede { color: var(--muted); margin: 4px 0 0; max-width: 78ch; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 12px; min-width: 0; align-content: start; }
.note { color: var(--muted); font-size: .8rem; margin: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 2px; }
.kpi .l { color: var(--muted); font-size: .78rem; }
.kpi .v { font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.25; }
.kpi .s { font-size: .75rem; color: var(--muted); }
.kpi.alert .v { color: var(--dye); }
.mono { font-family: var(--font-mono); font-size: .78rem; color: var(--muted); }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-weight: 500; color: var(--muted); font-size: .76rem; white-space: nowrap; }
td.n, th.n { text-align: right; }
th button.sort { all: unset; cursor: pointer; }
th button.sort:focus-visible { outline: 2px solid var(--accent); }
th[aria-sort="ascending"] button.sort::after { content: " ▲"; }
th[aria-sort="descending"] button.sort::after { content: " ▼"; }
tr.sub td { border-bottom-color: transparent; }
.nm { min-width: 14rem; max-width: 24rem; }
.nm .t { font-weight: 500; }
.nm .v { color: var(--muted); font-size: .8rem; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: .74rem; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.mute { background: var(--sunk); color: var(--muted); border: 1px solid var(--line); }
.chip.acc { background: var(--accent-soft); color: var(--accent); }
.chip.dye { background: var(--dye-soft); color: var(--dye); }
.old { color: var(--muted); text-decoration: line-through; font-size: .78rem; }
.up { color: var(--bad); } .down { color: var(--ok); }
input[type=text], input[type=number], input[type=search], input[type=date], select, textarea { font: inherit; font-size: .86rem; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--ink); min-width: 0; }
textarea { width: 100%; resize: vertical; line-height: 1.55; }
input.num { width: 5.4rem; text-align: right; font-variant-numeric: tabular-nums; }
input.num.set { border-color: var(--accent); background: var(--accent-soft); }
input.num.err { border-color: var(--bad); background: var(--bad-soft); }
button { font: inherit; font-size: .84rem; cursor: pointer; border-radius: 7px; padding: 6px 12px; border: 1px solid var(--accent); background: var(--accent); color: var(--panel); white-space: nowrap; }
button.ghost { background: transparent; color: var(--accent); }
button.plain { border-color: var(--line); background: var(--panel); color: var(--ink); }
button.dye { border-color: var(--dye); background: var(--dye); color: var(--panel); }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; text-decoration: underline; }
button[disabled] { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.ck { display: inline-flex; align-items: center; gap: 6px; font-size: .86rem; }
input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); border-radius: 0; padding: 8px 14px; font-weight: 500; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.drop { border: 1.5px dashed var(--line); border-radius: var(--r); padding: 18px; display: grid; gap: 6px; justify-items: center; text-align: center; background: var(--sunk); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs figure { margin: 0; position: relative; width: 92px; height: 92px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--sunk); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs button { position: absolute; top: 3px; right: 3px; padding: 0 6px; font-size: .8rem; background: var(--panel); color: var(--ink); border-color: var(--line); }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: .78rem; color: var(--muted); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); padding-block: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bar input[type=search] { flex: 1 1 14rem; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: .85rem; z-index: 30; max-width: calc(100% - 32px); }
.banner { padding: 10px 14px; border-radius: var(--r); background: var(--warn-soft); color: var(--warn); font-size: .86rem; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.empty { color: var(--muted); padding: 22px; text-align: center; border: 1px dashed var(--line); border-radius: var(--r); }
.list { display: grid; gap: 0; }
.list .it { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.list .it:last-child { border-bottom: 0; }
.list .it .a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .it .b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars { display: grid; gap: 6px; }
.hbar { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr) 6rem; gap: 8px; align-items: center; font-size: .82rem; }
.hbar .track { height: 10px; background: var(--sunk); border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.hbar .fill { height: 100%; background: var(--accent); }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; }
svg text { fill: var(--muted); font-family: var(--font-body); font-size: 11px; }
.draft { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.draft:last-child { border-bottom: 0; }
.draft img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.stdt td.cell { white-space: nowrap; }
.stdt input.num { width: 4.4rem; }
.stdt .s2 { font-size: .72rem; color: var(--muted); line-height: 1.3; }
.stdt .s2 b { color: var(--accent); font-weight: 600; }
.tips { margin: 0; padding-left: 1.1rem; display: grid; gap: 4px; font-size: .86rem; }
.tips li::marker { color: var(--dye); }
.copyrow { display: flex; gap: 6px; align-items: flex-start; }
.copyrow > :first-child { flex: 1; }
details summary { cursor: pointer; color: var(--accent); font-size: .86rem; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: .84rem; color: var(--muted); }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.pcard { all: unset; box-sizing: border-box; cursor: pointer; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.pcard:hover { border-color: var(--accent); }
.pcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pcard .body { padding: 8px 10px 10px; display: grid; gap: 4px; align-content: start; }
.pcard .nm2 { font-size: .84rem; font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard .meta { display: flex; justify-content: space-between; gap: 6px; font-size: .8rem; font-variant-numeric: tabular-nums; align-items: center; }
.sp { background-color: var(--sunk); background-repeat: no-repeat; aspect-ratio: 1; width: 100%; max-width: 100%; display: block; }
.sp.none { display: grid; place-items: center; color: var(--muted); font-size: .75rem; }
.mini { width: 36px; min-width: 36px; height: 36px; border-radius: 6px; border: 1px solid var(--line); background-color: var(--sunk); background-repeat: no-repeat; }
.nmrow { display: flex; gap: 8px; align-items: center; min-width: 0; }
.nmrow > div { min-width: 0; }
.ov { position: fixed; inset: 0; z-index: 25; background: color-mix(in srgb, var(--ink) 45%, transparent); display: grid; place-items: center; padding: calc(16px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.ov .sheet { background: var(--panel); border-radius: 14px; width: min(920px, 100%); max-height: 100%; overflow: auto; display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 18px; padding: 18px; position: relative; }
.ov .x { position: absolute; top: 10px; right: 10px; background: var(--panel); color: var(--ink); border-color: var(--line); }
.ov .opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ov .opt { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; align-items: center; font-size: .8rem; border: 1px solid var(--line); border-radius: 8px; padding: 5px; }
.ov .opt .mini { width: 44px; height: 44px; }
@media (max-width: 700px) { .ov .sheet { grid-template-columns: 1fr; } .pgrid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { min-width: 0; }
  .rail { position: sticky; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); border-right: 0; border-bottom: 1px solid var(--line); background: var(--bg); z-index: 8; }
  .rail .foot, .skein, .brand span { display: none; }
  nav.pages { grid-auto-flow: column; overflow-x: auto; width: 100%; min-width: 0; -webkit-overflow-scrolling: touch; }
  nav.pages a { padding: 6px 10px; white-space: nowrap; }
  nav.pages a .n { display: none; }
  main { padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .bar { position: static; }
}
@media (max-width: 520px) { .draft { grid-template-columns: 72px minmax(0, 1fr); } .draft img { width: 72px; height: 72px; } .draft .acts { grid-column: 1 / -1; } .hbar { grid-template-columns: 6rem minmax(0,1fr) 5rem; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.login .card { width: min(380px, 100%); }
.login h1 { font-size: 1.4rem; }
.login input { width: 100%; padding: 9px 10px; font-size: 1rem; }
.login button { padding: 9px 12px; font-size: .95rem; }
.who { font-size: .75rem; color: var(--muted); display: grid; gap: 4px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
