:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef0f4; --text: #16181d; --muted: #5d6573; --border: #d9dde4;
  --accent: #2f6fde; --accent-text: #ffffff; --human: #e3ecfc; --good: #1f8a4c; --warn: #a86a00; --bad: #c23b3b;
  --radius: 12px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a; --surface: #1d2026; --surface-2: #262a31; --text: #e8eaee; --muted: #9aa2af; --border: #323741;
    --accent: #5b91f0; --accent-text: #0d1117; --human: #243452; --good: #46c07b; --warn: #e0a93a; --bad: #ef6b6b; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161a; --surface: #1d2026; --surface-2: #262a31; --text: #e8eaee; --muted: #9aa2af; --border: #323741;
  --accent: #5b91f0; --accent-text: #0d1117; --human: #243452; --good: #46c07b; --warn: #e0a93a; --bad: #ef6b6b; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); padding: 10px 14px; min-height: 44px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 6px 10px; min-height: 36px; font-size: 14px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.icon { border: none; background: transparent; font-size: 30px; line-height: 1; padding: 0 10px 4px 0; min-height: 44px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; padding: 32px 0; }
.error { color: var(--bad); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); }
.top-title { flex: 1; min-width: 0; }
#title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
main { max-width: 820px; margin: 0 auto; padding: 12px 16px 24px; }

.card { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-title { font-weight: 600; overflow-wrap: anywhere; }
.card-goal { margin: 4px 0 8px; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted); }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.pill.Active { color: var(--good); }
.pill.Inactive { color: var(--muted); }
.pill.Offline { color: var(--warn); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 12px; font-weight: 700; }

.status-bar { font-size: 14px; color: var(--muted); margin-bottom: 8px; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; background: var(--surface-2); border-color: transparent; }
.tab.active { background: var(--surface); border-color: var(--border); font-weight: 600; }

#chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.turn { max-width: 100%; border-radius: var(--radius); padding: 10px 12px; overflow-wrap: anywhere; }
.turn.Human { align-self: flex-end; max-width: 88%; background: var(--human); white-space: pre-wrap; }
.turn.Lead { background: var(--surface); border: 1px solid var(--border); }
.turn.Relayed { background: var(--surface-2); font-size: 14px; }
.turn.Relayed .body { white-space: pre-wrap; }
.turn.Note { font-size: 13px; color: var(--muted); padding: 2px 4px; white-space: pre-wrap; }
.turn .when { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.turn pre { overflow-x: auto; background: var(--surface-2); padding: 8px; border-radius: 8px; font-size: 13px; }
.turn code { font-size: 13px; }
.turn table, .detail table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 14px; }
.turn th, .turn td, .detail th, .detail td { border: 1px solid var(--border); padding: 4px 6px; }
.turn img, .detail img { max-width: 100%; }
.turn p:first-child, .detail p:first-child { margin-top: 0; }
.turn p:last-child, .detail p:last-child { margin-bottom: 0; }
summary { cursor: pointer; color: var(--muted); }

.composer { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end; padding: 8px 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: var(--bg); }
.composer textarea, .approval textarea { flex: 1; width: 100%; resize: vertical; min-height: 48px; max-height: 40vh; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.note { color: var(--muted); padding: 4px 2px; }

.approval .kind { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.approval .question { font-weight: 600; margin: 8px 0; }
.approval .detail { margin: 8px 0; font-size: 15px; overflow-wrap: anywhere; }
.approval .ruling { border-left: 3px solid var(--accent); padding: 4px 10px; margin: 8px 0; }
.approval .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.approval .actions button { flex: 1 1 auto; }

.toast { position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 10; max-width: 560px; margin: 0 auto; padding: 12px 14px;
  border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgba(0,0,0,.25); }

.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card label { display: block; margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.login-card input { display: block; width: 100%; margin-top: 4px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.login-card button { width: 100%; margin-top: 20px; }
