:root {
  color-scheme: dark;
  --bg: #09090b;
  --bg-raised: #0f0f12;
  --surface: #111113;
  --surface-strong: #18181b;
  --surface-soft: #18181b;
  --border: #27272a;
  --border-strong: #3f3f46;
  --text: #fafafa;
  --muted: #71717a;
  --muted-strong: #a1a1aa;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --violet: #a78bfa;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.24);
  --track: rgba(255, 255, 255, 0.055);
  --subtle: rgba(255, 255, 255, 0.035);
  --status-green: #86efac;
  --status-amber: #fcd34d;
  --status-red: #fca5a5;
  --chart-text: #72809a;
  --chart-grid: rgba(255, 255, 255, 0.06);
  --backdrop: rgba(9, 9, 11, 0.84);
  --modal-shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
  --focus-ring: rgba(161, 161, 170, 0.12);
  --button-bg: #fafafa;
  --button-text: #18181b;
  --button-border: #e4e4e7;
  --error-text: #ff8c9d;
  --radius-xl: 14px;
  --radius-lg: 12px;
  --radius-md: 8px;
  font-family: Inter, "IBM Plex Sans Thai", "Noto Sans Thai", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fafafa;
  --bg-raised: #f4f4f5;
  --surface: #ffffff;
  --surface-strong: #f4f4f5;
  --surface-soft: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --muted: #71717a;
  --muted-strong: #52525b;
  --shadow: 0 1px 2px rgba(24, 24, 27, 0.06);
  --track: rgba(24, 24, 27, 0.075);
  --subtle: rgba(24, 24, 27, 0.035);
  --status-green: #15803d;
  --status-amber: #b45309;
  --status-red: #b91c1c;
  --chart-text: #71717a;
  --chart-grid: rgba(24, 24, 27, 0.08);
  --backdrop: rgba(244, 244, 245, 0.86);
  --modal-shadow: 0 18px 50px rgba(24, 24, 27, 0.14);
  --focus-ring: rgba(24, 24, 27, 0.12);
  --button-bg: #18181b;
  --button-text: #fafafa;
  --button-border: #18181b;
  --error-text: #b91c1c;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  transition: color 220ms ease, background-color 220ms ease;
}

button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.ambient {
  display: none;
}

.ambient-one { top: 15%; right: -170px; background: #6e5cf4; }
.ambient-two { bottom: 5%; left: -220px; background: #0bbf93; }

.topbar {
  width: min(1440px, calc(100% - 64px));
  min-height: 62px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--text);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: 0.02em; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; }

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

.theme-chip {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted-strong);
  background: var(--surface);
  font-size: 11px;
  white-space: nowrap;
}

.theme-icon { width: 14px; text-align: center; color: var(--status-amber); font-size: 14px; line-height: 1; }
.theme-chip[data-theme="dark"] .theme-icon { color: #c4b5fd; }

.live-chip {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-strong);
  background: transparent;
  font-size: 12px;
}

.live-chip i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: none;
}

.icon-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.icon-button:hover { border-color: var(--border-strong); background: var(--surface-strong); }
.icon-button:active { transform: translateY(1px); }
.icon-button:disabled { opacity: 0.55; cursor: wait; }
.icon-button.refreshing span:first-child { animation: spin 1s linear infinite; }

main { width: min(1440px, calc(100% - 64px)); margin: 0 auto; padding: 24px 0 64px; }

.hero {
  min-height: 112px;
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(560px, 1.15fr);
  gap: 30px;
  align-items: center;
}

