/* ══════════════════════════════════════════════════════════════════
   JARVIS Design System — v3.1
   Mobile-first. Tokens, layout shell, shared components.
   ══════════════════════════════════════════════════════════════════ */

:root {
  /* ── Colour palette ────────────────────────────────────────────── */
  --c-bg:           #060810;
  --c-surface:      #0a0e1a;
  --c-elevated:     #0e1422;
  --c-input:        #0c1120;
  --c-overlay:      rgba(6, 8, 16, 0.82);

  --c-border:       rgba(0, 160, 255, 0.09);
  --c-border-md:    rgba(0, 160, 255, 0.18);
  --c-border-hi:    rgba(0, 180, 255, 0.38);

  --c-accent:       #00a8ff;
  --c-accent-dim:   rgba(0, 168, 255, 0.55);
  --c-accent-glow:  rgba(0, 168, 255, 0.15);
  --c-accent-soft:  rgba(0, 168, 255, 0.08);
  --c-accent-pill:  rgba(0, 168, 255, 0.13);   /* active tab bg */

  --c-cyan:         #00ffcc;
  --c-purple:       #818cf8;

  --c-text:         #e2f0ff;
  --c-text-2:       rgba(160, 210, 255, 0.62);
  --c-text-3:       rgba(100, 155, 215, 0.36);

  --c-success:      #00d68f;
  --c-warning:      #ffbe00;
  --c-error:        #ff4560;

  /* ── Typography ────────────────────────────────────────────────── */
  --font-ui:   -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* ── Fixed shell heights ───────────────────────────────────────── */
  --header-h:   52px;
  --nav-h:      44px;
  --footer-h:   32px;

  /* ── Spacing ───────────────────────────────────────────────────── */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;
  --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;

  /* ── Radius ────────────────────────────────────────────────────── */
  --r-sm: 4px; --r-md: 6px; --r-lg: 8px; --r-xl: 12px;

  /* ── Transitions ───────────────────────────────────────────────── */
  --t-fast: 110ms ease;
  --t-mid:  200ms ease;
  --t-slow: 340ms ease;
}

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

html, body {
  height: 100%;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Atmospheric background ─────────────────────────────────────── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse at 15% 55%, rgba(0, 80, 200, 0.07) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 20%, rgba(0, 168, 255, 0.05) 0%, transparent 48%),
    url("data:image/svg+xml,%3Csvg width='60' height='52' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0L60 17.3V34.6L30 52 0 34.6V17.3Z' fill='none' stroke='rgba(0,100,200,0.04)' stroke-width='0.5'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0;
}
body::after {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px,
    rgba(0,0,0,0.022) 2px, rgba(0,0,0,0.022) 4px);
  pointer-events: none; z-index: 0;
}

/* ══════════════════════════════════════════════════════════════════
   APP SHELL — CSS Grid (rows are fixed, content fills the rest)
   ══════════════════════════════════════════════════════════════════ */
#app {
  display: grid;
  grid-template-rows: var(--header-h) var(--nav-h) 1fr var(--footer-h);
  height: 100dvh;           /* dvh respects iOS Safari bottom chrome */
  height: 100vh;            /* fallback */
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ── Header ─────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--c-border);
  background: rgba(6, 8, 16, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: relative;
  z-index: 20;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex-shrink: 0;
}

.brand-mark {
  width: 29px; height: 29px;
  border-radius: var(--r-md);
  border: 1px solid var(--c-border-md);
  background: var(--c-accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-accent);
  flex-shrink: 0;
  letter-spacing: -0.01em;
}

.brand-text { display: flex; flex-direction: column; gap: 1px; }

.brand-name {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.26em;
  color: var(--c-accent);
  text-shadow: 0 0 14px rgba(0, 168, 255, 0.4);
  text-transform: uppercase;
  line-height: 1;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 7.5px;
  letter-spacing: 0.11em;
  color: var(--c-text-3);
  line-height: 1;
  white-space: nowrap;
}

/* ─── Stats: pill layout, truncates gracefully ─── */
.header-stats {
  display: flex;
  align-items: center;
  gap: 0;
  background: rgba(0, 168, 255, 0.04);
  border: 1px solid var(--c-border);
  border-radius: 20px;
  padding: 0 2px;
  flex-shrink: 0;
  overflow: hidden;
  max-width: calc(100% - 160px); /* never crowd brand */
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.09em;
  color: var(--c-text-3);
  white-space: nowrap;
  border-right: 1px solid var(--c-border);
  transition: color var(--t-mid);
}
.stat-chip:last-child { border-right: none; }

.stat-chip.online {
  color: rgba(0, 214, 143, 0.78);
  gap: 7px;
}

.online-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--c-cyan);
  box-shadow: 0 0 5px var(--c-cyan);
  flex-shrink: 0;
  animation: dot-pulse 2.4s ease-in-out infinite;
}
@keyframes dot-pulse { 0%,100%{opacity:1} 50%{opacity:.28} }

/* ── Navigation ─────────────────────────────────────────────────── */
#nav {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 10px;
  border-bottom: 1px solid var(--c-border);
  background: rgba(6, 8, 16, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: relative;
  z-index: 19;
  overflow-x: auto;
  scrollbar-width: none;
}
#nav::-webkit-scrollbar { display: none; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--c-text-3);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color var(--t-mid), background var(--t-mid), border-color var(--t-mid);
  white-space: nowrap;
  flex-shrink: 0;
  outline: none;
}

