:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #627d98;
  --line: #d9e2ec;
  --band: #f5f7fa;
  --head: #102a43;
  --accent: #0b7285;
  --danger: #b42318;
  --danger-bg: #fde7e7;
  --warn: #a15c07;
  --warn-bg: #fff2cc;
  --over: #b54708;
  --over-bg: #ffead5;
  --ok: #176b3a;
  --ok-bg: #e5f6ed;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #ffffff;
  color: var(--ink);
  font-family: Aptos, Segoe UI, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: #000;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  display: block;
  width: 190px;
  height: 46px;
  flex: 0 0 auto;
  background: #000 url('/assets/team18-logo.png') center / 150% auto no-repeat;
  border-radius: 4px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
}

.topbar p {
  margin-top: 4px;
  color: #bcccdc;
  font-size: 13px;
}

.actions,
.pager {
  display: flex;
  gap: 8px;
  align-items: center;
}

button,
.button {
  border: 1px solid #bcccdc;
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 6px;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

button:hover,
.button:hover {
  border-color: var(--accent);
}

main {
  padding: 18px 24px 28px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 260px));
  gap: 12px;
}

.master-add-shell {
  margin-bottom: 14px;
}

.master-part-form {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}

.form-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.form-message {
  align-self: end;
  color: var(--muted);
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--band);
}

.metric span {
  display: block;
  font-size: 26px;
  line-height: 1;
  font-weight: 700;
}

