/* Badmus AI — web console. Light is the default; dark follows the OS until the
   toggle is used, which pins the choice in localStorage. */

:root {
  --bg: #ffffff;
  --surface: #f0f4f9;
  --surface-2: #e9eef6;
  --edge: #dde3ec;
  --text: #1f1f1f;
  --dim: #5f6368;
  --accent: #2f6fed;
  --accent-soft: #e8effd;
  --on-accent: #ffffff;
  --ok: #1e9e5a;
  --warn: #b07418;
  --err: #d93025;
  --code-bg: #f6f8fb;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 8px 28px rgba(20, 30, 50, .09);
  --sidebar-w: 264px;
  --drawer-w: 360px;
  font-size: 15px;
}
:root[data-theme="dark"] {
  --bg: #131314;
  --surface: #1e1f20;
  --surface-2: #282a2c;
  --edge: #333537;
  --text: #e3e3e3;
  --dim: #9aa0a6;
  --accent: #8ab4f8;
  --accent-soft: #1e2a41;
  --on-accent: #0b1a33;
  --ok: #6dd58c;
  --warn: #e0b25a;
  --err: #f28b82;
  --code-bg: #1a1b1d;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #131314;
    --surface: #1e1f20;
    --surface-2: #282a2c;
    --edge: #333537;
    --text: #e3e3e3;
    --dim: #9aa0a6;
    --accent: #8ab4f8;
    --accent-soft: #1e2a41;
    --on-accent: #0b1a33;
    --ok: #6dd58c;
    --warn: #e0b25a;
    --err: #f28b82;
    --code-bg: #1a1b1d;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  overflow: hidden;
}
button { font: inherit; cursor: pointer; }
svg { stroke: currentColor; fill: none; }
code, pre { font-family: "Cascadia Code", Consolas, "SF Mono", monospace; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--surface);
  border-right: 1px solid var(--edge);
  display: flex; flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
}
.side-top { display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 700; letter-spacing: .3px; font-size: 1.05rem; }
.brand span { color: var(--accent); }
.new-session {
  display: flex; align-items: center; gap: 10px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid transparent; border-radius: 14px;
  padding: 10px 14px; font-weight: 600;
  transition: filter .15s ease;
}
.new-session svg { width: 18px; height: 18px; }
.new-session:hover { filter: brightness(.97); }
.side-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .8px;
  color: var(--dim); padding: 8px 8px 0;
}
.session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.session-item {
  display: flex; flex-direction: column; gap: 2px;
  border: none; background: transparent; color: var(--text);
  text-align: left; border-radius: 10px; padding: 8px 10px;
}
.session-item:hover { background: var(--surface-2); }
.session-item .s-title {
  font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-item .s-meta { font-size: .72rem; color: var(--dim); }
.session-item .s-actions { display: flex; gap: 6px; margin-top: 4px; }
.session-item .s-actions button {
  font-size: .72rem; padding: 2px 9px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--edge); color: var(--dim);
}
.session-item .s-actions button:hover { color: var(--text); }
.session-empty { color: var(--dim); font-size: .84rem; padding: 8px 10px; }
.side-bottom { display: flex; align-items: center; gap: 8px; }
.side-bottom .ghost { flex: 1; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: transparent; border: none; color: var(--dim);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.only-mobile { display: none; }

.scrim {
  position: fixed; inset: 0; background: rgba(10, 14, 22, .45);
  z-index: 30; border: none; padding: 0;
}

/* ── Shell ──────────────────────────────────────────────────────────────── */
.shell { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--edge);
}
.topbar-spacer { flex: 1; }
.conn { font-size: .78rem; color: var(--dim); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--err); }
.conn-on::before { background: var(--ok); }
.phase {
  font-size: .76rem; color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px; padding: 4px 12px;
}

.workarea { flex: 1; display: flex; min-height: 0; }
.conversation-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Conversation stream ────────────────────────────────────────────────── */
.stream {
  flex: 1; overflow-y: auto;
  padding: 22px 18px 10px;
  scroll-behavior: smooth;
}
.stream > * { max-width: 820px; margin-left: auto; margin-right: auto; }

