/* Cerveau · mise en page de l'application, posée sur le socle univers.css (accent marque violet → cyan). */

html, body { height: 100%; }
body { overflow: hidden; }
.view { padding: 0; }
.view + .view::before { display: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: 296px 1fr; height: 100vh; height: 100dvh; }

/* ---------- Barre latérale ---------- */
.sidebar {
  display: flex; flex-direction: column; gap: 14px; min-height: 0;
  padding: 18px 14px 14px;
  background: rgba(8, 6, 22, .78);
  border-right: 1px solid var(--line);
}
.brand-row { display: flex; align-items: center; gap: 12px; padding: 4px 6px 2px; }
.brand { font-family: var(--serif); font-size: 30px; line-height: 1; }
.brand em { font-style: italic; }
.planet {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 32% 28%, #ede9fe 0%, #a78bfa 28%, #6d28d9 60%, #1e1048 100%);
  box-shadow: 0 0 22px rgba(167, 139, 250, .55), inset -4px -5px 10px rgba(0,0,0,.45);
}
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 999px; background: rgba(255,255,255,.04); border: 1px solid var(--line); }
.tab { border: 0; background: none; padding: 8px 4px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--dim); cursor: pointer; transition: background .3s, color .3s; }
.tab:hover { color: var(--text); }
.tab.is-active { background: rgba(var(--accent-rgb), .18); color: var(--text); box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), .35); }

.side-chat { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.new-chat { width: 100%; }
.search {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255,255,255,.03); color: var(--text); font: inherit; font-size: 14px; outline: none;
}
.search:focus { border-color: rgba(var(--accent-rgb), .5); }
.history { overflow-y: auto; flex: 1; min-height: 0; margin: 0 -6px; padding: 0 6px; scrollbar-width: thin; }
.history-group { font-size: 10.5px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: var(--faint); margin: 16px 8px 6px; }
.conv {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 0; background: none; padding: 9px 10px; border-radius: 10px; cursor: pointer;
  font-size: 14px; color: var(--text-strong); transition: background .25s;
}
.conv:hover { background: rgba(255,255,255,.05); }
.conv.is-active { background: rgba(var(--accent-rgb), .14); box-shadow: inset 2px 0 0 var(--accent); }
.conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-badge { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-light); background: rgba(var(--accent-rgb), .14); padding: 2px 7px; border-radius: 999px; }
.history-empty { color: var(--faint); font-size: 13px; padding: 12px 8px; }

