/* Drug List Report — หน้าตาตามตัวอย่างที่ผู้ใช้เลือก (2026-10-30)
   Layout: แถบเมนูซ้าย + แถบควบคุมบน (แผนก / เดือน) ; สีเขียวสมุดบัญชีบนพื้นเทาอมเขียว */
:root {
  --bg: #F2F4F1; --surface: #FFFFFF; --sunk: #E9EDE9; --ink: #16201B; --muted: #5A6760; --line: #D6DDD8; --line-strong: #B9C4BD;
  --accent: #1C6A4F; --accent-ink: #FFFFFF; --accent-soft: #DFEDE5; --accent-hover: #155A42;
  --warn: #875700; --warn-bg: #FAEFD6; --bad: #A3241B; --bad-bg: #F9E3DF; --ok: #22704A; --ok-bg: #E0F0E6; --info: #2A5A86; --info-bg: #E2ECF6;
  --f-ui: 'IBM Plex Sans Thai', 'Leelawadee UI', 'Tahoma', sans-serif;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #111613; --surface: #18201C; --sunk: #202A25; --ink: #E4EBE7; --muted: #9BA9A2; --line: #2B3631; --line-strong: #3E4B45;
  --accent: #5DBE95; --accent-ink: #0D1A14; --accent-soft: #1D3128; --accent-hover: #79D0AA;
  --warn: #E6B65A; --warn-bg: #352A14; --bad: #F08A80; --bad-bg: #3A1D1A; --ok: #6FCB98; --ok-bg: #16301F; --info: #8DB8E6; --info-bg: #172839;
  color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #111613; --surface: #18201C; --sunk: #202A25; --ink: #E4EBE7; --muted: #9BA9A2; --line: #2B3631; --line-strong: #3E4B45;
  --accent: #5DBE95; --accent-ink: #0D1A14; --accent-soft: #1D3128; --accent-hover: #79D0AA;
  --warn: #E6B65A; --warn-bg: #352A14; --bad: #F08A80; --bad-bg: #3A1D1A; --ok: #6FCB98; --ok-bg: #16301F; --info: #8DB8E6; --info-bg: #172839;
  color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14.5px/1.55 var(--f-ui); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; line-height: 1.3; text-wrap: balance; }
h2 { font-size: 16px; margin: 0; text-wrap: balance; }
h3 { font-size: 15px; margin: 0; }
.sub { color: var(--muted); margin: 2px 0 0; font-size: 13.5px; }
.hint, .note { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }
.num, td.n { font-variant-numeric: tabular-nums; }

