/* CP Tech fleet platform — design system.
 *
 * One hand-written stylesheet, served as a file rather than inlined into every
 * page: the browser caches it once, and there is exactly one place to change a
 * colour. No build step, no framework — consistent with the rest of the stack.
 *
 * Dark only, deliberately. A second scheme means every colour, border and state
 * has to be checked twice, and the public driver forms will get their own light
 * appearance anyway.
 *
 * Palette derives from the brand assets: #1f1d21 (dark) and #59c2dc (cyan) are
 * taken from the logo SVG, everything else is built around them.
 */

:root {
  color-scheme: dark;

  --bg-body:      #17161a;
  --bg-sidebar:   #1f1d21;  /* brand dark — the navigation carries the brand */
  --bg-panel:     #232227;
  --bg-raised:    #2b292f;
  --bg-input:     #16151a;

  --border:        #35333b;
  --border-strong: #474450;

  --text:       #ecebef;
  --text-dim:   #9c97a4;
  --text-faint: #6e6976;

  --accent:        #59c2dc;  /* CP cyan */
  --accent-hover:  #7bd3ea;
  --accent-ink:    #0d2a32;  /* text on top of accent */
  --accent-soft:   #59c2dc1f;

  --ok:      #5cc98d;
  --warn:    #e0b355;
  --danger:  #f07a72;
  --danger-bg:     #3a1d1d;
  --danger-border: #6d3230;

  --radius:    9px;
  --radius-sm: 6px;

  /* Compact by choice: 57 vehicles and 7,272 transactions mean the number of
   * rows visible without scrolling is what decides whether a list is usable. */
  --row-h: 34px;

  --font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--bg-body);
  color: var(--text);
  font: var(--font);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Never remove focus rings: keyboard users lose all orientation without them. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------------------------------------------------------------------------
 * Application shell
 * ------------------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: 216px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand { padding: 0 1.15rem; }
.sidebar .brand img { width: 118px; height: auto; display: block; }

.nav { display: flex; flex-direction: column; gap: 1px; }

.nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem 1.15rem;
  color: var(--text-dim);
  font-size: .875rem;
  border-left: 2px solid transparent;
}
.nav a:hover { background: #ffffff08; color: var(--text); text-decoration: none; }

/* aria-current, not a class: the marker and the accessible state cannot drift
 * apart if they are the same attribute. */
.nav a[aria-current="page"] {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--text);
  font-weight: 500;
}

.nav .group {
  padding: 1rem 1.15rem .3rem;
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-faint);
}

.sidebar .foot { margin-top: auto; padding: 0 1.15rem; }
.sidebar .foot .who { font-size: .8125rem; color: var(--text); }
.sidebar .foot .role { font-size: .75rem; color: var(--text-faint); margin-bottom: .6rem; }

