/* HeadQ — ระบบคนงาน & หัวคิว (ต้นแบบ)
   ดีไซน์ตามชุด ERP ของ Ozariam (demosap / MaidERP): accent เดียว #2563eb · พื้น #f6f8fb · เส้น #eef1f5 · ตัวหนังสือโทน slate
   กฎ: ไม่มี backdrop-filter/blur · modal อยู่กลางจอ · dropdown ทุกตัวค้นหาได้ · ข้อความไทยยาวต้องตัดบรรทัดได้ (overflow-wrap) */

:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --hover: #f2f5fa;
  --row-hover: #f6f9fe;
  --line: #eef1f5;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-2: #334155;
  --ink-3: #475569;
  --muted: #64748b;
  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --brand-soft: #eaf1ff;
  --brand-track: #dbe7fd;
  --ring: rgba(37, 99, 235, 0.22);
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --ok-mark: #16a34a;
  --ok-track: #d3f0dc;
  --warn: #b45309;
  --warn-soft: #fff4e2;
  --warn-mark: #f59e0b;
  --warn-track: #fdebc8;
  --crit: #b91c1c;
  --crit-soft: #fdeded;
  --crit-mark: #dc2626;
  --crit-track: #f9d6d6;
  --info: #0e6aa8;
  --info-soft: #e7f3fb;
  /* ชุดสีกราฟ (ตรวจแล้ว: แยกได้สำหรับคนตาบอดสี เรียงตามลำดับนี้) */
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --spark: #94a3b8;
  --r-sm: 8px;
  --r: 10px;
  --r-md: 14px;
  --r-lg: 16px;
  --r-xl: 18px;
  --sh-1: 0 1px 2px rgba(15, 23, 42, 0.05);
  --sh-pop: 0 12px 32px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.06);
  --font: 'Inter', 'IBM Plex Sans Thai', 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --sbw: 248px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-2);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
