:root {
  --bg: #f4f1ec; --panel: #fbfaf7; --line: #e2dcd2; --text: #2b2724; --muted: #8a8178;
  --rust: #b5542b; --rust-soft: #f3e2d6; --me: #2f5d7c; --me-text: #fff;
  --ok: #3f8a4f; --wait: #a07c1e; --block: #b23a3a; --doing: #2f6fa8; --todo: #8a8178;
  --radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / .06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1917; --panel: #24211e; --line: #3a3531; --text: #ece6df; --muted: #9b9188;
    --rust: #e07a4a; --rust-soft: #3a2a20; --me: #3b6f93; --ok: #6cbf7c; --wait: #d6aa45; --block: #e06a6a;
    --doing: #6aa6db; --todo: #9b9188; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, sans-serif;
  display: grid; grid-template-columns: var(--left, 240px) minmax(0, 1fr) var(--right, 320px); }
button { font: inherit; color: inherit; cursor: pointer; }
aside, main { min-height: 0; }

/* conversations */
.convs { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px; font-weight: 700; font-size: 18px; }
.brand img { width: 36px; height: 36px; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.new { margin: 4px 12px 10px; padding: 8px; border: 1px dashed var(--line); background: none; border-radius: 10px; }
.convs ul { list-style: none; margin: 0; padding: 0 8px; overflow: auto; }
.convs li { padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.convs li.on { background: var(--rust-soft); }
.convs li b { display: block; font-weight: 600; font-size: 14px; }
.convs li span { font-size: 12px; color: var(--muted); }
.me { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* chat */
main { display: flex; flex-direction: column; }
header.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
header.top h1 { font-size: 16px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 4px 10px; }
.menu, .trains-btn { display: none; }
.log { flex: 1; overflow: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 760px; }
.msg img.av { width: 34px; height: 34px; flex: none; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: var(--me); color: var(--me-text); border-color: transparent; }
.msg.user { flex-direction: column; align-items: flex-end; gap: 2px; }
.uacts { display: flex; gap: 10px; font-size: 12px; opacity: 0; transition: opacity .15s; }
.msg.user:hover .uacts, .uacts.show { opacity: 1; }
.uacts a { color: var(--muted); } .uacts a:hover { color: var(--rust); }
.queued .bubble { opacity: .6; } .queued .uacts { opacity: 1; }

/* turn in progress */
.run { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.spin { width: 10px; height: 10px; border-radius: 50%; background: var(--doing); animation: pulse 1s infinite; }
.steps { list-style: none; margin: 0 0 8px; padding: 0; font-size: 13px; }
.steps li { margin: 2px 0; }
.steps summary { display: flex; gap: 8px; align-items: baseline; }
.steps .st { width: 1em; text-align: center; }
.steps .ok { color: var(--ok); } .steps .go { color: var(--doing); } .steps .err { color: var(--block); }
.steps .dur { margin-left: auto; color: var(--muted); font-size: 11px; }
.steps pre { margin: 4px 0 6px 20px; font-size: 12px; background: var(--bg); padding: 6px 8px; border-radius: 6px; white-space: pre-wrap; }
.typing::after { content: "▍"; animation: pulse .8s infinite; color: var(--rust); }
.stats { font-size: 11px; color: var(--muted); margin-top: 6px; }
.stopped { font-size: 12px; color: var(--block); margin-top: 6px; }
body.busy .send { background: var(--block); }

/* file previews + viewer */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 8px; }
.tile { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); cursor: zoom-in; display: flex; flex-direction: column; }
.tile .pv { height: 110px; display: grid; place-items: center; overflow: hidden; background: #fff; position: relative; }
.tile .pv > img, .tile .pv > video { width: 100%; height: 100%; object-fit: cover; }
.tile .pv.doc > img { object-fit: contain; background: #fff; }
.tile .pv iframe { position: absolute; top: 0; left: 0; width: 400%; height: 400%; transform: scale(.25); transform-origin: 0 0; border: 0; pointer-events: none; }
.tile .pv .ico { font-size: 34px; }
.tile .badge { position: absolute; left: 6px; top: 6px; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: rgb(0 0 0 / .6); color: #fff; }
.tile .dur { left: auto; right: 6px; top: auto; bottom: 6px; }
.tile .name { font-size: 12px; padding: 5px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .name small { color: var(--muted); }
.tile.audio { grid-column: span 2; cursor: default; }
.tile.audio .pv { height: auto; padding: 10px; background: var(--rust-soft); display: flex; gap: 10px; }
.tile.audio audio { width: 100%; }
.tile table { font-size: 10px; border-collapse: collapse; width: 100%; align-self: start; }
.tile td { border-bottom: 1px solid #eee; padding: 2px 6px; color: #333; white-space: nowrap; }
.viewer { position: fixed; inset: 0; z-index: 7; background: rgb(15 13 12 / .92); display: none; flex-direction: column; color: #eee; }
.viewer.open { display: flex; }
.viewer header { display: flex; align-items: center; gap: 12px; padding: 10px 14px; font-size: 14px; }
.viewer header b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer header a, .viewer header button { color: #eee; background: none; border: 1px solid #555; border-radius: 8px; padding: 3px 10px; font-size: 13px; }
.viewer .stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 56px 16px; position: relative; }
.viewer .stage > img { max-width: 100%; max-height: 100%; cursor: zoom-in; }
.viewer .stage.zoom { overflow: auto; place-items: start center; } .viewer .stage.zoom > img { max-width: none; max-height: none; cursor: zoom-out; }
.viewer .stage > video { max-width: 100%; max-height: 100%; }
.viewer .stage > iframe { width: min(1100px, 100%); height: 100%; border: 0; border-radius: 8px; background: #fff; }
.viewer .stage > pre, .viewer .stage > .tbl { background: #fff; color: #222; padding: 16px; border-radius: 8px; max-width: 900px; max-height: 100%; overflow: auto; }
.viewer .tbl table { border-collapse: collapse; } .viewer .tbl td, .viewer .tbl th { border: 1px solid #ddd; padding: 4px 10px; text-align: left; }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 30px; background: none; border: 0; color: #eee; padding: 10px; }
.viewer .prev { left: 6px; } .viewer .next { right: 6px; }
.viewer .sandbox { font-size: 12px; color: #c9b7a8; text-align: center; padding: 0 0 10px; }
.viewer .big { font-size: 80px; text-align: center; } .viewer .big audio { display: block; margin-top: 14px; width: min(480px, 80vw); }

/* dialogs (rewind, session view): shown with .open */
.modal { display: none; position: fixed; inset: 0; z-index: 6; background: rgb(0 0 0 / .35); place-items: center; padding: 16px; }
.modal > div { background: var(--panel); border-radius: 16px; padding: 18px 20px; width: min(460px, 100%); box-shadow: 0 10px 40px rgb(0 0 0 / .3); }
.modal h2 { margin: 0 0 8px; font-size: 17px; }
.modal label { display: flex; gap: 8px; font-size: 14px; margin: 6px 0; }
.modal .note { font-size: 13px; color: var(--muted); }
.modal .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal .btns a { padding: 6px 14px; border-radius: 10px; border: 1px solid var(--line); }
.modal .btns a.go { background: var(--rust); color: #fff; border-color: transparent; }
.bubble p { margin: 0 0 6px; } .bubble p:last-child { margin: 0; }
.event { align-self: center; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.event::before, .event::after { content: ""; width: 24px; height: 1px; background: var(--line); }

/* train card */
.train { margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.train h3 { margin: 0; padding: 8px 12px; font-size: 14px; background: var(--rust-soft); display: flex; justify-content: space-between; }
.train h3 span { font-weight: 400; color: var(--muted); font-size: 12px; }
.who { font-size: 11px; border-radius: 999px; padding: 1px 8px; white-space: nowrap; align-self: start; margin-top: 2px; color: var(--text); }
.who.agent { background: var(--rust-soft); } .who.robot { background: var(--line); } .who.person { background: color-mix(in srgb, var(--me) 22%, transparent); }
.mine .task { grid-template-columns: 22px 1fr; }
.mine .acts { grid-column: 2; display: flex; gap: 6px; margin-top: 4px; }
.mine .acts button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 2px 10px; font-size: 13px; }
.mine .acts button.ok { background: var(--ok); color: #fff; border-color: transparent; }
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
.caret { display: inline-block; width: 1em; color: var(--muted); transition: transform .15s; }
details[open] > summary .caret { transform: rotate(90deg); }
.kids { margin-left: 18px; border-left: 2px solid var(--line); }
.kids .task { border-top: 1px dashed var(--line); font-size: 13px; }
.roll { font-size: 11px; color: var(--muted); margin-left: 6px; }
.task { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 8px; align-items: start; padding: 7px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.task .after { display: block; font-size: 11px; color: var(--muted); }
.task .result { display: block; font-size: 12px; color: var(--muted); font-style: italic; }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; border: 2px solid currentColor; }
.s-done { color: var(--ok); } .s-done .dot { background: currentColor; }
.s-doing { color: var(--doing); } .s-doing .dot { animation: pulse 1.2s infinite; }
.s-waiting { color: var(--wait); } .s-blocked { color: var(--block); } .s-todo { color: var(--todo); }
.task > span:nth-child(2) { color: var(--text); }
.state { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
@keyframes pulse { 50% { opacity: .3; } }

/* ask card */
.ask { margin-top: 8px; border: 2px solid var(--rust); border-radius: 12px; padding: 10px 12px; }
.ask b { display: block; margin-bottom: 8px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices button { border: 1px solid var(--rust); background: none; color: var(--rust); border-radius: 999px; padding: 4px 12px; }
.choices button:hover { background: var(--rust); color: #fff; }
.ask input { margin-top: 8px; width: 100%; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }

/* composer */
form.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
form.composer .send { background: var(--rust); color: #fff; border: 0; border-radius: 12px; padding: 0 18px; height: 44px; font-weight: 600; }
.clip { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; width: 44px; height: 44px; font-size: 18px; flex: none; }

/* rich field: composer, ask answer, comment */
.field { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.field:focus-within { border-color: var(--rust); }
.rich { min-height: 42px; max-height: 40vh; overflow-y: auto; padding: 10px 12px; outline: none; overflow-wrap: anywhere; }
.rich:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.rich p, .rich ul, .rich ol, .rich pre, .rich blockquote { margin: 0 0 4px; }
.rich pre, .bubble pre { background: var(--bg); padding: 6px 8px; border-radius: 6px; overflow-x: auto; }
.rich blockquote, .bubble blockquote { border-left: 3px solid var(--line); padding-left: 8px; color: var(--muted); }
.field.small .rich { min-height: 36px; padding: 7px 10px; font-size: 14px; }
.field.drag { border-style: dashed; border-color: var(--rust); background: var(--rust-soft); }
.files { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 8px 0; }
.files:empty { display: none; }
.file { position: relative; display: flex; align-items: center; gap: 6px; max-width: 220px; padding: 4px 26px 4px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 12px; }
.file img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file small { color: var(--muted); }
.file button { position: absolute; top: 2px; right: 2px; border: 0; background: none; color: var(--muted); }
.bubble .file { padding-right: 6px; } .msg.user .file { color: var(--text); }
.ask .field { margin-top: 8px; }

/* trains panel */
.side { border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 14px; }
.side h2 { font-size: 14px; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.side .train { margin-bottom: 18px; }
.side .empty { text-align: center; color: var(--muted); font-size: 13px; }

a { color: inherit; text-decoration: none; } a:hover { text-decoration: underline; }
.choices button.action { background: var(--ok); border-color: var(--ok); color: #fff; }

/* side drawer (task, fiche): shown with .open */
.drawer { display: none; position: fixed; inset: 0 0 0 auto; width: min(var(--drawer, 440px), 100vw); z-index: 5; overflow: auto;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgb(0 0 0 / .18); padding: 16px 18px; }
.drawer .close { float: right; font-size: 20px; color: var(--muted); }
.drawer h2 { margin: 0 0 6px; font-size: 18px; }
.drawer .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.drawer h4 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.drawer .rule { font-size: 13px; padding: 6px 10px; border: 1px dashed var(--line); border-radius: 8px; margin-bottom: 6px; }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { margin: 0 0 10px; }
.hist .upd { font-size: 12px; color: var(--muted); }
.hist .upd b { color: var(--text); font-weight: 600; }
.cmt { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); font-size: 14px; }
.cmt header { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.cmt header b { color: var(--text); }
.cmt footer { font-size: 12px; margin-top: 4px; } .cmt footer a { color: var(--rust); }
.replies { list-style: none; margin: 8px 0 0 14px; padding: 0 0 0 10px; border-left: 2px solid var(--line); }

/* views: chat | tasks */
.views { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 0 12px 10px; }
.views a { text-align: center; padding: 6px 4px; white-space: nowrap; font-size: 13px; border-radius: 10px; font-size: 14px; border: 1px solid var(--line); }
.views a[data-view="chat"] { grid-column: 1 / -1; }
.views a.on { background: var(--rust); color: #fff; border-color: transparent; }
.views a:hover { text-decoration: none; }
.views .n { font-size: 11px; background: var(--block); color: #fff; border-radius: 999px; padding: 0 6px; margin-left: 4px; }
.tasks-view { display: none; grid-column: 2 / 4; min-height: 0; flex-direction: column; }
body.view-tasks .tasks-view:not(.kb-view), body.view-kb .kb-view { display: flex; }
body.view-tasks main, body.view-tasks .side, body.view-kb main, body.view-kb .side { display: none; }
.tv-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.tv-bar h1 { font-size: 16px; margin: 0 8px 0 0; }
.tv-bar input { flex: 1; min-width: 200px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); font: inherit; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 5px 12px; font-size: 13px; }
.seg button.on { background: var(--rust-soft); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.chips button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 12px; font-size: 13px; }
.chips button.on { border-color: var(--rust); color: var(--rust); background: var(--rust-soft); }
.chips .c { color: var(--muted); font-size: 11px; margin-left: 4px; }
.tv-body { flex: 1; overflow: auto; padding: 14px 16px; }
.tree { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); overflow: hidden; }
.tree .row { display: grid; grid-template-columns: 22px minmax(0, 1fr) 120px 110px 90px; gap: 10px; align-items: center; padding: 7px 12px; border-top: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.tree .row:first-child { border-top: 0; }
.tree .row.head { cursor: default; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); }
.tree .row:not(.head):hover { background: var(--bg); }
.tree .row .dot { margin-top: 0; }
.tree .row.root { background: var(--rust-soft); font-weight: 600; }
.tree .t { display: flex; align-items: baseline; gap: 4px; min-width: 0; }
.tree .t > span.tt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .tog { width: 1em; color: var(--muted); flex: none; }
.tree .conv { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.tree .due { font-size: 12px; color: var(--muted); }
.tree .row.dim { opacity: .55; }
.board { display: flex; gap: 12px; align-items: flex-start; min-height: 100%; }
.col { flex: 1 0 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.col h3 { margin: 2px 4px 8px; font-size: 13px; display: flex; justify-content: space-between; }
.col h3 span { color: var(--muted); font-weight: 400; }
.card { background: var(--bg); border: 1px solid var(--line); border-left: 4px solid currentColor; border-radius: 8px; padding: 7px 9px; margin-bottom: 8px; cursor: pointer; font-size: 13px; }
.card b { display: block; color: var(--text); font-weight: 500; font-size: 14px; }
.card .path { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.card .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; color: var(--muted); font-size: 11px; }
.empty-col { color: var(--muted); font-size: 12px; text-align: center; padding: 10px; }
.tree .row .t, .tree .row .due { color: var(--text); } .tree .row .due { color: var(--muted); }
.drawer .kidlist { font-size: 14px; }
.drawer .kidlist div { padding: 3px 0; }

@media (max-width: 1000px) {
  body { grid-template-columns: minmax(0, 1fr); } /* minmax: a long title must not widen the page */
  .convs { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 3; transform: translateX(-100%); transition: transform .2s; }
  .side { position: fixed; inset: auto 0 0 0; max-height: 70vh; z-index: 3; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; transform: translateY(100%); transition: transform .2s; }
  body.show-convs .convs, body.show-side .side { transform: none; }
  .menu, .trains-btn { display: inline-block; }
  .tasks-view { grid-column: 1; }
  .tree .row { grid-template-columns: 18px minmax(0, 1fr) auto; }
  .tree .row > .state, .tree .row > .due, .tree .row.head > span:nth-child(n+4) { display: none; }
  .tree .conv, .tree .after { display: none; }
}

/* ---- app additions ---- */
[hidden] { display: none !important; }
.login { grid-column: 1 / -1; display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: min(360px, 100%); display: grid; gap: 10px; text-align: center; }
.login img { width: 140px; margin: 0 auto; }
.login input { padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; }
.login button { background: var(--rust); color: #fff; border: 0; border-radius: 10px; padding: 10px; font-weight: 600; }
.login .err { color: var(--block); font-size: 13px; min-height: 1em; }
.me { display: flex; align-items: center; gap: 8px; }
.me .who-am { flex: 1; }
.me button { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 2px 4px; }
.bell { position: relative; font-size: 16px !important; }
.bell .n { position: absolute; top: -4px; right: -6px; font-size: 10px; background: var(--block); color: #fff; border-radius: 999px; padding: 0 5px; }
.notices, .keys { position: fixed; left: 12px; bottom: 56px; width: 300px; max-height: 60vh; overflow: auto; z-index: 8; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgb(0 0 0 / .2); padding: 8px; }
.notices div { font-size: 13px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.notices div.new { font-weight: 600; }
.notices small { display: block; color: var(--muted); font-weight: 400; }
.keys { display: grid; gap: 8px; font-size: 13px; }
.keys .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.keys small { color: var(--muted); }
.keys button, .logins button { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); padding: 4px 10px; font: inherit; cursor: pointer; }
.logins { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
.logins > div { background: var(--panel); border: 2px solid var(--rust); border-radius: 12px; padding: 10px 12px; box-shadow: 0 8px 30px rgb(0 0 0 / .25); display: grid; gap: 8px; font-size: 14px; }
.logins .row { display: flex; gap: 8px; }
.logins .yes { background: var(--rust); color: #fff; border: 0; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 9; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; max-width: 360px; font-size: 14px; box-shadow: 0 8px 30px rgb(0 0 0 / .3); }
.convs li .busy-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--doing); margin-left: 6px; animation: pulse 1s infinite; }
.banner { align-self: center; font-size: 13px; background: var(--rust-soft); border-radius: 10px; padding: 6px 12px; }
.banner button { border: 0; background: none; color: var(--rust); font-weight: 600; }
.bubble .md p { margin: 0 0 6px; } .bubble .md p:last-child { margin-bottom: 0; }
.bubble .md ul, .bubble .md ol { margin: 4px 0 6px; padding-left: 22px; }
.bubble .md h1, .bubble .md h2, .bubble .md h3 { font-size: 15px; margin: 8px 0 4px; }
.bubble .md code { background: var(--bg); padding: 0 4px; border-radius: 4px; font-size: 13px; }
.msg.user .bubble .md code { background: rgb(255 255 255 / .15); }
.bubble .md a { color: var(--rust); text-decoration: underline; } .msg.user .bubble .md a { color: inherit; }
.bubble .md table { border-collapse: collapse; margin: 6px 0; font-size: 13px; } .bubble .md td, .bubble .md th { border: 1px solid var(--line); padding: 3px 8px; }
.err-line { color: var(--block); font-size: 13px; margin-top: 6px; }
.ask.done { border-color: var(--line); }
.ask.done .upd { font-size: 13px; color: var(--muted); }
.train .task { cursor: pointer; }
.choices button.action:disabled { background: var(--ok); color: #fff; border-color: transparent; }
.choices button:disabled { opacity: .6; cursor: default; }
.mine .empty, .side .none { font-size: 13px; color: var(--muted); padding: 8px 12px; }
.session-view .log { max-height: none; overflow: visible; padding: 0; }
.drawer .state-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.drawer .state-btns button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 3px 10px; font-size: 13px; }
.drawer .state-btns button.on { border-color: var(--rust); color: var(--rust); }
.drawer .body-text { font-size: 14px; white-space: pre-wrap; margin: 8px 0 0; }
.drawer .result { font-size: 14px; background: var(--bg); border-radius: 8px; padding: 6px 10px; margin-top: 8px; }
.drawer .path a { color: var(--muted); }
.cmt .md p { margin: 0; }
.hist .replies .field { margin-top: 6px; }
.newtask { display: flex; gap: 6px; margin-top: 10px; }
.newtask input { flex: 1; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.newtask button { border: 0; background: var(--rust); color: #fff; border-radius: 8px; padding: 0 12px; }
.welcome { margin: auto; text-align: center; color: var(--muted); }
.welcome img { width: 200px; display: block; margin: 0 auto 10px; }
.drawer.open { display: block; }
.modal.open { display: grid; }
.modal > div { max-height: 90vh; overflow: auto; }
.modal.wide > div { width: min(860px, 100%); }

/* a secret: real value for the family, «secret:N» for the AI (secrets.ts); the lock is CSS so it is never copied */
span.secret, .secret-chip { border-bottom: 1px dashed currentColor; background: color-mix(in srgb, currentColor 12%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
span.secret::before, .secret-chip::before { content: '🔒'; font-size: .75em; margin-right: 2px; user-select: none; }
span.secret.hidden-key { font-style: italic; opacity: .7; }

/* 🔒 in a rich field: masks a secret (chip), warning bar while typing */
.field { position: relative; }
.field > .lock { position: absolute; right: 6px; top: 8px; border: 0; background: none; font-size: 15px; opacity: .45; cursor: pointer; padding: 2px 4px; }
.field > .lock:hover { opacity: 1; }
.field .rich { padding-right: 30px; }
.secret-chip { display: inline-block; margin: 0 1px; }
.secret-hint { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 10px; border-top: 1px dashed var(--line); font-size: 13px; }
.secret-hint span { flex: 1 1 220px; }
.secret-hint button { border: 1px solid var(--rust); background: var(--rust); color: #fff; border-radius: 8px; padding: 3px 10px; font-size: 13px; }
.secret-hint button.ghost { background: none; color: inherit; border-color: var(--line); }
.secret-hint input { flex: 1 1 160px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }

/* Mémoire (knowledge fiches) */
.kb-view .btn-new { border: 1px solid var(--rust); color: var(--rust); border-radius: 10px; padding: 5px 12px; font-size: 13px; text-decoration: none; }
.kb-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.kb-card { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 10px 12px; cursor: pointer; text-decoration: none; color: inherit; display: block; }
.kb-card:hover { border-color: var(--rust); }
.kb-card h3 { margin: 0 0 4px; font-size: 14px; }
.kb-card .md { font-size: 13px; color: var(--muted); max-height: 5.5em; overflow: hidden; }
.kb-card .tags, .kb-edit .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.kb-tag { font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; color: var(--muted); }
.kb-tag.vis { border-color: var(--rust); color: var(--rust); }
.kb-card.stale { opacity: .6; }
.kb-edit label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 3px; }
.kb-edit input, .kb-edit textarea, .kb-edit select { width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.kb-edit textarea { min-height: 140px; resize: vertical; }
.kb-edit .row2 { display: flex; gap: 8px; } .kb-edit .row2 > div { flex: 1; }
.kb-edit .btns { display: flex; gap: 8px; margin-top: 12px; }
.kb-edit .btns button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 5px 14px; }
.kb-edit .btns button.go { background: var(--rust); color: #fff; border-color: var(--rust); }
.kb-hist { font-size: 12px; color: var(--muted); margin-top: 14px; padding-left: 16px; }

@keyframes pulse { 50% { opacity: .55; } }
.agent-state { padding: 8px 16px; font-size: 14px; border-bottom: 1px solid var(--line); background: var(--rust-soft); }
.agent-state[hidden] { display: none; }
.agent-state.offline { background: color-mix(in srgb, var(--block, #c0392b) 15%, transparent); }
.err-line .retry { margin-left: 6px; font-weight: 600; white-space: nowrap; }
.msg .when { font-size: 11px; color: var(--muted); }
.msg.user .under { display: flex; gap: 10px; align-items: baseline; }
.conv-search { margin: 0 12px 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); font: inherit; font-size: 13px; }
.conv-list .list-head { font-size: 12px; color: var(--muted); padding: 6px 18px; cursor: default; }
.conv-list .list-head a { margin-left: 6px; }
.conv-list li.archived b { opacity: .75; }
.conv-list .excerpt { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.archives-link { display: block; margin: 4px 12px 8px; font-size: 13px; color: var(--muted); }
.archive-btn.on { color: var(--rust); }
.me .folder { position: relative; }
.me .folder .dot { position: absolute; right: 0; top: 2px; width: 7px; height: 7px; border-radius: 50%; background: transparent; }
.me .folder[data-state="granted"] .dot { background: var(--ok, #2e7d32); }
.me .folder[data-state="prompt"] .dot { background: var(--rust); }
.me .folder.off { opacity: .4; }

/* code blocks: bar (language, copy, save), long ones folded */
.code { margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.code pre { margin: 0; border: 0; border-radius: 0; }
.code-bar { display: flex; align-items: center; gap: 6px; padding: 3px 8px; font-size: 11px; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--line); }
.code-bar span { flex: 1; }
.code-bar button, .code-more { border: 0; background: none; color: var(--muted); font-size: 11px; cursor: pointer; padding: 2px 4px; }
.code-bar button:hover, .code-more:hover { color: var(--rust); }
.code.folded pre { max-height: 13.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.code-more { display: block; width: 100%; padding: 5px; border-top: 1px solid var(--line); background: var(--bg); }
.shared-file { margin: 6px 0; }

/* resizable panels: a handle on the inner edge (drag; double-click = default width); widths kept per browser */
@media (min-width: 1001px) { .convs, .side { position: relative; } } /* the handle's anchor; on a phone they slide in (fixed) */
.resize { position: absolute; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 6; touch-action: none; }
.resize::after { content: ''; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: transparent; transition: background .15s; }
.resize:hover::after, .resize.dragging::after { background: var(--rust); }
.convs > .resize { right: -4px; } .side > .resize, .drawer > .resize { left: -4px; }
.drawer > .resize { position: fixed; top: 0; bottom: 0; left: auto; right: calc(min(var(--drawer, 440px), 100vw) - 4px); }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing iframe { pointer-events: none; }
@media (max-width: 1000px) { .resize { display: none; } }
.task-ref { font-weight: 600; text-decoration: underline dotted; }
.step-link { margin-left: 6px; font-size: 12px; text-decoration: none; }
.drawer .result.folded { max-height: 11em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 65%, transparent); mask-image: linear-gradient(#000 65%, transparent); }
.drawer .result .md p, .drawer .body-text .md p, .cmt .md p { margin: 0 0 .6em; }
.drawer .md li { margin: .15em 0; }
.drawer .md { line-height: 1.5; }
.cmt .permalink { color: var(--muted); font-size: 11px; }
li.flash > .cmt { outline: 2px solid var(--rust); outline-offset: 2px; border-radius: 8px; transition: outline-color 1s; }
.drawer-back { display: inline-block; margin: 0 0 8px; font-size: 13px; color: var(--muted); max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-back:hover { color: var(--rust); }
/* the right panel only when it has something (my tasks, this conversation's tasks) */
@media (min-width: 1001px) {
  body.no-side { grid-template-columns: var(--left, 240px) minmax(0, 1fr) 0; }
  body.no-side aside.side { display: none; }
  .trains-btn { display: inline-block; }
}
/* closable panels (computer): ☰ for the conversation list, ✕ / « Mes tâches » for the right panel */
@media (min-width: 1001px) {
  .menu { display: inline-block; }
  aside.convs { grid-column: 1; } main { grid-column: 2; } aside.side { grid-column: 3; } /* fixed columns: hiding one never shifts the others */
  body.no-convs { grid-template-columns: 0 minmax(0, 1fr) var(--right, 320px); }
  body.no-convs.no-side { grid-template-columns: 0 minmax(0, 1fr) 0; }
  body.no-convs aside.convs { display: none; }
}
aside.side .panel-close { position: absolute; top: 8px; right: 8px; border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; z-index: 2; }
aside.side .panel-close:hover { color: var(--rust); }
/* long titles: the whole title is kept, CSS shortens it (full title on hover) */
.conv-list li b { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
table.usage { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0 12px; }
table.usage th, table.usage td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.usage td:nth-child(n+3) { text-align: right; } .usage-view h3 { font-size: 14px; margin: 8px 0 2px; }

/* the person's browser, live (phase 2): frames from gniafd, clicks and keys sent back */
.live { position: fixed; top: 0; right: 0; bottom: 0; z-index: 4; width: min(var(--live, 600px), 100vw); display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
body.live-open { box-sizing: border-box; padding-right: min(var(--live, 600px), 100vw); } /* a drawer beside the conversation, never over it */
.live > .resize { left: 0; }
.live[hidden] { display: none; }
.live header { display: flex; gap: 6px; padding: 6px; align-items: center; }
.live header .url { flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.live header button { border: 1px solid var(--line); background: none; color: var(--text); border-radius: 8px; padding: 3px 9px; cursor: pointer; }
.live header .done { background: var(--rust); color: #fff; border-color: transparent; }
.live .why { padding: 6px 10px; font-size: 13px; background: var(--rust-soft); color: var(--text); }
.live .screen { position: relative; flex: 1; min-height: 120px; overflow: hidden; background: #222; }
.live .screen img { display: block; width: 100%; cursor: default; outline: none; touch-action: none; user-select: none; }
.live .screen img:focus { box-shadow: inset 0 0 0 2px var(--rust); }
.live .screen .wait { position: absolute; inset: 0; display: grid; place-items: center; color: #ccc; font-size: 14px; cursor: pointer; text-align: center; padding: 16px; }
@media (max-width: 1000px) { /* phone: a drawer at the top, the conversation below */
  .live { left: 0; bottom: auto; width: auto; height: 55vh; border-left: 0; border-bottom: 1px solid var(--line); }
  body.live-open { padding-right: 0; padding-top: 55vh; }
}
.live .ask-gniaf { display: flex; gap: 6px; padding: 6px; }
.live .ask-gniaf input { flex: 1; min-width: 0; font: inherit; font-size: 14px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.live .ask-gniaf button { border: 0; border-radius: 8px; padding: 4px 12px; background: var(--rust); color: #fff; cursor: pointer; }
.live .tabs { display: flex; gap: 4px; padding: 0 6px 6px; overflow-x: auto; }
.live .tabs[hidden] { display: none; }
.live .tab { display: flex; align-items: center; max-width: 200px; min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.live .tab.on { border-color: var(--rust); background: var(--rust-soft); }
.live .tab button { border: 0; background: none; color: var(--text); font: inherit; font-size: 12px; cursor: pointer; padding: 3px 6px; }
.live .tab .pick { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live .tab .close { padding: 3px 6px 3px 0; color: var(--muted); }
.steps .stepgroup > details > summary { color: var(--muted); cursor: pointer; }
.steps .stepgroup > details > summary > span:nth-child(2) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps .stepgroup > details[open] > summary .st { transform: rotate(90deg); }
.steps .stepgroup > details > .steps { margin: 2px 0 4px 14px; padding-left: 8px; border-left: 2px solid var(--line); }
.browser-btn.off { filter: grayscale(1); opacity: .55; }
