:root {
  --bg: #f7f6f3;
  --side: #f0eee9;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #8a867d;
  --line: #e6e3dc;
  --hover: #ebe9e3;
  --accent: #1f6f5c;
  --on-accent: #ffffff;
  --rec: #d63c35;
  --interim: #aaa69d;
  --toast-action: #7fd3b8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --side: #1b1b19;
    --surface: #21201e;
    --text: #ecebe7;
    --muted: #8f8b83;
    --line: #2f2e2b;
    --hover: #2a2926;
    --accent: #3f9f84;
    --on-accent: #ffffff;
    --rec: #e5534b;
    --interim: #6f6c66;
    --toast-action: #1f6f5c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Barres */
.bar { display: flex; align-items: center; gap: 2px; height: 56px; flex: none; padding: 0 8px 0 16px; border-bottom: 1px solid var(--line); }
.icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: var(--muted); }
.icon:hover { background: var(--hover); color: var(--text); }
.icon:disabled { opacity: .3; pointer-events: none; }
.icon.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon.sm svg { width: 16px; height: 16px; }
.only-mobile { display: none; }

/* Liste des fils */
#side { display: flex; flex-direction: column; min-height: 0; background: var(--side); border-right: 1px solid var(--line); }
#side h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 650; }
#list { flex: 1; overflow-y: auto; padding: 6px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 1px 8px; width: 100%; padding: 10px 12px; border-radius: 10px; text-align: left; }
.item:hover { background: var(--hover); }
.item.on { background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.item .t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 15px; font-weight: 600; }
.item .d { align-self: center; font-size: 12px; color: var(--muted); }
.item .p { grid-column: 1 / -1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; color: var(--muted); }

/* Fil */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#title { flex: 1; min-width: 0; padding: 6px 8px; margin-left: -8px; border: 0; border-radius: 8px; outline: none; background: none; color: var(--text); font: inherit; font-size: 17px; font-weight: 650; }
#title:focus { background: var(--hover); }
#title::placeholder { color: var(--text); opacity: .5; }

#notes { flex: 1; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; padding: 16px 16px 8px; }
#notes > * { width: 100%; max-width: 720px; margin: 0 auto; flex: none; }
.day { margin-top: 6px; text-align: center; font-size: 12px; color: var(--muted); }
.note { padding: 10px 14px 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.note:focus-within { border-color: var(--accent); }
.note .txt { min-height: 1.5em; outline: none; white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { display: flex; align-items: center; justify-content: flex-end; gap: 2px; min-height: 30px; font-size: 12px; color: var(--muted); }
.meta time { margin-right: auto; }
@media (hover: hover) {
  .note .meta button { opacity: 0; transition: opacity .12s; }
  .note:hover .meta button, .note:focus-within .meta button { opacity: 1; }
}
.note.draft { border: 1.5px dashed var(--accent); }
.note.draft .txt:empty::before, .interim { color: var(--interim); }
.note.draft .txt:empty::before { content: "…"; }

/* Saisie */
#composer { display: flex; align-items: flex-end; gap: 8px; width: 100%; max-width: 752px; margin: 0 auto; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
#input, #login input { flex: 1; min-height: 48px; max-height: 40vh; padding: 12px 18px; border: 1px solid var(--line); border-radius: 24px; outline: none; resize: none; background: var(--surface); color: var(--text); font: inherit; line-height: 1.4; }
#input:focus, #login input:focus { border-color: var(--accent); }
.round { display: grid; place-items: center; flex: none; width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--on-accent); }
.round svg { width: 22px; height: 22px; }
#send, #mic .i-stop { display: none; }
#composer.has-text #send { display: grid; }
#composer.has-text #mic { display: none; }
body.rec #mic { display: grid; background: var(--rec); animation: pulse 1.4s ease-out infinite; }
body.rec #send, body.rec #mic .i-mic { display: none; }
body.rec #mic .i-stop { display: block; }
body.no-sr #mic { display: none; }
body.no-sr #send { display: grid; }
@keyframes pulse {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--rec) 50%, transparent); }
  to { box-shadow: 0 0 0 14px transparent; }
}

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 10; display: flex; align-items: center; gap: 4px; padding: 8px 16px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 14px; opacity: 0; pointer-events: none; transform: translate(-50%, 10px); transition: opacity .18s, transform .18s; }
#toast { width: max-content; max-width: calc(100% - 32px); }
#toast span { overflow-wrap: anywhere; }
#toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
#toast.act { padding-right: 6px; }
#toast button { padding: 4px 10px; border-radius: 999px; color: var(--toast-action); font-weight: 650; }

/* Connexion */
#login { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--bg); }
#login[hidden] { display: none; }
#login form { display: flex; gap: 8px; width: min(340px, calc(100% - 32px)); }
#login.err form { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* Mobile : une vue à la fois */
@media (max-width: 759px) {
  body { grid-template-columns: 1fr; }
  body.v-thread #side, body.v-list #main { display: none; }
  #side { border-right: 0; background: var(--bg); }
  .only-mobile { display: grid; }
  .bar { padding-left: 4px; }
  #side .bar { padding-left: 16px; }
  .item.on { background: none; box-shadow: none; }
  #notes { padding: 12px 12px 8px; }
  #composer { padding-left: 12px; padding-right: 12px; }
}
