@import url('/vendor/fonts/plex/thai-400.css');
@import url('/vendor/fonts/plex/latin-400.css');
@import url('/vendor/fonts/plex/thai-500.css');
@import url('/vendor/fonts/plex/latin-500.css');
@import url('/vendor/fonts/plex/thai-600.css');
@import url('/vendor/fonts/plex/latin-600.css');
@import url('/vendor/fonts/plex/thai-700.css');
@import url('/vendor/fonts/plex/latin-700.css');

:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --ink: #151a2d;
  --ink-2: #393f57;
  --muted: #6b7189;
  --faint: #9ca2b8;
  --line: #e8eaf1;
  --line-strong: #d6dae6;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --ring: rgba(79, 70, 229, 0.18);
  --ok: #0e9f6e;
  --ok-soft: #e4f6ee;
  --warn: #c27a03;
  --warn-soft: #fff4de;
  --danger: #dc3b4b;
  --danger-soft: #fdecee;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px -10px rgba(16, 24, 40, 0.1);
  --shadow-lg: 0 24px 60px -16px rgba(16, 24, 40, 0.3);
  --sidebar-w: 252px;
  --sb-bg: #11142b;
  --sb-bg-2: #181c3b;
  --sb-ink: #a9aed0;
}

/* Accent colour per document type */
.t-QO { --tc: #7c3aed; --tc-soft: #f2edff; }
.t-BN { --tc: #d97706; --tc-soft: #fff3e0; }
.t-DN { --tc: #0d9488; --tc-soft: #e1f5f2; }
.t-TIV { --tc: #2563eb; --tc-soft: #e7efff; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans Thai', 'Sarabun', Tahoma, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.ic { display: inline-flex; vertical-align: middle; flex: none; }
.ic svg { width: 16px; height: 16px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; color: var(--ink); }
[v-cloak] { display: none; }
::selection { background: #dcd9ff; }

/* ================= layout ================= */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: radial-gradient(420px 260px at 0% 0%, rgba(124, 108, 255, 0.18), transparent 70%), linear-gradient(180deg, var(--sb-bg), var(--sb-bg-2));
  color: var(--sb-ink);
  padding: 20px 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
  z-index: 40;
}
.sb-brand { display: flex; gap: 12px; align-items: center; padding: 0 6px 18px; color: #fff; text-decoration: none !important; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, #8a7bff, #36c2d6);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; letter-spacing: 0.02em;
  overflow: hidden; box-shadow: 0 8px 18px -8px rgba(138, 123, 255, 0.9);
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.sb-name { color: #fff; font-weight: 600; font-size: 15px; line-height: 1.25; }
.sb-sub { font-size: 12px; color: var(--sb-ink); }
.sb-create { display: block; margin: 0 2px 8px; }
.sb-create > .btn { width: 100%; height: 40px; }
.sb-label { font-size: 12px; color: #6c7299; padding: 16px 12px 6px; font-weight: 500; }
.sb-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px;
  color: var(--sb-ink); font-weight: 500; position: relative; transition: background 0.15s, color 0.15s;
}
.sb-link:hover { background: rgba(255, 255, 255, 0.05); color: #fff; text-decoration: none; }
.sb-link.active { background: rgba(255, 255, 255, 0.09); color: #fff; }
.sb-link.active::before { content: ''; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: linear-gradient(#8a7bff, #36c2d6); }
.sb-link .ic svg { width: 18px; height: 18px; }
.sb-link[class*='t-'] .ic { color: var(--tc); filter: brightness(1.45) saturate(0.9); }
.sb-count { margin-left: auto; font-size: 11.5px; font-weight: 600; background: rgba(255, 255, 255, 0.1); color: #fff; border-radius: 20px; padding: 0 8px; min-width: 22px; text-align: center; line-height: 20px; }
.sb-foot { margin-top: auto; padding-top: 14px; }
.sb-company { margin-top: 10px; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.06); font-size: 12px; line-height: 1.55; }
.sb-company b { color: #fff; font-weight: 500; font-size: 12.5px; }
.sb-backdrop { display: none; }
.sb-user { margin-top: 10px; padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.06); display: flex; align-items: center; gap: 10px; }
.sb-user .avatar { width: 32px; height: 32px; border-radius: 9px; }
.sb-user-text { display: flex; flex-direction: column; min-width: 0; font-size: 12px; line-height: 1.35; }
.sb-user-text b { color: #fff; font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-logout { margin-left: auto; background: none; border: 0; color: var(--sb-ink); cursor: pointer; padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.sb-logout:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.sb-logout .ic svg { width: 17px; height: 17px; }

/* ================= login ================= */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(700px 400px at 85% 10%, rgba(54, 194, 214, 0.35), transparent 65%), radial-gradient(600px 400px at 10% 90%, rgba(167, 139, 250, 0.4), transparent 60%), linear-gradient(140deg, #11142b, #1d2150 55%, #2b2a7a);
}
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 28px; box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.55); display: flex; flex-direction: column; gap: 16px; animation: rise 0.25s ease-out; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 15px; font-size: 18px; }
.login-title { font-size: 18px; font-weight: 600; line-height: 1.3; }
.login-btn { height: 44px; font-size: 15px; margin-top: 4px; }
.login-error { display: flex; gap: 8px; align-items: center; background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 9px 12px; font-size: 13.5px; }

.notice { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--warn-soft); color: #8a5a00; border: 1px solid #f6dfa8; border-radius: 12px; padding: 10px 14px; margin-bottom: 18px; font-size: 14px; }
.notice .btn { margin-left: auto; }
.notice.info { background: var(--primary-soft); color: var(--primary); border-color: #d9d5ff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 28px 36px 64px; max-width: 1340px; width: 100%; margin: 0 auto; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 272px; height: auto; transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: var(--shadow-lg); }
  .layout.nav-open .sidebar { transform: none; }
  .layout.nav-open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgba(12, 14, 30, 0.45); z-index: 39; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
    padding: 10px 16px; background: rgba(255, 255, 255, 0.86); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  }
  .topbar .brand-mark { width: 32px; height: 32px; border-radius: 9px; font-size: 12px; box-shadow: none; }
  .tb-name { font-weight: 600; font-size: 14.5px; }
  .topbar .spacer { flex: 1; }
  .content { padding: 20px 16px 48px; }
}

/* ================= page header ================= */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--primary); }
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 24px; letter-spacing: -0.01em; line-height: 1.25; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.page-head .spacer { flex: 1; }
.page-icon { width: 46px; height: 46px; border-radius: 13px; background: var(--tc-soft, var(--primary-soft)); color: var(--tc, var(--primary)); display: grid; place-items: center; flex: none; }
.page-icon .ic svg { width: 22px; height: 22px; }

/* ================= cards ================= */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .ed-grid > .card + .card, .view-side > .card + .card { margin-top: 0; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.card-title > .ic svg { width: 18px; height: 18px; color: var(--faint); }
.card-title .spacer { flex: 1; }
.card-sub { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.table-card { padding: 0; overflow: hidden; }
.table-card .table-toolbar { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.section-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; margin-bottom: 16px; }
.section-title .num-badge { width: 26px; height: 26px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 13px; font-weight: 700; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mt { margin-top: 16px; }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1000px) { .grid-main, .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }

/* ================= buttons ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 500; font-size: 14px; height: 38px; padding: 0 15px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); border-color: #c8cddc; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, #5b52f0, #4a40dc); border-color: #463cd6; color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 6px 14px -6px rgba(79, 70, 229, 0.65);
}
.btn-primary:hover { background: linear-gradient(180deg, #5249e6, #4136c9); border-color: #4136c9; }
.btn-danger { color: var(--danger); border-color: #f2c6cb; }
.btn-danger:hover { background: var(--danger-soft); border-color: #eeb3ba; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn-ghost:hover { background: rgba(21, 26, 45, 0.05); border-color: transparent; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn-icon { width: 34px; padding: 0; }
.btn-sm.btn-icon { width: 32px; }
.btn .ic svg { width: 16px; height: 16px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 80; animation: pop 0.12s ease-out; }
.dropdown-menu button, .dropdown-menu a { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.dropdown-menu button:hover, .dropdown-menu a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.dropdown-menu button:disabled { opacity: 0.4; cursor: default; background: none; }
.dropdown-menu .label { font-size: 11.5px; color: var(--faint); padding: 8px 10px 4px; font-weight: 600; letter-spacing: 0.03em; }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.dropdown-menu .danger { color: var(--danger); }
.dropdown-menu .danger:hover { background: var(--danger-soft); color: var(--danger); }
.mt-ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--tc-soft); color: var(--tc); flex: none; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ================= forms ================= */
label.field, div.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); font-weight: 500; min-width: 0; }
.input, select.input, textarea.input {
  font: inherit; font-size: 14px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 8px 12px; width: 100%; min-width: 0; min-height: 40px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input::placeholder { color: var(--faint); }
.input:hover { border-color: #c4c9d8; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.input[readonly] { background: var(--surface-2); }
.input.num { text-align: right; }
select.input { appearance: none; padding-right: 34px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7189' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px; }
textarea.input { resize: vertical; line-height: 1.5; }
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.form-grid .span-4, .form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 800px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .span-3, .form-grid .span-4 { grid-column: 1 / -1; } }
@media (max-width: 520px) { .form-grid, .form-grid.cols-2 { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 400; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg label { padding: 5px 12px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--muted); font-size: 13px; }
.seg label.on { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.seg input { display: none; }

/* ================= tables ================= */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: #fafaff; }
.table tr.clickable { cursor: pointer; }
.table tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--line); border-bottom: 0; }
.table th.th-num, .table th.num { text-align: right; }
.doc-no { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
a.doc-no:hover { color: var(--primary); }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.amount { font-weight: 600; color: var(--ink); }
.row-actions { opacity: 0.55; transition: opacity 0.12s; white-space: nowrap; }
tr:hover .row-actions { opacity: 1; }
.empty { text-align: center; color: var(--muted); padding: 48px 10px !important; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 36px 10px; color: var(--muted); text-align: center; }
.empty-state .es-icon { width: 52px; height: 52px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; color: var(--faint); }
.empty-state .es-icon .ic svg { width: 24px; height: 24px; }
.empty-state b { color: var(--ink); font-weight: 600; }

.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); font: inherit; font-size: 13.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; transition: all 0.15s; }
.pill:hover { border-color: var(--line-strong); }
.pill.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.pill .count { font-size: 11.5px; background: var(--surface-2); color: var(--muted); border-radius: 20px; padding: 0 7px; line-height: 18px; }
.pill.active .count { background: rgba(255, 255, 255, 0.18); color: #fff; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .input, .table-toolbar .input { width: auto; min-height: 36px; padding-top: 6px; padding-bottom: 6px; }
.toolbar .spacer, .table-toolbar .spacer { flex: 1; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.search .input { width: 100%; padding-left: 36px; }
.search > .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }

/* ================= badges, avatars ================= */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; height: 24px; padding: 0 10px; border-radius: 999px; font-weight: 500; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-draft { background: #eef0f5; color: #5d6379; }
.st-pending { background: var(--warn-soft); color: var(--warn); }
.st-done { background: var(--ok-soft); color: var(--ok); }
.st-rejected, .st-cancelled { background: var(--danger-soft); color: var(--danger); }
.type-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; padding: 2px 9px 2px 7px; border-radius: 7px; background: var(--tc-soft, var(--primary-soft)); color: var(--tc, var(--primary)); white-space: nowrap; }
.type-chip .ic svg { width: 14px; height: 14px; }
.code-chip { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.avatar { width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; color: var(--av); background: var(--av-soft); }
.who { display: flex; align-items: center; gap: 11px; min-width: 0; }
.who-text { min-width: 0; }
.who-name { font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.who-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }

/* ================= dashboard ================= */
.hero-card {
  position: relative; overflow: hidden; color: #fff; border: 0; padding: 24px;
  background: radial-gradient(600px 260px at 100% 0%, rgba(54, 194, 214, 0.45), transparent 65%), radial-gradient(500px 300px at 0% 100%, rgba(167, 139, 250, 0.35), transparent 60%), linear-gradient(125deg, #2e2a9e, #4f46e5 55%, #6d5dfc);
  box-shadow: 0 18px 40px -18px rgba(79, 70, 229, 0.7);
}
.hero-card::after { content: ''; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; border: 36px solid rgba(255, 255, 255, 0.06); }
.hero-label { font-size: 13.5px; opacity: 0.85; }
.hero-value { font-size: 36px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin: 4px 0 6px; font-variant-numeric: tabular-nums; }
.hero-value small { font-size: 16px; font-weight: 500; opacity: 0.8; margin-left: 4px; }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.hero-card .delta { background: rgba(255, 255, 255, 0.16); }
.delta.up { color: #5eead4; }
.delta.down { color: #fda4af; }
.card .delta.up { color: var(--ok); background: var(--ok-soft); }
.card .delta.down { color: var(--danger); background: var(--danger-soft); }
.hero-card .delta.up, .hero-card .delta.down { background: rgba(255, 255, 255, 0.16); }
.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 22px; position: relative; z-index: 1; }
.quick a { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.16); color: #fff; border-radius: 12px; padding: 12px; display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 13.5px; transition: background 0.15s, transform 0.15s; }
.quick a:hover { background: rgba(255, 255, 255, 0.18); text-decoration: none; transform: translateY(-1px); }
.quick .q-text { min-width: 0; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick .q-text small { display: block; font-size: 11.5px; opacity: 0.75; font-weight: 400; }
.quick .q-ic { width: 30px; height: 30px; border-radius: 9px; background: rgba(255, 255, 255, 0.95); color: var(--tc); display: grid; place-items: center; flex: none; }
@media (max-width: 640px) { .quick { grid-template-columns: 1fr 1fr; } .hero-value { font-size: 30px; } }

.kpi-label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.kpi-value small { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.kpi-foot { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--muted); margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.progress { height: 8px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; display: flex; margin-top: 14px; }
.progress span { display: block; height: 100%; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 3px; margin-right: 6px; }

.type-card { display: flex; flex-direction: column; gap: 4px; position: relative; transition: box-shadow 0.15s, transform 0.15s; color: inherit; }
.type-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }
.type-card .tc-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tc-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--tc-soft); color: var(--tc); }
.tc-icon .ic svg { width: 20px; height: 20px; }
.tc-name { font-weight: 600; color: var(--ink); }
.tc-arrow { color: var(--faint); }
.type-card:hover .tc-arrow { color: var(--tc); }

.chart { position: relative; height: 230px; display: flex; align-items: flex-end; gap: 8px; padding: 10px 0 26px 44px; }
.chart-grid { position: absolute; inset: 10px 0 26px 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.chart-grid div { height: 0; border-top: 1px dashed var(--line); font-size: 11px; color: var(--faint); }
.chart-grid div:last-child { border-top-style: solid; border-color: var(--line-strong); }
.chart-grid div span { position: relative; top: -9px; background: var(--surface); padding-right: 6px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; position: relative; z-index: 1; }
.bar { width: 100%; max-width: 30px; border-radius: 6px 6px 3px 3px; min-height: 3px; background: linear-gradient(180deg, #c4bdff, #9d93ff); transition: filter 0.15s; }
.bar-col.current .bar { background: linear-gradient(180deg, #7c6cff, #4f46e5); box-shadow: 0 8px 18px -8px rgba(79, 70, 229, 0.8); }
.bar-col:hover .bar { filter: brightness(0.92); }
.bar-col .bar-x { position: absolute; bottom: -24px; font-size: 11.5px; color: var(--muted); }
.bar-col.current .bar-x { color: var(--primary); font-weight: 600; }
.bar-tip { position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 0.12s; }
.bar-wrap { position: relative; width: 100%; display: flex; justify-content: center; align-items: flex-end; height: 100%; }
.bar-col:hover .bar-tip { opacity: 1; }

.due-list { display: flex; flex-direction: column; }
.due-item { display: flex; align-items: center; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--line); color: inherit; }
.due-item:last-child { border-bottom: 0; }
.due-item:hover { text-decoration: none; }
.due-item:hover .who-name { color: var(--primary); }
.due-right { margin-left: auto; text-align: right; }
.due-tag { font-size: 12px; color: var(--muted); }
.due-tag.late { color: var(--danger); font-weight: 500; }

/* ================= doc list ================= */
.mini { padding: 16px 18px; }
.mini .kpi-value { font-size: 21px; }
.mini .kpi-label .dot { width: 8px; height: 8px; border-radius: 50%; }

/* ================= editor ================= */
.ed-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .ed-grid { grid-template-columns: 1fr; } }
.items-table th { padding: 10px 6px; }
.items-table td { padding: 8px 6px; vertical-align: top; border-bottom: 1px solid var(--line); }
.items-table tbody tr:hover { background: transparent; }
.items-table .input { min-height: 38px; padding: 7px 10px; background: var(--surface-2); border-color: transparent; }
.items-table .input:hover { border-color: var(--line-strong); }
.items-table .input:focus { background: #fff; border-color: var(--primary); }
.items-table .c-idx { width: 40px; text-align: center; padding-top: 14px; }
.idx { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; color: var(--muted); font-weight: 600; }
.items-table .c-qty { width: 96px; }
.items-table .c-unit { width: 88px; }
.items-table .c-price { width: 128px; }
.items-table .c-disc { width: 112px; }
.items-table .c-amt { width: 128px; padding-top: 16px; font-weight: 600; }
.items-table .c-act { width: 42px; padding-top: 10px; }
.items-table textarea.input { margin-top: 6px; font-size: 13px; min-height: 34px; color: var(--ink-2); }
.add-row { margin-top: 12px; border-style: dashed; color: var(--primary); background: var(--primary-soft); border-color: #cfcaff; box-shadow: none; }
.add-row:hover { background: #e5e2ff; border-color: #b9b2ff; }
.bottom-grid { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 24px; margin-top: 20px; align-items: start; }
@media (max-width: 900px) { .bottom-grid { grid-template-columns: 1fr; } }
.totals-box { width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 16px 14px; }
.totals-box .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; color: var(--ink-2); }
.totals-box .row:last-of-type { border-bottom: 0; }
.totals-box .row .num { color: var(--ink); font-weight: 500; }
.totals-box .row.grand { font-size: 16px; font-weight: 600; color: var(--ink); border-bottom: 0; border-top: 1px solid var(--line-strong); margin-top: 6px; padding-top: 12px; }
.totals-box .row.grand .num { font-size: 22px; font-weight: 700; color: var(--primary); }
.totals-box .row .input { width: 130px; min-height: 34px; padding-top: 5px; padding-bottom: 5px; background: #fff; }
.baht-chip { background: var(--primary-soft); color: var(--primary); border-radius: 9px; padding: 8px 12px; font-weight: 500; font-size: 13.5px; text-align: center; margin-top: 10px; }
.sticky-actions {
  position: sticky; bottom: 14px; z-index: 20; margin-top: 20px;
  display: flex; gap: 10px; align-items: center; justify-content: flex-end;
  background: rgba(255, 255, 255, 0.88); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow);
}
.sticky-actions .sa-info { margin-right: auto; font-size: 13px; color: var(--muted); padding-left: 6px; }
.sticky-actions .sa-info b { color: var(--ink); font-size: 16px; font-variant-numeric: tabular-nums; }

/* combobox */
.combo { position: relative; }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); max-height: 300px; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 90; padding: 5px; min-width: 280px; animation: pop 0.1s ease-out; }
.combo-list button { display: block; width: 100%; text-align: left; background: none; border: 0; font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.combo-list button.hl { background: var(--primary-soft); }
.combo-list .sub { font-size: 12px; color: var(--muted); }
.combo-list .add { color: var(--primary); font-weight: 500; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 4px; }

/* ================= document view ================= */
.view-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 1150px) { .view-layout { grid-template-columns: 1fr; } }
.view-side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 20px; }
.view-side .card + .card { margin-top: 0; }
.preview {
  border-radius: var(--radius); padding: 28px; overflow: hidden; border: 1px solid var(--line);
  background: #e8eaf2 radial-gradient(rgba(21, 26, 45, 0.09) 1px, transparent 1px) 0 0 / 18px 18px;
}
.preview .paper { box-shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 20px 40px -20px rgba(16, 24, 40, 0.35); margin: 0 auto; border-radius: 2px; }
@media (max-width: 640px) { .preview { padding: 12px; } }
.side-list { display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; }
.side-list .kv { display: flex; justify-content: space-between; gap: 12px; }
.side-list .kv > span:first-child { color: var(--muted); }
.big-amount { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.big-amount small { font-size: 14px; color: var(--muted); font-weight: 500; }
.flow { display: flex; gap: 8px; flex-wrap: wrap; }
.flow .btn { flex: 1; }
.rel-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); color: var(--ink); background: var(--surface-2); }
.rel-link:hover { border-color: var(--tc); text-decoration: none; }
.rel-link .rl-label { font-size: 12px; color: var(--muted); }
.rel-link .doc-no { font-size: 13.5px; }
.rel-link > .ic:last-child { margin-left: auto; color: var(--faint); }

.stepper { display: flex; margin: 4px 0 18px; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; font-size: 12px; color: var(--muted); text-align: center; }
.step .dot { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line-strong); background: #fff; display: grid; place-items: center; z-index: 1; font-weight: 600; font-size: 12px; }
.step .dot .ic svg { width: 14px; height: 14px; }
.step::before { content: ''; position: absolute; top: 13px; left: -50%; right: 50%; height: 2px; background: var(--line-strong); }
.step:first-child::before { display: none; }
.step.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done::before, .step.current::before { background: var(--ok); }
.step.current { color: var(--ink); font-weight: 600; }
.step.current .dot { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.step.bad .dot { border-color: var(--danger); background: var(--danger); color: #fff; box-shadow: 0 0 0 4px var(--danger-soft); }
.step.bad { color: var(--danger); }

/* ================= modal & toast ================= */
.modal-back { position: fixed; inset: 0; background: rgba(15, 17, 35, 0.48); backdrop-filter: blur(2px); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 7vh 16px; overflow: auto; animation: fade 0.15s; }
.modal { background: #fff; border-radius: 18px; width: 100%; max-width: 680px; box-shadow: var(--shadow-lg); animation: rise 0.18s ease-out; }
.modal.wide { max-width: 920px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 14px; }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 6px 22px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 18px 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.99); } }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { display: flex; align-items: center; gap: 10px; background: #171b33; color: #fff; padding: 11px 16px 11px 12px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 14px; max-width: 380px; animation: rise 0.2s ease-out; }
.toast .t-ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--ok); flex: none; }
.toast .t-ic .ic svg { width: 13px; height: 13px; }
.toast.error .t-ic { background: var(--danger); }

.img-drop { display: flex; align-items: center; gap: 14px; padding: 14px; border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--surface-2); }
.img-drop .thumb { width: 76px; height: 76px; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; overflow: hidden; background: #fff; color: var(--faint); font-size: 12px; text-align: center; flex: none; }
.img-drop .thumb img { width: 100%; height: 100%; object-fit: contain; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: 13px; }

@media (max-width: 640px) {
  .page-head h1 { font-size: 20px; }
  .page-icon { width: 40px; height: 40px; }
  .card { padding: 16px; }
  .table-card { padding: 0; }
  .sticky-actions { bottom: 8px; flex-wrap: wrap; }
  .sticky-actions .sa-info { width: 100%; }
}
