/* =========================================================
   LLM Proxy — Admin Dashboard
   Dark theme, sidebar layout, SPA navigation
   ========================================================= */

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-input: #21262d;
  --bg-sidebar: #0d1117;
  --border: #30363d;
  --border-light: #21262d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #484f58;
  --green: #3fb950;
  --green-bg: rgba(63, 185, 80, 0.15);
  --yellow: #d29922;
  --yellow-bg: rgba(210, 153, 34, 0.15);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, 0.15);
  --blue: #58a6ff;
  --blue-bg: rgba(88, 166, 255, 0.12);
  --purple: #bc8cff;
  --purple-bg: rgba(188, 140, 255, 0.12);
  --orange: #f0883e;
  --sidebar-w: 220px;
  --radius: 8px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  --transition: 0.2s ease;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
}

/* ==========================================================
   SIDEBAR
   ========================================================== */

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 1.4rem;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
  color: var(--text);
  background: rgba(88, 166, 255, 0.08);
  border-left-color: var(--blue);
}

.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.nav-count {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-muted);
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ==========================================================
   MOBILE HEADER
   ========================================================== */

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 90;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  align-items: center;
  gap: 12px;
}

.hamburger {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
}

.mobile-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.mobile-status {
  margin-left: auto;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 95;
}

/* ==========================================================
   MAIN CONTENT
   ========================================================== */

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 28px 32px;
  max-width: 1200px;
  min-height: 100vh;
}

/* ==========================================================
   PAGE SYSTEM
   ========================================================== */

.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-header h1 small {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ==========================================================
   STAT CARDS (Dashboard)
   ========================================================== */

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

.stat-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ==========================================================
   HEALTH BAR
   ========================================================== */

.health-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 24px;
}

.health-segments {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.segment {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
}

.segment .count { font-size: 1.15rem; font-weight: 700; }
.segment.available { background: var(--green-bg); color: var(--green); }
.segment.cooldown { background: var(--yellow-bg); color: var(--yellow); }
.segment.disabled { background: var(--red-bg); color: var(--red); }

/* ==========================================================
   DASHBOARD — TOKEN LIST
   ========================================================== */

.dash-token-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dash-token-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.dash-token-row .token-label { font-weight: 600; flex: 1; }

.dash-token-row .util-mini {
  width: 60px;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.dash-token-row .util-mini-fill {
  height: 100%;
  border-radius: 3px;
}

/* ==========================================================
   SECTIONS & HEADINGS
   ========================================================== */

section { margin-bottom: 28px; }

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================================
   DOT (status indicator)
   ========================================================== */

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  display: inline-block;
  flex-shrink: 0;
}

.dot.healthy { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.degraded { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.dot.unavailable { background: var(--red); box-shadow: 0 0 6px var(--red); }

/* ==========================================================
   TOKEN GRID
   ========================================================== */

.token-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.token-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--transition);
}

.token-card:hover { border-color: #444c56; }

.token-card.available-true { border-left: 3px solid var(--green); }
.token-card.available-false.enabled-true { border-left: 3px solid var(--yellow); }
.token-card.enabled-false { border-left: 3px solid var(--red); opacity: 0.7; }

.token-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.token-label { font-weight: 600; font-size: 0.95rem; }

.token-badges { display: flex; gap: 6px; align-items: center; }

.token-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.token-meta span {
  background: var(--bg-input);
  padding: 2px 7px;
  border-radius: 4px;
}

/* Proxy info within token card */
.proxy-section {
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.proxy-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  flex-wrap: wrap;
}

.proxy-info .label { color: var(--text-muted); font-weight: 500; }
.proxy-info .value { color: var(--text); font-family: var(--mono); font-size: 0.73rem; word-break: break-all; }
.proxy-health.healthy { color: var(--green); }
.proxy-health.unhealthy { color: var(--red); }

.proxy-form {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.proxy-form-actions { display: flex; gap: 6px; margin-top: 6px; }

/* Utilization bars */
.util-bars { margin-bottom: 10px; }
.util-bar { margin-bottom: 5px; }

.util-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.util-bar-track {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.util-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.util-bar-fill.green { background: var(--green); }
.util-bar-fill.yellow { background: var(--yellow); }
.util-bar-fill.red { background: var(--red); }

/* Token details & actions */
.token-details {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.token-details div { margin-bottom: 2px; }
.token-details .label { color: var(--text-muted); }
.token-details .value { color: var(--text); }

.token-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
}

/* ==========================================================
   BADGES
   ========================================================== */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-available { background: var(--green-bg); color: var(--green); }
.badge-cooldown { background: var(--yellow-bg); color: var(--yellow); }
.badge-disabled { background: var(--red-bg); color: var(--red); }
.badge-type { background: var(--blue-bg); color: var(--blue); }
.badge-location { background: var(--purple-bg); color: var(--purple); font-size: 0.68rem; padding: 1px 6px; }
.badge-anthropic { background: rgba(240, 136, 62, 0.15); color: var(--orange); }
.badge-openai { background: var(--green-bg); color: var(--green); }
.badge-vertex { background: var(--blue-bg); color: var(--blue); }

/* ==========================================================
   PROXY PAGE
   ========================================================== */

/* Summary */
.proxy-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.proxy-summary-stat {
  text-align: center;
  min-width: 60px;
}

.proxy-summary-stat .proxy-summary-value {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.proxy-summary-stat .proxy-summary-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.proxy-summary-stat.available .proxy-summary-value { color: var(--green); }
.proxy-summary-stat.assigned .proxy-summary-value { color: var(--blue); }

.proxy-summary-countries {
  flex: 1;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  font-size: 0.78rem;
}

.country-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-input);
  border-radius: 12px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.filter-btn {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.filter-btn:hover { color: var(--text); border-color: var(--text-dim); }
.filter-btn.active { background: var(--blue-bg); color: var(--blue); border-color: var(--blue); }

/* Proxy status badges */
.proxy-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
}

.proxy-status.available { background: var(--green-bg); color: var(--green); }
.proxy-status.assigned { background: var(--blue-bg); color: var(--blue); }
.proxy-status.disabled { background: var(--bg-input); color: var(--text-muted); }

/* Proxy table actions */
.proxy-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.proxy-assign-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.73rem;
  padding: 4px 6px;
  max-width: 130px;
}

.proxy-assign-select:focus { outline: none; border-color: var(--blue); }

/* Import form */
.import-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.import-form textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  resize: vertical;
  margin: 8px 0;
}

.import-form textarea:focus { outline: none; border-color: var(--blue); }

/* ==========================================================
   STICKY SESSIONS
   ========================================================== */

.sticky-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.sticky-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.sticky-stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sticky-stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ==========================================================
   SETTINGS PAGE
   ========================================================== */

.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}


.info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.82rem;
}

