: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;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.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;
}

.utility-button {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 14px;
  background: var(--surface);
  color: #334155;
  font-weight: 800;
}

.utility-button:hover,
.icon-button:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.debug-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.debug-panel.hidden {
  display: none;
}

.debug-panel .section-head {
  margin-bottom: 0;
}

.debug-panel pre {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.filter-band {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.filter-summary {
  display: none;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
}

.filter-summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.filter-summary strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}

.filter-summary:focus-visible {
  outline: 2px solid rgba(37, 99, 235, .65);
  outline-offset: 2px;
}

.filter-controls {
  display: grid;
  grid-template-columns: minmax(320px, 1.4fr) minmax(150px, .5fr) minmax(150px, .5fr) auto auto;
  gap: 10px;
  align-items: end;
  overflow: hidden;
  max-height: 220px;
  opacity: 1;
  transform: translateY(0);
  transition: max-height .22s ease, opacity .18s ease, transform .22s ease, margin-top .22s ease;
}

.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;
}

.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: 224px;
  padding: 12px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  box-shadow: none;
  border-left: 5px solid var(--center-color, var(--blue));
}

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

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

.center-work-breakdown {
  display: grid;
  gap: 5px;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
}

.center-company-breakdown {
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.center-company-breakdown p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.center-company-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

.center-company-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.center-company-line span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.center-company-line strong {
  color: #0f172a;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.center-company-bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef6;
}

.center-company-bar span {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: var(--center-color, var(--blue));
}

.center-company-meta {
  color: #64748b;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.center-company-row.muted-row {
  color: var(--muted);
}

.driver-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.driver-row {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
  min-height: 132px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr;
  align-content: space-between;
  gap: 14px;
  text-align: left;
  box-shadow: 0 8px 22px rgba(15, 23, 42, .05);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease, background .15s ease;
}

.driver-row:hover {
  border-color: #a9b7c9;
  transform: translateY(-1px);
}

.driver-row.active {
  border-color: var(--blue);
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .16), 0 14px 28px rgba(37, 99, 235, .12);
}

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

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

.stacked {
  height: 18px;
  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: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

.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-controls {
    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: 118px;
    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;
  }

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

  .filter-band {
    top: 0;
    padding: 8px;
  }

  .filter-summary {
    display: flex;
  }

  .filter-controls {
    grid-template-columns: 1fr;
    max-height: 420px;
  }

  .filter-band.mobile-collapsed .filter-controls {
    max-height: 0;
    margin-top: -10px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
  }

  .filter-band.mobile-collapsed {
    box-shadow: 0 8px 24px rgba(15, 23, 42, .09);
  }

  .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);
  }
}
