/* FleetTrack — dark purple theme */
:root {
  color-scheme: dark;
  --bg: #0d0d0f; --card: #1b1b1d; --card2: #232326; --ink: #f2f2f5; --muted: #9a9aa6; --line: #2e2e33;
  --brand: #a94cf5; --brand2: #7f2fd6; --brand-ink: #fff; --glow: #3a1470;
  --ok: #5fdc9a; --warn: #e8c35a; --bad: #ff7a85;
  --ok-bg: #12301f; --warn-bg: #3a3112; --bad-bg: #3a1820; --radius: 16px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); min-height: 100vh;
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1100px 520px at 12% -8%, var(--glow) 0%, transparent 62%), var(--bg);
  background-attachment: fixed;
}
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: 1.15rem; } h2 { font-size: 1.05rem; } h3 { font-size: 1rem; }
a { color: var(--brand); text-decoration: none; }
.boot { text-align: center; margin-top: 30vh; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .8rem; }
.right { text-align: right; } .nowrap { white-space: nowrap; }
svg.ic { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.25em; flex: none; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 6px; }
.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.brand .ic { color: var(--brand); }
.quick { display: none; }
.userpill {
  display: flex; align-items: center; gap: 10px; padding: 5px 6px 5px 14px; border-radius: 99px;
  background: rgba(255,255,255,.07); border: 1px solid var(--line); color: var(--ink); cursor: pointer; font-weight: 600; font-size: .85rem;
}
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand2)); display: grid; place-items: center; font-size: .75rem; font-weight: 700; }
.content { max-width: 1280px; margin: 0 auto; padding: 8px 14px 24px; display: grid; gap: 14px; align-content: start; }
.pagehead { display: flex; align-items: center; gap: 10px; }
.pagehead h1 { font-weight: 600; font-size: 1.1rem; }

