/* ═══════════════════════════════════════════════════════════
   Saiko Intelligence — Base CSS
   Variables, reset, dark theme, typography, layout grid
   ═══════════════════════════════════════════════════════════ */

/* — Theme Variables (overridden per-tenant via inline CSS or JS) — */
:root {
  /* ── Target design system ── */
  --bg: #07070a;
  --bg1: #0c0c10;
  --bg2: #121218;
  --bg3: #1a1a22;
  --bg4: #22222c;
  --border: #1e1e28;
  --border-h: #2a2a38;
  --text: #e8e8ec;
  --text2: #9a9ab0;
  --text3: #5c5c72;
  --accent: #c8ff00;
  --accent-d: rgba(200, 255, 0, .06);
  --accent-b: rgba(200, 255, 0, .15);
  --red: #ef4444;
  --orange: #ff9f43;
  --blue: #4da6ff;
  --purple: #a855f7;
  --cyan: #22d3ee;
  --teal: #2dd4bf;
  --green: #22c55e;
  --amber: #f59e0b;
  --pink: #f472b6;
  --discord: #5865f2;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --sidebar-w: 232px;
  --topbar-h: 52px;
  --font-body: 'Outfit', 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Space Mono', monospace;
  /* ── Backwards-compatible aliases (removed in Sprint 12) ── */
  --card: var(--bg2);
  --card2: var(--bg3);
  --border2: var(--border-h);
  --dim: var(--text3);
  --muted: var(--text2);
  --r: var(--radius);
}

/* — Reset — */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: var(--bg); }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 3px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}
button { cursor: pointer; }

/* — Animations — */
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes glow {
  0%,100% { box-shadow: 0 0 20px var(--accent-d); }
  50% { box-shadow: 0 0 40px var(--accent-b); }
}

/* — Typography — */
h1 { font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
h2 { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
h3 { font-size: 14px; font-weight: 600; }
.mono { font-family: var(--font-mono); }
.dim { color: var(--text3); }
.muted { color: var(--text2); }
.accent { color: var(--accent); }
.small { font-size: 11px; }
.tiny { font-size: 9px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .7px; }

/* — Layout: Topbar + Sidebar + Main — */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg1);
}
.topbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-b), transparent);
}
.tb-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}
.tb-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #000));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: var(--bg);
  font-family: serif;
  animation: glow 4s infinite;
}
.tb-name { font-weight: 700; font-size: 14px; letter-spacing: -.3px; }
.tb-sub {
  font-size: 9px;
  font-family: var(--font-mono);
  color: var(--text3);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.tb-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.tb-live {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text2);
  font-family: var(--font-mono);
}
.tb-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
.tb-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg2);
}

.layout {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  position: relative;
}
/* Subtle noise texture — adds depth and reduces the flat look */
.layout::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: .015;
  pointer-events: none;
  z-index: 9999;
  mix-blend-mode: overlay;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg1);
  overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 0; }
