/* FleetExpert portal — one stylesheet for the customer portal and the platform admin console.
   Idea: a dispatch desk. Quiet cool-grey paper, highway-sign green for the customer side, ink-blue for the admin side so the two
   can never be mistaken for each other. The one loud thing is the licence-plate chip, because that is what a dispatcher actually looks for. */
:root {
  --ink: #17211c; --ink-2: #4a5750; --ink-3: #75817a;
  --paper: #f2f4f1; --panel: #ffffff; --line: #d6dcd7; --line-2: #e7ebe8;
  --brand: #0e6b4a; --brand-ink: #ffffff; --brand-soft: #e1f0e9; --brand-deep: #0a4f37;
  --rail: #14231c; --rail-ink: #cfe0d6; --rail-dim: #8aa597;
  --amber: #b87400; --amber-soft: #fbefd2; --red: #b3382c; --red-soft: #f9e0dc; --blue: #2b5fa8; --blue-soft: #e0eaf7; --grey-soft: #e9ecea;
  --radius: 6px; --gap: 16px;
  --font: "Noto Sans Thai UI", "Noto Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
html[data-mode="admin"] { --brand: #2c4a86; --brand-soft: #e3e9f6; --brand-deep: #1f3563; --rail: #18202e; --rail-ink: #d3dbea; --rail-dim: #8d9ab3; }
@media (prefers-color-scheme: dark) {
  :root { --ink: #e8eee9; --ink-2: #b4c0b9; --ink-3: #8b9992; --paper: #101613; --panel: #18201b; --line: #2b362f; --line-2: #222c26;
          --brand: #3fae80; --brand-ink: #06130d; --brand-soft: #173326; --brand-deep: #5cc99b; --amber: #e3a533; --amber-soft: #33290f; --red: #e9786b; --red-soft: #3a1b17;
          --blue: #7aa6e6; --blue-soft: #17263d; --grey-soft: #222a25; color-scheme: dark; }
  html[data-mode="admin"] { --brand: #7f9fe0; --brand-ink: #0b1220; --brand-soft: #1b2740; --brand-deep: #a4bcf0; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--paper); font-variant-numeric: tabular-nums; -webkit-text-size-adjust: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0 0 8px; }
a { color: var(--brand); text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-3); } .small { font-size: 13px; } .nowrap { white-space: nowrap; } .right { text-align: right; } .mono { font-family: var(--mono); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; } .stack { display: flex; flex-direction: column; gap: var(--gap); } .stack.tight { gap: 8px; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
#app { display: grid; grid-template-columns: 224px minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr); height: 100vh; height: 100dvh; }
#rail { grid-row: 1 / 3; background: var(--rail); color: var(--rail-ink); display: flex; flex-direction: column; min-height: 0; }
#rail .brand { height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 16px; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
#rail .brand svg { width: 22px; height: 22px; }
#rail .brand small { font-weight: 500; color: var(--rail-dim); margin-left: auto; font-size: 12px; }
#rail nav { overflow-y: auto; padding: 10px 8px; flex: 1; }
#rail nav .group { margin: 14px 10px 4px; color: var(--rail-dim); font-size: 12px; }
#rail nav a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: var(--radius); color: var(--rail-ink); text-decoration: none; }
#rail nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
#rail nav a:hover { background: rgba(255,255,255,.07); }
#rail nav a[aria-current="page"] { background: rgba(255,255,255,.13); color: #fff; box-shadow: inset 3px 0 0 var(--brand-soft); }
#rail nav a .count { margin-left: auto; background: var(--red); color: #fff; font-size: 12px; border-radius: 10px; padding: 0 7px; line-height: 18px; }
#rail .foot { padding: 10px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: var(--rail-dim); }
#top { background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 16px; min-width: 0; }
#top .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .menu-btn { display: none; }
#main { overflow: hidden; min-height: 0; position: relative; display: flex; flex-direction: column; }
#banners { flex: none; }
#view { flex: 1 1 auto; min-height: 0; overflow: auto; position: relative; }
.page { padding: 20px 24px 40px; max-width: 1280px; margin: 0 auto; }
.page.full { max-width: none; padding: 0; height: 100%; }
.page-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--ink-3); font-size: 14px; }

/* ---------- surfaces ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card > .hd { padding: 12px 16px; border-bottom: 1px solid var(--line-2); display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.card > .bd { padding: 16px; }
.card > .bd.flush { padding: 0; }
.grid { display: grid; gap: var(--gap); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: var(--gap); }
.kpi { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .n { font-size: 24px; font-weight: 650; line-height: 1.1; overflow-wrap: anywhere; } .kpi .l { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.kpi.warn .n { color: var(--amber); } .kpi.bad .n { color: var(--red); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 7px 12px; cursor: pointer; text-decoration: none; color: var(--ink); line-height: 1.2; min-height: 34px; }
.btn:hover { background: var(--grey-soft); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; } .btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, var(--line)); } .btn.danger:hover { background: var(--red-soft); }
.btn.quiet { border-color: transparent; background: transparent; } .btn.quiet:hover { background: var(--grey-soft); }
.btn.sm { padding: 3px 8px; min-height: 28px; font-size: 13px; }
.btn[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }   /* toggle buttons such as the days of a rule's schedule */
.field { display: flex; flex-direction: column; gap: 4px; } .field > label { font-weight: 600; font-size: 14px; } .field .help { color: var(--ink-3); font-size: 13px; } .field .err { color: var(--red); font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], input[type=tel], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 10px; background: var(--panel); min-height: 36px; }
textarea { min-height: 72px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--line); } .seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a[aria-current="true"] { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 600; font-size: 13px; color: var(--ink-2); padding: 9px 14px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 55%, var(--panel)); white-space: nowrap; }
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--grey-soft); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl td.act { text-align: right; white-space: nowrap; }

