/* Saives.ai Admin Console — Styles */

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --error: #dc2626;
  --error-soft: #fef2f2;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --sidebar-active-bg: rgba(255,255,255,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ───────────────────────────── */

#sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  margin-bottom: 32px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
}

.brand-name {
  color: white;
  font-weight: 600;
  font-size: 16px;
}

.nav-items {
  list-style: none;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
  border-left-color: var(--accent);
}

.nav-icon { font-size: 16px; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--sidebar-text);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: var(--error);
}

.status-dot.connected { background: var(--success); }

/* ─── Main Content ──────────────────────── */

#mainContent {
  flex: 1;
  margin-left: 240px;
  padding: 32px;
  max-width: 1200px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

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

.last-updated {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ─── Stats Grid ────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  transition: box-shadow 0.2s ease;
}

.stat-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.stat-card.highlight {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
}

.stat-change {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.stat-change.positive { color: var(--success); }

.stat-sublabel {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.stat-mrr {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
}

/* ─── Section Cards ─────────────────────── */

.section-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 24px;
}

.section-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.retention-grid, .health-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.retention-item, .health-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.retention-label, .health-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.retention-value, .health-value {
  font-size: 18px;
  font-weight: 700;
}

.health-item.warning .health-value { color: var(--error); }

/* ─── Tables ────────────────────────────── */

.table-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.search-input {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  width: 300px;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }

select {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  background: white;
  cursor: pointer;
}

.table-container {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.data-table td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: rgba(0,0,0,0.01); }

.empty-cell {
  text-align: center;
  padding: 48px 16px !important;
  color: var(--text-tertiary);
}

/* ─── Badges & Pills ────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-active { background: var(--success-soft); color: var(--success); }
.badge-trial { background: var(--accent-soft); color: var(--accent); }
.badge-expired { background: var(--error-soft); color: var(--error); }
.badge-cancelled { background: var(--border-light); color: var(--text-tertiary); }
.badge-queued { background: var(--accent-soft); color: var(--accent); }
.badge-processing { background: var(--warning-soft); color: var(--warning); }
.badge-complete { background: var(--success-soft); color: var(--success); }
.badge-failed { background: var(--error-soft); color: var(--error); }
.badge-open { background: var(--warning-soft); color: var(--warning); }
.badge-closed { background: var(--border-light); color: var(--text-tertiary); }

/* ─── Buttons ───────────────────────────── */

.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover { background: #1d4ed8; }

.btn-outline {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
}

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

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

.btn-danger {
  background: var(--error-soft);
  color: var(--error);
}

.btn-danger:hover { background: var(--error); color: white; }

/* ─── Funnel ────────────────────────────── */

.funnel-container {
  max-width: 600px;
}

.funnel-stage {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

.funnel-bar {
  background: var(--accent);
  color: white;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  transition: width 0.6s ease;
}

.funnel-count {
  font-size: 18px;
  font-weight: 700;
  min-width: 60px;
}

/* ─── Feature Flags ─────────────────────── */

.flags-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.flag-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.flag-info h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.flag-info p {
  font-size: 12px;
  color: var(--text-secondary);
}

.toggle {
  width: 44px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
}

.toggle.active { background: var(--accent); }

.toggle::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 10px;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle.active::after { transform: translateX(20px); }

/* ─── Modal ─────────────────────────────── */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  min-width: 400px;
  max-width: 500px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-content h2 {
  font-size: 20px;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ─── Pages ─────────────────────────────── */

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

/* ─── Responsive ────────────────────────── */

@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .section-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  #sidebar { width: 64px; }
  .brand-name, .nav-item span:not(.nav-icon) { display: none; }
  #mainContent { margin-left: 64px; }
  .stats-grid { grid-template-columns: 1fr; }
  .flags-grid { grid-template-columns: 1fr; }
}
