/* Ultron — interface : structure en panneaux façon Obsidian, finition Apple. */

/* ---------- Jetons ---------- */
:root {
  --bg: #0b0b0d;
  --surface: #121216;
  --surface-2: #17171c;
  --surface-3: #1d1d23;
  --glass: rgba(18, 18, 22, 0.72);
  --text: #ececf1;
  --text-2: #9a9aa6;
  --text-3: #63636e;
  --line: rgba(255, 255, 255, 0.06);
  --line-2: rgba(255, 255, 255, 0.12);
  --accent: #ff3b3b;
  --accent-soft: rgba(255, 59, 59, 0.12);
  --accent-line: rgba(255, 59, 59, 0.35);
  --amber: #ffb347;
  --cyan: #58d6ff;
  --ok: #4ade80;
  --danger: #ff5f5f;
  --field: rgba(255, 255, 255, 0.04);
  --hover: rgba(255, 255, 255, 0.05);
  --active: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 40px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.25);
  --r-xs: 4px; --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --t-fast: 150ms; --t-med: 200ms; --t-slow: 250ms;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --hud: "Rajdhani", "Inter", sans-serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --rail: 48px;
  --titlebar: 40px;
  --tabbar: 56px;
  --drawer: 440px;
  --core-w: 420px;
  --chat-bg-user: var(--surface-3);
  --pane-title-bg: rgba(11, 11, 13, 0.6);
  color-scheme: dark;
}

/* Thème clair : uniquement sur choix explicite (ou « Système » résolu en clair par le script). */
:root[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f2f2f5;
  --surface-3: #e9e9ee;
  --glass: rgba(255, 255, 255, 0.72);
  --text: #1b1b1f;
  --text-2: #63636e;
  --text-3: #9a9aa6;
  --line: rgba(0, 0, 0, 0.07);
  --line-2: rgba(0, 0, 0, 0.13);
  --accent: #e0262b;
  --accent-soft: rgba(224, 38, 43, 0.1);
  --accent-line: rgba(224, 38, 43, 0.35);
  --amber: #c47b12;
  --cyan: #0d86b8;
  --ok: #1f9d55;
  --danger: #d62d2d;
  --field: rgba(0, 0, 0, 0.035);
  --hover: rgba(0, 0, 0, 0.04);
  --active: rgba(0, 0, 0, 0.07);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 12px 40px rgba(0, 0, 0, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.08);
  --chat-bg-user: #ffffff;
  --pane-title-bg: rgba(245, 245, 247, 0.6);
  color-scheme: light;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); font-size: 13px; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-xs); }
input:focus-visible, textarea:focus-visible { outline-offset: 0; }

.glass { background: var(--glass); backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3); border: 1px solid var(--line-2); }

