/* Alfred — Apple-grade. Graphite profond, vibrancy, SF Pro, précision. */
:root {
  --bg:        oklch(0.152 0.004 265);
  --bg-2:      oklch(0.128 0.004 265);
  --mat:       oklch(0.205 0.005 265 / 0.66);        /* matériau translucide */
  --mat-2:     oklch(0.235 0.006 265 / 0.85);
  --solid:     oklch(0.205 0.005 265);
  --hair:      oklch(1 0 0 / 0.09);
  --hair-2:    oklch(1 0 0 / 0.05);

  --ink:       oklch(0.985 0.001 265);
  --ink-2:     oklch(0.79 0.006 265);
  --muted:     oklch(0.645 0.008 265);
  --faint:     oklch(0.5 0.008 265);

  --accent:    oklch(0.72 0.14 262);
  --accent-hi: oklch(0.80 0.13 262);
  --on:        oklch(0.78 0.16 150);
  --warn:      oklch(0.83 0.135 82);
  --crit:      oklch(0.67 0.20 25);

  --r-lg: 20px; --r: 15px; --r-sm: 10px; --r-xs: 8px; --pill: 999px;
  --sp: clamp(0.85rem, 2.2vw, 1.35rem);
  --side-w: 264px;

  --sh-1: 0 0.5px 0 oklch(1 0 0 / 0.05) inset, 0 1px 2px oklch(0 0 0 / 0.4);
  --sh-2: 0 0.5px 0 oklch(1 0 0 / 0.07) inset, 0 10px 30px -14px oklch(0 0 0 / 0.65), 0 40px 70px -40px oklch(0 0 0 / 0.7);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.35, 0.5, 1);
  --font: -apple-system, "SF Pro Text", "SF Pro Display", ui-sans-serif, "Inter", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;
  --z-scrim: 30; --z-side: 35; --z-top: 40; --z-gate: 80;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); line-height: 1.5; letter-spacing: -0.006em;
  background:
    radial-gradient(130% 90% at 50% -15%, oklch(0.25 0.03 262 / 0.30), transparent 55%),
    radial-gradient(100% 70% at 92% 108%, oklch(0.24 0.03 300 / 0.12), transparent 60%),
    linear-gradient(var(--bg), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -0.022em; text-wrap: balance; font-weight: 600; }
button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
::selection { background: oklch(0.72 0.14 262 / 0.32); }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: oklch(1 0 0 / 0.08); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: oklch(1 0 0 / 0.14); background-clip: padding-box; }

/* Marque : orbe spectral */
.brand-mark { width: 24px; height: 24px; border-radius: 50%; flex: none; position: relative;
  background: radial-gradient(circle at 34% 28%, oklch(0.99 0.015 262), oklch(0.72 0.06 265) 48%, oklch(0.35 0.03 275) 100%);
  box-shadow: 0 0 0 0.5px oklch(1 0 0 / 0.18), 0 3px 10px -3px oklch(0.6 0.1 262 / 0.5), inset 0 -2px 5px oklch(0 0 0 / 0.3); }
.brand-mark::after { content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 68% 74%, oklch(0.55 0.14 300 / 0.45), transparent 52%); mix-blend-mode: screen; }
.brand-mark.lg { width: 52px; height: 52px; } .brand-mark.xl { width: 66px; height: 66px; }

.btn { border: 1px solid var(--hair); background: var(--mat-2); color: var(--ink); border-radius: var(--r-sm);
  padding: 0.72rem 1.05rem; font-weight: 560; cursor: pointer; box-shadow: var(--sh-1);
  transition: background 0.2s var(--ease), transform 0.1s var(--ease); }
.btn:hover { background: oklch(0.29 0.006 265); } .btn:active { transform: translateY(0.5px) scale(0.99); }
.btn-primary { background: var(--accent); border-color: transparent; color: oklch(0.15 0.03 262); font-weight: 620;
  box-shadow: 0 1px 0 oklch(1 0 0 / 0.25) inset, 0 6px 20px -8px var(--accent); }