/* ---------- โครงหน้า ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.nav { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px 18px max(12px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; }
.brand-mark { width: 34px; height: 34px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.brand b { display: block; font-size: 15px; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }
.nav button { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; text-align: left; border: 0;
  background: none; padding: 9px 12px; border-radius: 7px; cursor: pointer; color: var(--ink); }
.nav button:hover { background: var(--sunk); }
.nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .sep { height: 1px; background: var(--line); margin: 8px 4px; }
.badge { min-width: 20px; height: 20px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 11.5px; display: inline-grid; place-items: center; padding: 0 6px; font-weight: 600; }
.nav-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.nav-foot b { color: var(--ink); font-weight: 600; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-align: left; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line);
  padding-block: 10px; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px));
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
.ctl { display: flex; align-items: center; gap: 8px; }
.ctl > label { font-size: 12.5px; color: var(--muted); }
.view { padding-block: 22px 48px; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 18px; max-width: 1280px; width: 100%; }
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.card p { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spacer { flex: 1; }

/* ---------- ฟอร์ม ---------- */
select, input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], input:not([type]), textarea {
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 10px; min-width: 0; }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--sunk); color: var(--muted); }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
.fld, label.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld > span:first-child { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.fld.wide { grid-column: 1 / -1; }
.req { color: var(--bad); font-style: normal; }
.unit-wrap { display: flex; gap: 6px; align-items: center; }
.unit-wrap input, .unit-wrap select { flex: 1; width: 100%; }
.unit-wrap em { font-style: normal; color: var(--muted); font-size: 13px; }
.err { color: var(--bad); font-size: 13.5px; font-weight: 500; min-height: 1.2em; margin: 0; }
label { display: grid; gap: 4px; }
label.inline { display: flex; align-items: center; gap: 6px; }

/* ---------- ปุ่ม ---------- */
.btn, button.primary { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 7px; padding: 7px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--sunk); }
.btn.pri, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.pri:hover { background: var(--accent-hover); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.sm { padding: 3px 10px; font-size: 13px; }
.btn[disabled], button[disabled] { opacity: .45; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- สถานะ ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 20px; padding: 2px 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.p-open { background: var(--info-bg); color: var(--info); }
.p-submitted { background: var(--warn-bg); color: var(--warn); }
.p-approved { background: var(--ok-bg); color: var(--ok); }
.tag { display: inline-block; font-size: 11.5px; border-radius: 4px; padding: 0 6px; background: var(--sunk); color: var(--muted); font-weight: 500; white-space: nowrap; }
.tag.sys { background: var(--info-bg); color: var(--info); }
.tag.void { background: var(--bad-bg); color: var(--bad); }
.tag.prog { background: var(--warn-bg); color: var(--warn); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.alerts { display: flex; flex-direction: column; gap: 8px; }
.al { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: 7px; font-size: 14px; }
.al .ic { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; margin-top: 1px; }
.al > div { flex: 1; min-width: 0; }
.al.block, .al.bad { background: var(--bad-bg); } .al.block .ic, .al.bad .ic { background: var(--bad); color: #fff; }
.al.warn { background: var(--warn-bg); } .al.warn .ic { background: var(--warn); color: var(--surface); }
.al.ok { background: var(--ok-bg); } .al.ok .ic { background: var(--ok); color: var(--surface); }
.al.info { background: var(--info-bg); } .al.info .ic { background: var(--info); color: var(--surface); }
.lock { display: flex; gap: 10px; align-items: center; background: var(--warn-bg); color: var(--warn); padding: 9px 12px; border-radius: 7px; font-size: 14px; }

/* ---------- ตาราง ---------- */
.tw, .tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
table.t, .tablewrap table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.t th, .tablewrap th { background: var(--sunk); color: var(--muted); font-weight: 600; font-size: 12.5px; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td, .tablewrap td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr:last-child td, .tablewrap tr:last-child td { border-bottom: 0; }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; }
table.t tr.carry td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); color: var(--muted); }
table.t tr.voided td { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--bad); }
table.t tr.voided td.keep { text-decoration: none; }
table.t tr.sum td { font-weight: 700; background: var(--sunk); }
tr.muted td { opacity: .55; }
.lotcell b { font-weight: 600; }
.lotcell small { display: block; color: var(--muted); font-size: 12px; }

/* ---------- ส่วนประกอบหน้า ---------- */
.prodtabs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.prodtabs button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 20px; padding: 5px 14px; cursor: pointer; }
.prodtabs button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.stock { display: flex; flex-direction: column; gap: 12px; }
.stock-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.stock-item:last-child { border-bottom: 0; padding-bottom: 0; }
.stock-item .tot { font-weight: 700; font-size: 16px; text-align: right; }
.chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; background: var(--sunk); border-radius: 5px; padding: 2px 8px; }
.chip b { font-weight: 600; }
.bar { height: 10px; border-radius: 5px; background: var(--sunk); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.steps { display: flex; flex-wrap: wrap; align-items: center; }
.step { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 0; color: var(--muted); font-size: 13.5px; }
.step i { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-strong); display: grid; place-items: center; font-style: normal; font-size: 12px; font-weight: 700; }
.step.done i { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.step.cur { color: var(--ink); font-weight: 600; } .step.cur i { border-color: var(--accent); color: var(--accent); }
.step + .step::before { content: ""; width: 22px; height: 2px; background: var(--line-strong); margin-right: 8px; }
.batch { border: 1px solid var(--line); border-radius: 7px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.batch-h { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: baseline; }
.var { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.var div { background: var(--sunk); border-radius: 6px; padding: 7px 10px; }
.var small { display: block; font-size: 12px; color: var(--muted); }
.var b { font-size: 15px; }
.var .bad b { color: var(--bad); } .var .warn b { color: var(--warn); } .var .good b { color: var(--ok); }
.pl-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--muted); border-radius: 0; }
.tabs button.active, .tabs button.on { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.empty { padding: 22px; text-align: center; color: var(--muted); }
.loading { color: var(--muted); padding: 20px 0; }

/* ---------- กล่องโต้ตอบ / แจ้งเตือน ---------- */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
dialog.wide { width: min(780px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(10 16 13 / .55); }
.dlg { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.dlg-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.dlgform { display: grid; gap: 12px; padding: 20px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(560px, calc(100% - 32px)); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgb(0 0 0 / .25); animation: tin .2s ease-out; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- เข้าสู่ระบบ ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px)); }
.auth .box { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; }
.auth form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; display: grid; gap: 12px; }
#msg { color: var(--bad); min-height: 1.2em; margin: 0; }

/* ---------- หน้าเดิม: ผู้ใช้ / ทะเบียน ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.toolbar h2 { margin-right: 8px; }
.notice { background: var(--ok-bg); border-radius: 8px; padding: 10px 14px; }
.notice code { font-size: 1.15rem; font-weight: bold; user-select: all; }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0; padding: 8px 12px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 12px; max-height: 220px; overflow-y: auto; }
.grid2f { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; max-height: 65vh; overflow-y: auto; padding-right: 4px; }
.grid2f .span2 { grid-column: 1 / -1; }
.grid2f h4 { margin: 6px 0 0; border-bottom: 1px solid var(--line); }
#m-search { width: 220px; }
button.link { background: none; border: 0; color: var(--accent); padding: 2px 4px; text-decoration: underline; cursor: pointer; }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); border-radius: 7px; padding: 7px 14px; cursor: pointer; }
.warn { color: var(--warn); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav { position: static; height: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line);
    padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); }
  .brand, .nav-foot, .nav .sep { display: none; }
  .nav button { width: auto; white-space: nowrap; flex: none; }
  .top { position: static; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .view { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .pl-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .pl-row .btn { grid-column: 1 / -1; justify-self: start; }
  .grid2f { grid-template-columns: 1fr; }
}

/* ---------- ตารางลงข้อมูล (สมุดรับ-จ่าย) ---------- */
.lg-keys { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); }
.lg-keys kbd { font: 600 12px/1 var(--f-ui); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 2px 6px; background: var(--surface); color: var(--ink); }
.lg-grid { border-collapse: collapse; width: 100%; min-width: 1160px; font-size: 14px; }
.lg-grid th { background: var(--sunk); color: var(--muted); font-weight: 600; font-size: 12.5px; text-align: left; padding: 8px; white-space: nowrap; border-bottom: 1px solid var(--line); }
.lg-grid th.n { text-align: right; }
.lg-grid tbody.entry { border-bottom: 1px solid var(--line); }
.lg-grid tbody.entry:last-child { border-bottom: 0; }
.lg-grid td { padding: 4px; vertical-align: top; }
.lg-grid input, .lg-grid select { width: 100%; min-width: 0; border: 1px solid var(--line); background: var(--surface); padding: 6px 7px; border-radius: 4px; }
.lg-grid input:hover, .lg-grid select:hover { border-color: var(--line-strong); }
.lg-grid input:focus, .lg-grid select:focus { border-color: var(--accent); background: var(--surface); }
.lg-grid input:disabled { color: var(--line-strong); text-align: center; background: var(--sunk); border-color: transparent; }
.lg-grid input.q { text-align: right; font-variant-numeric: tabular-nums; }
.lg-grid td.bad input, .lg-grid td.bad select { border-color: var(--bad); background: var(--bad-bg); }
.lg-grid .lg-auto, .lg-grid th.lg-auto { background: var(--info-bg); color: var(--info); }
.lg-grid td.lg-auto { vertical-align: top; padding-top: 12px; text-align: right; padding-right: 10px; font-variant-numeric: tabular-nums; }
.lg-day { display: flex; align-items: center; gap: 4px; }
.lg-grid .lg-day input { width: 56px; flex: none; text-align: center; }
.lg-day span { color: var(--accent); font-weight: 600; white-space: nowrap; }
.lg-type { display: flex; flex-direction: column; gap: 3px; }
.lg-dir { text-align: center; font-size: 12px; font-weight: 600; border-radius: 10px; padding: 1px 0; }
.lg-dir.in { background: var(--ok-bg); color: var(--ok); }
.lg-dir.out { background: var(--warn-bg); color: var(--warn); }
.lg-more { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 6px; padding: 4px 8px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.lg-more[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.lg-more:disabled { opacity: .45; cursor: default; }
.lg-more .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-left: 4px; vertical-align: middle; }
.lg-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 4px 8px; }
.lg-x:hover { color: var(--bad); }
.lg-grid tr.det td { background: var(--sunk); padding: 10px 12px 12px; }
.lg-det { display: flex; flex-direction: column; gap: 8px; }
.lg-why { font-size: 13px; color: var(--warn); font-weight: 500; }
.lg-det-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 12px; }
.lg-det-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
.lg-det-grid input { border: 1px solid var(--line-strong); background: var(--surface); }
.lg-grid tr.errrow td { color: var(--bad); font-size: 12.5px; padding: 0 12px 6px; }
.lg-ledger { max-height: 70vh; }
.lg-ledger thead th { position: sticky; top: 0; z-index: 1; }