/* Défilement discret */
* { scrollbar-width: thin; scrollbar-color: rgba(128, 128, 140, 0.3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: rgba(128, 128, 140, 0.3); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------- Champs & boutons ---------- */
input[type="text"], input[type="password"], input:not([type]), textarea {
  background: var(--field); border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 8px 10px; outline: none;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
input:not([type="range"]):not([type="checkbox"]):focus, textarea:focus { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
#input, #search, #palette-input, #note-path, #input:focus, #search:focus, #palette-input:focus, #note-path:focus { background: none; border: 0; padding: 0; box-shadow: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 11px;
  background: var(--field); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  font-weight: 500; font-size: 13px; color: var(--text); white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:hover { background: var(--hover); border-color: var(--line-2); }
.btn:active { transform: scale(0.97); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { background: #ff5252; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(255, 95, 95, 0.1); border-color: rgba(255, 95, 95, 0.3); }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  width: 30px; height: 30px; display: grid; place-items: center; background: none; border: 1px solid transparent; border-radius: var(--r-sm); color: var(--text-2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* Interrupteur façon iOS */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 12px; font-weight: 500; color: var(--text-2); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { position: relative; width: 30px; height: 18px; border-radius: 9px; background: var(--active); border: 1px solid var(--line-2); transition: background var(--t-med) var(--ease); flex-shrink: 0; }
.switch i::after { content: ""; position: absolute; top: 1px; left: 1px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); transition: transform var(--t-med) var(--ease); }
.switch input:checked + i { background: var(--accent); border-color: transparent; }
.switch input:checked + i::after { transform: translateX(12px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:checked ~ span { color: var(--text); }

/* ---------- Structure ---------- */
.app { display: flex; height: 100%; }

.rail {
  width: var(--rail); flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-right: 1px solid var(--line); z-index: 6;
}
.rail-brand { width: 28px; height: 28px; display: grid; place-items: center; margin-bottom: 10px; }
.rail-brand span { width: 14px; height: 14px; border-radius: 50%; border: 2.5px solid var(--accent); box-shadow: inset 0 0 0 3px var(--bg), inset 0 0 0 20px var(--accent); }
.rail-btn {
  position: relative; width: 36px; height: 36px; display: grid; place-items: center; background: none; border: 0; border-radius: var(--r-sm); color: var(--text-2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.rail-btn svg { width: 20px; height: 20px; }
.rail-btn:hover { background: var(--hover); color: var(--text); }
.rail-btn.active { color: var(--text); background: var(--active); }
.rail-btn.active::before { content: ""; position: absolute; left: -6px; top: 10px; bottom: 10px; width: 2px; border-radius: 2px; background: var(--accent); }
.rail-btn b { position: absolute; top: 3px; right: 3px; min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: #fff; font: 600 10px/15px var(--mono); text-align: center; }
.rail-spacer { flex: 1; }
.rail-status { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 0; }
.ind { position: relative; width: 20px; height: 20px; display: grid; place-items: center; }
.ind i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); transition: background var(--t-med) var(--ease), box-shadow var(--t-med) var(--ease); }
.ind.on i { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.ind.warn i { background: var(--amber); box-shadow: 0 0 6px var(--amber); }

/* Info-bulles de la barre latérale */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%) translateX(-4px);
  padding: 4px 8px; border-radius: var(--r-xs); background: var(--surface-3); border: 1px solid var(--line-2); color: var(--text);
  font: 500 12px/1.3 var(--sans); white-space: nowrap; box-shadow: var(--shadow-sm); pointer-events: none; opacity: 0; z-index: 30;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translateY(-50%) translateX(0); transition-delay: 300ms; }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.titlebar {
  height: var(--titlebar); flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 0 16px 0 14px;
  border-bottom: 1px solid var(--line); background: var(--surface); font-size: 13px; color: var(--text-2);
}
.brand { font: 700 15px/1 var(--hud); letter-spacing: 0.34em; color: var(--accent); }
.brand.big { font-size: 34px; text-align: center; margin-bottom: 6px; letter-spacing: 0.4em; }
.titlebar-sep { width: 1px; height: 14px; background: var(--line-2); }
.titlebar-view { font-weight: 500; color: var(--text); }
.titlebar-stats { font: 500 12px var(--mono); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock { margin-left: auto; font-weight: 500; font-size: 13px; color: var(--text-2); }

.panes { flex: 1; min-height: 0; display: flex; }
.pane { position: relative; min-width: 0; min-height: 0; }
.pane.core { width: var(--core-w); flex-shrink: 0; display: flex; flex-direction: column; background: var(--bg); }
.pane.brain { flex: 1; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, rgba(255, 59, 59, 0.05), transparent 60%), var(--bg); }
.divider { width: 5px; margin: 0 -2px; cursor: col-resize; flex-shrink: 0; position: relative; z-index: 3; }
.divider::after { content: ""; position: absolute; top: 0; bottom: 0; left: 2px; width: 1px; background: var(--line); transition: background var(--t-fast) var(--ease), width var(--t-fast) var(--ease); }
.divider:hover::after, .divider.dragging::after, .divider:focus-visible::after { background: var(--accent); width: 2px; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing .pane.brain { pointer-events: none; }

/* ---------- Orbe ---------- */
.orb-card { position: relative; margin: 12px 12px 0; height: 34%; min-height: 220px; flex-shrink: 0; border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
#orb { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; }
.orb-label { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; pointer-events: none; }
.orb-label span { display: block; font: 700 14px var(--hud); letter-spacing: 0.36em; color: var(--accent); transition: color var(--t-slow) var(--ease); }
.orb-label small { color: var(--text-2); font-size: 12px; }

/* Jauge de sympathie */
.sympathy { position: absolute; top: 10px; right: 10px; display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 10px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); opacity: 0.55; transition: opacity var(--t-med) var(--ease); }
.sympathy:hover, .sympathy:focus-within { opacity: 1; }
.sympathy label { font-size: 11px; font-weight: 500; color: var(--text-2); }
.sympathy b { font-size: 11px; font-weight: 500; color: var(--text); min-width: 2ch; text-align: right; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 84px; height: 18px; background: none; margin: 0; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: linear-gradient(90deg, var(--accent) var(--fill, 60%), var(--line-2) var(--fill, 60%)); }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: var(--line-2); }
input[type="range"]::-moz-range-progress { height: 3px; border-radius: 2px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); transition: transform var(--t-fast) var(--ease); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Conversation ---------- */
.chat { flex: 1; overflow-y: auto; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.msg { position: relative; max-width: 88%; padding: 8px 12px; border-radius: var(--r-md); word-wrap: break-word; overflow-wrap: anywhere; font-size: 14px; line-height: 1.5; animation: rise var(--t-slow) var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg.user { align-self: flex-end; background: var(--chat-bg-user); border: 1px solid var(--line); border-bottom-right-radius: var(--r-xs); }
.msg.user .via { font: 500 10px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); display: block; margin-bottom: 2px; }
.msg.ultron { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-left: 2px solid var(--accent); border-bottom-left-radius: var(--r-xs); }
.msg.ultron.interrupted { opacity: 0.55; }
.msg.system { align-self: center; font: 12px var(--mono); color: var(--text-2); background: none; padding: 2px 8px; }
.msg time { display: block; margin-top: 4px; font: 400 10px var(--mono); color: var(--text-3); text-align: right; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg ul, .msg ol { margin: 4px 0; padding-left: 20px; }
.msg pre { background: var(--bg); border: 1px solid var(--line); padding: 8px 10px; border-radius: var(--r-sm); overflow-x: auto; font-size: 12px; }
.msg code { font-family: var(--mono); font-size: 0.86em; }
.msg :not(pre) > code { background: var(--active); padding: 1px 5px; border-radius: var(--r-xs); }
.msg a { color: var(--cyan); text-decoration: none; }
.msg a:hover { text-decoration: underline; }
.tools { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tools:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 5px; font: 500 10.5px var(--mono); letter-spacing: 0.02em; padding: 1px 7px; border-radius: var(--r-xs); background: var(--field); border: 1px solid var(--line-2); color: var(--text-2); }
.chip::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: 0.7; }
.chip.run { color: var(--amber); }
.chip.run::before { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.15; } }
.chip.ok { color: var(--ok); }
.chip.err { color: var(--danger); }

.composer { display: flex; gap: 8px; align-items: center; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.composer-field { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 6px 0 12px; background: var(--field); border: 1px solid var(--line-2); border-radius: 20px; transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
.composer-field:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer-field #input { flex: 1; min-width: 0; }
.composer-field .switch { padding-right: 4px; }
.mic, .send { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-2); display: grid; place-items: center; flex-shrink: 0; position: relative; transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease); }
.mic { background: var(--accent); color: #fff; border-color: transparent; box-shadow: 0 2px 10px rgba(255, 59, 59, 0.3); }
.mic:hover { background: #ff5252; }
.mic:active { transform: scale(0.95); }
.mic svg { width: 20px; height: 20px; }
.mic.rec::before, .mic.rec::after { content: ""; position: absolute; inset: -1px; border-radius: 50%; border: 2px solid var(--accent); animation: halo 1.4s var(--ease) infinite; pointer-events: none; }
.mic.rec::after { animation-delay: 0.7s; }
@keyframes halo { from { transform: scale(1); opacity: 0.8; } to { transform: scale(1.9); opacity: 0; } }
.send { background: var(--field); color: var(--text-2); }
.send:hover { background: var(--hover); color: var(--text); }

/* ---------- Cerveau ---------- */
#graph { position: absolute; inset: 0; }
.brain-hud { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; align-items: flex-start; pointer-events: none; }
.brain-hud > * { pointer-events: auto; }
.brain-search { position: relative; margin-left: auto; width: min(340px, 100%); height: 34px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border-radius: var(--r-md); box-shadow: var(--shadow-sm); }
.brain-search-icon { width: 16px; height: 16px; color: var(--text-3); }
.brain-search input { flex: 1; min-width: 0; }
.brain-hud .btn { height: 34px; border-radius: var(--r-md); box-shadow: var(--shadow-sm); }
.results { position: absolute; top: 40px; left: 0; right: 0; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--r-md); max-height: 50vh; overflow-y: auto; box-shadow: var(--shadow); padding: 4px; }
.results button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: var(--r-sm); padding: 7px 10px; font-size: 13px; font-weight: 500; }
.results button:hover { background: var(--hover); }
.results small { display: block; color: var(--text-2); font-size: 12px; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend { position: absolute; left: 12px; bottom: 12px; display: flex; flex-wrap: wrap; gap: 6px 12px; font: 500 11px var(--mono); color: var(--text-2); max-width: 60%; pointer-events: none; }
.legend span::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 0; }
.activity { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; font: 500 11px var(--mono); pointer-events: none; }
.activity div { background: var(--glass); border: 1px solid var(--line-2); padding: 3px 8px; border-radius: var(--r-xs); animation: fade 4s var(--ease) forwards; }
@keyframes fade { 0% { opacity: 0; transform: translateY(4px); } 8%, 70% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- Volets de droite (façon Obsidian) ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--drawer), 100vw); z-index: 8; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line-2); box-shadow: var(--shadow);
  transition: transform var(--t-slow) var(--ease), visibility 0s linear 0s;
}
.drawer[hidden] { display: flex !important; transform: translateX(calc(100% + 24px)); visibility: hidden; pointer-events: none; transition: transform var(--t-slow) var(--ease), visibility 0s linear var(--t-slow); }
.drawer-head { display: flex; gap: 8px; align-items: center; height: 48px; padding: 0 8px 0 14px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.drawer-title { margin: 0; flex: 1; font-size: 14px; }
.drawer-actions { display: flex; gap: 4px; align-items: center; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px; }
.drawer-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); font-size: 12px; color: var(--text-2); flex-shrink: 0; line-height: 1.6; }
.drawer-foot button { background: var(--field); border: 1px solid var(--line-2); border-radius: var(--r-xs); padding: 0 6px; margin: 2px 2px 2px 0; font: 500 11px/18px var(--mono); color: var(--cyan); transition: background var(--t-fast) var(--ease); }
.drawer-foot button:hover { background: var(--hover); }

/* Éditeur de note */
.note-path { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; letter-spacing: -0.01em; outline: none; border-radius: 0; }
#note-view { padding: 18px 22px 28px; }
#note-edit, #note-edit:focus { flex: 1; resize: none; background: var(--bg); border: 0; border-radius: 0; padding: 18px 22px; font: 13px/1.65 var(--mono); outline: none; box-shadow: none; tab-size: 2; }
.md h1, .md h2, .md h3 { letter-spacing: -0.015em; margin: 1.1em 0 0.4em; line-height: 1.25; }
.md h1 { font-size: 22px; margin-top: 0; }
.md h2 { font-size: 17px; }
.md h3 { font-size: 15px; }
.md p, .md li { font-size: 14px; line-height: 1.65; }
.md a { color: var(--cyan); }
.md a.wikilink { color: var(--accent); text-decoration: none; cursor: pointer; border-radius: var(--r-xs); padding: 0 2px; margin: 0 -2px; transition: background var(--t-fast) var(--ease); }
.md a.wikilink:hover { background: var(--accent-soft); }
.md a.wikilink.ghost { color: var(--text-2); border-bottom: 1px dashed var(--text-3); }
.md code { font-family: var(--mono); font-size: 0.86em; background: var(--active); padding: 1px 5px; border-radius: var(--r-xs); }
.md pre { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; overflow-x: auto; }
.md pre code { display: block; padding: 0; background: none; }
.md blockquote { border-left: 2px solid var(--accent); margin: 0.6em 0; padding: 2px 0 2px 12px; color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--line-2); margin: 1.2em 0; }
.md table { border-collapse: collapse; font-size: 13px; }
.md th, .md td { border: 1px solid var(--line-2); padding: 4px 8px; }
.md img { max-width: 100%; border-radius: var(--r-sm); }

/* ---------- Cartes, chantiers, paramètres ---------- */
.card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.forge-new { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.forge-new textarea { resize: vertical; min-height: 64px; }
.forge-new-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.task { padding: 12px; display: flex; flex-direction: column; gap: 8px; transition: border-color var(--t-med) var(--ease); }
.task.review { border-color: var(--accent-line); }
.task-head { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.task-head strong { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
.badge, .task-status { display: inline-flex; align-items: center; gap: 5px; font: 500 11px var(--mono); padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap; }
.task-status::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.task-status.review { color: var(--accent); border-color: var(--accent-line); }
.task-status.running, .task-status.revising, .task-status.queued, .task-status.deploying { color: var(--amber); }
.task-status.running::before, .task-status.revising::before, .task-status.deploying::before { animation: blink 1s infinite; }
.task-status.deployed { color: var(--ok); }
.task-status.failed, .task-status.deploy_failed { color: var(--danger); }
.task-meta { font: 11.5px var(--mono); color: var(--text-2); }
.task-summary { font-size: 13.5px; }
.task-summary p { margin: 0 0 6px; }
.task-summary p:last-child { margin: 0; }
.task-progress { font: 11px/1.5 var(--mono); color: var(--text-2); background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 6px 8px; max-height: 110px; overflow-y: auto; white-space: pre-wrap; }
.task-files { font: 11.5px/1.6 var(--mono); color: var(--cyan); word-break: break-all; }
.task-actions { display: flex; gap: 6px; justify-content: flex-end; }
.task-actions:empty { display: none; }
.task-error { color: var(--danger); font-size: 13px; }

.set-card { overflow: hidden; }
.set-card h3 { display: flex; align-items: center; gap: 8px; margin: 0; padding: 9px 12px; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--text); border-bottom: 1px solid var(--line); background: var(--surface); }
.set-card h3 svg { width: 15px; height: 15px; color: var(--accent); }
.set-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.set-row:last-child { border-bottom: 0; }
.set-row span { color: var(--text-2); }
.set-row b { font: 500 12px var(--mono); text-align: right; word-break: break-word; color: var(--text); }
.set-row b.yes { color: var(--ok); }
.set-row b.no { color: var(--text-3); }
.set-row b.warn { color: var(--amber); }

/* Contrôle segmenté (thème) */
.segmented { display: inline-flex; margin: 0; padding: 2px; gap: 2px; background: var(--field); border: 1px solid var(--line-2); border-radius: var(--r-sm); }
.segmented label { position: relative; padding: 4px 12px; border-radius: var(--r-xs); font-size: 12px; font-weight: 500; color: var(--text-2); cursor: pointer; user-select: none; transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.segmented label:hover { color: var(--text); }
.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented input:checked + span { color: var(--text); }
.segmented label:has(input:checked) { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.set-row .segmented { margin-left: auto; }

/* ---------- Palette de commandes ---------- */
.palette-backdrop { position: fixed; inset: 0; z-index: 40; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; background: rgba(0, 0, 0, 0.45); animation: appear var(--t-fast) var(--ease); }
@keyframes appear { from { opacity: 0; } }
.palette { width: min(600px, 100%); max-height: 70vh; display: flex; flex-direction: column; border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; animation: pop var(--t-med) var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(-8px) scale(0.98); } }
.palette-field { display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.palette-field svg { color: var(--text-3); }
.palette-field input { flex: 1; min-width: 0; font-size: 15px; }
kbd { font: 500 10.5px var(--mono); padding: 1px 6px; border-radius: var(--r-xs); border: 1px solid var(--line-2); color: var(--text-2); background: var(--field); }
.palette-list { overflow-y: auto; padding: 6px; }
.palette-group { padding: 8px 10px 4px; font: 500 11px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.palette-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; background: none; border: 0; border-radius: var(--r-sm); text-align: left; font-size: 13.5px; color: var(--text); }
.palette-item svg { width: 16px; height: 16px; color: var(--text-2); }
.palette-item .pi-text { flex: 1; min-width: 0; }
.palette-item small { display: block; color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item.sel, .palette-item:hover { background: var(--hover); }
.palette-item.sel { background: var(--accent-soft); }
.palette-empty { padding: 20px; text-align: center; color: var(--text-2); font-size: 13px; }

/* ---------- Autorisation ---------- */
.confirm { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 25; width: min(440px, calc(100vw - 32px));
  border-color: var(--accent-line); border-radius: var(--r-lg); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); animation: pop var(--t-med) var(--ease); }
.confirm-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; color: var(--accent); }
.confirm-title svg { width: 16px; height: 16px; }
.confirm p { margin: 0; font-size: 12.5px; line-height: 1.5; word-break: break-word; max-height: 30vh; overflow-y: auto; color: var(--text); }
.confirm-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.confirm small { margin-right: auto; color: var(--text-2); font-size: 11.5px; }

/* ---------- Divers ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--bg); padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px 24px; border: 1px solid var(--line-2); border-radius: var(--r-xl); background: var(--surface); box-shadow: var(--shadow); }
.login-card p { margin: 0; color: var(--text-2); font-size: 13px; text-align: center; }
.login-card code { font-family: var(--mono); font-size: 12px; background: var(--active); padding: 1px 5px; border-radius: var(--r-xs); }
.login-card input { padding: 11px 12px; }
.login-card .btn { height: 40px; font-weight: 600; }
.error { color: var(--danger) !important; }
.toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 50; padding: 9px 14px; border-radius: var(--r-md); max-width: calc(100vw - 32px); font-size: 13px; box-shadow: var(--shadow); animation: rise var(--t-med) var(--ease); }

/* ---------- Volet Agent PC (journal en direct) ---------- */
.agent-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.agent-title #agent-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--text-3); transition: background var(--t-med) var(--ease), box-shadow var(--t-med) var(--ease); }
.agent-dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.agent-state { font: 500 11px var(--mono); color: var(--text-3); }
.agent-info { flex-shrink: 0; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.agent-info .set-row { padding: 5px 14px; font-size: 12px; }
.agent-tools { display: flex; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.agent-tools input { flex: 1; min-width: 0; }
.agent-offline { padding: 24px 18px; text-align: center; line-height: 1.6; }
.agent-log { flex: 1; overflow-y: auto; padding: 8px 0 14px; background: var(--bg); font: 12px/1.55 var(--mono); overscroll-behavior: contain; }
.agent-log[hidden] { display: none; }
.log-line { display: grid; grid-template-columns: auto 5.5em 1fr; gap: 10px; padding: 1px 14px; color: var(--text); }
.log-line:hover { background: var(--hover); }
.log-line time { color: var(--text-3); }
.log-line b { font-weight: 600; color: var(--text-2); }
.log-line span { white-space: pre-wrap; word-break: break-word; }
.log-line.warning b, .log-line.warning span { color: var(--amber); }
.log-line.error { background: var(--accent-soft); }
.log-line.error b, .log-line.error span { color: var(--danger); }
.agent-follow { position: absolute; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); font-size: 12px; box-shadow: var(--shadow-sm); animation: rise var(--t-med) var(--ease); }
.tab { position: relative; }
.tab b { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: #fff; font: 600 10px/15px var(--mono); text-align: center; }

/* Tabbar mobile : cachée sur grand écran */
.tabbar { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .rail { display: none; }
  .titlebar { padding: 0 16px; padding-top: env(safe-area-inset-top); height: calc(var(--titlebar) + env(safe-area-inset-top)); }
  .titlebar-stats { display: none; }
  .panes { display: block; position: relative; }
  .pane { position: absolute; inset: 0; width: auto !important; }
  .divider { display: none; }
  .workspace[data-view="core"] .pane.brain, .workspace[data-view="brain"] .pane.core { display: none; }
  .orb-card { margin: 12px 16px 0; height: 30%; min-height: 200px; }
  .chat { padding: 14px 16px 8px; }
  .msg { max-width: 92%; }
  .composer { padding: 10px 16px; }
  .composer-field .switch span { display: none; }
  .brain-hud { left: 16px; right: 16px; }
  .brain-search { width: 100%; margin-left: 0; }
  .brain-hud .btn span { display: none; }
  .brain-hud .btn { width: 34px; padding: 0; }
  .legend { left: 16px; bottom: 12px; max-width: 70%; }
  .activity { right: 16px; }
  .tabbar {
    display: flex; flex-shrink: 0; height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding: 0 8px env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; background: none; border: 0; color: var(--text-2); font-size: 10.5px; font-weight: 500; border-radius: var(--r-sm); transition: color var(--t-fast) var(--ease); }
  .tab svg { width: 22px; height: 22px; transition: transform var(--t-fast) var(--ease); }
  .tab.active { color: var(--accent); }
  .tab:active svg { transform: scale(0.9); }
  .drawer { width: 100vw; border-left: 0; }
  .drawer-body { padding: 14px 16px; }
  #agent-restart span { display: none; }
  #agent-restart { width: 34px; padding: 0; }
  #note-view, #note-edit { padding: 16px; }
  .confirm { top: calc(16px + env(safe-area-inset-top)); }
  .toast { bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); }
  .palette-backdrop { padding: calc(8px + env(safe-area-inset-top)) 16px 16px; align-items: flex-start; }
  .palette { max-height: 80vh; }
}

/* ---------- Mouvement réduit ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .mic.rec::before, .mic.rec::after { display: none; }
  .mic.rec { box-shadow: 0 0 0 4px var(--accent-soft); }
}
