:root {
  --bg: #f6f7f9; --panel: #ffffff; --side: #eef1f5; --text: #1b1f24; --muted: #5d6673; --line: #dde2e8;
  --accent: #0b63ce; --accent-text: #ffffff; --accent-soft: #e3eefc; --user: #0b63ce; --user-text: #ffffff;
  --danger: #c4332b; --code: #f0f2f5; --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c; --panel: #1d2126; --side: #191c21; --text: #e6e9ed; --muted: #9aa3ae; --line: #2e343b;
    --accent: #4d94f0; --accent-text: #0d1117; --accent-soft: #1e2b3d; --user: #2a5ea8; --user-text: #f4f7fb;
    --danger: #f0716a; --code: #262b31;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link.danger { color: var(--danger); }
.icon { background: none; border: 0; color: var(--text); font-size: 20px; padding: 6px 10px; cursor: pointer; border-radius: 8px; }
.icon:hover { background: var(--side); }

/* Connexion */
body.login { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; color: var(--text); text-decoration: none; }
.brand h1 { font-size: 22px; margin: 0; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }
.brand.small { margin: 0; font-weight: 700; font-size: 16px; gap: 8px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
input[type=email], input[type=password], input[type=text], textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn.google { width: 100%; }
.sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Coquille commune : barre latérale + contenu, toujours sur toute la hauteur de la fenêtre */
/* Fixée aux quatre bords de la fenêtre : remplit toute la hauteur quel que soit le navigateur (100vh/100dvh et les
   hauteurs en % dans une grille ne se comportent pas pareil partout). */
body.app { position: fixed; inset: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr); overflow: hidden; }
#sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; padding: 14px; min-height: 0; }
.side-head { display: flex; justify-content: space-between; align-items: center; }
.mainnav { display: grid; gap: 2px; margin: 0 -6px; }
.mainnav a { padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 15px; }
.mainnav a:hover { background: var(--panel); }
.mainnav a.active { background: var(--accent-soft); color: var(--accent); }
.side-fill { flex: 1; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; }
#convs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; }
#convs a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
#convs a:hover { background: var(--panel); }
#convs a.active { background: var(--accent-soft); font-weight: 600; }
#convs a.running::after { content: " ●"; color: var(--accent); }
.side-foot { display: grid; gap: 8px; font-size: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.side-foot a { text-decoration: none; }
.side-foot .link { color: var(--muted); text-align: left; }

#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar h2 { flex: 1; font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .link { font-size: 14px; font-weight: 600; }
#conv-actions { display: flex; gap: 14px; font-size: 14px; }
#conv-actions[hidden] { display: none; }
#thread { flex: 1; overflow-y: auto; padding: 24px max(20px, calc((100% - 820px) / 2)); display: flex; flex-direction: column; gap: 18px; }
.empty { margin: auto 0; text-align: center; color: var(--muted); }
.empty[hidden] { display: none; }
.empty h3 { color: var(--text); font-size: 22px; margin: 0 0 6px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 22px; text-align: left; }
.suggestions button { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--text); font: inherit; font-size: 14px; cursor: pointer; text-align: left; }
.suggestions button:hover { border-color: var(--accent); }

.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.user .body { background: var(--user); color: var(--user-text); padding: 10px 14px; border-radius: 16px 16px 4px 16px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .body { overflow-wrap: anywhere; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.body h1, .body h2, .body h3 { font-size: 17px; margin: 18px 0 8px; }
.body p, .body ul, .body ol { margin: 0 0 10px; }
.body li { margin: 3px 0; }
.body code { background: var(--code); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.body pre { background: var(--code); padding: 12px; border-radius: 10px; overflow-x: auto; }
.body pre code { padding: 0; background: none; }
.body table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0 0 12px; font-size: 14px; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.body th { background: var(--side); }
.body blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.status { color: var(--muted); font-size: 14px; margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.status[hidden] { display: none; }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }

.levels { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 10px max(20px, calc((100% - 820px) / 2)) 0; font-size: 13px; color: var(--muted); }
.levels label { display: inline-flex; align-items: center; gap: 6px; }
.levels select { padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; }
#composer { display: flex; gap: 10px; align-items: flex-end; padding: 12px max(20px, calc((100% - 820px) / 2)) 4px; }
#composer textarea { resize: none; max-height: 220px; border-radius: 14px; padding: 12px 14px; background: var(--panel); }
#composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#composer .btn { height: 46px; }
#composer .btn[hidden] { display: none; }
.hint { margin: 0; padding: 0 20px 12px; text-align: center; font-size: 12px; color: var(--muted); }
.only-mobile, #scrim { display: none; }
.only-narrow { display: none; }

@media (max-width: 760px) {
  body.app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  body.side-open #sidebar { box-shadow: 0 0 40px rgba(0,0,0,.25); }
  body.side-open #scrim { display: block; position: fixed; inset: 0; z-index: 9; background: rgba(0,0,0,.3); }
  body.side-open #sidebar { transform: none; }
  button.only-mobile { display: inline-block; }
  .topbar { padding: 8px 10px; }
  #thread { padding: 16px; }
  .levels { padding: 8px 16px 0; }
  #composer { padding: 10px 16px 4px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .msg.user .body { max-width: 92%; }
}

/* Pages simples */
.page-wrap { max-width: 860px; margin: 0 auto; padding: 8px 20px 40px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 18px 0; }
.card h2 { margin-top: 0; font-size: 18px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 14px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.upload { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 12px 0 18px; }
.docs { width: 100%; border-collapse: collapse; font-size: 14px; }
.docs th, .docs td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.docs th { color: var(--muted); font-weight: 600; }
@media (max-width: 600px) { .docs th:nth-child(3), .docs td:nth-child(3) { display: none; } }

/* Catalogue */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.filters input[type=search] { flex: 1 1 260px; min-width: 0; }
.filters input[type=number] { width: 130px; }
.filters select, .filters input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; }
.cat-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.cats { overflow-y: auto; border-right: 1px solid var(--line); padding: 10px 8px 30px; background: var(--panel); }
.cat-group summary { cursor: pointer; padding: 7px 8px; font-weight: 700; font-size: 14px; border-radius: 8px; list-style-position: inside; }
.cat-group summary:hover { background: var(--side); }
.cat-list { padding: 2px 0 8px; }
a.cat { display: block; padding: 5px 10px; border-radius: 7px; color: var(--text); text-decoration: none; font-size: 14px; }
a.cat:hover { background: var(--side); }
a.cat.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.results { overflow-y: auto; padding: 14px 20px 30px; min-height: 0; }
.crumb { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; margin-bottom: 14px; }
.crumb a { text-decoration: none; }
.crumb .sep { color: var(--muted); }
.crumb .count { margin-left: auto; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.pcard { display: flex; flex-direction: column; gap: 6px; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; font: inherit; color: var(--text); cursor: pointer; }
.pcard:hover { border-color: var(--accent); }
.pimg { aspect-ratio: 4 / 3; background: #fff; border-radius: 8px; display: grid; place-items: center; overflow: hidden; }
.pimg img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pname { font-size: 14px; font-weight: 600; line-height: 1.35; flex: 1; }
.psku { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted); }
.pprice { font-size: 14px; }
.badge { align-self: flex-start; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge.ok { background: #e3f6e8; color: #17703a; }
.badge.ko { background: #fde7e5; color: #b0261e; }
.badge.warn { background: #fff1d6; color: #8a5a00; }
@media (prefers-color-scheme: dark) {
  .badge.ok { background: #173523; color: #7fdc9f; }
  .badge.ko { background: #3d1c1a; color: #f39a93; }
  .badge.warn { background: #3a2e12; color: #f0c56b; }
}
.more { display: flex; justify-content: center; margin-top: 18px; }
.home { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.home-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.home-card h3 { margin: 0 0 10px; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.detail { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--panel); border-left: 1px solid var(--line); box-shadow: -10px 0 40px rgba(0,0,0,.15); z-index: 5; display: flex; flex-direction: column; }
.detail[hidden] { display: none; }
.detail .close { position: absolute; top: 8px; right: 8px; z-index: 1; background: var(--panel); }
#detail-body { flex: 1; overflow-y: auto; padding: 20px 22px 40px; }
.dimg { width: 100%; max-height: 300px; object-fit: contain; background: #fff; border-radius: 10px; }
.thumbs { display: flex; gap: 6px; margin: 8px 0; overflow-x: auto; }
.thumbs img { width: 56px; height: 56px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; flex: none; }
#detail-body h3 { margin: 14px 40px 6px 0; font-size: 18px; }
.dmeta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 14px; align-items: center; }
.dmeta code { background: var(--code); padding: 2px 6px; border-radius: 5px; }
.dprice { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 17px; margin: 12px 0; }
.dactions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
#detail-body h4 { margin: 20px 0 8px; font-size: 15px; }
.specs { width: 100%; border-collapse: collapse; font-size: 14px; }
.specs th, .specs td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.specs th { color: var(--muted); font-weight: 500; width: 45%; }
.ddesc { white-space: pre-wrap; font-size: 14px; }
@media (max-width: 900px) {
  .only-narrow { display: inline-flex; }
  .cat-layout { grid-template-columns: minmax(0, 1fr); position: relative; }
  .cats { display: none; position: absolute; inset: 0; z-index: 4; border-right: 0; }
  body.cats-open .cats { display: block; }
}
@media (max-width: 760px) {
  .filters { padding: 8px 12px; gap: 6px; }
  .filters input[type=search] { flex: 1 1 55%; }
  .filters select { flex: 1 1 30%; min-width: 0; }
  .filters input[type=number] { width: 104px; }
  .results { padding: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .small-hide { display: none; }
}

/* Pages publiques (confidentialité) */
.legal-link { margin: 18px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.legal h1 { font-size: 26px; }
.legal h2 { font-size: 18px; margin-top: 26px; }
.legal li { margin: 6px 0; }

/* Retour sous une réponse */
.fb { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 10px; font-size: 13px; }
.fb-v { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 999px; padding: 3px 10px; font: inherit; cursor: pointer; }
.fb-v:hover { border-color: var(--accent); }
.fb-v.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.fb-form { flex-basis: 100%; display: grid; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.fb-form[hidden] { display: none; }
.fb-form label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
.fb-form textarea { font-weight: 400; resize: vertical; }
.fb-actions { display: flex; gap: 8px; }
.msg.pending .fb { display: none; }

/* Apprentissages */
.lesson { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.lesson.off .lesson-text { color: var(--muted); text-decoration: line-through; }
.lesson-text { width: 100%; }
.lesson-meta { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.lesson-tools { display: flex; gap: 10px; align-items: start; }
.lesson textarea { font: inherit; }
.add-lesson { display: flex; gap: 8px; margin: 12px 0 4px; }
.add-lesson input { flex: 1; }
.fb-list td { vertical-align: top; }
.clip { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
