/*
 * Naming: BEM-ish — block-element pattern (no __ or -- delimiters).
 * Examples: block-header, block-title, agent-card, agent-dot, task-item, task-meta.
 * State variants use dot-chained classes: .agent-status.ready, .block-status--processing.
 * Tokens: spacing uses --space-*, typography uses --text-*, colors use named vars.
 */

/* ── Variables ── */
:root {
  --bg: #0a0a0f;
  --bg-panel: #12121a;
  --bg-card: #1a1a26;
  --bg-hover: #22222e;
  --border: #2a2a3a;
  --text: #e0e0e8;
  --text-dim: #888898;
  --text-muted: #555568;
  --accent: #7c5cff;
  --green: #00ff88;
  --blue: #00aaff;
  --pink: #ff88ff;
  --orange: #ffaa00;
  --red: #ff6666;
  --cyan: #88ffff;
  --glass: rgba(255, 255, 255, 0.03);
  --glass-b: rgba(255, 255, 255, 0.06);
  --glass-hover: rgba(255, 255, 255, 0.08);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --block-header: 32px;
  --sidebar-w: 48px;
  --statusbar-h: 36px;

  /* Spacing scale */
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 6px;
  --space-4: 8px;
  --space-5: 12px;
  --space-6: 16px;
  --space-7: 24px;
  --space-8: 32px;

  /* Typography scale */
  --text-2xs: 8px;
  --text-xs: 9px;
  --text-sm: 11px;
  --text-base: 12px;
  --text-md: 13px;
  --text-lg: 16px;

  /* Interactive states */
  --bg-active: rgba(255, 255, 255, 0.12);
  --bg-focus: rgba(124, 92, 255, 0.12);
  --focus-ring: 0 0 0 2px var(--accent);
}

/*
 * Light theme. Only the neutral surface/text/border/glass tokens change —
 * --accent/--green/--blue/--pink/--orange/--red/--cyan stay the same hex in
 * both themes (they're used as button/status backgrounds with a fixed
 * contrasting #fff/#000 text color elsewhere, so retuning them for
 * text-on-white contrast would break those pairings; a per-role accent
 * token split is a reasonable follow-up but out of scope here).
 * Applied via data-theme="light" (explicit choice, set by theme.ts) or,
 * with no explicit choice, via prefers-color-scheme below.
 */
:root[data-theme="light"] {
  --bg: #f7f7fb;
  --bg-panel: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eeeef4;
  --border: #dcdce6;
  --text: #16161f;
  --text-dim: #55556b;
  --text-muted: #8a8aa0;
  --glass: rgba(0, 0, 0, 0.03);
  --glass-b: rgba(0, 0, 0, 0.06);
  --glass-hover: rgba(0, 0, 0, 0.08);
  --bg-active: rgba(0, 0, 0, 0.08);
  --bg-focus: rgba(124, 92, 255, 0.1);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f7f7fb;
    --bg-panel: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #eeeef4;
    --border: #dcdce6;
    --text: #16161f;
    --text-dim: #55556b;
    --text-muted: #8a8aa0;
    --glass: rgba(0, 0, 0, 0.03);
    --glass-b: rgba(0, 0, 0, 0.08);
    --glass-hover: rgba(0, 0, 0, 0.06);
    --bg-active: rgba(0, 0, 0, 0.08);
    --bg-focus: rgba(124, 92, 255, 0.1);
  }
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

::selection {
  background: rgba(255, 255, 255, 0.15);
}
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* ── Animations ── */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}
@keyframes typingBounce {
  0%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-3px);
  }
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Tablet/Mobile overrides ── */
@media (max-width: 768px) {
  :root {
    --block-header: 44px;
    --statusbar-h: 48px;
    --sidebar-w: 0px;
  }
}

/* ── iOS Safe Areas ── */
@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .add-bar {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--statusbar-h) + env(safe-area-inset-bottom));
  }
  .input-area {
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }
}

.muted {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* Visually hidden but still announced by screen readers (e.g. live regions). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  text-decoration: none;
}
.btn:hover { opacity: 0.85; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: var(--space-3) var(--space-5);
}

.btn-link {
  background: none;
  color: var(--blue);
  padding: var(--space-1) 0;
  font-size: inherit;
  font-weight: inherit;
}
.btn-link:hover { text-decoration: underline; }

/* ── Utility Classes ── */
.flex-row { display: flex; flex-direction: row; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; min-width: 0; min-height: 0; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.touch-target { min-height: 44px; min-width: 44px; }

/* ── Auth Gate ── */
#auth-gate {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-gate-card {
  background: var(--bg-panel);
  border: 1px solid var(--glass-b);
  border-radius: 12px;
  max-width: 400px;
  width: 90%;
  padding: var(--space-7);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.auth-gate-card h2 { margin: 0; font-size: var(--text-lg); }
.auth-gate-logo { font-family: monospace; color: var(--accent); letter-spacing: 2px; }
.auth-gate-subtitle { color: var(--text-muted); font-size: var(--text-sm); margin: 0; }
.auth-gate-btn-skip {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  opacity: 0.7;
  font-family: var(--font);
}
.auth-gate-btn-skip:hover { opacity: 1; }
.auth-gate-btn-skip:focus-visible { outline: 1px solid var(--text-dim); outline-offset: 2px; }
