/* Autopilot base styles. Mobile-first, light/dark via prefers-color-scheme. Shared by all pages. */
:root {
  --bg: #f8fafc; --fg: #0f172a; --muted: #64748b; --card: #ffffff; --border: #e2e8f0;
  --accent: #2563eb; --accent-fg: #ffffff; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --user: #dbeafe; --assistant: #ffffff; --thinking: #f1f5f9; --system: #fef9c3;
  --radius: 12px; --gap: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --fg: #e2e8f0; --muted: #94a3b8; --card: #111827; --border: #1f2937;
    --user: #1e3a8a; --assistant: #111827; --thinking: #0f172a; --system: #422006; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
pre { white-space: pre-wrap; word-break: break-word; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; gap: 16px; align-items: center; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top)); background: #0f172a; color: #fff; overflow-x: auto; }
.topbar .brand { color: #fff; font-weight: 700; white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav-item { color: #cbd5e1; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.nav-item.active, .nav-item:hover { background: #1e293b; color: #fff; text-decoration: none; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 6px; border-radius: 9px; background: var(--danger);
  color: #fff; font-size: 12px; line-height: 18px; text-align: center; }
.content { max-width: 1100px; margin: 0 auto; padding: 16px; }
.content.narrow { max-width: 440px; padding-top: 12vh; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: var(--gap); }
.stack > * + * { margin-top: var(--gap); }
.row { display: flex; gap: var(--gap); align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.btn { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--card);
  color: var(--fg); cursor: pointer; font: inherit; }
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field > span { font-weight: 600; font-size: 14px; }
.form-field small { color: var(--muted); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--fg); width: 100%; }
textarea { min-height: 80px; resize: vertical; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--border); color: var(--fg); }
.pill.idle { background: #dcfce7; color: #166534; } .pill.working { background: #dbeafe; color: #1e40af; }
.pill.question, .pill.dialog { background: #fef3c7; color: #92400e; } .pill.offline, .pill.archived { background: #e5e7eb; color: #374151; }
.pill.starting { background: #e0e7ff; color: #3730a3; } .pill.asleep, .pill.suspended { background: #ede9fe; color: #5b21b6; }
.pill.failed, .pill.rolled_back { background: #fee2e2; color: #991b1b; } .pill.live { background: #dcfce7; color: #166534; }
/* chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 140px); height: calc(100dvh - 140px); }
.chat-header { display: flex; align-items: center; gap: 10px; padding-bottom: 8px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px 2px; }
.msg { max-width: 85%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--assistant); }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg.user { align-self: flex-end; background: var(--user); }
.msg.assistant { align-self: flex-start; }
.msg.thinking { align-self: flex-start; background: var(--thinking); color: var(--muted); font-style: italic; font-size: 14px; }
.msg.system { align-self: center; background: var(--system); font-size: 13px; }
.msg.pending { opacity: .7; border-style: dashed; }
.composer { display: flex; gap: 8px; padding-top: 8px; padding-bottom: env(safe-area-inset-bottom); }
.composer textarea { flex: 1; min-height: 44px; max-height: 200px; }
.question { border: 2px solid var(--warn); }
.tree ul { list-style: none; padding-left: 20px; border-left: 1px dashed var(--border); }
.tree > ul { padding-left: 0; border-left: none; }
.tree li { margin: 8px 0; }
.md p:first-child { margin-top: 0; } .md p:last-child { margin-bottom: 0; }
.md pre { background: var(--thinking); padding: 8px; border-radius: 8px; overflow-x: auto; }
.screen { background: #0b1120; color: #e2e8f0; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; line-height: 1.25; }
@media (max-width: 640px) { .msg { max-width: 95%; } .content { padding: 10px; } }
/* chat, notifications, settings */
[hidden] { display: none !important; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.small { font-size: 13px; }
.btn-small { padding: 4px 10px; font-size: 13px; }
.cell-action { text-align: right; white-space: nowrap; }
.chat { position: relative; }
.chat-switcher { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; flex: none; }
.chat-switcher::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--fg);
  font-size: 14px; white-space: nowrap; }
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip-state { margin-left: 6px; font-size: 12px; opacity: .75; }
.chat-header { flex: none; }
.chat-title { flex: 1; min-width: 0; }
.chat-title h1 { margin: 0; font-size: 18px; line-height: 1.3; }
.chat-sub { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-log { overscroll-behavior: contain; }
.chat-log .md { overflow-wrap: anywhere; }
.chat-log .md table { border-collapse: collapse; display: block; overflow-x: auto; }
.chat-log .md th, .chat-log .md td { border: 1px solid var(--border); padding: 4px 8px; }
.chat-log .md img { max-width: 100%; }
.msg .meta { display: flex; gap: 8px; align-items: baseline; }
.msg .meta time { margin-left: auto; }
.msg .sender { font-weight: 600; }
details.msg > summary { cursor: pointer; list-style: none; }
details.msg > summary::-webkit-details-marker { display: none; }
details.msg > summary::before { content: "▸"; font-style: normal; }
details.msg[open] > summary::before { content: "▾"; }
details.msg[open] > summary { margin-bottom: 6px; }
details.msg:not([open]) { padding-top: 6px; padding-bottom: 6px; }
details.msg .gist { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.msg.thinking { opacity: .85; }
.msg.from-autopilot { background: var(--thinking); }
#chat-outbox { display: flex; flex-direction: column; gap: 8px; }
.msg.outbox .outbox-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.outbox.pending, .msg.outbox.queued { opacity: .75; border-style: dashed; }
.msg.outbox.failed, .msg.outbox.uncertain { border-color: var(--danger); }
.msg.outbox.failed .delivery, .msg.outbox.uncertain .delivery { color: var(--danger); }
.outbox-edit { margin-top: 6px; }
.chat-notice { align-self: center; margin: 4px 0; font-size: 13px; text-align: center; }
.chat-working { align-self: flex-start; padding: 2px 4px; color: var(--muted); font-size: 14px; }
.chat-working .dots span { animation: ap-blink 1.4s infinite both; }
.chat-working .dots span:nth-child(2) { animation-delay: .2s; }
.chat-working .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes ap-blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .chat-working .dots span { animation: none; } }
.chat-jump { position: sticky; bottom: 8px; align-self: center; z-index: 1; box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.chat-offline { position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 2; margin: 0; padding: 2px 10px;
  border-radius: 999px; background: var(--warn); color: #fff; font-size: 12px; }
.chat-question { flex: none; margin: 4px 0 8px; max-height: 40%; overflow-y: auto; }
.question-prompt { margin-top: 0; font-weight: 600; white-space: pre-wrap; }
.question-options { display: flex; flex-wrap: wrap; gap: 8px; }
.question-text { margin-top: 8px; flex-wrap: nowrap; }
.composer { flex: none; align-items: flex-end; }
.composer textarea { resize: none; }
.composer-actions { display: flex; flex-direction: column; gap: 4px; }
.composer-actions .btn { padding: 6px 12px; }
.notifications-head { justify-content: space-between; }
.notification .row { gap: 8px; }
.notification.unread { border-left: 4px solid var(--accent); }
.notification-body { margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