/* ---------- แท็บหน้าลงข้อมูล (รับ-จ่าย / การผลิต / รับโอน-โอนออก) ---------- */
.etabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
.etabs button { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-bottom: 0; background: none; border-radius: 8px 8px 0 0;
  padding: 8px 16px; cursor: pointer; color: var(--muted); font-weight: 500; margin-bottom: -1px; }
.etabs button:hover { color: var(--ink); background: var(--sunk); }
.etabs button.on { background: var(--surface); color: var(--accent); font-weight: 700; border-color: var(--line); }

/* ---------- หัวกระดาษแบบฟอร์ม อย. บนหน้าลงข้อมูล ---------- */
.formhead { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 20px; background: var(--surface); border: 1px solid var(--line-strong);
  border-left: 4px solid var(--accent); border-radius: var(--r); padding: 12px 16px; }
.formhead > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.formhead > div.wide { grid-column: 1 / -1; }
.formhead span { font-size: 12px; color: var(--muted); }
.formhead b { font-weight: 600; border-bottom: 1px dotted var(--line-strong); padding-bottom: 2px; }
.formhead small { font-weight: 400; color: var(--muted); }
.bad-text { color: var(--bad); }
table.t .tag.in { background: var(--ok-bg); color: var(--ok); }
table.t .tag.out { background: var(--warn-bg); color: var(--warn); }

