:root {
  --bg: #ffffff; --surface: #f4f6f9; --border: #dde2e8; --border-input: #7c8693;
  --text: #16202b; --text-muted: #55606d; --accent: #0b6e8a; --on-accent: #ffffff;
  --danger: #b42323; --success: #1a7048; --warning: #8a5a00; --nav: #10243a; --on-nav: #e8eef5;
  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --r-sm: 6px; --r-md: 10px; --r-lg: 16px;
  --card: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
  --pop: 0 12px 32px rgba(16,24,40,.16);
  --side-w: 232px;
}
[data-theme="forest"] { --accent: #1a6b4a; --nav: #12301f; }
[data-theme="slate"] { --accent: #3d4f8f; --nav: #1d2433; }

* { box-sizing: border-box; }
html { font-family: var(--font); font-size: 16px; color: var(--text); background: var(--surface); }
body { margin: 0; line-height: 1.5; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; } h3, h2.h3 { font-size: 1.05rem; }
.pub-title { font-size: 1.5rem; margin-bottom: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--text-muted); }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: #fff; padding: 8px; z-index: 99; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.inline { display: inline; margin: 0; }

/* shell */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side { background: var(--nav); color: var(--on-nav); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--on-nav); text-decoration: none; padding: 4px 8px 16px; }
.brand.dark { color: var(--text); padding: 0; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 700; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); color: var(--on-nav); text-decoration: none; }
.nav-link:hover { background: rgba(255,255,255,.08); }
.nav-link.active { background: rgba(255,255,255,.16); font-weight: 600; }
.side-foot { margin-top: auto; padding: 8px; font-size: .875rem; }
.who small { display: block; color: #b9c6d6; }
.main { min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.top-title { font-size: 1.25rem; margin: 0; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; background: transparent; border-radius: var(--r-md); color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface); }
.badge { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; display: grid; place-items: center; }
.lang { text-decoration: none; font-weight: 600; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--r-md); color: var(--text); }
.content { padding: 24px; max-width: 1040px; }
.content.wide { max-width: 1280px; }
.pub-top { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; background: var(--bg); border-bottom: 1px solid var(--border); }
.pub { max-width: 720px; margin: 32px auto; padding: 0 16px; }
.pub.wide { max-width: 1000px; }

