:root {
  --bg: #030305;
  --surface: rgba(10, 15, 30, 0.82);
  --surface-2: rgba(15, 23, 42, 0.9);
  --border: rgba(0, 243, 255, 0.14);
  --text: #e2e8f0;
  --muted: #8892b0;
  --accent: #00f3ff;
  --accent-dim: rgba(0, 243, 255, 0.1);
  --accent-2: #f5c518;
  --danger: #ff2a2a;
  --friendly: #39ff14;
  --radius: 8px;
  --font: "Rajdhani", system-ui, sans-serif;
  --font-title: "Orbitron", sans-serif;
  --mono: "Fira Code", ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

body {
  background: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(0, 102, 255, 0.15), transparent),
    var(--bg);
}

.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 2;
  background: linear-gradient(transparent 50%, rgba(0,0,0,0.15) 50%);
  background-size: 100% 4px; opacity: 0.25;
}
.login-canvas { position: fixed; inset: 0; z-index: 1; pointer-events: none; opacity: 0.5; }
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: linear-gradient(rgba(0,243,255,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,243,255,0.05) 1px, transparent 1px);
  background-size: 40px 40px;
}
.bg-glow { position: fixed; width: 55vw; height: 55vw; border-radius: 50%; filter: blur(130px); opacity: 0.1; pointer-events: none; z-index: 0; }
.bg-glow-a { top: -15%; right: -10%; background: #0066ff; }
.bg-glow-b { bottom: -25%; left: -10%; background: var(--accent); }

/* ── Login ── */
.login-gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; background: rgba(3,3,5,0.5); backdrop-filter: blur(8px);
}
.login-gate[hidden] { display: none !important; }
.login-card {
  width: min(400px, 100%); padding: 2rem;
  border: 1px solid rgba(0,243,255,0.35);
  background: rgba(10,15,30,0.88); backdrop-filter: blur(20px);
  box-shadow: 0 0 60px rgba(0,243,255,0.08);
  text-align: center;
}
.login-hex { width: 64px; height: 64px; margin: 0 auto 1rem; color: var(--accent); }
.login-tag { font-family: var(--mono); font-size: 0.65rem; color: var(--accent); letter-spacing: 0.2em; margin: 0; }
.login-title { font-family: var(--font-title); font-size: 1.4rem; letter-spacing: 0.15em; margin: 0.25rem 0; color: var(--accent); text-shadow: 0 0 20px rgba(0,243,255,0.4); }
.login-sub { color: var(--muted); font-size: 0.85rem; margin: 0 0 1.25rem; }
.login-form { display: flex; flex-direction: column; gap: 0.85rem; text-align: left; }
.login-form label span { font-family: var(--font-title); font-size: 0.65rem; letter-spacing: 0.1em; color: rgba(0,243,255,0.7); }
.login-form input {
  width: 100%; padding: 0.6rem 0.8rem; margin-top: 0.25rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--font); font-size: 1rem;
}
.login-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.login-btn { width: 100%; margin-top: 0.5rem; }
.login-error { color: var(--danger); font-size: 0.82rem; margin: 0; }
.login-portal { display: block; margin-top: 1rem; font-size: 0.75rem; color: var(--muted); text-decoration: none; font-family: var(--mono); }
.login-portal:hover { color: var(--accent); }

