:root {
  --navy: #0d1b3a;
  --navy-2: #15294f;
  --navy-3: #1e3766;
  --red: #e11d27;
  --red-dark: #b5121b;
  --bg: #f2f4f8;
  --card: #ffffff;
  --line: #e4e8ef;
  --text: #18202f;
  --muted: #6a7487;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .06);

  --green: #15803d;  --green-bg: #dcfce7;
  --amber: #a16207;  --amber-bg: #fef3c7;
  --red-t: #c81e1e;  --red-bg: #fee2e2;
  --blue: #1d4ed8;   --blue-bg: #dbeafe;
  --purple: #6d28d9; --purple-bg: #ede9fe;
  --orange: #c2410c; --orange-bg: #ffedd5;
  --gray: #475569;   --gray-bg: #e8ecf2;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex: none; background: var(--navy); color: #dfe6f3;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: block; padding: 22px 22px 18px; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { display: block; font-weight: 800; font-style: italic; font-size: 26px; letter-spacing: .5px; color: var(--red); line-height: 1; }
.brand-sub { display: block; margin-top: 6px; font-size: 11px; letter-spacing: 3px; color: #9fb0cf; font-weight: 600; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  text-decoration: none; color: #c9d3e6; position: relative;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.on { background: linear-gradient(90deg, var(--red), var(--red-dark)); color: #fff; box-shadow: 0 6px 16px rgba(225,29,39,.35); }
.nav a svg.ic { width: 21px; height: 21px; }
.nav .lbl { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.nav .lbl b { font-weight: 600; font-size: 14px; }
.nav .lbl small { font-size: 11.5px; opacity: .7; }
.nav .soon { margin-left: auto; font-size: 10px; padding: 2px 7px; border-radius: 99px; background: rgba(255,255,255,.1); color: #aebbd3; white-space: nowrap; }
.nav .ready { margin-left: auto; width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }
.nav a.on .ready { background: #fff; }
.sidebar-foot { margin-top: auto; padding: 18px 22px; font-size: 11px; color: #6f81a6; border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 16px 28px; color: #fff;
  background:
    linear-gradient(115deg, transparent 62%, rgba(225,29,39,.9) 62.2%, rgba(225,29,39,.9) 63.4%, transparent 63.6%),
    linear-gradient(100deg, var(--navy) 0%, var(--navy-2) 55%, var(--navy-3) 100%);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: 1.5px; line-height: 1.1; }
.topbar p { margin: 2px 0 0; font-size: 13px; color: #c3cee4; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 0; background: rgba(255,255,255,.1); color: inherit; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.18); }
.menu-btn { display: none; }
.view { padding: 24px 28px 48px; max-width: 1500px; width: 100%; }
.scrim { display: none; }

/* ---------- page head ---------- */
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head > div { flex: 1; min-width: 220px; }
.page-head h2 { margin: 0; font-size: 24px; font-weight: 800; color: var(--navy); }
.page-head p { margin: 2px 0 0; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--red); border-bottom-color: var(--red); }
.tabs a span { font-weight: 500; font-size: 12px; background: var(--gray-bg); border-radius: 99px; padding: 1px 8px; margin-left: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c9d0dc; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red-t); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- cards & KPI ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card + .card, .grid + .card, .card + .grid, .kpis + .card, .kpis + .grid { margin-top: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 17px; font-weight: 700; color: var(--navy); flex: 1; min-width: 160px; }
.card-head a.more { font-size: 13px; color: var(--blue); text-decoration: none; font-weight: 600; }
.grid { display: grid; gap: 18px; }
.grid > .card { margin-top: 0; }
.grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  display: flex; gap: 12px; align-items: center; padding: 16px; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); border-top: 4px solid var(--tone, var(--blue)); text-decoration: none;
}
.kpi .kpi-ic { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--tone-bg, var(--blue-bg)); color: var(--tone, var(--blue)); flex: none; }
.kpi .kpi-ic svg.ic { width: 22px; height: 22px; }
.kpi b { display: block; font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--navy); }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi.dark { background: linear-gradient(135deg, var(--navy), var(--navy-3)); border-top-color: var(--red); }
.kpi.dark b, .kpi.dark span { color: #fff; }
.kpi.dark .kpi-ic { background: rgba(255,255,255,.12); color: #fff; }
.tone-green { --tone: var(--green); --tone-bg: var(--green-bg); }
.tone-amber { --tone: var(--amber); --tone-bg: var(--amber-bg); }
.tone-red { --tone: var(--red-t); --tone-bg: var(--red-bg); }
.tone-blue { --tone: var(--blue); --tone-bg: var(--blue-bg); }
.tone-purple { --tone: var(--purple); --tone-bg: var(--purple-bg); }
.tone-orange { --tone: var(--orange); --tone-bg: var(--orange-bg); }
.tone-gray { --tone: var(--gray); --tone-bg: var(--gray-bg); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: #fafbfd; flex: 1; min-width: 200px; max-width: 360px; color: var(--muted); }
.search input { border: 0; outline: 0; background: transparent; padding: 9px 0; width: 100%; color: var(--text); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13px; color: var(--muted); }
.chip span { font-size: 11.5px; background: var(--gray-bg); border-radius: 99px; padding: 0 7px; margin-left: 2px; }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip.on span { background: rgba(255,255,255,.2); }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); cursor: pointer; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.tbl { width: 100%; border-collapse: collapse; min-width: 760px; }
.tbl th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 10px 10px; border-bottom: 1px solid var(--line); background: #f8f9fc; white-space: nowrap; }
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #fafbfe; }
.tbl .num { width: 36px; color: var(--muted); text-align: center; }
.tbl .nowrap { white-space: nowrap; }
.tbl td.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.tbl .act { width: 1%; white-space: nowrap; text-align: right; }
.tbl tr.done td:not(.act) { opacity: .62; }
.t-main { font-weight: 600; color: var(--text); cursor: pointer; text-decoration: none; }
.t-main:hover { color: var(--red); text-decoration: underline; }
.t-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.sku { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 12.5px; font-weight: 600; color: var(--navy-3); }
.clip { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.overdue { color: var(--red-t); font-weight: 600; }
.muted { color: var(--muted); }
.row-btn { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 6px; border-radius: 8px; display: inline-grid; place-items: center; }
.row-btn:hover { background: var(--gray-bg); color: var(--text); }
.row-btn svg.ic { width: 16px; height: 16px; }

.person { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; flex: none; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--tone-bg); color: var(--tone); }
select.pill {
  appearance: none; border: 0; cursor: pointer; padding-right: 24px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 11px top 50%, right 7px top 50%; background-size: 4px 4px; background-repeat: no-repeat;
  background-color: var(--tone-bg);
}
.progress { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.bar { flex: 1; height: 8px; background: var(--gray-bg); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--tone, var(--blue)); }
.progress b { font-size: 12.5px; min-width: 38px; text-align: right; }

.link-btn { display: inline-flex; align-items: center; gap: 4px; color: var(--blue); font-weight: 600; text-decoration: none; font-size: 13px; white-space: nowrap; }
.link-btn:hover { text-decoration: underline; }
.link-btn svg.ic { width: 14px; height: 14px; }

/* ---------- mini lists (dashboard) ---------- */
.mini { list-style: none; margin: 0; padding: 0; }
.mini li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mini li:last-child { border-bottom: 0; }
.mini .grow { flex: 1; min-width: 0; }
.mini .grow .t-main { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .empty { color: var(--muted); justify-content: center; padding: 24px 0; }

/* ---------- docs summary ---------- */
.stack { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--gray-bg); margin: 10px 0 12px; }
.stack i { display: block; height: 100%; background: var(--tone); }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 14px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--tone); }
.legend b { margin-left: auto; }
.big-num { font-size: 32px; font-weight: 800; color: var(--navy); line-height: 1; }

/* ---------- soon / notice ---------- */
.soon-card { text-align: center; padding: 56px 24px; }
.soon-card .kpi-ic { margin: 0 auto 14px; width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--gray-bg); color: var(--navy-3); }
.soon-card .kpi-ic svg.ic { width: 30px; height: 30px; }
.soon-card h3 { margin: 0 0 6px; font-size: 20px; color: var(--navy); }
.soon-card p { margin: 0 auto; max-width: 460px; color: var(--muted); }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--blue-bg); color: var(--blue); margin-bottom: 16px; font-size: 13.5px; }
.notice.err { background: var(--red-bg); color: var(--red-t); }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }

