:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #17202f;
  --muted: #677189;
  --line: #e1e5ee;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --mine: #2f6fed;
  --mine-text: #ffffff;
  --voice: #e9eefb;
  --screen: #fbfcfe;
  --ok: #12805c;
  --bad: #c2352b;
  --warn: #b26b00;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131a;
    --panel: #171c25;
    --text: #e6eaf2;
    --muted: #8d97ab;
    --line: #262d3a;
    --accent: #5b8cff;
    --mine: #3a6ee8;
    --voice: #1d2636;
    --screen: #131820;
    --ok: #3cc28f;
    --bad: #ff6b5e;
    --warn: #f0a640;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f131a; --panel: #171c25; --text: #e6eaf2; --muted: #8d97ab; --line: #262d3a;
  --accent: #5b8cff; --mine: #3a6ee8; --voice: #1d2636; --screen: #131820;
  --ok: #3cc28f; --bad: #ff6b5e; --warn: #f0a640; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button {
  font: inherit; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); padding: 10px 16px;
}
button.ghost { background: transparent; color: var(--muted); padding: 6px 10px; }
button.ghost:hover { color: var(--text); background: var(--line); }
button:disabled { opacity: .5; cursor: default; }

/* ---- login ---- */
body.login { display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 24px; display: grid; gap: 10px;
}
.card .logo { width: 44px; height: 44px; justify-self: center; }
.card h1 { margin: 0 0 8px; text-align: center; font-size: 22px; }
.card label { font-size: 14px; color: var(--muted); }
.card input {
  font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.error { color: var(--bad); margin: 0; font-size: 14px; }

/* ---- app ---- */
body.app { display: flex; flex-direction: column; height: 100dvh; }
.bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.brand img { width: 24px; height: 24px; }
.actions { margin-left: auto; display: flex; gap: 4px; }
.actions form { margin: 0; }
.status {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted);
  padding: 3px 10px; border-radius: 999px; background: var(--bg);
}
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="idle"] i { background: var(--ok); }
.status[data-state="listening"] i { background: var(--accent); animation: pulse 1.2s infinite; }
.status[data-state="thinking"] i { background: var(--warn); animation: pulse 1.2s infinite; }
.status[data-state="speaking"] i { background: var(--accent); }
.status[data-state="offline"] i { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }

#log {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
  max-width: 860px; width: 100%; margin: 0 auto;
}
#log > * { flex-shrink: 0; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 3px; }
.msg .bubble {
  padding: 9px 13px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg .meta { font-size: 11.5px; color: var(--muted); padding: 0 6px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 5px; }
.msg.user.voice .bubble { background: var(--voice); color: var(--text); }
.msg.jarvis { align-self: flex-start; }
.msg.jarvis .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.progress { align-self: flex-start; font-size: 14px; color: var(--muted); font-style: italic; padding: 0 6px; }
.notice { align-self: center; font-size: 13px; color: var(--muted); text-align: center; }
.notice.error { color: var(--bad); }

.screen {
  align-self: stretch; background: var(--screen); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 12px; padding: 4px 16px; overflow-x: auto;
}
.screen .label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-top: 8px; }
.screen table { border-collapse: collapse; margin: 8px 0; }
.screen th, .screen td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.screen pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; }
.screen code { font-size: 14px; }
.screen img { max-width: 100%; border-radius: 8px; }
.screen a { color: var(--accent); }

.permission {
  align-self: flex-start; max-width: 82%; background: var(--panel); border: 1px solid var(--warn);
  border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 8px;
}
.permission .q { font-weight: 600; }
.permission .buttons { display: flex; gap: 8px; }
.permission .no { background: var(--line); color: var(--text); }
.permission .result { font-size: 14px; color: var(--muted); }

.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
  max-height: 40vh;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer button { width: 44px; height: 44px; padding: 0; border-radius: 50%; display: grid; place-items: center; }
.composer svg { width: 20px; height: 20px; fill: currentColor; }

@media (max-width: 600px) {
  .bar { padding-left: 16px; padding-right: 10px; gap: 8px; }
  .brand span { display: none; }
  #reset { font-size: 0; }
  #reset::after { content: "Nouvelle"; font-size: 14px; }
  .actions button { font-size: 14px; }
  .msg, .permission { max-width: 92%; }
}
