/* ===================================================================
   DS Usage Dashboard — ClickHouse-inspired design system
   Tokens from DESIGN.md
   =================================================================== */

:root {
  --primary: #faff69;
  --primary-active: #e6eb52;
  --primary-disabled: #3a3a1f;
  --ink: #ffffff;
  --body: #cccccc;
  --body-strong: #e6e6e6;
  --muted: #888888;
  --muted-soft: #5a5a5a;
  --hairline: #2a2a2a;
  --hairline-strong: #3a3a3a;
  --canvas: #0a0a0a;
  --surface-soft: #121212;
  --surface-card: #1a1a1a;
  --surface-elevated: #242424;
  --on-primary: #0a0a0a;
  --on-dark: #ffffff;
  --emerald: #22c55e;
  --rose: #ef4444;
  --blue: #3b82f6;
  --yellow: #faff69;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  --space-xxs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-xxl: 48px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--canvas);
  color: var(--body);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- Typography ---- */
.title-sm  { font-size: 16px; font-weight: 600; line-height: 1.4; color: var(--body-strong); }
.title-md  { font-size: 18px; font-weight: 600; line-height: 1.4; }
.caption   { font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--muted); }
.caption-uppercase { font-size: 12px; font-weight: 600; line-height: 1.4; letter-spacing: 1.5px; text-transform: uppercase; }
kbd {
  font-family: var(--font-mono);
  background: var(--surface-elevated);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  padding: 2px 7px;
  font-size: 12px;
  color: var(--body-strong);
}

/* ---- Layout ---- */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

/* ---- Top bar ---- */
.top-bar {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--hairline);
}
.top-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}
.top-bar-left { display: flex; align-items: center; gap: var(--space-sm); flex-shrink: 0; }
.top-bar-center { flex: 1; display: flex; justify-content: center; }
.top-bar-right { display: flex; align-items: center; gap: var(--space-sm); flex-shrink: 0; }

.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.5px;
}
.logo-accent { color: var(--primary); }

.badge-pill {
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-card);
  color: var(--emerald);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--hairline);
}

/* ---- Filter group ---- */
.filter-group {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}
.filter-input {
  height: 36px;
  background: var(--surface-card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  padding: 0 var(--space-xs);
  outline: none;
  transition: border-color .15s;
}
.month-input { width: 48px; }
.year-input { width: 72px; }
.filter-input:focus { border-color: var(--primary); }
.filter-input-wide {
  width: 140px;
  height: 36px;
  background: var(--surface-card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 0 10px;
  outline: none;
  transition: border-color .15s;
}
.filter-input-wide:focus { border-color: var(--primary); }
.filter-input-wide::placeholder { color: var(--muted-soft); }
.filter-sep { color: var(--muted); font-size: 16px; font-weight: 600; }

/* ---- Buttons ---- */
.btn-primary {
  height: 36px;
  padding: 0 16px;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--primary-active); }

.btn-secondary {
  height: 36px;
  padding: 0 14px;
  background: var(--surface-card);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--surface-elevated); }
.btn-icon { padding: 0 10px; font-size: 14px; }
#btn-currency { width: 78px; text-align: center; }

/* ---- Presets ---- */
.presets-bar {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--hairline);
}
.preset-btn {
  height: 30px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.preset-btn:hover { color: var(--ink); border-color: var(--hairline-strong); }
.preset-btn.active { background: var(--surface-card); color: var(--primary); border-color: var(--primary); }
.preset-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted-soft);
  font-family: var(--font-mono);
}

/* ---- Main ---- */
.main-content {
  flex: 1;
  padding: var(--space-lg) 0;
}

/* ---- Summary cards ---- */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.stat-card {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
  line-height: 1.1;
}

/* ---- View tabs ---- */
.view-tabs {
  display: flex;
  align-items: center;
  gap: var(--space-xxs);
  margin-bottom: var(--space-md);
}
.view-tab {
  height: 34px;
  padding: 0 16px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.view-tab:hover { color: var(--ink); }
.view-tab.active { background: var(--surface-card); color: var(--ink); }
.view-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted-soft);
  font-family: var(--font-mono);
}

.view-panel { display: none; }
.view-panel.active { display: block; }

/* ---- Charts ---- */
.chart-section {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { width: 100%; height: 200px; display: block; }

/* ---- Bar list (used in model chart, claude chart, token breakdown) ---- */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.bar-label {
  width: 180px;
  font-size: 13px;
  font-weight: 500;
  color: var(--body);
  text-align: right;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  flex: 1;
  height: 24px;
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  transition: width .4s ease;
  min-width: 2px;
}
.bar-fill.yellow { background: var(--primary); }
.bar-fill.green  { background: var(--emerald); }
.bar-fill.blue   { background: var(--blue); }
.bar-fill.rose   { background: var(--rose); }
.bar-fill.cyan   { background: #22d3ee; }
.bar-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--body-strong);
  width: 80px;
  text-align: right;
  flex-shrink: 0;
  font-family: var(--font-mono);
}

/* ---- Stats table ---- */
.stats-table-wrap { overflow-x: auto; }
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.stats-table th {
  text-align: left;
  padding: var(--space-xs) var(--space-sm);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
.stats-table td {
  padding: var(--space-xs) var(--space-sm);
  border-bottom: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--body);
  white-space: nowrap;
}
.stats-table td:first-child {
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--body-strong);
}
.stats-table .num { text-align: right; }
.stats-table .total { font-weight: 600; color: var(--ink); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface-card);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  max-width: 420px;
  width: 90%;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}
