@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=Inter:wght@500;600;700;800&display=swap");

:root {
  --brand: #ff7a1a;
  --brand-hover: #e56a0e;
  --brand-soft: #fff4ec;
  --brand-ring: rgba(255, 122, 26, 0.22);

  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-muted: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --ink: #111827;
  --ink-soft: #4b5563;
  --ink-muted: #9ca3af;

  --success: #059669;
  --success-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;

  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow: 0 1px 3px rgba(17, 24, 39, 0.06), 0 4px 12px rgba(17, 24, 39, 0.04);
  --shadow-lg: 0 12px 32px rgba(17, 24, 39, 0.08);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

[data-theme="dark"] {
  --brand-soft: #2a1c0e;
  --brand-ring: rgba(255, 138, 56, 0.28);

  --bg: #0e1116;
  --surface: #161a21;
  --surface-muted: #1e242d;
  --border: #2a313c;
  --border-strong: #3a424f;

  --ink: #e8eaed;
  --ink-soft: #aab2bf;
  --ink-muted: #6e7787;

  --success: #34d399;
  --success-soft: #0f2a20;
  --warn: #fbbf24;
  --warn-soft: #2a2310;
  --danger: #f87171;
  --danger-soft: #2a1414;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

html { transition: background-color 0.2s ease; }
body { transition: background-color 0.2s ease, color 0.2s ease; }

body {
  font-family: "IBM Plex Sans Thai", "Inter", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* ============ Typography ============ */

h1, h2, h3 {
  font-family: "Inter", "IBM Plex Sans Thai", sans-serif;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--ink);
}

.section-kicker {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-head.stack { flex-direction: column; }

.section-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.page-subtitle,
.list-card span,
.stat-card small,
.stat-card span,
.table-stack span {
  color: var(--ink-soft);
}

/* ============ Buttons ============ */

.primary, .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.06s ease;
  white-space: nowrap;
}

.primary:hover, .secondary:hover { }
.primary:active, .secondary:active { transform: translateY(1px); }

.primary {
  color: white;
  background: var(--brand);
  box-shadow: var(--shadow-sm);
}
.primary:hover { background: var(--brand-hover); }
.primary:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--brand-ring); }

.secondary {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--border);
}
.secondary:hover { background: var(--surface-muted); border-color: var(--border-strong); }
.secondary:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(17, 24, 39, 0.08); }

.primary[disabled], .secondary[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}
.primary[aria-busy="true"], .secondary[aria-busy="true"] {
  position: relative;
  color: transparent;
}
.primary[aria-busy="true"]::after,
.secondary[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: white;
  animation: spin 0.7s linear infinite;
}
.secondary[aria-busy="true"]::after { color: var(--ink); }

@keyframes spin { to { transform: rotate(360deg); } }

.full { width: 100%; }

/* ============ Pills / Badges ============ */

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.4;
  border: 1px solid transparent;
}

.pill-good {
  background: var(--success-soft);
  color: var(--success);
  border-color: rgba(5, 150, 105, 0.18);
}

.pill-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: rgba(180, 83, 9, 0.18);
}

.pill-dark {
  background: var(--surface-muted);
  color: var(--ink-soft);
  border-color: var(--border);
}

/* ============ Form fields ============ */

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field-full { grid-column: 1 / -1; }

input, select, textarea, .search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder, textarea::placeholder { color: var(--ink-muted); }

input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }

input:focus, select:focus, textarea:focus, .search:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-ring);
}

textarea { resize: vertical; min-height: 90px; }

select {
  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' stroke='%236b7280' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.input-with-btn {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-with-btn input { flex: 1; min-width: 0; }
.input-with-btn .secondary { flex: 0 0 auto; white-space: nowrap; }

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  flex: 1;
  min-width: 0;
  padding-right: 72px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft, #f4f5f7);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.password-toggle:hover { border-color: var(--brand); color: var(--brand); }

.remember-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.remember-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  accent-color: var(--brand);
  cursor: pointer;
}

.form-grid { display: grid; gap: 14px; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ============ Login ============ */

.login-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  gap: 40px;
  min-height: 100vh;
  padding: 40px clamp(20px, 5vw, 64px);
  align-items: center;
  background:
    radial-gradient(circle at 0% 0%, rgba(255, 122, 26, 0.08), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(255, 122, 26, 0.05), transparent 45%),
    var(--bg);
}

.login-stage { display: grid; gap: 24px; }

.login-brand { padding: 4px; max-width: 560px; }

