:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #eef2f3;
  --ink: #162126;
  --muted: #66757d;
  --line: #dce3e6;
  --teal: #087e72;
  --teal-soft: #dff3ef;
  --blue: #2563a6;
  --blue-soft: #e4effa;
  --amber: #a76305;
  --amber-soft: #faefd8;
  --red: #b93832;
  --red-soft: #f9e7e5;
  --shadow: 0 8px 24px rgba(22, 33, 38, 0.07);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

button, input { font: inherit; }

button { letter-spacing: 0; }

.shell {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(220, 227, 230, 0.88);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.topbar-inner {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.brand-name { font-size: 14px; font-weight: 760; line-height: 1.2; }
.brand-source { margin-top: 3px; color: var(--muted); font-size: 11px; }

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

.connection, .status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a8b2b7;
  box-shadow: 0 0 0 3px rgba(168, 178, 183, 0.16);
}

.connection.online .status-dot,
.status-badge.active .status-dot {
  background: #119a75;
  box-shadow: 0 0 0 3px rgba(17, 154, 117, 0.15);
}

.connection.error .status-dot,
.status-badge.error .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(185, 56, 50, 0.14);
}

.auto-refresh { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; cursor: pointer; }
.auto-refresh input { position: absolute; opacity: 0; pointer-events: none; }

.toggle {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: #cbd4d8;
  transition: background 160ms ease;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(22, 33, 38, 0.25);
  transition: transform 160ms ease;
}

.auto-refresh input:checked + .toggle { background: var(--teal); }
.auto-refresh input:checked + .toggle::after { transform: translateX(14px); }
.auto-refresh input:focus-visible + .toggle { outline: 2px solid var(--blue); outline-offset: 2px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.icon-button:hover { border-color: #aebbc0; background: var(--surface-muted); }
.icon-button:disabled { cursor: wait; opacity: 0.6; }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.loading svg { animation: spin 800ms linear infinite; }

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

.overview-band { padding: 34px 0 38px; background: var(--surface); border-bottom: 1px solid var(--line); }
.section-kicker-row, .section-heading-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.section-kicker { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.timestamp { color: var(--muted); font-size: 12px; }

.overview-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.18fr) minmax(440px, 1fr);
  gap: 48px;
  margin-top: 24px;
  align-items: stretch;
}

.quota-primary { min-width: 0; padding-right: 8px; }
.quota-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.eyebrow, .metric-label, .summary-label { color: var(--muted); font-size: 12px; font-weight: 620; }

.quota-value {
  min-height: 66px;
  margin-top: 4px;
  font-size: 52px;
  line-height: 1.18;
  font-weight: 770;
  font-variant-numeric: tabular-nums;
}

.status-badge {
  margin-top: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
}

.quota-track {
  height: 9px;
  margin-top: 18px;
  overflow: hidden;
  border-radius: 5px;
  background: #e6ecee;
}

.quota-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 500ms cubic-bezier(.2,.8,.2,1), background 200ms ease;
}

.quota-labels { display: flex; justify-content: space-between; gap: 20px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.quota-labels strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.metric { position: relative; min-height: 118px; padding: 20px 22px; background: var(--surface); }
.metric:nth-child(odd) { border-right: 1px solid var(--line); }
.metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }

.metric-icon {
  position: absolute;
  top: 18px;
  right: 18px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
}

.metric-icon svg { width: 15px; height: 15px; }
.metric-icon.teal { color: var(--teal); background: var(--teal-soft); }
.metric-icon.blue { color: var(--blue); background: var(--blue-soft); }
.metric-icon.amber { color: var(--amber); background: var(--amber-soft); }
.metric-icon.red { color: var(--red); background: var(--red-soft); }
.metric-value { margin-top: 16px; font-size: 25px; line-height: 1; font-weight: 730; font-variant-numeric: tabular-nums; }

.stats-band { padding: 34px 0 30px; border-bottom: 1px solid var(--line); }
h1, h2, p { margin: 0; }
h1 { font-size: 23px; line-height: 1.25; }
h2 { font-size: 17px; line-height: 1.3; }
.section-heading-row p, .panel-heading p { margin-top: 5px; color: var(--muted); font-size: 12px; }
.section-heading-row.compact { align-items: center; }