/* ---------- small things ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 11px; font-size: 13px; line-height: 20px; background: var(--grey-soft); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--brand-soft); color: var(--brand-deep); } .badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.bad { background: var(--red-soft); color: var(--red); } .badge.info { background: var(--blue-soft); color: var(--blue); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); display: inline-block; flex: none; }
.dot.moving { background: #1b9a62; box-shadow: 0 0 0 3px color-mix(in srgb, #1b9a62 25%, transparent); } .dot.stopped { background: var(--amber); } .dot.offline { background: var(--ink-3); }
/* the one loud element: a licence plate */
.plate { display: inline-block; font-weight: 700; letter-spacing: .02em; font-size: 13px; line-height: 1; padding: 4px 8px 3px; border: 1.5px solid var(--ink); border-radius: 4px; background: #fff; color: #111; white-space: nowrap; box-shadow: inset 0 0 0 1px #fff; }
.plate.none { border-style: dashed; color: var(--ink-3); background: transparent; font-weight: 500; }
.banner { padding: 10px 24px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.banner.warn { background: var(--amber-soft); color: var(--amber); } .banner.bad { background: var(--red-soft); color: var(--red); } .banner.info { background: var(--blue-soft); color: var(--blue); }
.banner .grow { color: var(--ink); }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-3); } .empty h3 { color: var(--ink); margin-bottom: 4px; }
.bar { height: 8px; border-radius: 4px; background: var(--grey-soft); overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--brand); } .bar.warn > i { background: var(--amber); } .bar.bad > i { background: var(--red); }
.spin { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--ink-3); }
.steps { counter-reset: s; list-style: none; margin: 0; padding: 0; } .steps li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); align-items: center; }
.steps li:last-child { border-bottom: 0; } .steps .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; }
.steps li.done .tick { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); } .steps li.done .t { color: var(--ink-3); text-decoration: line-through; }
.kv { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 6px 16px; } .kv dt { color: var(--ink-3); } .kv dd { margin: 0; }

