:root {
  color-scheme: light;
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #172033;
  --muted: #64748b;
  --line: #d8e0ea;
  --line-strong: #c4cfdd;
  --blue: #2563eb;
  --orange: #f59e0b;
  --red: #ef4444;
  --purple: #7c3aed;
  --green: #16a34a;
  --amber: #d97706;
  --danger: #dc2626;
  --shadow: 0 18px 45px rgba(15, 23, 42, .08);
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1560px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 22px 22px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.topbar,
.filter-band,
.section-block,
.detail-panel,
.metric,
.center-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 64px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #111827;
  color: #fff;
  font-weight: 800;
  flex: 0 0 auto;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.25;
  font-weight: 760;
}

.brand p,
.section-head p,
.detail-panel p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--surface);
  color: #334155;
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

.filter-band {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(320px, 1.4fr) minmax(150px, .5fr) minmax(150px, .5fr) auto auto;
  gap: 10px;
  align-items: end;
}

.segments {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segment {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #475569;
  font-size: 14px;
  font-weight: 700;
}

.segment.active {
  background: #111827;
  color: #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, .18);
}

.date-field {
  display: grid;
  gap: 6px;
}

.date-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.date-field input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: var(--radius);
  padding: 0 18px;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-button {
  border: 0;
  background: var(--blue);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #334155;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 88px;
  padding: 14px;
  display: grid;
  align-content: space-between;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

.metric.alert strong {
  color: var(--danger);
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

.main-column {
  display: grid;
  gap: 14px;
}

.section-block,
.detail-panel {
  padding: 14px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

h2 {
  font-size: 18px;
  line-height: 1.35;
}

.center-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.center-card {
  min-height: 88px;
  padding: 12px;
  display: grid;
  align-content: space-between;
  box-shadow: none;
  border-left: 5px solid var(--center-color, var(--blue));
}

.center-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.center-card strong {
  font-size: 26px;
  line-height: 1;
}

.driver-list {
  display: grid;
  gap: 8px;
}

.driver-row {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  min-height: 72px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 150px minmax(260px, 1fr) 84px 96px;
  gap: 12px;
  align-items: center;
  text-align: left;
}

.driver-row.active {
  border-color: #111827;
  box-shadow: 0 0 0 2px rgba(17, 24, 39, .08);
}

.driver-row.high {
  background: #fff7f7;
  border-color: #fecaca;
}

.driver-name strong {
  display: block;
  font-size: 16px;
  line-height: 1.3;
}

.driver-name span,
.score-text,
.diff-text {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stacked {
  height: 20px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.stack {
  min-width: 2px;
  height: 100%;
  background: var(--center-color);
}

.ratio-labels {
  margin-top: 6px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ratio-labels span {
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}

.badge {
  min-height: 30px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.good {
  color: #166534;
  background: #dcfce7;
}

.badge.warn {
  color: #92400e;
  background: #fef3c7;
}

.badge.bad {
  color: #991b1b;
  background: #fee2e2;
}

.detail-panel {
  position: sticky;
  top: 92px;
}

.donut-wrap {
  width: 184px;
  height: 184px;
  margin: 4px auto 14px;
  position: relative;
  display: grid;
  place-items: center;
}

.donut {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(var(--line) 0 100%);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 30px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.donut-center {
  position: absolute;
  display: grid;
  justify-items: center;
  gap: 2px;
}

.donut-center strong {
  font-size: 28px;
  line-height: 1;
}

.donut-center span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.legend {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

.legend-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--center-color);
}

.history-head {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

h3 {
  font-size: 15px;
  line-height: 1.35;
}

.history-list {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  max-height: 390px;
  overflow: auto;
  padding-right: 4px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  gap: 5px;
  background: #fff;
}

.history-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.center-pill {
  border-radius: 999px;
  color: #fff;
  background: var(--center-color);
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}

.busy {
  opacity: .65;
  pointer-events: none;
}

@media (max-width: 1100px) {
  .filter-band {
    grid-template-columns: 1fr 1fr;
  }

  .segments {
    grid-column: 1 / -1;
  }

  .layout-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (min-width: 1280px) and (max-height: 820px) {
  .app-shell {
    padding-top: 14px;
    gap: 12px;
  }

  .topbar {
    min-height: 58px;
  }

  .section-head {
    margin-bottom: 10px;
  }

  .driver-row {
    min-height: 64px;
    padding-block: 8px;
  }

  .center-card,
  .metric {
    min-height: 78px;
  }

  .history-list {
    max-height: 320px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
    gap: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 18px;
  }

  .filter-band,
  .kpi-grid,
  .center-grid {
    grid-template-columns: 1fr;
  }

  .segments {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .driver-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .metric {
    min-height: 86px;
  }

  .donut-wrap {
    width: min(210px, 76vw);
    height: min(210px, 76vw);
  }
}
