/* Nils — application privée. Sobre, calme, lisible. Sombre par défaut, clair si le système le demande. */
:root {
  --bg: #0e1116; --bg-2: #141922; --card: #181e28; --line: #262e3b; --line-2: #313b4b;
  --text: #e8ebf0; --muted: #8b95a5; --accent: #4f7cff; --accent-2: #2f5bea; --accent-soft: rgba(79, 124, 255, .14);
  --ok: #3fb67a; --warn: #e0a331; --bad: #ec5b5b; --bad-soft: rgba(236, 91, 91, .14); --warn-soft: rgba(224, 163, 49, .14); --ok-soft: rgba(63, 182, 122, .14);
  --radius: 14px; --radius-s: 10px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f5f6f8; --bg-2: #eceef2; --card: #ffffff; --line: #e1e4ea; --line-2: #d3d8e0; --text: #161a21; --muted: #6a7382; --accent: #2f5bea; --accent-soft: rgba(47, 91, 234, .1); color-scheme: light; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .6rem; font-weight: 600; }
h3 { margin: 0 0 .5rem; font-size: 1.1rem; }
pre { white-space: pre-wrap; word-break: break-word; font: inherit; margin: 0; }
code { background: var(--bg-2); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.error { color: var(--bad); min-height: 1.2em; }
.late { color: var(--bad); }

/* ─────────── Boutons ─────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 42px; padding: 0 1rem; border-radius: var(--radius-s); border: 1px solid var(--line-2); background: var(--card); cursor: pointer; font-weight: 500; white-space: nowrap; touch-action: manipulation; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.btn.small { min-height: 34px; padding: 0 .7rem; font-size: .88rem; }
.btn.block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--bg-2); color: var(--text); }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.link { background: none; border: 0; color: var(--accent); padding: .4rem 0; cursor: pointer; font-weight: 500; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .65rem .8rem; min-height: 44px; width: 100%; font-size: 16px; /* pas de zoom iOS */ }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: .85rem; color: var(--muted); margin: .8rem 0 .3rem; }

/* ─────────── Connexion ─────────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom)); }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card form { text-align: left; margin-top: 1.2rem; }
.login-card .btn { margin-top: 1.2rem; }
#pair-code { font-size: 1.8rem; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }
.logo { width: 64px; height: 64px; margin: 0 auto 1rem; border-radius: 18px; background: var(--accent-2); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 2rem; }
.logo.small { width: 36px; height: 36px; border-radius: 10px; font-size: 1.1rem; margin: 0; }
.hint { background: var(--accent-soft); border-radius: var(--radius-s); padding: .7rem .9rem; font-size: .9rem; text-align: left; }
.help { text-align: left; margin-top: 1.5rem; color: var(--muted); font-size: .9rem; }
.help summary { cursor: pointer; }

/* ─────────── Coque ─────────── */
.app { min-height: 100dvh; }
.sidebar { display: none; }
.main { padding: calc(12px + var(--safe-top)) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px); max-width: 860px; margin: 0 auto; }
.view-inner { display: flex; flex-direction: column; gap: 1rem; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px); border-top: 1px solid var(--line); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .68rem; position: relative; -webkit-tap-highlight-color: transparent; }
.tab.active { color: var(--accent); }
.tab .badge { position: absolute; top: 6px; left: calc(50% + 6px); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--muted); color: #fff; font-size: .7rem; font-weight: 700; display: inline-grid; place-items: center; line-height: 1; }
.badge.critical { background: var(--bad); } .badge.accent { background: var(--accent); }

