:root {
  --navy: #1f3a5f;
  --navy-2: #2b4c78;
  --accent: #0f8a6c;
  --accent-ink: #0b6b54;
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #5d6b7c;
  --line: #e1e6ed;
  --soft: #f7f9fb;
  --danger: #b42318;
  --warn-bg: #fff6e5;
  --ok-bg: #e8f6f1;
  --err-bg: #fdecea;
  --info-bg: #eaf1fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; margin-top: 1.25rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--navy-2); }
code { background: var(--soft); border: 1px solid var(--line); border-radius: 6px; padding: .05rem .35rem; font-size: .9em; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { color: #fff; text-decoration: none; display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; }
.brand b { font-weight: 700; }
.tabs { max-width: 1100px; margin: 0 auto; padding: 0 .5rem; display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { color: rgba(255, 255, 255, .78); text-decoration: none; padding: .55rem .75rem .6rem; white-space: nowrap; border-bottom: 3px solid transparent; font-size: .95rem; }
.tabs a:hover { color: #fff; }
.tabs a.on { color: #fff; border-bottom-color: #5fd3b1; font-weight: 600; }

.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255, 255, 255, .18); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.uname { font-size: .9rem; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); background: #fff; color: var(--ink); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); min-width: 220px; overflow: hidden; }
.menu-head { padding: .75rem 1rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.menu-head small { color: var(--muted); }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: .7rem 1rem; background: none; border: 0; font: inherit; color: var(--ink); text-decoration: none; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--soft); }

/* ---------- layout ---------- */
.wrap { max-width: 1100px; width: 100%; margin: 0 auto; padding: 1rem; flex: 1; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h1, .card-head h2 { margin: 0; }
.layout-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; align-items: start; }
.layout-2 > .card { margin-bottom: 0; }
.layout-2 > div > .card:last-child { margin-bottom: 0; }
@media (min-width: 880px) {
  .layout-2 { grid-template-columns: 1fr 1fr; }
  .layout-2.wide-left { grid-template-columns: 1.5fr 1fr; }
}
.cols { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 760px) { .cols { grid-template-columns: 1fr 1fr; } }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }
.login { margin-top: 8vh !important; }

/* ---------- forms ---------- */
.field { margin-bottom: 1rem; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.opt { font-weight: 400; color: var(--muted); font-size: .85em; }
input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  padding: .65rem .75rem;
  min-height: 46px;
  border: 1px solid #c9d2dd;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(15, 138, 108, .25); border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.err { color: var(--danger); font-size: .85rem; margin: .3rem 0 0; }
.hint { color: var(--muted); font-size: .85rem; margin: .35rem 0 0; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; margin: .6rem 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: .15rem; flex: none; accent-color: var(--accent); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.danger-zone { border-top: 1px solid var(--line); margin-top: 1.5rem; padding-top: 1rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 42px; padding: .5rem 1rem; border-radius: 8px;
  border: 1px solid #c9d2dd; background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-height: 48px; padding: .6rem 1.4rem; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); border-color: #f1c4bf; }
.btn.danger:hover { background: var(--err-bg); }
.btn.block { width: 100%; }
.btn.icon { width: 42px; padding: 0; font-size: 1.5rem; line-height: 1; }
.btn:disabled { opacity: .6; cursor: default; }
.link { color: var(--navy-2); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

@media (max-width: 560px) {
  .entry-form .btn.primary { width: 100%; }
}

/* ---------- alerts ---------- */
.alert { border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1rem; border: 1px solid transparent; }
.alert.success { background: var(--ok-bg); border-color: #b9e4d6; }
.alert.error { background: var(--err-bg); border-color: #f4c7c2; }
.alert.info { background: var(--info-bg); border-color: #c8d9f2; }
.credentials .cred { display: flex; gap: .75rem; align-items: center; margin-top: .5rem; flex-wrap: wrap; }
.credentials .cred span { min-width: 150px; color: var(--muted); font-size: .9rem; }
.credentials code { font-size: 1rem; user-select: all; }

/* ---------- stats ---------- */
.stats { display: flex; gap: .75rem; margin: .75rem 0 1rem; flex-wrap: wrap; }
.stat { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .9rem; min-width: 96px; flex: 1; }
.stat .v { display: block; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--navy); }
.stat .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- trip list (this week) ---------- */
.trips { list-style: none; margin: 0; padding: 0; }
.trips li { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 0; border-top: 1px solid var(--line); }
.t-main { display: flex; flex-direction: column; min-width: 0; }
.t-date { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.t-loc { font-weight: 600; }
.t-desc { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.t-side { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; flex: none; }
.t-miles { font-weight: 700; font-variant-numeric: tabular-nums; }
.t-miles small { color: var(--muted); font-weight: 400; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -.25rem; }
.grid { width: 100%; border-collapse: collapse; font-size: .93rem; }
.grid th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem .5rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
.grid td { padding: .6rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr:hover { background: var(--soft); }
.grid.compact td { padding: .4rem .5rem; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid .act { text-align: right; width: 1%; white-space: nowrap; }
.grid .desc { color: var(--muted); max-width: 320px; }
.grid tr.inactive td { color: var(--muted); }
.nowrap { white-space: nowrap; }
.sub { color: var(--muted); font-size: .85rem; }
.lock { opacity: .55; }
.code { font-weight: 700; color: var(--navy); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .05rem .45rem; border-radius: 999px; background: #eef1f5; color: var(--muted); }
.tag.ok { background: var(--ok-bg); color: var(--accent-ink); }
.tag.warn { background: var(--warn-bg); color: #8a5a00; }
.empty { color: var(--muted); padding: 1rem 0; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.show-sm { display: none; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .show-sm { display: block; }
}

/* ---------- report controls ---------- */
.period { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin: .5rem 0; }
.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 3px; overflow-x: auto; max-width: 100%; }
.seg a { padding: .45rem .8rem; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; white-space: nowrap; }
@media (max-width: 420px) { .seg a { padding: .45rem .55rem; font-size: .85rem; } }
.seg a.on { background: #fff; color: var(--navy); box-shadow: var(--shadow); }
.stepper { display: flex; gap: .4rem; align-items: center; }
.stepper .jump input { min-height: 42px; padding: .4rem .5rem; width: auto; }
.custom-range { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin: .5rem 0; }
.custom-range label { font-weight: 600; font-size: .85rem; }
.custom-range input { width: auto; min-height: 42px; }
.range { margin: 1rem 0 0; font-size: 1.05rem; }
.filters { display: grid; grid-template-columns: 1fr; gap: .5rem; margin: .5rem 0 .75rem; }
@media (min-width: 640px) { .filters { grid-template-columns: 1fr 1fr; } }
.breakdown { margin-bottom: 1rem; }
.breakdown summary { cursor: pointer; font-weight: 600; color: var(--navy-2); padding: .25rem 0; }
