*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-alt: #11161d;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, 0.2);
  --green: #3fb950;
  --green-soft: rgba(63, 185, 80, 0.2);
  --red: #f85149;
  --red-soft: rgba(248, 81, 73, 0.2);
  --orange: #d29922;
  --orange-soft: rgba(210, 153, 34, 0.2);
  --purple: #a371f7;
  --cyan: #39c5cf;
  --ttft: #f778ba;
  --teal: #2fbf9f;
  --radius: 10px;
}

html {
  font-size: 15px;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
}

.hover-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 16px));
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(13, 17, 23, 0.96);
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  font-size: 0.82rem;
  line-height: 1.4;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.08s ease, transform 0.08s ease;
}

.hover-tooltip-visible {
  opacity: 1;
  transform: translateY(0);
}

.hover-tooltip > div + div {
  margin-top: 0.2rem;
}

.hover-tooltip-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.1rem;
}

.hover-tooltip-badge {
  display: inline-block;
  width: fit-content;
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(88, 166, 255, 0.35);
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  margin-bottom: 0.1rem;
}

.hover-tooltip-metric {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.hover-tooltip-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
  font-size: 0.78rem;
  color: #c9d1d9;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 0.28rem 0.38rem;
}

.hover-tooltip-muted {
  color: var(--text2);
}

nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 700;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 1rem;
  margin-left: auto;
}

.nav-links a {
  color: var(--text2);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
  background: var(--border);
}

main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
}

footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  color: var(--text2);
  font-size: 0.8rem;
  text-align: center;
}

h1 {
  margin-bottom: 0.35rem;
  font-size: 1.65rem;
}

h2 {
  font-size: 1.15rem;
  color: var(--text2);
}

