/* ═══════════════════════════════════════════════════════════════════
   SUPERVITY DESIGN SYSTEM — Fapio Command Center
   Brand: Navy #141A42 · Cornflower #8AA2DF · Purple #535EA4
   Fonts: Funnel Display (headings) · Geologica (body)
   ═══════════════════════════════════════════════════════════════════ */

/* ── Google Fonts ──────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Funnel+Display:wght@400;500;600;700&family=Geologica:wght@300;400;500;600;700&display=swap');

/* ── Design Tokens ────────────────────────────────────────────────── */
:root {
  --navy:        #141A42;
  --navy-light:  #1E2654;
  --cornflower:  #8AA2DF;
  --cornflower-light: #A8BCEB;
  --purple:      #535EA4;
  --muted:       #848EAA;
  --light:       #E7E7E7;
  --bg:          #F5F7FF;
  --card:        #FFFFFF;
  --border:      #E8EBF2;
  --text:        #141A42;
  --text-muted:  #848EAA;
  --success:     #10B981;
  --warning:     #F59E0B;
  --error:       #EF4444;
  --radius:      0.75rem;
  --sidebar-w:   256px;
  --sidebar-cw:  64px;
  --header-h:    56px;
  --strip-h:     44px;
  --font-display: 'Funnel Display', system-ui, sans-serif;
  --font-body:    'Geologica', system-ui, sans-serif;
  --shadow-glass: inset 0 1px 0 0 rgba(255,255,255,0.8), 0 0 0 1px rgba(0,0,0,0.03);
  --shadow-float: 0 8px 30px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.03);
  --shadow-accent: 0 0 0 1px rgba(138,162,223,0.3), 0 0 20px -5px rgba(138,162,223,0.15);
}

[data-theme="dark"] {
  --bg:         #0A0E1F;
  --card:       rgba(20,26,66,0.8);
  --border:     rgba(138,162,223,0.15);
  --text:       #E7E7E7;
  --text-muted: #848EAA;
  --shadow-glass: inset 0 1px 0 0 rgba(255,255,255,0.05), 0 0 0 1px rgba(138,162,223,0.1);
  --shadow-float: 0 8px 30px rgba(0,0,0,0.3), 0 0 0 1px rgba(138,162,223,0.1);
}

/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

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

h1,h2,h3,h4,h5,h6 { font-family: var(--font-display); font-weight: 600; }

a { color: var(--cornflower); text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; font-family: var(--font-body); }

/* ── Noise Texture (premium paper feel) ───────────────────────────── */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none; z-index: 9999; opacity: 0.02;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Layout Shell ─────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid rgba(0,0,0,0.06);
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.8);
  display: flex; flex-direction: column;
  transition: width 0.3s ease;
  z-index: 200;
}
.sidebar.collapsed { width: var(--sidebar-cw); }

[data-theme="dark"] .sidebar {
  background: rgba(10,14,31,0.9);
  border-right-color: rgba(138,162,223,0.1);
}

