/* Conseil IA — interface légère, PC + iPhone, clair/sombre */
:root {
  --bg: #f6f5f2; --panel: #ffffff; --panel-2: #efede8; --text: #1d1f24; --muted: #6b6f78; --border: #dedbd3;
  --user: #e8e6df; --claude: #d97757; --claude-bg: #fbeee8; --gpt: #3b82f6; --gpt-bg: #e9f1fe;
  --synth: #8b5cf6; --synth-bg: #f1ecfe; --danger: #d64545; --primary: #1d1f24; --primary-text: #fff;
  --radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .05);
  --safe-top: env(safe-area-inset-top); --safe-bottom: env(safe-area-inset-bottom);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c; --panel: #1b1e26; --panel-2: #232733; --text: #e8e9ec; --muted: #9aa0ab; --border: #2e3340;
    --user: #2a2f3b; --claude-bg: #2d211d; --gpt-bg: #1a2436; --synth-bg: #241d36; --primary: #e8e9ec; --primary-text: #14161c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; }
.spacer { flex: 1; }

/* Boutons */
.btn { border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: .55rem .9rem; cursor: pointer; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger.ghost { background: transparent; color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { border: 0; background: transparent; font-size: 1.15rem; width: 2.4rem; height: 2.4rem; border-radius: 10px; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--panel-2); }
.dot { display: inline-block; width: .8rem; height: .8rem; border-radius: 50%; }
.dot.claude { background: var(--claude); } .dot.gpt { background: var(--gpt); margin-left: -.3rem; }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 2rem 1.5rem; text-align: center; box-shadow: var(--shadow); display: grid; gap: .75rem; }
.login-card h1 { margin: .25rem 0 0; font-size: 1.5rem; }
.login-card p { margin: 0 0 .5rem; }
.login-card .logo .dot { width: 1.4rem; height: 1.4rem; }
input, select, textarea { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gpt); outline-offset: -1px; }

/* Mise en page */
.app { display: grid; grid-template-columns: 290px 1fr; height: 100dvh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: calc(.9rem + var(--safe-top)) .9rem calc(.9rem + var(--safe-bottom)); display: flex; flex-direction: column; gap: .6rem; overflow: hidden; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .35rem; }
.field-label { font-size: .8rem; color: var(--muted); margin-top: .4rem; }
.row { display: flex; gap: .3rem; align-items: center; }
.row select { flex: 1; min-width: 0; }
#project-desc { margin: 0; max-height: 3.2em; overflow: hidden; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: .2rem -.3rem; }
.conv-item { text-align: left; border: 0; background: transparent; padding: .55rem .6rem; border-radius: 9px; cursor: pointer; display: flex; gap: .45rem; align-items: baseline; }
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-2); font-weight: 600; }
.conv-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backdrop { display: none; }
.only-mobile { display: none; }

