@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;600;700;800&display=swap');

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { cursor: pointer; border: none; background: none; font: inherit; }
select { font: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ── Design tokens ── */
:root {
  --bg:                 #100f0e;
  --panel:              #191716;
  --panel-hi:           #2b2827;
  --text:               #f5f3f2;
  --text-70:            rgba(245,243,242,0.65);
  --text-60:            rgba(245,243,242,0.60);
  --text-55:            rgba(245,243,242,0.55);
  --text-45:            rgba(245,243,242,0.45);
  --text-40:            rgba(245,243,242,0.40);
  --text-35:            rgba(245,243,242,0.35);
  --text-30:            rgba(245,243,242,0.30);
  --text-28:            rgba(245,243,242,0.28);
  --line:               rgba(245,243,242,0.07);
  --line-strong:        rgba(245,243,242,0.10);
  --control:            rgba(245,243,242,0.05);
  --control-border:     rgba(245,243,242,0.09);
  --control-hover:      rgba(245,243,242,0.13);
  --row-line:           rgba(245,243,242,0.06);
  --accent:             #ff6a4f;
  --accent-hover:       #ff8368;
  --accent-grad:        linear-gradient(160deg,#ff6a4f,#c62f14);
  --accent-soft-bg:     rgba(255,106,79,0.12);
  --accent-soft-border: rgba(255,106,79,0.30);
}

/* ── Base ── */
html {
  background: var(--bg);
  color: var(--text);
  font-family: 'Archivo', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { background: var(--bg); min-height: 100vh; }

/* ── Page layout ── */
.page { padding: 36px 44px 72px; }
.content { max-width: 1340px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.header-left { display: flex; align-items: center; gap: 12px; }

.logo-tile {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.logo-tile svg { width: 19px; height: 19px; stroke: #100f0e; stroke-width: 2.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.header-titles { display: flex; flex-direction: column; gap: 1px; }
.page-title { font-size: 20px; font-weight: 800; letter-spacing: -0.015em; line-height: 1.2; }
.page-subtitle { font-size: 12.5px; color: var(--text-55); }

.header-right { display: flex; align-items: center; gap: 10px; }

/* Status pill */
.status-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 13px;
  background: var(--control);
  border-radius: 999px;
  font-size: 12px; color: var(--text-55);
  white-space: nowrap;
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #25b877;
  flex-shrink: 0;
}

/* Buttons */
.btn-ghost {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px;
  background: var(--control);
  border: 1px solid var(--control-border);
  border-radius: 11px;
  font-size: 13.5px; font-weight: 600;
  color: var(--text);
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--control-hover); }
.btn-ghost svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.btn-accent {
  display: flex; align-items: center; gap: 7px;
  padding: 10px 15px;
  background: var(--accent);
  border-radius: 11px;
  font-size: 13.5px; font-weight: 700;
  color: #100f0e;
  transition: background 0.15s;
}
.btn-accent:hover { background: var(--accent-hover); }
.btn-accent svg { width: 15px; height: 15px; stroke: #100f0e; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.btn-round {
  width: 32px; height: 32px;
  border-radius: 999px;
  background: var(--control);
  border: 1px solid var(--control-border);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-round:hover:not(:disabled) { background: var(--control-hover); }
.btn-round:disabled { opacity: 0.35; cursor: default; }
.btn-round svg { width: 14px; height: 14px; stroke: var(--text); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  padding: 12px 14px;
  background: var(--panel);
  border-radius: 16px;
  border: 1px solid var(--line);
}

.chip {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  background: var(--control);
  border: 1px solid var(--control-border);
  border-radius: 999px;
  font-size: 13.5px;
  white-space: nowrap;
}

.chip-label { font-size: 11.5px; color: var(--text-55); }
.chip-value { font-size: 13.5px; font-weight: 700; color: var(--accent-hover); }

/* API key chip — accent tinted */
.chip-apikey {
  background: var(--accent-soft-bg);
  border-color: var(--accent-soft-border);
}

/* Chip with select */
.chip-select { position: relative; }
.chip-select select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13.5px; font-weight: 700;
  padding: 0 18px 0 0;
  cursor: pointer;
  outline: none;
}
.chip-select select option {
  background: #1d1b1a;
  color: #f5f3f2;
}
.chip-select .chevron {
  position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
  pointer-events: none;
  width: 13px; height: 13px;
  stroke: var(--text-55); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round;
}
/* Push select text so chevron doesn't overlap */
.chip-select select { padding-right: 22px; }

.chip-calendar {
  display: flex; align-items: center; gap: 6px;
}
.chip-calendar .cal-icon {
  width: 14px; height: 14px;
  stroke: var(--text-55); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

/* Vertical divider */
.divider-v {
  width: 1px; height: 22px;
  background: var(--line-strong);
  margin: 0 3px;
  flex-shrink: 0;
}

.period-group { display: flex; align-items: center; gap: 6px; }

.range-text {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--text-45);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Alert banner ── */
.banner {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  background: var(--accent-soft-bg);
  border: 1px solid rgba(255,106,79,0.28);
  border-radius: 14px;
}
.banner[hidden] { display: none; }
.banner-icon {
  width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px;
  stroke: var(--accent-hover); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.banner-title { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
.banner-body { font-size: 13px; color: var(--text-70); }

/* ── Cards ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px 20px;
  display: flex; flex-direction: column; gap: 10px;
}

.card-header { display: flex; align-items: center; gap: 7px; }
.card-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.card-label { font-size: 12.5px; color: var(--text-55); }

.card-metric {
  font-size: 31px; font-weight: 800;
  letter-spacing: -0.025em; line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.card-note { font-size: 11.5px; color: var(--text-35); }

/* ── Chart panel ── */
.chart-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  position: relative;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px 22px 4px;
}

.panel-title { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.panel-subtitle { font-size: 12.5px; color: var(--text-45); margin-top: 2px; }

/* View toggle (Chart / Table) */
.view-toggle {
  display: flex;
  background: var(--control);
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}
.view-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border-radius: 9px;
  font-size: 13px; font-weight: 600;
  color: var(--text-70);
  transition: background 0.15s, color 0.15s;
}
.view-btn svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.view-btn.active {
  background: var(--text);
  color: #100f0e;
}
.view-btn.active svg { stroke: #100f0e; }

/* Panel body */
.panel-body { padding: 18px 22px 10px; }

/* ── Chart area ── */
.chart-area {
  display: flex;
  flex-direction: row;
  gap: 8px;
  height: 290px;
}

.y-axis {
  width: 54px;
  min-width: 54px;
  height: 290px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: right;
  padding-right: 4px;
  flex-shrink: 0;
}

.y-label {
  font-size: 11px;
  color: var(--text-35);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.plot-wrapper {
  flex: 1;
  min-width: 0;
  height: 290px;
  position: relative;
  overflow: hidden;
}

.gridlines {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  z-index: 0;
}
.grid-line { width: 100%; height: 1px; background: var(--line); }

.bars-row {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: row;
  gap: 5px;
  z-index: 1;
}

.bar-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
  border-radius: 8px;
  transition: background 0.12s;
  cursor: default;
}
.bar-col.hovered { background: rgba(245,243,242,0.06); }

.bar-seg { flex-shrink: 0; }

/* X-axis */
.x-axis {
  display: flex;
  flex-direction: row;
  gap: 5px;
  padding: 6px 0 0;
  /* Left margin to align with bars (y-axis width + gap) */
  margin-left: calc(54px + 8px);
}
.x-label {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-35);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  line-height: 1;
}
.x-label.invisible { visibility: hidden; }

/* ── Tooltip ── */
.chart-tooltip {
  position: absolute;
  top: 14px;
  z-index: 3;
  pointer-events: none;
  min-width: 230px;
  background: var(--panel-hi);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.55);
}
.chart-tooltip[hidden] { display: none; }
.tooltip-date { font-size: 12.5px; color: var(--text-55); margin-bottom: 8px; }
.tooltip-rows { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; }
.tooltip-row { display: flex; align-items: center; gap: 8px; }
.tooltip-swatch {
  width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0;
}
.tooltip-value {
  font-size: 13px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 76px;
}
.tooltip-label { font-size: 13px; color: var(--text-60); white-space: nowrap; }
.tooltip-divider { height: 1px; background: var(--line); margin: 4px 0; }
.tooltip-total-row { display: flex; align-items: center; gap: 8px; }
.tooltip-spacer { width: 9px; flex-shrink: 0; }
.tooltip-total-value {
  font-size: 13px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 76px;
}
.tooltip-total-label { font-size: 13px; color: var(--text-60); }

/* ── Empty state ── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  padding: 64px 24px 72px;
  text-align: center;
}
.empty-state[hidden] { display: none; }
.empty-icon {
  width: 30px; height: 30px; stroke: var(--text-35);
  stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round;
  margin-bottom: 16px;
}
.empty-title { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.empty-body { font-size: 13.5px; color: var(--text-45); max-width: 46ch; }

/* ── Table ── */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; }
.data-table th {
  font-size: 11.5px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-40);
  padding: 11px 12px;
  text-align: right;
  white-space: nowrap;
}
.data-table th:first-child { text-align: left; }
.data-table td {
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  padding: 11px 12px;
  text-align: right;
  border-top: 1px solid var(--row-line);
}
.data-table td:first-child, .data-table td:last-child { font-weight: 800; }
.data-table td:first-child { text-align: left; }
.data-table td.zero { color: rgba(245,243,242,0.3); }

/* ── Legend ── */
.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
}
.legend-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.legend-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 13px;
  background: var(--control);
  border-radius: 999px;
  cursor: pointer;
  font-size: 11.5px;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  user-select: none;
}
.legend-chip:hover { background: var(--control-hover); }
.legend-chip.hidden {
  background: transparent;
  opacity: 0.4;
}
.legend-swatch {
  width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0;
}
.legend-chip.hidden .legend-swatch { background: transparent !important; }

.legend-total { font-weight: 800; font-variant-numeric: tabular-nums; margin-left: 4px; }
.legend-hint { font-size: 11.5px; color: var(--text-30); white-space: nowrap; }

/* ── Loading overlay ── */
.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(16,15,14,0.72);
  backdrop-filter: blur(2px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  z-index: 10;
}
.loading-overlay[hidden] { display: none; }

.spinner {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(245,243,242,0.15);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { font-size: 13px; color: var(--text-70); }

/* ── Footer ── */
.footer {
  display: flex; flex-wrap: wrap; gap: 26px;
  font-size: 11.5px; color: var(--text-28);
}

/* ── Summary-card dot colours (moved off inline style for a strict CSP) ── */
.card-dot-total  { background: #ff6a4f; }
.card-dot-token  { background: #3d7ff2; }
.card-dot-search { background: #25b877; }
.card-dot-exec   { background: rgba(245,243,242,0.35); }

/* ── Header user menu (logout / admin) ── */
.user-menu { display: flex; align-items: center; gap: 8px; }
.user-logout { display: inline-flex; margin: 0; }
a.btn-ghost { text-decoration: none; display: inline-flex; align-items: center; }

/* ── Hidden utility ── */
[hidden] { display: none !important; }
