/* Police Inter auto-hébergée (RGPD : aucun appel à Google Fonts) */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/inter-400.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/inter-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/inter-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/inter-700.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 800; font-display: swap; src: url('/fonts/inter-800.woff2') format('woff2'); }

:root {
  /* Palette Diagonale Santé */
  --brand: #1B5E20;          /* vert Diagonale (accent officiel) */
  --brand-2: #2E7D32;        /* vert clair (dégradés) */
  --brand-dark: #14431A;
  --sand: #D7C7A8;           /* sable chaud (accent) */
  --sand-soft: #efe7d6;
  --cream: #F7F4EE;          /* fond crème */
  --panel: #ffffff;
  --text: #1A1A1A;
  --muted: #75726b;
  --border: #E5E0D6;
  --user-bubble: #1B5E20;
  --danger: #C0392B;
  --ok: #15803D;
  --shadow: 0 1px 2px rgba(27, 64, 32, .06), 0 10px 30px rgba(27, 64, 32, .07);
  --radius: 12px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); background: var(--cream); color: var(--text); font-size: 15px; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button { font-family: inherit; }

/* ───────────── Login ───────────── */
.login-view { min-height: 100%; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero {
  position: relative; overflow: hidden; color: #fff;
  background: linear-gradient(150deg, var(--brand-2), var(--brand) 55%, var(--brand-dark));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px;
}
/* trait diagonal = signature de marque */
.login-hero::before, .login-hero::after {
  content: ""; position: absolute; left: -20%; width: 140%; height: 80px;
  background: rgba(255,255,255,.06); transform: rotate(-22deg);
}
.login-hero::before { top: 22%; }
.login-hero::after { top: 60%; height: 36px; background: rgba(215,199,168,.14); }
.hero-mascot { width: 132px; height: 132px; filter: drop-shadow(0 8px 18px rgba(0,0,0,.25)); position: relative; }
.hero-word { font-size: 40px; font-weight: 800; letter-spacing: -.02em; margin-top: 10px; position: relative; }
.hero-slash { display: inline-block; width: 5px; height: .8em; background: var(--sand); transform: skewX(-22deg); border-radius: 2px; margin-left: 7px; vertical-align: -1px; }
.hero-tagline { max-width: 360px; font-size: 16px; opacity: .95; position: relative; }
.hero-brand { font-size: 13px; letter-spacing: .04em; opacity: .8; position: relative; text-transform: uppercase; }
.hero-brand em { color: var(--sand); font-style: italic; text-transform: none; }

.login-card {
  align-self: center; justify-self: center; width: 100%; max-width: 380px; margin: 24px;
  background: var(--panel); border-radius: 16px; padding: 34px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; color: var(--brand); font-size: 24px; }
.login-card .subtitle { margin: 0 0 6px; color: var(--muted); }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 15px; }
.login-card input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.login-card button { margin-top: 6px; padding: 12px; background: var(--brand); color: #fff; border: none; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; }
.login-card button:hover { background: var(--brand-dark); }
.error { color: var(--danger); font-size: 13px; margin: 0; }
.privacy-note { font-size: 11px; color: var(--muted); margin: 4px 0 0; line-height: 1.4; }
.auth-banner { font-size: 13px; padding: 9px 12px; border-radius: 9px; margin: 2px 0; line-height: 1.4; }
.auth-banner.ok { background: #e0f0e4; color: var(--ok); }
.auth-banner.err { background: #fbe3df; color: var(--danger); }
.auth-banner.info { background: var(--sand-soft); color: #6b5a35; }
.auth-switch { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.auth-switch a { color: var(--brand); cursor: pointer; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* ───────────── Layout app ───────────── */
.app-view, .admin-view { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mascot { width: 38px; height: 38px; flex-shrink: 0; }
.brand-name { font-size: 18px; font-weight: 800; color: var(--brand); letter-spacing: -.01em; line-height: 1.1; }
.brand-slash { display: inline-block; width: 3px; height: .85em; background: var(--sand); transform: skewX(-22deg); border-radius: 2px; margin-left: 5px; vertical-align: -1px; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.user-email { color: var(--muted); font-size: 13px; }
.model-select { font-family: inherit; font-size: 12.5px; color: var(--text); background: var(--cream); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; max-width: 230px; cursor: pointer; }
.model-select:focus { outline: 2px solid var(--brand); border-color: transparent; }
.link-btn { background: none; border: none; color: var(--brand); cursor: pointer; font-size: 13px; padding: 6px 8px; border-radius: 8px; white-space: nowrap; }
.link-btn:hover { background: var(--sand-soft); }

/* ───────────── Messages ───────────── */
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.welcome { max-width: 720px; margin: 18px auto; text-align: center; color: var(--muted); }
.welcome-mascot { width: 96px; height: 96px; }
.welcome h2 { color: var(--text); margin: 10px 0 8px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.suggestion { background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 9px 15px; cursor: pointer; color: var(--brand); font-size: 13px; }
.suggestion:hover { border-color: var(--brand); background: var(--sand-soft); }

.msg { max-width: 780px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; }
.msg .role { font-size: 12px; color: var(--muted); margin-bottom: 5px; display: flex; align-items: center; gap: 6px; }
.msg .role img { width: 20px; height: 20px; }
.bubble { padding: 13px 16px; border-radius: var(--radius); line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; max-width: 88%; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; box-shadow: var(--shadow); white-space: normal; }

/* Rendu Markdown dans les réponses de l'assistant */
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: .5em 0; }
.answer h1, .answer h2, .answer h3, .answer h4 { margin: .7em 0 .35em; line-height: 1.25; color: var(--text); }
.answer h1 { font-size: 1.25em; } .answer h2 { font-size: 1.15em; } .answer h3 { font-size: 1.05em; } .answer h4 { font-size: 1em; }
.answer ul, .answer ol { margin: .4em 0; padding-left: 1.35em; }
.answer li { margin: .25em 0; }
.answer li > ul, .answer li > ol { margin: .2em 0; }
.answer strong { font-weight: 700; }
.answer em { font-style: italic; }
.answer a { color: var(--brand); text-decoration: underline; }
.answer blockquote { margin: .6em 0; padding: .4em .9em; border-left: 3px solid var(--sand); background: var(--sand-soft); border-radius: 6px; color: #5b5346; }
.answer code { background: #eef2ec; border: 1px solid var(--border); border-radius: 5px; padding: .05em .35em; font-size: .9em; font-family: ui-monospace, Menlo, Consolas, monospace; }
.answer pre { background: #f3f1ea; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.answer pre code { background: none; border: none; padding: 0; }
.answer hr { border: none; border-top: 1px solid var(--border); margin: .8em 0; }
.answer table { border-collapse: collapse; margin: .5em 0; font-size: .95em; }
.answer th, .answer td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.answer th { background: var(--sand-soft); }
.cursor { display: inline-block; width: 7px; height: 1.1em; background: var(--brand-2); vertical-align: text-bottom; animation: blink 1s steps(2) infinite; border-radius: 1px; }
@keyframes blink { 50% { opacity: 0; } }

.cite { display: inline-block; min-width: 18px; text-align: center; background: var(--brand-2); color: #fff; border-radius: 5px; padding: 0 5px; font-size: 11px; font-weight: 700; cursor: pointer; vertical-align: super; line-height: 1.4; margin: 0 1px; }

/* Feedback */
.feedback { margin-top: 8px; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.fb-btn { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; cursor: pointer; padding: 3px 9px; font-size: 14px; }
.fb-btn:hover { border-color: var(--brand); }
.fb-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.fb-thanks { color: var(--ok); }

/* Questions de suivi suggérées (façon LLM moderne) */
.followups { margin-top: 12px; }
.followups-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.followup-chip { display: block; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 9px 13px; margin: 6px 0; cursor: pointer; color: var(--brand); font-size: 13.5px; line-height: 1.4; transition: border-color .15s, background .15s; }
.followup-chip::before { content: "→ "; color: var(--muted); }
.followup-chip:hover { border-color: var(--brand); background: var(--sand-soft); }

/* Sources — affichage compact (puces) pour laisser la place à la réponse */
.sources { margin-top: 10px; }
.sources-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
.source-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.source-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 240px; border: 1px solid var(--border); background: #fcfbf7; border-radius: 999px; padding: 3px 11px 3px 4px; font-size: 12px; color: var(--text); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-chip:hover { border-color: var(--brand); }
.source-chip.active { border-color: var(--brand); background: var(--sand-soft); }
.chip-num { background: var(--brand); color: #fff; border-radius: 999px; min-width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.source-detail { margin-top: 8px; border: 1px solid var(--border); border-radius: 9px; background: #fcfbf7; padding: 9px 12px; }
.source-detail-head { display: flex; align-items: center; gap: 8px; }
.source-detail .source-doc { font-weight: 600; font-size: 13px; }
.source-detail .source-section { color: var(--muted); font-size: 12px; margin-top: 3px; }
.source-detail .source-excerpt { margin-top: 4px; color: #313a37; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.source-passage { padding: 8px 0; border-top: 1px dashed var(--border); }
.source-passage:first-of-type { border-top: none; padding-top: 4px; }
.source-passage.hl { background: #fff6d6; border-radius: 6px; padding: 8px 10px; }
.source-dl { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--brand); }

/* ───────────── Composer ───────────── */
.composer { border-top: 1px solid var(--border); background: var(--panel); padding: 12px 18px calc(8px + env(safe-area-inset-bottom)); }
#chat-form { display: flex; gap: 10px; max-width: 780px; margin: 0 auto; align-items: flex-end; }
#chat-input { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; font-size: 15px; font-family: inherit; max-height: 180px; line-height: 1.4; }
#chat-input:focus { outline: 2px solid var(--brand); border-color: transparent; }
#send-btn { width: 44px; height: 44px; border-radius: 14px; border: none; background: var(--brand); color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0; }
#send-btn:disabled { background: #b6c3b3; cursor: default; }
.disclaimer { text-align: center; color: var(--muted); font-size: 11px; margin: 8px 0 2px; }

/* ───────────── Console admin ───────────── */
.admin-body { flex: 1; overflow-y: auto; padding: 22px; max-width: 1040px; width: 100%; margin: 0 auto; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-value { font-size: 28px; font-weight: 800; color: var(--brand); line-height: 1; }
.stat-value.warn { color: #B8860B; }
.stat-value.bad { color: var(--danger); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 6px; }

.admin-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 13px; color: var(--text); }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.questions-list { display: flex; flex-direction: column; gap: 12px; }
.q-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.q-card.unanswered { border-left: 4px solid var(--danger); }
.q-top { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.q-question { font-weight: 600; font-size: 15px; }
.q-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.q-answer { margin-top: 8px; color: #3a3a36; font-size: 14px; line-height: 1.5; max-height: 110px; overflow: auto; }
.q-tags { margin-top: 9px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.q-tag { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--sand-soft); color: #6b5a35; }
.q-tag.bad { background: #fbe3df; color: var(--danger); }
.q-tag.ok { background: #e0f0e4; color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* ───────────── Profils / comptes (console admin) ───────────── */
.admin-section { margin: 6px 0 4px; }
.admin-section-title { margin: 20px 0 4px; font-size: 15px; }
.admin-section-hint { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }
.users-list { display: flex; flex-direction: column; gap: 8px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; box-shadow: var(--shadow); }
.user-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.user-mail { font-weight: 500; word-break: break-all; }
.role-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--sand-soft); color: #6b5a35; }
.role-badge.admin { background: var(--brand); color: #fff; }
.role-badge.warn { background: #fbe3df; color: var(--danger); }
.role-locked { font-size: 12px; color: var(--muted); white-space: nowrap; }
.role-btn { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 6px 11px; cursor: pointer; font-size: 12.5px; color: var(--brand); white-space: nowrap; flex-shrink: 0; }
.role-btn:hover { border-color: var(--brand); background: var(--sand-soft); }
.role-btn:disabled { opacity: .5; cursor: default; }

/* ───────────── Modale ───────────── */
.modal { position: fixed; inset: 0; background: rgba(20,30,22,.45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 14px; width: 100%; max-width: 560px; max-height: 80vh; overflow: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
/* Upload de documents */
.docs-upload { padding: 16px 20px 4px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  border: 2px dashed var(--border); border-radius: 12px; padding: 22px 16px; cursor: pointer;
  color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--sand-soft); }
.dz-icon { font-size: 24px; }
.dz-text { font-size: 14px; color: var(--text); }
.dz-link { color: var(--brand); text-decoration: underline; }
.dz-hint { font-size: 12px; }
.upload-status { margin-top: 10px; font-size: 13px; padding: 9px 12px; border-radius: 9px; }
.upload-status.loading { background: var(--sand-soft); color: #6b5a35; }
.upload-status.ok { background: #e0f0e4; color: var(--ok); }
.upload-status.err { background: #fbe3df; color: var(--danger); }

.docs-list { padding: 12px 20px 20px; display: flex; flex-direction: column; gap: 10px; }
.doc-item { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.doc-item .doc-info { flex: 1; min-width: 0; }
.doc-item .doc-title { font-weight: 600; }
.doc-item .doc-meta { color: var(--muted); font-size: 12px; }
.doc-del { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 6px 9px; cursor: pointer; font-size: 14px; line-height: 1; color: var(--danger); flex-shrink: 0; }
.doc-del:hover { border-color: var(--danger); background: #fbe3df; }
.doc-del:disabled { opacity: .5; cursor: default; }

/* ───────────── Responsive / mobile ───────────── */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .login-view { grid-template-columns: 1fr; }
  .login-hero { padding: 30px 24px 26px; }
  .hero-mascot { width: 96px; height: 96px; }
  .hero-word { font-size: 32px; }
  .hero-tagline { font-size: 15px; }
  .login-card { margin: 18px; padding: 26px; box-shadow: none; border: 1px solid var(--border); }

  .topbar { padding: 9px 12px; }
  .brand-mascot { width: 34px; height: 34px; }
  .brand-name { font-size: 16px; }
  .brand-sub { display: none; }
  .user-email { display: none; }
  .link-btn { padding: 6px 7px; font-size: 13px; }
  .topbar-right { flex-wrap: wrap; justify-content: flex-end; gap: 6px 10px; }
  .model-select { max-width: 150px; font-size: 12px; padding: 5px 6px; }

  .messages { padding: 16px 12px; gap: 14px; }
  .msg.user .bubble { max-width: 92%; }
  .composer { padding: 10px 12px calc(8px + env(safe-area-inset-bottom)); }

  .admin-body { padding: 14px 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 22px; }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .hero-word { font-size: 28px; }
}
