/* LocalLM — chat simple, thème sombre, mobile-first (iOS) */

:root {
  --bg: #0b0d10; --s1: #13171c; --s2: #1b2128; --s3: #262e38; --line: #2a323c;
  --txt: #e9edf2; --mut: #8e99a8; --acc: #6b8cff; --acc-d: #4a68d6; --err: #ff6b6b;
  --tap: 48px;
  color-scheme: dark;
  --vvh: 100dvh;   /* mis à jour par app.js : suit le clavier iOS */
  --vvt: 0px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--txt);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
body { position: fixed; inset: 0; overflow: hidden; }
button, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { position: fixed; left: 0; right: 0; top: var(--vvt); height: var(--vvh); display: flex; flex-direction: column; max-width: 720px; margin-inline: auto; }
@media (min-width: 760px) { #app { border-inline: 1px solid var(--line); } }

/* En-tête */
#topbar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) max(10px, env(safe-area-inset-right, 0px)) 6px max(10px, env(safe-area-inset-left, 0px));
  background: var(--s1); border-bottom: 1px solid var(--line);
}
#modelSel {
  flex: 1; color-scheme: dark; min-width: 0; height: 44px; padding: 0 12px;
  background: var(--s2); border: 1px solid var(--line); border-radius: 14px; font-size: 15px;
}
.icon-btn {
  width: var(--tap); height: var(--tap); flex: none; border: 0; border-radius: 14px;
  background: var(--s2); font-size: 24px; display: grid; place-items: center;
}
.icon-btn:active { background: var(--s3); }