.greeting { text-align: center; margin-top: 12vh; }
.greet-mark { font-weight: 700; letter-spacing: .3px; color: var(--dim); }
.greet-mark span { color: var(--accent); }
.greeting h1 {
  font-size: 2.1rem; font-weight: 600; margin: 14px 0 10px;
  background: linear-gradient(90deg, var(--accent), #9a5cf0);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.greet-sub { color: var(--dim); max-width: 460px; margin: 0 auto; line-height: 1.5; }

/* User bubble — filled, right-aligned. */
.msg-user {
  display: flex; justify-content: flex-end; margin: 14px 0;
}
.msg-user .bubble {
  background: var(--surface); color: var(--text);
  border-radius: 18px 18px 4px 18px;
  padding: 11px 16px; max-width: 78%;
  white-space: pre-wrap; word-break: break-word;
  font-size: .95rem;
}

/* Assistant turn — open text on the background, markdown-rendered. */
.msg-assistant { margin: 14px 0; font-size: .95rem; line-height: 1.6; }
.msg-assistant .who {
  display: flex; align-items: center; gap: 8px;
  font-size: .74rem; font-weight: 600; color: var(--accent);
  margin-bottom: 6px; letter-spacing: .4px;
}
.msg-assistant .who::before {
  content: ""; width: 18px; height: 18px; border-radius: 50%;
  background: conic-gradient(from 180deg, var(--accent), #9a5cf0, var(--accent));
  -webkit-mask: radial-gradient(circle 5px, transparent 98%, #000) center / 100% 100%;
          mask: radial-gradient(circle 5px, transparent 98%, #000) center / 100% 100%;
}
.msg-assistant .body { word-break: break-word; }
.msg-assistant .body > :first-child { margin-top: 0; }
.msg-assistant .body > :last-child { margin-bottom: 0; }
.msg-assistant.cursor-on .body::after {
  content: ""; display: inline-block; width: 8px; height: 15px;
  background: var(--accent); margin-left: 3px; vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Markdown inside assistant turns. */
.markdown p { margin: .45em 0; }
.markdown h1, .markdown h2, .markdown h3 { margin: .9em 0 .35em; line-height: 1.3; }
.markdown h1 { font-size: 1.25rem; } .markdown h2 { font-size: 1.12rem; } .markdown h3 { font-size: 1rem; }
.markdown ul, .markdown ol { margin: .45em 0; padding-left: 1.5em; }
.markdown li { margin: .2em 0; }
.markdown blockquote {
  margin: .6em 0; padding: 2px 12px; color: var(--dim);
  border-left: 3px solid var(--edge);
}
.markdown code.inline {
  background: var(--code-bg); border: 1px solid var(--edge);
  border-radius: 5px; padding: 1px 5px; font-size: .86em;
}
.markdown .codeblock {
  margin: .6em 0; border: 1px solid var(--edge); border-radius: 10px;
  overflow: hidden; background: var(--code-bg);
}
.markdown .codeblock .cb-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 10px; font-size: .72rem; color: var(--dim);
  border-bottom: 1px solid var(--edge); background: var(--surface);
}
.markdown .codeblock .cb-copy {
  border: none; background: transparent; color: var(--dim);
  font-size: .72rem; padding: 2px 8px; border-radius: 6px;
}
.markdown .codeblock .cb-copy:hover { background: var(--surface-2); color: var(--text); }
.markdown .codeblock pre { margin: 0; padding: 10px 12px; overflow-x: auto; font-size: .82rem; line-height: 1.5; }
.markdown a { color: var(--accent); }
.markdown hr { border: none; border-top: 1px solid var(--edge); margin: 1em 0; }

/* Event chips — the old log lines, promoted to quiet timeline markers. */
.chip {
  display: flex; align-items: baseline; gap: 8px;
  color: var(--dim); font-size: .8rem;
  margin: 7px 0; line-height: 1.45;
}
.chip .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--dim); position: relative; top: -1px; }
.chip.status .dot { background: var(--accent); }
.chip.tool .dot { background: var(--warn); }
.chip.err { color: var(--err); }
.chip.err .dot { background: var(--err); }
.chip.cmd { color: var(--ok); }
.chip.cmd .dot { background: var(--ok); }
.chip .txt { white-space: pre-wrap; word-break: break-word; }

/* Result / summary card. */
.summary-card {
  border: 1px solid var(--edge); border-left: 3px solid var(--ok);
  background: var(--surface); border-radius: 12px;
  padding: 12px 16px; margin: 14px 0;
}
.summary-card .sc-label {
  font-size: .7rem; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--ok); margin-bottom: 6px;
}
.summary-card .sc-body { font-size: .92rem; line-height: 1.55; }

/* ── Approval card ──────────────────────────────────────────────────────── */
.approval {
  max-width: 820px; width: calc(100% - 36px);
  margin: 0 auto 8px;
  background: var(--bg); border: 1px solid var(--warn);
  border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
}
.approval-head { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.approval-head b { word-break: break-all; }
.chip-icon { display: inline-flex; width: 18px; height: 18px; }
.chip-icon svg { width: 18px; height: 18px; }
.chip-icon.warn { color: var(--warn); }
.approval-diff {
  max-height: 200px; overflow: auto; font-size: .76rem; line-height: 1.5;
  background: var(--code-bg); border: 1px solid var(--edge);
  border-radius: 8px; padding: 8px 10px; margin: 10px 0;
  white-space: pre; }
.approval-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Composer ───────────────────────────────────────────────────────────── */
.composer { padding: 6px 18px 14px; }
.composer-row {
  max-width: 820px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--edge); border-radius: 26px;
  padding: 8px 10px 8px 8px;
  box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.composer-row:focus-within { border-color: var(--accent); }
.composer input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  color: var(--text); font: inherit; padding: 8px 4px;
}
.composer input::placeholder { color: var(--dim); }
.mode-switch { display: flex; background: var(--bg); border: 1px solid var(--edge); border-radius: 999px; padding: 3px; flex: none; }
.mode-btn {
  border: none; background: transparent; color: var(--dim);
  padding: 6px 14px; border-radius: 999px; font-size: .84rem; font-weight: 600;
}
.mode-btn.active { background: var(--accent); color: var(--on-accent); }
.round-btn {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  border: none; display: inline-flex; align-items: center; justify-content: center;
}
.round-btn svg { width: 19px; height: 19px; }
.round-btn.send { background: var(--accent); color: var(--on-accent); }
.round-btn.send:disabled { background: var(--surface-2); color: var(--dim); cursor: default; }
.round-btn.stop { background: transparent; border: 1px solid var(--edge); color: var(--err); }
.round-btn.stop:hover { background: var(--surface-2); }
.composer-hint {
  max-width: 820px; margin: 8px auto 0; text-align: center;
  font-size: .72rem; color: var(--dim);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
button.primary {
  background: var(--accent); color: var(--on-accent);
  border: none; border-radius: 10px; padding: 9px 18px; font-weight: 600;
}
button.primary:hover { filter: brightness(1.06); }
button.ghost {
  background: transparent; color: var(--dim);
  border: none; border-radius: 8px; padding: 7px 10px; font-size: .8rem;
}
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.danger-ghost {
  background: transparent; color: var(--err);
  border: 1px solid var(--edge); border-radius: 10px; padding: 9px 18px; font-weight: 600;
}
button.danger-ghost:hover { background: var(--surface-2); }
.wide { width: 100%; }

/* ── Drawer: plan + terminal ────────────────────────────────────────────── */
.drawer {
  width: var(--drawer-w); flex: none;
  border-left: 1px solid var(--edge);
  background: var(--bg);
  display: none; flex-direction: column; min-height: 0;
  padding: 12px; gap: 12px;
}
.drawer.open { display: flex; }
.panel {
  border: 1px solid var(--edge); border-radius: 12px;
  padding: 12px; overflow: hidden; display: flex; flex-direction: column; min-height: 0;
}
.panel h3 {
  margin: 0 0 8px; font-size: .74rem; color: var(--dim);
  text-transform: uppercase; letter-spacing: .8px;
}
.cwd { text-transform: none; letter-spacing: 0; color: var(--accent); }
.plan { margin: 0; padding-left: 20px; font-size: .86rem; }
.plan li { margin: 5px 0; }
.plan li[data-status="done"] { color: var(--ok); text-decoration: line-through; }
.plan li[data-status="in_progress"] { color: var(--accent); }
.plan li[data-status="cancelled"] { color: var(--err); }
#term-panel { flex: 1; }
.term {
  flex: 1; min-height: 160px; overflow-y: auto;
  background: var(--code-bg); border: 1px solid var(--edge); border-radius: 8px;
  padding: 8px; margin: 0 0 8px;
  font-size: .76rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-all;
}
#term-form input {
  width: 100%; background: var(--code-bg); border: 1px solid var(--edge);
  border-radius: 8px; color: var(--text); padding: 8px 10px;
  font: 13px "Cascadia Code", Consolas, monospace; outline: none;
}
#term-form input:focus { border-color: var(--accent); }

/* ── Login ──────────────────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login form {
  width: min(400px, 90vw); text-align: center;
  background: var(--surface); border: 1px solid var(--edge);
  border-radius: 18px; padding: 30px 26px; box-shadow: var(--shadow);
}
.login-brand { font-weight: 700; font-size: 1.1rem; margin-bottom: 14px; }
.login-brand span { color: var(--accent); }
.login h2 { margin: 0 0 8px; font-weight: 600; }
.login p { color: var(--dim); font-size: .86rem; line-height: 1.5; }
.login input {
  width: 100%; margin: 14px 0; padding: 11px 14px;
  background: var(--bg); border: 1px solid var(--edge); border-radius: 10px;
  color: var(--text); font: inherit; outline: none;
}
.login input:focus { border-color: var(--accent); }
.error { color: var(--err); font-size: .84rem; }

/* ── Small screens ──────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .drawer.open {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 35;
    width: min(420px, 92vw); box-shadow: var(--shadow);
  }
}
@media (max-width: 800px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 35;
    transform: translateX(-105%); transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-flex; }
  .msg-user .bubble { max-width: 88%; }
  .stream { padding: 16px 12px 8px; }
  .composer { padding: 6px 12px 12px; }
  .composer-hint { display: none; }
}
