/* ── โทนสี: ม่วง-ทอง ของ กฟภ. ───────────────────────────── */
:root {
  color-scheme: light;
  --bg: #f5f2f9;
  --bg-2: #ece6f3;
  --surface: #ffffff;
  --surface-2: #faf8fc;
  --line: rgba(40, 16, 60, .10);
  --line-2: rgba(40, 16, 60, .18);
  --ink: #1b1224;
  --ink-2: #594d66;
  --ink-3: #8a7f96;
  --brand: #7b2a9e;
  --brand-ink: #6a1f8b;
  --brand-2: #a44fc9;
  --brand-soft: #f1e4f8;
  --gold: #f6b91f;
  --gold-ink: #8a6100;
  --good: #0ca30c;
  --good-ink: #006300;
  --good-soft: #e4f6e4;
  --warn: #fab219;
  --warn-ink: #7d5400;
  --warn-soft: #fff3d6;
  --crit: #d03b3b;
  --crit-ink: #a52222;
  --crit-soft: #fde8e8;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e7e2ee;
  --shadow: 0 1px 2px rgba(40, 16, 60, .05), 0 8px 24px -12px rgba(40, 16, 60, .18);
  --shadow-lg: 0 24px 60px -20px rgba(40, 16, 60, .35);
  --viewer: #e4deec;
  --r: 16px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #100b16;
  --bg-2: #17101f;
  --surface: #1b1424;
  --surface-2: #221a2d;
  --line: rgba(255, 255, 255, .09);
  --line-2: rgba(255, 255, 255, .17);
  --ink: #f5f0fa;
  --ink-2: #c4b8d1;
  --ink-3: #8f8499;
  --brand: #b565da;
  --brand-ink: #d39cee;
  --brand-2: #8a3bb0;
  --brand-soft: #2f1d3d;
  --gold: #f6b91f;
  --gold-ink: #f6c94f;
  --good-ink: #4cd24c;
  --good-soft: #12301a;
  --warn-ink: #fbc54d;
  --warn-soft: #36290b;
  --crit-ink: #f08080;
  --crit-soft: #3a1717;
  --series-1: #3987e5;
  --series-2: #d95926;
  --grid: #2d2438;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
  --viewer: #0b0710;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.55 "IBM Plex Sans Thai", "Leelawadee UI", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.3; text-wrap: balance; }
a { color: var(--brand-ink); }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--ink-3); }
.sm { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ── ปุ่ม / ฟอร์ม ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: transform .12s, box-shadow .15s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #8a2fb3, #6a1f8b); color: #fff; border-color: transparent; box-shadow: 0 6px 18px -8px #7b2a9e; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.gold { background: var(--gold); color: #33230a; border-color: transparent; }
.btn.danger { color: var(--crit-ink); border-color: color-mix(in srgb, var(--crit) 45%, transparent); }
.btn.danger:hover { background: var(--crit-soft); border-color: var(--crit); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--brand-soft); box-shadow: none; }
.btn.sm { height: 32px; padding: 0 11px; border-radius: 9px; font-size: 13px; }
.btn.icon { width: 40px; padding: 0; }
.btn.icon.sm { width: 32px; }
.btn.block { width: 100%; }
.btn.big { height: 48px; font-size: 16px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; height: 42px; padding: 0 13px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 13px; resize: vertical; min-height: 76px; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--bg-2); color: var(--ink-2); white-space: nowrap;
}
.chip svg.ic { width: 13px; height: 13px; stroke-width: 2.4; }
.chip.brand { background: var(--brand-soft); color: var(--brand-ink); }
.chip.good { background: var(--good-soft); color: var(--good-ink); }
.chip.warn { background: var(--warn-soft); color: var(--warn-ink); }
.chip.crit { background: var(--crit-soft); color: var(--crit-ink); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card.pad { padding: 20px; }
.card h3 { font-size: 15px; font-weight: 600; }

/* ── หน้าเข้าสู่ระบบ ───────────────────────────────────────── */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero {
  position: relative; overflow: hidden; color: #fff; padding: 56px;
  background: radial-gradient(1200px 600px at 10% 0%, #a44fc9 0%, transparent 60%), linear-gradient(150deg, #4a1263, #7b2a9e 55%, #3a0d52);
  display: flex; flex-direction: column; justify-content: space-between;
}
.login-hero::before, .login-hero::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55; animation: float 14s ease-in-out infinite alternate;
}
.login-hero::before { width: 420px; height: 420px; background: #f6b91f; right: -140px; bottom: -120px; }
.login-hero::after { width: 320px; height: 320px; background: #d77bff; left: -80px; top: 40%; animation-delay: -6s; }
@keyframes float { to { transform: translate(40px, -50px) scale(1.15); } }
.login-hero > * { position: relative; z-index: 1; }
.login-hero h1 { font-size: clamp(30px, 3.4vw, 46px); font-weight: 700; letter-spacing: -.01em; }
.login-hero p { font-size: 17px; opacity: .85; max-width: 46ch; }
.flow-demo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 28px; }
.flow-demo span { padding: 7px 13px; border-radius: 99px; background: rgba(255,255,255,.13); border: 1px solid rgba(255,255,255,.22); font-size: 13px; backdrop-filter: blur(6px); animation: pop .6s both; }
.flow-demo i { opacity: .6; font-style: normal; }
@keyframes pop { from { opacity: 0; transform: translateY(10px); } }
.login-form { display: grid; place-items: center; padding: 32px; }
.login-form form { width: min(400px, 100%); display: grid; gap: 16px; }
.demo-list { display: flex; flex-wrap: wrap; gap: 6px; }
.demo-list button { border: 1px solid var(--line-2); background: var(--surface); border-radius: 99px; padding: 4px 11px; font-size: 12.5px; cursor: pointer; }
.demo-list button:hover { border-color: var(--brand); color: var(--brand-ink); }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #9a3fc4, #5c177a); box-shadow: inset 0 1px 0 rgba(255,255,255,.3), 0 6px 14px -6px #5c177a;
}
.logo svg { width: 22px; height: 22px; fill: var(--gold); }
@media (max-width: 860px) { .login { grid-template-columns: 1fr; } .login-hero { padding: 32px; min-height: 280px; } }

/* ── โครงหน้า ─────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 256px minmax(0, 1fr); height: 100vh; }
.side {
  display: flex; flex-direction: column; gap: 6px; padding: 18px 14px; overflow: auto;
  background: linear-gradient(180deg, #45115c, #2b0a3b); color: #eadcf3;
}
.side .brand { padding: 4px 8px 18px; color: #fff; }
.side .brand small { display: block; font-weight: 400; font-size: 12px; opacity: .7; }
.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; cursor: pointer; text-decoration: none; color: inherit; border: 0; background: none; text-align: left; width: 100%; transition: background .15s; }
.nav:hover { background: rgba(255,255,255,.08); }
.nav.on { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--gold); }
.nav .badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 99px; background: var(--gold); color: #33230a; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.side-foot { margin-top: auto; padding: 12px; border-radius: 14px; background: rgba(255,255,255,.07); font-size: 13px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; background: linear-gradient(135deg, #f6b91f, #e0781f); }
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.top { display: flex; align-items: center; gap: 10px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(10px); }
.search-btn { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 14px; width: min(360px, 100%); border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-3); cursor: pointer; }
.search-btn kbd { margin-left: auto; font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 6px; background: var(--bg-2); }
#view { flex: 1; overflow: auto; padding: 24px; }
.view-in { animation: viewIn .28s ease both; max-width: 1280px; margin: 0 auto; }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; font-weight: 700; }
.dot { position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--crit); border: 2px solid var(--surface); }
.pop { position: absolute; right: 0; top: 46px; width: 340px; max-height: 420px; overflow: auto; z-index: 30; padding: 8px; }
.pop .item { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; border: 0; background: none; cursor: pointer; }
.pop .item:hover { background: var(--brand-soft); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .side { order: 2; flex-direction: row; padding: 6px; gap: 2px; justify-content: space-around; overflow: visible; }
  .side .brand, .side-foot, .nav span:not(.badge) { display: none; }
  .nav { width: auto; padding: 10px 14px; position: relative; }
  .nav.on { box-shadow: inset 0 -3px 0 var(--gold); }
  .nav .badge { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; font-size: 10px; }
  .main { height: auto; min-height: 0; }
  #view { padding: 16px; }
  .top { padding: 10px 16px; }
}

/* ── แดชบอร์ด ─────────────────────────────────────────────── */
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.seg button { border: 0; background: none; padding: 6px 13px; border-radius: 9px; cursor: pointer; font-size: 13.5px; color: var(--ink-2); font-weight: 500; }
.seg button.on { background: var(--surface); color: var(--brand-ink); box-shadow: var(--shadow); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tile { padding: 18px 20px; position: relative; overflow: hidden; }
.tile .lbl { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 7px; }
.tile .val { font-size: 38px; font-weight: 700; line-height: 1.2; margin-top: 6px; }
.tile .sub { font-size: 12.5px; color: var(--ink-3); }
.tile .glyph { position: absolute; right: 14px; top: 14px; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-ink); }
.tile.hero { background: linear-gradient(135deg, #8a2fb3, #55156f); color: #fff; border: 0; }
.tile.hero .lbl, .tile.hero .sub { color: rgba(255,255,255,.8); }
.tile.hero .glyph { background: rgba(255,255,255,.16); color: var(--gold); }
.pipe { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.lv { padding: 16px; position: relative; transition: transform .18s, box-shadow .18s; }
.lv:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.lv .step { font-size: 11.5px; font-weight: 700; color: var(--brand-ink); letter-spacing: .04em; }
.lv .name { font-weight: 600; font-size: 14px; min-height: 2.9em; }
.lv .pending { font-size: 34px; font-weight: 700; line-height: 1.1; }
.lv dl { margin: 12px 0 0; display: grid; gap: 5px; font-size: 13px; }
.lv dl div { display: flex; justify-content: space-between; gap: 8px; }
.lv dt { color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.lv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.key { width: 9px; height: 9px; border-radius: 3px; flex: none; display: inline-block; }
.meter { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; display: flex; gap: 2px; margin-top: 10px; }
.meter i { display: block; height: 100%; border-radius: 99px; transition: width .8s cubic-bezier(.2,.8,.2,1); }
.lv:not(:last-child)::after { content: "›"; position: absolute; right: -11px; top: 50%; translate: 0 -50%; z-index: 2; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line-2); display: grid; place-items: center; font-size: 14px; line-height: 1; color: var(--ink-3); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 14px; margin-top: 14px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart { position: relative; margin-top: 8px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-3); font-size: 11px; font-family: inherit; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: color-mix(in srgb, var(--ink) 6%, transparent); }
.tip { position: absolute; pointer-events: none; z-index: 5; padding: 8px 11px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 12.5px; white-space: nowrap; box-shadow: var(--shadow-lg); translate: -50% -110%; }
.tip b { font-weight: 600; }
@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .pipe { grid-template-columns: repeat(2, minmax(0, 1fr)); } .lv::after { display: none !important; } .grid-2 { grid-template-columns: 1fr; } }

/* ── ตาราง / รายการเอกสาร ─────────────────────────────────── */
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.r, .tbl th.r { text-align: right; font-variant-numeric: tabular-nums; }
.list { display: grid; gap: 8px; }
.doc-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 170px 190px 120px; align-items: center; gap: 16px;
  padding: 13px 18px; cursor: pointer; text-decoration: none; color: inherit;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.doc-row:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--brand); }
.doc-row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-row .m { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps-mini { display: flex; gap: 3px; }
.steps-mini i { flex: 1; height: 6px; border-radius: 99px; background: var(--bg-2); }
.steps-mini i.done { background: var(--brand); }
.steps-mini i.cur { background: var(--gold); animation: pulse 1.6s ease-in-out infinite; }
.steps-mini i.ret { background: var(--crit); }
@keyframes pulse { 50% { opacity: .45; } }
.empty { padding: 56px 20px; text-align: center; color: var(--ink-3); }
.empty svg { width: 44px; height: 44px; stroke-width: 1.3; margin-bottom: 8px; }
@media (max-width: 900px) { .doc-row { grid-template-columns: 1fr; gap: 8px; } }

/* ── ส่งงานใหม่ ───────────────────────────────────────────── */
.drop {
  border: 2px dashed var(--line-2); border-radius: 20px; padding: 44px 20px; text-align: center; cursor: pointer;
  background: var(--surface); transition: border-color .15s, background .15s, transform .15s;
}
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop.over { transform: scale(1.01); }
.drop svg { width: 46px; height: 46px; color: var(--brand); stroke-width: 1.4; }
.up-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) 150px 40px; gap: 12px; align-items: center; padding: 12px 14px; position: relative; overflow: hidden; }
.up-row .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--brand); width: 0; transition: width .3s; }
.pdf-ico { width: 40px; height: 46px; border-radius: 8px; background: var(--crit-soft); color: var(--crit-ink); display: grid; place-items: center; font-size: 10px; font-weight: 700; }
@media (max-width: 700px) { .up-row { grid-template-columns: 40px minmax(0, 1fr) 40px; } .up-row select { grid-column: 2; } }