.info-row:last-child { border-bottom: none; }
.info-row .label { color: var(--text-muted); }
.info-row .value { color: var(--text); font-family: var(--mono); }

/* ==========================================================
   COLLAPSIBLE PANELS
   ========================================================== */

.collapsible-panel {
  margin-bottom: 16px;
  transition: all var(--transition);
}

.collapsible-panel.hidden { display: none; }

/* ==========================================================
   BUTTONS
   ========================================================== */

.btn {
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover { background: var(--border); }

.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { opacity: 0.85; }

.btn-danger { color: var(--red); border-color: rgba(248, 81, 73, 0.4); }
.btn-danger:hover { background: var(--red-bg); }

.btn-sm { padding: 4px 10px; font-size: 0.73rem; }

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

/* ==========================================================
   FORMS
   ========================================================== */

.add-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.form-group {
  flex: 1;
  min-width: 150px;
}

.form-group.full { flex-basis: 100%; }

.form-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.form-group textarea { resize: vertical; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--blue);
}

/* ==========================================================
   TABLES
   ========================================================== */

.table-wrap {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  font-family: var(--mono);
  font-size: 0.76rem;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* Status badges in tables */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.73rem;
  font-family: var(--mono);
}

.status-ok { background: var(--green-bg); color: var(--green); }
.status-rate-limit { background: var(--yellow-bg); color: var(--yellow); }
.status-client-error { background: var(--red-bg); color: var(--red); }
.status-server-error { background: var(--red-bg); color: var(--red); font-weight: 700; }

.request-row.has-error { cursor: pointer; }
.request-row.has-error:hover td { background: rgba(248, 81, 73, 0.04); }

.detail-row td { padding: 0 !important; }

.error-detail {
  padding: 10px 12px;
  background: var(--red-bg);
  color: var(--red);
  font-family: var(--mono);
  font-size: 0.73rem;
  white-space: pre-wrap;
  word-break: break-all;
}

.error-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--red);
}

/* ==========================================================
   UTILITY CLASSES
   ========================================================== */

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-red { color: var(--red); }
.text-sm { font-size: 0.78em; }
code { font-family: var(--mono); font-size: 0.88em; }

.empty-state {
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  padding: 20px;
  font-size: 0.82rem;
}

/* ==========================================================
   RESPONSIVE — MOBILE
   ========================================================== */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close { display: block; }

  .sidebar-overlay.active { display: block; }

  .mobile-header {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: 60px 14px 20px;
  }

  .token-grid { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; }
  .form-group { min-width: 100%; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .proxy-summary { flex-direction: column; align-items: flex-start; }
  .proxy-summary-countries { justify-content: flex-start; }
}

@media (max-width: 480px) {
  .stat-cards { grid-template-columns: 1fr; }
}

/* --- New: observability upgrades --- */

.text-green { color: var(--green); }
.text-yellow { color: var(--yellow); }

.compact-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.compact-table th { text-align: left; padding: 6px 10px; color: var(--text-muted); font-weight: 500; border-bottom: 1px solid var(--border); }
.compact-table td { padding: 6px 10px; border-bottom: 1px solid var(--border-light); }
.compact-table tr:hover { background: var(--bg-input); }

.identity-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 24px; }
.identity-grid .info-row { display: flex; justify-content: space-between; padding: 3px 0; }
.identity-grid .label { color: var(--text-muted); font-size: 0.85rem; }
.identity-grid .value { font-size: 0.85rem; font-family: var(--font-mono, monospace); }