/* ── App shell ── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; position: relative; z-index: 10; }
.app-shell[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.65rem 1.25rem; border-bottom: 1px solid var(--border);
  background: rgba(3,3,5,0.85); backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 0.6rem; min-width: 180px; }
.brand-mark { color: var(--accent); font-size: 1.2rem; }
.brand h1 { margin: 0; font-family: var(--font-title); font-size: 0.95rem; letter-spacing: 0.08em; }
.brand-sub { margin: 0; font-size: 0.68rem; color: var(--muted); }
.topbar-center { display: flex; align-items: center; gap: 0.75rem; flex: 1; }
.model-select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 0.35rem 0.6rem; border-radius: 6px; font-family: var(--font); font-size: 0.85rem;
}
.workspace-chip {
  font-family: var(--mono); font-size: 0.72rem; color: var(--accent);
  padding: 0.25rem 0.6rem; border: 1px solid var(--border); border-radius: 999px;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.status-pill {
  display: flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0.7rem;
  border-radius: 999px; border: 1px solid var(--border); font-size: 0.75rem;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-pill.ok .dot { background: var(--friendly); box-shadow: 0 0 8px var(--friendly); }

.workspace {
  flex: 1; display: grid;
  grid-template-columns: 220px 1fr 200px;
  gap: 0; min-height: 0;
}

.activity-panel, .context-panel {
  padding: 0.85rem; border-color: var(--border); background: rgba(5,8,16,0.6);
  overflow-y: auto;
}
.activity-panel { border-right: 1px solid var(--border); }
.context-panel { border-left: 1px solid var(--border); }
.activity-panel h3, .ctx-card h3 {
  margin: 0 0 0.65rem; font-family: var(--font-title); font-size: 0.7rem;
  letter-spacing: 0.15em; color: var(--accent); text-transform: uppercase;
}
.activity-list { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: 0.68rem; }
.activity-list li { padding: 0.3rem 0; border-bottom: 1px solid rgba(255,255,255,0.04); color: var(--muted); }
.activity-list .act-tool { color: var(--accent); }
.activity-list .act-iter { color: var(--accent-2); }

.chat-main {
  display: flex; flex-direction: column; min-height: calc(100vh - 110px);
  background: rgba(0,0,0,0.2);
}

.welcome {
  padding: 3rem 2rem 1rem; text-align: center; max-width: 640px; margin: 0 auto;
}
.welcome[hidden] { display: none !important; }
.welcome-tag { font-family: var(--mono); color: var(--accent); font-size: 0.75rem; letter-spacing: 0.2em; }
.welcome h2 { font-family: var(--font-title); font-size: 1.5rem; margin: 0.5rem 0; letter-spacing: 0.05em; }
.welcome-desc { color: var(--muted); margin-bottom: 1.5rem; }
.quick-prompts { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.quick-btn {
  padding: 0.5rem 0.85rem; border-radius: 6px; cursor: pointer;
  background: var(--accent-dim); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font); font-size: 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.quick-btn:hover { border-color: var(--accent); box-shadow: 0 0 12px rgba(0,243,255,0.15); }

.messages {
  flex: 1; overflow-y: auto; padding: 1rem 1.25rem 0.5rem;
  display: flex; flex-direction: column; gap: 1.25rem;
}

.turn { display: flex; flex-direction: column; gap: 0.35rem; }
.turn-user { align-items: flex-end; }
.turn-assistant { align-items: flex-start; }
.turn-label {
  font-family: var(--font-title); font-size: 0.62rem; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase;
}
.turn-body { max-width: 92%; display: flex; flex-direction: column; gap: 0.5rem; }
.bubble {
  padding: 0.75rem 1rem; border-radius: var(--radius); line-height: 1.55; font-size: 0.95rem;
}
.user-bubble {
  background: var(--accent-dim); border: 1px solid rgba(0,243,255,0.25);
  white-space: pre-wrap; word-break: break-word;
}
.assistant-bubble {
  background: var(--surface-2); border: 1px solid var(--border);
}

.notice {
  align-self: center; font-size: 0.78rem; color: #a5b4fc;
  padding: 0.4rem 0.75rem; border: 1px dashed rgba(129,140,248,0.35);
  border-radius: 6px; background: rgba(129,140,248,0.06);
}

/* Markdown */
.markdown-body { font-size: 0.92rem; }
.markdown-body p { margin: 0.4rem 0; }
.markdown-body pre {
  background: #080c14; border: 1px solid var(--border); border-radius: 6px;
  padding: 0.75rem; overflow-x: auto; margin: 0.5rem 0;
}
.markdown-body code { font-family: var(--mono); font-size: 0.85em; }
.markdown-body :not(pre) > code {
  background: rgba(0,243,255,0.08); padding: 0.1rem 0.35rem; border-radius: 4px;
}
.markdown-body ul, .markdown-body ol { margin: 0.4rem 0; padding-left: 1.25rem; }

/* Tool blocks — Claude Code style */
.tool-block {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #080c14; overflow: hidden; font-size: 0.82rem;
}
.tool-block summary {
  cursor: pointer; padding: 0.5rem 0.75rem; list-style: none;
  display: flex; align-items: center; gap: 0.5rem;
  background: rgba(0,243,255,0.04); user-select: none;
}
.tool-block summary::-webkit-details-marker { display: none; }
.tb-icon { font-size: 0.9rem; }
.tb-name { font-family: var(--mono); color: var(--accent); font-weight: 500; }
.tb-state { margin-left: auto; font-size: 0.68rem; color: var(--muted); }
.tb-state.done { color: var(--friendly); }
.tool-block-body { padding: 0.5rem 0.75rem 0.75rem; }
.tool-input-pre, .tool-output-pre {
  margin: 0; font-family: var(--mono); font-size: 0.72rem;
  white-space: pre-wrap; word-break: break-all; color: #a5b4c8;
}

