:root {
  color-scheme: dark;
  --font-mono: "Cascadia Code", "Fira Code", Consolas, "SFMono-Regular", monospace;
  --bg-main: #0a0e0a;
  --bg-panel: #0d120d;
  --bg-sidebar: #080c08;
  --bg-input: #0f160f;
  --bg-code: #070b07;
  --green: #00ff41;
  --green-dim: #0a6e24;
  --green-soft: #4a8a5a;
  --green-pale: #b6ffcb;
  --text-main: #c8f5c8;
  --text-bright: #e0ffe0;
  --text-dim: #5a7a5a;
  --border: #1a2e1a;
  --border-bright: #2a4a2a;
  --danger: #ff4a4a;
  --yellow: #d4ff00;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
}

body.locked {
  background: #000;
}

/* ── No-premium paywall screen ───────────────────── */
.no-premium-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 9999;
}

.no-premium-box {
  text-align: center;
  padding: 2.5rem 2rem;
  border: 1px solid var(--green);
  border-radius: var(--radius);
  background: var(--surface);
  max-width: 340px;
  width: 90%;
}

.no-premium-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: .75rem;
}

.no-premium-box h2 {
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 1.25rem;
  margin: 0 0 .5rem;
}

.no-premium-box p {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: .9rem;
  margin: 0 0 1.25rem;
}

.no-premium-link {
  display: inline-block;
  padding: .65rem 1.5rem;
  background: var(--green);
  color: #000;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: .95rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: opacity .2s;
}

.no-premium-link:hover {
  opacity: .85;
}

/* ── App shell ───────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  position: relative;
}

/* ── Sidebar (slide-in panel) ────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 90;
}

.sidebar-overlay.open {
  display: block;
  animation: fade-in 200ms ease;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  color: var(--green-soft);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversation-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease, transform 120ms ease;
}

.conversation-item:hover {
  background: rgba(0, 255, 65, 0.04);
  border-color: var(--border);
}

.conversation-item.active {
  background: rgba(0, 255, 65, 0.08);
  border-color: var(--green-dim);
}

.conversation-item:active {
  transform: scale(0.98);
}

.conversation-title {
  font-weight: 600;
  color: var(--green-pale);
}

.conversation-time {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Shared button styles ────────────────────────── */
.terminal-btn {
  background: transparent;
  border: 1px solid var(--border-bright);
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 8px 16px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease, transform 120ms ease;
}

.terminal-btn:hover {
  background: rgba(0, 255, 65, 0.08);
  border-color: var(--green-dim);
}

.terminal-btn:active {
  transform: scale(0.96);
}

/* ── Workspace (main column) ─────────────────────── */
.workspace {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

/* ── Top bar ─────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sidebar-toggle {
  background: transparent;
  border: 1px solid var(--border-bright);
  color: var(--green);
  font-size: 1.1rem;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 200ms ease, transform 120ms ease;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: rgba(0, 255, 65, 0.08);
}

.sidebar-toggle:active {
  transform: scale(0.92);
}

.brand-title {
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  font-weight: 700;
  color: var(--green);
  line-height: 1;
  letter-spacing: 0.06em;
}

.brand-dot {
  color: var(--green);
  text-shadow: 0 0 12px var(--green);
  animation: pulse-dot 2s ease-in-out infinite;
}

/* ── Terminal body (chat area) ───────────────────── */
.terminal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 24px;
  scroll-behavior: smooth;
}

/* ── Typing indicator ────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
  animation: fade-in 200ms ease;
}

.typing-indicator[hidden] {
  display: none;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

.typing-label {
  font-size: 0.78rem;
  color: var(--green-soft);
  letter-spacing: 0.04em;
}

/* ── Messages ────────────────────────────────────── */
.message {
  display: flex;
  gap: 16px;
  padding: 14px 16px;
  margin-bottom: 4px;
  border-radius: var(--radius);
  animation: msg-in 250ms ease;
  max-width: 960px;
  transition: background 200ms ease;
}

.message:hover {
  background: rgba(0, 255, 65, 0.02);
}

.msg-role {
  flex-shrink: 0;
  width: 48px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding-top: 2px;
}

.msg-body {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 10px;
}

.message.user .msg-role { color: var(--green); }
.message.ai .msg-role { color: var(--green); }
.message.system .msg-role { color: var(--yellow); }
.message.error .msg-role { color: var(--danger); }

.message.user .msg-body { color: var(--text-bright); }
.message.ai .msg-body { color: var(--green-pale); }
.message.system .msg-body { color: var(--yellow); }
.message.error .msg-body { color: var(--danger); }

.message p {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
}

.message ul,
.message ol {
  padding-left: 20px;
  display: grid;
  gap: 4px;
}

.message li { line-height: 1.65; }

.message code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-xs);
  background: rgba(0, 255, 65, 0.08);
  color: var(--green-pale);
}

.message strong { color: var(--green); font-weight: 700; }
.message em { font-style: italic; }

