/* ═══════════════════════════════════════════════════════════
   Aeldorado Admin — Control Room
   Built on shared theme.css tokens. Login screen, sidebar,
   status rail, stat cards, and per-page detail chrome.
   ═══════════════════════════════════════════════════════════ */

:root {
  --rail-width: 3px;
  --sidebar-width: 240px;
}

/* ── Status Rail — signature element ─────────────────────────
   A persistent left-edge strip that is the panel's heartbeat:
   solid green line when clean, amber when today has errors.
   A small live dot sits at the very top as a readable anchor. */
.status-rail {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--rail-width);
  height: 100vh;
  background: var(--success);
  z-index: 100;
  transition: background 0.6s ease;
  box-shadow: 0 0 12px 0 rgba(74, 222, 128, 0.35);
}

.status-rail.has-errors {
  background: var(--warning);
  box-shadow: 0 0 12px 0 rgba(245, 179, 66, 0.35);
}

.status-rail::after {
  content: "";
  position: absolute;
  top: 0;
  left: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: inherit;
  box-shadow: 0 0 0 4px var(--bg), inherit 0 0 8px 2px;
  animation: rail-pulse 2.4s ease-in-out infinite;
}

@keyframes rail-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

@media (prefers-reduced-motion: reduce) {
  .status-rail::after { animation: none; }
}

/* ── Login Screen ─────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background:
    radial-gradient(900px 500px at 50% 0%, rgba(91,157,250,0.08), transparent 65%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.login-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-5);
  border-radius: var(--radius);
  background: var(--primary-container);
  border: 1px solid rgba(91, 157, 250, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-title {
  font-size: 1.3125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-2);
}

.login-sub {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-bottom: var(--space-6);
  line-height: 1.6;
}

.login-error {
  margin-top: var(--space-4);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--error-container);
  border: 1px solid rgba(247, 100, 100, 0.25);
  color: var(--error);
  font-size: 0.8125rem;
  display: none;
}

.login-error.visible {
  display: block;
}

/* ── App Shell ────────────────────────────────────────────── */
.admin-shell {
  display: none;
  min-height: 100vh;
  padding-left: var(--rail-width);
}

.admin-shell.visible {
  display: flex;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-6) var(--space-4);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 0 var(--space-2);
}

.sidebar-brand .brand-logo-svg {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.sidebar-brand-sub {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  margin: 3px 0 var(--space-8) 0;
  padding: 0 var(--space-2) var(--space-5) var(--space-2);
  border-bottom: 1px solid var(--border);
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  position: relative;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-container);
  color: var(--primary);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  border-radius: var(--radius-full);
  background: var(--primary);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: var(--space-4);
  margin-top: var(--space-4);
}

.admin-identity {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  padding: 0 var(--space-2);
  word-break: break-all;
  font-family: var(--font-mono);
}

/* ── Main Content ─────────────────────────────────────────── */
.main {
  flex: 1;
  padding: var(--space-8) var(--space-10);
  max-width: 1240px;
}

.main-header {
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border);
}

.main-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.main-sub {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 4px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: view-in 0.15s ease;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .view.active { animation: none; }
}

/* ── Stat Cards ───────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color 0.15s ease;
}

.stat-card:hover {
  border-color: var(--border-strong);
}

.stat-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stat-value {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-value.success { color: var(--success); }
.stat-value.error { color: var(--error); }

.tier-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--space-3);
}

.tier-chip {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.tier-chip b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .admin-shell.visible {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    position: static;
    min-height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: var(--space-3) var(--space-4);
  }
  .sidebar-brand-sub {
    display: none;
  }
  .sidebar-brand {
    margin-right: var(--space-4);
  }
  .nav-list {
    flex-direction: row;
  }
  .nav-item.active::before {
    display: none;
  }
  .sidebar-footer {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }
  .admin-identity {
    display: none;
  }
  .main {
    padding: var(--space-5) var(--space-4);
  }
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .studio-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* Visible keyboard focus everywhere in admin */
.nav-item:focus-visible,
.btn:focus-visible,
.link-btn:focus-visible,
.detail-tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Row Actions ──────────────────────────────────────────── */
.row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.link-btn:hover {
  background: var(--surface-hover);
  color: var(--primary);
}

.link-btn[data-action="suspend"]:hover,
.link-btn[data-action="logout"]:hover {
  color: var(--error);
  background: var(--error-container);
}

/* ── Load More ────────────────────────────────────────────── */
.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: var(--space-6);
}

/* ── Filter Bar ───────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
  align-items: center;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.filter-bar .studio-input,
.filter-bar .studio-select {
  width: auto;
  min-width: 150px;
  flex: 1;
}

/* ── User Detail Page ─────────────────────────────────────── */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border);
}

.detail-identity {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.detail-email {
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.detail-uid {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.detail-tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
}

.detail-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 16px;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.detail-tab:hover {
  color: var(--text);
}

.detail-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.range-pill {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.range-pill:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.range-pill.active {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-container);
}

.detail-pane {
  display: none;
}

.detail-pane.active {
  display: block;
  animation: view-in 0.15s ease;
}

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.breakdown-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.breakdown-card-title {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}

.breakdown-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.breakdown-row .count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Profile key/value table reads better with a fixed label column */
#pane-profile .studio-table td:first-child {
  width: 200px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--text-muted) !important;
}

/* Stale-tag / suspension notice banners inside user detail */
#view-user-detail .empty-state {
  border-radius: var(--radius-lg);
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 7, 0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-overlay.visible {
  display: flex;
  animation: modal-fade 0.15s ease;
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay.visible, .modal-card { animation: none; }
}

.modal-title {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-3);
}

.modal-body {
  color: var(--text-secondary);
  font-size: 0.8125rem;
  line-height: 1.55;
  margin-bottom: var(--space-6);
}

.modal-body .studio-select,
.modal-body .studio-input,
.modal-body .studio-textarea {
  margin-top: var(--space-3);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 11px 20px;
  font-size: 0.8125rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast.toast-error {
  border-color: rgba(247, 100, 100, 0.4);
  color: var(--error);
}

.toast.toast-success {
  border-color: rgba(74, 222, 128, 0.4);
  color: var(--success);
}
