/* VoxIA — un carnet de bord.
 * L'interface s'efface derrière la lecture. Un seul élément marquant : le « rail »,
 * trait vertical qui respire tant que Claude travaille, puis s'éteint.
 * Réponses et questions en Source Serif 4 (accord avec les formules KaTeX) ; interface en police système.
 */

@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("/fonts/source-serif-4-latin-wght-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("/fonts/source-serif-4-latin-wght-italic.woff2") format("woff2");
}

:root {
  color-scheme: light dark;
  --paper: #f1f3f2;
  --surface: #ffffff;
  --ink: #151a1e;
  --graphite: #59636b;
  --rule: #d5dadd;
  --signal: #2446c7;      /* encre bleue : action principale et travail en cours */
  --on-signal: #ffffff;
  --alert: #b42318;
  --code-bg: #e6eae8;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --font-read: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-code: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --measure: 40rem;
  --pad-l: max(1.125rem, env(safe-area-inset-left));
  --pad-r: max(1.125rem, env(safe-area-inset-right));
  --rail: 3px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #000000;     /* noir OLED : lecture de nuit sur iPhone */
    --surface: #0c0f11;
    --ink: #e5e9ec;
    --graphite: #97a1a8;
    --rule: #252b2f;
    --signal: #93a6ff;
    --on-signal: #05070d;
    --alert: #ff8b7b;
    --code-bg: #111619;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }   /* sinon « display » des boutons l'emporte sur l'attribut hidden */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 400 0.9375rem/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 4px; }
main:focus { outline: none; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ------------------------------------------------------------------ barres */

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: calc(env(safe-area-inset-top) + 0.7rem) var(--pad-r) 0.7rem var(--pad-l);
}
.topbar-inner {
  max-width: var(--measure); margin: 0 auto;
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
}
.brand { font: 600 1.3125rem/1 var(--font-read); letter-spacing: -0.01em; text-decoration: none; }
.topbar-back {
  display: inline-flex; align-items: center;
  min-height: 44px; margin: -0.7rem 0;        /* zone tactile de 44 px sans épaissir la barre */
  color: var(--signal); font-size: 1rem; text-decoration: none;
}
.relay-state { font-size: 0.8125rem; color: var(--graphite); text-align: right; }

main {
  max-width: calc(var(--measure) + var(--pad-l) + var(--pad-r)); margin: 0 auto;
  padding: 0 var(--pad-r) calc(6.5rem + env(safe-area-inset-bottom)) var(--pad-l);
}

.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: 0.75rem var(--pad-r) calc(0.75rem + env(safe-area-inset-bottom)) var(--pad-l);
}
.bottombar[hidden] { display: none; }
.bottombar-inner { max-width: var(--measure); margin: 0 auto; }

/* ------------------------------------------------------------------ le rail */

.rail { display: block; width: var(--rail); border-radius: var(--rail); background: var(--rule); align-self: stretch; }
[data-status="queued"] .rail,
[data-status="transcribing"] .rail,
[data-status="thinking"] .rail,
[data-status="answering"] .rail { background: var(--signal); animation: breathe 1.6s ease-in-out infinite; }
[data-status="error"] .rail { background: var(--alert); }
[data-status="cancelled"] .rail { background: repeating-linear-gradient(to bottom, var(--graphite) 0 4px, transparent 4px 8px); }

@keyframes breathe { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .rail { animation: none !important; } }

/* ------------------------------------------------------------------ historique */

