:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --border: #e3e1dd;
  --accent: #c8643b;
  --ok: #2f8f5b;
  --warn: #b7860b;
  --err: #c0392b;
  --code: #f0eeea;
  --prompt-bg: #a94f28;
  --danger-bg: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --text: #e8e6e3;
    --muted: #8f949c;
    --border: #2c3036;
    --accent: #e8875b;
    --ok: #4cc38a;
    --warn: #e0b341;
    --err: #ef6b5b;
    --code: #262a30;
    --prompt-bg: #b5582c;
    --danger-bg: #b8352a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--prompt-bg); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 14px; cursor: pointer; min-height: 44px;
}
button.ghost { background: transparent; color: var(--muted); }
button.danger { background: var(--danger-bg); }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%;
}

/* Login */
#login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: min(360px, 100%); display: grid; gap: 14px; }
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.error { color: var(--err); margin: 0; min-height: 1em; font-size: 14px; }

/* App */
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
header {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0;
}
header select { flex: 1; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--err); flex: none; }
.dot.on { background: var(--ok); }
.state {
  margin: 8px 16px 0; padding: 10px 12px; border-radius: 12px; font-size: 13px;
  border: 1px solid var(--border); border-left: 4px solid var(--tone, var(--muted)); background: var(--surface);
}
.state.busy { --tone: var(--warn); }
.state.attn { --tone: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.state.ok { --tone: var(--ok); }
.state.bad { --tone: var(--err); }
.state.off { --tone: var(--muted); opacity: 0.85; }
.state-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.state-head strong { font-size: 15px; }
.since, .state-where { color: var(--muted); font-size: 12px; }
.state-detail { margin-top: 4px; overflow-wrap: anywhere; }
.state-where { margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-sid { margin-top: 2px; display: flex; gap: 8px; align-items: center; color: var(--muted); font: 11px ui-monospace, monospace; }
.state-sid span { overflow-wrap: anywhere; user-select: all; min-width: 0; }
.state-sid button { flex: none; padding: 2px 8px; font-size: 11px; }
.state.attn strong { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .state.attn strong { animation: none; } }
.q { margin-top: 8px; }
.q-title { font-weight: 600; }
.q-opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { border: 1px solid var(--accent); color: var(--text); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.ev.ask { border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.ev.ask .body { white-space: normal; }
.ev.answer.asks { border-left-color: var(--accent); }

#feed { flex: 1; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.ev { border-radius: 12px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); overflow-wrap: anywhere; }
.ev .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; margin-bottom: 4px; }
.ev .body { white-space: pre-wrap; }
.ev.prompt {
  align-self: flex-end; max-width: 85%;
  background: var(--prompt-bg); color: #fff; border: 0;
  border-radius: 16px 16px 4px 16px; font-weight: 500;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}
.ev.prompt .meta { color: rgb(255 255 255 / 0.8); justify-content: flex-end; }
.ev.prompt.queued { background: transparent; color: var(--text); border: 2px dashed var(--accent); }
.ev.prompt.queued .meta { color: var(--muted); }
.ev.answer { border-left: 3px solid var(--ok); }
.ev.answer.bad { border-left-color: var(--err); }
.ev.tool { padding: 6px 12px; background: transparent; font-size: 13px; }
.ev.tool .body { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.expandable { cursor: pointer; }
.ev.expandable.open .body { white-space: pre-wrap; overflow: visible; color: var(--text); }
.ev.tool .output { display: none; margin: 8px 0 0; padding: 8px; border-radius: 8px; background: var(--bg); font-size: 12px; max-height: 50vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.ev.tool.open .output { display: block; }
.ev.tool:has(.output) .body::before { content: '▸ '; }
.ev.tool.open:has(.output) .body::before { content: '▾ '; }
.ev.suggestion { cursor: pointer; border: 1px dashed var(--accent); background: transparent; }
.ev.suggestion .body { white-space: pre-wrap; }
.ev.tool.err .body { color: var(--err); }
.ev.wait { border-left: 3px solid var(--warn); }
.ev.system { background: transparent; border: 0; text-align: center; font-size: 12px; color: var(--muted); padding: 2px; }
.more { align-self: center; }

#compose {
  display: flex; gap: 8px; padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg);
}
#compose textarea { resize: none; max-height: 40vh; min-height: 44px; }
#compose button { flex: none; width: 48px; padding: 0; }

/* Answering a question from the phone */
.answer-form { display: grid; gap: 10px; margin-top: 4px; }
.answer-form .q { margin-top: 4px; display: grid; gap: 6px; }
.answer-form .q-opts { margin-top: 0; }
button.chip {
  min-height: 40px; padding: 6px 14px; background: transparent; color: var(--text);
  border: 1px solid var(--accent); border-radius: 999px; font-size: 14px;
}
button.chip[aria-pressed="true"] { background: var(--prompt-bg); color: #fff; border-color: var(--prompt-bg); }
.answer-form input { min-height: 40px; }
.answer-form button[type=submit] { justify-self: start; }
.answer-form button[type=submit]:disabled { opacity: 0.45; cursor: default; }

/* Away mode and approvals from the phone */
button.away { min-height: 36px; padding: 6px 12px; background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; font-size: 13px; }
button.away[aria-pressed="true"] { background: var(--prompt-bg); color: #fff; border-color: var(--prompt-bg); }
.decide { display: flex; flex-wrap: wrap; gap: 8px; }
.decide button { min-height: 40px; }
.decide button:disabled { opacity: 0.45; }
pre.plan {
  margin: 0; max-height: 40vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--code); border-radius: 8px; padding: 10px; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.state-detail.cmd {
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--code); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap;
}

/* Claude / AsaPlan tabs */
.tabs { display: flex; flex: none; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
button.tab { min-height: 36px; padding: 6px 12px; border-radius: 0; background: transparent; color: var(--muted); font-size: 13px; }
button.tab[aria-selected="true"] { background: var(--prompt-bg); color: #fff; }

/* AsaPlan */
#asaplan, #tasks { flex: 1; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 8px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.hcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; overflow-wrap: anywhere; }
.hcard summary { cursor: pointer; font-weight: 600; min-height: 28px; }
.hrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hrow strong { flex: 1; min-width: 0; }
button.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.hform { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
.hform button[type=submit] { justify-self: start; }
.hform textarea { resize: vertical; }
.ev.issue { padding: 8px 10px; }
.ev.issue .body { cursor: pointer; }
.issue-tools { margin-top: 8px; }
#task-list, #asaplan-projects { display: grid; gap: 8px; }

/* Tasks tab */
.task { display: grid; gap: 6px; padding: 8px 0; border-top: 1px solid var(--border); }
.task.done .task-text { color: var(--muted); text-decoration: line-through; }
.task-text { white-space: pre-wrap; overflow-wrap: anywhere; }