.segmented { display: grid; grid-template-columns: repeat(3, 64px); padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: #e9eef0; }
.segmented button { height: 30px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(22, 33, 38, 0.12); font-weight: 700; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 24px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.summary-item { min-width: 0; padding: 20px 22px; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-item strong { display: block; margin-top: 9px; font-size: 25px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-note { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.summary-item.highlight { background: #f1faf8; }
.summary-item.highlight strong { color: var(--teal); }

.charts-band { padding: 30px 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.chart-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 22px; }
.chart-panel, .catalog-panel { min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.chart-panel { padding: 21px 22px 16px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.panel-heading > svg { width: 18px; height: 18px; color: var(--muted); }
.chart-wrap { position: relative; height: 280px; margin-top: 17px; }

.table-band, .daily-band { padding: 30px 0; border-bottom: 1px solid var(--line); }
.daily-band { background: var(--surface); }
.table-scroll { margin-top: 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.mobile-detail-list { display: none; }
table { width: 100%; min-width: 920px; border-collapse: collapse; font-size: 12px; }
th, td { height: 46px; padding: 0 16px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { height: 40px; background: #edf1f3; color: var(--muted); font-size: 11px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7f9fa; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.model-name { display: flex; align-items: center; gap: 9px; font-weight: 650; }
.model-dot { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: var(--teal); }
.cost-actual { color: var(--teal); font-weight: 700; }

.catalog-band { padding: 32px 0 46px; }
.catalog-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(240px, .72fr); gap: 20px; align-items: stretch; }
.catalog-panel { overflow: hidden; }
.catalog-panel > .panel-heading { min-height: 80px; padding: 21px 22px 17px; }
.model-catalog { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; border-top: 1px solid var(--line); overflow: hidden; background: var(--surface); }
.catalog-item { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 43px; padding: 0 14px; border-bottom: 1px solid var(--line); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.catalog-item:nth-child(odd) { border-right: 1px solid var(--line); }
.catalog-item:nth-last-child(-n+2) { border-bottom: 0; }
.catalog-item svg { flex: 0 0 auto; width: 14px; height: 14px; color: var(--blue); }
.catalog-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.billing-panel { padding: 0; }
.billing-list { margin: 0; padding: 0 22px 18px; border-top: 1px solid var(--line); }
.billing-list > div { display: flex; justify-content: space-between; gap: 20px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.billing-list > div:last-child { border-bottom: 0; padding-bottom: 0; }
.billing-list dt { color: var(--muted); font-size: 12px; }
.billing-list dd { margin: 0; max-width: 60%; text-align: right; font-size: 12px; font-weight: 700; overflow-wrap: anywhere; }

.error-banner {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(560px, calc(100% - 32px));
  padding: 12px 14px;
  transform: translateX(-50%);
  border: 1px solid #e7b7b3;
  border-radius: 8px;
  background: #fff5f4;
  color: #792c28;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.error-banner[hidden] { display: none; }
.error-banner > svg { flex: 0 0 auto; width: 17px; height: 17px; }
.error-banner span { flex: 1; }
.error-banner button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: inherit; font-weight: 700; cursor: pointer; }
.error-banner button svg { width: 14px; height: 14px; }

body.loading main { opacity: 0.58; }
main { transition: opacity 160ms ease; }

@media (max-width: 920px) {
  .overview-grid { grid-template-columns: 1fr; gap: 28px; }
  .chart-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-item:nth-child(2) { border-right: 0; }
  .summary-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 620px) {
  .shell { width: min(100% - 28px, 1240px); }
  .topbar-inner { min-height: 62px; }
  .connection span:last-child, .auto-refresh span:last-child { display: none; }
  .top-actions { gap: 11px; }
  .overview-band { padding: 26px 0 30px; }
  .section-kicker-row { align-items: center; }
  .timestamp { max-width: 180px; text-align: right; }
  .quota-value { min-height: 53px; font-size: 40px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 108px; padding: 17px; }
  .metric-icon { top: 14px; right: 14px; }
  .metric-value { margin-top: 15px; font-size: 21px; }
  .section-heading-row { align-items: center; }
  .section-heading-row h1 { font-size: 20px; }
  .section-heading-row p { display: none; }
  .segmented { grid-template-columns: repeat(3, 52px); }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-item { padding: 17px 15px; }
  .summary-item strong { font-size: 20px; }
  .chart-panel { padding: 18px 15px 13px; }
  .chart-wrap { height: 248px; }
  .table-scroll { display: none; }
  .mobile-detail-list { display: block; margin-top: 17px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface); }
  .mobile-record { border-bottom: 1px solid var(--line); }
  .mobile-record:last-child { border-bottom: 0; }
  .mobile-record summary { display: grid; grid-template-columns: minmax(0, 1fr) auto 22px; align-items: center; gap: 10px; min-height: 64px; padding: 10px 2px; cursor: pointer; list-style: none; }
  .mobile-record summary::-webkit-details-marker { display: none; }
  .mobile-record summary::after { content: "+"; grid-column: 3; grid-row: 1; width: 22px; color: var(--muted); font-size: 19px; text-align: right; }
  .mobile-record[open] summary::after { content: "-"; }
  .mobile-record-title { min-width: 0; padding-right: 4px; }
  .mobile-record-title strong { display: block; overflow: hidden; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-record-title span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
  .mobile-record-cost { grid-column: 2; grid-row: 1; color: var(--teal); font-size: 13px; font-weight: 750; font-variant-numeric: tabular-nums; }
  .mobile-record-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin: 0 0 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--line); }
  .mobile-record-grid div { min-width: 0; padding: 10px 11px; background: var(--bg); }
  .mobile-record-grid span { display: block; color: var(--muted); font-size: 10px; }
  .mobile-record-grid strong { display: block; margin-top: 4px; overflow: hidden; font-size: 12px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-daily-row { padding: 14px 2px; border-bottom: 1px solid var(--line); }
  .mobile-daily-row:last-child { border-bottom: 0; }
  .mobile-daily-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
  .mobile-daily-head strong { font-size: 13px; }
  .mobile-daily-head span { color: var(--teal); font-size: 14px; font-weight: 750; font-variant-numeric: tabular-nums; }
  .mobile-daily-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
  .mobile-daily-metrics div { min-width: 0; }
  .mobile-daily-metrics span { display: block; color: var(--muted); font-size: 10px; }
  .mobile-daily-metrics strong { display: block; margin-top: 3px; overflow: hidden; font-size: 11px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
  .model-catalog { grid-template-columns: 1fr; }
  .catalog-grid { grid-template-columns: 1fr; }
  .catalog-item:nth-child(odd) { border-right: 0; }
  .catalog-item:nth-last-child(2) { border-bottom: 1px solid var(--line); }
  .catalog-item:last-child { border-bottom: 0; }
}

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