/* ---------- modal ---------- */
.modal { border: 0; border-radius: 18px; padding: 0; width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 24px 60px rgba(13,27,58,.3); }
.modal::backdrop { background: rgba(13, 27, 58, .55); }
.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.modal-head { display: flex; align-items: center; padding: 16px 20px; background: var(--navy); color: #fff; }
.modal-head h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfd; }
.spacer { flex: 1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--navy); }
.field label .req { color: var(--red); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; width: 100%; outline: 0;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--navy-3); box-shadow: 0 0 0 3px rgba(30,55,102,.12); }
.field textarea { min-height: 84px; resize: vertical; }
.field .range { display: flex; align-items: center; gap: 10px; }
.field .range input { padding: 0; accent-color: var(--red); }
.field .range output { min-width: 44px; font-weight: 700; text-align: right; }
.field.invalid input { border-color: var(--red); }

/* ---------- gate & toast ---------- */
.gate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--navy), var(--navy-3)); }
.gate[hidden] { display: none; }
.gate-card { background: #fff; border-radius: 18px; padding: 32px 28px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.gate-card h2 { margin: 0; color: var(--navy); }
.gate-card p { margin: 0; color: var(--muted); }
.gate-card input { border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; text-align: center; }
.gate-card .btn { justify-content: center; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red-t); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .grid.g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 14px 16px; }
  .topbar h1 { font-size: 19px; }
  .view { padding: 18px 16px 40px; }
  .grid.g3, .grid.g2 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .card { padding: 16px; }
}
@media (max-width: 560px) {
  .modal-body { grid-template-columns: 1fr; }
  .kpi { padding: 12px; gap: 10px; }
  .kpi .kpi-ic { width: 36px; height: 36px; }
  .kpi b { font-size: 22px; }
  .search { max-width: none; }
}