.content {
  padding: 1.6rem 2rem 3rem;
  min-width: 0;
  /* One rule spaces every section identically, whatever the element is. */
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
/* Margins on direct children would add to the gap and make it uneven again. */
.content > * { margin-top: 0; margin-bottom: 0; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.page-head .sub { margin: .15rem 0 0; color: var(--text-dim); font-size: .8125rem; }

/* On a narrow screen the sidebar becomes a scrollable strip at the top. No
 * JavaScript and no collapsing menu: fewer moving parts than a hamburger, and
 * nothing to get stuck open. */
@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    flex-direction: row; align-items: center; gap: .5rem;
    padding: .6rem .8rem;
    border-right: 0; border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .sidebar .brand { padding: 0 .5rem 0 0; flex: none; }
  .sidebar .brand img { width: 84px; }
  .nav { flex-direction: row; gap: .15rem; }
  .nav a { padding: .4rem .65rem; border-left: 0; border-bottom: 2px solid transparent; white-space: nowrap; }
  .nav a[aria-current="page"] { border-left-color: transparent; border-bottom-color: var(--accent); }
  .nav .group { display: none; }
  .sidebar .foot { margin: 0 0 0 auto; padding: 0 .3rem; display: flex; align-items: center; gap: .6rem; }
  .sidebar .foot .role { display: none; }
  .content { padding: 1.1rem 1rem 2.5rem; }
}

/* ---------------------------------------------------------------------------
 * Centred card — login, second factor, enrolment
 * ------------------------------------------------------------------------- */

body.centred { display: grid; place-items: center; padding: 1.5rem; }

.card {
  width: min(26rem, 100%);
  padding: 2rem 2rem 1.75rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.card.wide { width: min(34rem, 100%); }
.card .brand { margin-bottom: 1.5rem; }
.card .brand img { width: 128px; height: auto; display: block; }
.card h1 { margin: 0 0 .2rem; font-size: 1.125rem; font-weight: 600; }
.card .sub { margin: 0 0 1.4rem; color: var(--text-dim); font-size: .875rem; }

/* ---------------------------------------------------------------------------
 * Panels
 * ------------------------------------------------------------------------- */

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel > h2 {
  margin: 0;
  padding: .8rem 1rem;
  font-size: .875rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.panel .body { padding: 1rem; }
.panel .body > :first-child { margin-top: 0; }
.panel .body > :last-child { margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1.25rem; }

/* Side-by-side panels are equal height, so their closing action would otherwise
 * sit at a different vertical position in each one — the shorter panel's button
 * floating in the middle of empty space. Pushing the last action row to the
 * bottom lines them up. */
.grid-2 > .panel { display: flex; flex-direction: column; }
.grid-2 > .panel > .body { flex: 1; display: flex; flex-direction: column; }
.grid-2 > .panel > .body > .actions-row:last-child { margin-top: auto; padding-top: 1.1rem; }

/* ---------------------------------------------------------------------------
 * Stat tiles
 * ------------------------------------------------------------------------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1.25rem; }

.tile {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem 1rem;
}
.tile.warn { border-color: #6b5626; }
.tile .t-label { font-size: .75rem; color: var(--text-dim); text-transform: uppercase;
                 letter-spacing: .04em; margin-bottom: .35rem; }
.tile .t-value { font-size: 1.75rem; font-weight: 600; line-height: 1.1;
                 font-variant-numeric: tabular-nums; }
.tile .t-sub { margin-top: .4rem; font-size: .75rem; color: var(--text-faint); }

/* ---------------------------------------------------------------------------
 * Bar chart
 * ------------------------------------------------------------------------- */

/* Plain CSS, no library and no script — the content security policy forbids
 * script outright, and a dozen bars do not need one. */
.chart {
  /* Shared by the bars and the reference line, so the line cannot drift away
   * from them when one of these changes. */
  --track-h: 132px;
  --label-h: 1.45rem;
  position: relative;
  display: flex; gap: .35rem; align-items: flex-end;
}
.chart .col { flex: 1; min-width: 0; text-align: center; }
.chart .track { height: var(--track-h); display: flex; flex-direction: column; justify-content: flex-end; }

/* Median line.
 *
 * It crosses two backgrounds — the dark panel between the bars and the light
 * bars themselves — so no single colour reads well everywhere. A light dash
 * with a dark shadow underneath is legible on both.
 *
 * z-index puts it over the bars; without it the line disappears behind every
 * bar taller than the median, which is exactly where it matters most. */
.chart .ref {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--label-h) + var(--track-h) * var(--pct));
  border-top: 1px dashed rgba(255, 255, 255, .72);
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .5));
  pointer-events: none;
  z-index: 1;
}
/* Top right, clear of the bars. Boxed and on top, because the tallest bar can
 * still be the last one. */
