@font-face { font-family: Geist; src: url(/fonts/geist-latin.woff2) format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Geist; src: url(/fonts/geist-latin-ext.woff2) format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
    --plum: #3b1f52;
    --plum-2: #52306f;
    --plum-soft: #f1e8f9;
    --plum-dim: #bba6d1;
    --ink: #1d1626;
    --mut: #62586e;
    --line: #e4deea;
    --bg: #f7f4fa;
    --bg-2: #efe9f5;
    --surface: #fff;
    --you: #9a4407;
    --you-dot: #c2600b;
    --you-bg: #fff0db;
    --you-line: #e9b678;
    --work: #0f766e;
    --done: #3f6b52;
    --danger: #a3182f;
    --focus: #8b5fc4;
    --r: 8px;
    --side-w: 208px;
    --list-w: 400px;
    color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; font: 400 0.90625rem/1.45 Geist, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--surface); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
input, textarea { caret-color: var(--plum); }
button { cursor: pointer; }
h1, h2 { margin: 0; }
p { margin: 0; }
::selection { background: #e6d6f5; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
* { scrollbar-width: thin; scrollbar-color: #cfc3dc transparent; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 0.5rem 1rem; font-weight: 600; min-height: 2.5rem; transition: background 150ms, border-color 150ms; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--plum); border-color: var(--plum); color: #fff; }
.btn.primary:hover { background: var(--plum-2); border-color: var(--plum-2); }
.btn.small { padding: 0.35rem 0.7rem; min-height: 2rem; font-weight: 500; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.danger { color: var(--danger); }
.link { border: 0; background: none; padding: 0; text-decoration: underline; text-underline-offset: 3px; color: inherit; }
.form-error { color: var(--danger); font-weight: 500; }

/* Connexion */
body.login { display: grid; place-items: center; background: var(--plum); padding: 1rem; }
.login-card { background: var(--surface); border-radius: 14px; padding: 2rem; width: min(100%, 24rem); display: grid; gap: 0.5rem; }
.login-card h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
.login-card > p { color: var(--mut); margin-bottom: 0.75rem; }
.login-card form { display: grid; gap: 0.4rem; }
.login-card label { font-weight: 500; margin-top: 0.5rem; }
.login-card input { border: 1px solid #cdc3d8; border-radius: var(--r); padding: 0.6rem 0.75rem; }
.login-card .btn { margin-top: 1rem; }

/* Coque à trois volets */
.shell { display: grid; grid-template-columns: var(--side-w) var(--list-w) minmax(0, 1fr); height: 100dvh; }

.side { background: var(--plum); color: #fff; padding: 1.1rem 0.75rem; display: flex; flex-direction: column; gap: 1.25rem; overflow-y: auto; }
.brand { font-weight: 700; font-size: 1.2rem; padding: 0 0.6rem; letter-spacing: -0.01em; }
.side h2 { font-size: 0.78rem; font-weight: 500; color: var(--plum-dim); margin: 0 0 0.25rem; padding: 0 0.6rem; }
.side-item { display: flex; align-items: center; gap: 0.6rem; width: 100%; border: 0; background: none; color: #e9dff3; padding: 0.45rem 0.6rem; border-radius: var(--r); text-align: left; }
.side-item:hover { background: var(--plum-2); }
.side-item[aria-pressed="true"] { background: #fff; color: var(--plum); font-weight: 600; }
.side-item .count { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.side-item.quiet { color: var(--plum-dim); }
.side-item .del { margin-left: auto; border: 0; background: none; color: inherit; opacity: 0; padding: 0 0.25rem; border-radius: 4px; }
.side-item:hover .del, .side-item .del:focus-visible { opacity: 1; }
.side :focus-visible { outline-color: #fff; }
.tag { width: 0.65rem; height: 0.65rem; border-radius: 3px; flex: none; }
.dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; flex: none; background: #7a6a8c; }
.dot.on { background: #6fdc9f; }
.machine { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.6rem; color: #e9dff3; }
.machine small { margin-left: auto; color: var(--plum-dim); }
.account { margin-top: auto; padding: 0 0.6rem; font-size: 0.82rem; color: var(--plum-dim); display: grid; gap: 0.25rem; overflow-wrap: anywhere; }

.lab-blue { --lab: #2f6fe0; --lab-bg: #e3edff; --lab-fg: #1e429f; }
.lab-red { --lab: #d92d4a; --lab-bg: #ffe4e8; --lab-fg: #8f1027; }
.lab-green { --lab: #1f9d62; --lab-bg: #def5e8; --lab-fg: #0b5a36; }
.lab-violet { --lab: #8e57d6; --lab-bg: #efe4fb; --lab-fg: #5a2a99; }
.lab-yellow { --lab: #d9a400; --lab-bg: #fff3c4; --lab-fg: #6b4e00; }
.lab-gray { --lab: #8a8296; --lab-bg: #eceaf0; --lab-fg: #4a4356; }
.tag { background: var(--lab, #8a8296); }
/* On the plum rail the saturated hues sink: lighter tints there. */
.side .lab-blue { --lab: #6fa0f5; }
.side .lab-red { --lab: #f2667a; }
.side .lab-green { --lab: #5fcb93; }
.side .lab-violet { --lab: #c3a0f2; }
.side .lab-yellow { --lab: #f0c94a; }
.side .lab-gray { --lab: #bdb4c9; }

.list { background: var(--bg); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 0.85rem 1rem; border-bottom: 1px solid var(--line); }
.list-head input { width: 100%; border: 1px solid var(--line); border-radius: var(--r); padding: 0.5rem 0.75rem; background: var(--surface); }
.list-head input::placeholder { color: var(--mut); }
.list-body { overflow-y: auto; flex: 1; }
.offline { padding: 0.6rem 1rem; background: #fde8ec; color: var(--danger); font-weight: 500; border-bottom: 1px solid var(--line); }
.sep { padding: 0.45rem 1rem; font-size: 0.8rem; font-weight: 600; color: var(--mut); background: var(--bg-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; }
.conv { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 0.65rem 1rem 0.65rem 1.9rem; position: relative; transition: background 150ms; }
.conv:hover { background: var(--bg-2); }
.conv[aria-current="true"] { background: var(--surface); }
.conv[aria-current="true"] .conv-name { color: var(--plum); }
.conv-top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.conv-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 0.4rem; align-items: center; min-width: 0; }
.conv-name .tag { width: 0.5rem; height: 0.5rem; }
.conv time { font-size: 0.8rem; color: var(--mut); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* block: an inline span would not clip */
.conv-line { display: block; margin-top: 0.1rem; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv::before { content: ""; position: absolute; left: 0.8rem; top: 1rem; width: 0.55rem; height: 0.55rem; border-radius: 50%; }
.conv.s-needs_you .conv-name { font-weight: 700; }
.conv.s-needs_you .conv-line { color: var(--ink); }
.conv.s-needs_you time { color: var(--you); font-weight: 600; }
.conv.s-needs_you::before { background: var(--you-dot); }
.conv.s-working::before { border: 2px solid var(--work); border-top-color: transparent; animation: spin 1.1s linear infinite; }
.conv.s-done .conv-name { text-decoration: line-through; color: var(--mut); }
.list-empty { padding: 1.5rem 1rem; color: var(--mut); }
@keyframes spin { to { transform: rotate(360deg); } }

.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.thread-full { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.thread-empty { margin: auto; max-width: 26rem; padding: 2rem; text-align: center; display: grid; gap: 0.5rem; }
.thread-empty h1 { font-size: 1.25rem; }
.thread-empty p { color: var(--mut); }
.thread-head { padding: 0.8rem 1.5rem; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 0.45rem 1rem; }
.thread-title { grid-column: 1; align-self: center; }
.thread-head .actions { grid-column: 2; grid-row: 1; }
.thread-head .chips { grid-column: 1 / -1; }
.net { display: none; }
.thread-title h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
#rename-form { display: flex; gap: 0.4rem; flex-wrap: wrap; }
#rename-form input { border: 1px solid #cdc3d8; border-radius: var(--r); padding: 0.3rem 0.6rem; width: 14rem; max-width: 100%; }
.back { display: none; border: 0; background: none; padding: 0.4rem; border-radius: var(--r); margin-left: -0.5rem; }
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.chip { font-size: 0.8rem; border-radius: 6px; padding: 0.15rem 0.5rem; background: var(--bg); color: var(--mut); white-space: nowrap; }
.chip.state-needs_you { background: var(--you-bg); color: #7a3606; font-weight: 600; }
.chip.state-working { background: #dcf3f0; color: #0b544e; font-weight: 600; }
.chip.state-done { background: #e2efe7; color: #2c5540; font-weight: 600; }
.chip.label { background: var(--lab-bg); color: var(--lab-fg); font-weight: 500; }
.chip.warn { background: #fde8ec; color: var(--danger); font-weight: 600; }
.actions { display: flex; gap: 0.4rem; flex-wrap: nowrap; }

.msgs { flex: 1; overflow-y: auto; padding: 1.4rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.msgs > * { max-width: 52rem; }
.msg { border-radius: 14px; padding: 0.65rem 0.95rem; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--plum); color: #fff; border-bottom-right-radius: 4px; max-width: min(70%, 40rem); white-space: pre-wrap; }
.msg.user ::selection { background: #7d5aa3; }
.msg.assistant { align-self: flex-start; background: var(--bg); border-top-left-radius: 4px; max-width: min(92%, 34rem); }
.msg.brief { background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.msg.ask { background: var(--you-bg); box-shadow: 0 0 0 1.5px var(--you-line); }
.msg.ask .ask-q { font-weight: 600; font-size: 1.02rem; }
.msg-label { font-size: 0.8rem; font-weight: 600; color: var(--mut); margin-bottom: 0.3rem; }
.msg.ask .msg-label { color: #7a3606; }
.md > * + * { margin-top: 0.55rem; }
.md ul, .md ol { margin: 0; padding-left: 1.2rem; }
.md li + li { margin-top: 0.15rem; }
.md code { font: 0.86em ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: #e9e2f1; border-radius: 4px; padding: 0.05em 0.3em; }
.md pre { margin: 0; background: #2a1d38; color: #f3ecfa; border-radius: var(--r); padding: 0.7rem 0.85rem; overflow-x: auto; font: 0.82rem/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.md pre code { background: none; padding: 0; font: inherit; }
.md .h { font-weight: 700; }
.fold { align-self: center; color: var(--mut); font-size: 0.82rem; }

.composer { border-top: 1px solid var(--line); padding: 0.8rem 1.5rem 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.quick { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.quick:empty { display: none; }
.quick button { border: 1.5px solid var(--plum); background: var(--surface); color: var(--plum); border-radius: 999px; padding: 0.4rem 1rem; font-weight: 600; min-height: 2.5rem; text-align: left; }
.quick button:hover { background: var(--plum-soft); }
.quick kbd { font: 600 0.75rem Geist, sans-serif; border: 1px solid currentColor; border-radius: 4px; padding: 0 0.35rem; margin-right: 0.45rem; opacity: 0.85; }
.box { border: 1.5px solid var(--line); border-radius: 12px; padding: 0.6rem 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; background: var(--surface); transition: border-color 150ms, background 150ms; }
.box:focus-within { border-color: var(--focus); }
.box.drag { border-color: var(--plum); border-style: dashed; background: var(--plum-soft); }
.box textarea { border: 0; resize: none; background: none; outline: none; min-height: 2.9rem; max-height: 40dvh; width: 100%; }
.box textarea::placeholder { color: var(--mut); }
.box-row { display: flex; align-items: center; gap: 0.5rem 0.75rem; flex-wrap: wrap; }
.attach { display: flex; align-items: center; gap: 0.4rem; color: var(--mut); padding: 0.35rem 0.5rem; border-radius: var(--r); cursor: pointer; }
.attach:hover { background: var(--bg); color: var(--ink); }
.attach:has(+ #file-input:focus-visible) { outline: 3px solid var(--focus); }
.hint { color: var(--mut); font-size: 0.8rem; margin-left: auto; }
.files { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.files:empty { display: none; }
.file { display: flex; align-items: center; gap: 0.4rem; background: var(--bg); border-radius: 6px; padding: 0.2rem 0.3rem 0.2rem 0.55rem; font-size: 0.85rem; }
.file button { display: grid; border: 0; background: none; padding: 0.25rem; border-radius: 4px; color: var(--mut); }
.file button:hover { background: var(--bg-2); color: var(--ink); }

.pop { border: 1px solid var(--line); border-radius: 12px; padding: 0.9rem 1rem; box-shadow: 0 12px 32px -12px rgba(59, 31, 82, 0.35); min-width: 15rem; margin: 0; position: fixed; inset: auto; }
.pop h2, .dialog h2 { font-size: 1rem; margin-bottom: 0.6rem; }
.pop label { display: flex; align-items: center; gap: 0.55rem; padding: 0.35rem 0; cursor: pointer; }
.pop input { accent-color: var(--plum); width: 1rem; height: 1rem; }
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 1.25rem 1.4rem; width: min(calc(100% - 2rem), 22rem); box-shadow: 0 24px 48px -16px rgba(59, 31, 82, 0.45); }
.dialog::backdrop { background: rgba(29, 22, 38, 0.4); }
.dialog form { display: grid; gap: 0.5rem; }
.dialog input[type="text"] { border: 1px solid #cdc3d8; border-radius: var(--r); padding: 0.5rem 0.7rem; }
.dialog fieldset { border: 0; padding: 0; margin: 0.4rem 0 0; }
.dialog legend { padding: 0; margin-bottom: 0.35rem; font-weight: 500; }
.dialog label { font-weight: 500; }
.swatches { display: flex; gap: 0.5rem; }
.swatches label { cursor: pointer; }
.swatches span { display: block; width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--lab); border: 3px solid var(--surface); box-shadow: 0 0 0 1.5px var(--line); }
.swatches input:checked + span { box-shadow: 0 0 0 2.5px var(--ink); }
.swatches input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.75rem; }

.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 0.55rem 1rem; border-radius: 999px; font-weight: 500; z-index: 20; max-width: calc(100% - 2rem); }
.toast.error { background: var(--danger); }

@media (max-width: 1180px) {
    :root { --list-w: 320px; --side-w: 184px; }
    .hint { display: none; }
}

/* Téléphone et petite tablette : un volet à la fois */
@media (max-width: 860px) {
    .shell { display: flex; flex-direction: column; height: 100dvh; }
    .side { flex-direction: row; align-items: center; gap: 0.4rem; padding: 0.5rem max(0.75rem, env(safe-area-inset-left)); overflow-x: auto; flex: none; }
    .side .brand, .side h2, #account-email, #nav-machines, #label-new, .side-group:nth-of-type(4) { display: none; }
    .account { margin: 0 0 0 auto; padding: 0 0.25rem 0 0.75rem; white-space: nowrap; position: sticky; right: 0; background: var(--plum); box-shadow: -12px 0 12px -6px var(--plum); }
    .account .link { min-height: 2.75rem; color: #e9dff3; }
    .side-group, #nav-labels { display: flex; gap: 0.3rem; }
    .side-item { white-space: nowrap; width: auto; min-height: 2.75rem; padding: 0.45rem 0.75rem; }
    .side-item .count { margin-left: 0.4rem; }
    .side-item .del { display: none; }
    .list { flex: 1; border-right: 0; }
    .conv { padding-top: 0.8rem; padding-bottom: 0.8rem; }
    .conv::before { top: 1.15rem; }
    .shell[data-view="thread"] .side, .shell[data-view="thread"] .list { display: none; }
    .shell[data-view="list"] .thread { display: none; }
    .thread { flex: 1; }
    .back { display: grid; min-width: 2.75rem; min-height: 2.75rem; place-items: center; }
    .thread-head { padding: 0.5rem 1rem; grid-template-columns: auto minmax(0, 1fr); }
    .back { grid-column: 1; grid-row: 1; }
    .thread-title { grid-column: 2; align-self: center; }
    .thread-head .chips { grid-column: 1 / -1; flex-wrap: nowrap; overflow-x: auto; }
    .thread-head .actions { grid-column: 1 / -1; grid-row: auto; flex-wrap: wrap; }
    .net:not([hidden]) { display: block; padding: 0.5rem 1rem; background: #fde8ec; color: var(--danger); font-weight: 500; }
    .actions .btn { min-height: 2.75rem; }
    .quick { flex-wrap: nowrap; overflow-x: auto; }
    .quick button { white-space: nowrap; flex: none; }
    .msgs { padding: 1rem; }
    .msg.user { max-width: 88%; }
    .msg.assistant { max-width: 100%; }
    .composer { padding: 0.6rem 1rem max(0.8rem, env(safe-area-inset-bottom)); }
    .attach span { display: none; }
    .attach { min-width: 2.75rem; min-height: 2.75rem; justify-content: center; }
    .quick button { min-height: 2.75rem; }
    #send { margin-left: auto; min-height: 2.75rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

.side-row { display: flex; align-items: center; border-radius: var(--r); }
.side-row .side-item { flex: 1; min-width: 0; }
.side-row .del { border: 0; background: none; color: var(--plum-dim); opacity: 0; padding: 0.3rem 0.5rem; border-radius: 4px; }
.side-row:hover .del, .side-row .del:focus-visible { opacity: 1; }
.side-row .del:hover { color: #fff; }

.login-card .secret { font: 600 1.05rem ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--bg); border-radius: var(--r); padding: 0.6rem 0.75rem; letter-spacing: 0.04em; overflow-wrap: anywhere; user-select: all; }
.login-card a { color: var(--plum); text-underline-offset: 3px; }