/* ── หน้าเอกสาร / ตัวอ่าน PDF ─────────────────────────────── */
#view.doc-mode { padding: 0; overflow: hidden; }
.docv { display: grid; grid-template-columns: minmax(0, 1fr) 390px; height: 100%; }
.viewer { position: relative; background: var(--viewer); overflow: auto; overflow-y: scroll; min-height: 0; }
.viewer-bar { position: sticky; top: 12px; z-index: 6; width: max-content; margin: 12px auto -52px; display: flex; align-items: center; gap: 4px; padding: 5px; border-radius: 14px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border: 1px solid var(--line); box-shadow: var(--shadow); }
.pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 72px 24px 48px; width: max-content; min-width: 100%; }
.page { position: relative; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.14), 0 14px 40px -18px rgba(0,0,0,.45); flex: none; }
.page canvas { width: 100%; height: 100%; display: block; }
#hint { position: sticky; top: calc(100% - 58px); z-index: 6; height: 0; display: grid; justify-content: center; }
.hint { width: max-content; max-width: 90%; padding: 7px 14px; border-radius: 99px; background: var(--gold); color: #33230a; font-size: 13px; font-weight: 600; box-shadow: var(--shadow); display: flex; gap: 8px; align-items: center; }
.stamp { position: absolute; cursor: grab; touch-action: none; outline: 2px dashed var(--brand); outline-offset: 3px; border-radius: 4px; background: rgba(164, 79, 201, .07); animation: stampIn .35s cubic-bezier(.2,1.4,.4,1) both; }
.stamp:active { cursor: grabbing; }
.stamp img { width: 100%; display: block; pointer-events: none; user-select: none; }
.stamp-h { position: absolute; right: -10px; bottom: -10px; width: 20px; height: 20px; border-radius: 50%; background: var(--brand); border: 3px solid #fff; cursor: nwse-resize; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.stamp-x { position: absolute; right: -11px; top: -11px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--crit); color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 14px; line-height: 1; }
@keyframes stampIn { from { opacity: 0; transform: scale(1.5) rotate(-6deg); } }
.panel { border-left: 1px solid var(--line); background: var(--surface); overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.panel h2 { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 6px 10px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.alert { padding: 12px 14px; border-radius: 12px; font-size: 13.5px; display: flex; gap: 10px; }
.alert.crit { background: var(--crit-soft); color: var(--crit-ink); }
.alert.good { background: var(--good-soft); color: var(--good-ink); }
.alert.brand { background: var(--brand-soft); color: var(--brand-ink); }
.stepper { display: grid; }
.st { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; position: relative; padding-bottom: 16px; }
.st:last-child { padding-bottom: 0; }
.st::before { content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--line-2); }
.st:last-child::before { display: none; }
.st.done::before { background: var(--brand); }
.st .b { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-2); color: var(--ink-3); font-size: 12px; font-weight: 700; z-index: 1; }
.st .b svg.ic { width: 14px; height: 14px; stroke-width: 2.6; }
.st.done .b { background: var(--brand); color: #fff; }
.st.cur .b { background: var(--gold); color: #33230a; box-shadow: 0 0 0 5px color-mix(in srgb, var(--gold) 28%, transparent); animation: pulse 1.8s infinite; }
.st.ret .b { background: var(--crit); color: #fff; }
.st .n { font-weight: 600; font-size: 14px; }
.st .w { font-size: 12.5px; color: var(--ink-3); }
.hist { display: grid; gap: 10px; font-size: 13px; }
.hist > div { display: grid; grid-template-columns: 8px minmax(0, 1fr); gap: 10px; }
.hist i { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-top: 7px; }
.hist i.ret { background: var(--crit); }
.hist i.ok { background: var(--good); }
.actions-bar { display: grid; gap: 10px; position: sticky; bottom: -20px; margin: auto -20px -20px; padding: 16px 20px; background: linear-gradient(to top, var(--surface) 75%, transparent); }
@media (max-width: 1000px) { #view.doc-mode { overflow: auto; } .docv { grid-template-columns: 1fr; height: auto; } .viewer { height: 72vh; } .panel { border-left: 0; } }

/* ── โมดัล / ลายเซ็น / พาเล็ตคำสั่ง ───────────────────────── */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(20, 8, 30, .5); backdrop-filter: blur(5px); animation: fade .18s both; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: 22px; padding: 24px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); animation: modalIn .25s cubic-bezier(.2,1.2,.4,1) both; display: grid; gap: 16px; }
.modal.wide { width: min(720px, 100%); }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.97); } }
.modal h2 { font-size: 19px; font-weight: 700; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.pad-wrap { border-radius: 16px; border: 1px dashed var(--line-2); position: relative; overflow: hidden;
  background: #fff linear-gradient(to bottom, transparent calc(72% - 1px), #cfc6d9 72%, transparent calc(72% + 1px)); }
.pad-wrap canvas { width: 100%; height: 220px; display: block; touch-action: none; cursor: crosshair; }
.checker { background: #fff repeating-conic-gradient(#ece7f1 0 25%, #fff 0 50%) 0 0 / 18px 18px; border-radius: 14px; border: 1px solid var(--line); display: grid; place-items: center; min-height: 150px; padding: 14px; }
.checker img, .checker canvas { max-width: 100%; max-height: 190px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line-2); cursor: pointer; padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--brand); }
.cmdk { width: min(600px, 100%); padding: 0; gap: 0; overflow: hidden; align-self: start; margin-top: 10vh; }
.cmdk input { width: 100%; height: 56px; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 0 20px; font-size: 16px; outline: none; }
.cmdk .res { max-height: 380px; overflow: auto; padding: 8px; }
.cmdk .res button { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 10px; cursor: pointer; }
.cmdk .res button.sel { background: var(--brand-soft); color: var(--brand-ink); }

#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: grid; gap: 10px; }
.toast { display: flex; gap: 10px; align-items: center; max-width: 380px; padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); animation: toastIn .3s cubic-bezier(.2,1.3,.4,1) both; cursor: pointer; font-size: 14px; }
.toast.err { background: var(--crit); color: #fff; }
.toast.out { opacity: 0; transform: translateX(30px); transition: .25s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px) scale(.95); } }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 80px; color: var(--brand); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs button.on { color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ── ตีกลับ: แคปหน้าเอกสารและตีกรอบจุดที่ผิด ─────────────── */
.modal.xl { width: min(1180px, 100%); }
.ret-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); gap: 18px; }
.anno-box { max-height: 62vh; overflow: auto; border-radius: 12px; border: 1px solid var(--line-2); background: var(--viewer); }
.anno-box canvas { width: 100%; display: block; cursor: crosshair; touch-action: none; }
.note-row { display: flex; align-items: flex-start; gap: 8px; }
.num-badge { flex: none; width: 26px; height: 26px; margin-top: 8px; border-radius: 50%; background: var(--crit); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; }
.note-row > div:not(.grow) { padding-top: 9px; overflow-wrap: anywhere; }
.marks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -8px; }
.marks.small { margin: 6px 0; }
.mark-thumb { width: 104px; padding: 0; border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; background: var(--surface); cursor: zoom-in; text-align: center; transition: transform .15s, border-color .15s; }
.mark-thumb:hover { transform: translateY(-2px); border-color: var(--crit); }
.mark-thumb img { width: 100%; height: 96px; object-fit: cover; object-position: top; display: block; background: #fff; }
.mark-thumb span { display: block; font-size: 11.5px; padding: 3px 4px; color: var(--ink-2); }
.marks.small .mark-thumb { width: 72px; }
.marks.small .mark-thumb img { height: 64px; }
@media (max-width: 860px) { .ret-grid { grid-template-columns: 1fr; } .anno-box { max-height: 50vh; } }

/* ── ผังองค์กร ─────────────────────────────────────────────── */
.pipe { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.lv::after { display: none !important; }
.lv .name { min-height: 0; margin-bottom: 8px; }
.route { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.route i { font-style: normal; color: var(--ink-3); }
.route .chip { height: 28px; font-size: 12.5px; }
.org-wrap { overflow: auto; padding: 28px 20px; }
.org { width: max-content; min-width: 100%; }
.org ul { display: flex; justify-content: center; position: relative; margin: 0; padding: 26px 0 0; list-style: none; }
.org li { position: relative; display: flex; flex-direction: column; align-items: center; padding: 26px 8px 0; }
.org li::before, .org li::after { content: ""; position: absolute; top: 0; right: 50%; width: 50%; height: 26px; border-top: 2px solid var(--line-2); }
.org li::after { right: auto; left: 50%; border-left: 2px solid var(--line-2); }
.org li:only-child::before, .org li:only-child::after { display: none; }
.org li:only-child { padding-top: 0; }
.org li:first-child::before, .org li:last-child::after { border: 0 none; }
.org li:last-child::before { border-right: 2px solid var(--line-2); border-radius: 0 8px 0 0; }
.org li:first-child::after { border-radius: 8px 0 0 0; }
.org ul ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 26px; border-left: 2px solid var(--line-2); }
.org > ul { padding-top: 0; gap: 24px; }
.org > ul > li { padding-top: 0; }
.org > ul > li::before, .org > ul > li::after { display: none; }
.org-node { position: relative; width: 190px; padding: 12px 12px 16px; border-radius: 14px; background: var(--surface); border: 1.5px solid var(--line-2); border-top: 4px solid var(--brand); box-shadow: var(--shadow); text-align: center; cursor: pointer; display: grid; gap: 4px; justify-items: center; transition: transform .15s, box-shadow .15s, border-color .15s; }
.org-node:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--brand); }
.org-node.reg { border-top-color: var(--good); }
.org-node.vacant { border-style: dashed; border-top-style: solid; border-top-color: var(--ink-3); }
.org-t { font-weight: 600; font-size: 13.5px; line-height: 1.35; overflow-wrap: anywhere; }
.org-u { font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.org-node.vacant .org-u { color: var(--ink-3); font-style: italic; }
.org-add { position: absolute; left: 50%; bottom: -12px; translate: -50% 0; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 17px; line-height: 1; cursor: pointer; display: grid; place-items: center; opacity: 0; transition: opacity .15s, transform .15s; z-index: 2; }
.org-node:hover .org-add, .org-node:focus-within .org-add, .org-add:focus-visible { opacity: 1; }
.org-add:hover { transform: scale(1.15); }
@media (hover: none) { .org-add { opacity: 1; } }

/* ── จอเล็ก (มือถือ) ──────────────────────────────────────── */
.search-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
@media (max-width: 900px) {
  .search-btn kbd { display: none; }
  .search-btn { min-width: 0; flex: 1; }
  .top .grow { display: none; }
  #toasts { right: 12px; left: 12px; bottom: 76px; }
  .toast { max-width: none; }
  .modal { padding: 18px; border-radius: 18px; }
  .page-head h1 { font-size: 21px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .val { font-size: 30px; }
  .viewer { height: 62vh; }
  .pages { padding: 64px 10px 32px; }
}

/* ── รองรับทุกขนาดจอ: คอมพิวเตอร์ / แท็บเล็ต / มือถือ ─────── */
.shell, .main { height: 100dvh; }
.login { min-height: 100dvh; }
.seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg button { white-space: nowrap; flex: none; }
.btn, .nav, .input { -webkit-tap-highlight-color: transparent; }
@media (max-width: 1200px) and (min-width: 901px) {
  .shell { grid-template-columns: 220px minmax(0, 1fr); }
  .docv { grid-template-columns: minmax(0, 1fr) 340px; }
}
/* แท็บเล็ตแนวตั้งและมือถือ: เมนูอยู่ล่าง เอกสารอยู่บน รายละเอียดอยู่ล่าง ปุ่มดำเนินการลอยอยู่เหนือเมนูเสมอ */
@media (max-width: 900px) {
  .shell { height: 100dvh; }
  .main { height: auto; }
  .side { height: calc(56px + env(safe-area-inset-bottom)); padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); align-items: center; }
  .nav { justify-content: center; flex: 1; max-width: 120px; }
  #view.doc-mode { overflow: auto; }
  .docv { grid-template-columns: 1fr; height: auto; }
  .viewer { height: 64dvh; }
  .panel { border-left: 0; padding-bottom: 150px; }
  .actions-bar { position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); margin: 0; z-index: 20; padding: 10px 14px; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -10px 30px -18px rgba(0,0,0,.45); grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 8px; }
  .actions-bar .btn { height: 46px; font-size: 14px; padding: 0 10px; white-space: normal; line-height: 1.2; }
  .actions-bar .btn:only-child { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: 1fr !important; }
  .input, select.input, textarea.input { font-size: 16px; } /* กัน iOS ซูมเข้าเองเมื่อแตะช่องกรอก */
  .anno-box { max-height: 56dvh; }
  .overlay { padding: 10px; align-items: end; }
  .modal { max-height: calc(100dvh - 20px); }
  .pop { position: fixed; right: 10px; left: 10px; top: 60px; width: auto; }
  .org-node { width: 160px; }
}
/* แท็บเล็ตแนวตั้ง: ใช้ความกว้างให้คุ้ม */
@media (min-width: 600px) and (max-width: 900px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tile { padding: 14px; }
  .tile .glyph { display: none; }
  .doc-row { grid-template-columns: minmax(0, 1fr) 150px 170px; }
  .doc-row > :last-child { display: none; }
  .overlay { align-items: center; padding: 20px; }
}
@media (max-width: 599px) {
  #view { padding: 14px 12px; }
  .card.pad { padding: 16px; }
  .tile { padding: 14px; }
  .tile .glyph { width: 30px; height: 30px; right: 10px; top: 10px; }
  .tile .lbl { padding-right: 34px; }
  .lv .pending { font-size: 28px; }
  .pipe { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .lv { padding: 12px; }
  .viewer-bar .btn.sm { padding: 0 8px; }
  .login-hero { padding: 24px; min-height: 0; gap: 18px; }
  .login-hero p, .flow-demo { display: none; }
  .login-form { padding: 22px 16px; place-items: start center; }
  .modal-foot .btn { flex: 1; }
  .tabs button { padding: 10px 10px; }
  #f-q, #f-dept { width: 100% !important; }
}
@media (max-width: 599px) {
  .page-head { gap: 10px; }
  .page-head > .grow { flex-basis: 100%; }
  #dash > .row { flex-wrap: wrap; gap: 2px 10px; }
}

/* กล่องลากวางไฟล์เป็น <label> ซึ่งปกติเป็น inline จึงต้องบังคับให้เป็นบล็อกเต็มความกว้าง */
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; width: 100%; min-height: 200px; }