.terminal {
  font-family: var(--mono); font-size: 0.75rem;
  background: #05080f; border-radius: 6px; padding: 0.65rem; border: 1px solid #1a2535;
}
.term-cmd { color: var(--accent); margin-bottom: 0.35rem; }
.term-cmd .prompt { color: var(--friendly); margin-right: 0.35rem; }
.term-stdout { margin: 0; color: #c8d4e8; white-space: pre-wrap; }
.term-stderr { margin: 0.25rem 0 0; color: #f87171; white-space: pre-wrap; }
.term-exit { margin-top: 0.35rem; font-size: 0.65rem; color: var(--muted); }

.file-result code { color: var(--accent); font-family: var(--mono); }
.file-result pre { margin: 0.35rem 0 0; font-size: 0.72rem; max-height: 200px; overflow: auto; }

/* Composer */
.composer-wrap {
  border-top: 1px solid var(--border); background: rgba(5,8,16,0.9);
  padding: 0.65rem 1rem 0.85rem;
}
.composer-status {
  display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem;
  font-size: 0.78rem; color: var(--accent);
}
.composer-status[hidden] { display: none !important; }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.composer { display: flex; gap: 0.5rem; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 160px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 0.65rem 0.85rem; font-family: var(--font); font-size: 0.95rem;
}
.composer textarea:focus { outline: none; border-color: rgba(0,243,255,0.4); }
.btn-send { width: 44px; height: 44px; padding: 0; border-radius: 8px; font-size: 1.1rem; }

.btn-primary, .btn-ghost {
  border: none; border-radius: 6px; padding: 0.45rem 0.9rem;
  font-family: var(--font-title); font-weight: 600; font-size: 0.78rem;
  cursor: pointer; letter-spacing: 0.05em;
}
.btn-primary {
  background: linear-gradient(135deg, #00b8d4, var(--accent)); color: #021018;
  box-shadow: 0 0 16px rgba(0,243,255,0.25);
}
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 0.25rem 0.55rem; font-size: 0.7rem; }

/* Context panel */
.ctx-card { margin-bottom: 1rem; }
.ctx-card.muted { opacity: 0.85; }
.tool-chip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tool-chip-list li {
  display: inline-flex; align-items: center; gap: 0.2rem;
  padding: 0.2rem 0.45rem; border-radius: 999px; font-size: 0.62rem;
  background: var(--surface-2); border: 1px solid var(--border);
}
.tool-chip-list code { font-family: var(--mono); color: var(--accent); }

.session-stats { margin: 0; font-size: 0.8rem; }
.session-stats dt { color: var(--muted); font-size: 0.68rem; margin-top: 0.35rem; }
.session-stats dd { margin: 0.1rem 0 0; font-family: var(--mono); color: var(--accent); }

.parity-list { list-style: none; margin: 0; padding: 0; font-size: 0.75rem; }
.parity-list li { padding: 0.25rem 0; padding-left: 1rem; position: relative; }
.parity-list li::before { content: "○"; position: absolute; left: 0; color: var(--muted); }
.parity-list li.ok::before { content: "●"; color: var(--friendly); }
.parity-list li.pending::before { content: "◐"; color: var(--accent-2); }

.todo-panel { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.todo-panel[hidden] { display: none !important; }
.todo-panel h4 { margin: 0 0 0.5rem; font-size: 0.72rem; color: var(--accent); font-family: var(--font-title); }
.todo-badge { background: var(--accent-dim); padding: 0 0.35rem; border-radius: 999px; font-size: 0.65rem; }
#todo-list { list-style: none; margin: 0; padding: 0; }
.todo-item { font-size: 0.75rem; padding: 0.3rem 0; border-left: 2px solid var(--muted); padding-left: 0.5rem; margin-bottom: 0.25rem; }
.todo-item.todo-in_progress { border-color: #818cf8; color: #c7d2fe; }
.todo-item.todo-completed { opacity: 0.55; text-decoration: line-through; border-color: var(--friendly); }

.footer {
  display: flex; justify-content: space-between; padding: 0.5rem 1.25rem;
  font-size: 0.68rem; color: var(--muted); border-top: 1px solid var(--border);
  font-family: var(--mono);
}

@media (max-width: 1024px) {
  .workspace { grid-template-columns: 1fr; }
  .activity-panel, .context-panel { display: none; }
}