.metric label {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.metric.danger {
  background: var(--danger-bg);
  border-color: #f1b8b5;
}

.metric.warn {
  background: var(--warn-bg);
  border-color: #f4d27a;
}

.metric.service-over {
  background: var(--over-bg);
  border-color: #f2b87b;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) 150px 150px minmax(200px, 1fr) 130px;
  gap: 12px;
  align-items: end;
  margin: 18px 0;
}

.filters.compact {
  grid-template-columns: minmax(260px, 2fr) minmax(220px, 1fr);
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab.active {
  color: var(--head);
  border-bottom-color: var(--accent);
}

.view {
  display: none;
  margin-top: 18px;
}

.view.active {
  display: block;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  min-height: 36px;
  border: 1px solid #bcccdc;
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

.cell-input {
  width: 120px;
  min-height: 30px;
  padding: 5px 7px;
}

.cell-input.notes {
  width: min(260px, 100%);
}

.row-actions {
  white-space: nowrap;
}

.row-actions button {
  min-height: 30px;
  padding: 5px 9px;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  min-height: 0;
  text-align: left;
}

.link-button:hover {
  text-decoration: underline;
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.editor-grid button {
  align-self: end;
}

.check {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  min-height: 36px;
}

.check input {
  min-height: auto;
}

.table-shell {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  background: var(--band);
  border-bottom: 1px solid var(--line);
}

.table-title p,
#pageLabel {
  color: var(--muted);
  font-size: 13px;
}

.scroll {
  overflow: auto;
  max-height: calc(100vh - 285px);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1180px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: var(--head);
  color: #fff;
  z-index: 1;
  font-size: 12px;
}

.table-sort {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

.table-sort::after {
  content: "";
  display: inline-block;
  width: 12px;
  margin-left: 5px;
}

.table-sort.active[data-direction="asc"]::after {
  content: "▲";
}

.table-sort.active[data-direction="desc"]::after {
  content: "▼";
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #eef9fb;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.status {
  display: inline-block;
  min-width: 76px;
  padding: 4px 8px;
  border-radius: 999px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.status.over {
  color: var(--over);
  background: var(--over-bg);
}

.status.near {
  color: var(--warn);
  background: var(--warn-bg);
}

.status.ok {
  color: var(--ok);
  background: var(--ok-bg);
}

.status.unknown {
  color: var(--muted);
  background: #edf1f5;
}

.status.manual {
  color: var(--ink);
  background: #edf1f5;
}

.status.not_fitted {
  color: var(--muted);
  background: #edf1f5;
}

.status.damaged {
  color: #fff;
  background: var(--danger);
}

.status.retired {
  color: #fff;
  background: #52606d;
}

.status.good {
  color: var(--ok);
  background: var(--ok-bg);
}

.status.attention {
  color: var(--warn);
  background: var(--warn-bg);
}

.condition-select, .location-select { min-width: 132px; }
.part-row-crashed { background: #fde7e7; }
.part-row-over { background: #fff4e8; }
.part-row-retired { background: #edf1f5; }
.part-row-good { background: #f1fbf5; }
.region-hotspot.has-over { background: rgba(181, 71, 8, 0.9); border-color: #ffd0a1; }
.region-hotspot.all-good { background: rgba(23, 107, 58, 0.84); border-color: #a7e8bf; }
.exploded-card.has-over { border-left: 5px solid var(--over); }
.exploded-card.all-good { border-left: 5px solid var(--ok); }
.category-alert { display: inline-block; margin-left: 6px; color: var(--over); font-size: 12px; }

.parts-used-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--band);
}
.parts-used-form[hidden] { display: none; }
.parts-used-form textarea { border: 1px solid #bcccdc; border-radius: 6px; padding: 8px; font: inherit; resize: vertical; }
.used-notes { grid-column: span 3; }
.parts-used-table { min-width: 1250px; }

.event-import-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px;
  background: var(--band);
  border-bottom: 1px solid var(--line);
}
.event-import-form[hidden] { display: none; }
.event-import-form textarea { border: 1px solid #bcccdc; border-radius: 6px; padding: 8px; font: inherit; resize: vertical; }
.event-notes { grid-column: span 3; }
.source-badge { display: inline-block; margin-top: 4px; padding: 2px 6px; border-radius: 4px; background: #edf1f5; color: var(--muted); font-size: 11px; }

.detail {
  position: fixed;
  top: 0;
  right: 0;
  width: min(680px, 96vw);
  height: 100vh;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 30px rgba(16, 42, 67, 0.16);
  transform: translateX(102%);
  transition: transform 160ms ease;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.detail.open {
  transform: translateX(0);
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  background: var(--head);
  color: #fff;
}

.detail-head p {
  color: #bcccdc;
  font-size: 13px;
  margin-top: 4px;
}

#detailBody {
  overflow: auto;
  padding: 14px 16px 22px;
}

.history-row {
  display: grid;
  grid-template-columns: 96px 1fr 90px 92px;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 12px;
  padding: 14px;
}

.category-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.category-card h3 {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 10px 12px;
  background: var(--head);
  color: #fff;
  font-size: 15px;
}

.category-card table {
  min-width: 0;
}

.category-card th,
.category-card td {
  font-size: 12px;
  padding: 6px 8px;
}

.pill-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--band);
}

.pill {
  border-radius: 999px;
  background: #edf1f5;
  color: var(--muted);
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 700;
}

.location-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  background: #edf1f5;
  color: var(--muted);
}

.location-pill.installed {
  background: #e8f6ee;
  color: var(--ok);
}

.location-pill.spare {
  background: #edf1f5;
  color: var(--ink);
}

.location-pill.heritage {
  background: #fff2cf;
  color: #7a4b00;
}

.location-select {
  min-width: 120px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
}

.component-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  padding: 12px 14px;
  background: var(--band);
  border-bottom: 1px solid var(--line);
}

.summary-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
}

.summary-chip span {
  display: block;
  font-weight: 700;
  font-size: 18px;
}

.summary-chip label {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.detail-table {
  margin-top: 16px;
}

.visual-board {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}

.visual-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.visual-head p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.workshop-map {
  display: grid;
  grid-template-columns: minmax(520px, 1.5fr) minmax(240px, 0.7fr);
  gap: 18px;
  padding: 18px;
  min-height: 640px;
}

.car-zone {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  grid-template-rows: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 18px;
}

.visual-car {
  position: relative;
  min-height: 280px;
  border: 2px solid #9fb3c8;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(16, 42, 67, 0.08);
  overflow: hidden;
}

.visual-car img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.96;
}

.car-label {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: start;
  justify-items: start;
  min-height: 100%;
  padding: 18px 22px;
  text-align: left;
  background: transparent;
}

.car-label strong {
  display: inline-block;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 24px;
  color: var(--head);
  box-shadow: 0 4px 14px rgba(16, 42, 67, 0.18);
}

.car-label span {
  margin-top: 6px;
  color: var(--head);
  font-size: 13px;
}

.car-alerts {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.visual-car.car-15 {
  grid-column: 1 / 3;
  width: min(62%, 460px);
  justify-self: center;
}

.location-zone {
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  gap: 18px;
}

.location-card {
  border: 2px solid #9fb3c8;
  border-radius: 12px;
  background: #fff;
  color: var(--head);
  display: grid;
  place-content: center;
  gap: 8px;
  min-height: 180px;
}

.location-card span {
  font-size: 24px;
  font-weight: 800;
}

.location-card small {
  color: var(--muted);
  font-size: 13px;
}

.truck-card {
  background: linear-gradient(135deg, #f8fafc, #e6f6f8);
}

.sca-truck-card {
  background: linear-gradient(135deg, #f8fafc, #e9f7ef);
}

.stores-card {
  background: linear-gradient(135deg, #fff, #f5f7fa);
}

.heritage-card {
  background: linear-gradient(135deg, #fffaf0, #fff2cf);
}

.exploded {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.exploded-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(260px, 0.7fr);
  gap: 12px;
  padding: 14px;
  background: #fff;
}

.location-detail {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.location-detail table {
  margin: 0;
}

.region-stage {
  position: relative;
  min-height: 660px;
  grid-row: span 6;
  border-radius: 8px;
  background: #050505;
  overflow: hidden;
}

.region-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.86;
}

.region-hotspot {
  position: absolute;
  display: grid;
  place-items: center;
  min-height: 54px;
  border: 2px solid rgba(255,255,255,0.92);
  background: rgba(16, 42, 67, 0.72);
  color: #fff;
  border-radius: 8px;
  padding: 6px;
  text-align: center;
}

.region-hotspot span {
  font-weight: 800;
  font-size: 12px;
}

.region-hotspot small {
  font-size: 11px;
  color: #d9e2ec;
}

.region-hotspot.front-clip { left: 30%; top: 5%; width: 40%; }
.region-hotspot.front-left-corner { left: 7%; top: 18%; width: 24%; }
.region-hotspot.front-right-corner { right: 7%; top: 18%; width: 24%; }
.region-hotspot.cockpit { left: 34%; top: 34%; width: 32%; }
.region-hotspot.engine { left: 34%; top: 24%; width: 32%; }
.region-hotspot.engine-cooling { left: 34%; top: 49%; width: 32%; }
.region-hotspot.driveline { left: 36%; top: 63%; width: 28%; }
.region-hotspot.rear-left-corner { left: 7%; top: 70%; width: 24%; }
.region-hotspot.rear-right-corner { right: 7%; top: 70%; width: 24%; }
.region-hotspot.rear-clip { left: 31%; bottom: 4%; width: 38%; }
.region-hotspot.electrical { left: 39%; top: 40%; width: 22%; }
.region-hotspot.air-jack { right: 6%; top: 24%; width: 22%; }
.region-hotspot.other { left: 5%; top: 42%; width: 22%; }

.region-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--band);
}

.region-detail h3 {
  margin: 0 0 4px;
}

.region-detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.region-components {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.region-parts,
.swap-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.region-part-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 80px minmax(130px, auto) minmax(135px, auto) auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.region-part-row.expected-row {
  border-style: dashed;
  background: #f8fafc;
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
}

.region-part-row span,
.swap-option small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.swap-target {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--band);
}

.swap-option {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 400;
}

.exploded-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.exploded-card h3 {
  margin: 0;
  padding: 9px 10px;
  background: var(--head);
  color: #fff;
  font-size: 14px;
}

.exploded-card .component-link {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 8px 10px;
  text-align: left;
}

.exploded-card .component-link:last-child {
  border-bottom: 0;
}

.muted {
  color: var(--muted);
}

@media (max-width: 900px) {
  .topbar,
  .table-title {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics,
  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .brand-logo {
    width: 150px;
  }

  .scroll {
    max-height: calc(100vh - 420px);
  }

  .workshop-map {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .location-zone {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
  }

  .location-card {
    min-height: 120px;
  }
}

.record-detail-shell {
  min-height: 360px;
}

.record-detail-body {
  padding: 16px;
}

.record-detail-body > .scroll {
  max-height: none !important;
}

.load-error {
  padding: 16px;
  border: 1px solid #d7dee8;
  background: #fff4f4;
  color: #8b1e1e;
}

@media (max-width: 560px) {
  .brand {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-logo {
    width: 180px;
  }

  .metrics,
  .filters,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .car-zone,
  .location-zone {
    grid-template-columns: 1fr;
  }

  .car-zone {
    grid-template-rows: none;
  }

  .visual-car.car-15 {
    grid-column: auto;
    width: 100%;
  }
}
