:root {
  color: #171a1f;
  background: #f5f7f9;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #171a1f;
  --muted: #68707c;
  --line: #dce1e7;
  --line-strong: #c8cfd8;
  --blue: #225dbd;
  --blue-soft: #edf4ff;
  --green: #11785d;
  --green-soft: #eaf7f2;
  --red: #b7352d;
  --red-soft: #fff0ee;
  --amber: #956500;
  --amber-soft: #fff7df;
  --gray-soft: #eef1f4;
  --shadow: 0 16px 48px rgb(20 27 36 / 14%);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #f5f7f9; }

body {
  margin: 0;
  min-height: 100vh;
  background: #f5f7f9;
  color: var(--ink);
  font-size: 14px;
}

button, input, select { font: inherit; letter-spacing: 0; }

button { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(12px);
}

.brand-block { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; object-fit: contain; }
.brand-block h1 { margin: 0; font-size: 17px; line-height: 1.25; font-weight: 720; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; min-width: 0; }
.header-actions time { color: var(--muted); font-size: 12px; white-space: nowrap; }

.source-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid #b9dfd3;
  border-radius: 4px;
  background: var(--green-soft);
  color: #0b5e48;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.source-state.error { border-color: #f0c6c1; background: var(--red-soft); color: #972b25; }
.source-state.error .state-dot { background: var(--red); }

.state-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover { border-color: #96a1af; background: var(--surface-soft); }
.icon-button:focus-visible, input:focus-visible, select:focus-visible, .provider-tab:focus-visible, .detail-button:focus-visible { outline: 2px solid #78a7ee; outline-offset: 2px; }

main { min-width: 0; }

.summary-band {
  display: grid;
  grid-template-columns: minmax(210px, 1.35fr) repeat(5, minmax(92px, 0.72fr)) minmax(150px, 1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.summary-primary, .metric-item, .budget-meter {
  min-width: 0;
  min-height: 82px;
  padding: 14px 18px;
  border-right: 1px solid var(--line);
}

.summary-primary { display: grid; grid-template-columns: auto 1fr; align-content: center; column-gap: 14px; }
.summary-primary .metric-label { grid-column: 1 / -1; }
.metric-label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.metric-money { align-self: end; margin-top: 3px; font-size: 25px; line-height: 1; font-variant-numeric: tabular-nums; }
.metric-sub { align-self: end; color: var(--green); font-size: 12px; font-weight: 650; overflow-wrap: anywhere; }
.metric-item { display: flex; flex-direction: column; justify-content: center; gap: 5px; }
.metric-item strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.budget-meter { display: flex; flex-direction: column; justify-content: center; gap: 9px; border-right: 0; }
.budget-track { height: 7px; overflow: hidden; border-radius: 3px; background: #e5e8ec; }
.budget-track span { display: block; width: 0; height: 100%; background: var(--blue); transition: width 180ms ease; }
.budget-meter > span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.controls {
  position: sticky;
  top: 64px;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgb(245 247 249 / 97%);
  backdrop-filter: blur(12px);
}

.provider-tabs {
  display: flex;
  min-height: 43px;
  align-items: end;
  gap: 4px;
  overflow-x: auto;
  padding: 6px 24px 0;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}

.provider-tab {
  min-height: 36px;
  padding: 0 13px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}

.provider-tab[aria-selected="true"] { border-color: var(--blue); color: var(--ink); }
.provider-tab-count { margin-left: 6px; color: #8a939f; font-size: 11px; }

.filter-row {
  display: flex;
  min-height: 54px;
  align-items: center;
  gap: 10px;
  padding: 8px 24px;
}

.search-field {
  position: relative;
  flex: 1 1 360px;
  max-width: 520px;
}

.search-symbol { position: absolute; left: 11px; top: 50%; color: #7b8490; transform: translateY(-50%); }
.search-field input { width: 100%; padding-left: 32px; }

input[type="search"], select {
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
}

input[type="search"] { min-width: 0; padding-right: 10px; }
select { min-width: 148px; padding: 0 30px 0 10px; cursor: pointer; }

.check-control { display: inline-flex; min-height: 36px; align-items: center; gap: 7px; padding: 0 8px; white-space: nowrap; cursor: pointer; }
.check-control input { width: 16px; height: 16px; accent-color: var(--blue); }
.result-count { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }

.data-surface { padding: 16px 24px 40px; }
.provider-section { margin-bottom: 18px; border: 1px solid var(--line); background: var(--surface); }
.provider-heading { display: flex; min-height: 46px; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: #f9fafb; }
.provider-name { margin-right: 10px; font-size: 14px; font-weight: 760; }
.provider-meta { color: var(--muted); font-size: 12px; }
.provider-cost { font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 1080px; border-collapse: collapse; table-layout: fixed; }
th, td { height: 50px; padding: 7px 10px; border-bottom: 1px solid #e8ebef; text-align: left; vertical-align: middle; }
th { position: sticky; top: 162px; z-index: 5; height: 39px; background: #f5f7f9; color: #5f6874; font-size: 11px; font-weight: 720; }
th:nth-child(1) { width: 260px; }
th:nth-child(2) { width: 142px; }
th:nth-child(3), th:nth-child(4) { width: 112px; }
th:nth-child(5) { width: 100px; }
th:nth-child(6), th:nth-child(7) { width: 125px; }
th:nth-child(8) { width: 116px; }
th:nth-child(9) { width: 44px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.sorted-column { color: var(--blue); }
.supplier-name { display: block; overflow: hidden; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
.group-name { display: block; overflow: hidden; margin-top: 2px; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.model-name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.delta { display: block; margin-top: 2px; font-size: 10px; }
.delta.bad { color: var(--red); }
.delta.good { color: var(--green); }
.status-badge { display: inline-flex; min-height: 24px; align-items: center; padding: 0 7px; border: 1px solid transparent; border-radius: 4px; font-size: 11px; font-weight: 680; white-space: nowrap; }
.status-badge.good { border-color: #b8dfd2; background: var(--green-soft); color: #0e654e; }
.status-badge.bad { border-color: #f0c6c1; background: var(--red-soft); color: #972b25; }
.status-badge.info { border-color: #c4d7f6; background: var(--blue-soft); color: #194f9f; }
.status-badge.warning { border-color: #ead28d; background: var(--amber-soft); color: #765000; }
.status-badge.muted { border-color: #d8dde3; background: var(--gray-soft); color: #626b76; }
.cache-outcome { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.25; }
.detail-button { display: grid; width: 30px; height: 30px; place-items: center; border: 0; border-radius: 4px; background: transparent; color: var(--blue); font-size: 21px; cursor: pointer; }
.detail-button:hover { background: var(--blue-soft); }
.empty-state { padding: 64px 20px; border: 1px dashed var(--line-strong); background: var(--surface); color: var(--muted); text-align: center; }
.mobile-groups { display: none; }

.route-dialog {
  width: min(560px, 100vw);
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.route-dialog::backdrop { background: rgb(17 24 39 / 35%); }
.dialog-header { display: flex; min-height: 94px; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 4px 0 2px; font-size: 19px; }
.dialog-header p { margin: 0; color: var(--muted); }
.dialog-eyebrow { color: var(--blue); font-size: 11px; font-weight: 760; text-transform: uppercase; }
.dialog-tabs { display: flex; min-height: 44px; align-items: end; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.dialog-tabs button { min-height: 40px; padding: 0 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 12px; font-weight: 680; cursor: pointer; }
.dialog-tabs button[aria-selected="true"] { border-color: var(--blue); color: var(--ink); }
.dialog-content { padding: 18px; overflow-y: auto; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.detail-field { min-height: 70px; padding: 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-field span { display: block; color: var(--muted); font-size: 11px; }
.detail-field strong { display: block; overflow-wrap: anywhere; margin-top: 6px; font-size: 14px; font-variant-numeric: tabular-nums; }
.detail-section-title { margin: 22px 0 8px; font-size: 13px; }
.detail-table { min-width: 0; table-layout: auto; }
.detail-table th, .detail-table td { position: static; height: 40px; font-size: 12px; }
.detail-table th { background: #f6f8fa; }
.formula-block { padding: 13px; border-left: 3px solid var(--blue); background: #f4f7fb; color: #3e4752; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; line-height: 1.7; overflow-wrap: anywhere; }
.price-line { display: grid; grid-template-columns: 1fr repeat(4, 72px); gap: 4px; align-items: center; min-height: 36px; border-bottom: 1px solid var(--line); font-size: 12px; }
.price-line span:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 1180px) {
  .summary-band { grid-template-columns: minmax(210px, 1.4fr) repeat(3, minmax(95px, 0.75fr)) minmax(160px, 1fr); }
  .metric-item:nth-of-type(4), .metric-item:nth-of-type(5) { display: none; }
}

@media (max-width: 760px) {
  body { font-size: 13px; }
  .app-header { min-height: 58px; padding: 7px 12px; gap: 10px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-block h1 { font-size: 15px; }
  .brand-block p, .source-state, .header-actions time { display: none; }
  .header-actions { gap: 6px; }
  .summary-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-primary { grid-column: 1 / -1; min-height: 74px; }
  .summary-primary, .metric-item, .budget-meter { min-height: 62px; padding: 11px 12px; }
  .metric-item:nth-of-type(4), .metric-item:nth-of-type(5) { display: flex; }
  .metric-item { border-top: 1px solid var(--line); }
  .metric-money { font-size: 22px; }
  .budget-meter { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .controls { top: 58px; }
  .provider-tabs { min-height: 42px; padding: 5px 12px 0; }
  .filter-row { display: grid; grid-template-columns: 1fr 1fr; min-height: auto; padding: 9px 12px; }
  .search-field { grid-column: 1 / -1; max-width: none; }
  select { width: 100%; min-width: 0; }
  .check-control { min-height: 32px; padding: 0; }
  .result-count { align-self: center; justify-self: end; margin: 0; }
  .data-surface { padding: 12px 0 28px; }
  .desktop-groups { display: none; }
  .mobile-groups { display: block; }
  .provider-section { margin: 0 0 12px; border-right: 0; border-left: 0; }
  .provider-heading { position: sticky; top: 208px; z-index: 10; min-height: 44px; padding: 8px 12px; }
  .mobile-route { display: block; width: 100%; padding: 11px 12px; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); text-align: left; cursor: pointer; }
  .mobile-route:last-child { border-bottom: 0; }
  .mobile-route-top, .mobile-route-second, .mobile-route-metrics, .mobile-route-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
  .mobile-route-top { margin-bottom: 6px; }
  .mobile-route-top .model-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-route-second { margin-bottom: 7px; }
  .mobile-route-second span:first-child { overflow: hidden; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-cost { flex: 0 0 auto; font-weight: 760; font-variant-numeric: tabular-nums; }
  .mobile-route-metrics { justify-content: flex-start; gap: 14px; color: #505966; font-size: 11px; font-variant-numeric: tabular-nums; }
  .mobile-route-foot { margin-top: 6px; color: var(--muted); font-size: 11px; }
  .route-dialog { width: 100vw; height: min(92dvh, 820px); margin: auto 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .dialog-header { min-height: 84px; }
  .dialog-content { padding: 14px; }
  .detail-grid { grid-template-columns: 1fr; }
  .price-line { grid-template-columns: 1fr repeat(4, 54px); font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