/* Sidebar Logo */
.sidebar-logo {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 16px; height: 80px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}
.sidebar-logo-icon {
  width: 40px; height: 40px; min-width: 40px;
  background: var(--navy); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 15px -3px rgba(0,0,0,0.1);
  transition: transform 0.2s, box-shadow 0.2s;
}
.sidebar-logo-icon:hover { transform: scale(1.05); box-shadow: var(--shadow-accent); }
.sidebar-logo-icon svg { width: 24px; height: 24px; }
.sidebar-logo-text { display: flex; flex-direction: column; }
.sidebar-logo-text .brand { font-family: var(--font-display); font-size: 18px; font-weight: 700; color: var(--navy); }
.sidebar-logo-text .sub { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.sidebar.collapsed .sidebar-logo-text { display: none; }
.sidebar.collapsed .sidebar-logo { justify-content: center; padding: 20px 8px; }

[data-theme="dark"] .sidebar-logo-text .brand { color: #fff; }

/* Sidebar Nav */
.sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
.sidebar-nav::-webkit-scrollbar { display: none; }
.nav-section { margin-bottom: 24px; }
.nav-section-title {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: rgba(132,142,170,0.7);
  padding: 0 12px; margin-bottom: 8px;
}
.sidebar.collapsed .nav-section-title { display: none; }

.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px;
  font-size: 14px; font-weight: 500;
  color: var(--muted);
  transition: all 0.2s ease;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-link:hover { background: rgba(138,162,223,0.1); color: var(--navy); transform: translateX(4px); text-decoration: none; }
.nav-link.active { background: var(--navy); color: #fff; box-shadow: 0 2px 15px -3px rgba(0,0,0,0.1); }
.nav-link.active:hover { transform: none; }
.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-link span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 10px 8px; }
.sidebar.collapsed .nav-link:hover { transform: none; }
.sidebar.collapsed .nav-link span { display: none; }

[data-theme="dark"] .nav-link:hover { color: #fff; }

/* Sidebar Footer */
.sidebar-footer { border-top: 1px solid rgba(0,0,0,0.04); padding: 12px; }
.sidebar-collapse-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 12px; border-radius: 8px;
  border: none; background: none; color: var(--muted);
  font-size: 13px; font-weight: 500; transition: all 0.2s;
}
.sidebar-collapse-btn:hover { color: var(--navy); background: rgba(0,0,0,0.03); }
.sidebar-collapse-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar.collapsed .sidebar-collapse-btn span { display: none; }
.sidebar.collapsed .sidebar-collapse-btn { justify-content: center; }

[data-theme="dark"] .sidebar-collapse-btn:hover { color: #fff; }

/* ── Main Content ─────────────────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  transition: margin-left 0.3s ease;
  display: flex; flex-direction: column;
  padding-bottom: var(--strip-h);
}
.sidebar.collapsed ~ .main { margin-left: var(--sidebar-cw); }

/* ── Header ───────────────────────────────────────────────────────── */
.header {
  position: sticky; top: 16px; z-index: 100;
  margin: 16px 24px 0;
  padding: 0 20px; height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 16px;
  box-shadow: var(--shadow-glass);
}
[data-theme="dark"] .header { background: rgba(20,26,66,0.6); }

.header-left { display: flex; align-items: center; gap: 12px; }
.header-title { font-family: var(--font-display); font-size: 16px; font-weight: 600; color: var(--text); }

.header-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--cornflower); color: var(--navy); box-shadow: var(--shadow-accent); }
.icon-btn svg { width: 18px; height: 18px; }

[data-theme="dark"] .icon-btn { background: rgba(20,26,66,0.6); color: var(--muted); border-color: var(--border); }
[data-theme="dark"] .icon-btn:hover { color: #fff; }

/* ── Page Content ─────────────────────────────────────────────────── */
.page-content { padding: 24px 24px 32px; flex: 1; }
.page { display: none; }
.page.active { display: block; animation: fadeUp 0.3s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Stats Grid ───────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-glass);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative; overflow: hidden;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-float); }
.stat-card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.stat-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted);
}
.stat-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.navy { background: var(--navy); }
.stat-icon.cornflower { background: var(--cornflower); }
.stat-icon.purple { background: var(--purple); }
.stat-icon.gradient { background: linear-gradient(135deg, var(--navy), var(--purple)); }
.stat-value {
  font-family: var(--font-display); font-size: 36px;
  font-weight: 700; line-height: 1; color: var(--navy);
  margin-top: 8px;
}
[data-theme="dark"] .stat-value { color: #fff; }
.stat-trend { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 12px; font-weight: 500; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--error); }