.btn-primary:hover { background: var(--accent-hi); }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-xs); border: none;
  background: none; color: var(--ink-2); cursor: pointer; transition: background 0.18s var(--ease), color 0.18s var(--ease); }
.icon-btn:hover { background: oklch(1 0 0 / 0.07); color: var(--ink); }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.82rem; padding: 0; transition: color 0.18s; }
.link-btn:hover { color: var(--ink); }

/* ── Connexion ── */
.gate { position: fixed; inset: 0; z-index: var(--z-gate); display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(90% 70% at 50% -10%, oklch(0.24 0.03 262 / 0.5), transparent), var(--bg-2); }
.gate-card { width: min(370px, 100%); display: flex; flex-direction: column; align-items: center; gap: 0.5rem; text-align: center;
  background: var(--mat); backdrop-filter: blur(30px) saturate(1.6); -webkit-backdrop-filter: blur(30px) saturate(1.6);
  border: 1px solid var(--hair); border-radius: var(--r-lg); padding: 2.6rem 2rem; box-shadow: var(--sh-2); }
.gate-card .brand-mark { margin-bottom: 0.7rem; }
.gate-title { font-size: 1.6rem; font-weight: 640; }
.gate-sub { margin: 0.15rem 0 1.1rem; color: var(--muted); font-size: 0.9rem; }
.field { width: 100%; text-align: left; }
.field-label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }
.gate input { width: 100%; background: oklch(0.11 0.004 265); border: 1px solid var(--hair); border-radius: var(--r-sm);
  padding: 0.8rem 0.9rem; letter-spacing: 0.1em; transition: border-color 0.2s, box-shadow 0.2s; }
.gate input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px oklch(0.72 0.14 262 / 0.16); }
.gate .btn-primary { width: 100%; margin-top: 1rem; }
.gate-err { color: var(--crit); font-size: 0.85rem; margin: 0.6rem 0 0; }

/* ── Barre du haut (collante) ── */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: var(--z-top); display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem var(--sp); background: oklch(0.165 0.004 265 / 0.72);
  backdrop-filter: blur(26px) saturate(1.8); -webkit-backdrop-filter: blur(26px) saturate(1.8);
  border-bottom: 1px solid var(--hair-2); }
.topbar-left { display: flex; align-items: center; gap: 0.5rem; flex: none; }
.brand { display: flex; align-items: center; gap: 0.5rem; font-size: 1.02rem; }
.brand strong { font-weight: 640; letter-spacing: -0.01em; }

.topbar-health { flex: 1; display: flex; align-items: center; justify-content: center; gap: clamp(0.7rem, 2vw, 1.5rem);
  min-width: 0; overflow: hidden; }