/* Chat */
.chat { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.chat-head { display: flex; align-items: center; gap: .4rem; padding: calc(.6rem + var(--safe-top)) 1rem .6rem; border-bottom: 1px solid var(--border); background: var(--bg); }
.chat-title { flex: 1; min-width: 0; }
.chat-title h2 { margin: 0; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .9rem; overscroll-behavior: contain; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 28rem; }
.msg { max-width: min(760px, 92%); border-radius: var(--radius); padding: .7rem .95rem; border: 1px solid transparent; overflow-wrap: anywhere; }
.msg .who { font-size: .8rem; font-weight: 700; margin-bottom: .2rem; display: flex; gap: .4rem; align-items: center; }
.msg .who .meta { font-weight: 400; color: var(--muted); }
.msg.user { align-self: flex-end; background: var(--user); }
.msg.claude { align-self: flex-start; background: var(--claude-bg); border-color: color-mix(in srgb, var(--claude) 30%, transparent); }
.msg.claude .who { color: var(--claude); }
.msg.gpt { align-self: flex-start; background: var(--gpt-bg); border-color: color-mix(in srgb, var(--gpt) 30%, transparent); }
.msg.gpt .who { color: var(--gpt); }
.msg.synthesis { align-self: stretch; max-width: none; background: var(--synth-bg); border: 1px solid color-mix(in srgb, var(--synth) 45%, transparent); }
.msg.synthesis .who { color: var(--synth); }
.msg.error { border-style: dashed; opacity: .85; }
.msg.stopped .who::after { content: "interrompu"; font-weight: 400; color: var(--muted); }
.msg.typing .body:empty::before { content: "réfléchit…"; color: var(--muted); animation: pulse 1.2s infinite; }
.msg .body > :first-child { margin-top: 0; } .msg .body > :last-child { margin-bottom: 0; }
.msg .body p { margin: .45rem 0; } .msg .body ul, .msg .body ol { margin: .4rem 0; padding-left: 1.3rem; }
.msg .body h3, .msg .body h4, .msg .body h5, .msg .body h6 { margin: .7rem 0 .3rem; font-size: 1rem; }
.msg .body pre { background: var(--panel-2); padding: .6rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; }
.msg .body code { font-family: ui-monospace, Menlo, monospace; font-size: .88em; }
.msg .body blockquote { margin: .4rem 0; padding-left: .7rem; border-left: 3px solid var(--border); color: var(--muted); }
.msg.user .body { white-space: pre-wrap; }
@keyframes pulse { 50% { opacity: .35; } }

.banner { margin: 0 1rem .5rem; padding: .5rem .8rem; border-radius: 10px; background: var(--panel-2); font-size: .9rem; }

/* Saisie */
.composer { border-top: 1px solid var(--border); background: var(--bg); padding: .6rem .8rem calc(.6rem + var(--safe-bottom)); display: grid; gap: .45rem; }
.modes { display: flex; gap: .35rem; overflow-x: auto; scrollbar-width: none; }
.mode { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: .3rem .75rem; white-space: nowrap; cursor: pointer; font-size: .9rem; }
.mode[aria-checked="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.mode.opt { margin-left: auto; }
.options { display: flex; flex-wrap: wrap; gap: .5rem 1rem; font-size: .9rem; }
.options select { width: auto; padding: .25rem .4rem; }
.send-row { display: flex; gap: .45rem; align-items: flex-end; }
.send-row textarea { flex: 1; resize: none; max-height: 40dvh; min-height: 2.8rem; line-height: 1.4; }
.send-row .btn { height: 2.8rem; }
.send-row .send { width: 3rem; font-size: 1.1rem; }
.send-extra { display: flex; align-items: center; gap: .6rem; min-height: 1.6rem; }

/* Fenêtre projet */
.dialog { border: 1px solid var(--border); border-radius: 18px; padding: 1.2rem; width: min(640px, calc(100vw - 2rem)); background: var(--panel); color: var(--text); }
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog form { display: grid; gap: .75rem; }
.dialog h3 { margin: 0; }
.dialog label { display: grid; gap: .3rem; font-size: .9rem; }
.dialog-actions { display: flex; gap: .5rem; align-items: center; }

/* Mobile */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 20; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .backdrop { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 10; }
  .msg { max-width: 94%; }
  .messages { padding: .8rem .7rem; }
}

/* V2 — Réglages */
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.tabs { display: flex; gap: .3rem; background: var(--panel-2); padding: .25rem; border-radius: 12px; }
.tab { flex: 1; border: 0; background: transparent; padding: .45rem; border-radius: 9px; cursor: pointer; font-size: .92rem; }
.tab[aria-selected="true"] { background: var(--panel); font-weight: 600; box-shadow: var(--shadow); }
.settings-fields { display: grid; gap: .7rem; }
.settings-fields label { display: grid; gap: .25rem; font-size: .9rem; }
.icon-field { width: 5.5rem; flex: none; }
.icon-field input { text-align: center; }
.grow { flex: 1; }

/* V2 — Modèles */
.msg .fallback { font-size: .8rem; margin: -.1rem 0 .35rem; padding: .25rem .5rem; border-radius: 7px; background: color-mix(in srgb, #f59e0b 16%, transparent); }
.model-tools { display: flex; flex-wrap: wrap; gap: .4rem; padding-top: .3rem; border-top: 1px solid var(--border); }

/* V2 — 🧠 Résumé */
.summary-panel { display: grid; gap: .55rem; }
.summary-panel h4 { margin: .4rem 0 0; font-size: .95rem; }
.summary-panel p { margin: 0; }
.decisions { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.decisions li { display: flex; align-items: center; gap: .3rem; background: var(--panel-2); border-radius: 8px; padding: .3rem .3rem .3rem .6rem; }
.decisions li > span:first-child { flex: 1; }
.decisions .icon-btn { width: 1.9rem; height: 1.9rem; font-size: .85rem; }
.msg .fallback.info { background: color-mix(in srgb, var(--gpt) 12%, transparent); }
.link-btn { border: 0; background: none; color: var(--gpt); text-decoration: underline; cursor: pointer; padding: 0; font-size: inherit; }