.nav-btn svg {
  width: 14px; height: 14px;
  stroke: currentColor; fill: none; stroke-width: 1.7;
  flex-shrink: 0;
  transition: stroke var(--t-mid);
}

.nav-btn:hover {
  color: var(--c-text-2);
  background: rgba(255,255,255,0.035);
}

/* Active: filled pill with border — strong visual weight */
.nav-btn.active {
  color: var(--c-accent);
  background: var(--c-accent-pill);
  border-color: rgba(0, 168, 255, 0.24);
  box-shadow: 0 0 12px rgba(0, 168, 255, 0.08), inset 0 1px 0 rgba(255,255,255,0.04);
}

/* ── Content / panels ───────────────────────────────────────────── */
#content { overflow: hidden; position: relative; }

.tab-panel { display: none; height: 100%; overflow: hidden; }
.tab-panel.active { display: flex; flex-direction: column; }

/* ── Footer ─────────────────────────────────────────────────────── */
#footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-top: 1px solid var(--c-border);
  background: rgba(6, 8, 16, 0.94);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--c-text-3);
}

/* ── Corner accents ─────────────────────────────────────────────── */
.corner { position:fixed; width:16px; height:16px; pointer-events:none; z-index:100; opacity:0.16; }
.corner-tl { top:5px;    left:5px;   border-top:1.5px solid var(--c-accent); border-left:1.5px solid var(--c-accent); }
.corner-tr { top:5px;    right:5px;  border-top:1.5px solid var(--c-accent); border-right:1.5px solid var(--c-accent); }
.corner-bl { bottom:5px; left:5px;   border-bottom:1.5px solid var(--c-accent); border-left:1.5px solid var(--c-accent); }
.corner-br { bottom:5px; right:5px;  border-bottom:1.5px solid var(--c-accent); border-right:1.5px solid var(--c-accent); }

/* ══════════════════════════════════════════════════════════════════
   SHARED COMPONENT LIBRARY
   ══════════════════════════════════════════════════════════════════ */

.field {
  background: var(--c-input);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  color: var(--c-text);
  font-family: var(--font-ui);
  font-size: 12px;
  outline: none;
  width: 100%;
  transition: border-color var(--t-mid), box-shadow var(--t-mid);
}
.field::placeholder { color: var(--c-text-3); }
.field:focus { border-color: var(--c-border-hi); box-shadow: 0 0 0 3px rgba(0,168,255,0.07); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-md); border: 1px solid transparent;
  font-family: var(--font-ui); font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all var(--t-mid); white-space: nowrap; outline: none;
}
.btn:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: rgba(0,168,255,0.1); border-color: rgba(0,168,255,0.28); color: var(--c-accent);
}
.btn-primary:hover {
  background: rgba(0,168,255,0.18); border-color: rgba(0,168,255,0.5);
  box-shadow: 0 0 14px rgba(0,168,255,0.1);
}

.btn-ghost { background: transparent; border-color: var(--c-border); color: var(--c-text-2); }
.btn-ghost:hover { background: rgba(255,255,255,0.04); border-color: var(--c-border-md); color: var(--c-text); }

.sec-label {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.2em;
  color: var(--c-text-3); text-transform: uppercase;
  padding: 8px 0 6px; flex-shrink: 0; border-bottom: 1px solid var(--c-border);
}

/* Scrollbars */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,168,255,0.16); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,168,255,0.3); }

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE — mobile-first adjustments
   ══════════════════════════════════════════════════════════════════ */

/* ─── Phones: ≤ 640px ─── */
@media (max-width: 640px) {
  :root { --header-h: 48px; --nav-h: 42px; --footer-h: 28px; }

  #header { padding: 0 14px; }

  /* Hide all stats chips on mobile — keep only the online dot */
  .header-stats .stat-chip:not(.online) { display: none; }
  .header-stats { border: none; background: none; padding: 0; }
  .stat-chip.online { padding: 0; }

  /* Tighten brand sub-text on small screens */
  .brand-sub { display: none; }

  #nav { padding: 0 6px; gap: 2px; }
  .nav-btn { padding: 6px 9px; font-size: 11px; }
  /* Show icons + short labels on phones */

  #footer { padding: 0 12px; }
  /* Hide middle footer item on very small screens */
  #footer > :nth-child(2) { display: none; }
}

/* ─── Narrow landscape / small tablet: 641–900px ─── */
@media (min-width: 641px) and (max-width: 900px) {
  .header-stats .stat-chip:not(.online):nth-child(n+3) { display: none; }
  .brand-sub { display: none; }
}

/* ══════════════════════════════════════════════════════════════════
   BRAIN TAB — background image + screen-blend Three.js canvas
   Higher specificity (#panel-brain #brain-wrap) beats brain.js
   injected styles (#brain-wrap) to ensure background shows through.
   mix-blend-mode: screen makes canvas black pixels transparent,
   letting the static neural bg layer behind the live Three.js viz.
   ══════════════════════════════════════════════════════════════════ */

#panel-brain #brain-wrap {
  background:
    radial-gradient(ellipse at center, transparent 25%, rgba(6,8,16,0.45) 100%),
    url("/img/brain_bg.jpg") center / cover no-repeat !important;
  background-color: #060810 !important;
}

#panel-brain #brain-canvas {
  mix-blend-mode: screen !important;
}
