:root {
  --bg: #F6F7F4; --surface: #FFFFFF; --ink: #1B1F1D; --muted: #6B716D; --line: #E1E4DF;
  --accent: #1F5F5B; --accent-soft: #DCEDE9; --accent-ink: #143F3C;
  --amber: #B8791E; --amber-soft: #F6ECD9; --red: #B3402E; --red-soft: #F7E3DF; --green: #2F7D4F;
  --user-bubble: #E9ECE7; --radius: 12px; --font: "Schibsted Grotesk", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151816; --surface: #1E2220; --ink: #ECEFEA; --muted: #9AA19C; --line: #2C312E;
    --accent: #7FC6BC; --accent-soft: #1E3431; --accent-ink: #BDE6DF; --amber-soft: #3A2E17; --red-soft: #3D211C; --user-bubble: #262B28; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }

.shell { display: grid; grid-template-columns: 240px 1fr auto; height: 100dvh; }
.rail { border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--surface); }
.rail-top { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.brand { font-weight: 600; font-size: 18px; }
.sessions { flex: 1; overflow-y: auto; padding: 4px 8px; }
.session { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session:hover, .session.active { background: var(--bg); }
.session.active { color: var(--accent-ink); font-weight: 500; }
.rail-bottom { border-top: 1px solid var(--line); padding: 8px; display: grid; gap: 2px; }
.rail-link { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; color: var(--muted); }
.rail-link:hover { background: var(--bg); color: var(--ink); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.topbar-title { font-weight: 500; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-status { color: var(--muted); font-size: 13px; }
.only-mobile { display: none; }

.thread { flex: 1; overflow-y: auto; padding: 24px 20px 8px; }
.thread-inner, .turn { max-width: 720px; margin: 0 auto; }
.turn { margin-bottom: 26px; }
.turn.user { display: flex; justify-content: flex-end; }
.turn.user .bubble { background: var(--user-bubble); border-radius: 18px 18px 4px 18px; padding: 10px 14px; max-width: 78%; white-space: pre-wrap; }
.turn.agent .answer { margin-bottom: 12px; }
.answer p { margin: 0 0 10px; } .answer p:last-child { margin: 0; }
.answer table { border-collapse: collapse; margin: 8px 0; } .answer td, .answer th { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.answer code { background: var(--user-bubble); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

.empty { max-width: 720px; margin: 10vh auto 0; }
.empty h1 { font-size: 28px; margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 0 0 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; }
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }

/* work trace — the one bold element */
.trace { border-left: 2px solid var(--accent); padding: 2px 0 2px 16px; margin: 6px 0 14px; }
.trace.done { border-left-color: var(--line); }
.trace-head { color: var(--muted); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.trace-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; }
.trace.done .dot { animation: none; background: var(--muted); }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }
@media (prefers-reduced-motion: reduce) { .trace-head .dot { animation: none; } }
.plan { list-style: none; margin: 8px 0 4px; padding: 0; }
.plan li { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; }
.plan .st { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--line); flex: none; position: relative; top: 2px; }
.plan .st.running { border-color: var(--amber); background: var(--amber-soft); }
.plan .st.done { border-color: var(--green); background: var(--green); }
.plan .st.failed { border-color: var(--red); background: var(--red-soft); }
.activity { margin: 6px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.activity li { padding: 1px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity .ok { color: var(--green); } .activity .err { color: var(--red); }
.activity .agent { color: var(--accent-ink); font-weight: 500; }
.trace-toggle { border: 0; background: none; color: var(--muted); padding: 0; font-size: 13px; text-decoration: underline; }
.trace.collapsed .plan, .trace.collapsed .activity { display: none; }

/* blocks */
.blocks { display: grid; gap: 10px; margin: 6px 0 12px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 12px 14px; }
.card.map { padding: 0; overflow: hidden; } .leaflet-map { height: 280px; width: 100%; }
.card-title { font-weight: 600; margin-bottom: 2px; }
.card-sub { color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin-top: 8px; }
.kv .k { color: var(--muted); }
.src { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.tbl { width: 100%; border-collapse: collapse; } .tbl th, .tbl td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); } .tbl th { color: var(--muted); font-weight: 500; }
.tbl tr:last-child td { border-bottom: 0; }
.list-item { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); align-items: baseline; } .list-item:last-child { border-bottom: 0; }
.list-item button { border: 0; background: none; padding: 0; text-align: left; color: var(--ink); }
.headline { font-size: 18px; font-weight: 600; } .caption { color: var(--muted); font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: 999px; padding: 8px 16px; font-weight: 500; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-secondary { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; }
.btn-secondary:hover { border-color: var(--accent); }
.btn-quiet { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; color: var(--muted); font-size: 13px; }
.btn-danger { background: var(--red-soft); color: var(--red); border: 0; border-radius: 999px; padding: 7px 14px; }
.followups { display: flex; flex-wrap: wrap; gap: 8px; }
hr.divider { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.card.ask { border-color: var(--amber); background: var(--amber-soft); }
.card.ask .card-title { color: var(--ink); }
.ask-form { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.ask-form input { flex: 1; min-width: 200px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font: inherit; background: var(--surface); color: var(--ink); }
.error { color: var(--red); }

.composer { border-top: 1px solid var(--line); padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--surface); }
.composer form { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; font: inherit; background: var(--bg); color: var(--ink); max-height: 160px; }
.composer textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.panel { width: 360px; border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; }
.panel[hidden] { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.panel-body { padding: 14px 16px; overflow-y: auto; display: grid; gap: 10px; align-content: start; }
.panel-body label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.panel-body input { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; background: var(--bg); color: var(--ink); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .meta { color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; inset: 0 30% 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .rail.open { transform: none; }
  .only-mobile { display: inline-block; }
  .panel { position: fixed; inset: 0; width: auto; z-index: 30; }
  .turn.user .bubble { max-width: 90%; }
}
