:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1c1f23;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --ok: #1a7f47;
  --warn: #a15c07;
  --bad: #b42318;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

/* ---------- Layout ---------- */

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.tabs a.tablink {
  padding: 10px 16px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
.tabs a.tablink.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

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

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-note { font-size: 12px; color: var(--muted); }
.stat.stat-warn { border-color: #f0c98a; background: #fffaf2; }

/* ---------- Sidebar shell ---------- */

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

.sidebar {
  width: 220px;
  flex: none;
  background: #1c2733;
  color: #c7d0da;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 20px 18px;
  font-weight: 700;
  color: #fff;
  font-size: 19px;
  letter-spacing: .01em;
  background: #12191f;
  border-bottom: 1px solid #2b3846;
  line-height: 1.25;
}
.sidebar nav { flex: 1; padding: 8px 0; }
.sidebar .navgroup {
  padding: 14px 18px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6f7d8c;
}
.sidebar a.nav {
  display: block;
  padding: 9px 18px;
  color: #c7d0da;
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar a.nav:hover { background: #24313f; color: #fff; }
.sidebar a.nav.active {
  background: #24313f;
  color: #fff;
  border-left-color: var(--accent);
  font-weight: 600;
}
.sidebar .foot { padding: 14px 18px; border-top: 1px solid #2b3846; font-size: 13px; }
.sidebar .foot .who { color: #8b97a5; display: block; margin-bottom: 8px; }
.sidebar .foot a { color: #c7d0da; text-decoration: none; }
.sidebar .foot a:hover { color: #fff; }

.main { flex: 1; min-width: 0; }
.main .mainhead {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
}
.main .mainwrap { padding: 24px; max-width: 1150px; }

@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row;
             flex-wrap: wrap; }
  .sidebar nav { display: flex; flex-wrap: wrap; }
  .sidebar .navgroup { display: none; }
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 27, 35, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  width: 100%;
  max-width: 780px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 15px; flex: 1; }
.modal-head .x {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--muted); line-height: 1; padding: 0 4px;
}
.modal-body { padding: 20px; }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--line);
  display: flex; gap: 8px; justify-content: flex-end; align-items: center;
}
.modal-foot .spacer { flex: 1; }

/* ---------- Wheel layout grid ---------- */

h3.sub {
  font-size: 13px;
  margin: 22px 0 10px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.axle {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.axle:last-child { border-bottom: none; }
.axle-label {
  width: 62px;
  flex: none;
  font-size: 12px;
  color: var(--muted);
}
.axle-positions { display: flex; gap: 10px; flex-wrap: wrap; }

.tile {
  min-width: 132px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #fff;
}
.tile:hover { border-color: var(--accent); }
.tile.filled { background: #f2f7fd; border-color: #cddffa; }
.tile.spare { border-style: dashed; }
.tile-code { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile-serial { font-size: 13px; font-weight: 600; }
.tile-note { font-size: 12px; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 4px; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.card-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
}
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }

/* invoice totals */
.totals { margin: 14px 0 4px; margin-left: auto; max-width: 320px; }
.totrow {
  display: flex; justify-content: space-between; padding: 5px 0;
  font-variant-numeric: tabular-nums;
}
.totrow span:first-child { color: var(--muted); }
.totrow.grand {
  border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px;
  font-weight: 600; font-size: 15px;
}

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

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

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

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  resize: vertical;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
select.mini { padding: 4px 8px; font-size: 12px; }

label.check {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  font-size: 13px;
  white-space: nowrap;
}
label.check input { padding: 0; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #eef1f4;
  padding: 1px 5px;
  border-radius: 4px;
}

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }

button.btn {
  font: inherit;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
button.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
button.btn.danger { background: #fff; color: var(--bad); border-color: var(--line); }
button.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Status ---------- */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  background: #eef1f4;
  color: var(--muted);
}
.pill.ok { background: #e7f5ec; color: var(--ok); }
.pill.warn { background: #fdf3e2; color: var(--warn); }
.pill.bad { background: #fdeceb; color: var(--bad); }

.msg { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin: 12px 0; }
.msg.error { background: #fdeceb; color: var(--bad); }
.msg.warn { background: #fdf3e2; color: var(--warn); }
.msg.ok { background: #e7f5ec; color: var(--ok); }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.login-card .field { margin-bottom: 14px; }
.login-card input { width: 100%; }
.login-card button.btn { width: 100%; }