.quota { padding: 10px 8px 2px; border-top: 1px solid var(--line); margin-top: auto; }
.quota-text { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.quota-bar { height: 4px; border-radius: 4px; background: rgba(255,255,255,.07); overflow: hidden; }
.quota-bar span { display: block; height: 100%; width: 0; background: var(--btn-grad); transition: width .6s var(--ease); }
.quota.is-high .quota-bar span { background: linear-gradient(90deg, #f59e0b, #ef4444); }

/* ---------- Zone principale ---------- */
.main { min-width: 0; min-height: 0; position: relative; }
.view { display: none; height: 100%; flex-direction: column; min-height: 0; }
.view.is-active { display: flex; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex: none;
  padding: 16px 28px; border-bottom: 1px solid var(--line);
  background: rgba(4, 3, 11, .55);
}
.chat-title {
  font-size: 26px; line-height: 1.15; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; outline: none; border-radius: 6px;
}
.chat-title em { font-style: italic; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; padding-right: .06em; }
.chat-title[contenteditable="true"] { box-shadow: 0 0 0 1px rgba(var(--accent-rgb), .5); padding: 0 6px; white-space: normal; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  width: 38px; height: 38px; flex: none; display: inline-grid; place-items: center;
  border: 0; border-radius: 10px; background: rgba(255,255,255,.04); cursor: pointer; font-size: 16px; color: var(--dim);
  transition: background .25s, color .25s;
}
.icon-btn:hover { background: rgba(255,255,255,.09); color: var(--text); }
.icon-btn.is-on { color: var(--accent-light); }
.only-mobile { display: none; }

/* ---------- Fil de discussion ---------- */
.thread { flex: 1; overflow-y: auto; padding: 28px 28px 12px; scroll-behavior: smooth; }
.thread > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.welcome { text-align: center; padding: 8vh 0 24px; }
.welcome h2 { font-size: clamp(34px, 4.6vw, 52px); margin-bottom: 14px; }
.welcome p { margin: 0 auto 28px; max-width: 520px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  border: 1px solid var(--line); background: rgba(255,255,255,.035); color: var(--text-strong);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; cursor: pointer; transition: border-color .3s, background .3s;
}
.chip:hover { border-color: rgba(var(--accent-rgb), .5); background: rgba(var(--accent-rgb), .08); }

.msg { margin-bottom: 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: 85%; padding: 12px 16px; border-radius: 18px 18px 4px 18px;
  background: rgba(var(--accent-rgb), .14); border: 1px solid rgba(var(--accent-rgb), .25);
  color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.bot { display: grid; grid-template-columns: 26px 1fr; gap: 14px; }
.msg.bot .planet { width: 22px; height: 22px; margin-top: 4px; box-shadow: 0 0 14px rgba(167, 139, 250, .45), inset -3px -3px 6px rgba(0,0,0,.45); }
.msg.bot .content { min-width: 0; }

.steps { margin-bottom: 10px; font-size: 13px; color: var(--dim); }
.steps summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.035); border: 1px solid var(--line); }
.steps summary::-webkit-details-marker { display: none; }
.steps summary::after { content: "▾"; font-size: 11px; opacity: .7; }
.steps[open] summary::after { content: "▴"; }
.steps ol { list-style: none; margin: 8px 0 0; padding: 0 0 0 4px; border-left: 1px solid rgba(var(--accent-rgb), .25); }
.steps li { padding: 3px 0 3px 12px; position: relative; overflow-wrap: anywhere; }
.steps li::before { content: ""; position: absolute; left: -3px; top: 11px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.steps li.is-error { color: #fca5a5; }
.steps li.is-error::before { background: #f87171; }
.steps li.is-note { font-style: italic; color: var(--faint); }
.steps li.is-running::before { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .2; } }

.md { color: var(--text-strong); overflow-wrap: anywhere; }
.md > *:first-child { margin-top: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: 0 0 14px; }
.md p { color: var(--text-strong); }
.md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 400; margin: 22px 0 8px; line-height: 1.2; }
.md h2 { font-size: 30px; }
.md h3 { font-size: 24px; }
.md h4 { font-size: 19px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--accent); }
.md code { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: .88em; background: rgba(255,255,255,.07); padding: 2px 6px; border-radius: 6px; }
.md pre { background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 13px; }
.md blockquote { border-left: 2px solid var(--accent); padding: 2px 0 2px 14px; color: var(--dim); }
.md a { color: var(--accent-light); text-decoration-color: rgba(var(--accent-rgb), .5); text-underline-offset: 3px; }
.md .wikilink { color: var(--accent-light); cursor: pointer; border-bottom: 1px dashed rgba(var(--accent-rgb), .6); }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.md th { background: rgba(255,255,255,.04); font-weight: 700; }
.md hr { border: 0; height: 1px; background: var(--line); margin: 20px 0; }
.cursor::after { content: "▍"; color: var(--accent); animation: pulse 1s steps(2) infinite; margin-left: 2px; }
.meta { font-size: 12px; color: var(--faint); margin-top: 4px; }
.error-text { color: #fca5a5; }

/* Propositions à valider : les seuls éléments à bordure lumineuse de l'écran */
.checkpoint { margin-top: 14px; padding: 18px 20px; }
.checkpoint .eyebrow { margin-bottom: 8px; }
.checkpoint h4 { font-family: var(--serif); font-weight: 400; font-size: 21px; margin-bottom: 6px; overflow-wrap: anywhere; }
.checkpoint p { font-size: 14px; margin-bottom: 4px; }
.checkpoint .path { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--accent-light); overflow-wrap: anywhere; }
.checkpoint .row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.checkpoint details { margin-top: 8px; font-size: 13px; }
.checkpoint details summary { cursor: pointer; color: var(--dim); }
.checkpoint details pre { white-space: pre-wrap; max-height: 320px; overflow: auto; background: rgba(0,0,0,.3); padding: 10px; border-radius: 10px; margin-top: 6px; font-size: 12.5px; }
.checkpoint.is-done { opacity: .75; }
.checkpoint .status { font-size: 13px; font-weight: 600; margin-top: 10px; }
.checkpoint .status.ok { color: #6ee7b7; }
.checkpoint .status.no { color: var(--faint); }
.card:hover { transform: none; }

/* ---------- Saisie ---------- */
.composer { flex: none; padding: 10px 28px 18px; position: relative; }
.composer > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.composer-box {
  display: flex; align-items: flex-end; gap: 10px; padding: 10px 10px 10px 18px;
  border-radius: 24px; border: 1px solid rgba(255,255,255,.12);
  background: var(--glass), rgba(14, 11, 32, .85);
  box-shadow: 0 18px 50px -20px rgba(0,0,0,.8);
  transition: border-color .3s;
}
.composer-box:focus-within { border-color: rgba(var(--accent-rgb), .55); }
#input {
  flex: 1; resize: none; border: 0; outline: none; background: none; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.5; max-height: 220px; padding: 8px 0;
}
#input::placeholder { color: var(--faint); }
.send {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--btn-grad); display: grid; place-items: center;
  box-shadow: 0 8px 24px -8px rgba(var(--accent-rgb), .8);
  transition: transform .3s var(--ease), opacity .3s;
}
.send svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.send.stop svg { fill: #fff; stroke: none; }
.send:hover { transform: translateY(-2px); }
.send:disabled { opacity: .4; cursor: default; transform: none; }
.composer-hint { font-size: 11.5px; color: var(--faint); text-align: center; margin-top: 8px; }
.cmd-menu {
  position: absolute; bottom: calc(100% - 4px); left: 28px; right: 28px; max-width: 780px; margin: 0 auto;
  background: rgba(14, 11, 32, .97); border: 1px solid rgba(var(--accent-rgb), .35); border-radius: 16px; padding: 6px; z-index: 5;
}
.cmd {
  display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 10px; padding: 9px 12px; cursor: pointer; font-size: 14px;
}
.cmd b { color: var(--accent-light); margin-right: 8px; }
.cmd span { color: var(--dim); }
.cmd:hover, .cmd.is-active { background: rgba(var(--accent-rgb), .14); }

/* ---------- Coffre ---------- */
.vault { flex: 1; display: grid; grid-template-columns: 300px 1fr; min-height: 0; }
.vault-tree { overflow-y: auto; padding: 16px 12px 24px; border-right: 1px solid var(--line); font-size: 14px; }
.vault-tree details > summary { list-style: none; cursor: pointer; padding: 6px 8px; border-radius: 8px; display: flex; gap: 8px; align-items: center; color: var(--text-strong); font-weight: 600; }
.vault-tree details > summary::-webkit-details-marker { display: none; }
.vault-tree details > summary::before { content: "▸"; font-size: 11px; color: var(--faint); transition: transform .2s; }
.vault-tree details[open] > summary::before { transform: rotate(90deg); }
.vault-tree summary:hover, .tree-file:hover { background: rgba(255,255,255,.05); }
.vault-tree .tree-children { padding-left: 14px; border-left: 1px solid var(--line); margin-left: 12px; }
.tree-file { display: block; width: 100%; text-align: left; border: 0; background: none; cursor: pointer; padding: 5px 8px; border-radius: 8px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-file.is-active { color: var(--text); background: rgba(var(--accent-rgb), .14); }
.tree-count { margin-left: auto; font-size: 11px; color: var(--faint); font-weight: 500; }
.vault-file { overflow-y: auto; padding: 28px 36px 40px; min-width: 0; }
.vault-file > * { max-width: 820px; }
.file-empty { padding-top: 10vh; }
.file-empty h2 { margin-bottom: 12px; }
.file-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.file-path { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--accent-light); flex: 1; min-width: 200px; overflow-wrap: anywhere; }
.file-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.editor {
  width: 100%; min-height: 60vh; resize: vertical; padding: 18px; border-radius: 16px;
  border: 1px solid rgba(var(--accent-rgb), .35); background: rgba(0,0,0,.35); color: var(--text);
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 14px; line-height: 1.6; outline: none;
}
.vault-file .md h1 { font-size: clamp(34px, 4vw, 46px); margin-bottom: 18px; }

/* ---------- Réglages ---------- */
.settings { flex: 1; overflow-y: auto; padding: 28px 28px 48px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-content: start; }
.settings .card { padding: 24px; min-width: 0; }
.settings .card.wide { grid-column: 1 / -1; }
.settings h3 { font-size: 26px; margin-bottom: 6px; }
.settings .card > p { font-size: 14px; margin-bottom: 14px; }
.field { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.input, .select {
  flex: 1 1 180px; min-width: 0; max-width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0,0,0,.3); color: var(--text); font: inherit; font-size: 14px; outline: none;
}
.select option { background: #0e0b20; }
.input:focus, .select:focus { border-color: rgba(var(--accent-rgb), .55); }
.status-line { font-size: 14px; margin: 4px 0; color: var(--text-strong); }
.status-line .ok { color: #6ee7b7; }
.status-line .ko { color: #fca5a5; }
.big-usage { font-family: var(--serif); font-size: 64px; line-height: 1; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.big-usage small { font-size: 26px; color: var(--faint); -webkit-text-fill-color: var(--faint); }
.usage-bar { height: 6px; border-radius: 6px; background: rgba(255,255,255,.07); overflow: hidden; margin: 14px 0; }
.usage-bar span { display: block; height: 100%; background: var(--btn-grad); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 14px; color: var(--dim); }
.kv b { color: var(--text-strong); font-weight: 600; }
.role { padding: 16px 0; border-top: 1px solid var(--line); }
.role:first-of-type { border-top: 0; }
.role-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.role-head strong { font-size: 15px; }
.role-head span { font-size: 13px; color: var(--dim); }
.role .field { margin-top: 8px; }
.role .rank { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); width: 74px; }
.routine { display: flex; gap: 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.routine:first-of-type { border-top: 0; }
.routine-text { flex: 1; min-width: 180px; }
.routine-text strong { display: block; font-size: 15px; }
.routine-text span { font-size: 13px; color: var(--dim); }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,.12); cursor: pointer; transition: background .3s; }
.switch span::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .3s var(--ease); }
.switch input:checked + span { background: var(--btn-grad); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent-light); outline-offset: 2px; }
.hint { font-size: 12.5px; color: var(--faint); margin-top: 10px; }
.hint a { color: var(--accent-light); }

/* ---------- Divers ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(14, 11, 32, .97); border: 1px solid rgba(var(--accent-rgb), .4); color: var(--text);
  padding: 12px 18px; border-radius: 14px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px);
  transition: opacity .3s, transform .4s var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { border-color: rgba(248, 113, 113, .6); }
.backdrop { display: none; }
.spinner { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Connexion ---------- */
body.login-page { overflow-y: auto; }
.login { min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; text-align: center; }
.login-planet { width: 72px; height: 72px; margin-bottom: 26px; box-shadow: 0 0 60px rgba(167, 139, 250, .6), inset -8px -10px 18px rgba(0,0,0,.45); }
.login h1 { margin-bottom: 30px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 10px; text-align: left; padding: 26px; }
.login-card label { font-size: 13px; font-weight: 600; color: var(--dim); margin-top: 4px; }
.login-card .input { width: 100%; min-width: 0; font-size: 16px; }
.login-card .btn { margin-top: 10px; width: 100%; }
.login-intro { font-size: 14px; margin-bottom: 4px; }
.login-error { color: #fca5a5; font-size: 14px; min-height: 1.4em; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 30;
    transform: translateX(-102%); transition: transform .45s var(--ease);
    background: #0a0818; padding-top: max(18px, env(safe-area-inset-top));
  }
  .sidebar.is-open { transform: none; box-shadow: 30px 0 80px rgba(0,0,0,.6); }
  .brand-row .only-mobile { margin-left: auto; }
  .backdrop.is-on { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
  .topbar { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
  .chat-title { font-size: 22px; }
  .thread { padding: 20px 16px 8px; }
  .composer { padding: 8px 12px max(12px, env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .cmd-menu { left: 12px; right: 12px; }
  .msg.bot { grid-template-columns: 1fr; gap: 6px; }
  .msg.bot .planet { display: none; }
  .msg.user .bubble { max-width: 92%; }
  .vault { grid-template-columns: 1fr; }
  .vault-tree { border-right: 0; }
  .vault.show-file .vault-tree { display: none; }
  .vault:not(.show-file) .vault-file { display: none; }
  .vault-file { padding: 20px 16px 32px; }
  .settings { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 40px; }
  .role .select { flex-basis: 100%; }
  .settings .card { padding: 20px; }
  .role .rank { width: 100%; }
}