p {
  margin: 0;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.page-subtitle,
.section-note,
.muted,
.refresh-indicator,
.chart-note,
.card-note {
  color: var(--text2);
}

.page-subtitle,
.section-note,
.chart-note,
.card-note,
.muted {
  font-size: 0.9rem;
}

.refresh-indicator {
  font-size: 0.8rem;
  white-space: nowrap;
}

.section {
  margin-bottom: 2rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.range-picker {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.range-option {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text2);
  background: var(--surface);
  font-size: 0.85rem;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.range-option:hover,
.range-option-active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.card,
.stat-card,
table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card {
  padding: 1rem 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

.card-note {
  margin-top: 0.6rem;
}

.card-table {
  margin: 0.9rem 0;
}

.error-card {
  margin-bottom: 0.75rem;
  padding: 1rem;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  background: #1c0f0f;
  color: var(--red);
}

.badge,
.plan-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-ok,
.plan-badge {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-warn {
  background: var(--orange-soft);
  color: var(--orange);
}

.quota-grid,
.stats-grid,
.viz-grid {
  display: grid;
  gap: 0.9rem;
}

.quota-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.quota-grid > .card:only-child {
  max-width: 320px;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin: 0.9rem 0;
}

.stats-grid-compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.viz-grid {
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  margin-bottom: 0.9rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem;
}

.stat-card-label {
  color: var(--text2);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card-value {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.stat-card-hint {
  color: var(--text2);
  font-size: 0.85rem;
}

.stat-card-good {
  border-color: rgba(63, 185, 80, 0.35);
}

.stat-card-warn {
  border-color: rgba(210, 153, 34, 0.35);
}

.stat-card-bad {
  border-color: rgba(248, 81, 73, 0.35);
}

.stat-card-muted,
.stat-card-info {
  border-color: var(--border);
}

.quota-details {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.15rem 0;
}

.stat-label {
  color: var(--text2);
  font-size: 0.85rem;
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.stat-value.highlight {
  color: var(--accent);
  font-weight: 700;
}

.progress-bar {
  height: 8px;
  margin-top: 0.8rem;
  overflow: hidden;
  background: var(--border);
  border-radius: 999px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s;
  width: var(--w, 0%);
}

.progress-warn {
  background: var(--orange);
}

.legend-row,
.chart-footer,
.model-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.legend-row {
  margin-bottom: 0.75rem;
  color: var(--text2);
  font-size: 0.82rem;
}

.chart-footer,
.model-meta {
  margin-top: 0.85rem;
  color: var(--text2);
  font-size: 0.82rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot-input,
.mini-bar-input {
  background: var(--accent);
}

.legend-dot-cached,
.mini-bar-cached,
.mini-bar-rate {
  background: var(--cyan);
}

.legend-dot-output,
.mini-bar-output {
  background: var(--purple);
}

.legend-dot-avg,
.mini-bar-avg,
.mini-bar-success {
  background: var(--green);
}

.legend-dot-p95,
.mini-bar-p95,
.mini-bar-error {
  background: var(--orange);
}

.legend-dot-ttft,
.mini-bar-ttft {
  background: var(--ttft);
}

.mini-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  min-height: 180px;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.mini-bar-wrap {
  flex: 1;
  min-width: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}

.mini-bar-wrap-idle {
  opacity: 0.45;
}

.bucket-strip {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: repeat(var(--bucket-count, 24), minmax(0, 1fr));
  grid-auto-columns: minmax(0, 1fr);
  gap: 0.4rem;
  align-items: end;
  overflow-x: hidden;
  padding-bottom: 0.4rem;
  min-height: 225px;
}

.bucket-column {
  display: grid;
  grid-template-rows: auto minmax(160px, 1fr) auto;
  gap: 0.35rem;
  min-width: 28px;
}

.bucket-column-idle {
  opacity: 0.35;
}

.bucket-value,
.bucket-label {
  color: var(--text2);
  font-size: 0.7rem;
  line-height: 1.2;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.bucket-label {
  min-height: 1.7em;
  word-break: normal;
}

.bucket-bar {
  align-self: end;
  width: 72%;
  justify-self: center;
  min-height: 10px;
  border-radius: 8px 8px 4px 4px;
  background: var(--surface-alt);
  overflow: hidden;
  height: var(--h, 0%);
}

.bucket-bar-stack {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: var(--h, 0%);
}

.bucket-segment {
  width: 100%;
  height: var(--h, 0%);
}

.bucket-column,
.bucket-segment,
.stat-card[data-tooltip] {
  cursor: default;
}

.bucket-segment-input {
  background: var(--accent);
}

.bucket-segment-cached {
  background: var(--cyan);
}

.bucket-segment-output {
  background: var(--purple);
}

.mini-bar,
.mini-bar-pair {
  width: 100%;
  max-width: 18px;
  border-radius: 999px 999px 4px 4px;
}

.mini-bar {
  min-height: 2px;
}

.mini-bar-split,
.mini-bar-stack {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  background: var(--surface-alt);
}

.mini-bar-split > div,
.mini-bar-stack > div {
  width: 100%;
}

.mini-bar-pair {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  height: 100%;
}

.mini-bar-latency {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(210, 153, 34, 0.95) 0%, rgba(210, 153, 34, 0.5) 100%);
}

.mini-bar-ttft {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  min-height: 2px;
  opacity: 0.95;
}

.mini-bar-pair .mini-bar {
  width: 7px;
}

.mini-bar-label,
.mini-bar-value {
  color: var(--text2);
  font-size: 0.72rem;
  text-align: center;
}

.mini-bar-label {
  line-height: 1.2;
  max-width: 48px;
  word-break: break-word;
}

.mini-bar-value {
  font-variant-numeric: tabular-nums;
}

.model-list {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.model-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
}

.model-list-more {
  margin-top: 0.9rem;
}

.model-row {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.model-bars {
  display: grid;
  gap: 0.55rem;
}

.model-bar-label {
  margin-bottom: 0.22rem;
  color: var(--text2);
  font-size: 0.8rem;
}

.model-row-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.model-name {
  font-weight: 600;
}

.model-share {
  color: var(--text2);
  font-size: 0.82rem;
  text-align: right;
}

.model-progress {
  margin-top: 0;
}

.progress-fill-model-token {
  background: var(--purple);
  width: var(--w, 0%);
}

.progress-fill-model-request {
  background: var(--teal);
  width: var(--w, 0%);
}

.model-more-toggle {
  margin-top: 1rem;
}

.link-button {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

.link-button:hover {
  text-decoration: underline;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

th {
  padding: 0.65rem 0.75rem;
  background: var(--border);
  color: var(--text2);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
}

td {
  padding: 0.58rem 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

tr:hover td {
  background: rgba(88, 166, 255, 0.04);
}

.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 220px);
}

.login-container .card {
  width: 100%;
  max-width: 380px;
}

.login-container h1 {
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--text2);
  font-size: 0.85rem;
}

.form-group input {
  width: 100%;
  padding: 0.58rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

button[type="submit"] {
  width: 100%;
  padding: 0.65rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: opacity 0.15s;
}

button[type="submit"]:hover {
  opacity: 0.88;
}

button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error {
  margin-top: 0.5rem;
  color: var(--red);
  font-size: 0.85rem;
}

@media (max-width: 760px) {
  nav {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .nav-links {
    width: 100%;
    margin-left: 0;
  }

  .page-header,
  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .range-picker {
    width: 100%;
  }

  main {
    margin: 1rem auto;
    padding: 0 1rem;
  }

  .mini-bar-wrap {
    min-width: 28px;
  }

  .quota-grid,
  .stats-grid,
  .viz-grid {
    grid-template-columns: 1fr;
  }

  .bucket-strip {
    grid-template-columns: repeat(var(--bucket-count, 24), minmax(0, 1fr));
    grid-auto-columns: minmax(0, 1fr);
    min-height: 210px;
  }

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

.section-loading {
  min-height: 120px;
}

.loading-skeleton {
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.loading-skeleton-text {
  display: block;
  color: var(--text2);
  font-size: 0.9rem;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* --- Model speed line graph --- */

.model-speed-chart-wrap {
  overflow-x: auto;
  padding: 1rem 0;
}

.model-speed-svg {
  width: 100%;
  max-height: 300px;
  font-family: var(--font, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
}

.model-speed-line {
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.model-speed-dot {
  opacity: 0.7;
  pointer-events: none;
  transition: opacity 0.15s, r 0.15s;
}

.model-speed-hit {
  pointer-events: all;
  cursor: default;
}

.model-speed-hit:hover ~ .model-speed-dot {
  opacity: 1;
  r: 5;
}

.model-speed-ylabel {
  fill: var(--text2);
  font-size: 0.78rem;
  dominant-baseline: middle;
}

.model-speed-xlabel {
  fill: var(--text2);
  font-size: 0.72rem;
  text-anchor: middle;
  dominant-baseline: hanging;
}

.model-speed-grid {
  stroke: var(--border);
  stroke-width: 0.5;
  stroke-dasharray: 4 2;
}

.model-speed-legend {
  padding: 0.5rem 0;
}

.model-speed-legend-dot {
  /* background set via JS from data-color attribute (CSP: no inline styles) */
}

/* --- Help page --- */

.help-pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  margin: 0;
}

.help-markdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text);
  margin: 0;
}

.help-markdown h1,
.help-markdown h2,
.help-markdown h3 {
  color: var(--accent);
  margin: 1rem 0 0.5rem;
  font-weight: 600;
}

.help-markdown h1 { font-size: 1.4rem; }
.help-markdown h2 { font-size: 1.15rem; }
.help-markdown h3 { font-size: 1rem; }

.help-markdown p {
  margin: 0.5rem 0;
}

.help-markdown ul,
.help-markdown ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.help-markdown li {
  margin: 0.25rem 0;
}

.help-markdown code {
  background: var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.3rem;
  font-size: 0.85em;
  color: var(--text);
}

.help-markdown pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.8rem;
  margin: 0.75rem 0;
}

.help-markdown pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

.help-markdown strong {
  color: var(--text);
}

.help-markdown a {
  color: var(--accent);
  text-decoration: underline;
}

/* --- Credential box --- */

.credential-box {
  padding: 1rem;
  font-size: 0.85rem;
  line-height: 1.8;
}

.credential-box p {
  margin: 0.25rem 0;
}

.credential-box code {
  background: var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  font-size: 0.85em;
  color: var(--text);
}

.credential-box a {
  color: var(--accent);
  text-decoration: underline;
}

.copy-btn {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
}

/* --- Nav credentials --- */

.nav-credentials {
  font-size: 0.7rem;
  color: var(--text2);
  opacity: 0.7;
  padding: 0 0.5rem;
}