.stat { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.stat-k { font-size: 0.64rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.stat-v { font-family: var(--mono); font-size: 0.82rem; color: var(--ink); white-space: nowrap; display: flex; align-items: center; gap: 0.35rem; }
.stat-bar { display: block; height: 3px; width: 68px; border-radius: 99px; background: oklch(0.3 0.006 265); overflow: hidden; }
.stat-bar i { display: block; height: 100%; width: 0%; background: var(--on); border-radius: 99px; transition: width 0.6s var(--ease), background 0.4s; }
.stat-bar i[data-level="warn"] { background: var(--warn); } .stat-bar i[data-level="crit"] { background: var(--crit); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--on); box-shadow: 0 0 7px 0 var(--on); }
.dot[data-level="warn"] { background: var(--warn); box-shadow: 0 0 7px 0 var(--warn); }
.dot[data-level="crit"] { background: var(--crit); box-shadow: 0 0 7px 0 var(--crit); }

.topbar-engine { display: flex; align-items: center; gap: 0.75rem; flex: none; }
.status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.led { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.status[data-state="on"] .led { background: var(--on); box-shadow: 0 0 10px 0 var(--on); animation: pulse 2.6s var(--ease) infinite; }
.status[data-state="on"] .status-text { color: var(--ink); }
.status[data-state="loading"] .led { background: var(--warn); box-shadow: 0 0 10px 0 var(--warn); animation: pulse 1s linear infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.power { display: inline-flex; align-items: center; gap: 0.5rem; background: none; border: none; cursor: pointer; padding: 0.2rem; }
.power-track { width: 46px; height: 27px; border-radius: var(--pill); background: oklch(0.3 0.005 265); border: 1px solid var(--hair-2);
  position: relative; transition: background 0.3s var(--ease); box-shadow: inset 0 1px 3px oklch(0 0 0 / 0.5); }
.power-knob { position: absolute; top: 2px; left: 2px; width: 21px; height: 21px; border-radius: 50%; background: oklch(0.95 0 0);
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.5); transition: transform 0.34s var(--spring); }
.power[aria-checked="true"] .power-track { background: var(--on); border-color: transparent; }
.power[aria-checked="true"] .power-knob { transform: translateX(19px); }
.power[data-busy="true"] { opacity: 0.55; pointer-events: none; }
.power-label { font-size: 0.7rem; font-weight: 640; letter-spacing: 0.08em; color: var(--muted); min-width: 2.4ch; }
.power[aria-checked="true"] .power-label { color: var(--on); }

/* ── Corps : sidebar + chat ── */
.body { flex: 1; min-height: 0; display: flex; position: relative; }
.sidebar { width: var(--side-w); flex: none; display: flex; flex-direction: column; gap: 0.5rem; padding: 0.9rem 0.75rem;
  border-right: 1px solid var(--hair-2); background: oklch(0.17 0.004 265 / 0.45);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); overflow: hidden; transition: transform 0.32s var(--ease); }
.new-conv { display: flex; align-items: center; gap: 0.55rem; width: 100%; padding: 0.7rem 0.85rem; border-radius: var(--r-sm);
  border: 1px solid var(--hair); background: var(--mat-2); color: var(--ink); font-weight: 560; cursor: pointer; box-shadow: var(--sh-1);
  transition: background 0.18s var(--ease); }
.new-conv:hover { background: oklch(0.29 0.006 265); }
.new-conv svg { color: var(--accent); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; margin: 0.3rem -0.25rem 0; padding: 0 0.25rem; }
.conv { display: flex; align-items: center; gap: 0.5rem; padding: 0.55rem 0.7rem; border-radius: var(--r-xs); cursor: pointer;
  color: var(--ink-2); font-size: 0.88rem; position: relative; transition: background 0.15s var(--ease), color 0.15s var(--ease); }
.conv:hover { background: oklch(1 0 0 / 0.05); color: var(--ink); }
.conv.active { background: oklch(0.72 0.14 262 / 0.16); color: var(--ink); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del { opacity: 0; border: none; background: none; color: var(--faint); cursor: pointer; padding: 2px; border-radius: 5px; display: grid; place-items: center; transition: opacity 0.15s, color 0.15s, background 0.15s; }
.conv:hover .conv-del { opacity: 1; } .conv-del:hover { color: var(--crit); background: oklch(1 0 0 / 0.06); }
.conv-day { font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); font-weight: 600; padding: 0.7rem 0.7rem 0.3rem; }
.sidebar-foot { display: flex; flex-direction: column; gap: 0.4rem; padding: 0.55rem 0 0.2rem; border-top: 1px solid var(--hair-2); }
.sidebar-foot-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0 0.5rem; }
.model-foot { font-size: 0.72rem; color: var(--faint); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-switch { display: flex; flex-direction: column; gap: 0.32rem; padding: 0.1rem 0.5rem 0.15rem; }
.model-switch-lbl { font-size: 0.66rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); font-weight: 640; }
.model-select-wrap { position: relative; display: flex; align-items: center; }
.model-select { -webkit-appearance: none; appearance: none; width: 100%; background: var(--mat-2);
  border: 1px solid var(--hair); border-radius: var(--r-sm); color: var(--ink-2);
  font-family: var(--font); font-size: 0.78rem; font-weight: 540; letter-spacing: -0.006em;
  padding: 0.5rem 2rem 0.5rem 0.66rem; cursor: pointer; box-shadow: var(--sh-1);
  transition: border-color 0.18s var(--ease), color 0.18s var(--ease), background 0.18s var(--ease); }
