/* ============================================================
   CCN Transport — ระบบใหม่ (standalone)
   ออกแบบใหม่ทั้งหมด ไม่เกี่ยวกับระบบเดิม
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;600&display=swap');

:root {
  /* Brand */
  --brand:        #b91c1c;   /* red-700 — สีประจำบริษัท */
  --brand-dark:   #991b1b;
  --brand-soft:   #fef2f2;
  --brand-ring:   rgba(185, 28, 28, 0.15);

  /* Semantic */
  --income:       #16a34a;
  --income-soft:  #f0fdf4;
  --expense:      #dc2626;
  --expense-soft: #fef2f2;
  --fuel:         #d97706;
  --fuel-soft:    #fffbeb;
  --net:          #2563eb;
  --net-soft:     #eff6ff;

  /* Neutral */
  --bg:        #f8fafc;
  --surface:   #ffffff;
  --surface-2: #f1f5f9;
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #94a3b8;
  --border:    #e2e8f0;
  --border-2:  #cbd5e1;

  /* Shape */
  --radius:    14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --pill:      999px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow:    0 1px 3px rgba(15,23,42,.08), 0 4px 16px rgba(15,23,42,.05);
  --shadow-lg: 0 12px 40px rgba(15,23,42,.14);

  --font: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;

  color-scheme: light;
}

/* ─────────────── Dark theme ─────────────── */
:root[data-theme="dark"] {
  color-scheme: dark;

  --brand:        #ef4444;
  --brand-dark:   #dc2626;
  --brand-soft:   rgba(239, 68, 68, 0.16);
  --brand-ring:   rgba(239, 68, 68, 0.32);

  --income:       #34d399;
  --income-soft:  rgba(52, 211, 153, 0.14);
  --expense:      #f87171;
  --expense-soft: rgba(248, 113, 113, 0.14);
  --fuel:         #fbbf24;
  --fuel-soft:    rgba(251, 191, 36, 0.14);
  --net:          #60a5fa;
  --net-soft:     rgba(96, 165, 250, 0.14);

  --bg:        #0e1217;
  --surface:   #161c24;
  --surface-2: #1f2730;
  --text:      #e6eaf0;
  --text-2:    #9aa6b4;
  --text-3:    #6b7785;
  --border:    #283039;
  --border-2:  #3a4654;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow:    0 1px 3px rgba(0, 0, 0, 0.40), 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
}
/* dark-specific component fixes (override hardcoded light colors) */
:root[data-theme="dark"] tr.row-truck:hover { background: rgba(251, 191, 36, 0.18); }
:root[data-theme="dark"] .alert.info { color: #93c5fd; }
:root[data-theme="dark"] .alert.warn { color: #fcd34d; }
:root[data-theme="dark"] .backdrop { background: rgba(0, 0, 0, 0.62); }

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─────────────── Top bar ─────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-mark {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow-sm);
}
.logo-text { display: flex; flex-direction: column; }
.logo-title { font-weight: 700; font-size: 16px; line-height: 1.2; }
.logo-sub { font-size: 12px; color: var(--text-3); }

.nav {
  display: flex;
  gap: 4px;
  margin-left: 24px;
}
.nav a {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  transition: all .12s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }

.theme-btn {
  margin-left: auto;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text-2);
  font-size: 18px;
  line-height: 1;
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .12s;
}
.theme-btn:hover { background: var(--surface-2); border-color: var(--brand); }

