: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; grid-template-rows: minmax(0, 1fr); height: 100dvh; overflow: hidden; }
.rail { border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--surface); min-height: 0; overflow: hidden; }
.main { min-height: 0; }
.rail-top { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.brand { font-weight: 600; font-size: 18px; }
.rail-nav { padding: 4px 8px 8px; display: grid; gap: 2px; border-bottom: 1px solid var(--line); }
.history-head { display: flex; align-items: center; gap: 6px; width: 100%; border: 0; background: none; text-align: left; padding: 10px 16px 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.history-head .chev { display: inline-block; transition: transform .15s; } .history-head[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.history-head .count { margin-left: auto; font-weight: 400; }
.sessions { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px; }
.sessions[hidden] { display: none; }
.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-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; }
.blocks > * { min-width: 0; max-width: 100%; }   /* scrollable children must not widen the column */
.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: 340px; width: 100%; background: var(--user-bubble); }
.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%; }
}

/* sessions with delete */
.session-row { display: flex; align-items: center; border-radius: 8px; }
.session-row:hover, .session-row.active { background: var(--bg); }
.session-row .session { flex: 1; } .session-row .session:hover { background: none; }
.session-del { border: 0; background: none; color: var(--muted); padding: 4px 8px; font-size: 16px; opacity: 0; }
.session-row:hover .session-del { opacity: 1; } .session-del:hover { color: var(--red); }

/* weather card */
.card.weather { color: #fff; border: 0; background: linear-gradient(135deg, #3d5a80, #6b8cae); }
.card.weather.clear, .card.weather.mostly-clear { background: linear-gradient(135deg, #3d8ef2, #66bff9); }
.card.weather.partly-cloudy { background: linear-gradient(135deg, #4c8cd9, #8cb3e0); }
.card.weather.rain, .card.weather.heavy-rain, .card.weather.showers, .card.weather.drizzle, .card.weather.sleet { background: linear-gradient(135deg, #40597f, #66809e); }
.card.weather.thunderstorm { background: linear-gradient(135deg, #333359, #595280); }
.card.weather.snow { background: linear-gradient(135deg, #8ca6cc, #bfd1ea); }
.card.weather.fog { background: linear-gradient(135deg, #808c9e, #a6adbd); }
.card.weather.night { background: linear-gradient(135deg, #1a244d, #0d1229); }
.card.weather { padding: 18px 18px 14px; border-radius: 16px; }
.wx-head { display: flex; justify-content: space-between; align-items: flex-start; }
.wx-loc { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; } .wx-cond { opacity: .9; font-size: 14px; } .wx-big { font-size: 46px; line-height: 1; filter: drop-shadow(0 2px 6px rgba(0,0,0,.25)); }
.wx-temp { display: flex; align-items: center; gap: 14px; margin: 2px 0 6px; } .wx-now { font-size: 64px; font-weight: 300; line-height: 1; letter-spacing: -0.02em; } .wx-hl { font-size: 13px; opacity: .92; line-height: 1.5; }
.wx-stats { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; opacity: .92; margin-bottom: 12px; white-space: normal; }
.wx-k { opacity: .7; margin-right: 2px; }
.wx-section { font-size: 12px; font-weight: 600; opacity: .8; margin: 0 0 6px 2px; }
.wx-hours { display: flex; gap: 6px; overflow-x: auto; padding: 8px 6px; background: rgba(255,255,255,.12); border-radius: 12px; margin-bottom: 10px; scrollbar-width: thin; }
.wx-h { text-align: center; font-size: 12px; flex: 0 0 48px; } .wx-h .wx-i { font-size: 22px; margin: 4px 0 2px; } .wx-h .wx-p { color: #a8dbff; font-size: 11px; height: 14px; } .wx-h .wx-t { font-weight: 500; font-size: 14px; }
.wx-days { background: rgba(255,255,255,.12); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; }
.wx-d { display: grid; grid-template-columns: 56px 28px 40px 40px minmax(60px, 1fr) 40px; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.18); font-size: 14px; } .wx-d:last-child { border-bottom: 0; }
.wx-d .wx-i { font-size: 18px; text-align: center; }
@media (max-width: 480px) { .wx-now { font-size: 52px; } .wx-d { grid-template-columns: 48px 26px 36px 36px 1fr 36px; font-size: 13px; } }
.wx-d .wx-p { color: #a8dbff; font-size: 11px; } .wx-d .wx-lo { opacity: .8; text-align: right; } .wx-d .wx-hi { font-weight: 500; text-align: right; }
.wx-bar { position: relative; height: 6px; background: rgba(255,255,255,.18); border-radius: 3px; } .wx-bar span { position: absolute; top: 0; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #66b3ff, #ffbf4d); }
.wx-outlook { font-size: 14px; opacity: .95; }

.btn-primary.btn-stop { background: var(--red); }
.steer { align-self: flex-end; margin: 6px 0 6px auto; max-width: 78%; border: 1px solid var(--line); border-radius: 14px; padding: 6px 12px; font-size: 14px; }
.interim { color: var(--muted); font-size: 14px; margin: 4px 0; padding-left: 14px; border-left: 2px solid var(--line); }
.routine-form { display: grid; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.routine-form textarea, .routine-form select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; background: var(--bg); color: var(--ink); }
.routine { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
.routine-head { display: flex; justify-content: space-between; align-items: center; }
.routine .actions { margin-top: 4px; } .meta.ok { color: var(--green); } .meta.err { color: var(--red); }
.card.file .actions { margin-top: 10px; }
.card.file a { text-decoration: none; display: inline-flex; align-items: center; }