.model-select:hover { color: var(--ink); background: var(--mat); }
.model-select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px oklch(0.72 0.14 262 / 0.16); }
.model-select:disabled { opacity: 0.6; cursor: progress; }
.model-select option { background: var(--solid); color: var(--ink); }
.model-select-wrap::after { content: ""; position: absolute; right: 0.72rem; top: 50%; width: 7px; height: 7px;
  border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted);
  transform: translateY(-72%) rotate(45deg); pointer-events: none; }
.model-spin { position: absolute; right: 1.95rem; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid oklch(1 0 0 / 0.16); border-top-color: var(--accent); animation: mspin 0.7s linear infinite; }
@keyframes mspin { to { transform: rotate(360deg); } }
.scrim { position: absolute; inset: 0; z-index: var(--z-scrim); background: oklch(0 0 0 / 0.5); backdrop-filter: blur(2px); }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: clamp(1.2rem, 3.5vw, 2.4rem) clamp(1rem, 5vw, 3rem); display: flex; flex-direction: column; gap: 1.35rem; scroll-behavior: smooth; }
.welcome { margin: auto; max-width: 42ch; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0.85rem; color: var(--muted); animation: rise 0.6s var(--ease) both; }
.welcome h2 { font-size: clamp(1.5rem, 4vw, 1.95rem); color: var(--ink); font-weight: 640; }
.welcome p { margin: 0; font-size: 0.98rem; max-width: 38ch; }