.chart .ref-label {
  position: absolute; top: 0; right: 0; z-index: 2;
  font-size: .6875rem; font-weight: 500; color: var(--text-dim);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1rem .45rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chart .fill {
  width: 100%; background: var(--accent); opacity: .9;
  border-radius: 3px 3px 0 0; min-height: 2px;
  /* Clips the value rather than letting it spill out of a short bar. */
  overflow: hidden;
  display: flex; justify-content: center; align-items: flex-start;
  padding-top: .3rem;
}
.chart .col:hover .fill { opacity: 1; }
/* Dark ink on the cyan fill; the same size above the bar when it is too short. */
.chart .v { font-size: .6875rem; font-weight: 600; color: var(--accent-ink);
            white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart .track > .v { color: var(--text-dim); text-align: center; padding-bottom: .2rem; }
.chart .lbl { height: var(--label-h); line-height: var(--label-h);
              font-size: .6875rem; color: var(--text-faint);
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------------------
 * Tables
 * ------------------------------------------------------------------------- */

/* Wide tables scroll inside their own container. The page body must never
 * scroll sideways — that breaks every other column on the screen. */
.table-scroll { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .8125rem;
}
table.data th {
  text-align: left;
  padding: .5rem .75rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 500;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
/* Sortable headers. The whole cell reacts, not just the word — a one-line
 * target at this font size is hard to hit. */
table.data th a.sort {
  color: inherit; text-decoration: none;
  display: inline-flex; align-items: center; gap: .3rem;
}
table.data th a.sort:hover { color: var(--text); text-decoration: none; }
table.data th a.sort.active { color: var(--accent); }
table.data th .arrow { font-size: .7em; line-height: 1; }

table.data td {
  padding: 0 .75rem;
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #ffffff06; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .mono { font-family: var(--mono); font-size: .78125rem; }
table.data .actions { text-align: right; white-space: nowrap; }
table.data .dim { color: var(--text-dim); }

.empty { padding: 2rem 1rem; text-align: center; color: var(--text-dim); font-size: .875rem; }

/* Key/value list for detail views. */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0; font-size: .875rem; }
dl.kv dt { color: var(--text-dim); }
dl.kv dd { margin: 0; }

/* ---------------------------------------------------------------------------
 * Badges
 * ------------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: .1rem .45rem;
  border-radius: 999px;
  font-size: .6875rem;
  font-weight: 500;
  border: 1px solid;
  white-space: nowrap;
}
.badge.ok      { color: var(--ok);      border-color: #2f6b4a; background: #1c2f24; }
.badge.warn    { color: var(--warn);    border-color: #6b5626; background: #2f2819; }
.badge.danger  { color: var(--danger);  border-color: var(--danger-border); background: var(--danger-bg); }
.badge.neutral { color: var(--text-dim); border-color: var(--border-strong); background: var(--bg-raised); }
.badge.accent  { color: var(--accent);  border-color: #2f6675; background: #16303a; }

/* ---------------------------------------------------------------------------
 * Forms
 * ------------------------------------------------------------------------- */

label { display: block; margin-bottom: .3rem; font-size: .8125rem; color: var(--text-dim); }

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
  width: 100%;
  padding: .55rem .65rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: .875rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: transparent;
}
input[disabled], select[disabled] { opacity: .55; cursor: not-allowed; }
textarea { min-height: 6rem; resize: vertical; }

.field { margin-bottom: 1rem; }
.field .hint { margin: .3rem 0 0; font-size: .75rem; color: var(--text-faint); }

/* One-time codes: wide tracking so a six-digit code is read in one glance. */
input.code {
  font-size: 1.3rem; letter-spacing: .4em; text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem .9rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--bg-raised); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: #34313a; }
.btn.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.btn.danger:hover { background: #4a2525; }
.btn.small { padding: .3rem .6rem; font-size: .8125rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.actions-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------------------
 * Messages
 * ------------------------------------------------------------------------- */

.msg {
  padding: .65rem .8rem;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: .875rem;
}
.card .msg { margin-bottom: 1.25rem; }
.msg.error   { background: var(--danger-bg); border-color: var(--danger-border); color: #fbb4ae; }
.msg.ok      { background: #1c2f24; border-color: #2f6b4a; color: #a6e5c2; }
.msg.info    { background: #16303a; border-color: #2f6675; color: #b3e4f1; }
.msg.warn    { background: #2f2819; border-color: #6b5626; color: #ecd39a; }

.note { color: var(--text-dim); font-size: .8125rem; }

/* ---------------------------------------------------------------------------
 * Enrolment specifics
 * ------------------------------------------------------------------------- */

/* The QR code needs a light quiet zone to scan reliably — a dark page behind a
 * dark-on-transparent code does not scan. */
.qr { display: grid; place-items: center; padding: .9rem; background: #fff; border-radius: var(--radius); margin-bottom: 1.1rem; }
.qr svg { width: 190px; height: 190px; display: block; }

.secret { font-family: var(--mono); font-size: .8125rem; word-break: break-all; text-align: center; color: var(--text-dim); margin-bottom: 1.1rem; }

ol.codes {
  margin: 0 0 1.1rem; padding-left: 1.4rem;
  columns: 2; column-gap: 1.5rem;
  font-family: var(--mono); font-size: .9375rem;
}
ol.codes li { margin: .18rem 0; }

@media print {
  /* Recovery codes are meant to be printed. Everything else on the page is
   * noise on paper. */
  body { background: #fff; color: #000; }
  .sidebar, .btn, form { display: none !important; }
  .panel, .card { border-color: #999; }
}