.eyebrow, .section-kicker {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.hero h1 {
  max-width: 620px;
  margin: 0;
  font-size: clamp(26px, 3vw, 42px);
  line-height: 1.05;
  letter-spacing: -0.04em;
  font-weight: 760;
}

.hero h1 span {
  color: var(--muted-strong);
}

.hero-description {
  max-width: 590px;
  margin: 9px 0 0;
  color: var(--muted-strong);
  font-size: 12px;
  line-height: 1.55;
}

.last-updated { margin: 8px 0 0; color: var(--muted); font-size: 10px; }

.summary-panel {
  min-height: 90px;
  padding: 0;
  border: 0;
  border-radius: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
  align-items: center;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.summary-item { min-width: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.summary-label { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em; }
.summary-item strong { display: block; margin-top: 7px; font-size: 25px; line-height: 1; letter-spacing: -0.04em; }
.summary-item small { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-divider { display: none; }
.summary-wide strong { font-size: 20px; }

.section-block { margin-top: 26px; }

.section-heading, .panel-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 14px;
}

.section-heading h2, .panel-heading h2 { margin: 0; font-size: 22px; line-height: 1.2; letter-spacing: -0.025em; }
.section-heading .section-kicker, .panel-heading .section-kicker { margin-bottom: 8px; }

.legend { display: flex; flex-wrap: wrap; gap: 18px; color: var(--muted); font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-dot.healthy { background: var(--green); }
.legend-dot.warning { background: var(--amber); }
.legend-dot.critical { background: var(--red); }

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

.provider-card, .loading-card {
  grid-column: span 2;
  min-height: 330px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.loading-card {
  background: linear-gradient(100deg, var(--surface) 20%, var(--surface-strong) 40%, var(--surface) 60%);
  background-size: 220% 100%;
  animation: shimmer 1.6s infinite linear;
}

.provider-card {
  position: relative;
  padding: 20px;
  overflow: hidden;
  transition: transform 180ms ease, border-color 180ms ease;
}

.provider-card::after {
  display: none;
}

.provider-card:hover { transform: none; border-color: var(--border-strong); }

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

.provider-glyph {
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--surface-strong);
  font-weight: 800;
  font-size: 15px;
  overflow: hidden;
}

.provider-logo { width: 22px; height: 22px; display: block; object-fit: contain; }
.provider-glyph[data-provider="codex"] { background: #fafafa; }
.provider-glyph[data-provider="claude"] { background: #f2e5dc; }
.provider-glyph[data-provider="grok"] { background: #050505; }
.provider-glyph[data-provider="grok"] .provider-logo { width: 28px; height: 28px; }
.provider-glyph[data-provider="sakana"] { background: #fafafa; }
.provider-glyph[data-provider="sakana"] .provider-logo { width: 24px; height: 24px; }
.provider-glyph[data-provider="cursor"] { background: #14120b; }

.provider-title { min-width: 0; flex: 1; }
.provider-title h3 { margin: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.provider-title p { margin: 4px 0 0; color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-pill {
  min-width: 54px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-pill { border: 1px solid var(--border); }
.status-pill.healthy { color: var(--status-green); background: rgba(34, 197, 94, 0.08); }
.status-pill.warning { color: var(--status-amber); background: rgba(245, 158, 11, 0.08); }
.status-pill.danger, .status-pill.critical { color: var(--status-red); background: rgba(239, 68, 68, 0.08); }
.status-pill.unknown { color: var(--muted-strong); background: var(--surface-strong); }

.primary-usage {
  margin: 24px 0 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.usage-ring {
  width: auto;
  height: auto;
  border-radius: 0;
  display: block;
  background: none;
  box-shadow: none;
}

.usage-ring::before {
  display: none;
}

.usage-ring-content { position: relative; z-index: 1; text-align: left; }
.usage-ring-content strong { display: block; font-size: 34px; line-height: 1; letter-spacing: -0.05em; }
.usage-ring-content span { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; }

.primary-copy p { margin: 0 0 7px; color: var(--muted); font-size: 10px; }
.primary-copy strong { display: block; font-size: 15px; line-height: 1.35; }
.primary-copy small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; line-height: 1.4; }

.metric-list { display: grid; gap: 13px; }
.metric-row { min-width: 0; }
.metric-meta { margin-bottom: 7px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted-strong); font-size: 10px; }
.metric-meta span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-meta strong { color: var(--text); font-size: 10px; }
.metric-track { height: 5px; border-radius: 999px; background: var(--track); overflow: hidden; }
.metric-fill { height: 100%; border-radius: inherit; background: var(--provider-accent); }
.primary-progress { margin-bottom: 18px; height: 6px; background: var(--surface-strong); }

.provider-foot {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 18px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 9px;
}

.provider-foot span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.setup-state { min-height: 270px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
.setup-state strong { margin-top: 14px; font-size: 19px; }
.setup-state p { margin: 10px 0 0; color: var(--muted-strong); font-size: 12px; line-height: 1.65; }
.setup-symbol { width: 48px; height: 48px; border: 1px dashed var(--border-strong); border-radius: 10px; display: grid; place-items: center; color: var(--muted-strong); background: var(--surface-strong); font-size: 20px; }

.analytics-grid { margin-top: 22px; display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(320px, 0.7fr); gap: 16px; }

.panel {
  min-height: 400px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading { align-items: center; }
.panel-heading.compact { margin-bottom: 18px; }

.segmented { padding: 3px; border: 1px solid var(--border); border-radius: 8px; display: flex; background: var(--bg); }
.segmented button { min-height: 28px; padding: 0 10px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-size: 10px; cursor: pointer; }
.segmented button.active { color: var(--text); background: var(--surface-strong); }

.chart-wrap { position: relative; width: 100%; height: 255px; }
#history-chart { width: 100%; height: 100%; display: block; }
.chart-empty { position: absolute; inset: 0; margin: 0; display: none; place-items: center; color: var(--muted); font-size: 12px; text-align: center; }
.chart-empty.visible { display: grid; }
.chart-legend { min-height: 26px; margin-top: 12px; display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 2px; border-radius: 999px; }

.attention-count { min-width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 9px; display: grid; place-items: center; color: var(--muted-strong); background: var(--subtle); font-size: 11px; }
.attention-list { display: grid; gap: 10px; }
.attention-item { padding: 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.attention-item-head { display: flex; align-items: center; gap: 9px; }
.attention-item-head i { width: 8px; height: 8px; border-radius: 50%; background: var(--item-accent); box-shadow: 0 0 0 5px color-mix(in srgb, var(--item-accent) 10%, transparent); }
.attention-item-head strong { flex: 1; font-size: 12px; }
.attention-item-head span { color: var(--muted); font-size: 9px; }
.attention-item p { margin: 9px 0 0 17px; color: var(--muted-strong); font-size: 10px; line-height: 1.55; }
.attention-empty { min-height: 225px; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; }

footer { width: min(1440px, calc(100% - 64px)); min-height: 72px; margin: 0 auto; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 24px; color: var(--muted); font-size: 10px; }

.auth-backdrop { position: fixed; z-index: 50; inset: 0; padding: 24px; display: grid; place-items: center; background: var(--backdrop); backdrop-filter: blur(12px); }
.auth-card { width: min(420px, 100%); padding: 30px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--modal-shadow); }
.auth-lock { width: 44px; height: 44px; margin-bottom: 20px; border: 1px solid var(--border-strong); border-radius: 9px; display: grid; place-items: center; color: var(--muted-strong); background: var(--surface-strong); font-size: 20px; }
.auth-card h2 { margin: 0; font-size: 28px; }
.auth-card > p:not(.section-kicker):not(.auth-error) { margin: 12px 0 24px; color: var(--muted-strong); font-size: 13px; line-height: 1.6; }
.auth-card label { display: block; margin-bottom: 8px; color: var(--muted-strong); font-size: 11px; }
.auth-card input { width: 100%; height: 42px; padding: 0 13px; border: 1px solid var(--border-strong); border-radius: 8px; color: var(--text); outline: 0; background: var(--bg); }
.auth-card input:focus { border-color: var(--muted-strong); box-shadow: 0 0 0 3px var(--focus-ring); }
.auth-card .auth-remember { margin: 13px 0 2px; display: flex; align-items: center; gap: 9px; color: var(--muted-strong); cursor: pointer; }
.auth-card .auth-remember input { width: 16px; height: 16px; margin: 0; accent-color: var(--text); }
.auth-card .auth-remember span { font-size: 12px; }
.primary-button { width: 100%; height: 42px; margin-top: 14px; border: 1px solid var(--button-border); border-radius: 8px; color: var(--button-text); background: var(--button-bg); font-weight: 700; cursor: pointer; }
.auth-error { margin: 10px 0 0; color: var(--error-text); font-size: 11px; }
.hidden { display: none !important; }

@keyframes shimmer { to { background-position: -120% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .hero { grid-template-columns: minmax(0, 0.72fr) minmax(500px, 1.28fr); gap: 20px; }
  .provider-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .provider-card, .loading-card { grid-column: span 2; }
  .provider-card:nth-child(4), .provider-card:nth-child(5), .loading-card:nth-child(4), .loading-card:nth-child(5) { grid-column: span 3; }
}

@media (max-width: 820px) {
  .topbar, main, footer { width: min(100% - 34px, 680px); }
  main { padding-top: 18px; }
  .hero { min-height: auto; grid-template-columns: 1fr; gap: 14px; }
  .summary-panel { width: 100%; grid-template-columns: 1fr 1fr 1.2fr; gap: 8px; }
  .summary-wide { grid-column: auto; padding-top: 0; margin-top: 0; border-top: 0; }
  .provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .provider-card, .loading-card, .provider-card:nth-child(4), .provider-card:nth-child(5), .loading-card:nth-child(4), .loading-card:nth-child(5) { grid-column: span 1; }
  .analytics-grid { grid-template-columns: 1fr; }
  .attention-panel { min-height: 320px; }
  footer { padding: 22px 0; align-items: flex-start; flex-direction: column; }
}

@media (max-width: 580px) {
  .topbar { min-height: 58px; }
  .live-chip { display: none; }
  .theme-chip { width: 34px; padding: 0; justify-content: center; }
  .theme-label { display: none; }
  .button-label { display: none; }
  .icon-button { width: 38px; padding: 0; justify-content: center; }
  .brand small { display: none; }
  .hero .eyebrow { display: none; }
  .hero h1 { font-size: clamp(24px, 8vw, 32px); }
  .hero-description { margin-top: 6px; font-size: 11px; line-height: 1.45; }
  .last-updated { margin-top: 5px; font-size: 9px; }
  .summary-panel { min-height: 74px; padding: 0; border-radius: 0; gap: 6px; }
  .summary-item { padding: 10px 8px; border-radius: 9px; }
  .summary-label { font-size: 7px; letter-spacing: .06em; }
  .summary-item strong { margin-top: 5px; font-size: 18px; }
  .summary-item small { margin-top: 4px; font-size: 7px; }
  .summary-wide strong { font-size: 15px; }
  .summary-divider { height: 36px; }
  .section-block { margin-top: 22px; }
  .section-heading { align-items: center; flex-direction: row; margin-bottom: 11px; }
  .section-heading .section-kicker, .legend { display: none; }
  .section-heading h2 { font-size: 18px; }
  .provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: stretch; }
  .provider-card, .loading-card, .provider-card:nth-child(4), .provider-card:nth-child(5), .loading-card:nth-child(4), .loading-card:nth-child(5) { grid-column: span 1; }
  .provider-card, .loading-card { min-height: 312px; border-radius: 10px; }
  .provider-card { padding: 12px; }
  .provider-card::after { width: 110px; height: 110px; top: -72px; right: -58px; }
  .provider-head { gap: 6px; }
  .provider-glyph { width: 28px; height: 28px; border-radius: 9px; font-size: 12px; }
  .provider-logo { width: 17px; height: 17px; }
  .provider-glyph[data-provider="grok"] .provider-logo { width: 22px; height: 22px; }
  .provider-glyph[data-provider="sakana"] .provider-logo { width: 19px; height: 19px; }
  .provider-title h3 { font-size: 11px; }
  .provider-title p { display: none; }
  .status-pill { min-width: 0; min-height: 20px; padding: 0 6px; font-size: 6px; letter-spacing: .05em; }
  .primary-usage { margin: 14px 0 12px; grid-template-columns: 1fr; justify-items: center; gap: 7px; text-align: center; }
  .usage-ring { width: auto; height: auto; box-shadow: none; }
  .usage-ring-content { text-align: center; }
  .usage-ring-content strong { font-size: 25px; }
  .usage-ring-content span { margin-top: 3px; font-size: 7px; }
  .primary-copy p { margin-bottom: 4px; font-size: 8px; }
  .primary-copy strong { font-size: 12px; }
  .primary-copy small { margin-top: 4px; font-size: 8px; }
  .metric-list { gap: 9px; }
  .metric-meta { margin-bottom: 5px; gap: 5px; font-size: 8px; }
  .metric-meta strong { font-size: 8px; }
  .metric-track { height: 4px; }
  .primary-progress { margin-bottom: 12px; height: 5px; }
  .provider-foot { left: 12px; right: 12px; bottom: 10px; padding-top: 9px; gap: 5px; font-size: 7px; }
  .setup-state { min-height: 220px; align-items: center; text-align: center; }
  .setup-state strong { margin-top: 10px; font-size: 13px; }
  .setup-state p { margin-top: 7px; font-size: 9px; line-height: 1.45; }
  .setup-symbol { width: 42px; height: 42px; border-radius: 13px; font-size: 18px; }
  .panel { padding: 19px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .panel-heading.compact { flex-direction: row; }
  .segmented { align-self: stretch; }
  .segmented button { flex: 1; }
}

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