/* ---------- แฟ้มแบบฟอร์ม + กระดาษแบบฟอร์ม (forms.js) ---------- */
:root { --f-form: 'Sarabun', 'TH Sarabun New', Tahoma, sans-serif; --fill: #FFF8DC; --fill-line: #E2C76A; --rule: #3B3B3B; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --fill: #3A3317; --fill-line: #8C7426; --rule: #8E9893; } }
:root[data-theme="dark"] { --fill: #3A3317; --fill-line: #8C7426; --rule: #8E9893; }
.fsec { display: flex; flex-direction: column; gap: 10px; }
.fsec h2 small { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.fcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.fcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 5px; }
.fcard.entry { border-top: 4px solid var(--accent); }
.fcard.auto, .fcard.none { border-top: 4px solid var(--line-strong); background: var(--sunk); }
.fcard .fcode-c { font: 700 17px/1.3 var(--f-form); }
.fcard .drug { font-weight: 600; }
.fcard .lic { font-size: 12.5px; color: var(--muted); }
.fcard .act { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 6px; }
.fcard .st { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.fcard .st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.fcard .st.done { color: var(--ok); } .fcard .st.none { color: var(--warn); } .fcard .st.sys { color: var(--muted); font-weight: 500; }
.fm-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.sheet { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 4px; box-shadow: 0 2px 10px rgb(0 0 0 / .06);
  padding: 20px 22px 22px; font-family: var(--f-form); font-size: 15px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sheet-code { font-weight: 700; border: 1.5px solid var(--rule); padding: 1px 10px; align-self: flex-start; }
.sheet-title { text-align: center; font-weight: 700; font-size: 17.5px; line-height: 1.45; text-wrap: balance; }
.sheet-hl { display: flex; flex-wrap: wrap; gap: 4px 26px; justify-content: center; }
.dotf { border-bottom: 1px dotted var(--rule); padding: 0 6px; font-weight: 600; }
.sheet-legend, .fm-how { display: flex; flex-wrap: wrap; gap: 4px 18px; font: 13px/1.6 var(--f-ui); color: var(--muted); }
.fm-how b { color: var(--ink); }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--line-strong); }
.sw.fill { background: var(--fill); } .sw.calc { background: var(--info-bg); }
table.fm { border-collapse: collapse; width: 100%; font-size: 14px; }
table.fm th, table.fm td { border: 1px solid var(--rule); padding: 4px 6px; vertical-align: top; }
table.fm th { font-weight: 600; text-align: center; vertical-align: middle; line-height: 1.3; }
table.fm td.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.fm td.c { text-align: center; }
table.fm .calc { background: var(--info-bg); color: var(--info); }
table.fm tr.carry td { color: var(--muted); }
table.fm tr.voided td { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--bad); }
table.fm tr.total td { font-weight: 700; }
table.fm .small { display: block; font-size: 12px; color: var(--muted); }
table.fm .kind { display: inline-block; margin-top: 2px; font: 600 11.5px var(--f-ui); border-radius: 8px; padding: 0 6px; white-space: nowrap; }
table.fm .kind.in { background: var(--ok-bg); color: var(--ok); } table.fm .kind.out { background: var(--warn-bg); color: var(--warn); } table.fm .kind.prod { background: var(--accent-soft); color: var(--accent); }
.prog { display: inline-block; font: 600 12px var(--f-ui); color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 0 6px; white-space: nowrap; }
table.fm tbody.entry td { background: var(--fill); padding: 3px; }
table.fm tbody.entry td.calc { background: var(--info-bg); }
table.fm tbody.entry td.fm-auto { color: var(--muted); font-size: 13px; vertical-align: middle; }
table.fm tbody.entry input, table.fm tbody.entry select { width: 100%; min-width: 0; border: 1px solid var(--fill-line); background: var(--surface); border-radius: 3px; padding: 4px 5px; font: 14px var(--f-form); color: var(--ink); }
table.fm tbody.entry select { margin-top: 3px; font-size: 12.5px; }
table.fm tbody.entry input:focus, table.fm tbody.entry select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
table.fm tbody.entry input:disabled, table.fm tbody.entry select:disabled { background: transparent; border-color: transparent; color: var(--muted); }
table.fm tbody.entry input.q { text-align: right; font-variant-numeric: tabular-nums; }
table.fm tbody.entry td.bad input { border-color: var(--bad); background: var(--bad-bg); }
.fm-day { display: flex; align-items: center; gap: 3px; }
.fm-day input { width: 42px !important; flex: none; text-align: center; }
.fm-day em { font-style: normal; font-weight: 600; white-space: nowrap; font-size: 13px; }
table.fm tr.fm-det td { background: var(--sunk) !important; }
.fm-det-in { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; font: 12.5px var(--f-ui); color: var(--muted); }
.fm-det-in label { display: flex; flex-direction: column; gap: 2px; min-width: 160px; }
.fm-why { color: var(--warn); font-weight: 600; align-self: center; }
table.fm tr.fm-err td { background: var(--surface) !important; color: var(--bad); font: 13px var(--f-ui); padding: 0 8px 5px; }
.fm-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 6px; }
.fm-x:hover { color: var(--bad); }
.fm-close { display: flex; flex-direction: column; gap: 3px; align-items: stretch; min-width: 130px; }
.fm-close input { border: 1px solid var(--fill-line); background: var(--fill); border-radius: 3px; padding: 3px 5px; font: 13.5px var(--f-form); text-align: right; width: 100%; }
.fm-close .fm-day input { width: 42px; text-align: center; }