.login-logo {
  display: block;
  width: min(180px, 36vw);
  height: auto;
  margin-bottom: 24px;
  border-radius: 18px;
}

.brand-chip {
  display: inline-flex;
  align-items: center;
  margin-bottom: 16px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-hover);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.login-brand h1 {
  margin: 0 0 16px;
  font-size: clamp(2rem, 3.8vw, 3.4rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.login-brand p {
  color: var(--ink-soft);
  font-size: 1rem;
  max-width: 52ch;
}

.login-card {
  padding: 32px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 18px;
}

/* ============ App shell ============ */

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 8px 20px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 10px;
  background:
    url("/assets/rst-logo.png?v=20260429") center / cover no-repeat,
    var(--brand);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  text-indent: -999px;
}

.sidebar-brand .section-kicker { font-size: 0.65rem; margin-bottom: 2px; }
.sidebar-brand h2 { font-size: 1rem; }

.sidebar-nav {
  display: grid;
  gap: 2px;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.sidebar-nav a:hover { background: var(--surface-muted); color: var(--ink); }

.sidebar-nav a.active {
  background: var(--brand-soft);
  color: var(--brand-hover);
  font-weight: 600;
}

.sidebar-user {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

.sidebar-user strong { font-size: 0.92rem; font-weight: 600; }
.sidebar-user span { color: var(--ink-muted); font-size: 0.8rem; }

/* ============ Topbar (mobile) ============ */

.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 12px calc(16px + env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.topbar-brand .brand-mark { width: 32px; height: 32px; border-radius: 8px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  color: var(--ink);
}

.icon-btn:hover { background: var(--surface-muted); }

.icon-btn svg { width: 20px; height: 20px; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(17, 24, 39, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.scrim.open { opacity: 1; pointer-events: auto; }

/* ============ Main ============ */

.main-shell {
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 20px clamp(16px, 3vw, 32px);
  max-width: 1400px;
  width: 100%;
}

.page-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 4px 0 8px;
}

.page-top h1 {
  margin: 0 0 4px;
  font-size: clamp(1.4rem, 2.4vw, 1.8rem);
}

.page-top .page-subtitle { margin: 0; font-size: 0.92rem; }

/* ============ Grids ============ */

.dashboard-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
}

.overview-grid,
.history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.masters-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dispatch-grid { align-items: start; }

.span-2 { grid-column: 1 / -1; }

/* ============ Panels / Cards ============ */

.panel {
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.ghost-link:hover { background: var(--brand-soft); color: var(--brand-hover); }

.workflow-banner {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 122, 26, 0.18);
  border-radius: var(--radius);
  background: var(--brand-soft);
}

.workflow-banner strong { color: var(--ink); font-size: 0.95rem; }
.workflow-banner span { color: var(--ink-soft); font-size: 0.85rem; }

/* ============ LINE preview panel ============ */

.preview-panel {
  background: var(--surface-muted);
}

.preview-panel .section-kicker { color: var(--brand); }
.preview-panel h2 { color: var(--ink); }
.preview-panel .preview-caption { color: var(--ink-soft); font-size: 0.82rem; }

.hint-card {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.88rem;
}

.hint-card strong { color: var(--ink); margin-right: 6px; }
.hint-card span { color: var(--ink-soft); }

.preview-shell { display: grid; gap: 12px; }

.line-preview-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}

.line-preview-head { display: grid; gap: 4px; }
.line-preview-head strong { font-size: 1rem; font-weight: 700; }
.line-preview-head small { color: var(--ink-soft); font-size: 0.82rem; }

.line-preview-chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-hover);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.line-preview-group {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.line-preview-group p {
  margin: 0 0 2px;
  color: var(--ink-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.line-preview-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  font-size: 0.9rem;
}

.line-preview-row span { color: var(--ink-soft); }
.line-preview-row strong { max-width: 65%; text-align: right; font-weight: 600; }

.line-preview-note { line-height: 1.6; font-size: 0.9rem; }
.preview-caption { margin: 0; }

/* ============ Stat grid ============ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.stat-card:hover { border-color: var(--border-strong); }

.stat-card span {
  display: block;
  font-size: 0.76rem;
  color: var(--ink-soft);
  font-weight: 500;
}

.stat-card strong {
  display: block;
  margin: 4px 0 2px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.stat-card small {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

/* ============ Activity / Route / Tip cards ============ */

.activity-grid,
.route-watch-grid,
.tips-grid {
  display: grid;
  gap: 10px;
}

.route-watch-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tips-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.activity-card,
.route-card,
.snapshot-card,
.tip-card {
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.activity-card { display: grid; gap: 8px; }
.activity-card-head,
.activity-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.activity-card-head > div { display: grid; gap: 2px; }
.activity-card-head strong { font-weight: 600; }
.activity-card-head > div span,
.activity-meta span,
.route-card span,
.snapshot-card span,
.snapshot-card small,
.tip-card span {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.route-card {
  display: grid;
  gap: 4px;
}
.route-card strong { font-weight: 600; }

.history-snapshot {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.snapshot-card strong,
.tip-card strong {
  display: block;
  margin: 4px 0 2px;
  font-weight: 600;
}

.snapshot-card strong { font-size: 1.25rem; }

.tip-card { display: grid; gap: 4px; }

/* ============ Tables ============ */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th, td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--surface-muted);
  position: sticky;
  top: 0;
}

tbody tr:hover { background: var(--brand-soft); }
tbody tr:last-child td { border-bottom: 0; }

.table-stack { display: grid; gap: 2px; }
.status-select { min-width: 130px; padding: 6px 10px; font-size: 0.85rem; }

.ta-right { text-align: right; }
.nowrap { white-space: nowrap; }
td.muted, .muted { color: var(--ink-muted); }

/* งานล่าสุด (Recent Jobs) — ตารางแบบกระชับ */
.recent-table { min-width: 720px; }
.recent-table th,
.recent-table td { padding: 9px 12px; vertical-align: middle; }
.recent-table tbody td { font-size: 0.88rem; }

/* ============ List grids ============ */

.list-grid { display: grid; gap: 10px; }

/* ============ Dispatch board (table) ============ */

.board-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.chip:hover { background: var(--surface-muted); }
.chip.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

/* ============ */

.board-row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.board-row-actions .icon-edit {
  font-size: 0.78rem;
  padding: 4px 9px;
}

.board-subtime {
  font-size: 0.72rem;
  color: var(--ink-muted);
  margin-top: 3px;
}

/* ============ Compact fleet list ============ */

.list-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.list-toolbar .search { flex: 1; }

.limit-select {
  width: auto;
  flex: 0 0 auto;
  min-width: 130px;
}

.th-sort {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.th-sort:hover { color: var(--brand); }
#fleetSortArrow { color: var(--brand); font-size: 0.7rem; }

.table-footer {
  margin-top: 12px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.fleet-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
}

.fleet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.fleet-row:hover {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.fleet-row-main {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.fleet-row-main strong {
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.fleet-unit {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
}

.fleet-row-driver {
  font-size: 0.82rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-top: 3px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.link-badge-ok { background: var(--success-soft); color: var(--success); border-color: rgba(5, 150, 105, 0.2); }
.link-badge-warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(180, 83, 9, 0.2); }

.fleet-row-side {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.fleet-phone {
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.fleet-phone:hover { color: var(--brand-hover); }
.fleet-phone.muted { color: var(--ink-muted); }

.icon-edit {
  flex: 0 0 auto;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.icon-edit:hover {
  background: var(--brand-soft);
  color: var(--brand-hover);
  border-color: rgba(255, 122, 26, 0.3);
}

.icon-danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.3);
}

.icon-link {
  background: var(--brand-soft);
  color: var(--brand-hover);
  border-color: rgba(255, 122, 26, 0.3);
}
.icon-link:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.icon-link:disabled { opacity: 0.6; cursor: not-allowed; }

.list-card,
.empty-card {
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.list-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.list-card-head > div { display: grid; gap: 2px; }
.list-card-head strong { font-weight: 600; }

.list-card-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.list-card-actions .secondary { padding: 6px 10px; font-size: 0.82rem; }

.list-card-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.empty, .empty-card {
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.92rem;
  padding: 24px;
}

/* ============ Skeleton loading ============ */

.skeleton {
  background: linear-gradient(90deg, var(--surface-muted) 0%, var(--border) 50%, var(--surface-muted) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-row { height: 14px; margin: 6px 0; }
.skeleton-block { height: 88px; }

/* ============ Modal ============ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(17, 24, 39, 0.55);
  overflow-y: auto;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  display: grid;
  gap: 16px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.share-preview {
  margin: 0;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-family: "IBM Plex Sans Thai", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 40vh;
  overflow-y: auto;
}

.modal-actions { display: grid; gap: 10px; }
.modal-actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions-row .secondary { justify-content: center; }
.modal-note { margin: 0; font-size: 0.82rem; color: var(--ink-muted); text-align: center; }

/* ============ Theme toggle ============ */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.theme-toggle:hover {
  background: var(--surface-muted);
  color: var(--ink);
  border-color: var(--border-strong);
}

.theme-toggle svg { width: 16px; height: 16px; }

.theme-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ปุ่มสลับธีมบน topbar (มือถือ) */
.topbar .theme-toggle {
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============ Driver Job Page (mobile-first) ============ */

.driver-shell {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.driver-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 12px calc(16px + env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: 0.85rem; }
.avatar-empty { background: var(--surface-soft, #e6e8ec); color: var(--ink-soft); }
.driver-cell { display: flex; align-items: center; gap: 8px; min-width: 0; }

.driver-topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.driver-topbar-brand .brand-mark { width: 36px; height: 36px; border-radius: 9px; }
.driver-topbar-brand strong { display: block; font-size: 1rem; font-weight: 700; }
.driver-topbar-brand span { display: block; font-size: 0.78rem; color: var(--ink-soft); }
.driver-topbar .secondary { padding: 8px 12px; font-size: 0.85rem; }

.driver-section-title {
  margin: 4px 2px 10px;
  font-size: 1rem;
  color: var(--ink-soft);
}

/* summary cards */
.driver-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.driver-sum-card {
  padding: 12px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
}
.driver-sum-card span { display: block; font-size: 0.72rem; color: var(--ink-soft); }
.driver-sum-card strong { display: block; margin-top: 4px; font-size: 1.15rem; }
.driver-sum-money { color: var(--brand); }

/* tabs */
.driver-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
.driver-tab {
  padding: 12px 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.driver-tab.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

/* history + income cards */
.driver-day { margin-bottom: 16px; }
.driver-day-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 0 2px 8px;
  font-size: 0.95rem;
}
.driver-day-title span { font-size: 0.8rem; color: var(--ink-soft); font-weight: 500; }

.driver-hist-card,
.driver-month-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.driver-hist-card strong,
.driver-month-card strong { display: block; font-size: 1rem; }
.driver-hist-card span,
.driver-month-card span { font-size: 0.82rem; color: var(--ink-soft); }
.driver-fee { font-size: 1.05rem; font-weight: 700; color: var(--brand); white-space: nowrap; }

.report-fee { font-weight: 700; color: var(--brand); white-space: nowrap; }

/* System monitor / live log */
.log-console {
  max-height: 70vh;
  overflow-y: auto;
  background: #0e1116;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: "IBM Plex Sans Thai", ui-monospace, monospace;
  font-size: 0.82rem;
  line-height: 1.6;
}
.log-line { display: flex; gap: 10px; padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.04); white-space: nowrap; }
.log-time { color: #6b7382; flex: 0 0 auto; }
.log-body { color: #cbd2dc; overflow: hidden; text-overflow: ellipsis; }
.log-dim { color: #6b7382; }
.log-path { color: #e8eaed; }
.log-info .log-time { color: #6b7382; }
.log-warn .log-body { color: #fbbf24; }
.log-err .log-body { color: #f87171; }
.log-method { font-weight: 700; }
.log-m-get { color: #38bdf8; }
.log-m-post { color: #34d399; }
.log-m-put, .log-m-patch { color: #fbbf24; }
.log-m-delete { color: #f87171; }
.log-status { font-weight: 700; }
.log-s2 { color: #34d399; }
.log-s3 { color: #38bdf8; }
.log-s4 { color: #fbbf24; }
.log-s5 { color: #f87171; }
.log-pod { color: #34d399; font-weight: 700; }

/* Searchable combo (dispatch fleet picker) */
.combo { position: relative; }
.combo-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.combo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.combo-item:last-child { border-bottom: 0; }
.combo-item:hover { background: var(--brand-soft); }

.combo-unit {
  flex: 0 0 auto;
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
}
.combo-main { display: grid; gap: 1px; min-width: 0; }
.combo-main strong { font-size: 1rem; font-weight: 700; }
.combo-main span { font-size: 0.82rem; color: var(--ink-soft); }

.combo-item-plain { color: var(--ink-soft); font-size: 0.9rem; }

/* POD finish modal */
.pod-form { display: grid; gap: 16px; }
.pod-slot { display: grid; gap: 8px; }
.pod-label { font-weight: 600; font-size: 0.95rem; }
.pod-preview {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  overflow: hidden;
}
.pod-preview img { width: 100%; height: auto; max-height: 220px; object-fit: contain; }
.pod-empty { color: var(--ink-muted); font-size: 0.85rem; }

.driver-reject {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 600;
}

.pod-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pod-cell .icon-edit { padding: 4px 9px; font-size: 0.78rem; }

.driver-pod-link,
.pod-link {
  display: inline-block;
  margin-top: 3px;
  color: var(--brand-hover);
  font-size: 0.82rem;
  font-weight: 600;
}
.driver-pod-link:hover,
.pod-link:hover { text-decoration: underline; }

.driver-income-total {
  padding: 18px;
  margin-bottom: 14px;
  border-radius: var(--radius-lg);
  background: var(--brand-soft);
  border: 1px solid rgba(255, 122, 26, 0.2);
  text-align: center;
}
.driver-income-total span { display: block; font-size: 0.82rem; color: var(--ink-soft); }
.driver-income-total strong { display: block; margin: 4px 0 2px; font-size: 1.9rem; color: var(--brand-hover); }
.driver-income-total small { color: var(--ink-soft); }

.driver-job-list { display: grid; gap: 12px; margin-bottom: 20px; }

.driver-job-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.driver-job-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.driver-job-head strong { font-size: 1.15rem; line-height: 1.3; }

.driver-job-meta { color: var(--ink-soft); font-size: 0.92rem; }

.driver-job-actions { display: grid; gap: 8px; margin-top: 4px; }
.driver-job-actions .driver-btn { min-height: 52px; font-size: 1.1rem; }

.driver-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 18px;
  display: grid;
  gap: 16px;
}

.driver-badge {
  justify-self: start;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-hover);
  font-size: 0.82rem;
  font-weight: 700;
}

.driver-badge.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.driver-title {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.2;
}

.driver-plate {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.driver-plates { display: grid; gap: 10px; }

.driver-plate-box {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-muted);
}
.driver-plate-box span { font-size: 0.82rem; color: var(--ink-soft); }
.driver-plate-box strong { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.01em; }

.driver-route {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface-muted);
  text-align: center;
}
.driver-loc { display: grid; gap: 2px; }
.driver-loc span { font-size: 0.82rem; color: var(--ink-soft); }
.driver-loc strong { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
.driver-arrow { font-size: 1.2rem; color: var(--brand); font-weight: 700; }
.driver-muted .driver-loc strong, .driver-muted div { color: var(--ink-muted); }

.driver-meta {
  display: grid;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 600;
}

.driver-note {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 1rem;
  line-height: 1.5;
}

.driver-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 60px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.15s ease, transform 0.06s ease;
}
.driver-btn:active { transform: scale(0.98); }

.driver-btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow);
}
.driver-btn-primary:hover { background: var(--brand-hover); }
.driver-btn-primary:disabled { opacity: 0.6; }

.driver-btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
  min-height: 54px;
  font-size: 1.05rem;
}
.driver-btn-ghost:hover { background: var(--surface-muted); }

.driver-actions { display: grid; gap: 10px; }

.driver-acked {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--success-soft);
  color: var(--success);
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
}

.driver-cancel-warn {
  margin: 0;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
}

.driver-jobid { margin: 0; text-align: center; color: var(--ink-muted); font-size: 0.82rem; }
.driver-loading { padding: 20px; }
.driver-error { text-align: center; }

/* ============ Toast ============ */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 28px));
  padding: 12px 16px;
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 0.92rem;
  font-weight: 500;
  transform: translateY(0);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.hidden {
  display: block !important;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

.toast[data-tone="good"] {
  border-color: rgba(5, 150, 105, 0.3);
  background: var(--success-soft);
  color: var(--success);
}

.toast[data-tone="error"] {
  border-color: rgba(185, 28, 28, 0.3);
  background: var(--danger-soft);
  color: var(--danger);
}

/* ============ Responsive ============ */

@media (max-width: 1200px) {
  .dashboard-grid,
  .masters-grid,
  .login-shell { grid-template-columns: 1fr; }

  .stat-grid,
  .history-snapshot,
  .route-watch-grid,
  .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .tips-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }

  .topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .main-shell { padding: 16px; }

  .page-top { flex-direction: column; gap: 12px; }

  .form-grid-2,
  .form-grid-4,
  .stat-grid,
  .history-snapshot,
  .route-watch-grid { grid-template-columns: 1fr; }

  .field-full { grid-column: auto; }

  .line-preview-row,
  .activity-card-head,
  .activity-meta { flex-direction: column; gap: 4px; }

  .line-preview-row strong { max-width: 100%; text-align: left; }

  .login-shell {
    grid-template-columns: 1fr;
    padding: 32px 20px;
    gap: 24px;
    align-items: start;
  }

  .login-card { padding: 24px; }
}

@media (min-width: 901px) {
  .topbar { display: none; }
}