.nav-section {
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 18px 16px 6px;
  font-weight: 600;
  user-select: none;
}
.nav-section-row { display: flex; align-items: center; justify-content: space-between; }
.nav-new-btn {
  font-size: 9px;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 500;
  opacity: .8;
  transition: opacity .12s;
}
.nav-new-btn:hover { opacity: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  margin: 1px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  user-select: none;
}
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active {
  background: var(--accent-d);
  color: var(--accent);
  font-weight: 500;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
/* AI Strategist hero nav item — matches reference .si.active pattern */
.ai-nav-hero {
  margin: 4px 8px 8px !important;
  padding: 10px 14px !important;
  background: linear-gradient(135deg, rgba(200,255,0,.08), rgba(168,85,247,.08)) !important;
  border: 1px solid rgba(200,255,0,.15);
  border-radius: 8px;
  font-weight: 600 !important;
  font-size: 13px !important;
  letter-spacing: 0.3px;
  height: auto !important;
}
.ai-nav-hero:hover {
  background: linear-gradient(135deg, rgba(200,255,0,.12), rgba(168,85,247,.1)) !important;
  border-color: rgba(200,255,0,.25);
}
.ai-nav-hero.active {
  background: linear-gradient(135deg, rgba(200,255,0,.15), rgba(168,85,247,.12)) !important;
  border-color: rgba(200,255,0,.3);
  color: var(--accent);
}
.ai-nav-hero.active::before { display: none; }
.ai-nav-hero .nav-icon { font-size: 16px; }

.nav-icon { font-size: 13px; width: 18px; text-align: center; opacity: .7; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-family: var(--font-mono);
  background: var(--accent);
  color: var(--bg);
  padding: 1px 6px;
  border-radius: 100px;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
  line-height: 1.5;
}
.nav-badge-red {
  margin-left: auto;
  font-size: 9px;
  font-family: var(--font-mono);
  background: rgba(239, 68, 68, .15);
  color: var(--red);
  padding: 1px 6px;
  border-radius: 100px;
  font-weight: 700;
}
.sb-foot {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--text2);
}

/* AI Floating Button */
.ai-float-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c8ff00, #a855f7);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(200,255,0,.3);
  transition: transform .15s, box-shadow .15s;
}
.ai-float-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(200,255,0,.4);
}

/* AI Floating Panel */
.ai-panel {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: 999;
  width: 380px;
  height: 60vh;
  max-height: 600px;
  background: var(--bg);
  border: 1px solid rgba(200,255,0,.2);
  border-radius: 12px;
  display: none;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.5), 0 0 20px rgba(200,255,0,.08);
  overflow: hidden;
}
.ai-panel.open { display: flex; }
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#ai-panel-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 0;
}
/* Ensure chat core fills its container in both modes */
#ai-chat-core {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
/* In floating mode, hide full-page title bar (panel has its own header) */
.ai-panel #ai-title-bar { display: none !important; }
/* In floating mode, compact tabs + fill remaining space properly */
.ai-panel .ai-tabs-bar { margin-bottom: 4px; flex-shrink: 0; }
.ai-panel .ai-tab { font-size: 9px; padding: 3px 7px; }
/* New campaign-tabs also hidden/compact in panel mode */
.ai-panel .campaign-tabs { height: 34px; padding: 0 10px; margin: 0; }
.ai-panel .ctab { font-size: 10px; padding: 3px 8px; }
.ai-panel .ai-body { flex: 1; min-height: 0; }
.ai-panel .ai-body-left { flex: 1; min-height: 0; }
.ai-panel .ai-input-wrap { padding: 4px 8px 8px; }
.ai-panel .context-panel, .ai-panel #ai-context-panel { display: none !important; }
.ai-panel .camp-banner { display: none !important; }
.ai-panel .chat-area { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.ai-panel .chat-msgs { flex: 1; min-height: 0; max-height: none; overflow-y: auto; }
.ai-panel .chat-input { flex-shrink: 0; padding: 6px 8px 8px; }
.ai-panel .chat-input textarea { min-height: 36px; padding: 8px 12px; font-size: 12px; }
.ai-panel .chat-send { padding: 8px 14px; font-size: 10px; }

/* Main Content */
.main {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
}
.view { display: none; animation: slideUp .25s ease; }
.view.active { display: flex; flex-direction: column; }
/* Section label — small uppercase descriptor used throughout views */
.section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text3);
  font-weight: 600;
  margin-bottom: 12px;
}
/* Large page/view heading (was .section-title before Sprint 0) */
.page-title { font-size: 22px; font-weight: 800; letter-spacing: -.5px; margin-bottom: 3px; }
.section-sub { font-size: 12px; color: var(--text2); margin-bottom: 20px; }

/* — Responsive — */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .grid-2, .grid-3 { grid-template-columns: 1fr !important; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: 14px 12px; }
}