/* ─────────────── Layout ─────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.page-sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }

/* ─────────────── Date filter ─────────────── */
.filterbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 28px;
}
.filterbar-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--pill);
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  padding: 6px 14px;
  border-radius: var(--pill);
  cursor: pointer;
  transition: all .15s;
}
.seg button:hover { color: var(--text); }
.seg button.active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}
.divider-v { width: 1px; height: 26px; background: var(--border); }
.daterange { display: flex; align-items: center; gap: 8px; }
.daterange .lbl { font-size: 12px; color: var(--text-3); }
input[type="date"] {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  padding: 7px 11px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
input[type="date"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

/* ─────────────── Section ─────────────── */
.section { margin-bottom: 40px; }
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.section-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
}
.section-title { font-size: 18px; font-weight: 700; }
.section-note {
  font-size: 12.5px;
  color: var(--text-3);
  font-weight: 500;
}
.range-chip {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  border: 1px solid var(--brand-ring);
  border-radius: var(--pill);
  padding: 4px 14px;
}

/* ─────────────── KPI cards ─────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  cursor: pointer;
  transition: transform .14s, box-shadow .14s, border-color .14s;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
}
.kpi.k-income::before  { background: var(--income); }
.kpi.k-expense::before { background: var(--expense); }
.kpi.k-net::before     { background: var(--net); }
.kpi:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-2);
}
.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.kpi-label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.kpi-badge {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
}
.k-income  .kpi-badge { background: var(--income-soft); }
.k-expense .kpi-badge { background: var(--expense-soft); }
.k-net     .kpi-badge { background: var(--net-soft); }
.kpi-value {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.kpi-value.pos { color: var(--income); }
.kpi-value.neg { color: var(--expense); }
.kpi-value.net { color: var(--net); }
.kpi-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 8px;
}
.kpi-cta {
  position: absolute;
  right: 18px; bottom: 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  opacity: 0;
  transition: opacity .15s, transform .15s;
  transform: translateX(-4px);
}
.kpi:hover .kpi-cta { opacity: 1; transform: translateX(0); }

@media (max-width: 760px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ─────────────── Table ─────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data thead th.th-sort {
  cursor: pointer;
  user-select: none;
}
table.data thead th.th-sort:hover {
  color: var(--accent);
}
table.data tfoot tr.tfoot-total td {
  padding: 12px 18px;
  border-top: 2px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
}
table.data thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
table.data tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
.t-right { text-align: right; }
.t-center { text-align: center; }
.num { font-family: var(--mono); font-weight: 600; white-space: nowrap; }

tr.row-click { cursor: pointer; transition: background .12s; }
tr.row-click:hover { background: var(--brand-soft); }
tr.row-truck { background: var(--fuel-soft); }
tr.row-truck:hover { background: #fef3c7; }
tr.row-total {
  font-weight: 700;
  background: var(--surface-2);
  border-top: 2px solid var(--border-2);
}
tr.row-total td { border-bottom: none; }

/* center identity */
.center-cell { display: flex; align-items: center; gap: 12px; }
.center-tag {
  flex-shrink: 0;
  width: 44px; height: 30px;
  border-radius: 8px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex; align-items: center; justify-content: center;
}
.center-name { font-weight: 600; }
.center-bar-wrap { margin-top: 5px; height: 4px; width: 130px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.center-bar { height: 100%; border-radius: 2px; transition: width .5s ease; }

.pos { color: var(--income); }
.neg { color: var(--expense); }
.muted { color: var(--text-3); }

/* ─────────────── Modal ─────────────── */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  animation: fade .15s ease;
  overflow-y: auto;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 940px;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.97) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.modal-title .amt { font-family: var(--mono); }
.modal-body { padding: 24px 26px; }
.btn-close {
  border: 1px solid var(--border-2);
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
}
.btn-close:hover { background: var(--surface-2); color: var(--text); }

/* mini stat cards in modal */
.mini-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 22px;
}
.mini-grid.c3 { grid-template-columns: repeat(3, 1fr); }
.mini-grid.c4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 640px) {
  .mini-grid.c3, .mini-grid.c4 { grid-template-columns: repeat(2, 1fr); }
}
.mini {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  border-left-width: 4px;
}
.mini.m-income  { border-left-color: var(--income); }
.mini.m-expense { border-left-color: var(--expense); }
.mini.m-fuel    { border-left-color: var(--fuel); }
.mini.m-net     { border-left-color: var(--net); }
.mini-label { font-size: 12px; color: var(--text-2); font-weight: 600; margin-bottom: 5px; }
.mini-value { font-family: var(--mono); font-size: 20px; font-weight: 700; }
.mini-sub { font-size: 12px; color: var(--text-3); margin-top: 3px; }