/* ── Code blocks ─────────────────────────────────── */
.code-block {
  overflow: hidden;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  background: var(--bg-code);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 255, 65, 0.03);
}

.code-block-language {
  color: var(--green-soft);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.copy-code-button {
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: 1px solid var(--border-bright);
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 200ms ease, transform 120ms ease;
}

.copy-code-button:hover {
  background: rgba(0, 255, 65, 0.08);
}

.copy-code-button:active {
  transform: scale(0.95);
}

.code-block pre {
  overflow-x: auto;
  padding: 14px;
}

.code-block code {
  display: block;
  padding: 0;
  background: transparent;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ── Composer bar ────────────────────────────────── */
.composer-bar {
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  padding: 12px 20px;
  flex-shrink: 0;
}

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.prompt-label {
  color: var(--green);
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  color: var(--text-bright);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 250ms ease, box-shadow 250ms ease;
}

#message-input:focus {
  border-color: var(--green-dim);
  box-shadow: 0 0 12px rgba(0, 255, 65, 0.08);
}

#message-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#message-input::placeholder {
  color: var(--text-dim);
}

.transmit-btn {
  background: rgba(0, 255, 65, 0.1);
  border: 1px solid var(--green-dim);
  color: var(--green);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 200ms ease, box-shadow 200ms ease, transform 120ms ease;
  white-space: nowrap;
}

.transmit-btn:hover {
  background: rgba(0, 255, 65, 0.18);
  box-shadow: 0 0 16px rgba(0, 255, 65, 0.15);
}

.transmit-btn:active {
  transform: scale(0.95);
}

.transmit-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Status bar ──────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.75rem;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--green-soft);
}

.status-right {
  color: var(--text-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.status-dot.busy {
  background: var(--yellow);
  box-shadow: 0 0 8px rgba(212, 255, 0, 0.5);
}

.status-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 6px rgba(255, 74, 74, 0.3);
}

/* ── Animations ──────────────────────────────────── */
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; text-shadow: 0 0 12px var(--green); }
  50% { opacity: 0.5; text-shadow: 0 0 4px var(--green); }
}

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ── CRT scanline overlay ────────────────────────── */
.workspace::before {
  content: "";
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
  pointer-events: none;
  z-index: 200;
}

/* ── Admin styles ────────────────────────────────── */
.admin-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 24px auto;
  padding-bottom: 24px;
  font-family: var(--font-mono);
}

.admin-card,
.admin-topbar {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-card { padding: 22px; }

.admin-copy,
.admin-error { margin: 0; color: var(--text-dim); }
.admin-error { color: var(--danger); margin-top: 12px; }

.admin-form {
  display: grid;
  gap: 10px;
  max-width: 420px;
  margin-top: 18px;
}

.admin-form input,
.admin-form select {
  background: var(--bg-input);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-xs);
  color: var(--text-main);
  font-family: var(--font-mono);
  padding: 10px 12px;
}

.admin-form button {
  background: rgba(0, 255, 65, 0.1);
  border: 1px solid var(--green-dim);
  color: var(--green);
  font-family: var(--font-mono);
  padding: 10px 16px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background 200ms ease;
}

.admin-form button:hover {
  background: rgba(0, 255, 65, 0.18);
}

.admin-app { display: grid; gap: 18px; }

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
}

.admin-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
}

.admin-form-compact { max-width: none; margin-top: 0; }

.admin-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.admin-card-header h2 { margin: 0; font-size: 1.2rem; }

.admin-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  margin-bottom: 14px;
  align-items: center;
}

.admin-search-row input {
  background: var(--bg-input);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-xs);
  color: var(--text-main);
  font-family: var(--font-mono);
  padding: 10px 12px;
}

.admin-summary {
  display: flex;
  gap: 14px;
  color: var(--text-dim);
  font-size: 0.78rem;
  white-space: nowrap;
}

.admin-table-wrap { overflow: auto; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}

.admin-table tbody tr { cursor: pointer; }
.admin-table tbody tr:hover { background: rgba(0, 255, 65, 0.04); }

/* ── Mobile ──────────────────────────────────────── */
@media (max-width: 600px) {
  .topbar { padding: 12px 14px; }
  .topbar-left { gap: 10px; }
  .brand-title { font-size: 1.1rem; }
  .eyebrow { font-size: 0.58rem; }

  .terminal-banner { padding: 12px 14px; font-size: 0.75rem; }
  .chat-log { padding: 12px 14px 20px; }

  .composer-bar { padding: 10px 14px; }
  .prompt-label { display: none; }
  #message-input { font-size: 0.85rem; padding: 8px 10px; }
  .transmit-btn { padding: 8px 14px; font-size: 0.8rem; }

  .message { gap: 10px; }
  .msg-role { width: 38px; font-size: 0.7rem; }

  .sidebar { width: 260px; }

  .admin-shell { width: min(100vw - 16px, 100%); margin: 8px auto; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-search-row { grid-template-columns: 1fr; }
  .admin-summary { white-space: normal; }
}