/* Light is the default theme. Dark is opt-in via [data-theme="dark"] on <html>. */
:root {
  --bg: #f6f7fb;
  --bg-grad-1: #fff4ec;
  --panel: #ffffff;
  --panel-2: #f0f2f7;
  --line: #e2e5ee;
  --text: #1b1e28;
  --muted: #6b7185;
  --flame: #ff6a1a;
  --flame-2: #ff9500;
  --think: #1a73e8;
  --act: #e0322f;
  --act-glow: rgba(224,50,47,.18);
  --act-bg: rgba(224,50,47,.06);
  --ok: #1a9d57;
  --shadow: 0 20px 60px rgba(30,34,50,.14);
  --primary-fg: #2a1500;
}
:root[data-theme="dark"] {
  --bg: #0a0b0f;
  --bg-grad-1: #16121a;
  --panel: #12141c;
  --panel-2: #171a24;
  --line: #232838;
  --text: #e8eaf0;
  --muted: #8a90a6;
  --flame: #ff6a1a;
  --flame-2: #ffb020;
  --think: #4aa3ff;
  --act: #ff4d4d;
  --act-glow: rgba(255,77,77,.25);
  --act-bg: rgba(255,77,77,.04);
  --ok: #37d67a;
  --shadow: 0 30px 80px rgba(0,0,0,.5);
  --primary-fg: #1a0f00;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-grad-1) 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.55 ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100vh; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ── Auth ── */
#auth-view { align-items: center; justify-content: center; }
.auth-card {
  width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.brand { font-size: 26px; font-weight: 700; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.brand.small { font-size: 18px; }
.flame { filter: drop-shadow(0 0 8px var(--flame)); }
.tagline { color: var(--muted); margin: 6px 0 22px; }
.tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.tab { flex: 1; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  padding: 10px; border-radius: 10px; cursor: pointer; font: inherit; }
.tab.active { color: var(--text); border-color: var(--flame); box-shadow: inset 0 0 0 1px var(--flame); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input, .modal input, .modal select, .modal textarea {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; border-radius: 10px; font: inherit; outline: none;
}
.auth-form input:focus { border-color: var(--flame); }
.primary {
  background: linear-gradient(135deg, var(--flame), var(--flame-2)); color: var(--primary-fg);
  border: 0; padding: 12px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer;
}
.primary:hover { filter: brightness(1.06); }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font: inherit; }
.ghost:hover { color: var(--text); border-color: var(--flame); }
.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px; line-height: 1; }
.icon-btn:hover { color: var(--text); border-color: var(--flame); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.msg { margin-top: 12px; font-size: 13px; min-height: 18px; }
.msg.err { color: var(--act); }
.msg.ok { color: var(--ok); }

/* ── Topbar ── */
.topbar { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge { color: var(--muted); font-size: 12px; }
.badge b { color: var(--text); }

/* ── Stream ── */
.stream { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 18px; }
.turn { margin-bottom: 20px; max-width: 900px; }
.turn .who { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 4px; }
.turn.user .who { color: var(--flame-2); }
.turn.think .who { color: var(--think); }
.turn.act .who { color: var(--act); }
.turn .body { white-space: pre-wrap; word-break: break-word; }
.turn.think .body { border-left: 2px solid var(--think); padding-left: 12px; }
.turn.act .body {
  border-left: 2px solid var(--act); padding-left: 12px; background: var(--act-bg);
  border-radius: 0 8px 8px 0; padding: 8px 12px;
}
.turn .status { font-size: 12px; color: var(--muted); margin-top: 6px; font-style: italic; min-height: 16px; }
.cursor::after { content: "▋"; color: var(--muted); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ── ACT live activity panel: makes "CHIP is working" unmistakable ── */
.act-activity {
  margin-top: 10px; padding: 10px 12px;
  border: 1px solid var(--act); border-radius: 8px;
  background: var(--act-bg); box-shadow: 0 0 0 3px var(--act-glow);
  display: flex; flex-direction: column; gap: 6px;
}
.act-activity .act-now { display: flex; align-items: center; gap: 8px; }
.act-activity .act-spin {
  width: 13px; height: 13px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid var(--act); border-top-color: transparent;
  animation: act-spin .8s linear infinite;
}
@keyframes act-spin { to { transform: rotate(360deg); } }
.act-activity .act-label { font-weight: 700; color: var(--act); font-size: 13px; letter-spacing: .2px; }
/* Task timer — the live "working for …" / frozen "worked for …" readout. */
.act-activity .act-elapsed { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--act); font-size: 12px; font-weight: 600; }
/* Session timer — total worked time this session, kept visually secondary. */
.act-activity .act-session { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 11.5px; opacity: .85; }
/* Idle/ready: stop the spinner and turn it solid green so "done" reads at a glance. */
.act-activity .act-spin.done { animation: none; border-color: var(--ok, #3fb950); border-top-color: var(--ok, #3fb950); background: var(--ok, #3fb950); }
.act-activity .act-step { font-size: 12.5px; color: var(--text); opacity: .85; min-height: 15px; }
.act-activity .act-log { margin: 2px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.act-activity .act-log li { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.act-activity .act-log .act-log-dot { color: var(--flame-2); font-weight: 700; }
.act-activity .act-log .act-log-text { overflow-wrap: anywhere; }
.act-activity .act-stop {
  margin-left: 10px; padding: 3px 14px; font-size: 12px; font-weight: 700;
  color: var(--act); background: transparent; border: 1px solid var(--act);
  border-radius: 6px; cursor: pointer; flex: 0 0 auto;
  transition: background .15s ease, color .15s ease;
}
.act-activity .act-stop:hover { background: var(--act); color: #fff; }
.act-activity .act-stop:disabled { opacity: .55; cursor: default; }
.act-activity.stopping .act-spin { animation-duration: .4s; opacity: .5; }

/* ── Command bar ── */
.cmdbar { display: flex; align-items: center; gap: 10px; padding: 14px 18px;
  border-top: 1px solid var(--line); background: var(--panel); }
.plus { color: var(--flame); font-size: 22px; font-weight: 700; }
.mode {
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; cursor: pointer;
  font: inherit; font-weight: 700; letter-spacing: 1px; min-width: 76px; transition: all .15s;
}
.mode.think { color: var(--think); border-color: var(--think); box-shadow: 0 0 12px rgba(26,115,232,.2); }
.mode.act { color: #fff; background: var(--act); border-color: var(--act);
  box-shadow: 0 0 18px var(--act-glow); }
#cmd-input { flex: 1; background: transparent; border: 0; color: var(--text);
  font: inherit; font-size: 16px; outline: none; }
.send { background: transparent; border: 0; color: var(--flame); font-size: 20px; cursor: pointer; }
.send:disabled { color: var(--muted); cursor: default; }

/* ── Admin ── */
.admin-body { padding: 22px; overflow-y: auto; }
.admin-body h2 { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; margin-top: 24px; }
.table { display: flex; flex-direction: column; gap: 8px; }
.row { display: grid; grid-template-columns: 1.6fr .7fr .8fr 1fr auto; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.row .email { font-weight: 600; }
.row .status { font-size: 12px; }
.status.approved { color: var(--ok); }
.status.waitlisted { color: var(--flame-2); }
.status.suspended { color: var(--act); }
.row .muted { color: var(--muted); font-size: 12px; }

/* ── Modal ── */
.modal { position: fixed; inset: 0; background: rgba(10,12,20,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { width: min(520px, 94vw); max-height: 90vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.modal-card h3 { margin-top: 0; }
.modal-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.modal-card textarea { min-height: 60px; resize: vertical; }
.aws { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.aws legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ── Settings ── */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-of-type { border-bottom: 0; }
.setting-row .label { font-size: 14px; color: var(--text); }
.setting-row .sub { font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { background: var(--panel-2); color: var(--muted); border: 0; padding: 7px 16px; cursor: pointer; font: inherit; }
.seg button.active { background: var(--flame); color: var(--primary-fg); font-weight: 700; }

/* ── CHIP message formatting (Think + ACT bodies) ── */
.turn .body .chip-p { margin: 0 0 10px; line-height: 1.55; }
.turn .body .chip-p:last-child { margin-bottom: 0; }
.turn .body .chip-h { font-weight: 700; font-size: 15px; margin: 14px 0 8px; }
.turn .body .chip-h:first-child { margin-top: 0; }
.turn .body .chip-list { margin: 0 0 10px; padding-left: 22px; line-height: 1.55; }
.turn .body .chip-list li { margin: 3px 0; }
.turn .body .code-block {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; margin: 4px 0 10px; overflow-x: auto;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5;
  white-space: pre;
}
.turn .body .inline-code {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 5px; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px;
}
.turn .body .action-line {
  display: flex; align-items: baseline; gap: 8px; margin: 2px 0 8px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px;
  color: var(--muted);
}
.turn .body .action-line .action-dot { color: var(--flame-2); font-weight: 700; }
.turn .body .action-line .action-text { overflow-wrap: anywhere; }
/* Formatted bodies build their own blocks — pre-wrap would double the gaps. */
.turn.act .body, .turn.think .body { white-space: normal; }

/* ── Settings: top options (Profile, …) ── */
.settings-top { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.settings-option {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; font: inherit; color: var(--text);
}
.settings-option:hover { border-color: var(--flame); }
.settings-option .so-icon {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; font-size: 17px;
}
.settings-option .so-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.settings-option .so-label { font-size: 14px; font-weight: 700; }
.settings-option .so-sub { font-size: 12px; color: var(--muted); }
.settings-option .so-chev { color: var(--muted); font-size: 20px; }

/* ── Profile modal ── */
.profile-card { width: min(760px, 96vw); padding: 0; overflow: hidden; }
.profile-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.profile-head h3 { margin: 0; }
.profile-body { display: flex; min-height: 440px; max-height: 78vh; }
.profile-nav {
  flex: none; width: 210px; border-right: 1px solid var(--line); padding: 12px;
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto; background: var(--panel-2);
}
.profile-nav .pnav {
  text-align: left; background: transparent; border: 0; border-radius: 9px;
  padding: 10px 12px; cursor: pointer; font: inherit; color: var(--muted); font-size: 13px;
}
.profile-nav .pnav:hover { color: var(--text); background: var(--panel); }
.profile-nav .pnav.active { color: var(--text); background: var(--panel); box-shadow: inset 0 0 0 1px var(--flame); font-weight: 700; }
.profile-pane { flex: 1; min-width: 0; padding: 20px 22px; overflow-y: auto; }
.pf-title { margin: 0 0 16px; font-size: 17px; }
.pf-intro { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.pf-sub-h { margin: 22px 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

.pf-identity { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.pf-avatar {
  width: 54px; height: 54px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: linear-gradient(135deg, var(--flame), var(--flame-2)); color: var(--primary-fg);
  font-weight: 700; font-size: 24px;
}
.pf-who .pf-name { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.pf-who .pf-role { font-size: 12px; color: var(--muted); }

.pf-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.pf-label { font-size: 12px; color: var(--muted); }
.pf-value { font-size: 14px; overflow-wrap: anywhere; }
.profile-pane input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 13px; border-radius: 10px; font: inherit; outline: none; width: 100%;
}
.profile-pane input:focus { border-color: var(--flame); }
.pf-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.pf-msg { margin-top: 12px; font-size: 13px; min-height: 18px; text-align: right; }
.pf-msg.ok { color: var(--ok); }
.pf-msg.err { color: var(--act); }

.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.on { color: var(--ok); border-color: var(--ok); }
.pill.off { color: var(--muted); }

.conn-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.conn-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px;
  padding: 10px 12px; cursor: pointer; font: inherit; color: var(--text);
  border-left: 3px solid var(--brand, var(--line)); transition: border-color .12s, background .12s;
}
.conn-btn:hover { border-color: var(--brand, var(--flame)); }
.conn-btn .conn-badge {
  width: 26px; height: 26px; flex: none; display: grid; place-items: center;
  border-radius: 7px; color: #fff; font-size: 12px; font-weight: 700; line-height: 1;
}
.conn-btn .conn-label { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-btn .conn-mark { color: var(--ok); font-weight: 700; }
.conn-btn.connected { background: color-mix(in srgb, var(--ok) 9%, var(--panel-2)); border-color: var(--ok); }
@media (max-width: 620px) { .conn-grid { grid-template-columns: 1fr; } }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.toggle-row:last-of-type { border-bottom: 0; }
.toggle-text { min-width: 0; }
.toggle-name { font-size: 14px; font-weight: 600; }
.toggle-sub { font-size: 12px; color: var(--muted); }
.toggle-extra { padding: 0 0 14px; }
.switch { flex: none; width: 46px; height: 26px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; position: relative; padding: 0; transition: background .15s; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: left .15s, background .15s; }
.switch.on { background: var(--flame); border-color: var(--flame); }
.switch.on .knob { left: 22px; background: var(--primary-fg); }

.sess-list { display: flex; flex-direction: column; gap: 8px; }
.sess-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.sess-when { font-size: 13px; }
.sess-ip { font-size: 11px; color: var(--muted); }

.bill-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 18px; background: var(--panel-2); }
.bill-plan { font-size: 18px; font-weight: 700; }
.bill-plan-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

@media (max-width: 620px) {
  .profile-body { flex-direction: column; min-height: 0; }
  .profile-nav { width: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .profile-nav .pnav { white-space: nowrap; }
}

/* ── Add-ons marketplace ─────────────────────────────────────────────────────
   Cards, not switches: a priced card reads as a purchase, a toggle reads as a
   free flip. Locked cards stay visible so the catalog itself does the selling. */
.addon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 4px 0 16px; }
.addon-card {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.addon-card:hover { border-color: var(--flame); box-shadow: 0 2px 14px rgba(255,106,26,.10); }
.addon-card.active { border-color: var(--flame); background: linear-gradient(180deg, rgba(255,148,0,.05), transparent); }
.addon-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.addon-name { font-weight: 650; font-size: 15px; color: var(--text); }
.addon-price { font-size: 13px; font-weight: 600; color: var(--flame); white-space: nowrap; }
.addon-blurb { font-size: 13px; line-height: 1.45; color: var(--muted); flex: 1; }
.addon-note { font-size: 12px; color: var(--muted); opacity: .85; font-style: italic; }
.addon-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.addon-foot button { padding: 7px 12px; font-size: 13px; }
.addon-summary { border-top: 1px solid var(--line); padding-top: 12px; }
.addon-total { font-size: 17px; font-weight: 650; color: var(--text); }
.addon-total-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Plan chooser */
.plan-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.plan-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--panel);
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.plan-card.current { border-color: var(--flame); background: linear-gradient(180deg, rgba(255,148,0,.06), transparent); }
.plan-name { font-weight: 650; }
.plan-price { font-size: 20px; font-weight: 700; color: var(--text); }
.plan-cap { font-size: 12px; color: var(--muted); flex: 1; }
.plan-card button { width: 100%; margin-top: 4px; }

/* Billing line items */
.bill-lines { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.bill-line { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }
.bill-line-name { color: var(--muted); }
.bill-line-amt { color: var(--text); font-weight: 600; }
.bill-line-sub { font-size: 13px; color: var(--muted); }

/* Inline offer inside a CHIP reply — the door, shown at the wall. */
.addon-offer {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--flame); border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,148,0,.07), transparent);
  padding: 12px 14px; margin: 10px 0;
}
.addon-offer-info { flex: 1; min-width: 180px; }
.addon-offer-name { font-weight: 650; font-size: 14px; }
.addon-offer-blurb { font-size: 13px; color: var(--muted); line-height: 1.4; margin-top: 2px; }
.addon-tagline { font-size: 12px; color: var(--muted); margin-top: 1px; }
