:root{
  --bg:#f3f5f4;--surface:#fff;--surface-2:#f8faf9;--text:#17201b;--muted:#5d6b63;--line:#dfe5e1;
  --accent:#2f6f4f;--accent-ink:#fff;--accent-soft:#e5f1ea;--me:#dcefe3;--danger:#c0392b;
  --warn:#7a5200;--warnbg:#fff3d1;--shadow:0 8px 30px rgba(20,40,30,.12);--radius:14px;--fs:15px;
}
:root[data-theme="dark"]{
  --bg:#0e1311;--surface:#161c19;--surface-2:#1b2320;--text:#e5ece8;--muted:#93a29a;--line:#27312c;
  --accent:#5fb48a;--accent-ink:#0b1410;--accent-soft:#1d2e25;--me:#21382b;--danger:#ef6b5b;--warn:#ffd27a;--warnbg:#3a2f12;--shadow:0 8px 30px rgba(0,0,0,.45);
}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
  --bg:#0e1311;--surface:#161c19;--surface-2:#1b2320;--text:#e5ece8;--muted:#93a29a;--line:#27312c;
  --accent:#5fb48a;--accent-ink:#0b1410;--accent-soft:#1d2e25;--me:#21382b;--danger:#ef6b5b;--warn:#ffd27a;--warnbg:#3a2f12;--shadow:0 8px 30px rgba(0,0,0,.45);
}}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--text);font:var(--fs)/1.5 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-text-size-adjust:100%}
[hidden]{display:none!important}
svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;flex:none}
button{font:inherit;color:inherit;cursor:pointer;border:0;background:none}
.primary,.danger,.ghost,.secondary{padding:.6rem 1rem;border-radius:10px;font-weight:600}
.primary{background:var(--accent);color:var(--accent-ink)}
.danger{background:var(--danger);color:#fff}
.ghost{border:1px solid var(--line);background:var(--surface)}
.secondary{background:var(--accent-soft);color:var(--accent)}
input,select,textarea{font:inherit;color:var(--text);background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:.6rem .7rem;width:100%}
input:focus,select:focus,textarea:focus,button:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
label{display:grid;gap:.3rem;font-weight:600;font-size:.9rem}
.muted{color:var(--muted)}.small{font-size:.82rem}.error{color:var(--danger);min-height:1.2em;margin:0}

/* login */
.login{min-height:100%;display:grid;place-items:center;padding:16px;background:radial-gradient(circle at 30% 10%,var(--accent-soft),var(--bg) 60%)}
.login-card{background:var(--surface);border:1px solid var(--line);border-radius:20px;box-shadow:var(--shadow);padding:2rem 1.6rem;width:min(380px,100%);display:grid;gap:.9rem}
.login-card h1{margin:0;font-size:1.4rem}.login-card p.muted{margin:-.6rem 0 .2rem}
.login-logo{width:52px;height:52px}

/* app shell */
.app{height:100dvh;display:flex;flex-direction:column}
.topbar{position:relative;display:flex;align-items:center;gap:10px;padding:8px 12px;padding-top:max(8px,env(safe-area-inset-top));background:var(--surface);border-bottom:1px solid var(--line);z-index:20}
.brand{font-weight:700;flex:1;letter-spacing:.2px}
.icon-btn{position:relative;display:grid;place-items:center;width:40px;height:40px;border-radius:10px}
.icon-btn:hover{background:var(--surface-2)}
.avatar-btn{width:36px;height:36px;border-radius:50%;background:var(--accent-soft);color:var(--accent);font-weight:700}
.badge{position:absolute;top:6px;right:6px;width:9px;height:9px;border-radius:50%;background:var(--danger)}
.pill{margin-left:auto;background:var(--danger);color:#fff;border-radius:999px;padding:0 .5rem;font-size:.75rem;font-weight:700}
.menu{position:absolute;top:calc(100% + 6px);left:10px;background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow);padding:6px;min-width:230px;display:grid}
.menu button{display:flex;align-items:center;gap:12px;padding:.65rem .8rem;border-radius:10px;text-align:left}
.menu button:hover,.menu button.active{background:var(--accent-soft);color:var(--accent)}
.menu hr{border:0;border-top:1px solid var(--line);margin:4px 0}

.layout{flex:1;min-height:0;display:grid;grid-template-columns:minmax(360px,440px) 1fr}

/* assistant (left) */
.assistant{display:flex;flex-direction:column;min-height:0;background:var(--surface);border-right:1px solid var(--line)}
.assistant-head{display:flex;align-items:center;gap:12px;padding:12px 14px;border-bottom:1px solid var(--line)}
.bot-avatar{display:grid;place-items:center;width:42px;height:42px;border-radius:50%;background:var(--accent);color:#fff;font-weight:800;font-size:1.1rem;position:relative;flex:none}
.bot-avatar::after{content:"";position:absolute;right:0;bottom:1px;width:11px;height:11px;border-radius:50%;background:#3ccf7a;border:2px solid var(--surface)}
.bot-avatar.sm{width:28px;height:28px;font-size:.8rem}.bot-avatar.sm::after{display:none}
.assistant-id{display:grid;flex:1;min-width:0}.assistant-id span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.assistant-switch{width:auto;padding:.3rem .5rem;font-size:.85rem}
.thread{list-style:none;margin:0;padding:14px;overflow-y:auto;flex:1;display:flex;flex-direction:column;gap:12px;background:var(--surface-2)}
.row{display:flex;gap:8px;align-items:flex-end}.row.user{justify-content:flex-end}
.bubble{max-width:85%;padding:.6rem .85rem;border-radius:16px;white-space:pre-wrap;overflow-wrap:anywhere;background:var(--surface);border:1px solid var(--line)}
.row.user .bubble{background:var(--me);border-color:transparent;border-bottom-right-radius:4px}
.row.bot .bubble{border-bottom-left-radius:4px}
.row.error .bubble{border-color:var(--danger)}
.meta{display:block;font-size:.72rem;color:var(--muted);margin-top:.25rem}
.typing span{display:inline-block;width:7px;height:7px;margin:0 2px;border-radius:50%;background:var(--muted);animation:blink 1.2s infinite}
.typing span:nth-child(2){animation-delay:.2s}.typing span:nth-child(3){animation-delay:.4s}
@keyframes blink{0%,80%,100%{opacity:.25}40%{opacity:1}}
.empty{margin:auto;text-align:center;max-width:320px;display:grid;gap:12px;justify-items:center}
.empty .bot-avatar{width:64px;height:64px;font-size:1.6rem}
.chips{display:flex;flex-wrap:wrap;gap:8px;justify-content:center}
.chip{border:1px solid var(--line);background:var(--surface);border-radius:999px;padding:.4rem .8rem;font-size:.88rem}
.chip:hover{border-color:var(--accent);color:var(--accent)}
.composer{padding:10px 12px;padding-bottom:max(10px,env(safe-area-inset-bottom));border-top:1px solid var(--line);background:var(--surface);display:grid;gap:8px}
.ctx{display:flex;align-items:center;gap:8px;background:var(--accent-soft);color:var(--accent);border-radius:999px;padding:.25rem .4rem .25rem .8rem;font-size:.85rem;justify-self:start;max-width:100%}
.ctx span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ctx button{width:22px;height:22px;border-radius:50%}
.composer-row{display:flex;gap:8px;align-items:flex-end}
.composer textarea{resize:none;max-height:160px;border-radius:20px;padding:.6rem .9rem}
.send-btn{width:44px;height:44px;border-radius:50%;background:var(--accent);color:var(--accent-ink);display:grid;place-items:center;flex:none}

/* drafts */
.draft{border:2px dashed var(--accent);border-radius:var(--radius);padding:.75rem;background:var(--surface);display:grid;gap:.5rem;max-width:100%}
.draft.sent{border-style:solid;border-color:var(--line)}.draft.discarded{opacity:.55}
.draft-head{display:flex;gap:6px;align-items:center;font-weight:600;font-size:.9rem}
.status{margin-left:auto;font-size:.72rem;font-weight:700;text-transform:uppercase;letter-spacing:.4px;color:var(--muted)}
.flag{background:var(--warnbg);color:var(--warn);padding:.35rem .55rem;border-radius:8px;font-size:.84rem}
.actions{display:flex;gap:8px;flex-wrap:wrap}.actions button{padding:.45rem .8rem;font-size:.9rem}

/* workspace panel (right) */
.panel{display:flex;flex-direction:column;min-height:0;min-width:0}
.panel-head{display:flex;align-items:center;gap:8px;padding:12px 16px;border-bottom:1px solid var(--line);background:var(--surface)}
.panel-head h2{margin:0;font-size:1.1rem;flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.panel-body{flex:1;overflow-y:auto;padding:16px;display:grid;gap:14px;align-content:start}
.card{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);padding:16px;display:grid;gap:12px}
.card h3{margin:0;font-size:1rem}
.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:12px}
.stat{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);padding:14px;text-align:left}
.stat b{display:block;font-size:1.6rem}
.list{list-style:none;margin:0;padding:0;display:grid}
.list li{display:flex;align-items:center;gap:12px;padding:.6rem .5rem;border-radius:10px;cursor:pointer;min-width:0}
.list li:hover{background:var(--surface-2)}
.list .ava{width:40px;height:40px;border-radius:50%;display:grid;place-items:center;font-weight:700;color:#fff;flex:none}
.list .name{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.list .time{font-size:.75rem;color:var(--muted)}
.wa-msgs{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}
.wa-msgs li{max-width:85%;padding:.45rem .7rem;border-radius:12px;background:var(--surface);border:1px solid var(--line);overflow-wrap:anywhere;white-space:pre-wrap}
.wa-msgs li.me{align-self:flex-end;background:var(--me);border-color:transparent}
.wa-msgs .who{display:block;font-size:.75rem;font-weight:700;color:var(--accent)}
.sticky-bottom{position:sticky;bottom:0;padding-top:8px;background:linear-gradient(transparent,var(--bg) 40%)}
.tabs{display:flex;gap:6px}.tabs button{padding:.4rem .8rem;border-radius:999px;border:1px solid var(--line)}
.tabs button.active{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.seg{display:flex;border:1px solid var(--line);border-radius:10px;overflow:hidden}
.seg button{flex:1;padding:.5rem}.seg button.active{background:var(--accent);color:var(--accent-ink)}
.switch{display:flex;align-items:center;justify-content:space-between;gap:12px;font-weight:500}
.switch input{width:44px;height:24px;appearance:none;background:var(--line);border-radius:999px;position:relative;padding:0;border:0;cursor:pointer;flex:none}
.switch input::after{content:"";position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:50%;background:#fff;transition:.15s}
.switch input:checked{background:var(--accent)}.switch input:checked::after{left:23px}

dialog{border:1px solid var(--line);border-radius:16px;background:var(--surface);color:var(--text);width:min(520px,calc(100% - 32px));box-shadow:var(--shadow)}
dialog::backdrop{background:rgba(0,0,0,.45)}
dialog h2{margin-top:0}
dialog blockquote{white-space:pre-wrap;background:var(--surface-2);padding:.7rem;border-radius:10px;margin:0 0 1rem;overflow-wrap:anywhere}
menu{display:flex;justify-content:flex-end;gap:8px;padding:0;margin:0}
.toast{position:fixed;left:50%;bottom:calc(20px + env(safe-area-inset-bottom));transform:translateX(-50%);background:var(--text);color:var(--bg);padding:.6rem 1rem;border-radius:10px;z-index:50;max-width:calc(100% - 32px)}
.mobile-only{display:none}

/* mobile: Walter full screen, panels slide over */
@media (max-width:860px){
  .layout{grid-template-columns:1fr}
  .assistant{border-right:0}
  .panel{position:fixed;inset:0;z-index:30;background:var(--bg);transform:translateX(100%);transition:transform .22s ease;padding-top:env(safe-area-inset-top)}
  .panel.open{transform:none}
  .mobile-only{display:grid}
  .bubble{max-width:88%}
}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
.spacer{visibility:hidden}