.modal-body {}
.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-elevated); color: var(--ink); }

.shortcut-grid { display: flex; flex-direction: column; gap: var(--space-xs); }
.shortcut-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: 14px;
  color: var(--body);
}
.shortcut-row kbd { min-width: 40px; text-align: center; }

/* ---- Loading ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,10,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--hairline-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Footer ---- */
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) 0 var(--space-lg);
  border-top: 1px solid var(--hairline);
}

/* ---- Hidden ---- */
.hidden { display: none !important; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .app-layout { padding: 0 var(--space-md); }
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .top-bar-inner { flex-wrap: wrap; }
  .top-bar-center { order: 3; width: 100%; justify-content: stretch; }
  .filter-group { width: 100%; }
  .filter-input-wide { flex: 1; }
  .bar-label { width: 100px; font-size: 12px; }
}

/* ---- Auth ---- */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--canvas);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.auth-box {
  background: var(--surface-card);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  width: 100%; max-width: 380px;
}
.auth-header { text-align: center; margin-bottom: var(--space-lg); }
.auth-header .logo-text { font-size: 28px; }
.auth-tabs { display: flex; gap: 0; margin-bottom: var(--space-lg); border-bottom: 1px solid var(--hairline); }
.auth-tab {
  flex: 1; height: 36px; background: transparent; border: none; color: var(--muted);
  font-family: var(--font-sans); font-size: 14px; font-weight: 500; cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .15s;
}
.auth-tab:hover { color: var(--ink); }
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-form { display: flex; flex-direction: column; gap: var(--space-sm); }
.auth-input {
  height: 40px; background: var(--surface-soft); border: 1px solid var(--hairline);
  border-radius: var(--radius-md); color: var(--ink); font-family: var(--font-sans);
  font-size: 14px; padding: 0 14px; outline: none; transition: border-color .15s;
}
.auth-input:focus { border-color: var(--primary); }
.auth-input::placeholder { color: var(--muted-soft); }
.auth-submit { height: 40px; margin-top: var(--space-xs); }
.auth-error {
  font-size: 13px; color: var(--rose); padding: 8px; background: #2a1010;
  border-radius: var(--radius-sm); text-align: center;
}

/* ---- Calendar ---- */
.cal-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}
.cal-nav { display: flex; align-items: center; gap: var(--space-xs); }
.cal-nav-btn {
  height: 30px;
  padding: 0 10px;
  background: var(--surface-card);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.cal-nav-btn:hover { background: var(--surface-elevated); }
.cal-nav-btn.active { border-color: var(--primary); color: var(--primary); }
.cal-sub-btn { font-size: 12px; }
.cal-nav-label {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  min-width: 160px;
  text-align: center;
  letter-spacing: -0.3px;
}
.cal-summary {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 100%;
}
.cal-month-grid .day-name {
  font-size: 11px;
  color: var(--muted-soft);
  text-align: center;
  padding: 4px 0;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.cal-month-cell {
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: outline .1s, background .15s;
  color: var(--body);
  line-height: 1.2;
  padding: 8px 2px;
  min-height: 56px;
}
.cal-month-cell .cal-cell-cost {
  font-size: 10px;
  font-family: var(--font-mono);
  opacity: 0.9;
  line-height: 1;
  margin-top: 3px;
}
.cal-month-cell:hover { outline: 1px solid var(--primary); }
.cal-month-cell.other-month { color: var(--muted-soft); }
.cal-month-cell.level-0 { background: var(--surface-soft); }
.cal-month-cell.level-1 { background: #1a2a1a; }
.cal-month-cell.level-2 { background: #2a4a2a; }
.cal-month-cell.level-3 { background: #3a5a1f; color: var(--ink); }
.cal-month-cell.level-4 { background: var(--primary); color: var(--on-primary); font-weight: 700; }
.cal-month-cell.today { outline: 1px solid var(--muted); outline-offset: -1px; }

/* Yearly heatmap (GitHub-style) */
.cal-yearly-wrap { overflow-x: auto; }
.cal-yearly {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
}
.cal-yearly-row {
  display: flex;
  align-items: center;
  gap: 3px;
}
.cal-yearly-label {
  width: 26px;
  font-size: 10px;
  color: var(--muted-soft);
  text-align: center;
  flex-shrink: 0;
}
.cal-yearly .cal-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}
.cal-yearly .month-label {
  font-size: 9px;
  color: var(--muted-soft);
  padding-left: 26px;
  margin-bottom: 1px;
  display: flex;
  gap: 0;
}
.cal-yearly .month-label span {
  width: 12px;
  margin-right: 3px;
  text-align: center;
}

.cal-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--space-sm);
  font-size: 11px;
  color: var(--muted);
}
.cal-legend .cal-cell { width: 12px; height: 12px; cursor: default; }
.cal-legend .cal-cell:hover { outline: none; }

.cal-detail {
  font-size: 13px;
  color: var(--body);
  line-height: 1.8;
}
.cal-detail .model-tag {
  display: inline-block;
  font-size: 12px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  margin-right: 4px;
  font-family: var(--font-mono);
  color: var(--ink);
}
