/* ============================================================
   QSH IA - styles (clair / sombre automatique)
   ============================================================ */
:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f0f2f8;
  --border: #e3e6ef;
  --text: #161a26;
  --muted: #687089;
  --brand: #3b5bfd;
  --brand-2: #00c2a8;
  --brand-soft: #eaeeff;
  --danger: #e5484d;
  --ok: #12a150;
  --warn: #d98b00;
  --user-bubble: #3b5bfd;
  --user-text: #ffffff;
  --shadow: 0 6px 24px rgba(20, 30, 70, .08);
  --radius: 14px;
  --sidebar: 280px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e111a;
    --panel: #161a26;
    --panel-2: #1d2232;
    --border: #2a3045;
    --text: #e9ecf5;
    --muted: #9099b3;
    --brand: #6a83ff;
    --brand-soft: #232a48;
    --user-bubble: #3b5bfd;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
img { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, transform .05s; text-decoration: none;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.block { width: 100%; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 90px; }
.check { display: flex; align-items: center; gap: 9px; font-weight: 500; color: var(--text); font-size: 14px; cursor: pointer; margin: 12px 0; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.error-msg { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }
.ok-msg { color: var(--ok); font-size: 14px; margin-top: 10px; }

/* ---------- Page de connexion ---------- */
.auth-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--brand-soft), transparent),
              radial-gradient(900px 500px at 110% 110%, rgba(0, 194, 168, .12), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-logo img { width: 52px; height: 52px; border-radius: 12px; object-fit: contain; }
.auth-logo h1 { font-size: 22px; margin: 0; letter-spacing: -.3px; }
.auth-logo p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-card h2 { margin: 0 0 4px; font-size: 18px; }
.test-banner { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 20px; padding: 12px 14px; border-radius: 12px;
  background: #fff6e0; border: 1px solid #f3d27a; color: #6b4a00; font-size: 13px; line-height: 1.45; }
.test-banner span { font-size: 18px; line-height: 1.2; }
.test-banner b { font-size: 14px; }
.beta-tag { font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; padding: 2px 7px; border-radius: 99px;
  background: #fff6e0; color: #8a5d00; border: 1px solid #f3d27a; }
@media (prefers-color-scheme: dark) {
  .test-banner { background: #2e2510; border-color: #6b5320; color: #f3d9a0; }
  .beta-tag { background: #2e2510; border-color: #6b5320; color: #f3d9a0; }
}
.auth-card .sub { color: var(--muted); margin: 0 0 8px; font-size: 14px; }

/* ---------- Structure de l'appli ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar); flex: 0 0 var(--sidebar); background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; }
.side-head img { width: 34px; height: 34px; border-radius: 9px; object-fit: contain; }
.side-head strong { font-size: 17px; letter-spacing: -.2px; }
.side-new { padding: 6px 12px 10px; }
.side-nav { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 10px; border: 0;
  background: transparent; border-radius: 9px; cursor: pointer; color: var(--text); font-size: 14px;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; }
.side-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; padding: 14px 18px 6px; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; min-height: 0; }
.conv { display: flex; align-items: center; gap: 4px; border-radius: 9px; }
.conv button.open { flex: 1; text-align: left; background: none; border: 0; padding: 8px 10px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); font-size: 14px; border-radius: 9px; }
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--brand-soft); }
.conv .del { opacity: 0; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px 8px; border-radius: 7px; }
.conv:hover .del { opacity: 1; }
.side-user { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; flex: 0 0 36px; font-size: 14px; }
.avatar.lg { width: 84px; height: 84px; flex-basis: 84px; font-size: 28px; }
.side-user .who { flex: 1; min-width: 0; line-height: 1.25; }
.side-user .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.side-user .who span { color: var(--muted); font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel); }
.topbar strong { flex: 1; }
.view { flex: 1; overflow-y: auto; min-height: 0; }
.page { max-width: 980px; margin: 0 auto; padding: 28px 24px 60px; }
.page h1 { font-size: 24px; margin: 0 0 6px; letter-spacing: -.3px; }
.page .lead { color: var(--muted); margin: 0 0 22px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card h2 { font-size: 16px; margin: 0 0 6px; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 6px; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; height: 100%; }
.messages { flex: 1; overflow-y: auto; padding: 24px 16px; min-height: 0; }
.messages-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.msg .bubble { max-width: min(680px, 85%); padding: 12px 16px; border-radius: 16px; background: var(--panel); border: 1px solid var(--border); overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bubble); color: var(--user-text); border-color: transparent; border-bottom-right-radius: 5px; }
.msg.assistant .bubble { border-bottom-left-radius: 5px; }
.msg .bubble p { margin: 0 0 8px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble ul, .msg .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.msg .bubble code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg .bubble pre { background: var(--panel-2); padding: 10px 12px; border-radius: 9px; overflow-x: auto; }
.msg .bubble pre code { background: none; padding: 0; }
.msg .bubble h3, .msg .bubble h4 { margin: 10px 0 6px; font-size: 15px; }
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.msg-images img { width: 130px; height: 130px; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
.ai-badge { width: 34px; height: 34px; border-radius: 10px; flex: 0 0 34px; object-fit: contain; background: var(--panel); border: 1px solid var(--border); padding: 3px; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite both; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.welcome { text-align: center; margin: 8vh auto 0; max-width: 560px; padding: 0 12px; }
.welcome img { width: 72px; height: 72px; border-radius: 18px; }
.welcome h1 { font-size: 26px; margin: 14px 0 6px; }
.welcome p { color: var(--muted); }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-top: 22px; text-align: left; }
.suggestions button { border: 1px solid var(--border); background: var(--panel); border-radius: 12px; padding: 12px 14px; cursor: pointer; color: var(--text); font-size: 14px; }
.suggestions button:hover { border-color: var(--brand); }

.composer { padding: 10px 16px 16px; }
.composer-box { max-width: 820px; margin: 0 auto; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 8px; box-shadow: var(--shadow); }
.composer-previews { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 4px 8px; }
.composer-previews:empty { display: none; }
.composer-previews .pv { position: relative; }
.composer-previews img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.composer-previews button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); cursor: pointer; font-size: 13px; line-height: 1; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea { border: 0; box-shadow: none !important; resize: none; min-height: 24px; max-height: 200px; padding: 9px 6px; background: transparent; }
.icon-btn { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 11px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.send { background: var(--brand); color: #fff; }
.icon-btn.send:disabled { opacity: .45; }
.icon-btn svg { width: 20px; height: 20px; }
.composer-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }

/* Cartes dans le chat (document, visuel, mail) */
.tool-card { margin-top: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2); overflow: hidden; color: var(--text); }
.tool-card .tc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; font-weight: 600; font-size: 14px; }
.tool-card .tc-body { padding: 0 12px 12px; }
.tool-card .preview { display: block; width: 100%; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: zoom-in; }
.tool-card .preview.doc { max-height: 520px; object-fit: contain; }
.tool-card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel); border: 1px solid var(--border); color: var(--muted); }
.tag.ok { color: var(--ok); border-color: currentColor; }
.tag.warn { color: var(--warn); border-color: currentColor; }
.tag.err { color: var(--danger); border-color: currentColor; }
.tag.brand { color: var(--brand); border-color: currentColor; }
.networks { display: flex; gap: 14px; flex-wrap: wrap; }
.networks .check { margin: 6px 0; }

/* ---------- Tableaux & grilles ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { display: block; font-size: 24px; margin-top: 4px; letter-spacing: -.3px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.tile img { width: 100%; aspect-ratio: 3/4; object-fit: cover; object-position: top; background: #fff; cursor: zoom-in; border-bottom: 1px solid var(--border); }
.tile .tile-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.tile .tile-body b { font-size: 14px; }
.tile .tile-body small { color: var(--muted); }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--border); background: var(--panel); padding: 7px 14px; border-radius: 99px; cursor: pointer; font-size: 14px; color: var(--text); }
.tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.mail-item { display: flex; gap: 12px; padding: 12px 10px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: baseline; }
.mail-item:hover { background: var(--panel-2); }
.mail-item.unread b { color: var(--text); }
.mail-item .from { width: 200px; flex: 0 0 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.mail-item.unread .from { color: var(--text); font-weight: 700; }
.mail-item .subj { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-item .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mail-body { white-space: pre-wrap; background: var(--panel-2); padding: 14px; border-radius: 10px; max-height: 50vh; overflow: auto; font-size: 14px; }

/* ---------- Fenêtres ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(8, 10, 20, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 18px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 22px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .85); z-index: 60; display: grid; place-items: center; padding: 20px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; z-index: 70; font-size: 14px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }
.install-banner { display: flex; align-items: center; gap: 10px; margin: 8px 12px; padding: 10px 12px; border-radius: 11px; background: var(--brand-soft); font-size: 13px; }
.install-banner button { margin-left: auto; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar { display: flex; }
  .page { padding: 20px 16px 50px; }
  .mail-item { flex-wrap: wrap; }
  .mail-item .from { width: auto; flex: 1 1 100%; }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 39; }
}
