/* tonecar — interface web (aucune dépendance, thème clair/sombre automatique) */

:root {
  color-scheme: light dark;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --surface-3: #e3e6ec;
  --text: #15181e;
  --muted: #586070;
  --border: #dde1e8;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #dbe6ff;
  --on-primary: #ffffff;
  --green: #15803d;
  --green-soft: #dcfce7;
  --green-text: #166534;
  --yellow: #eab308;
  --yellow-soft: #fef3c7;
  --yellow-text: #854d0e;
  --orange: #c2410c;
  --orange-soft: #ffedd5;
  --orange-text: #9a3412;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --red-text: #991b1b;
  --grey: #6b7280;
  --grey-soft: #e5e7eb;
  --grey-text: #374151;
  --star: #d97706;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 10px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 30px rgba(16, 24, 40, .18);
  --header-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --surface-3: #2a2f3a;
    --text: #e8eaef;
    --muted: #9aa3b2;
    --border: #2c313c;
    --primary: #5b8cff;
    --primary-hover: #7aa2ff;
    --primary-soft: #1d2a4a;
    --on-primary: #0b1020;
    --green: #22a35a;
    --green-soft: #12301f;
    --green-text: #6ee7a0;
    --yellow: #eab308;
    --yellow-soft: #33290a;
    --yellow-text: #fcd34d;
    --orange: #ea6a1f;
    --orange-soft: #3a1f0e;
    --orange-text: #fdba74;
    --red: #dc3b3b;
    --red-soft: #3a1414;
    --red-text: #fca5a5;
    --grey: #6b7280;
    --grey-soft: #262b35;
    --grey-text: #c4cad4;
    --star: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 2px 10px rgba(0, 0, 0, .25);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, .55);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 100;
  background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm);
}
.skip-link:focus { left: 8px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --- En-tête ------------------------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1360px; margin: 0 auto; height: var(--header-h);
  display: flex; align-items: center; gap: 18px; padding: 0 16px;
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; }
.nav a {
  color: var(--muted); padding: 6px 10px; border-radius: var(--radius-sm); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.ai-cost {
  color: var(--muted); background: var(--surface-2); padding: 3px 9px; border-radius: 999px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.user-name { font-weight: 600; }
.logout-icon { display: none; }

@media (max-width: 720px) {
  .topbar-inner { gap: 8px; padding: 0 10px; }
  .nav a { padding: 6px 7px; font-size: .92rem; }
  .user-name { display: none; }
  .topbar-right { gap: 6px; }
  .ai-cost { font-size: .78rem; padding: 2px 7px; }
}
@media (max-width: 440px) {
  .brand { font-size: 1rem; }
  .ai-cost { display: none; }
  .logout-text { display: none; }
  .logout-icon { display: block; }
  .nav a { padding: 6px 5px; }
}

/* --- Mise en page ---------------------------------------------------------------- */

main { max-width: 1360px; margin: 0 auto; padding: 18px 16px 110px; outline: none; }
@media (max-width: 720px) { main { padding: 12px 10px 110px; } }

.page-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.panel + .panel { margin-top: 14px; }
.panel h2 { display: flex; align-items: center; gap: 8px; }

.loading {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--muted); padding: 48px 12px;
}
.spinner {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--surface-3); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
.spinner.large { width: 34px; height: 34px; border-width: 3.5px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

.empty {
  text-align: center; color: var(--muted); padding: 48px 16px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }
.empty .btn { margin-top: 12px; }

.error-box {
  background: var(--red-soft); color: var(--red-text); border: 1px solid color-mix(in srgb, var(--red) 35%, transparent);
  border-radius: var(--radius-sm); padding: 10px 12px; margin: 10px 0;
}
.notice {
  background: var(--yellow-soft); color: var(--yellow-text); border-radius: var(--radius-sm);
  padding: 10px 12px; margin: 12px 0; border: 1px solid color-mix(in srgb, var(--yellow) 35%, transparent);
}
.notice.info { background: var(--primary-soft); color: var(--text); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.notice.danger { background: var(--red-soft); color: var(--red-text); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.notice p:last-child { margin-bottom: 0; }

/* --- Formulaires & boutons ---------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .92rem; line-height: 1.2;
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; white-space: nowrap; min-height: 38px;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: .84rem; min-height: 32px; }
.btn.link {
  background: none; border: none; color: var(--primary); padding: 4px 6px; min-height: 0; font-weight: 500;
}
.btn.link:hover { background: none; text-decoration: underline; }
.btn.active { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 40%, transparent); color: var(--primary); }
.btn .star-on { color: var(--star); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

label { font-size: .85rem; color: var(--muted); font-weight: 500; }
input[type="text"], input[type="search"], input[type="number"], input[type="password"], input[type="url"],
select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 10px; width: 100%;
  min-height: 38px;
}
@media (min-width: 721px) {
  input[type="text"], input[type="search"], input[type="number"], input[type="password"], input[type="url"],
  select, textarea { font-size: .93rem; }
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 0; border-color: var(--primary); }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); margin: 0; flex: none; }

.field { display: flex; flex-direction: column; gap: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: .9rem; cursor: pointer; user-select: none; }

/* --- Connexion ---------------------------------------------------------------------- */

.login-screen {
  position: fixed; inset: 0; z-index: 80; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 28px 24px;
}
.login-card .brand { font-size: 1.8rem; display: block; margin-bottom: 2px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-card .btn { width: 100%; min-height: 44px; }

/* --- Filtres ------------------------------------------------------------------------ */

.filters {
  display: grid; gap: 10px 12px; align-items: end;
  grid-template-columns: minmax(180px, 2fr) repeat(6, minmax(110px, 1fr));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.filters .checks { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.filters .checks .spacer { flex: 1; }
@media (max-width: 1100px) { .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); } .filters .f-q { grid-column: 1 / -1; } }
@media (max-width: 620px) { .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px; } }
.filters-toggle { display: none; }
@media (max-width: 620px) {
  .filters-toggle { display: inline-flex; }
  .filters.collapsed > :not(.f-q):not(.checks) { display: none; }
}

.list-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; color: var(--muted); font-size: .9rem; margin: 0 2px 10px; }

/* --- Cartes d'annonce ---------------------------------------------------------------- */

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
@media (max-width: 620px) { .grid { grid-template-columns: 1fr; gap: 12px; } }

.card {
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card.is-excluded .card-photo img { filter: grayscale(.7); opacity: .8; }
.card.is-selected { outline: 2px solid var(--primary); outline-offset: -1px; }

.card-photo { position: relative; display: block; aspect-ratio: 4 / 3; background: var(--surface-2); overflow: hidden; }
.card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-photo {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .88rem; background: repeating-linear-gradient(135deg, var(--surface-2) 0 12px, var(--surface-3) 12px 24px);
}
.card-photo .score { position: absolute; left: 10px; top: 10px; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.fav-btn {
  position: absolute; right: 8px; top: 8px; width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 1.3rem; line-height: 1;
  background: rgba(0, 0, 0, .45); color: #fff; display: flex; align-items: center; justify-content: center;
}
.fav-btn:hover { background: rgba(0, 0, 0, .65); }
.fav-btn.on { color: #fbbf24; }

.card-body { padding: 12px 14px 12px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.card-title { font-weight: 650; font-size: .98rem; color: var(--text); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-title:hover { color: var(--primary); text-decoration: none; }
.price-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.price { font-size: 1.2rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.old-price { color: var(--muted); text-decoration: line-through; font-size: .9rem; }
.card-meta { color: var(--muted); font-size: .88rem; }
.subscores { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.subscores b { color: var(--text); font-weight: 600; }
.engine-line { display: flex; align-items: center; gap: 6px; font-size: .86rem; min-width: 0; }
.engine-line span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 14px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: .85rem;
}

.score {
  display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 30px;
  padding: 0 8px; border-radius: 999px; font-weight: 800; font-size: .95rem; font-variant-numeric: tabular-nums;
  color: #fff; background: var(--grey);
}
.score.s-green { background: var(--green); }
.score.s-yellow { background: var(--yellow); color: #231a00; }
.score.s-orange { background: var(--orange); }
.score.s-grey { background: var(--grey); }
.score.s-red { background: var(--red); text-decoration: line-through; text-decoration-thickness: 2px; }
.score.big { min-width: 56px; height: 40px; font-size: 1.25rem; }
.score.mini { min-width: 32px; height: 22px; font-size: .78rem; padding: 0 6px; }

.grade {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 5px;
  border-radius: 5px; font-weight: 800; font-size: .76rem; flex: none;
}
.grade.g-A { background: var(--green-soft); color: var(--green-text); }
.grade.g-B { background: var(--yellow-soft); color: var(--yellow-text); }
.grade.g-C { background: var(--orange-soft); color: var(--orange-text); }
.grade.g-X { background: var(--red-soft); color: var(--red-text); }
.grade.g-none { background: var(--grey-soft); color: var(--grey-text); }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: .76rem; font-weight: 600; background: var(--grey-soft); color: var(--grey-text); max-width: 100%;
}
.badge.new { background: var(--primary-soft); color: var(--primary); }
.badge.drop { background: var(--green-soft); color: var(--green-text); }
.badge.partial { background: var(--yellow-soft); color: var(--yellow-text); }
.badge.excluded { background: var(--red-soft); color: var(--red-text); white-space: normal; }
.badge.kind-compare { background: var(--orange-soft); color: var(--orange-text); }
.badge.kind-listing { background: var(--primary-soft); color: var(--primary); }
.badge.kind-general { background: var(--green-soft); color: var(--green-text); }

/* --- Barre de comparaison ------------------------------------------------------------- */

.compare-bar {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px;
  background: var(--text); color: var(--bg); border-radius: 999px; box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 20px);
}
.compare-bar .btn.link { color: var(--bg); opacity: .85; }
.compare-bar .btn.primary { border-radius: 999px; }
.compare-bar .count { font-size: .9rem; white-space: nowrap; }

/* --- Toasts -------------------------------------------------------------------------- */

.toasts {
  position: fixed; top: calc(var(--header-h) + 10px); right: 12px; z-index: 90;
  display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 24px));
}
.toast {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 10px 14px; font-size: .9rem;
}
.toast.error { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }

/* --- Fiche annonce -------------------------------------------------------------------- */

.detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 440px); gap: 18px; align-items: start; }
@media (max-width: 1020px) { .detail { grid-template-columns: minmax(0, 1fr); } }

.back { display: inline-block; margin-bottom: 8px; font-size: .9rem; }
.sheet-head { display: flex; gap: 14px; align-items: flex-start; }
.sheet-head h1 { margin-bottom: 4px; word-break: break-word; }
.sheet-head .score { flex: none; }
.sheet-sub { color: var(--muted); font-size: .92rem; }
.sheet-price { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 10px 0 12px; }
.sheet-price .price { font-size: 1.6rem; }
.sheet-actions { margin-bottom: 14px; }

.gallery-wrap { position: relative; margin: 0 0 14px; }
.gallery {
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius);
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.gallery a { flex: 0 0 auto; scroll-snap-align: start; display: block; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; }
.gallery img { display: block; height: 320px; width: auto; max-width: none; object-fit: cover; }
@media (max-width: 620px) { .gallery img { height: 230px; } }
.gallery-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, .55); color: #fff; font-size: 1.3rem; cursor: pointer;
}
.gallery-nav.prev { left: 8px; }
.gallery-nav.next { right: 8px; }
@media (hover: none) { .gallery-nav { display: none; } }
.gallery-count { position: absolute; right: 10px; bottom: 10px; background: rgba(0, 0, 0, .6); color: #fff; font-size: .78rem; padding: 2px 8px; border-radius: 999px; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px 16px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.facts dd { margin: 0; font-weight: 600; word-break: break-word; }

.scorebars { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 18px; margin-bottom: 14px; }
.scorebar .lbl { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 3px; }
.scorebar .lbl b { font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--grey); }
.bar > span.s-green { background: var(--green); }
.bar > span.s-yellow { background: var(--yellow); }
.bar > span.s-orange { background: var(--orange); }
.bar > span.s-red { background: var(--red); }

.points { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 18px; }
.points h3 { font-size: .9rem; margin-bottom: 4px; }
.points ul, .plain-list { margin: 0; padding-left: 1.15em; }
.points li, .plain-list li { margin: 2px 0; }
.points .pros h3 { color: var(--green-text); }
.points .cons h3 { color: var(--red-text); }
.points .checks h3 { color: var(--yellow-text); }

.kv { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 8px; font-size: .92rem; }
.kv span b { font-weight: 600; }

.history { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.history td { padding: 5px 4px; border-bottom: 1px solid var(--border); }
.history td:last-child { text-align: right; }
.delta-down { color: var(--green-text); font-weight: 600; }
.delta-up { color: var(--red-text); font-weight: 600; }
.sparkline { display: block; width: 100%; height: 56px; margin-bottom: 8px; }
.sparkline polyline { fill: none; stroke: var(--primary); stroke-width: 2; vector-effect: non-scaling-stroke; }
.sparkline circle { fill: var(--primary); }

.description { white-space: pre-wrap; word-break: break-word; font-size: .93rem; }
.description.clamped { max-height: 11.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: .84rem; }

.notes-status { font-size: .8rem; color: var(--muted); min-height: 1.2em; margin-top: 4px; }

.mini-list { display: flex; flex-direction: column; gap: 2px; }
.mini-row {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 6px; border-radius: var(--radius-sm); color: var(--text);
}
.mini-row:hover { background: var(--surface-2); text-decoration: none; }
.mini-row .thumb { width: 64px; height: 48px; border-radius: 6px; object-fit: cover; background: var(--surface-2); display: block; }
.mini-row .t { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row .m { color: var(--muted); font-size: .82rem; }

/* --- Discussion ------------------------------------------------------------------------- */

.chat-panel {
  position: sticky; top: calc(var(--header-h) + 12px);
  height: calc(100vh - var(--header-h) - 24px);
  height: calc(100dvh - var(--header-h) - 24px);
  display: flex; flex-direction: column; padding: 0; overflow: hidden;
}
@media (max-width: 1020px) {
  .chat-panel { position: static; height: auto; min-height: 420px; }
  .chat-panel .messages { max-height: 70vh; }
}
.chat-head { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.chat-head .row { display: flex; gap: 8px; align-items: center; }
.chat-head h2 { margin: 0; font-size: 1rem; }
.chat-head select { min-width: 0; flex: 1; }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.chat-full .messages { overflow: visible; padding: 4px 0 8px; }
.chat-intro { color: var(--muted); font-size: .92rem; text-align: center; padding: 20px 10px; }

.msg { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.msg-meta { font-size: .78rem; color: var(--muted); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.msg-meta b { color: var(--text); font-weight: 650; }
.msg-body { border-radius: 14px; padding: 10px 13px; word-break: break-word; overflow-wrap: anywhere; }
.msg.user { align-items: flex-end; }
.msg.user .msg-body { background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 4px; white-space: pre-wrap; max-width: 92%; }
.msg.assistant .msg-body { background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.assistant.streaming .msg-body::after {
  content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 2px; vertical-align: text-bottom;
  background: var(--primary); animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.msg .error-box { margin: 6px 0 0; font-size: .88rem; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

.quick { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 14px 0; }
.quick .btn { font-weight: 500; font-size: .82rem; min-height: 30px; padding: 5px 10px; border-radius: 999px; white-space: normal; text-align: left; }
.composer { padding: 10px 14px 12px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 220px; resize: none; }
.composer .btn { min-height: 44px; }
.chat-full .quick, .chat-full .composer { padding-left: 0; padding-right: 0; }
.chat-full .composer-wrap {
  position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); margin-top: 6px;
}
.chat-disabled { padding: 10px 14px 14px; }

/* Markdown des réponses */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h3, .md h4, .md h5 { margin: .9em 0 .35em; }
.md h3 { font-size: 1.08rem; }
.md h4 { font-size: 1rem; }
.md h5 { font-size: .94rem; }
.md p { margin: 0 0 .6em; }
.md ul, .md ol { margin: 0 0 .6em; padding-left: 1.35em; }
.md li { margin: .15em 0; }
.md hr { border: none; border-top: 1px solid var(--border); margin: .9em 0; }
.md code { font-family: var(--mono); font-size: .86em; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--surface-3); padding: 10px; border-radius: var(--radius-sm); overflow-x: auto; margin: 0 0 .6em; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 .6em; padding-left: 10px; border-left: 3px solid var(--border); color: var(--muted); }
.md .table-wrap { overflow-x: auto; margin: 0 0 .7em; }
.md table { border-collapse: collapse; font-size: .88rem; min-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-3); font-weight: 650; }

/* --- Tableau comparatif ------------------------------------------------------------------ */

.compare-wrap { overflow-x: auto; margin-bottom: 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
.compare-table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.compare-table th, .compare-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.compare-table tbody th { color: var(--muted); font-weight: 500; white-space: nowrap; position: sticky; left: 0; background: var(--surface); z-index: 1; font-size: .84rem; }
.compare-table td { min-width: 170px; }
.compare-table tr:last-child td, .compare-table tr:last-child th { border-bottom: none; }
.compare-table .ph { display: block; width: 100%; max-width: 220px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); }
.compare-table .best { color: var(--green-text); font-weight: 700; }
.compare-table .ttl { font-weight: 650; }

.conv-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.conv-head h1 { margin: 0; flex: 1 1 260px; font-size: 1.25rem; word-break: break-word; }
.chat-full { max-width: 900px; margin: 0 auto; }
.chat-full .chat-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.chat-full .chat-toolbar select { max-width: 320px; }
.conv-page { max-width: 900px; margin: 0 auto; }
.conv-page.wide { max-width: 1240px; }
.spacer { flex: 1; }
.results { transition: opacity .15s ease; }
.results.is-loading { opacity: .5; pointer-events: none; }
.detail > aside { align-self: stretch; min-width: 0; }
.sheet { min-width: 0; }
.related-convs { font-size: .82rem; color: var(--muted); }
.related-convs a { margin-right: 8px; }
.chat-full .chat-head { padding: 0 0 8px; border-bottom: none; flex-direction: row; flex-wrap: wrap; align-items: center; }
.chat-full .chat-head .row { flex: 0 1 380px; }
.chat-head label { white-space: nowrap; }
.chat-error { margin: 0 14px 8px; }
.chat-full .chat-error { margin: 8px 0; }
.only-narrow { display: none; }
@media (max-width: 1020px) { .only-narrow { display: inline-flex; } }

/* --- Liste des discussions ---------------------------------------------------------------- */

.conv-list { display: flex; flex-direction: column; gap: 8px; }
.conv-item {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.conv-item .main { flex: 1; min-width: 0; }
.conv-item .ttl { font-weight: 650; color: var(--text); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .ttl:hover { color: var(--primary); text-decoration: none; }
.conv-item .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .84rem; color: var(--muted); margin-top: 3px; align-items: center; }

/* --- Import -------------------------------------------------------------------------------- */

.import-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; max-width: 1100px; }
@media (max-width: 900px) { .import-layout { grid-template-columns: minmax(0, 1fr); } }
.import-form { display: flex; flex-direction: column; gap: 12px; }
.import-form textarea { min-height: 180px; }
.help { font-size: .88rem; color: var(--muted); }
.help ul, .help ol { padding-left: 1.2em; margin: 4px 0 8px; }
.bookmarklet {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font-weight: 700; cursor: grab; margin: 6px 0 10px;
  border: 2px dashed color-mix(in srgb, var(--on-primary) 45%, transparent);
}
.bookmarklet:hover { text-decoration: none; background: var(--primary-hover); }
.progress-box { display: flex; align-items: center; gap: 14px; padding: 18px; }

.noscript { padding: 20px; text-align: center; }
