:root {
  --bg: #0f1216; --panel: #161a20; --raise: #1d222a; --line: #2a313b; --text: #e7eaee; --muted: #9aa3ae;
  --accent: #e8b04a; --accent-ink: #1a1408; --good: #5cc98a; --bad: #ef6b6b; --mine: #2a3a52;
  --radius: 12px; font-family: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f4f5f7; --panel: #ffffff; --raise: #eef0f3; --line: #d9dde3; --text: #15181c; --muted: #5d6670; --mine: #dce8fb; --accent-ink: #1a1408; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--raise); border-radius: 10px; padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
a.button { display: block; margin-top: 16px; text-align: center; text-decoration: none; border-radius: 10px; padding: 9px 14px; border: 1px solid var(--line); color: inherit; }
a.button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: none; padding: 4px 6px; color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
textarea { resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.boot, .empty { color: var(--muted); padding: 24px; text-align: center; }
.error { color: var(--bad); font-size: 14px; margin: 8px 0; white-space: pre-wrap; }
.muted { color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-right: 6px; vertical-align: middle; }
.dot.on { background: var(--good); }

/* Claim screen */
.card { max-width: 420px; margin: 10vh auto; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card h1 { margin: 0 0 6px; font-size: 22px; }
.card form button { margin-top: 16px; width: 100%; }

/* Main layout */
.shell { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side header, .chat header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 56px; }
.side header h1 { font-size: 18px; margin: 0; flex: 1; }
.list { overflow-y: auto; flex: 1; padding: 6px; }
.list h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 8px 6px; }
.item { display: block; width: 100%; text-align: left; border: none; background: none; border-radius: 10px; padding: 10px; }
.item:hover { background: var(--raise); }
.item.active { background: var(--raise); outline: 1px solid var(--line); }
.item .sub { display: block; color: var(--muted); font-size: 12px; }
.status { padding: 10px 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

.chat { display: flex; flex-direction: column; min-height: 0; }
.chat header h2 { font-size: 16px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(720px, 88%); padding: 10px 13px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--mine); border-color: transparent; }
.msg .who { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.run { align-self: flex-start; font-size: 13px; color: var(--muted); padding: 2px 4px; }
.run.bad { color: var(--bad); }
.composer { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { min-height: 44px; max-height: 40vh; }
.composer button { align-self: flex-end; }

/* Setup panel */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; justify-content: flex-end; z-index: 10; }
.sheet > div { width: min(480px, 100%); height: 100%; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 0 18px 32px; }
.sheet header { display: flex; align-items: center; position: sticky; top: 0; background: var(--panel); padding: 14px 0; border-bottom: 1px solid var(--line); }
.sheet header h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.sheet section h3 { margin: 0 0 6px; font-size: 15px; }
.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.row > :first-child { flex: 1; }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-wrap: anywhere; user-select: all; margin: 8px 0; }

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .shell.open .side { display: none; }
  .shell:not(.open) .chat { display: none; }
  .back { display: inline-block; }
  .msg { max-width: 92%; }
}
.pad { padding: 0 10px; }
