/* Tokens pulled straight from the app's own AppColors/AppTheme/AppRadius/
   StatusBadge: black-white-grey with the deep green accent reserved for
   accents, amber for warning, no red anywhere in the real app — "danger"
   states (ban, reject, past due) read as a solid ink-filled pill/button
   instead, the same monochrome-plus-weight trick the brand already leans
   on. Layout: fixed left rail of nav sections + a scrolling content
   column; stat tiles open each panel, dense tables drive every queue. */
:root {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F4F4F6;
  --border: #E4E4E8;
  --border-strong: #D6D6DC;
  --ink: #131316;
  --ink-2: #6C6C72;
  --ink-3: #A3A3A9;
  --accent: #0D362B;
  --accent-soft: #E7EBEA;
  --warn: #9A6B12;
  --warn-soft: #FCEFD8;
  --danger: #131316;
  --danger-soft: #E3E3E8;
  --on-danger: #FFFFFF;
  --on-accent: #FFFFFF;
  --shadow: 0 1px 2px rgba(19,19,22,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214;
    --surface: #1A1B1E;
    --surface-2: #212226;
    --border: #2C2D32;
    --border-strong: #3A3B41;
    --ink: #F2F2F3;
    --ink-2: #A7A8AE;
    --ink-3: #74757C;
    --accent: #5BB596;
    --accent-soft: #17302A;
    --warn: #E3B567;
    --warn-soft: #362C16;
    --danger: #F2F2F3;
    --danger-soft: #2A2B30;
    --on-danger: #131316;
    --on-accent: #0B1F1B;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121214;
  --surface: #1A1B1E;
  --surface-2: #212226;
  --border: #2C2D32;
  --border-strong: #3A3B41;
  --ink: #F2F2F3;
  --ink-2: #A7A8AE;
  --ink-3: #74757C;
  --accent: #5BB596;
  --accent-soft: #17302A;
  --warn: #E3B567;
  --warn-soft: #362C16;
  --danger: #F2F2F3;
  --danger-soft: #2A2B30;
  --on-danger: #131316;
  --on-accent: #0B1F1B;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Plus Jakarta Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.mono { font-variant-numeric: tabular-nums; letter-spacing: .1px; }
button { font: inherit; }
table { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 26px; display: flex; flex-direction: column; gap: 14px;
}
.login-card .brand-mark { width: 30px; height: 30px; color: var(--accent); }
.login-title { font-size: 17px; font-weight: 800; margin-top: 4px; }
.login-sub { font-size: 12.5px; color: var(--ink-2); margin-top: -8px; margin-bottom: 4px; }
.login-btn { width: 100%; justify-content: center; padding: 10px 13px; margin-top: 4px; }

.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.form-field input {
  border: 1.5px solid var(--border); border-radius: 12px; background: var(--surface-2);
  color: var(--ink); padding: 10px 12px; font: inherit; font-size: 13.5px;
}
.form-field input:focus { outline: none; border-color: var(--accent); }
.form-error { font-size: 12.5px; font-weight: 600; color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 8px 10px; }

.shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.rail {
  width: 232px; flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  gap: 2px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px 18px;
  margin-bottom: 4px;
}
.brand svg { width: 20px; height: 20px; color: var(--accent); flex: none; }
.brand-name { font-weight: 700; font-size: 14.5px; letter-spacing: .1px; }
.brand-sub { font-size: 10.5px; color: var(--ink-3); font-weight: 600; letter-spacing: .4px; text-transform: uppercase; }

.nav-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--ink-3); padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 12px;
  color: var(--ink-2); font-weight: 500; font-size: 13.5px;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.nav-item svg { width: 16px; height: 16px; flex: none; color: var(--ink-3); }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.active svg { color: var(--accent); }
.nav-item .count {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--danger-soft); color: var(--danger);
  border-radius: 999px; padding: 1px 6px;
}
.nav-item.disabled { opacity: .45; cursor: default; }
.nav-item.disabled:hover { background: none; color: var(--ink-2); }

.rail-footer {
  margin-top: auto; padding: 10px; display: flex; align-items: center; gap: 9px;
  border-top: 1px solid var(--border);
}
.avatar {
  width: 26px; height: 26px; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 700; flex: none;
  text-transform: uppercase;
}
.rail-footer-text { min-width: 0; }
.rail-footer-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-footer-signout {
  border: none; background: none; padding: 0; margin-top: 1px;
  font-size: 11px; font-weight: 700; color: var(--ink-3); cursor: pointer;
}
.rail-footer-signout:hover { color: var(--ink); text-decoration: underline; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 22px; height: 56px; flex: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.menu-btn { display: none; border: none; background: none; color: var(--ink-2); padding: 6px; margin: -6px; border-radius: 999px; }
.menu-btn svg { width: 19px; height: 19px; }
.crumb { font-weight: 600; font-size: 14px; }
.env-pill {
  font-size: 10.5px; font-weight: 700; letter-spacing: .3px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 2px 8px;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.theme-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-2);
  width: 30px; height: 30px; border-radius: 999px; display: flex; align-items: center; justify-content: center;
}
.theme-btn svg { width: 15px; height: 15px; }