/* ---------- toasts, modal ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.bad { background: var(--red); color: #fff; } .toast.ok { background: var(--brand); color: var(--brand-ink); }
.overlay { position: fixed; inset: 0; background: rgba(10,16,13,.5); display: grid; place-items: center; z-index: 1500; padding: 16px; }
.modal { background: var(--panel); border-radius: 8px; width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { width: min(860px, 100%); }
.modal > .hd { padding: 14px 18px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; align-items: center; }
.modal > .bd { padding: 18px; overflow: auto; } .modal > .ft { padding: 12px 18px; border-top: 1px solid var(--line-2); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- map views ---------- */
.mapwrap { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100%; min-height: 0; }
.mapwrap .side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.mapwrap .side .tools { padding: 10px; border-bottom: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 8px; }
.mapwrap .side .list { overflow: auto; flex: 1; }
.vrow { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line-2); cursor: pointer; align-items: center; }
.vrow:hover, .vrow[aria-selected="true"] { background: var(--brand-soft); }
.vrow .name { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vrow .spd { font-weight: 600; text-align: right; font-size: 14px; } .vrow .spd small { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; }
.map { position: relative; min-height: 300px; background: #dfe5e0 repeating-linear-gradient(45deg, transparent 0 18px, rgba(0,0,0,.025) 18px 36px); }
.mapwrap .map { height: 100%; }
.map .leaflet-container { background: transparent; font: inherit; }
.map-note { position: absolute; left: 12px; bottom: 12px; z-index: 600; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; font-size: 13px; max-width: 70%; }
.vmark { display: grid; place-items: center; width: 30px; height: 30px; }
.vmark svg { width: 28px; height: 28px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.vmark.moving svg { color: #1b9a62; } .vmark.stopped svg { color: #d98a00; } .vmark.offline svg { color: #7c8780; }
.detail { position: absolute; right: 12px; top: 12px; z-index: 700; width: min(360px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; }
.legend { display: flex; gap: 12px; font-size: 13px; color: var(--ink-2); }
.videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--gap); }
.vid { background: #0b0f0d; border-radius: var(--radius); overflow: hidden; position: relative; aspect-ratio: 16 / 9; }
.vid video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.vid .cap { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.6); color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 13px; }
.vid .msg { position: absolute; inset: 0; display: grid; place-items: center; color: #cfd8d3; text-align: center; padding: 12px; font-size: 14px; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  #rail { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 1200; transform: translateX(-100%); transition: transform .18s; }
  #rail.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  #top .menu-btn { display: inline-flex; }
  .page { padding: 16px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: minmax(0, 1fr); }
  .mapwrap { grid-template-columns: minmax(0, 1fr); grid-template-rows: 42% minmax(0, 1fr); }
  .mapwrap .side { order: 2; border-right: 0; border-top: 1px solid var(--line); } .mapwrap .map { order: 1; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .banner { padding: 10px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { #rail, #top, .btn, .tabs { display: none !important; } #app { display: block; height: auto; } #main, #view { overflow: visible; } }

/* popovers (bell, user menu) */
.pop { position: absolute; right: 12px; top: 54px; z-index: 1300; width: min(380px, calc(100vw - 24px)); max-height: 70vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.pop .item { padding: 10px 14px; border-bottom: 1px solid var(--line-2); } .pop .item.unread { background: var(--brand-soft); } .pop .item:last-child { border-bottom: 0; }
.pop .item b { display: block; }
.pop button.item, .pop a.item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line-2); background: transparent; cursor: pointer; text-decoration: none; color: var(--ink); }
.pop button.item:hover, .pop a.item:hover { background: var(--grey-soft); }
.notice { border: 1px solid var(--line); border-left: 4px solid var(--brand); background: var(--panel); padding: 10px 14px; border-radius: var(--radius); }
.notice.warn { border-left-color: var(--amber); } .notice.bad { border-left-color: var(--red); }
.sign { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.sign .card { max-width: 440px; width: 100%; padding: 28px; }
.sign h1 { margin-bottom: 8px; }
.drawbar { position: absolute; left: 50%; transform: translateX(-50%); top: 12px; z-index: 800; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100% - 24px); }
.pre { white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 13px; background: var(--grey-soft); padding: 8px 10px; border-radius: var(--radius); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.sep { height: 1px; background: var(--line-2); margin: 12px 0; }
