/* ======================================================================
   GlideAPI — Admin Dashboard
   Dark-only ops console. Tokens from /DESIGN.md — do not invent values.
   ====================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design Tokens (DESIGN.md §1–§5) ────────────────────────────────── */
:root {
  --bg:             #07131b;
  --bg-subtle:      #0b1e29;
  --surface:        #102733;
  --surface-hover:  #15313e;
  --surface-raised: #183743;
  --border:         #234450;
  --border-strong:  #315b66;
  --text:           #e8f5f2;
  --text-secondary: #9bb8b2;
  --text-tertiary:  #66857f;

  --accent:         #2bb7a4;
  --accent-hover:   #239784;
  --success:        #22c55e;
  --warning:        #f59e0b;
  --danger:         #ef4444;

  --btn-primary-bg:    #e8f5f2;
  --btn-primary-text:  #07131b;
  --btn-primary-hover: #ffffff;

  --font-sans: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-pill: 999px;

  --shadow-border: 0 0 0 1px var(--border);
  --shadow-border-hover: 0 0 0 1px var(--border-strong);
  --shadow-modal: 0 0 0 1px var(--border), 0 8px 30px rgba(0, 0, 0, 0.35);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);

  color-scheme: dark;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 22px;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

svg { flex-shrink: 0; }

/* ── Shell ──────────────────────────────────────────────────────────── */
.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

.admin-workspace { min-width: 0; }

/* ── Sidebar (DESIGN.md §6 — 240px, bg-subtle, right hairline) ─────── */
.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  padding: 18px 12px;
  background:
    linear-gradient(180deg, rgba(43, 183, 164, 0.055), transparent 180px),
    var(--bg-subtle);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-brand {
  min-height: 48px;
  padding: 0 8px 12px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.logo-mark {
  width: 158px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-ai {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

/* Tab items: 36px, radius-sm, 16px lucide icons */
.admin-tabs {
  display: grid;
  align-content: start;
  gap: 2px;
}

.admin-tabs button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  text-align: left;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.admin-tabs button svg { color: var(--text-tertiary); transition: color 0.15s; }

.admin-tabs button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.admin-tabs button.active {
  background: linear-gradient(90deg, rgba(43, 183, 164, 0.16), var(--surface-hover));
  color: var(--text);
}
.admin-tabs button.active svg { color: var(--accent); }
.admin-tabs button.active::before {
  content: '';
  position: absolute;
  left: -12px;
  width: 3px;
  height: 18px;
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(43, 183, 164, 0.65);
}

.admin-tabs button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.sidebar-status {
  display: grid;
  gap: 8px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
}

.sidebar-status > span,
.admin-eyebrow {
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Status pill — pill shape is semantic for the runtime indicator */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--success) 12%, transparent);
  color: var(--success);
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  transition: background 0.15s, color 0.15s;
}
.status-pill.warn {
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  color: var(--warning);
}
.status-pill.err {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: currentColor;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* ── Top bar ────────────────────────────────────────────────────────── */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 19px clamp(24px, 3vw, 48px);
  background: rgba(7, 19, 27, 0.88);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

.top-bar h1 {
  color: var(--text);
  font-size: 25px;
  font-weight: 650;
  line-height: 32px;
  letter-spacing: -0.035em;
  margin-top: 2px;
}

.top-bar .subtitle {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 20px;
}

/* ── Grid layout ────────────────────────────────────────────────────── */
.grid {
  max-width: 1380px;
  margin: 0 auto;
  padding: 30px clamp(24px, 3vw, 48px) 72px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

[data-admin-tab] { display: none; }
[data-admin-tab].active { display: grid; }
.panel[data-admin-tab].active { display: block; }

.stat-row.active {
  grid-column: 1 / -1;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.wide,
.panel.wide { grid-column: 1 / -1; }

/* ── Stat cards ─────────────────────────────────────────────────────── */
.stat-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(24, 55, 67, 0.92), var(--surface) 58%);
  box-shadow: var(--shadow-border), 0 12px 28px rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.stat-card::after {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: linear-gradient(var(--accent), transparent 78%);
  opacity: 0.8;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-border-hover), 0 18px 34px rgba(0, 0, 0, 0.18);
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  line-height: 32px;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-trend {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* ── Panels ─────────────────────────────────────────────────────────── */
.panel {
  grid-column: span 6;
  background: linear-gradient(145deg, rgba(24, 55, 67, 0.56), var(--surface) 56%);
  box-shadow: var(--shadow-border), 0 18px 38px rgba(0, 0, 0, 0.11);
  border-radius: 10px;
  padding: 22px;
  min-width: 0;
  transition: box-shadow 0.18s ease;
}
.panel:hover { box-shadow: var(--shadow-border-hover), 0 20px 42px rgba(0, 0, 0, 0.14); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.customer-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.customer-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(330px, 32vw);
  height: 34px;
  padding: 0 10px;
  color: var(--text-tertiary);
  background: var(--bg);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-sm);
  transition: box-shadow 0.15s, color 0.15s;
}
.customer-search:focus-within {
  color: var(--accent);
  box-shadow: var(--focus-ring);
}
.customer-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font: 500 12px var(--font-sans);
}
.customer-search input::placeholder { color: var(--text-tertiary); }
.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-subtle);
  box-shadow: var(--shadow-border);
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.chip.live {
  background: color-mix(in srgb, var(--success) 12%, transparent);
  box-shadow: none;
  color: var(--success);
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--success);
  animation: pulse 1.5s ease-in-out infinite;
}