/* Rail: bottom bar on phones, left icon rail on desktop */
.rail { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; background: rgba(20,20,22,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); overflow-x: auto; }
.rail a { flex: 1 0 auto; min-width: 62px; display: grid; justify-items: center; gap: 2px; padding: 8px 4px 7px; color: var(--muted); font-size: .66rem; font-weight: 600; }
.rail a .ic { width: 22px; height: 22px; }
.rail a.on { color: #fff; }
.rail a.on .ic { color: var(--brand); }
.rail .sec, .rail .logo { display: none; }

@media (min-width: 860px) {
  .shell { padding-left: 104px; padding-bottom: 0; }
  .topbar { padding: 12px 24px 6px 8px; }
  .brand { display: none; }
  .quick { display: flex; gap: 8px; margin: 0 auto; }
  .quick button { background: none; color: var(--ink); min-height: 0; padding: 6px 12px; border-radius: 10px; display: grid; justify-items: center; gap: 3px; font-size: .7rem; font-weight: 500; border: 1px solid transparent; }
  .quick button:hover { background: rgba(255,255,255,.06); }
  .quick button .ic { width: 20px; height: 20px; }
  .content { padding: 8px 24px 28px 8px; }
  .rail { top: 0; bottom: auto; right: auto; width: 104px; height: 100vh; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); background: rgba(14,14,16,.78); padding: 0; overflow: visible; }
  .rail .logo { display: grid; place-items: center; height: 62px; color: var(--ink); }
  .rail .logo .ic { width: 26px; height: 26px; }
  .rail .sec { display: block; background: var(--card); color: #e9e9ee; font-size: .64rem; font-weight: 700; letter-spacing: .3px; padding: 12px 10px; margin-top: 6px; text-transform: uppercase; }
  .rail a { flex: none; width: 64px; height: 46px; margin: 8px auto 0; border-radius: 10px; padding: 0; place-items: center; align-content: center; position: relative; }
  .rail a span { display: none; }
  .rail a .ic { width: 22px; height: 22px; }
  .rail a.on { background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; }
  .rail a.on .ic { color: #fff; }
  .rail a:hover:not(.on) { background: rgba(255,255,255,.07); color: #fff; }
  .rail a:hover span { display: block; position: absolute; left: 70px; top: 50%; transform: translateY(-50%); background: #000; color: #fff; padding: 4px 9px; border-radius: 7px; font-size: .75rem; white-space: nowrap; z-index: 9; }
}

/* ---------- Components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card > h2 + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.stack { display: grid; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .grid4 { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .v { font-size: 1.3rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .75rem; margin-top: 2px; }
.reg { font-size: 1.5rem; font-weight: 800; letter-spacing: 1px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .72rem; font-weight: 600; background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.empty { text-align: center; color: var(--muted); padding: 26px 8px; }

button, .btn {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 99px; padding: 10px 18px; cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand2)); color: var(--brand-ink); min-height: 42px; text-align: center;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
button.secondary, .btn.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.secondary:hover, .btn.secondary:hover { border-color: var(--brand); }
button.outline, .btn.outline { background: transparent; color: var(--ink); border: 1px solid var(--brand); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.sm, .btn.sm { min-height: 30px; padding: 4px 14px; font-size: .78rem; }
button.block { width: 100%; }
button:disabled { opacity: .55; cursor: default; }

label { display: grid; gap: 5px; font-weight: 500; font-size: .85rem; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: #121214; color: var(--ink); min-height: 44px;
}
input::placeholder { color: #6b6b75; }
input[type=file] { padding: 9px 12px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.field-error { color: var(--bad); font-size: .78rem; font-weight: 500; }
.form-error { background: var(--bad-bg); color: var(--bad); padding: 10px 12px; border-radius: 10px; font-size: .85rem; }
.filters { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 900px) { .filters { grid-template-columns: repeat(5, 1fr); align-items: end; } }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .82rem; }
th { background: var(--card2); color: #e4e4ea; font-weight: 600; font-size: .74rem; padding: 10px 12px; text-align: left; white-space: nowrap; }
th:first-child { border-radius: 10px 0 0 10px; } th:last-child { border-radius: 0 10px 10px 0; }
td { padding: 13px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-bottom: 0; background: var(--card2); }
tr.click { cursor: pointer; } tr.click:hover td { background: rgba(255,255,255,.03); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { background: transparent; color: var(--ink); border: 0; padding: 8px 18px; min-height: 0; font-weight: 500; }
.tabs button.on { background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.thumb { display: block; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; color: var(--ink); }
.thumb img, .thumb .pdf { width: 100%; aspect-ratio: 1; object-fit: cover; display: grid; place-items: center; }
.thumb .pdf .ic { width: 38px; height: 38px; color: var(--muted); }
.thumb div.meta { padding: 7px 9px; font-size: .72rem; }

/* Slide-in side panel (forms) */
dialog { position: fixed; inset: 0 0 0 auto; margin: 0; height: 100%; max-height: 100%; width: min(440px, 100vw); border: 0; border-left: 1px solid var(--line); border-radius: 0; padding: 0; background: #141416; color: var(--ink); animation: slidein .2s ease-out; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } }
dialog form, dialog .dlg-body { padding: 22px 20px; display: grid; gap: 14px; align-content: start; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head .x { background: none; border: 0; min-height: 0; padding: 4px 8px; font-size: 1.5rem; line-height: 1; color: var(--ink); }
dialog .actions { display: flex; gap: 10px; justify-content: flex-end; }

#toasts { position: fixed; left: 0; right: 0; bottom: calc(80px + env(safe-area-inset-bottom)); display: grid; gap: 8px; justify-items: center; z-index: 20; pointer-events: none; }
.toast { background: #fff; color: #111; padding: 10px 16px; border-radius: 12px; font-size: .88rem; max-width: 90vw; box-shadow: 0 4px 20px rgba(0,0,0,.5); }
.toast.bad { background: var(--bad); color: #1a0508; }

.login { max-width: 380px; margin: 0 auto; padding: 14vh 20px 24px; display: grid; gap: 16px; }
.login .box { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 24px 20px; display: grid; gap: 14px; }
.login .logo { width: 68px; height: 68px; border-radius: 18px; margin: 0 auto; display: block; }
.login h1 { text-align: center; font-size: 1.4rem; }