.day { margin-top: 1.5rem; }
.day-title { margin: 0 0 0.25rem; font: 600 0.8125rem/1.3 var(--font-ui); color: var(--graphite); }
.day-entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: var(--rail) 3rem 1fr; column-gap: 0.75rem;
  min-height: 44px; padding: 0.8rem 0;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
}
.day-entries li:last-child .entry { border-bottom: 0; }
.entry-time { padding-top: 0.2rem; font-size: 0.8125rem; color: var(--graphite); font-variant-numeric: tabular-nums; }
.entry-body { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.entry-question {
  font: 400 1.0625rem/1.38 var(--font-read);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.entry-meta { font-size: 0.8125rem; color: var(--graphite); }
[data-status="error"] .entry-meta { color: var(--alert); }
.entry:hover .entry-question { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

.search-row { margin-top: 1rem; }
.search {
  width: 100%; min-height: 44px; padding: 0.6rem 0.875rem;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: 400 1rem/1.3 var(--font-ui);      /* 16 px : pas de zoom automatique sur iPhone */
}
.search:focus { outline: 2px solid var(--signal); outline-offset: 1px; }
.search::placeholder { color: var(--graphite); }
.result-count { margin: 1rem 0 0; font-size: 0.8125rem; color: var(--graphite); }
.entry-snippet {
  font-size: 0.875rem; line-height: 1.4; color: var(--graphite); overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
mark { background: color-mix(in srgb, var(--signal) 22%, transparent); color: var(--ink); border-radius: 2px; padding: 0 0.08em; }

.empty { padding: 3rem 0 1rem; }
.empty-title { margin: 0 0 0.5rem; font: 600 1.25rem/1.3 var(--font-read); }
.empty p { margin: 0; max-width: 32rem; color: var(--graphite); }
.loading { padding: 2rem 0; color: var(--graphite); }
.notice { margin-top: 2rem; padding: 1rem; border: 1px solid var(--alert); border-radius: 8px; }
.notice-title { margin: 0 0 0.35rem; font-weight: 600; color: var(--alert); }
.notice p { margin: 0; }
.more { margin-top: 1rem; }

/* ------------------------------------------------------------------ conversation */

.conversation { padding-top: 1.25rem; }
.exchange { scroll-margin-top: 5rem; }
.exchange + .exchange { margin-top: 2rem; padding-top: 1.75rem; border-top: 1px solid var(--rule); }
.label { margin: 0.75rem 0 0.3rem; font-size: 0.8125rem; color: var(--graphite); }
.question { margin: 0; font: 600 1.375rem/1.3 var(--font-read); letter-spacing: -0.005em; overflow-wrap: anywhere; }
h2.question { font-size: 1.25rem; }
.meta { margin: 0.55rem 0 0; font-size: 0.8125rem; color: var(--graphite); }
.transcript { margin-top: 0.75rem; font-size: 0.875rem; color: var(--graphite); }
.transcript summary { cursor: pointer; padding: 0.5rem 0; }
.transcript p { margin: 0.25rem 0 0; font-family: var(--font-read); font-size: 1rem; }
.answer-wrap { display: grid; grid-template-columns: var(--rail) 1fr; column-gap: 1rem; margin-top: 1.5rem; }
.status-line { min-height: 1.3em; margin: 1rem 0 0; font-size: 0.875rem; color: var(--graphite); }
[data-status="error"] .status-line { color: var(--alert); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.actions:empty { display: none; }

/* ------------------------------------------------------------------ réponse (lecture) */

.prose { min-width: 0; font: 400 1.0625rem/1.62 var(--font-read); overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre,
.prose .table-wrap, .prose .math-block { margin: 0 0 1em; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 1.6em 0 0.5em; font-family: var(--font-read); font-weight: 650; line-height: 1.3; }
.prose h1 { font-size: 1.375rem; }
.prose h2 { font-size: 1.25rem; }
.prose h3 { font-size: 1.0625rem; }
.prose h4 { font-size: 1rem; font-style: italic; font-weight: 600; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: 0.3em; }
.prose a { color: var(--signal); text-underline-offset: 2px; }
.prose blockquote { margin-left: 0; padding-left: 1em; border-left: 2px solid var(--rule); color: var(--graphite); }
.prose hr { margin: 1.5em 0; border: 0; border-top: 1px solid var(--rule); }
.prose code { font-family: var(--font-code); font-size: 0.86em; background: var(--code-bg); padding: 0.1em 0.3em; border-radius: 4px; }
.prose pre { background: var(--code-bg); padding: 0.85rem 1rem; border-radius: 6px; overflow-x: auto; font-size: 0.875rem; line-height: 1.5; }
.prose pre code { background: none; padding: 0; font-size: inherit; }
.prose pre code.hljs { background: transparent; padding: 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.prose table { min-width: 100%; border-collapse: collapse; font: 400 0.875rem/1.4 var(--font-ui); }
.prose th, .prose td { padding: 0.45rem 0.9rem 0.45rem 0; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.prose th { font-weight: 600; border-bottom-color: var(--graphite); }
.prose td { font-variant-numeric: tabular-nums; }
.prose .katex { font-size: 1.04em; }
.math-block, .math-display { display: block; overflow-x: auto; overflow-y: hidden; padding: 0.2rem 0; }
.prose .katex-display { margin: 0; }
.math-error { color: var(--alert); }

/* ------------------------------------------------------------------ nouvelle question */

.composer { display: grid; gap: 1.1rem; padding-top: 1.25rem; }
.composer-title { margin: 0; font: 600 1.375rem/1.3 var(--font-read); }
.composer-note { margin: 0; font-size: 0.875rem; color: var(--graphite); }
.composer-note:empty { display: none; }
.followup { margin-top: 2.25rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.followup .composer-title { font-size: 1.125rem; }
.conversation-end { margin-top: 1.5rem; }
.context { margin: 0; font-size: 0.875rem; color: var(--graphite); }
.context q { font-family: var(--font-read); font-size: 1rem; color: var(--ink); }
.field-label { display: block; margin-bottom: 0.4rem; font-size: 0.8125rem; color: var(--graphite); }
textarea {
  width: 100%; min-height: 9rem; resize: vertical;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: 400 1.0625rem/1.5 var(--font-read);
}
textarea:focus { outline: 2px solid var(--signal); outline-offset: 1px; }
.modes { margin: 0; padding: 0; border: 0; }
.modes legend { padding: 0; margin-bottom: 0.4rem; font-size: 0.8125rem; color: var(--graphite); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
.segmented label {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 0.5rem; text-align: center; font-size: 0.875rem; cursor: pointer;
}
.segmented label + label { border-left: 1px solid var(--rule); }
.segmented input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.segmented label:has(input:checked) { background: var(--ink); color: var(--paper); font-weight: 600; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--signal); outline-offset: -2px; }
.hint { min-height: 2.6em; margin: 0.45rem 0 0; font-size: 0.8125rem; color: var(--graphite); }
.form-error { margin: 0; color: var(--alert); font-size: 0.875rem; }
.form-error:empty { display: none; }

/* ------------------------------------------------------------------ dictée */

.recorder { display: grid; gap: 0.5rem; }
.rec-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.rec-actions .button:first-child:not([hidden]) { flex: 1 1 auto; }
.rec-status { min-height: 1.3em; margin: 0; font-size: 0.875rem; color: var(--graphite); font-variant-numeric: tabular-nums; }
.recorder[data-state="recording"] .rec-status { color: var(--ink); }
.recorder[data-state="recording"] .rec-status::before {
  content: ""; display: inline-block; width: 0.6rem; height: 0.6rem; margin-right: 0.5rem;
  border-radius: 50%; background: var(--alert); vertical-align: 0.05em;
  animation: breathe 1.2s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) { .recorder .rec-status::before { animation: none !important; } }

/* ------------------------------------------------------------------ détails techniques */

.details { margin-top: 1rem; font-size: 0.875rem; }
.details summary { padding: 0.5rem 0; color: var(--graphite); cursor: pointer; }
.details dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; margin: 0.5rem 0 0; }
.details dt { color: var(--graphite); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.audio-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.audio-row audio { max-width: 100%; height: 36px; }
@media (max-width: 30rem) {
  .details dl { grid-template-columns: 1fr; gap: 0.1rem; }
  .details dd { margin-bottom: 0.5rem; }
}

/* ------------------------------------------------------------------ connexion et appareils */

.login, .security { display: grid; gap: 1.1rem; padding-top: 1.25rem; }
.login h2, .security h2 { margin: 0 0 0.5rem; font: 600 1.0625rem/1.3 var(--font-read); }
.first-time { display: grid; gap: 0.9rem; }
.first-time-toggle summary { padding: 0.5rem 0; color: var(--graphite); cursor: pointer; }
.first-time-toggle[open] summary { margin-bottom: 0.75rem; }
.field {
  width: 100%; min-height: 44px; padding: 0.6rem 0.875rem;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: 400 1rem/1.3 var(--font-ui);           /* 16 px : pas de zoom automatique sur iPhone */
}
.field:focus { outline: 2px solid var(--signal); outline-offset: 1px; }
#setup-code { font-family: var(--font-code); letter-spacing: 0.08em; text-transform: uppercase; }
.passkeys { list-style: none; margin: 0; padding: 0; }
.passkey { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0; border-bottom: 1px solid var(--rule); }
.passkey:last-child { border-bottom: 0; }
.passkey-body { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; min-width: 0; }
.passkey-name { font-weight: 600; }
.passkey-meta { font-size: 0.8125rem; color: var(--graphite); }
.add-device { display: grid; gap: 0.75rem; }
.add-device h2 { margin: 0; }
.footer-link { margin: 2rem 0 0; font-size: 0.875rem; }
.footer-link a { color: var(--graphite); }

/* ------------------------------------------------------------------ boutons */

.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 1rem;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: 500 0.9375rem/1 var(--font-ui); text-decoration: none; cursor: pointer;
}
.button.primary { background: var(--signal); border-color: var(--signal); color: var(--on-signal); }
.button.quiet { background: transparent; border-color: transparent; color: var(--graphite); }
.button.danger { color: var(--alert); }
.button.wide { width: 100%; }
.button:disabled { opacity: 0.5; cursor: default; }

/* ------------------------------------------------------------------ message bref */

.toast {
  position: fixed; left: 50%; bottom: calc(5.75rem + env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%);
  padding: 0.6rem 1rem; border-radius: 999px;
  background: var(--ink); color: var(--paper); font-size: 0.875rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

@media (min-width: 48rem) {
  h1.question, .composer:not(.followup) .composer-title { font-size: 1.5rem; }
  h2.question { font-size: 1.3125rem; }
  .prose { font-size: 1.125rem; }
}
