/* Hub : système visuel tiré de la planche 1.
   Tailles 11, 13, 15, 22. Espacements sur une grille de 4. Arrondis 6, 10, 14. Une gamme de gris, un accent. */
:root {
  --ink: #1c1c1c; --ink-2: #5f5f5f; --ink-3: #767676; --off: #b0b0b0;
  --bg: #ffffff; --bg-2: #f6f6f6; --bg-3: #ececec; --sel: #e0e0e0;
  --line: #e2e2e2; --line-2: #d0d0d0; --danger: #c42b1c; --accent: #0f766e;
  --shadow: 0 8px 24px rgba(0, 0, 0, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 13px/20px var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
h1, h2, h3, p { margin: 0; }
svg { display: block; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* Boutons */
.ib { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; flex: none; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--ink-2); }
.ib:hover:not(:disabled) { background: var(--bg-3); color: var(--ink); }
.ib.on, .ib[aria-expanded="true"], .ib[aria-pressed="true"] { background: var(--bg-3); color: var(--ink); }
.ib.dark { background: var(--ink); color: #fff; }
.ib.dark:hover:not(:disabled) { background: #000; color: #fff; }
.ib.dark:disabled { background: var(--off); }
.ib.sm { width: 28px; height: 28px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 32px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--bg); white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--bg-2); }
.btn.primary { border-color: var(--ink); background: var(--ink); color: #fff; font-weight: 500; }
.btn.primary:hover:not(:disabled) { background: #000; }
.btn.danger { border-color: var(--danger); background: var(--danger); color: #fff; font-weight: 500; }
.btn:disabled { color: var(--off); }
.tb { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; border: 0; border-radius: 6px; background: transparent; }
.tb:hover { background: var(--bg-3); }
.field { width: 100%; height: 32px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--bg); }
textarea.field { height: auto; padding: 8px 12px; line-height: 20px; resize: vertical; }
select.field { padding: 0 8px; }
.switch { position: relative; width: 40px; height: 24px; flex: none; padding: 0; border: 0; border-radius: 12px; background: var(--line-2); }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .14s cubic-bezier(.22, 1, .36, 1); }
.switch[aria-checked="true"] { background: var(--ink); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

/* Structure */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* 1. Rail */
.rail { width: 80px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px 8px; background: var(--bg-3); border-right: 1px solid var(--line-2); }
.rail .create { margin-bottom: 12px; border-radius: 8px; }
.rail-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; width: 64px; height: 56px; border-radius: 6px; font-size: 11px; line-height: 14px; font-weight: 500; color: var(--ink-2); }
.rail-item.on { background: var(--sel); color: var(--ink); font-weight: 600; }
.rail-item.soon { color: var(--off); }
.rail .grow { flex: 1; }
.avatar { width: 32px; height: 32px; margin-top: 8px; padding: 0; border: 0; border-radius: 50%; background: var(--off); font-weight: 600; }

/* 2. Panneau Chat */
.side { width: 280px; flex: none; display: flex; flex-direction: column; background: var(--bg-2); border-right: 1px solid var(--line-2); overflow: hidden; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px; }
.side-head h2 { font-size: 15px; font-weight: 600; }
.ws { display: inline-flex; align-items: center; gap: 2px; margin-left: -4px; padding: 0 4px; border: 0; border-radius: 4px; background: transparent; font-size: 11px; line-height: 16px; color: var(--ink-2); }
.ws:hover { background: var(--bg-3); color: var(--ink); }
.side-search { padding: 0 12px 8px; }
.side-actions { display: flex; gap: 8px; padding: 0 12px 8px; }
.side-actions .btn { flex: 1; padding: 0 8px; }
.side-list { flex: 1; min-height: 0; overflow: auto; padding: 8px 8px 12px; }
.side-list h3 { margin: 16px 8px 4px; font-size: 11px; line-height: 16px; font-weight: 600; color: var(--ink-2); }
.side-list h3:first-child { margin-top: 4px; }
.row { position: relative; display: flex; align-items: center; margin-bottom: 2px; border-radius: 6px; }
.row:hover { background: var(--bg-3); }
.row.on { background: var(--sel); }
.row > .row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; border: 0; background: transparent; text-align: left; }
.row .label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row.on .label { font-weight: 500; }
.row.done .label { color: var(--ink-2); }
.row .ib { margin-right: 2px; opacity: 0; }
.row:hover .ib, .row .ib:focus-visible, .row .ib[aria-expanded="true"], .row.on .ib { opacity: 1; }
.row svg.pin { color: var(--ink-2); }
.side-empty { margin: 8px; font-size: 11px; line-height: 16px; color: var(--ink-2); }

/* 3. Conversation */
.main { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 52px; flex: none; padding: 0 12px; border-bottom: 1px solid var(--line); }
.bar-left, .bar-right { display: flex; align-items: center; gap: 4px; min-width: 0; }
.bar-title { margin-left: 4px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.thread { flex: 1; min-height: 0; overflow: auto; padding: 24px 24px 8px; }
.thread-in { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.msg.user { align-self: flex-end; max-width: 85%; padding: 8px 12px; border-radius: 10px; background: var(--bg-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.ai { min-width: 0; }
.msg-tools { display: flex; gap: 4px; margin-top: 4px; margin-left: -8px; }
.msg-tools .tb { height: 28px; font-size: 11px; color: var(--ink-2); }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 32px; margin-top: 8px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--bg); }
.chip:hover { background: var(--bg-2); }
.status { margin-top: 4px; font-size: 11px; line-height: 16px; color: var(--ink-2); }
.notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--bg-2); }
.notice.err { border-color: var(--danger); background: var(--bg); }
.dock { flex: none; padding: 8px 24px 24px; }
.main.empty .thread { display: none; }
.main.empty .dock { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 76px; }
.dock-in { width: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }

/* Texte mis en forme (réponses et canvas) */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { margin: 20px 0 8px; font-size: 15px; line-height: 20px; font-weight: 600; }
.md h1 { font-size: 22px; line-height: 28px; }
.md ul, .md ol { padding-left: 20px; }
.md li { margin: 2px 0; }
.md a { color: var(--accent); }
.md code { padding: 1px 4px; border-radius: 4px; background: var(--bg-3); font: 12px/20px var(--mono); }
.md pre { padding: 12px; border-radius: 6px; background: var(--bg-2); overflow: auto; }
.md pre code { padding: 0; background: none; }
.md blockquote { padding-left: 12px; border-left: 2px solid var(--line-2); color: var(--ink-2); }
.md hr { height: 1px; margin: 16px 0; border: 0; background: var(--line); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { padding: 4px 12px; border: 1px solid var(--line); text-align: left; }
.md th { background: var(--bg-2); font-weight: 600; }

/* Composer */
.composer { border: 1px solid var(--line-2); border-radius: 14px; background: var(--bg-2); }
.composer-in { border-radius: 14px; background: var(--bg); box-shadow: 0 0 0 1px var(--line); }
.composer.has-foot .composer-in { border-radius: 14px 14px 0 0; }
.composer textarea { display: block; width: 100%; min-height: 72px; max-height: 280px; padding: 20px 20px 8px; border: 0; background: transparent; resize: none; font-size: 15px; line-height: 24px; outline: none; }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px 12px; }
.composer-row > div { display: flex; align-items: center; gap: 4px; min-width: 0; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 40px; padding: 0 12px; }
.model { gap: 12px; font-size: 15px; min-width: 0; }
.model b { font-weight: 500; }
.model .ver { margin-left: 4px; color: var(--ink-3); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mark { width: 20px; height: 20px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--sel); font-size: 11px; line-height: 1; font-weight: 600; color: var(--ink); object-fit: cover; }
.foot-reason { color: var(--ink-2); }

/* 4. Panneau droit */
.panel { width: 400px; flex: none; display: flex; flex-direction: column; background: var(--bg-2); border-left: 1px solid var(--line-2); overflow: hidden; }
.panel.wide { width: 560px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 52px; flex: none; padding: 0 8px 0 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 15px; font-weight: 600; }
.panel-head > div { display: flex; align-items: center; gap: 4px; }
.vsep { width: 1px; height: 20px; margin: 0 4px; background: var(--line); }
.panel-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
.canvas-title { height: 32px; margin: 12px 16px 8px; padding: 0; border: 0; background: transparent; font-size: 15px; font-weight: 600; outline: none; }
.canvas-tools { display: flex; align-items: center; gap: 2px; flex: none; padding: 4px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--bg); }
.canvas-tools .sep { width: 1px; height: 16px; margin: 0 4px; background: var(--line); }
.canvas-tools .ib { color: var(--ink); }
.canvas-edit { flex: 1; min-height: 120px; overflow: auto; padding: 20px 24px; background: var(--bg); outline: none; }
.canvas-edit:empty::before { content: attr(data-placeholder); color: var(--ink-3); }
.canvas-foot { display: flex; justify-content: flex-end; gap: 8px; flex: none; padding: 12px 16px; border-top: 1px solid var(--line); }
.info { display: flex; flex-direction: column; gap: 20px; padding: 16px; }
.info label, .info .k { display: block; margin-bottom: 8px; font-weight: 500; }
.info .two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.info .cut { padding-top: 16px; border-top: 1px solid var(--line); }
.info .v, .hint { color: var(--ink-2); }
.hint { font-size: 11px; line-height: 16px; }
.meter { height: 4px; margin: 8px 0; border-radius: 2px; background: var(--bg-3); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ink); }
.files { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.file { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 8px 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.file .meta { flex: 1; min-width: 0; }
.file .name { font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Menus et fenêtres */
#layer { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.pop { position: absolute; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); box-shadow: var(--shadow); pointer-events: auto; max-height: calc(100vh - 16px); overflow: auto; }
.pop-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 32px; padding: 4px 12px; border: 0; border-radius: 6px; background: transparent; text-align: left; }
.pop-item:hover:not(:disabled), .pop-item.on { background: var(--bg-3); }
.pop-item:disabled { color: var(--off); }
.pop-item > span:not(.mark) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-item small { font-size: 11px; color: var(--ink-3); }
.pop-item svg { color: var(--ink-2); }
.pop-item:disabled svg { color: var(--off); }
.pop-item.danger, .pop-item.danger svg { color: var(--danger); }
.pop.end .pop-item { flex-direction: row-reverse; }
.pop-sep { height: 1px; margin: 4px 8px; background: var(--line); }
.pop-head { margin: 8px 12px 4px; font-size: 11px; line-height: 16px; font-weight: 600; color: var(--ink-2); }
.pop-search { margin: 4px 4px 8px; width: calc(100% - 8px); }
.pop-scroll { max-height: 320px; overflow: auto; }
.pop-note { margin: 8px 12px; color: var(--ink-2); }
.dlg { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 64px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--ink); box-shadow: var(--shadow); }
.dlg.small { width: min(420px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(28, 28, 28, .2); }
.dlg-in { display: flex; flex-direction: column; gap: 16px; max-height: calc(100vh - 66px); padding: 24px; }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dlg-head h2 { font-size: 15px; font-weight: 600; }
.dlg-head p { margin-top: 4px; color: var(--ink-2); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-foot .left { margin-right: auto; }
.dlg label { display: block; margin-bottom: 8px; font-weight: 500; }
.dlg .group { display: flex; flex-direction: column; gap: 16px; }
.dlg .cut { padding-top: 16px; border-top: 1px solid var(--line); }
.search { display: flex; align-items: center; gap: 8px; height: 36px; flex: none; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 6px; color: var(--ink-2); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--ink); }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.agents { min-height: 0; overflow: auto; }
.agent { display: flex; align-items: center; gap: 4px; border-radius: 10px; }
.agent:hover { background: var(--bg-2); }
.agent.on { background: var(--bg-3); }
.agent-main { flex: 1; min-width: 0; display: grid; grid-template-columns: 32px minmax(0, 200px) minmax(0, 1fr); align-items: center; gap: 12px; height: 48px; padding: 0 0 0 8px; border: 0; background: transparent; text-align: left; }
.agent-main .mark { width: 32px; height: 32px; background: var(--bg-3); }
.agent.on .agent-main .mark { background: var(--sel); }
.agent-main b { font-weight: 500; }
.agent-main b, .agent-main span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.agent-main span:last-child { color: var(--ink-2); }
.agent .ib.fav { color: var(--off); }
.agent .ib.fav[aria-pressed="true"] { background: transparent; color: var(--ink); }
.agent .ib:last-child { margin-right: 8px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 8px 16px; border-radius: 10px; background: var(--ink); color: #fff; box-shadow: var(--shadow); }

/* Connexion */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg-2); }
.gate form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 32px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.gate h1 { font-size: 22px; line-height: 28px; font-weight: 600; }
.gate p { color: var(--ink-2); }
.gate label { display: block; margin-bottom: 8px; font-weight: 500; }
.gate .err { color: var(--danger); }

/* Petits écrans */
@media (max-width: 1100px) {
  .panel, .panel.wide { position: absolute; top: 0; right: 0; bottom: 0; z-index: 20; width: min(440px, 100vw); box-shadow: var(--shadow); }
  .app { position: relative; }
}
@media (max-width: 760px) {
  .rail { width: 56px; padding: 12px 4px; }
  .rail-item { width: 48px; height: 48px; font-size: 0; line-height: 0; gap: 0; }
  .side { position: absolute; top: 0; bottom: 0; left: 56px; z-index: 20; width: min(280px, calc(100vw - 56px)); box-shadow: var(--shadow); }
  .thread { padding: 16px 12px 8px; }
  .dock { padding: 8px 12px 12px; }
  .model .ver { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