/* ── Dashboard Grid ───────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: 1fr 340px; gap: 24px; }

/* ── Card ─────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-glass);
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.card-title svg { width: 18px; height: 18px; color: var(--cornflower); }
.card-body { padding: 0; }

/* ── Batch Table ──────────────────────────────────────────────────── */
.batch-table { width: 100%; border-collapse: collapse; }
.batch-table th {
  text-align: left; padding: 10px 16px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.batch-table td {
  padding: 12px 16px; font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.batch-table tr:last-child td { border-bottom: none; }
.batch-table tr { transition: background 0.15s; cursor: pointer; }
.batch-table tr:hover { background: rgba(138,162,223,0.06); }

.batch-table .mono { font-family: 'SF Mono', 'Consolas', monospace; font-size: 12px; }

/* Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
}
.pill::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
}
.pill.queued { background: rgba(132,142,170,0.15); color: var(--muted); }
.pill.queued::before { background: var(--muted); }
.pill.processing { background: rgba(138,162,223,0.15); color: var(--cornflower); }
.pill.processing::before { background: var(--cornflower); animation: pulse 1.5s infinite; }
.pill.done { background: rgba(16,185,129,0.12); color: var(--success); }
.pill.done::before { background: var(--success); }
.pill.failed { background: rgba(239,68,68,0.12); color: var(--error); }
.pill.failed::before { background: var(--error); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Agent Panel ──────────────────────────────────────────────────── */
.agent-card {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.agent-card:last-child { border-bottom: none; }
.agent-card:hover { background: rgba(138,162,223,0.04); }
.agent-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.agent-name { font-size: 13px; font-weight: 600; color: var(--text); }
.agent-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.agent-dot.active { background: var(--success); box-shadow: 0 0 6px rgba(16,185,129,0.4); }
.agent-dot.idle { background: var(--muted); }
.agent-dot.degraded { background: var(--warning); box-shadow: 0 0 6px rgba(245,158,11,0.4); }
.agent-dot.error { background: var(--error); }
.agent-task { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.agent-progress { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.agent-progress-bar { height: 100%; border-radius: 2px; background: var(--cornflower); transition: width 0.5s ease; }
.agent-progress-bar.active { background: linear-gradient(90deg, var(--cornflower), var(--purple)); }
.agent-heartbeat { font-size: 10px; color: var(--muted); margin-top: 4px; }

/* ── Agent Bottom Strip ───────────────────────────────────────────── */
.agent-strip {
  position: fixed; bottom: 0; left: var(--sidebar-w); right: 0;
  height: var(--strip-h);
  background: var(--navy);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  z-index: 100;
  transition: left 0.3s ease;
}
.sidebar.collapsed ~ .main ~ .agent-strip,
.sidebar.collapsed ~ .agent-strip { left: var(--sidebar-cw); }

.strip-label { font-size: 11px; font-weight: 600; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 0.05em; }
.strip-agents { display: flex; gap: 12px; flex: 1; overflow-x: auto; }
.strip-agents::-webkit-scrollbar { display: none; }

.strip-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px; border-radius: 20px;
  background: rgba(255,255,255,0.08);
  font-size: 12px; color: rgba(255,255,255,0.8);
  white-space: nowrap;
  transition: background 0.2s;
}
.strip-pill:hover { background: rgba(255,255,255,0.15); }
.strip-pill .sdot { width: 6px; height: 6px; border-radius: 50%; }
.strip-pill .sdot.active { background: var(--success); box-shadow: 0 0 6px rgba(16,185,129,0.5); }
.strip-pill .sdot.idle { background: rgba(255,255,255,0.3); }
.strip-pill .sdot.degraded { background: var(--warning); }

/* ── Slide-Over ───────────────────────────────────────────────────── */
.slide-over-backdrop {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.slide-over-backdrop.open { opacity: 1; pointer-events: all; }

.slide-over {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 560px; max-width: 90vw;
  background: var(--card);
  box-shadow: -8px 0 30px rgba(0,0,0,0.1);
  z-index: 301;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex; flex-direction: column;
}
.slide-over.open { transform: translateX(0); }
.slide-over-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.slide-over-title { font-family: var(--font-display); font-size: 18px; font-weight: 700; color: var(--text); }
.slide-over-body { flex: 1; overflow-y: auto; padding: 24px; }
.slide-over-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  border: none; transition: all 0.2s;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-light); box-shadow: var(--shadow-accent); }
.btn-gradient { background: linear-gradient(135deg, var(--navy), var(--purple)); color: #fff; }
.btn-gradient:hover { box-shadow: var(--shadow-accent); }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--cornflower); color: var(--cornflower); }
.btn-ghost { background: none; border: none; color: var(--muted); }
.btn-ghost:hover { color: var(--navy); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── Empty State ──────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-family: var(--font-display); font-size: 16px; color: var(--text); margin-bottom: 4px; }
.empty-state p { font-size: 13px; }

/* ── Detail Fields ────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.detail-field label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 2px; }
.detail-field .val { font-size: 14px; font-weight: 500; color: var(--text); }

/* ── Loading / Shimmer ────────────────────────────────────────────── */
.shimmer {
  background: linear-gradient(90deg, var(--border) 0%, rgba(248,250,255,1) 50%, var(--border) 100%);
  background-size: 200% 100%;
  animation: shimmer 2s infinite linear;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* ── Settings Page ────────────────────────────────────────────────── */
.settings-card { max-width: 640px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: none; }
.settings-label { font-size: 14px; font-weight: 500; }
.settings-desc { font-size: 12px; color: var(--muted); }
.settings-val { font-family: 'SF Mono', 'Consolas', monospace; font-size: 13px; color: var(--muted); }

/* ── Toggle Switch ────────────────────────────────────────────────── */
.toggle { position: relative; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 12px;
  cursor: pointer; transition: background 0.3s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  left: 3px; bottom: 3px;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: transform 0.3s;
}
.toggle input:checked + .toggle-slider { background: var(--cornflower); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0 !important; }
  .header { margin: 8px 12px 0; }
  .page-content { padding: 16px 12px; }
  .agent-strip { left: 0 !important; }
  .slide-over { width: 100vw; }
}

/* ── Reduced Motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