.msg { max-width: min(70ch, 90%); display: flex; flex-direction: column; gap: 0.35rem; animation: rise 0.4s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.msg .who { font-size: 0.7rem; letter-spacing: 0.05em; color: var(--faint); text-transform: uppercase; font-weight: 600; }
.msg .bubble { border-radius: var(--r); padding: 0.85rem 1.05rem; box-shadow: var(--sh-1); }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: oklch(0.72 0.14 262 / 0.16); border: 1px solid oklch(0.72 0.14 262 / 0.25); border-bottom-right-radius: 6px; }
.msg.ai { align-self: flex-start; }
.msg.ai .bubble { background: var(--mat); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--hair-2); border-bottom-left-radius: 6px; }
.bubble p { margin: 0 0 0.6rem; } .bubble p:last-child { margin-bottom: 0; }
.bubble :where(code) { font-family: var(--mono); font-size: 0.85em; background: oklch(0.3 0.006 265); padding: 0.12em 0.38em; border-radius: 6px; }
.bubble pre { background: var(--bg-2); border: 1px solid var(--hair-2); border-radius: var(--r-sm); padding: 0.85rem 0.95rem; overflow-x: auto; margin: 0.55rem 0; }
.bubble pre code { background: none; padding: 0; font-size: 0.84em; line-height: 1.55; }
/* Bloc code avec aperçu live */
.code-block { margin: 0.6rem 0; border: 1px solid var(--hair); border-radius: var(--r-sm); overflow: hidden; background: var(--bg-2); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.34rem 0.55rem; background: oklch(0.19 0.005 265); border-bottom: 1px solid var(--hair-2); }
.code-lang { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.code-tabs { display: flex; gap: 2px; padding: 2px; background: oklch(0.14 0.004 265); border-radius: 8px; }
.code-tab { border: none; background: none; color: var(--muted); font-size: 0.74rem; font-weight: 540; padding: 0.24rem 0.68rem; border-radius: 6px; cursor: pointer; transition: background 0.16s var(--ease), color 0.16s var(--ease); }
.code-tab:hover { color: var(--ink); }
.code-tab.active { background: var(--mat-2); color: var(--ink); box-shadow: var(--sh-1); }
.code-block > pre { margin: 0; border: none; border-radius: 0; background: none; }
.code-preview { background: #fff; }
.preview-frame { width: 100%; height: 340px; border: 0; display: block; background: #fff; resize: vertical; min-height: 140px; }
/* Notice de compaction auto (mémoire résumée) */
.compact-note { align-self: center; display: inline-flex; align-items: center; gap: 0.5rem; margin: 0.3rem auto; padding: 0.42rem 0.95rem;
  font-size: 0.78rem; color: var(--ink-2); text-align: center;
  background: oklch(0.72 0.14 262 / 0.1); border: 1px solid oklch(0.72 0.14 262 / 0.22); border-radius: var(--pill);
  box-shadow: var(--sh-1); animation: compactIn 0.5s var(--ease) both; }
.compact-spark { display: inline-block; animation: compactPulse 1.7s var(--ease) infinite; }
@keyframes compactIn { from { opacity: 0; transform: translateY(7px) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes compactPulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.25); opacity: 0.65; } }
.msg.ai .bubble.streaming::after { content: "▍"; color: var(--accent); animation: caret 1.05s steps(2) infinite; }
@keyframes caret { 50% { opacity: 0; } }

.composer { padding: 0.7rem clamp(1rem, 5vw, 3rem) clamp(1rem, 2.4vw, 1.5rem); background: linear-gradient(oklch(0.152 0.004 265 / 0), var(--bg) 55%); }
.composer-inner { display: flex; align-items: flex-end; gap: 0.6rem; max-width: 76ch; margin: 0 auto; background: var(--mat);
  backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6); border: 1px solid var(--hair);
  border-radius: var(--r); padding: 0.5rem 0.5rem 0.5rem 1rem; box-shadow: var(--sh-1); transition: border-color 0.2s, box-shadow 0.2s; }
.composer-inner:focus-within { border-color: oklch(0.72 0.14 262 / 0.6); box-shadow: var(--sh-1), 0 0 0 4px oklch(0.72 0.14 262 / 0.12); }
#input { flex: 1; background: none; border: none; resize: none; max-height: 40vh; padding: 0.45rem 0; outline: none; line-height: 1.55; }
#input::placeholder { color: var(--faint); }
.send { flex: none; width: 40px; height: 40px; border-radius: 11px; border: none; cursor: pointer; background: var(--accent); color: oklch(0.15 0.03 262);
  display: grid; place-items: center; box-shadow: 0 4px 14px -6px var(--accent); transition: background 0.2s var(--ease), transform 0.12s var(--spring); }
.send:hover:not(:disabled) { background: var(--accent-hi); } .send:active:not(:disabled) { transform: scale(0.92); }
.send:disabled { background: oklch(0.3 0.006 265); color: var(--faint); cursor: not-allowed; box-shadow: none; }
.composer-hint { max-width: 76ch; margin: 0.55rem auto 0; text-align: center; font-size: 0.78rem; color: var(--faint); min-height: 1em; }
.composer-hint.warn { color: var(--warn); }

/* ── Responsive ── */
@media (max-width: 820px) {
  .sidebar { position: absolute; inset: 0 auto 0 0; z-index: var(--z-side); transform: translateX(-100%); box-shadow: var(--sh-2); }
  .sidebar.open { transform: none; }
  /* Barre du haut sur 2 lignes : (marque | moteur), puis TOUTES les stats en pleine largeur.
     Aucune info masquée sur mobile — elles s'enroulent au lieu d'être coupées. */
  .topbar { flex-wrap: wrap; row-gap: 0.55rem; }
  .topbar-left { order: 1; }
  .topbar-engine { order: 2; margin-left: auto; }
  .topbar-health { order: 3; flex-basis: 100%; width: 100%; justify-content: space-between;
    flex-wrap: wrap; gap: 0.7rem 0.9rem; overflow: visible;
    padding-top: 0.6rem; margin-top: 0.1rem; border-top: 1px solid var(--hair-2); }
  .stat { flex: 0 0 auto; }
  .stat-min { display: flex; }
}
@media (max-width: 430px) {
  .brand strong { display: none; }
  .topbar-health { gap: 0.6rem 0.7rem; }
  .stat-k { font-size: 0.6rem; } .stat-v { font-size: 0.78rem; }
  .stat-bar { width: 100%; min-width: 42px; }
}
@media (min-width: 821px) { .scrim { display: none; } .sidebar.hidden-desk { width: 0; padding: 0; border: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