/* Discussion : plein écran sur iPhone quand elle est affichée, masquée sinon. */
.chat { display: none; }
body[data-route="chat"] .main { display: none; }
body[data-route="chat"] .chat { display: flex; position: fixed; inset: 0 0 calc(var(--tabbar-h) + var(--safe-bottom)) 0; padding-top: var(--safe-top); }
.chat { flex-direction: column; background: var(--bg); min-height: 0; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: .5rem .8rem .5rem 1rem; border-bottom: 1px solid var(--line); }
.chat-title { display: flex; flex-direction: column; line-height: 1.2; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .55rem; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.msg { max-width: 86%; padding: .65rem .9rem; border-radius: 18px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.serious { border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.msg.sending { opacity: .7; } .msg.error { border-color: var(--bad); }
.msg .meta { font-size: .7rem; opacity: .7; margin-top: .25rem; }
.msg .actions { display: flex; gap: .5rem; margin-top: .6rem; }
.msg.intro { color: var(--muted); }
.day-sep { align-self: center; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: .6rem 0 .2rem; }
.suggestions { display: flex; gap: .5rem; overflow-x: auto; padding: 0 1rem .5rem; scrollbar-width: none; }
.suggestions::-webkit-scrollbar { display: none; }
.suggestion { flex: none; border: 1px solid var(--line-2); background: var(--card); border-radius: 999px; padding: .45rem .85rem; font-size: .88rem; cursor: pointer; }
.composer { display: flex; align-items: flex-end; gap: .5rem; padding: .5rem .75rem .6rem; border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { resize: none; max-height: 160px; min-height: 46px; border-radius: 23px; padding: .7rem 1rem; line-height: 1.3; }
.composer .send { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--bg-2); color: var(--accent); display: grid; place-items: center; cursor: pointer; flex: none; }
.mic { width: 56px; height: 56px; margin-bottom: -5px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; box-shadow: 0 4px 16px rgba(47, 91, 234, .35); order: 3; touch-action: manipulation; }
.mic.unavailable { background: var(--bg-2); color: var(--muted); box-shadow: none; }
.mic[data-state="listening"] { background: var(--bad); animation: pulse 1.4s infinite; }
.mic[data-state="thinking"] { background: var(--muted); }
.mic[data-state="speaking"] { background: var(--ok); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(236, 91, 91, .5); } 70% { box-shadow: 0 0 0 14px rgba(236, 91, 91, 0); } 100% { box-shadow: 0 0 0 0 rgba(236, 91, 91, 0); } }
.voice-bar { display: flex; align-items: center; gap: .8rem; margin: 0 .75rem .5rem; padding: .7rem .9rem; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); }
.voice-orb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); flex: none; }
.voice-bar[data-state="listening"] .voice-orb { background: var(--bad); animation: pulse 1.4s infinite; }
.voice-bar[data-state="speaking"] .voice-orb { background: var(--ok); }
.voice-bar[data-state="thinking"] .voice-orb { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.voice-text { flex: 1; min-width: 0; }
.voice-state { font-weight: 600; font-size: .9rem; }
.voice-transcript { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; }

/* ─────────── Vues ─────────── */
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem; padding-top: .4rem; }
.lead { color: var(--muted); margin: .3rem 0 0; }
.block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.empty { color: var(--muted); margin: .2rem 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list.plain li { padding: .35rem 0; border-bottom: 1px solid var(--line); } .list.plain li:last-child { border: 0; }
.row-item { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); cursor: default; }
.row-item:last-child { border-bottom: 0; }
.row-item.col { flex-direction: column; align-items: stretch; gap: .35rem; }
.row-item.done .item-title { text-decoration: line-through; color: var(--muted); }
.row-item.read { opacity: .65; } .row-item.unread .item-title { font-weight: 700; }
.grow { flex: 1; min-width: 0; }
.item-title { font-weight: 500; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.sub { color: var(--muted); font-size: .86rem; margin-top: .15rem; }
.sub.pre { white-space: pre-wrap; }
.row { display: flex; align-items: center; gap: .5rem; } .row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; } .row.end { justify-content: flex-end; }
.row-actions { display: flex; gap: .2rem; }
.time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3.2rem; color: var(--accent); }
.score { min-width: 2.4rem; height: 2.4rem; border-radius: 50%; background: var(--bg-2); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-2); background: transparent; cursor: pointer; flex: none; display: grid; place-items: center; padding: 0; }
.check:hover { border-color: var(--ok); } .check.done { border-color: var(--ok); color: var(--ok); }
.chip { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; background: var(--bg-2); color: var(--muted); white-space: nowrap; }
.chip.critical { background: var(--bad-soft); color: var(--bad); } .chip.high, .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.accent, .chip.estim { background: var(--accent-soft); color: var(--accent); } .chip.ok, .chip.saisi { background: var(--ok-soft); color: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.banner { padding: .7rem .9rem; border-radius: var(--radius-s); background: var(--bg-2); border: 1px solid var(--line); }
.banner.danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); } .banner.warn { background: var(--warn-soft); border-color: transparent; } .banner.ok { background: var(--ok-soft); border-color: transparent; }
.inline-form { display: flex; gap: .5rem; } .inline-form input { flex: 1; }
.inline-form.wrap { flex-wrap: wrap; } .inline-form.wrap > * { flex: 1 1 140px; } .inline-form.wrap .btn { flex: 0 0 auto; }
.inline-form.compact { margin-top: .3rem; }
.filters { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.filters::-webkit-scrollbar { display: none; }
.filters button { flex: none; border: 1px solid var(--line-2); background: transparent; border-radius: 999px; padding: .4rem .85rem; cursor: pointer; font-size: .9rem; }
.filters button.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.kpi { border: 1px solid var(--line); background: var(--card); border-radius: var(--radius-s); padding: .6rem .3rem; display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.kpi strong { font-size: 1.4rem; line-height: 1.1; } .kpi span { font-size: .7rem; color: var(--muted); }
.kpi.critical strong { color: var(--bad); } .kpi.high strong, .kpi.warn strong { color: var(--warn); } .kpi.accent strong { color: var(--accent); } .kpi.zero strong { color: var(--muted); }
.brief { background: var(--bg-2); border-radius: var(--radius-s); padding: .8rem; font-size: .92rem; margin-bottom: .6rem; max-height: 60vh; overflow: auto; }
.preview { background: var(--bg-2); border-radius: var(--radius-s); padding: .6rem .8rem; font-size: .85rem; max-height: 240px; overflow: auto; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: .6rem 0; }
.facts dt { color: var(--muted); font-size: .88rem; } .facts dd { margin: 0; }
.agent h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 1.05rem; color: var(--text); }
.checks { display: flex; flex-direction: column; gap: .2rem; margin: .6rem 0; }
.check-row { display: flex; align-items: center; gap: .6rem; margin: 0; color: var(--text); font-size: .95rem; padding: .35rem 0; cursor: pointer; }
.check-row input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); flex: none; }
.pair-code { margin-top: .8rem; padding: 1rem; border-radius: var(--radius-s); background: var(--accent-soft); display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.pair-code strong { font-size: 2rem; letter-spacing: .15em; font-variant-numeric: tabular-nums; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.menu-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: 1rem .3rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: .85rem; }
.menu-tile .badge { position: absolute; top: 8px; right: 8px; }
/* Finances */
.fin-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.stat { display: flex; flex-direction: column; gap: .3rem; align-items: flex-start; }
.stat.accent { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.big { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.threshold { margin-bottom: .6rem; }
.bar { height: 8px; background: var(--bg-2); border-radius: 4px; overflow: hidden; margin-top: .3rem; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.warn span { background: var(--warn); } .bar.danger span { background: var(--bad); }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 130px; padding: .4rem 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.chart .bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.chart .bars span { width: 40%; max-width: 12px; border-radius: 3px 3px 0 0; min-height: 1px; }
.f { background: var(--accent); } .e { background: var(--ok); }
.chart .lbl { font-size: .62rem; color: var(--muted); margin-top: 3px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.warn-list { color: var(--warn); font-size: .88rem; }

/* Feuille modale, toast, hors ligne, chargement */
.sheet-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; background: var(--card); border-radius: 20px 20px 0 0; padding: 1.2rem 1.2rem calc(1.2rem + var(--safe-bottom)); border: 1px solid var(--line); animation: up .18s ease-out; }
.sheet.wide { max-width: 720px; max-height: 88dvh; overflow: auto; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.toast { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 90px); max-width: min(92vw, 520px); background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 12px; font-size: .92rem; box-shadow: 0 8px 30px rgba(0, 0, 0, .3); white-space: pre-wrap; }
.toast.error { background: var(--bad); color: #fff; }
.offline { position: fixed; z-index: 55; top: var(--safe-top); left: 0; right: 0; text-align: center; background: var(--warn); color: #111; font-size: .85rem; padding: .3rem; }
.loading { display: flex; gap: 6px; justify-content: center; padding: 3rem 0; }
.loading span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: blink 1s infinite; }
.loading span:nth-child(2) { animation-delay: .15s; } .loading span:nth-child(3) { animation-delay: .3s; }

@media (max-width: 380px) { .kpis { grid-template-columns: repeat(3, 1fr); } .menu-grid { grid-template-columns: repeat(2, 1fr); } }

/* ─────────── PC : barre latérale + contenu + discussion ancrée ─────────── */
@media (min-width: 900px) {
  .tabbar { display: none; }
  .app { display: grid; grid-template-columns: 232px minmax(0, 1fr); height: 100dvh; }
  .sidebar { display: flex; flex-direction: column; gap: 1rem; padding: 1rem .7rem; border-right: 1px solid var(--line); background: var(--bg-2); overflow-y: auto; }
  .brand { display: flex; align-items: center; gap: .7rem; padding: 0 .4rem .6rem; }
  .brand > div:nth-child(2) { flex: 1; min-width: 0; }
  .side-link { display: flex; align-items: center; gap: .7rem; padding: .5rem .7rem; border-radius: var(--radius-s); color: var(--muted); font-size: .95rem; }
  .side-link span:nth-child(2) { flex: 1; }
  .side-link:hover { background: var(--card); color: var(--text); }
  .side-link.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
  .main { overflow-y: auto; height: 100dvh; padding: 1.4rem 2rem 3rem; max-width: none; margin: 0; }
  .view-inner { max-width: 880px; margin: 0 auto; }
  body[data-route="chat"] .app { grid-template-columns: 232px minmax(0, 1fr); }
  body[data-route="chat"] .chat { position: static; inset: auto; padding: 0; height: 100dvh; }
  body[data-route="chat"] .messages, body[data-route="chat"] .composer, body[data-route="chat"] .suggestions, body[data-route="chat"] .voice-bar { width: 100%; max-width: 860px; margin-left: auto; margin-right: auto; }
  .filters { margin: 0; padding: 0; flex-wrap: wrap; }
  .fin-grid { grid-template-columns: repeat(4, 1fr); }
  .menu-grid { grid-template-columns: repeat(4, 1fr); }
  .sheet-overlay { align-items: center; } .sheet { border-radius: 20px; }
  .toast { bottom: 24px; }
  .msg { max-width: 72%; }
  .composer .send { order: 2; }
}
@media (min-width: 1200px) {
  .app { grid-template-columns: 232px minmax(0, 1fr) 400px; }
  .chat { display: flex; height: 100dvh; border-left: 1px solid var(--line); }
  .chat .msg { max-width: 88%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* Mode vocal plein écran */
.voice-launch { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; padding: calc(12px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); }
.vl-top { display: flex; align-items: center; justify-content: space-between; }
.vl-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2rem; text-align: center; min-height: 0; }
.vl-mic { width: min(56vw, 220px); height: min(56vw, 220px); border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 10px 40px rgba(47, 91, 234, .45); touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.voice-launch[data-state="listening"] .vl-mic { background: var(--bad); animation: pulse 1.4s infinite; }
.voice-launch[data-state="thinking"] .vl-mic { background: var(--muted); }
.voice-launch[data-state="speaking"] .vl-mic { background: var(--ok); }
.vl-state { font-size: 1.15rem; font-weight: 600; }
.vl-transcript { color: var(--muted); max-width: 32rem; }
.vl-reply { max-width: 34rem; max-height: 34vh; overflow-y: auto; white-space: pre-wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; text-align: left; }
.vl-reply:empty { display: none; }
.vl-hint { color: var(--muted); text-align: center; }