/* ── Charts ─────────────────────────────────────────────────────────── */
.chart-container {
  position: relative;
  width: 100%;
  height: 240px;
}
.chart-container canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* ── Buttons (DESIGN.md §6) ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}
.btn-primary:hover { background: var(--btn-primary-hover); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-hover); }

.btn-danger {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

.compact-select {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.compact-select:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* ── Key list — dense divided rows ──────────────────────────────────── */
.key-list {
  display: flex;
  flex-direction: column;
}

.key-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.key-row:last-child { border-bottom: 0; }
.key-row:hover { background: var(--surface-hover); }

.key-badge {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}
.key-badge.active   { background: var(--success); }
.key-badge.cooldown { background: var(--warning); }
.key-badge.disabled { background: var(--danger); }

.key-info { flex: 1; min-width: 0; }
.key-name {
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.key-sub {
  margin-top: 2px;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.key-note {
  margin-top: 4px;
  color: var(--warning);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
}

.key-pool-toggle {
  margin-top: 4px;
  width: 100%;
  padding: 10px;
  background: transparent;
  box-shadow: var(--shadow-border);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.key-pool-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.key-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.key-fullrow {
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
  color: var(--text-secondary);
  word-break: break-all;
}

.key-actions { display: flex; gap: 6px; }

/* ── Badges / status tags (20px, radius-xs, 12% tint) ──────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  white-space: nowrap;
}
.tag-active {
  background: color-mix(in srgb, var(--success) 12%, transparent);
  color: var(--success);
}
.tag-cooldown {
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  color: var(--warning);
}
.tag-disabled {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

/* ── Customers ──────────────────────────────────────────────────────── */
.customer-card {
  border-bottom: 1px solid var(--border);
}
.customer-card:last-child { border-bottom: 0; }

.customer-main {
  display: grid;
  grid-template-columns: 10px minmax(240px, 1.4fr) repeat(3, minmax(88px, 0.42fr)) auto;
  align-items: center;
  gap: 16px;
  min-height: 44px;
  padding: 12px 4px;
  transition: background 0.15s;
}
.customer-main:hover { background: var(--surface-hover); }

.customer-identity { min-width: 0; }

.customer-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.customer-title strong,
.customer-email,

.customer-id {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-title strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}

.customer-email {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 16px;
}


.customer-id {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 16px;
}

.customer-stat span,
.customer-detail-grid span {
  display: block;
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 16px;
}

.customer-stat strong,
.customer-detail-grid strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}

.customer-stat strong.positive { color: var(--success); }
.customer-stat strong.empty { color: var(--danger); }

.customer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.customer-details {
  background: var(--bg-subtle);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 0 4px 12px;
}

.customer-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.customer-detail-grid > div {
  background: var(--surface);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-xs);
  padding: 12px;
}

.customer-sections {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.customer-section-title {
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.customer-mini-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-xs);
}

.customer-mini-row + .customer-mini-row { margin-top: 6px; }

.customer-mini-row strong,
.customer-mini-row span { display: block; }

.customer-mini-row strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
}

.customer-mini-row span {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 16px;
  word-break: break-word;
}

.customer-mini-meta {
  min-width: 130px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.customer-mini-meta .ok { color: var(--success); }
.customer-mini-meta .bad { color: var(--danger); }

.customer-empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 16px;
  padding: 12px;
}

/* ── Providers / models ─────────────────────────────────────────────── */
.provider-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.provider-card {
  background: var(--bg);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: box-shadow 0.15s;
}
.provider-card:hover { box-shadow: var(--shadow-border-hover); }

.provider-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 12px;
}

.provider-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.provider-toggle:hover { background: var(--surface-hover); color: var(--text); }
.provider-toggle svg { transition: transform 0.15s; }
.provider-card.open .provider-toggle svg { transform: rotate(90deg); }

.provider-info { flex: 1; min-width: 0; }
.provider-info strong {
  display: block;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}
.provider-info span {
  display: block;
  margin-top: 1px;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-actions,
.model-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.provider-models {
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  padding: 8px;
}

.model-empty {
  padding: 16px;
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 20px;
}

.model-table {
  display: flex;
  flex-direction: column;
}

.model-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 0.8fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.model-row:last-child { border-bottom: 0; }
.model-row:hover { background: var(--surface-hover); }

.model-main strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
}
.model-main span,
.model-price {
  display: block;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 18px;
}
.model-main code,
.fallback-summary code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}
.model-price {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.fallback-picker {
  display: grid;
  grid-template-columns: minmax(260px, 0.55fr) 1fr;
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}
.fallback-picker .form-group { margin-bottom: 0; }

.fallback-summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-sm);
}
.fallback-summary strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
}
.fallback-summary span {
  display: block;
  margin-top: 2px;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 16px;
}
.fallback-summary-actions { flex-shrink: 0; }

