:root {
  --bg: #ffffff;
  --surface: #f7f8fa;
  --surface-2: #eef0f3;
  --border: #d9dde2;
  --text: #111318;
  --text-2: #4b5563;
  --text-3: #6b7280;
  --accent: #0e6b4c;
  --accent-2: #0a5139;
  --accent-text: #ffffff;
  --focus: #146c54;
  --focus-ring: 0 0 0 3px rgba(20, 108, 84, 0.35);
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --ok: #0f6d4d;
  --warn: #92400e;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 8px rgba(0, 0, 0, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji";
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --header-h: 64px;
  --max-w: 1280px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1e2530;
    --border: #30363d;
    --text: #e6edf3;
    --text-2: #b0b8c4;
    --text-3: #7d8590;
    --accent: #3fb97f;
    --accent-2: #2a9d68;
    --accent-text: #05130d;
    --focus: #3fb97f;
    --focus-ring: 0 0 0 3px rgba(63, 185, 127, 0.35);
    --danger: #f87171;
    --danger-bg: #3f1010;
    --ok: #4ade80;
    --warn: #fbbf24;
  }
}

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

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: var(--accent-text);
  padding: 8px 12px;
  z-index: 100;
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  top: 0;
}

.offline-banner {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 8px 16px;
  text-align: center;
  font-weight: 500;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(4px);
}

.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  flex-shrink: 0;
}

.brand-name {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
  font-weight: 800;
}

.brand-tagline {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.freshness {
  color: var(--text-3);
  font-size: 0.82rem;
  max-width: 260px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.workload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label,
.field legend {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
}

.field input[type="number"],
.field select,
.search-input {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  min-height: 38px;
}

.field input[type="number"]:focus,
.field select:focus,
.search-input:focus,
.chip:focus,
.btn:focus,
.catalog-row:focus,
a:focus {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--focus);
}

.cache-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cache-field label {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cache-value {
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.mode-field {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-field legend {
  margin-bottom: 4px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  cursor: pointer;
}

.search-tools {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-input {
  width: 100%;
  font-size: 1rem;
}

.selects-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.select-field {
  min-width: 180px;
  flex: 1;
}

.select-field select {
  width: 100%;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip:hover {
  background: var(--surface-2);
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.chip[aria-pressed="true"] .chip-check::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: currentColor;
}

.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  flex-wrap: wrap;
}

.result-stats {
  margin: 0;
  color: var(--text-2);
  font-size: 0.9rem;
}

.catalog-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.catalog-head,
.catalog-row {
  display: grid;
  grid-template-columns: minmax(200px, 2.5fr) 0.9fr 0.9fr 1.1fr 1fr 1fr 1fr 1fr;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  text-align: left;
}

.catalog-head {
  position: sticky;
  top: var(--header-h);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-2);
  z-index: 10;
  pointer-events: none;
}

.catalog-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.catalog-row {
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: inherit;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s ease;
}

.catalog-row:last-child {
  border-bottom: none;
}

.catalog-row:hover,
.catalog-row:focus-visible {
  background: var(--surface-2);
}

.catalog-row .cell {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.catalog-row .cell-name {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.catalog-row .cell-lab {
  text-transform: capitalize;
  color: var(--text-2);
}

.model-title {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.model-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-3);
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.badge-accent {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.badge-ok {
  background: var(--ok);
  color: #fff;
  border-color: var(--ok);
}

.badge-warn {
  background: var(--warn);
  color: #1a0f00;
  border-color: var(--warn);
}

.badge-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.caps {
  display: inline-flex;
  gap: 3px;
}

.cap {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

.cell-count,
.cell-price,
.cell-cost,
.cell-context {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cell-cost {
  font-weight: 700;
}

.cell-cost-free {
  color: var(--ok);
}

.cell-cost-missing {
  color: var(--text-3);
}

.logo {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: contain;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.logo--missing {
  display: none !important;
}

.logo-fallback {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-2);
  color: var(--accent-text);
  display: inline-grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.crown {
  color: var(--warn);
  font-weight: 800;
}

.loading-state {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-2);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--danger);
}

.error-state p {
  margin: 0 0 12px;
}

.load-more-wrap {
  padding: 16px 0 8px;
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: var(--surface-2);
}

.btn-small {
  padding: 5px 10px;
  font-size: 0.82rem;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.site-footer {
  margin-top: auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px;
  text-align: center;
  color: var(--text-2);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--accent-2);
}

.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  z-index: 100;
}

/* Detail dialog */
.detail-dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 20px 40px rgba(0, 0, 0, 0.15);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  width: 100%;
}

.detail-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.detail-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  min-width: 0;
  outline: none;
}

.detail-content {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-2);
}

.detail-meta .meta-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}

.detail-meta .meta-key {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-3);
  margin-bottom: 2px;
}

.provider-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.provider-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.provider-table th,
.provider-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.provider-table th {
  background: var(--surface-2);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.provider-table tr:last-child td {
  border-bottom: none;
}

.provider-table tr.cheapest td {
  background: rgba(20, 108, 84, 0.08);
}

.provider-table .provider-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.provider-table .price {
  font-variant-numeric: tabular-nums;
}

.provider-table .diff {
  font-size: 0.8rem;
  color: var(--text-3);
}

.provider-table .env-hints {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.78rem;
  color: var(--text-3);
}

.provider-table .env-hints code {
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 3px;
}

.provider-table .doc-link {
  font-size: 0.8rem;
}

/* Mobile adaptations */
@media (max-width: 760px) {
  :root {
    --header-h: 56px;
  }

  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    gap: 8px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .brand-name {
    font-size: 1rem;
  }

  .brand-tagline {
    font-size: 0.72rem;
  }

  .status-bar {
    width: 100%;
    justify-content: space-between;
  }

  .freshness {
    text-align: left;
    max-width: none;
  }

  .main {
    padding: 12px;
  }

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

  .selects-row {
    flex-direction: column;
  }

  .catalog-head {
    display: none;
  }

  .catalog-list .catalog-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 14px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
  }

  .catalog-list .catalog-row .cell {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .catalog-list .catalog-row .cell::before {
    content: attr(data-label);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-3);
    font-weight: 700;
  }

  .catalog-list .cell-name {
    align-items: flex-start;
    flex-direction: column;
  }

  .catalog-list .cell-name::before {
    content: "Model";
  }

  .catalog-list .model-title {
    white-space: normal;
  }

  .catalog-wrap {
    border: none;
    background: transparent;
  }

  .provider-table th,
  .provider-table td {
    white-space: normal;
  }

  .provider-table .provider-cell {
    white-space: nowrap;
  }
}