.sub-head {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.sub-head::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.sub-head:first-child { margin-top: 0; }

.scroll-box { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.scroll-box table.data thead th { position: sticky; top: 0; }

/* formula display */
.formula {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 13.5px;
  color: var(--text-2);
  margin-bottom: 20px;
  line-height: 1.9;
}
.formula strong { color: var(--text); }

table.calc { width: 100%; border-collapse: collapse; font-size: 15px; }
table.calc td { padding: 14px 16px; border-bottom: 1px solid var(--border); }
table.calc tr.result {
  background: var(--net-soft);
  font-weight: 700;
  font-size: 19px;
  border-top: 2px solid var(--border-2);
}
table.calc tr.result td { border-bottom: none; }

/* badges */
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--pill);
}
.badge.paid    { background: var(--income-soft); color: var(--income); }
.badge.pending { background: var(--fuel-soft); color: var(--fuel); }
.badge.overdue { background: var(--expense-soft); color: var(--expense); }

.empty {
  text-align: center;
  color: var(--text-3);
  padding: 28px;
  font-size: 14px;
}

/* ─────────────── Tabs ─────────────── */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}
.tab {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .12s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .2s ease; }

/* ─────────────── Wizard steps ─────────────── */
.wiz-steps {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.wiz-step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-3);
  min-width: 0;
}
.wiz-step::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  margin-left: 6px;
}
.wiz-step:last-child {
  flex: 0 0 auto;
}
.wiz-step:last-child::after { display: none; }
.wiz-step .t { white-space: nowrap; }
.wiz-step .n {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  z-index: 1;
}
.wiz-step .t { font-size: 14px; font-weight: 600; }
.wiz-step.active { color: var(--brand); }
.wiz-step.active .n { background: var(--brand); color: #fff; }
.wiz-step.done { color: var(--income); }
.wiz-step.done .n { background: var(--income); color: #fff; }

.wiz-panel { display: none; }
.wiz-panel.active { display: block; }
.wiz-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ─────────────── Upload zone ─────────────── */
.dropzone {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
  transition: all .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone .ic { font-size: 44px; margin-bottom: 12px; }
.dropzone .big { font-size: 16px; font-weight: 600; }
.dropzone .small { font-size: 13px; color: var(--text-3); margin-top: 6px; }

/* ─────────────── Form ─────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid.wide { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .form-grid.wide { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .form-grid.wide { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); font-weight: 400; }
.input, .select {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  padding: 9px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
}
.input:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }

/* permission grid (หน้าผู้ใช้งาน) */
.perm-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 20px; }
@media (max-width: 640px) { .perm-grid { grid-template-columns: 1fr; } }
.perm-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.perm-row .perm-name { font-size: 14px; font-weight: 600; color: var(--text); }
.perm-row .select { max-width: 150px; }

/* photo thumbnails (งานซ่อม/เอกสารรถ) */
.photo-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.photo-thumb { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border-2); cursor: pointer; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .rm { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 12px; line-height: 1; }
.photo-add { width: 72px; height: 72px; border-radius: 8px; border: 1.5px dashed var(--border-2); display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 2px; cursor: pointer; color: var(--text-3); font-size: 11px; background: var(--surface); }
.photo-add:hover { border-color: var(--brand); color: var(--brand); }
.photo-big { max-width: 100%; max-height: 70vh; border-radius: 8px; display: block; margin: 0 auto; }

/* column checkbox chips */
.col-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.col-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  padding: 7px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--pill);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  transition: all .12s;
}
.col-chip:hover { border-color: var(--brand); }
.col-chip input { accent-color: var(--brand); cursor: pointer; }
.col-chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

