/* PK WorkHub — stylesheet
   Concept: ตู้ลิ้นชักยา (pharmacy cabinet) — หมวดหมู่คือลิ้นชักที่มีป้ายทองเหลือง */
:root {
  --ink: #14213D;
  --ink-2: #3C4A63;
  --muted: #66748C;
  --paper: #F2F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --line: #DAE1EB;
  --line-2: #C6D0DD;
  --blue: #0E5A8A;
  --blue-deep: #0A4268;
  --blue-soft: #E3EEF6;
  --brass: #A97B22;
  --brass-soft: #F4EAD2;
  --brass-line: #DCC48E;
  --green: #2A7F51;
  --green-soft: #E2F2E8;
  --orange: #C8661A;
  --orange-soft: #FBEBDC;
  --red: #A8323F;
  --red-soft: #F8E3E5;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --display: 'Bai Jamjuree', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --body: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --shadow-pop: 0 18px 50px -12px rgba(20, 33, 61, .28);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 15px/1.65 var(--body); -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
[role="dialog"]:focus { outline: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- boot ---------- */
.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.boot-mark { width: 44px; height: 44px; border-radius: 9px; background: var(--blue); position: relative; animation: pulse 1.2s ease-in-out infinite; }
.boot-mark::before, .boot-mark::after { content: ""; position: absolute; left: 9px; right: 9px; height: 9px; border-radius: 2px; background: var(--brass-soft); }
.boot-mark::before { top: 10px; } .boot-mark::after { bottom: 10px; }
@keyframes pulse { 50% { transform: scale(.92); } }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: var(--radius-s); font-weight: 500; font-size: 14px;
  text-decoration: none; line-height: 1.3; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
.btn-danger { color: var(--red); border-color: #E2B8BD; }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(20,33,61,.06); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 7px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn .spin { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--radius-s);
  padding: 9px 12px; font-size: 14px; line-height: 1.4;
}
.select { padding-right: 32px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2366748C' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.textarea { min-height: 110px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(14,90,138,.15); }
.field { display: grid; gap: 5px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field small { color: var(--muted); font-size: 12px; }
.field .err { color: var(--red); font-size: 12.5px; }
.field.has-err .input, .field.has-err .select { border-color: var(--red); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--blue); }

/* ---------- site header ---------- */
.site-head { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.site-head .wrap { display: flex; align-items: center; gap: 18px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand b { font: 700 18px/1 var(--display); letter-spacing: .01em; }
.brand small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; font-weight: 400; }
.site-nav { margin-left: auto; display: flex; gap: 2px; align-items: center; }
.site-nav a, .site-nav button {
  color: var(--ink-2); text-decoration: none; padding: 7px 12px; border-radius: var(--radius-s); font-size: 14px;
  font-weight: 500; border: 0; background: none; display: inline-flex; gap: 7px; align-items: center;
}
.site-nav a:hover, .site-nav button:hover { background: var(--paper); color: var(--ink); }
.site-nav a[aria-current="page"] { color: var(--blue); background: var(--blue-soft); }
.site-nav svg { width: 17px; height: 17px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }

/* ---------- hero: search + cabinet ---------- */
.hero { padding: 44px 0 36px; border-bottom: 1px solid var(--line); background: var(--surface); }
.hero .wrap { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 48px; align-items: start; }
.hero-who { font-size: 14px; color: var(--muted); margin: 0 0 14px; }
.hero-who b { color: var(--ink-2); font-weight: 600; }
.hero h1 {
  font: 700 clamp(30px, 3.6vw, 44px)/1.18 var(--display); margin: 0 0 14px; letter-spacing: -.005em; color: var(--ink);
  text-wrap: balance;
}
.hero p.lead { margin: 0 0 26px; color: var(--ink-2); font-size: 16px; max-width: 44ch; }
.search-big { position: relative; }
.search-big svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.search-big input {
  width: 100%; height: 54px; border: 1.5px solid var(--line-2); border-radius: var(--radius-m); padding: 0 52px 0 48px;
  font-size: 16px; background: var(--surface);
}
.search-big input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(14,90,138,.14); }
.search-big kbd {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font: 500 12px/1 var(--body); color: var(--muted);
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; padding: 4px 7px; background: var(--surface-2);
}
.hero-facts { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 22px; font-size: 13.5px; color: var(--muted); }
.hero-facts b { color: var(--ink); font-weight: 600; }

.cabinet {
  background: #E6ECF3; border: 1px solid var(--line-2); border-radius: var(--radius-l); padding: 14px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
}
.cabinet-cap { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 2px; font-size: 13px; color: var(--ink-2); }
.cabinet-cap button { border: 0; background: none; color: var(--blue); font-size: 13px; font-weight: 500; padding: 2px 4px; }
.drawer {
  position: relative; text-align: left; border: 1px solid var(--line-2); border-radius: var(--radius-s);
  background: linear-gradient(var(--surface), var(--surface-2)); padding: 12px 12px 22px; min-height: 92px;
  display: flex; flex-direction: column; gap: 8px; transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
  box-shadow: inset 0 -3px 0 rgba(20,33,61,.05);
}
.drawer::after { /* handle */
  content: ""; position: absolute; left: 50%; bottom: 9px; width: 34px; height: 5px; margin-left: -17px;
  border-radius: 3px; background: #B9C4D3; box-shadow: inset 0 1px 0 rgba(0,0,0,.12);
}
.drawer:hover { transform: translateY(2px); border-color: var(--muted); }
.drawer[aria-pressed="true"] { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue), inset 0 -3px 0 rgba(20,33,61,.05); }
.drawer[aria-pressed="true"]::after { background: var(--blue); }
.plate {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--brass-soft); border: 1px solid var(--brass-line); border-radius: 4px; padding: 5px 8px;
}
.plate b { font: 600 15px/1.25 var(--display); color: #4A3610; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.plate span { font: 600 13px/1 var(--display); color: var(--brass); font-variant-numeric: tabular-nums; }
.drawer small { font-size: 12px; color: var(--muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.drawer .tab { position: absolute; top: -1px; left: 12px; width: 22px; height: 3px; border-radius: 0 0 2px 2px; }

/* รูปจริงทับภาพแทนเสมอ (ภาพแทนแสดงเมื่อรูปโหลดไม่ได้) */
.cover img, .thumb img, .mini img, .img-prev img, .detail-cover img { position: relative; z-index: 1; }
.status-flag { z-index: 2; }

/* ---------- results ---------- */
.results { padding: 28px 0 64px; }
.results-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.results-head h2 { font: 600 22px/1.3 var(--display); margin: 0; }
.results-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.toolbar .select { width: auto; min-width: 140px; padding-top: 7px; padding-bottom: 7px; font-size: 13.5px; }
.toolbar .grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius-s); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 10px; color: var(--muted); display: grid; place-items: center; }
.seg button[aria-pressed="true"] { background: var(--blue-soft); color: var(--blue); }
.seg svg { width: 17px; height: 17px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px;
  background: var(--blue-soft); color: var(--blue-deep); font-size: 13px; font-weight: 500; border: 0;
}
.chip svg { width: 14px; height: 14px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden;
  display: flex; flex-direction: column; cursor: pointer; transition: border-color .15s;
}
.card:hover { border-color: var(--line-2); }
.card:hover .card-title { color: var(--blue); }
.cover { aspect-ratio: 16 / 9; background: var(--paper); position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; padding: 14px 16px;
  color: #fff; background: var(--c, var(--blue));
}
.cover-fallback::before { /* drawer lines */
  content: ""; position: absolute; inset: 14px 16px auto auto; width: 42%; height: 46%;
  background: repeating-linear-gradient(rgba(255,255,255,.22) 0 2px, transparent 2px 14px);
}
.cover-fallback b { font: 700 26px/1.1 var(--display); position: relative; }
.cover-fallback span { font-size: 12.5px; opacity: .85; position: relative; }
.status-flag {
  position: absolute; top: 10px; left: 10px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: rgba(255,255,255,.94); color: var(--ink-2);
}
.status-flag.beta { color: var(--orange); }
.status-flag.prototype { color: #6B4FA0; }
.status-flag.archived { color: var(--muted); }
.status-flag.private { left: auto; right: 10px; color: var(--red); }
.card-body { padding: 14px 16px 6px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.cat-line { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.dot { width: 9px; height: 9px; border-radius: 2px; flex: none; background: var(--c, var(--blue)); }
.card-title { font: 600 16.5px/1.4 var(--display); margin: 0; color: var(--ink); transition: color .15s; }
.card-desc { margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px 14px; font-size: 12.5px; color: var(--muted); }
.card-foot .btn { padding: 6px 12px; font-size: 13px; }
.featured-star { color: var(--brass); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.list-row { display: grid; grid-template-columns: 76px minmax(0, 1fr) 150px 120px 110px; gap: 16px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.list-row:first-child { border-top: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row .thumb { width: 76px; aspect-ratio: 16/10; border-radius: 5px; overflow: hidden; position: relative; background: var(--paper); }
.list-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.list-row .thumb .cover-fallback { padding: 6px; } .list-row .thumb .cover-fallback b { font-size: 12px; } .list-row .thumb .cover-fallback::before, .list-row .thumb .cover-fallback span { display: none; }
.list-row h3 { font: 600 15px/1.4 var(--display); margin: 0; }
.list-row p { margin: 2px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .meta { font-size: 13px; color: var(--ink-2); }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--radius-m); }
.empty h3 { color: var(--ink); font: 600 18px/1.4 var(--display); margin: 0 0 6px; }

/* ---------- overview ---------- */
.page-head { padding: 34px 0 20px; }
.page-head h1 { font: 700 30px/1.25 var(--display); margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 22px; }
.kpi { padding: 16px 20px; border-left: 1px solid var(--line); }
.kpi:first-child { border-left: 0; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi b { display: block; font: 700 28px/1.2 var(--display); font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi small { font-size: 12.5px; color: var(--ink-2); }
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px 20px 20px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel h2 { font: 600 17px/1.35 var(--display); margin: 0 0 2px; }
.panel > p { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.hbars { display: grid; gap: 7px; }
.hbar { display: grid; grid-template-columns: 120px minmax(0, 1fr) 34px; gap: 10px; align-items: center; font-size: 13.5px; border: 0; background: none; padding: 2px 0; text-align: left; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hbar .track { display: block; height: 14px; background: var(--paper); border-radius: 3px; overflow: hidden; }
.hbar .fill { display: block; height: 100%; border-radius: 3px; background: var(--c, var(--blue)); min-width: 3px; }
.hbar .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
button.hbar:hover .lbl { color: var(--blue); text-decoration: underline; }
.cols { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 18px; border-bottom: 1px solid var(--line-2); }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.col .bar { width: 100%; max-width: 38px; background: var(--blue); border-radius: 3px 3px 0 0; min-height: 2px; }
.col .v { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.cols-x { display: flex; gap: 6px; margin-top: 6px; }
.cols-x span { flex: 1; text-align: center; font-size: 11.5px; color: var(--muted); min-width: 0; overflow: hidden; white-space: nowrap; }
.dq { display: grid; gap: 2px; }
.dq-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.dq-row:first-child { border-top: 0; }
.dq-row b { font-variant-numeric: tabular-nums; }
.dq-row .ok { color: var(--green); } .dq-row .warn { color: var(--orange); } .dq-row .bad { color: var(--red); }
.toplist { margin: 0; padding: 0; list-style: none; counter-reset: t; }
.toplist li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; align-items: baseline; }
.toplist li:first-child { border-top: 0; }
.toplist li::before { counter-increment: t; content: counter(t); font: 600 13px var(--display); color: var(--brass); width: 18px; }
.toplist li span { flex: 1; } .toplist li b { font-variant-numeric: tabular-nums; }

/* ---------- modal / drawer panel ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20, 33, 61, .45); z-index: 60; display: flex; justify-content: center; align-items: flex-start; padding: 6vh 16px; overflow-y: auto; animation: fade .18s ease; }
.overlay.sheet-wrap { justify-content: flex-end; padding: 0; align-items: stretch; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--radius-l); width: 100%; max-width: 760px; box-shadow: var(--shadow-pop); animation: rise .22s cubic-bezier(.2,.8,.2,1); overflow: hidden; }
.modal.sm { max-width: 420px; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.sheet { background: var(--surface); width: min(640px, 100%); height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow-pop); animation: slidein .24s cubic-bezier(.2,.8,.2,1); }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } }
.m-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.m-head h2 { font: 600 18px/1.35 var(--display); margin: 0; flex: 1; min-width: 0; }
.m-body { padding: 20px; overflow-y: auto; }
.sheet .m-body { flex: 1; }
.m-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.m-foot .left { margin-right: auto; }
.detail-cover { aspect-ratio: 16 / 7; max-height: 250px; width: 100%; position: relative; background: var(--paper); }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-cover .cover-fallback b { font-size: 40px; }
.detail { padding: 22px 24px 8px; }
.detail h2 { font: 700 24px/1.3 var(--display); margin: 6px 0 12px; }
.detail .desc { white-space: pre-line; color: var(--ink-2); margin: 0 0 18px; max-width: 70ch; }
.meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 18px; overflow: hidden; }
.meta-grid div { padding: 10px 14px; min-width: 0; box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); }
.meta-grid span { display: block; font-size: 12px; color: var(--muted); }
.meta-grid b { font-weight: 500; font-size: 14px; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12.5px; padding: 2px 9px; border-radius: 4px; background: var(--paper); border: 1px solid var(--line); color: var(--ink-2); }
.note-box { background: var(--brass-soft); border: 1px solid var(--brass-line); border-radius: var(--radius-s); padding: 10px 14px; font-size: 14px; margin-bottom: 18px; white-space: pre-line; }
.note-box b { display: block; font-size: 12.5px; color: var(--brass); }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; width: min(440px, calc(100% - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--radius-s); font-size: 14px; box-shadow: var(--shadow-pop); animation: rise .2s ease; display: flex; gap: 10px; align-items: center; }
.toast.error { background: var(--red); }
.toast svg { width: 18px; height: 18px; flex: none; }

/* ---------- admin console ---------- */
.admin { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.a-side { background: var(--ink); color: #C9D3E3; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.a-side .brand { color: #fff; padding: 4px 8px 18px; }
.a-side .brand small { color: #93A3BD; }
.a-side a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-s); color: #C9D3E3; text-decoration: none; font-size: 14px; font-weight: 500; }
.a-side a:hover { background: rgba(255,255,255,.07); color: #fff; }
.a-side a[aria-current="page"] { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--brass-line); }
.a-side a svg { width: 18px; height: 18px; opacity: .85; }
.a-side .count { margin-left: auto; font-size: 12px; color: #93A3BD; font-variant-numeric: tabular-nums; }
.a-side .sep { height: 1px; background: rgba(255,255,255,.1); margin: 10px 6px; }
.a-side .who { margin-top: auto; padding: 12px; font-size: 13px; border-top: 1px solid rgba(255,255,255,.1); }
.a-side .who b { color: #fff; display: block; font-weight: 500; }
.a-main { padding: 24px 28px 60px; min-width: 0; }
.a-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.a-top h1 { font: 700 24px/1.3 var(--display); margin: 0; flex: 1; min-width: 200px; }
.a-menu-btn { display: none; }
.a-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.a-filters .input { max-width: 300px; }
.a-filters .select { width: auto; min-width: 130px; }
.bulkbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--blue-soft); border: 1px solid #BBD3E6; padding: 8px 12px; border-radius: var(--radius-s); margin-bottom: 12px; font-size: 14px; }
.bulkbar .select { width: auto; padding-top: 5px; padding-bottom: 5px; font-size: 13px; }
.tbl-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th button { border: 0; background: none; padding: 0; font: inherit; color: inherit; display: inline-flex; gap: 4px; align-items: center; }
.tbl td { padding: 9px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.tbl tr:first-child td { border-top: 0; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .t-title { font-weight: 500; color: var(--ink); max-width: 380px; }
.tbl .t-title small { display: block; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.tbl .mini { width: 54px; aspect-ratio: 16/10; border-radius: 4px; overflow: hidden; position: relative; background: var(--paper); }
.tbl .mini img { width: 100%; height: 100%; object-fit: cover; }
.tbl .mini .cover-fallback { padding: 3px 5px; } .tbl .mini .cover-fallback b { font-size: 10px; } .tbl .mini .cover-fallback::before, .tbl .mini .cover-fallback span { display: none; }
.tbl .cat-line { white-space: nowrap; }
.tbl .acts { white-space: nowrap; text-align: right; }
.code { font: 500 12.5px/1 var(--body); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.active { background: var(--green-soft); color: var(--green); }
.badge.beta { background: var(--orange-soft); color: var(--orange); }
.badge.prototype { background: #ECE6F5; color: #5B3F90; }
.badge.archived { background: var(--paper); color: var(--muted); }
.badge.private { background: var(--red-soft); color: var(--red); }
.badge.public { background: var(--blue-soft); color: var(--blue); }
.badge.admin { background: var(--brass-soft); color: #6B4E12; }
.link-ok { color: var(--green); } .link-warn { color: var(--orange); } .link-bad { color: var(--red); } .link-none { color: var(--line-2); }
.ls { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; white-space: nowrap; }
.ls i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 0; font-size: 13.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-sec { font: 600 14px/1.4 var(--display); color: var(--ink-2); margin: 22px 0 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.form-sec:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.img-pick { display: grid; grid-template-columns: 180px minmax(0,1fr); gap: 14px; align-items: start; }
.img-prev { aspect-ratio: 16/9; border-radius: var(--radius-s); overflow: hidden; position: relative; background: var(--paper); border: 1px solid var(--line); }
.img-prev img { width: 100%; height: 100%; object-fit: cover; }
.drop { border: 1.5px dashed var(--line-2); border-radius: var(--radius-s); padding: 12px; text-align: center; font-size: 13px; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 18px; }
.tabs button { border: 0; background: none; padding: 8px 12px; font-weight: 500; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--blue); border-bottom-color: var(--blue); }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { padding: 10px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.hist li:first-child { border-top: 0; }
.hist .when { color: var(--muted); font-size: 12.5px; }
.diff { margin-top: 6px; font-size: 12.5px; display: grid; gap: 3px; }
.diff div { display: grid; grid-template-columns: 100px minmax(0,1fr); gap: 8px; }
.diff del { color: var(--red); text-decoration: line-through; overflow-wrap: anywhere; }
.diff ins { color: var(--green); text-decoration: none; overflow-wrap: anywhere; }
.swatch { width: 16px; height: 16px; border-radius: 4px; display: inline-block; vertical-align: middle; border: 1px solid rgba(0,0,0,.1); }
.color-in { width: 48px; height: 38px; padding: 2px; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--surface); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 20px; align-items: start; }
.login-box { padding: 24px; }
.login-box p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.alert { padding: 10px 14px; border-radius: var(--radius-s); font-size: 14px; margin-bottom: 14px; }
.alert.err { background: var(--red-soft); color: var(--red); }
.alert.info { background: var(--blue-soft); color: var(--blue-deep); }


/* ---------- public shell: เมนูซ้าย ย่อ/ขยายได้ ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns .2s ease; }
.shell.collapsed { grid-template-columns: 68px minmax(0, 1fr); }
.side {
  background: var(--ink); color: #C9D3E3; position: sticky; top: 0; height: 100vh; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; padding: 14px 10px; z-index: 40;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; text-decoration: none; color: #fff; min-width: 0; }
.side-brand .brand-mark { width: 32px; height: 32px; }
.side-brand b { display: block; font: 700 17px/1.2 var(--display); white-space: nowrap; }
.side-brand small { display: block; font-size: 11px; color: #93A3BD; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-link {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 11px; border-radius: var(--radius-s);
  color: #C9D3E3; text-decoration: none; font-size: 14px; font-weight: 500; border: 0; background: none; text-align: left;
  white-space: nowrap; min-width: 0;
}
.side-link svg { width: 19px; height: 19px; flex: none; opacity: .9; }
.side-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-link[aria-current="page"] { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--brass-line); }
.side-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.side-n { font-size: 12px; color: #93A3BD; font-variant-numeric: tabular-nums; }
.side-chev svg, .side-ext svg { width: 15px; height: 15px; opacity: .6; transition: transform .2s; }
.side-group[aria-expanded="false"] .side-chev svg { transform: rotate(-90deg); }
.side-sub { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 4px; }
.side-link.sub { padding: 7px 11px 7px 20px; font-size: 13.5px; font-weight: 400; }
.side-link.sub .dot { width: 10px; height: 10px; margin: 0 4px; }
.side-sep { height: 1px; background: rgba(255,255,255,.1); margin: 10px 6px; }
.side-foot { border-top: 1px solid rgba(255,255,255,.1); padding-top: 10px; margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.side-collapse { color: #93A3BD; }
.shell.collapsed .side { padding: 14px 8px; }
.shell.collapsed .side-txt, .shell.collapsed .side-n, .shell.collapsed .side-chev, .shell.collapsed .side-ext, .shell.collapsed .side-sub { display: none; }
.shell.collapsed .side-link, .shell.collapsed .side-brand { justify-content: center; padding-left: 0; padding-right: 0; }
.shell.collapsed .side-brand { padding-bottom: 16px; }
.shell-main { min-width: 0; display: flex; flex-direction: column; }
.shell-main > .site-foot { margin-top: auto; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 10px;
  padding: 0 20px 0 12px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.topbar-title { font: 600 16px/1.3 var(--display); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-who { font-size: 13px; color: var(--muted); }
.scrim { display: none; }
@media (max-width: 1240px) { .shell:not(.collapsed) .hero .wrap { grid-template-columns: 1fr; gap: 28px; } }
@media (max-width: 1020px) {
  .shell, .shell.collapsed { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; width: 264px; transform: translateX(-100%); transition: transform .22s ease; z-index: 80; }
  .shell.side-open .side { transform: none; box-shadow: var(--shadow-pop); }
  .shell.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(20,33,61,.45); z-index: 75; }
  .shell.collapsed .side-txt, .shell.collapsed .side-n, .shell.collapsed .side-chev, .shell.collapsed .side-ext { display: revert; }
  .shell.collapsed .side-sub:not([hidden]) { display: flex; }
  .shell.collapsed .side-link, .shell.collapsed .side-brand { justify-content: flex-start; padding-left: 11px; padding-right: 11px; }
  .side-collapse { display: none; }
  .topbar-who { display: none; }
}
@media print { .side, .topbar, .scrim { display: none !important; } }

/* ---------- footer ---------- */
.site-foot { border-top: 1px solid var(--line); padding: 22px 0 30px; color: var(--muted); font-size: 13px; background: var(--surface); }
.site-foot .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- print report ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4 portrait; margin: 14mm; }
  body { background: #fff; font-size: 11.5pt; }
  #app, #modal-root, #toast-root { display: none !important; }
  #print-root { display: block; color: #000; }
  .pr-head { text-align: center; border-bottom: 2px solid #000; padding-bottom: 10px; margin-bottom: 14px; }
  .pr-head h1 { font: 700 18pt/1.3 var(--display); margin: 0 0 4px; }
  .pr-head p { margin: 2px 0; }
  .pr-tbl { width: 100%; border-collapse: collapse; font-size: 10pt; }
  .pr-tbl th, .pr-tbl td { border: 1px solid #777; padding: 5px 7px; vertical-align: top; text-align: left; }
  .pr-tbl th { background: #EEE; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pr-tbl tr { break-inside: avoid; }
  .pr-sum { display: flex; justify-content: space-between; margin-top: 16px; gap: 20px; }
  .pr-sign { text-align: center; margin-top: 40px; margin-left: auto; width: 260px; }
}

/* ---------- responsive ---------- */
@media (max-width: 1020px) {
  .hero .wrap { grid-template-columns: 1fr; gap: 28px; }
  .panels, .settings-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kpi:nth-child(3) { border-left: 0; } .kpi:nth-child(n+3) { border-top: 1px solid var(--line); }
  .admin { grid-template-columns: 1fr; }
  .a-side { position: fixed; left: 0; top: 0; z-index: 70; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .admin.menu-open .a-side { transform: none; box-shadow: var(--shadow-pop); }
  .a-menu-btn { display: inline-flex; }
  .list-row { grid-template-columns: 64px minmax(0,1fr) 110px; }
  .list-row .hide-md { display: none; }
}
@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .site-nav .lbl { display: none; }
  .brand small { display: none; }
  .hero { padding: 26px 0 24px; }
  .cabinet { grid-template-columns: repeat(2, minmax(0,1fr)); padding: 10px; gap: 8px; }
  .drawer small { display: none; }
  .drawer { min-height: 66px; }
  .search-big kbd { display: none; }
  .toolbar .select { min-width: 0; flex: 1 1 140px; }
  .grid { grid-template-columns: 1fr; }
  .meta-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .img-pick { grid-template-columns: 1fr; }
  .a-main { padding: 18px 16px 50px; }
  .list-row { grid-template-columns: 56px minmax(0,1fr); gap: 12px; }
  .list-row .hide-sm { display: none; }
  .hbar { grid-template-columns: 90px minmax(0,1fr) 30px; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: var(--radius-l) var(--radius-l) 0 0; max-height: 94vh; overflow-y: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.results { scroll-margin-top: 60px; }