.content { padding: 18px 22px 60px; flex: 1; }
.panel { display: flex; flex-direction: column; gap: 22px; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 19px; font-weight: 700; }
.page-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat-label { font-size: 11.5px; color: var(--ink-2); font-weight: 600; }
.stat-value { font-size: 25px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }

/* ---------- Cards / tables ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font-size: 13.5px; font-weight: 700; }
.card-head .hint { font-size: 11.5px; color: var(--ink-3); }
.search {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 6px 12px; font-size: 12.5px; color: var(--ink-3); max-width: 240px; width: 100%;
}
.search svg { width: 13px; height: 13px; flex: none; }
.search input { border: none; background: none; outline: none; color: var(--ink); width: 100%; font-size: 12.5px; }

.select {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 6px 10px;
  cursor: pointer;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
thead th {
  text-align: left; font-size: 10.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  color: var(--ink-3); padding: 9px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-exit { opacity: 0; transform: translateX(6px); transition: opacity .22s ease, transform .22s ease; }

.who { display: flex; align-items: center; gap: 9px; }
.who-avatar {
  width: 28px; height: 28px; border-radius: 999px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
  color: var(--ink-2); flex: none; border: 1px solid var(--border); text-transform: uppercase;
}
.who-name { font-weight: 600; font-size: 13px; }
.who-sub { font-size: 11.5px; color: var(--ink-3); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; border-radius: 999px; padding: 3px 9px; white-space: nowrap;
}
.pill.success { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.neutral { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); }

.row-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font-size: 12px; font-weight: 600; border-radius: 999px; padding: 6px 13px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:disabled:hover { background: var(--surface); }
.btn svg { width: 13px; height: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn.danger:hover { filter: brightness(1.1); }
.btn.ghost { background: none; }
.btn.icon { padding: 6px 7px; border-radius: 999px; }

.confirm-row {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  font-size: 12px; color: var(--ink-2); white-space: nowrap;
}
.confirm-row strong { color: var(--ink); }

/* ---------- Row kebab menu ---------- */
tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover { background: var(--surface-2); }
.menu-wrap { position: relative; display: inline-block; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); min-width: 170px; padding: 5px; display: none;
}
.dropdown.open { display: block; }
.dropdown button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: none; background: none; padding: 8px 9px; border-radius: 8px; font-size: 12.5px; color: var(--ink);
  cursor: pointer;
}
.dropdown button:hover { background: var(--surface-2); }
.dropdown button svg { width: 13px; height: 13px; color: var(--ink-3); flex: none; }
.dropdown button.danger { color: var(--danger); }
.dropdown button.danger svg { color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 2px; }

.empty {
  text-align: center; padding: 34px 20px; color: var(--ink-3); font-size: 12.5px;
}
.empty svg { width: 26px; height: 26px; margin-bottom: 8px; color: var(--ink-3); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--bg); font-size: 12.5px; font-weight: 600;
  padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 14px; height: 14px; flex: none; color: var(--bg); }

/* ---------- Detail drawer ---------- */
.drawer-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 24;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.drawer-scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 25;
  width: 380px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .24s cubic-bezier(.16,1,.3,1);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 16px 14px; border-bottom: 1px solid var(--border); flex: none;
}
.drawer-body { padding: 16px; overflow-y: auto; overflow-x: hidden; flex: 1; display: flex; flex-direction: column; gap: 18px; }

.detail-section-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 8px;
}
.detail-rows { display: flex; flex-direction: column; gap: 9px; }
.detail-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13px; }
.detail-row .k { color: var(--ink-2); flex: none; }
.detail-row .v { font-weight: 600; text-align: right; }

.drawer-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.drawer-stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.drawer-stat .n { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.drawer-stat .l { font-size: 10.5px; color: var(--ink-2); margin-top: 2px; }

.child-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.child-row:last-child { border-bottom: none; }
.child-row .name { font-weight: 600; }
.child-row .sub { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
/* min-width: 0 overrides the flex default (min-width: auto), which
   otherwise refuses to let a flex child shrink below its content's
   natural width — without it, a wide evidence-form here pushes the
   whole row past the drawer's edge instead of wrapping. */
.child-drivers { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: 1 1 auto; min-width: 0; }
.child-driver-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.evidence-form { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.evidence-form input[type="date"] {
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 11px; padding: 4px 6px; width: 112px;
}

.drawer-actions { display: flex; flex-direction: column; gap: 8px; }
.drawer-actions .btn { justify-content: center; width: 100%; }

.drawer-field { display: flex; flex-direction: column; gap: 6px; }
.drawer-field label { font-size: 11px; font-weight: 700; color: var(--ink-2); }
.drawer-field textarea, .drawer-field select {
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 13px; padding: 8px 10px; resize: vertical; width: 100%;
}
.quoted-body {
  background: var(--surface-2); border-radius: 12px; padding: 10px 12px;
  font-size: 13px; color: var(--ink); line-height: 1.45; white-space: pre-wrap;
}

/* ---------- Mobile ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 14; display: none; }
.scrim.open { display: block; }
@media (max-width: 760px) {
  .rail {
    position: fixed; inset: 0 auto 0 0; z-index: 15; transform: translateX(-100%);
    transition: transform .22s ease; width: 240px; box-shadow: var(--shadow);
  }
  .rail.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px 14px 60px; }
  .topbar { padding: 0 14px; }
  .drawer { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