/* buttons */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .12s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-ghost { background: var(--surface); color: var(--text-2); border-color: var(--border-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-success { background: var(--income); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(.95); }

/* toggle */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: var(--border-2);
  border-radius: var(--pill);
  transition: .2s;
}
.switch .slider::before {
  content: ''; position: absolute;
  height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--fuel); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* derived-center pill */
.derived {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.derived.ok { background: var(--income-soft); color: var(--income); }
.derived.warn { background: var(--fuel-soft); color: var(--fuel); }

/* alert */
.alert {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.alert.info { background: var(--net-soft); color: #1e40af; }
.alert.warn { background: var(--fuel-soft); color: #92400e; }

/* ══════════════════════════════════════════
   MOBILE / RESPONSIVE
══════════════════════════════════════════ */

/* — Topbar: logo + theme-btn ชั้นบน · nav เลื่อนได้ชั้นล่าง — */
@media (max-width: 640px) {
  .topbar-inner {
    flex-wrap: wrap;
    padding: 10px 14px;
    row-gap: 0;
    column-gap: 8px;
  }
  .logo-sub { display: none; }
  .theme-btn { margin-left: auto; }
  .nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 6px;
    gap: 2px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    font-size: 13px;
    padding: 7px 12px;
    white-space: nowrap;
  }
}

/* — Container & page head — */
@media (max-width: 640px) {
  .container { padding: 16px 14px 48px; }
  .page-title { font-size: 20px; }
  .page-sub   { font-size: 12px; }
}

/* — Filterbar: stack แนวตั้งบนมือถือ — */
@media (max-width: 640px) {
  .filterbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .filterbar .divider-v { display: none; }
  .seg button { padding: 5px 10px; font-size: 12px; }
  .daterange  { flex-wrap: wrap; gap: 6px; }
  input[type="date"] { font-size: 12px; padding: 6px 8px; }
}

/* — KPI: font เล็กลง — */
@media (max-width: 480px) {
  .kpi-value { font-size: 20px; }
  .kpi       { padding: 14px 16px; }
}

/* — Tabs: scroll แนวนอน — */
@media (max-width: 640px) {
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    font-size: 13px;
    padding: 10px 14px;
    white-space: nowrap;
  }
}

/* — Wizard steps: shrink / ซ่อน label บนมือถือเล็ก — */
@media (max-width: 640px) {
  .wiz-steps { padding: 12px 14px; }
  .wiz-step  { gap: 6px; }
  .wiz-step .n { width: 26px; height: 26px; font-size: 12px; }
  .wiz-step .t { font-size: 12px; }
}
@media (max-width: 440px) {
  .wiz-step .t { display: none; }
}

/* — Section head: wrap ได้ — */
@media (max-width: 640px) {
  .section-head { flex-wrap: wrap; row-gap: 8px; }
}

/* — Wiz actions: stack แนวตั้งบนหน้าจอแคบมาก — */
@media (max-width: 420px) {
  .wiz-actions { flex-direction: column-reverse; }
  .wiz-actions .btn { width: 100%; text-align: center; justify-content: center; }
}

/* — Modal: bottom-sheet บนมือถือ — */
@media (max-width: 640px) {
  .backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 90dvh;
    overflow-y: auto;
    width: 100%;
  }
  .modal-head { padding: 16px 18px; }
  .modal-body { padding: 16px 18px; }
}

/* — Mini-grid: 1 col บนมือถือเล็กมาก — */
@media (max-width: 420px) {
  .mini-grid.c3,
  .mini-grid.c4 { grid-template-columns: 1fr; }
}

/* — Big-truck 2-col upload area — */
.upload-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 16px;
}
@media (max-width: 640px) {
  .upload-2col { grid-template-columns: 1fr; }
}

/* — Table: smooth scroll hint — */
@media (max-width: 640px) {
  .table-scroll { -webkit-overflow-scrolling: touch; }
}

/* — Card padding: เล็กลงบนมือถือ — */
@media (max-width: 480px) {
  .card[style*="padding:24px"] { padding: 16px !important; }
  .modal-head, .modal-body { padding: 14px 16px; }
}