/* components */
.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--card); margin-bottom: 16px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.banner { background: linear-gradient(120deg, var(--nav), var(--accent)); color: #fff; border-radius: var(--r-lg); padding: 24px; margin-bottom: 16px; }
.banner h2 { margin: 0 0 4px; font-size: 1.4rem; }
.tile { display: block; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px; text-decoration: none; color: var(--text); box-shadow: var(--card); }
.tile:hover { border-color: var(--accent); }
.tile .num { font-size: 2rem; font-weight: 700; line-height: 1.1; color: var(--accent); }
.tile.hot .num { color: var(--danger); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border-radius: var(--r-md); border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--bg); color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.sm { min-height: 32px; padding: 4px 12px; font-size: .875rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .9rem; }
.hint { display: block; color: var(--text-muted); font-size: .85rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border-input); border-radius: var(--r-md); font: inherit; background: var(--bg); color: var(--text);
}
textarea { min-height: 96px; resize: vertical; }
input[type=file] { width: 100%; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); white-space: nowrap; }
.chip-ok { color: var(--success); border-color: currentColor; background: #eaf6ef; }
.chip-warn { color: var(--warning); border-color: currentColor; background: #fff6e0; }
.chip-bad { color: var(--danger); border-color: currentColor; background: #fdeeee; }
.chip-info { color: var(--accent); border-color: currentColor; background: #e7f3f7; }
.flash { padding: 12px 16px; border-radius: var(--r-md); margin-bottom: 16px; border: 1px solid; }
.flash-ok { background: #eaf6ef; color: var(--success); } .flash-err { background: #fdeeee; color: var(--danger); } .flash-info { background: #e7f3f7; color: var(--accent); }
.callout { border-left: 4px solid var(--accent); background: #e7f3f7; padding: 12px 16px; border-radius: var(--r-sm); margin: 12px 0; }
.callout-warn { border-color: var(--warning); background: #fff6e0; } .callout-bad { border-color: var(--danger); background: #fdeeee; }
.empty { text-align: center; padding: 32px 16px; color: var(--text-muted); border: 1px dashed var(--border-input); border-radius: var(--r-lg); background: var(--bg); }
table { width: 100%; border-collapse: collapse; background: var(--bg); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .85rem; color: var(--text-muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 10px 16px; text-decoration: none; color: var(--text-muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tab.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.pills { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.pill { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border-input); text-decoration: none; color: var(--text); background: var(--bg); font-size: .9rem; }
.pill.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 20px; overflow-x: auto; }
.steps li { flex: 1 0 auto; min-width: 84px; text-align: center; font-size: .8rem; color: var(--text-muted); padding-top: 8px; border-top: 4px solid var(--border); }
.steps li.done { border-color: var(--accent); color: var(--text); } .steps li.cur { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 14px 28px; color: var(--text-muted); }
.timeline li::before { content: ''; position: absolute; left: 4px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--border); }
.timeline li::after { content: ''; position: absolute; left: 9px; top: 18px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline li.done { color: var(--text); } .timeline li.done::before { background: var(--accent); }
.timeline li.cur { color: var(--accent); font-weight: 700; } .timeline li.cur::before { background: var(--accent); box-shadow: 0 0 0 4px #cfe7ee; }
.item-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.item-row:last-child { border-bottom: 0; }
.list-card { display: block; text-decoration: none; color: inherit; }
.msg { padding: 10px 14px; border-radius: var(--r-md); background: var(--surface); margin-bottom: 8px; }
.msg.mine { background: #e7f3f7; } .msg small { display: block; }
.remark { color: var(--danger); font-weight: 700; }
.opt { display: block; border: 2px solid var(--border); border-radius: var(--r-lg); padding: 16px; text-decoration: none; color: var(--text); background: var(--bg); }
.opt:hover, .opt.sel { border-color: var(--accent); }
.mono { font-family: var(--mono); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); }
.cal > div { background: var(--bg); min-height: 80px; padding: 4px; font-size: .8rem; }
.cal .dow { min-height: 0; background: var(--surface); font-weight: 600; text-align: center; }
.cal .closed { background: #e9ebee; }
.ev { display: block; border-radius: 4px; padding: 1px 6px; margin-top: 2px; background: #e7f3f7; color: var(--accent); text-decoration: none; }
.ev.measure { background: #fff6e0; color: var(--warning); } .ev.cert { background: #eaf6ef; color: var(--success); }
.idle { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: grid; place-items: center; z-index: 50; }
.idle[hidden] { display: none; }
.idle-card { background: var(--bg); border-radius: var(--r-lg); padding: 24px; box-shadow: var(--pop); max-width: 360px; }
.hero { text-align: center; padding: 48px 16px; }
.hero h1 { font-size: 2rem; }

/* print documents */
.print-body { background: #fff; }
.doc { max-width: 800px; margin: 24px auto; padding: 32px; font-size: 14px; background: #fff; }
.doc h1 { font-size: 22px; } .doc table th, .doc table td { padding: 6px 8px; }
.doc .toolbar { margin-bottom: 16px; display: flex; gap: 8px; }
@media print { .toolbar { display: none !important; } .doc { margin: 0; padding: 0; } }

/* mobile */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; justify-content: space-around; padding: 6px; z-index: 20; }
  .side .brand, .side-foot { display: none; }
  .nav-link { flex-direction: column; gap: 2px; font-size: .7rem; padding: 6px 8px; }
  .main { padding-bottom: 76px; }
  .content { padding: 16px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .grid.c4.keep { grid-template-columns: repeat(2, 1fr); }
  .top { padding: 10px 16px; }
  table.resp thead { display: none; }
  table.resp td { display: block; border: 0; padding: 4px 12px; }
  table.resp tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