body.modal-open { overflow: hidden; }
h1, h2, h3, h4 { color: var(--ink); line-height: 1.3; margin: 0; text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-strong); text-decoration: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
[hidden] { display: none !important; }
.i { flex: none; }
.bw { overflow-wrap: anywhere; min-width: 0; }
.muted { color: var(--muted); }
.tnum, .num { font-variant-numeric: tabular-nums; }
.grow { flex: 1; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ok-t { color: var(--ok); }
.warn-t { color: var(--warn); }
.crit-t { color: var(--crit); }
.mt { margin-top: 16px; }
.mt-s { margin-top: 8px; }
.mb { margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.sp { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.h3 { font-size: 14px; font-weight: 700; margin: 18px 0 8px; }
.hint { display: block; font-size: 12.5px; color: var(--muted); }
.err { display: block; font-size: 12.5px; color: var(--crit); font-weight: 500; }
small.sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }

/* ---------- โครงหน้า ---------- */
.app { display: grid; grid-template-columns: var(--sbw) minmax(0, 1fr); min-height: 100vh; }
.sb {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; overflow-x: hidden;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 40;
}
.sb-top { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; min-height: 64px; }
.logo {
  width: 38px; height: 38px; border-radius: 11px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; letter-spacing: -0.02em; flex: none;
}
.brand-t { min-width: 0; }
.brand-t b { display: block; color: var(--ink); font-size: 16.5px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.brand-t span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; }
.nav { padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-g { font-size: 11.5px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; padding: 14px 10px 6px; white-space: nowrap; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border-radius: var(--r);
  color: var(--ink-3); font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--hover); color: var(--ink); }
.nav a.on { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
.nav a span { overflow: hidden; text-overflow: ellipsis; }
.nb {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  display: inline-grid; place-items: center; background: var(--warn-soft); color: var(--warn);
}
.nb.crit { background: var(--crit-soft); color: var(--crit); }
.sb-foot { padding: 12px 18px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 60px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; padding: 0 24px;
}
.tb-btn {
  width: 38px; height: 38px; border-radius: var(--r); border: 1px solid transparent; background: transparent;
  display: grid; place-items: center; color: var(--ink-3); flex: none;
}
.tb-btn:hover { background: var(--hover); color: var(--ink); }
.tb-title { font-weight: 600; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-sp { flex: 1; }
.per-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; color: var(--ink-3); white-space: nowrap;
}
.demo-badge {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn); font-size: 12px; font-weight: 600; white-space: nowrap; cursor: default;
}
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; }
.content { width: 100%; max-width: 1440px; margin: 0 auto; padding: 24px 24px 56px; outline: none; }
.scrim { display: none; }
.only-m { display: none; }

@media (min-width: 1024px) {
  .app.sb-min { --sbw: 76px; }
  .sb-min .brand-t, .sb-min .nav a span, .sb-min .sb-foot, .sb-min .nb { display: none; }
  .sb-min .sb-top { justify-content: center; padding-inline: 0; }
  .sb-min .nav-g { font-size: 0; padding: 8px 0; margin: 0 14px; border-top: 1px solid var(--line); }
  .sb-min .nav-g:first-child { border-top: 0; }
  .sb-min .nav a { justify-content: center; padding: 0; }
}
@media (max-width: 1023px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sb {
    position: fixed; left: 0; top: 0; bottom: 0; width: 280px; height: auto;
    transform: translateX(-102%); transition: transform 0.2s ease; box-shadow: var(--sh-pop); z-index: 80;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .app.nav-open .sb { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4); z-index: 70; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .only-m { display: grid; }
  .only-d { display: none; }
  .topbar { padding: env(safe-area-inset-top, 0px) 12px 0; height: calc(56px + env(safe-area-inset-top, 0px)); gap: 6px; }
  .content { padding: 16px 16px 48px; }
  .per-chip .t2, .demo-badge .t { display: none; }
  .demo-badge { padding: 0 8px; }
}
@media (max-width: 420px) {
  .per-chip { padding: 0 10px; font-size: 12.5px; }
  .tb-title { font-size: 14.5px; }
}

/* ---------- หัวหน้า ---------- */
.ph { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 18px; }
.ph-t { min-width: 0; flex: 1 1 320px; }
.eyebrow { font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; color: var(--brand-strong); margin-bottom: 2px; }
.ph h1 { font-size: 23px; font-weight: 700; letter-spacing: -0.01em; }
.ph-sub { color: var(--muted); margin-top: 4px; font-size: 13.5px; overflow-wrap: anywhere; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ph-a { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- ปุ่ม / ช่องกรอก ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px;
  border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  font-weight: 500; white-space: nowrap; text-decoration: none; line-height: 1;
}
.btn:hover { background: var(--hover); border-color: var(--border-strong); color: var(--ink); text-decoration: none; }
.btn.on { background: var(--brand-soft); border-color: #c7d8fb; color: var(--brand-strong); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn-danger:hover { background: #991b1b; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
.btn[disabled], .btn[disabled]:hover { opacity: 0.45; cursor: not-allowed; background: var(--surface); color: var(--ink-3); border-color: var(--border); box-shadow: none; }
.btn-primary[disabled], .btn-primary[disabled]:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.inp {
  height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface);
  width: 100%; min-width: 0; color: var(--ink);
}
.inp:hover { border-color: var(--border-strong); }
.inp:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.inp.num { text-align: right; font-variant-numeric: tabular-nums; }
.inp.sm { height: 32px; width: 96px; padding: 0 8px; }
.inp::placeholder { color: #94a3b8; }
.search { position: relative; min-width: 200px; }
.search .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .inp { padding-left: 34px; }
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld > label { font-size: 12.5px; font-weight: 600; color: var(--ink-3); }
.fld > label em { color: var(--crit); font-style: normal; }
.fld .s2 { width: 100%; }
.form-g { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-g .full { grid-column: 1 / -1; }
.sec-t { grid-column: 1 / -1; font-size: 13px; font-weight: 700; color: var(--ink); padding-top: 6px; border-top: 1px solid var(--line); margin-top: 4px; }
.sec-t:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
@media (max-width: 560px) { .form-g { grid-template-columns: minmax(0, 1fr); } }

/* dropdown ค้นหาได้ */
.s2 {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; min-width: 150px; max-width: 100%;
  padding: 0 10px 0 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface);
  color: var(--ink-2); text-align: left;
}
.s2:hover { border-color: var(--border-strong); }
.s2[aria-expanded='true'] { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.s2 > .i:first-child { color: var(--muted); }
.s2 > .i:last-child { color: var(--muted); margin-left: auto; }
.s2-val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.s2-ph { color: var(--muted); }
.s2[disabled] { opacity: 0.5; cursor: not-allowed; }
#s2pop {
  position: fixed; z-index: 1000; display: none; flex-direction: column; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-pop); padding: 6px;
}
.s2-sw { position: relative; flex: none; }
.s2-sw .i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.s2-search { width: 100%; height: 36px; border: 1px solid var(--border); border-radius: 9px; padding: 0 10px 0 32px; background: var(--surface-2); }
.s2-search:focus { outline: none; border-color: var(--brand); background: var(--surface); }
.s2-list { list-style: none; margin: 6px 0 0; padding: 0; overflow-y: auto; min-height: 0; flex: 1; overscroll-behavior: contain; }
.s2-list li[data-i] { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.s2-list li[data-i]:hover, .s2-list li.act { background: var(--hover); }
.s2-list li[aria-selected='true'] { color: var(--brand-strong); font-weight: 600; }
.s2-list li[aria-selected='true'] .i { color: var(--brand); }
.s2-t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.s2-s { color: var(--muted); font-size: 12px; font-weight: 400; white-space: nowrap; }
.s2-g { font-size: 11.5px; color: var(--muted); font-weight: 600; padding: 8px 10px 4px; }
.s2-empty { padding: 12px 10px; color: var(--muted); font-size: 13px; }

/* segmented / tabs / switch */
.seg { display: inline-flex; background: var(--hover); border-radius: var(--r); padding: 3px; gap: 2px; flex-wrap: nowrap; }
.seg button { height: 30px; padding: 0 11px; border: 0; background: transparent; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--ink-3); white-space: nowrap; }
.seg button:hover:not([disabled]) { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); font-weight: 600; }
.seg button[disabled] { cursor: not-allowed; opacity: 0.55; }
.seg.sm button { height: 26px; padding: 0 9px; font-size: 12.5px; }
.seg.att button.on[data-s='P'] { background: var(--ok-soft); color: var(--ok); }
.seg.att button.on[data-s='L'] { background: var(--warn-soft); color: var(--warn); }
.seg.att button.on[data-s='A'] { background: var(--crit-soft); color: var(--crit); }
.seg.att button.on[data-s='S'] { background: var(--info-soft); color: var(--info); }
.seg.att button.on[data-s='V'] { background: #e2e8f0; color: var(--ink); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 4px 0 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  height: 42px; padding: 0 12px; border: 0; background: transparent; color: var(--ink-3); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--brand-strong); border-bottom-color: var(--brand); font-weight: 600; }
.tabs .n { font-size: 11.5px; background: var(--hover); color: var(--ink-3); border-radius: 999px; padding: 1px 7px; font-weight: 600; }
.tabs button.on .n { background: var(--brand-soft); color: var(--brand-strong); }
.sw { position: relative; width: 42px; height: 24px; flex: none; }
.sw input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.sw span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background 0.15s; }
.sw span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--sh-1); transition: transform 0.15s; }
.sw input:checked + span { background: var(--brand); }
.sw input:checked + span::after { transform: translateX(18px); }
.sw input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.sw-row { display: flex; gap: 14px; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.sw-row:last-child { border-bottom: 0; }
.sw-row b { display: block; color: var(--ink); font-weight: 600; }
.sw-row small { display: block; color: var(--muted); font-size: 12.5px; }

/* ป้าย */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--hover); color: var(--ink-3); line-height: 1; vertical-align: middle;
}
.chip.sm { height: 21px; padding: 0 8px; font-size: 11.5px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.crit { background: var(--crit-soft); color: var(--crit); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.brand { background: var(--brand-soft); color: var(--brand-strong); }
.chip.o { background: transparent; border: 1px solid var(--border); color: var(--ink-3); font-weight: 500; }
.note {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--r-md); margin: 0 0 14px;
  font-size: 13.5px; background: var(--info-soft); color: #0b4f7c; overflow-wrap: anywhere;
}
.note > .i { margin-top: 2px; }
.note > span { flex: 1; min-width: 0; }
.note .btn { flex: none; }
.note.ok { background: var(--ok-soft); color: #14532d; }
.note.warn { background: var(--warn-soft); color: #7c2d12; }
.note.crit { background: var(--crit-soft); color: #7f1d1d; }
.note.mt { margin-top: 14px; margin-bottom: 0; }

/* ---------- การ์ด / KPI ---------- */
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3-1 { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g-2, .g-3-1 { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; }
.card-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px 12px; padding: 16px 18px 10px; flex-wrap: wrap; }
.card-h h2 { font-size: 15.5px; font-weight: 700; }
.card-h .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.card-b { padding: 4px 18px 18px; min-width: 0; }
.card-b.form-g { padding-top: 8px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kpis.k4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kpi { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px 14px 19px; overflow: hidden; min-width: 0; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--kc, var(--brand)); }
.kpi .lb { color: var(--muted); font-size: 12.5px; font-weight: 500; overflow-wrap: anywhere; }
.kpi .v { font-size: 25px; font-weight: 700; color: var(--ink); margin-top: 3px; letter-spacing: -0.015em; line-height: 1.25; white-space: nowrap; }
.kpi .v small { font-size: 14px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.kpi .s { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; overflow-wrap: anywhere; }
.kpi-spark { margin-top: 8px; border-radius: 6px; width: max-content; max-width: 100%; }
.spark { display: block; max-width: 100%; height: auto; }
.nw { white-space: nowrap; }
@media (max-width: 560px) {
  .kpis, .kpis.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpis > .kpi:first-child:nth-last-child(odd) { grid-column: 1 / -1; }
  .kpi { padding: 12px 12px 12px 15px; }
  .kpi .v { font-size: 21px; }
  .kpi .s { font-size: 12px; }
}

/* แจ้งเตือน */
.alerts { display: flex; flex-direction: column; }
@media (max-width: 1100px) { .al-card { order: -1; } }
.al {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px; align-items: center;
  padding: 10px 8px; margin: 0 -8px; border-radius: 10px; color: inherit; border-bottom: 1px solid var(--line);
}
.al:last-child { border-bottom: 0; }
.al:hover { background: var(--row-hover); text-decoration: none; }
.al > .i { color: var(--border-strong); }
.al-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; }
.al.crit .al-ic { background: var(--crit-soft); color: var(--crit); }
.al.warn .al-ic { background: var(--warn-soft); color: var(--warn); }
.al.info .al-ic { background: var(--brand-soft); color: var(--brand-strong); }
.al-t { display: block; font-weight: 600; color: var(--ink); font-size: 13.5px; }
.al-d { display: block; font-size: 12.5px; color: var(--muted); }
.al-n { font-weight: 700; color: var(--ink); font-size: 15px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.al-n small { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------- กราฟ ---------- */
.legend { display: flex; gap: 8px 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-3); margin: 2px 0 12px; align-items: center; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.ub { display: flex; flex-direction: column; }
.ub-row { display: grid; grid-template-columns: minmax(110px, 170px) minmax(0, 1fr) 76px; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ub-row:last-child { border-bottom: 0; }
.ub-l b { display: block; font-size: 13.5px; color: var(--ink); font-weight: 600; }
.ub-l small { display: block; font-size: 12px; color: var(--muted); }
.ub-track { min-width: 0; }
.ub-bar { display: flex; gap: 2px; height: 22px; }
.ub-seg { display: flex; align-items: center; justify-content: center; height: 100%; flex-basis: 0; min-width: 3px; font-size: 11.5px; font-weight: 700; overflow: hidden; }
.ub-seg:last-child { border-radius: 0 4px 4px 0; }
.ub-seg:hover, .ub-seg:focus-visible { filter: brightness(1.08); outline-offset: 1px; }
.ub-v { text-align: right; }
.ub-v b { display: block; font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }
.ub-v small { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
@media (max-width: 560px) {
  .ub-row { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; }
  .ub-track { grid-column: 1 / -1; grid-row: 2; }
  .ub-v { grid-column: 2; grid-row: 1; }
}
.mini-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.mini-stats > div { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.mini-stats span { display: block; font-size: 12px; color: var(--muted); }
.mini-stats b { display: block; font-size: 17px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-stats b small { font-size: 12px; color: var(--muted); font-weight: 500; }
.mini-stats > div > small { display: block; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
@media (max-width: 560px) { .mini-stats { grid-template-columns: minmax(0, 1fr); } }
.hb { display: flex; flex-direction: column; }
.hb-row { display: grid; grid-template-columns: minmax(96px, 150px) minmax(0, 1fr); gap: 12px; align-items: center; padding: 7px 6px; margin: 0 -6px; border-radius: 8px; }
.hb-row[role='button'] { cursor: pointer; }
.hb-row:hover { background: var(--row-hover); }
.hb-l b { display: block; font-size: 13.5px; color: var(--ink); font-weight: 600; }
.hb-l small { display: block; font-size: 12px; color: var(--muted); }
.hb-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hb-track i { display: block; height: 16px; border-radius: 0 4px 4px 0; min-width: 3px; flex: none; }
.hb-v { font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.meter { --mc: var(--brand); --mtk: var(--brand-track); height: 8px; background: var(--mtk); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.meter > i { display: block; height: 100%; background: var(--mc); border-radius: 0 4px 4px 0; }
.meter.warn { --mc: var(--warn-mark); --mtk: var(--warn-track); }
.meter.crit { --mc: var(--crit-mark); --mtk: var(--crit-track); }
.hc { display: flex; flex-direction: column; gap: 4px; }
.hc-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.hc-row:last-child { border-bottom: 0; }
.hc-t { display: flex; justify-content: space-between; gap: 10px; }
.hc-t b { font-weight: 600; color: var(--ink); }
.hc-t span { color: var(--ink-3); white-space: nowrap; font-weight: 600; }
.hc-s { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12.5px; }

/* tooltip */
#tip {
  position: fixed; z-index: 2000; display: none; pointer-events: none; max-width: 280px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--sh-pop);
  padding: 8px 11px; font-size: 12.5px; color: var(--ink-3); line-height: 1.5;
}
#tip b { color: var(--ink); font-size: 13.5px; }

/* ---------- ตาราง ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.card-b .tbl-wrap { border-radius: 12px; }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.tbl th {
  background: var(--surface-2); color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em;
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tfoot td { background: var(--surface-2); font-weight: 600; color: var(--ink); border-top: 1px solid var(--line); border-bottom: 0; white-space: nowrap; }
.tbl th.num, .tbl td.num { text-align: right; white-space: nowrap; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td, .tbl tr.click:focus-visible td { background: var(--row-hover); }
.tbl tr.click:focus-visible { outline: none; }
.tbl tr.crit-row td:first-child { box-shadow: inset 3px 0 0 var(--crit-mark); }
.tbl tr.warn-row td { background: #fffaf0; }
.tbl .who { min-width: 190px; }
.pay-tbl td, .pay-tbl th { padding-inline: 10px; }
.rate-tbl .err { margin-top: 4px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 2px 0; flex-wrap: wrap; font-size: 13px; }
.pg-n { min-width: 56px; text-align: center; font-weight: 600; color: var(--ink-3); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who b { display: block; color: var(--ink); font-weight: 600; font-size: 13.5px; line-height: 1.35; }
.who small { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; }
.ava {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700;
  flex: none; color: #fff; background: var(--ava, #64748b);
}
.ava.lg { width: 44px; height: 44px; font-size: 17px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 28px 12px; color: var(--muted); text-align: center; }
.empty b { color: var(--ink-2); }
.empty p { font-size: 13px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .grow { flex: 1 1 220px; }
@media (max-width: 640px) {
  .toolbar .s2 { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .toolbar .search { flex: 1 1 100%; }
}

/* ---------- ลงเวลา ---------- */
.datenav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dn-t { font-weight: 600; color: var(--ink); min-width: 150px; text-align: center; white-space: nowrap; }
.att-sum { display: flex; gap: 6px 14px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; color: var(--ink-3); }
.att-sum.sm { margin: 10px 0 0; font-size: 12.5px; gap: 4px 12px; }
.as { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.as b { color: var(--ink); }
.as i { width: 9px; height: 9px; border-radius: 3px; background: var(--border-strong); }
.as.P i { background: var(--ok-mark); }
.as.L i { background: var(--warn-mark); }
.as.A i { background: var(--crit-mark); }
.as.S i { background: var(--info); }
.as.V i { background: var(--muted); }
.as.none i { background: transparent; border: 1.5px dashed var(--border-strong); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface); }
.stepper button { width: 30px; height: 30px; border: 0; background: transparent; display: grid; place-items: center; color: var(--ink-3); }
.stepper button:hover:not([disabled]) { background: var(--hover); color: var(--ink); }
.stepper button[disabled] { opacity: 0.35; cursor: not-allowed; }
.stepper span { min-width: 28px; text-align: center; font-weight: 700; color: var(--ink); }
.stepper.dis span { color: var(--muted); font-weight: 500; }
.ot-l { display: none; font-size: 12px; color: var(--muted); margin-left: 6px; }
.c-flag { white-space: nowrap; }
.c-flag .chip + .chip { margin-left: 4px; }
@media (max-width: 720px) {
  .att-tbl thead { display: none; }
  .att-tbl, .att-tbl tbody { display: block; }
  .att-tbl tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .att-tbl tbody tr:last-child { border-bottom: 0; }
  .att-tbl td { display: block; border: 0; padding: 0; }
  .att-tbl .c-who { grid-column: 1 / -1; }
  .att-tbl .c-seg { grid-column: 1 / -1; }
  .att-tbl .seg { display: flex; width: 100%; }
  .att-tbl .seg button { flex: 1; padding: 0 4px; height: 34px; }
  .att-tbl .c-ot { display: flex; align-items: center; }
  .att-tbl .ot-l { display: inline; }
  .att-tbl .c-flag { text-align: right; white-space: normal; }
}
.ag-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
table.ag { border-collapse: separate; border-spacing: 0; font-size: 12.5px; min-width: 100%; }
.ag th, .ag td { border-bottom: 1px solid var(--line); padding: 5px 2px; text-align: center; white-space: nowrap; }
.ag tr:last-child td { border-bottom: 0; }
.ag th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 11.5px; line-height: 1.25; padding: 7px 2px; }
.ag th small { display: block; font-weight: 500; font-size: 10.5px; }
.ag th.sun { color: var(--crit); }
.ag .today { background: var(--brand-soft); }
.ag th.today { color: var(--brand-strong); }
.ag .nm { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; padding: 6px 12px; min-width: 200px; border-right: 1px solid var(--line); }
.ag th.nm { background: var(--surface-2); z-index: 2; color: var(--ink-3); }
.ag .tot { padding-inline: 10px; font-size: 13px; color: var(--ink); background: var(--surface-2); }
.ag .tot:first-of-type { border-left: 1px solid var(--line); }
.cell {
  width: 30px; height: 28px; border-radius: 7px; display: inline-grid; place-items: center; font-weight: 700; font-size: 12px;
  border: 0; background: transparent; color: var(--muted); padding: 0; vertical-align: middle;
}
button.cell:hover:not([disabled]) { box-shadow: inset 0 0 0 1.5px var(--brand); }
button.cell[disabled] { cursor: default; }
.cell.P { background: var(--ok-soft); color: var(--ok); }
.cell.L { background: var(--warn-soft); color: var(--warn); }
.cell.A { background: var(--crit-soft); color: var(--crit); }
.cell.S { background: var(--info-soft); color: var(--info); }
.cell.V { background: var(--hover); color: var(--ink-3); }
.cell.none { border: 1.5px dashed var(--border-strong); width: 28px; height: 26px; }
.cell.off { color: var(--border-strong); font-weight: 500; }
.cell.fut { color: var(--border-strong); }
.cell.other { background: var(--hover); color: var(--muted); font-weight: 500; font-size: 11px; }
.att-lg { font-size: 12px; gap: 6px 14px; }
.att-lg .cell { width: 22px; height: 20px; font-size: 11px; border-radius: 5px; }
.att-lg .cell.none { width: 20px; height: 18px; }

/* ---------- โรงงาน ---------- */
.fac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.fac { display: flex; flex-direction: column; padding: 16px 18px; gap: 4px; }
.fac-h { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.fac-h h3 { font-size: 16px; font-weight: 700; }
.fac-h p { font-size: 12.5px; margin-top: 2px; }
.fac-hc { margin-top: 10px; font-size: 13px; }
.fac-kv { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.fac-kv span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.fac-kv b { display: block; font-size: 14px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fac-f { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.fac-ic { width: 44px; height: 44px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-strong); display: grid; place-items: center; flex: none; }
@media (max-width: 400px) { .fac-kv { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pick-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.pick {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; flex-wrap: wrap;
}
.pick:hover { background: var(--row-hover); }
.pick.on { border-color: #b9cffa; background: var(--brand-soft); }
.pick.dis { opacity: 0.6; cursor: not-allowed; }
.pick input { width: 18px; height: 18px; accent-color: var(--brand); flex: none; margin: 0; }
.pick .who { flex: 1 1 220px; }

/* ---------- สาย ---------- */
.br-list { border-top: 1px solid var(--line); }
.br-group { border-bottom: 1px solid var(--line); }
.br-group:last-child { border-bottom: 0; }
.br-row {
  display: grid; grid-template-columns: minmax(210px, 1.5fr) minmax(0, 1.5fr) repeat(4, minmax(84px, 0.7fr));
  gap: 12px; align-items: center; padding: 12px 18px; cursor: pointer;
}
.br-row.static { cursor: default; }
.br-row:not(.static):hover { background: var(--row-hover); }
.br-row + .br-row { border-top: 1px dashed var(--line); }
.br-who { display: flex; align-items: center; gap: 10px; min-width: 0; position: relative; }
.br-who b { display: block; color: var(--ink); font-weight: 700; }
.br-who small { display: block; font-size: 12px; color: var(--muted); }
.lvl1 .br-who { padding-left: 34px; }
.lvl1 .br-who::before { content: ''; position: absolute; left: 14px; top: -14px; width: 12px; height: 30px; border-left: 1.5px solid var(--border-strong); border-bottom: 1.5px solid var(--border-strong); border-bottom-left-radius: 8px; }
.br-rule { display: flex; gap: 5px; flex-wrap: wrap; min-width: 0; }
.br-stat span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.br-stat b { display: block; font-size: 14.5px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.br-stat small { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
@media (max-width: 1100px) {
  .br-row { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  .br-who, .br-rule { grid-column: 1 / -1; }
}
@media (max-width: 520px) { .br-row { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px 14px; } }
.pv-box { display: grid; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13.5px; }
.pv-box span { font-size: 12px; }
.pv-box p { color: var(--ink-2); }
.mini-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.mini-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.mini-list > div:last-child { border-bottom: 0; }
.mini-list b { color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.mini-list .tot { background: var(--surface-2); font-weight: 600; }

/* ---------- เงิน ---------- */
.strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 14px; overflow: hidden; }
.strip > div { padding: 12px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; min-width: 0; }
.strip span { display: block; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.strip b { display: block; font-size: 16px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 700px) { .strip { grid-template-columns: repeat(2, minmax(0, 1fr)); } .strip > div { padding: 10px 12px; } .strip b { font-size: 15px; } }
.pl { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.pl span { min-width: 0; overflow-wrap: anywhere; }
.pl b { white-space: nowrap; color: var(--ink); }
.pl.tot { border-bottom: 0; border-top: 2px solid var(--ink); margin-top: 2px; padding-top: 11px; font-weight: 700; font-size: 15px; color: var(--ink); }
.pl.tot small { font-weight: 500; color: var(--muted); font-size: 12.5px; }
.cks { display: flex; flex-direction: column; gap: 8px; }
.ck { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.ck-i { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.ck.ok .ck-i { background: var(--ok-soft); color: var(--ok); }
.ck.warn .ck-i { background: var(--warn-soft); color: var(--warn); }
.ck.crit .ck-i { background: var(--crit-soft); color: var(--crit); }
.ck.info .ck-i { background: var(--brand-soft); color: var(--brand-strong); }
.ck b { display: block; color: var(--ink); font-weight: 600; }
.ck small { display: block; color: var(--muted); font-size: 12.5px; }
.close-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 14px; }
.close-sum > div { padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); }
.close-sum span { display: block; font-size: 12px; color: var(--brand-strong); }
.close-sum b { display: block; font-size: 15px; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* เอกสาร (สลิป / ใบวางบิล) */
.doc { border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px; background: var(--surface); }
.doc-h { display: flex; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.doc-h b { display: block; color: var(--ink); font-size: 15px; }
.doc-h small { display: block; font-size: 12.5px; color: var(--muted); }
.doc-r { text-align: right; }
@media (max-width: 560px) { .doc-r { text-align: left; } }
.doc-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 640px) { .doc-2 { grid-template-columns: minmax(0, 1fr); } }
.doc table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.doc th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 600; padding: 6px 0; border-bottom: 1px solid var(--line); }
.doc td { padding: 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc th.num, .doc td.num { text-align: right; padding-left: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc tfoot td { font-weight: 700; color: var(--ink); border-bottom: 0; }
.doc tr.warn-row td { background: #fffaf0; }
.doc .chip { margin-left: 4px; }
.doc-net { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--brand-soft); }
.doc-net span { color: var(--brand-strong); font-weight: 600; }
.doc-net b { font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.checks .chip { height: auto; min-height: 24px; padding: 4px 9px; white-space: normal; line-height: 1.35; }
.bill-to { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); margin-bottom: 12px; }
.bill-to span, .bill-to small { display: block; font-size: 12.5px; }
.bill-to b { display: block; color: var(--ink); }
table.inv tfoot td { font-weight: 500; color: var(--ink-2); }
table.inv tfoot tr.grand td { font-weight: 700; color: var(--ink); font-size: 14.5px; border-top: 1px solid var(--border); }
.kv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
@media (max-width: 560px) { .kv-grid { grid-template-columns: minmax(0, 1fr); } }
.kv { display: flex; flex-direction: column; gap: 1px; padding: 9px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.kv span { font-size: 12px; color: var(--muted); }
.kv b { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.act-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.subform { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.subform .hint { margin-top: 8px; }
.cal-block + .cal-block { margin-top: 10px; }
.cal-block .h3 { margin: 10px 0 8px; }
.mcal { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 5px; }
.mc {
  position: relative; display: grid; place-items: center; height: 34px; border-radius: 8px; background: var(--hover);
  font-size: 12.5px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.mc em { font-style: normal; }
.mc i { position: absolute; right: 3px; top: 1px; font-style: normal; font-size: 9.5px; font-weight: 700; }
.mc.P { background: var(--ok-soft); color: var(--ok); }
.mc.L { background: var(--warn-soft); color: var(--warn); }
.mc.A { background: var(--crit-soft); color: var(--crit); }
.mc.S { background: var(--info-soft); color: var(--info); }
.mc.V { background: #e9edf3; color: var(--ink-3); }
.mc.none { background: transparent; border: 1.5px dashed var(--border-strong); }
.mc.off { background: transparent; color: var(--border-strong); }
.mc.fut { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.att-lg .mc { width: 18px; height: 16px; border-radius: 4px; }

/* ---------- modal / toast ---------- */
.ov {
  position: fixed; inset: 0; z-index: 500; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade 0.15s ease;
}
.md {
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh-pop); width: min(620px, 100%);
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; animation: pop 0.18s ease; min-width: 0;
}
.md.lg { width: min(880px, 100%); }
.md-h { display: flex; gap: 12px; align-items: flex-start; padding: 18px 18px 14px 20px; border-bottom: 1px solid var(--line); }
.md-ht { flex: 1; min-width: 0; }
.md-h h2 { font-size: 17px; font-weight: 700; }
.md-sub { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.md-b { padding: 16px 20px 20px; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.md-b > .tabs:first-child { margin-top: -8px; }
.md-f { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.md-f .grow { font-size: 13px; }
@media (max-width: 560px) {
  .md-h { padding: 14px 12px 12px 16px; }
  .md-b { padding: 14px 16px 16px; }
  .md-f { padding: 10px 16px; }
}
@keyframes pop { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  display: flex; gap: 10px; align-items: flex-start; max-width: min(440px, calc(100vw - 32px)); padding: 11px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--sh-pop);
  font-size: 13.5px; color: var(--ink); animation: pop 0.18s ease; pointer-events: auto; overflow-wrap: anywhere;
}
.toast .i { margin-top: 1px; }
.toast.ok .i { color: var(--ok); }
.toast.warn .i { color: var(--warn); }
.toast.crit .i { color: var(--crit); }
.toast.info .i { color: var(--brand); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@media (max-width: 560px) { #toasts { left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); align-items: stretch; } .toast { max-width: none; } }

/* ---------- หน้าจอมือถือ (ตัวอย่าง) ---------- */
.phones { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; }
.pv { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.pv-h { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; flex-wrap: wrap; max-width: 380px; width: 100%; margin: 0 auto; }
.pv-h h2 { font-size: 16px; font-weight: 700; }
.pv-h p { font-size: 12.5px; }
.pv-h .s2 { min-width: 170px; }
.phone { width: 100%; max-width: 360px; margin: 0 auto; border-radius: 34px; border: 1px solid var(--border-strong); background: var(--surface); box-shadow: var(--sh-pop); padding: 10px; position: relative; }
.phone-notch { width: 96px; height: 6px; border-radius: 999px; background: var(--border); margin: 4px auto 8px; }
.phone-scr { border-radius: 26px; background: #f3f6fb; overflow: hidden; padding: 16px 14px 18px; min-height: 600px; display: flex; flex-direction: column; gap: 10px; }
.ps-top small { display: block; font-size: 11.5px; color: var(--muted); }
.ps-top b { display: block; font-size: 19px; color: var(--ink); line-height: 1.3; }
.ps-hero { border-radius: 18px; padding: 14px 16px; background: var(--brand); color: #fff; }
.ps-hero.alt { background: #c2410c; }
.ps-hero span, .ps-hero small { display: block; font-size: 12.5px; opacity: 0.92; }
.ps-hero b { display: block; font-size: 28px; line-height: 1.25; font-variant-numeric: tabular-nums; }
.ps-2, .ps-3 { display: grid; gap: 8px; }
.ps-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ps-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ps-2 > div, .ps-3 > div { background: var(--surface); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.ps-2 span, .ps-3 span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ps-2 b, .ps-3 b { display: block; font-size: 16px; color: var(--ink); white-space: nowrap; }
.ps-row { display: flex; justify-content: space-between; gap: 10px; background: var(--surface); border-radius: 14px; padding: 10px 12px; font-size: 13px; }
.ps-row b { color: var(--ink); }
.ps-row.warn { background: var(--warn-soft); color: var(--warn); }
.ps-list-h { font-size: 12px; font-weight: 700; color: var(--ink-3); margin-top: 4px; }
.ps-list { list-style: none; margin: 0; padding: 4px 12px; background: var(--surface); border-radius: 14px; }
.ps-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.ps-list li:last-child { border-bottom: 0; }
.ps-list li .bw { flex: 1; }
.ps-list li b { color: var(--ink); white-space: nowrap; }
.ps-list li.more { color: var(--muted); justify-content: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex: none; }
.dot.P { background: var(--ok-mark); }
.dot.L { background: var(--warn-mark); }
.dot.A { background: var(--crit-mark); }
.dot.S, .dot.V { background: var(--info); }
.dot.none { background: transparent; border: 1.5px dashed var(--border-strong); }
.ps-foot { font-size: 12.5px; color: var(--muted); text-align: center; margin-top: auto; }
.ps-btn { height: 44px; border-radius: 14px; border: 0; background: var(--brand); color: #fff; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; }
.ps-lang { text-align: center; font-size: 12px; color: var(--muted); }
.phone .mcal { gap: 4px; }
.phone .mc { height: 30px; font-size: 12px; background: var(--surface); }
.phone .mc.P { background: var(--ok-soft); }
.phone .mc.off, .phone .mc.fut { background: transparent; }

/* ---------- แนวคิดระบบ ---------- */
.flow { display: flex; flex-direction: column; margin-top: 8px; }
.fl { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.fl.last { border-bottom: 0; }
.fl-ic { width: 36px; height: 36px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-strong); display: grid; place-items: center; }
.fl.last .fl-ic { background: #fdf3d7; color: #92400e; }
.fl-t { display: block; font-weight: 600; color: var(--ink); }
.fl small { display: block; font-size: 12.5px; color: var(--muted); }
.fl b { color: var(--ink); white-space: nowrap; font-size: 15px; }
@media (max-width: 480px) { .fl { grid-template-columns: auto minmax(0, 1fr); } .fl b { grid-column: 2; } }
.steps { margin: 0 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.steps.big { list-style: none; padding: 0; counter-reset: st; gap: 0; margin: 0; }
.steps.big li { counter-increment: st; position: relative; padding: 10px 0 10px 44px; border-bottom: 1px solid var(--line); }
.steps.big li:last-child { border-bottom: 0; }
.steps.big li::before { content: counter(st); position: absolute; left: 0; top: 10px; width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; display: grid; place-items: center; font-size: 13px; }
.steps.big b { display: block; color: var(--ink); }
.steps.big small { display: block; color: var(--muted); font-size: 12.5px; }
.codebox { white-space: pre; overflow-x: auto; font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; color: var(--ink-2); }
.opts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 640px) { .opts { grid-template-columns: minmax(0, 1fr); } }
.opt { padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.opt b { display: block; color: var(--ink); }
.opt small { display: block; font-size: 12.5px; color: var(--muted); }
.src2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
@media (max-width: 640px) { .src2 { grid-template-columns: minmax(0, 1fr); } }
.src { padding: 12px; border-radius: 12px; }
.src b { display: flex; gap: 6px; align-items: center; }
.src small { display: block; font-size: 12.5px; margin-top: 2px; }
.src.ok { background: var(--ok-soft); color: #14532d; }
.src.warn { background: var(--warn-soft); color: #7c2d12; }
.law { list-style: none; margin: 0; padding: 0; }
.law li { padding: 10px 0 10px 18px; border-bottom: 1px solid var(--line); position: relative; }
.law li:last-child { border-bottom: 0; }
.law li::before { content: ''; position: absolute; left: 2px; top: 18px; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }
.law b { display: block; color: var(--ink); }
.law small { display: block; color: var(--muted); font-size: 12.5px; }
.road { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.rd { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.rd b { display: block; color: var(--ink); }
.rd small { display: block; color: var(--muted); font-size: 12.5px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
/* กันไว้เผื่อ: ห้ามมี blur ที่ไหนเลย */
[class*='blur'] { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
