:root {
  --bg: #f6f5f2; --panel: #fff; --text: #1d1d1b; --muted: #6b6a66; --line: #e3e1dc;
  --accent: #1f5f5b; --accent-text: #fff; --user: #e8f0ef; --warn: #fff4e0; --error: #a32020;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --panel: #1f1f1d; --text: #ecebe7; --muted: #9b9a95; --line: #33322f;
    --accent: #4fa39c; --accent-text: #0d1716; --user: #24302f; --warn: #3a3020; --error: #ff8a80; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 6px; padding: .5rem .9rem; background: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .5; cursor: default; }
button.link, button.tab { background: none; color: var(--muted); padding: .4rem .6rem; }
button.tab.active { color: var(--text); font-weight: 600; }
input, textarea { font: inherit; width: 100%; padding: .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }
.error { color: var(--error); min-height: 1.5em; }

.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1.5rem; width: min(360px, 100%); display: grid; gap: .8rem; }
.card h1 { margin: 0; font-size: 1.4rem; }
.card label { display: grid; gap: .3rem; color: var(--muted); }

.app { display: flex; flex-direction: column; height: 100%; }
.top { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem; padding: .5rem 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top button { white-space: nowrap; }
.top nav { flex: 1; display: flex; gap: .2rem; }

.chat { flex: 1; display: grid; grid-template-columns: 240px 1fr; min-height: 0; }
.sessions { border-right: 1px solid var(--line); padding: .8rem; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; }
.sessions ul { list-style: none; margin: 0; padding: 0; }
.sessions li button { width: 100%; text-align: left; background: none; color: var(--text); padding: .45rem .5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sessions li button.active { background: var(--user); }
.thread { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1rem 16px; display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 46rem; padding: .6rem .8rem; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.event { align-self: flex-start; color: var(--muted); font-size: .85rem; padding: 0 .2rem; }
.msg.error { color: var(--error); }
.approval { align-self: stretch; background: var(--warn); border-radius: 10px; padding: .8rem; display: grid; gap: .5rem; }
.approval pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .85rem; }
.approval .actions { display: flex; gap: .5rem; }
.composer { display: flex; gap: .5rem; padding: .7rem 16px; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { resize: vertical; }

.about { flex: 1; overflow-y: auto; padding: 1rem 16px; max-width: 48rem; }
.about .note { color: var(--muted); }
.about ul { padding-left: 1.2rem; }
.about li { margin: .3rem 0; }
.about small { color: var(--muted); display: block; }

@media (max-width: 700px) {
  .chat { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sessions { border-right: 0; border-bottom: 1px solid var(--line); max-height: 30vh; }
}