/* Messages */
#chat { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); }
#msgs { max-width: 760px; margin: 0 auto; }
.msg { display: flex; flex-direction: column; margin: 12px 0; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }
.bubble {
  max-width: 90%; padding: 10px 14px; border-radius: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text;
}
.user .bubble { background: var(--acc); color: #fff; border-bottom-right-radius: 6px; }
.assistant .bubble { background: var(--s2); border-bottom-left-radius: 6px; }
.bubble.streaming::after { content: "▍"; color: var(--acc); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.bubble code { font: 0.88em ui-monospace, "SF Mono", Menlo, monospace; background: rgba(255,255,255,.09); padding: 1px 5px; border-radius: 6px; }
.bubble pre { margin: 8px 0; padding: 10px 12px; background: #0a0c0f; border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; white-space: pre; }
.bubble pre code { background: none; padding: 0; font-size: 0.85em; }
.bubble details.think { margin: 0 0 8px; padding: 6px 10px; background: rgba(255,255,255,.05); border-radius: 10px; color: var(--mut); font-size: 14px; }

.tools { display: flex; align-items: center; gap: 4px; margin-top: 2px; color: var(--mut); font-size: 12px; }
.tools button { min-height: 40px; padding: 0 10px; border: 0; background: transparent; color: var(--mut); font-size: 13px; border-radius: 10px; }
.tools button:active { background: var(--s3); }
.tools span { padding: 0 6px; }

.empty { text-align: center; padding: 14vh 18px 0; color: var(--mut); }
.empty h2 { margin: 0 0 6px; color: var(--txt); font-size: 22px; }
.empty p { margin: 6px auto; max-width: 420px; font-size: 15px; }

/* Bandeau d'erreur / info */
#notice { position: relative; flex: none; margin: 0 12px 8px; padding: 12px 44px 12px 14px; border-radius: 14px; border: 1px solid; font-size: 14px; }
#notice.err  { background: #2b1a1a; border-color: #6a3434; color: #ffd9d9; }
#notice.warn { background: #2b2417; border-color: #6a5430; color: #ffe8c2; }
#notice.info { background: #17232b; border-color: #2f566a; color: #d5ecf9; }
#notice .n-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
#notice .n-actions button { min-height: 40px; padding: 0 14px; border-radius: 12px; border: 1px solid currentColor; background: transparent; }
#notice .n-close { position: absolute; top: 4px; right: 4px; width: 40px; height: 40px; border: 0; background: transparent; font-size: 16px; opacity: .8; }

/* Progression du téléchargement */
#progress { flex: none; margin: 0 12px 8px; padding: 10px 14px; background: var(--s2); border: 1px solid var(--line); border-radius: 14px; font-size: 14px; }
#progress .p-row { display: flex; justify-content: space-between; gap: 10px; }
#progress .bar { height: 8px; margin: 8px 0 6px; background: var(--s3); border-radius: 4px; overflow: hidden; }
#pBar { height: 100%; width: 0; background: var(--acc); transition: width .25s; }
#progress .p-sub { color: var(--mut); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Saisie */
#composer { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 8px max(12px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--line); background: var(--bg); }
body.kb #composer { padding-bottom: 8px; }
#input {
  flex: 1; min-height: var(--tap); max-height: 140px; padding: 12px 16px;
  border: 1px solid var(--line); border-radius: 24px; background: var(--s2);
  resize: none; outline: none; font-size: 16px; line-height: 1.35;   /* 16px : pas de zoom auto sur iOS */
}
#input:focus { border-color: var(--acc); }
#btnSend { width: var(--tap); height: var(--tap); flex: none; border: 0; border-radius: 50%; background: var(--acc); color: #fff; font-size: 20px; display: grid; place-items: center; }
#btnSend:active { background: var(--acc-d); }
#btnSend.stop { background: var(--err); }
#btnSend.busy { opacity: .45; pointer-events: none; }

/* Boutons génériques */
button.primary, button.ghost { min-height: var(--tap); padding: 0 18px; border-radius: 14px; border: 1px solid var(--line); font-weight: 600; }
button.primary { background: var(--acc); border-color: var(--acc); color: #fff; }
button.primary:active { background: var(--acc-d); }
button.ghost { background: var(--s2); }
button.ghost:active { background: var(--s3); }
button.danger { color: var(--err); border-color: #5a2f2f; }
button.wide { width: 100%; margin-top: 10px; }

/* Panneau de réglages */
#scrim { position: fixed; left: 0; right: 0; top: var(--vvt); height: var(--vvh); background: rgba(0,0,0,.6); z-index: 20; }
#sheet {
  position: fixed; left: 0; right: 0; max-width: 720px; margin-inline: auto;
  top: calc(var(--vvt) + 36px); height: calc(var(--vvh) - 36px);
  background: var(--s1); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  transform: translateY(105%); transition: transform .28s ease; z-index: 40;
}
#sheet.open { transform: none; }
@media (prefers-reduced-motion: reduce) { #sheet { transition: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px 18px; flex: none; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 max(16px, env(safe-area-inset-right, 0px)) calc(28px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left, 0px)); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet-body h3 { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--mut); }
.sheet-body label { display: block; margin: 12px 0 0; font-size: 14px; color: var(--mut); }
.sheet-body label output { float: right; color: var(--txt); }
.sheet-body select, .sheet-body textarea, .sheet-body input[type="url"], .sheet-body input[type="password"] { display: block; width: 100%; min-height: var(--tap); margin-top: 6px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--s2); color: var(--txt); font-size: 16px; outline: none; }
.sheet-body textarea { resize: vertical; }
.sheet-body input[type="range"] { width: 100%; height: 36px; margin: 4px 0 0; accent-color: var(--acc); }
.sheet-body label.check { display: flex; align-items: center; gap: 12px; min-height: var(--tap); margin: 8px 0 0; color: var(--txt); font-size: 15px; }
.sheet-body label.check input { width: 24px; height: 24px; flex: none; accent-color: var(--acc); }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--mut); }

/* Cartes de modèles */
.model { display: block; width: 100%; margin: 8px 0; padding: 12px 14px; text-align: left; border: 1px solid var(--line); border-radius: 14px; background: var(--s2); cursor: pointer; }
.model:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.model.sel { border-color: var(--acc); background: #1a2238; }
.model.off { opacity: .45; cursor: not-allowed; }
.model .m-name { font-weight: 600; }
.model .m-meta, .model .m-note { margin-top: 4px; font-size: 13px; color: var(--mut); }
.model a { color: var(--acc); text-decoration: none; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; background: var(--s3); color: var(--mut); }
.badge.ok { background: #12322a; color: #3ddc97; }
.badge.warn { background: #3a2f14; color: #ffb454; }
.badge.err { background: #3a1b1b; color: var(--err); }
.badge.acc { background: #1e2a52; color: var(--acc); }