.modal-note {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 18px;
  padding: 12px;
  background: var(--bg);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-xs);
  margin-bottom: 16px;
}

/* ── Activity feed (live stream) ────────────────────────────────────── */
.activity-feed {
  display: flex;
  flex-direction: column;
  max-height: 360px;
  overflow-y: auto;
}
.activity-feed::-webkit-scrollbar { width: 4px; }
.activity-feed::-webkit-scrollbar-track { background: transparent; }
.activity-feed::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.activity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  line-height: 16px;
  animation: fadeIn 0.2s ease-out;
  transition: background 0.15s;
}
.activity-item:last-child { border-bottom: 0; }
.activity-item:hover { background: var(--surface-hover); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.act-time {
  color: var(--text-tertiary);
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  min-width: 52px;
  font-variant-numeric: tabular-nums;
}

.act-type {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-weight: 500;
  line-height: 16px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.act-type.stream   { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.act-type.request  { background: var(--bg-subtle); box-shadow: var(--shadow-border); color: var(--text-secondary); }
.act-type.failover { background: color-mix(in srgb, var(--warning) 12%, transparent); color: var(--warning); }
.act-type.error    { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.act-type.admin    { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.act-type.user     { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); }
.act-type.system   { background: var(--bg-subtle); box-shadow: var(--shadow-border); color: var(--text-secondary); }

.act-detail {
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 12px;
}
.act-tokens {
  color: var(--text);
  flex-shrink: 0;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ── Audit feed (system log) ────────────────────────────────────────── */
.audit-feed {
  display: flex;
  flex-direction: column;
  max-height: min(720px, calc(100vh - 260px));
  min-height: 420px;
  overflow-y: auto;
  padding: 2px 8px 2px 0;
}
.audit-feed::-webkit-scrollbar { width: 4px; }
.audit-feed::-webkit-scrollbar-track { background: transparent; }
.audit-feed::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.audit-row {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: 148px minmax(240px, 1fr) minmax(280px, 440px);
  gap: 18px;
  align-items: start;
  min-height: 74px;
  padding: 16px 12px 16px 14px;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid var(--border);
  transition: background 0.15s;
}
.audit-row:last-child { border-bottom: 0; }
.audit-row:hover { background: var(--surface-hover); }

.audit-row.admin  { border-left-color: var(--accent); }
.audit-row.user   { border-left-color: var(--success); }
.audit-row.system { border-left-color: var(--border-strong); }
.audit-row.error  { border-left-color: var(--danger); }

.audit-time strong,
.audit-time span { display: block; }

.audit-time strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
}

.audit-time span {
  margin-top: 3px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 15px;
  word-break: normal;
}

.audit-time {
  min-width: 0;
  overflow-wrap: anywhere;
}

.audit-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: visible;
}

.audit-title {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  min-width: 0;
}

.audit-title strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audit-sub {
  margin-top: 4px;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 18px;
  overflow-wrap: anywhere;
}

.audit-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.audit-details-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.audit-detail-chip {
  display: inline-grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  max-width: min(100%, 520px);
  min-height: 26px;
  padding: 5px 8px;
  background: var(--bg);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 15px;
}

.audit-detail-chip span {
  color: var(--text-tertiary);
  white-space: nowrap;
}

.audit-detail-chip strong {
  min-width: 0;
  max-width: 210px;
  overflow: hidden;
  color: var(--text-secondary);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audit-more {
  margin-top: 8px;
  width: 100%;
}

.audit-more summary {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  line-height: 16px;
}

.audit-more-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding: 8px;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-xs);
}

.audit-muted {
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 18px;
}

.inline-link {
  display: inline;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-underline-offset: 3px;
}
.inline-link:hover { color: var(--accent-hover); }

/* ── Modals (DESIGN.md §6) ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: overlayIn 0.15s ease-out;
}
@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface-raised);
  box-shadow: var(--shadow-modal);
  border-radius: var(--radius-md);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  animation: modalIn 0.15s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.98); }
  to   { opacity: 1; transform: scale(1); }
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 18px;
  font-weight: 600;
  line-height: 28px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.model-modal { max-width: 640px; }

.activity-modal {
  max-width: 640px;
  max-height: min(760px, calc(100vh - 32px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.modal-heading-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}
.modal-heading-row h3 { margin-bottom: 0; }

.modal-subtitle {
  margin-top: 4px;
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 20px;
}

.activity-profile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.activity-profile-grid > div,
.latest-error-box {
  background: var(--surface);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-xs);
  padding: 12px;
}

.activity-profile-grid span,
.latest-error-box span {
  display: block;
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 16px;
}

.activity-profile-grid strong,
.latest-error-box strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}

.latest-error-box {
  margin-bottom: 16px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--danger) 25%, transparent);
}

.latest-error-box p {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 18px;
}

.customer-audit-feed {
  max-height: none;
  min-height: 0;
}

/* Confirm dialog */
.confirm-modal {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 480px;
}
.confirm-modal h3 { margin-bottom: 6px; }
.confirm-modal p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 22px;
}
.confirm-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}
.confirm-modal .modal-actions {
  grid-column: 1 / -1;
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

/* ── Forms ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
  color: var(--text-secondary);
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-sans);
  line-height: 20px;
  outline: none;
  transition: border-color 0.15s;
}
.form-group textarea {
  height: auto;
  min-height: 72px;
  padding: 8px 12px;
}
.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-tertiary);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent);
}
.form-group input:focus-visible,
.form-group textarea:focus-visible,
.form-group select:focus-visible {
  box-shadow: var(--focus-ring);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 20px;
  cursor: pointer;
}
.check-row input { accent-color: var(--accent); }

.settings-grid {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 16px;
  align-items: end;
}

.settings-span { grid-column: 1 / -1; }

.help-text {
  margin-top: 6px;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 18px;
}

.lab-toggle-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  padding: 8px;
  background: var(--bg);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-sm);
}

.lab-toggle {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s;
}
.lab-toggle:hover { background: var(--surface-hover); }

.lab-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.lab-toggle span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.lab-toggle small {
  color: var(--text-tertiary);
  font-size: 11px;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Toasts — top-center (DESIGN.md §6) ─────────────────────────────── */
#toastRoot {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  background: var(--surface-raised);
  box-shadow: var(--shadow-modal);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  animation: toastIn 0.2s ease-out;
}
.toast.leaving {
  animation: toastOut 0.15s ease-out forwards;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.toast-icon {
  display: inline-flex;
  margin-top: 2px;
  flex-shrink: 0;
}
.toast.success .toast-icon { color: var(--success); }
.toast.error   .toast-icon { color: var(--danger); }
.toast.info    .toast-icon { color: var(--accent); }

.toast-message {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  color: var(--text);
}

/* ── Empty / error states (DESIGN.md §6) ────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 20px;
}
.empty-state svg { color: var(--text-tertiary); margin-bottom: 2px; }
.empty-state strong {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}
.empty-state span {
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 18px;
}
.empty-state.error-state strong { color: var(--danger); }
.empty-state.error-state svg { color: var(--danger); }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .admin-shell { grid-template-columns: 1fr; }

  /* Sidebar collapses to a top tab-bar; switchAdminTab untouched */
  .admin-sidebar {
    position: sticky;
    top: 0;
    z-index: 80;
    height: auto;
    grid-template-rows: none;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .admin-brand {
    min-height: 0;
    padding: 0;
    border-bottom: 0;
  }
  .admin-brand .logo-mark { width: 145px; height: 35px; }

  .admin-tabs {
    display: flex;
    overflow-x: auto;
    gap: 2px;
    scrollbar-width: none;
  }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .admin-tabs button { width: auto; flex-shrink: 0; padding: 0 12px; }

  .sidebar-status {
    padding: 0;
    border-top: 0;
  }
  .sidebar-status > span { display: none; }

  .top-bar { position: static; }
  .stat-row.active { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .grid {
    grid-template-columns: 1fr;
    padding: 16px 16px 48px;
    gap: 12px;
  }
  .panel, .panel.wide { grid-column: 1; }
  .stat-row.active { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-bar { padding: 12px 16px; }
  .settings-grid { grid-template-columns: 1fr; }
  .fallback-picker { grid-template-columns: 1fr; }
  .customer-main,
  .customer-sections,
  .customer-detail-grid { grid-template-columns: 1fr; }
  .customer-actions { justify-content: flex-start; }
  .customer-mini-row { display: grid; grid-template-columns: 1fr; }
  .customer-mini-meta { min-width: 0; text-align: left; }
  .activity-profile-grid { grid-template-columns: 1fr 1fr; }
  .audit-row { grid-template-columns: 1fr; gap: 6px; }
}

@media (max-width: 640px) {
  .admin-tabs button span { display: none; }
  .admin-tabs button { padding: 0 10px; }
  .sidebar-status .status-pill #statusText,
  .sidebar-status .status-pill span:last-child { display: none; }

  .stat-row.active { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .customer-toolbar { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .customer-search { width: min(100%, 360px); }
  .key-row {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .key-actions { width: 100%; justify-content: flex-end; }
  .provider-head { flex-wrap: wrap; }
  .provider-actions, .model-actions { width: 100%; justify-content: flex-end; }
  .model-row { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .act-detail { white-space: normal; overflow-wrap: anywhere; }
  .chart-container { height: 200px; }
  .modal { padding: 16px; }
}

/* ── Reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .pulse, .dot { animation: none; }
}
