/* ============================================================
   Carnet d'épisodes — feuille de style
   Palette pensée pour un usage nocturne, écran à bout de bras,
   la couleur vive réservée exclusivement à la sévérité.
   ============================================================ */

:root {
  --bg: #10151c;
  --surface: #182029;
  --surface-2: #212c37;
  --line: #2e3b49;
  --line-soft: #232f3b;
  --text: #e7edf3;
  --muted: #8ea0b1;
  --accent: #3fa898;
  --accent-soft: rgba(63, 168, 152, .16);
  --skin: #26333f;
  --skin-line: #3b4c5c;

  --i1: #4fb3a0;
  --i2: #7fbf7a;
  --i3: #e8b33c;
  --i4: #e07b3c;
  --i5: #d9455f;

  --radius: 14px;
  --radius-s: 9px;
  --gap: 14px;

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  --display: "Bricolage Grotesque", var(--sans);
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

[data-theme="jour"] {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --line: #d3dee5;
  --line-soft: #e3ebf0;
  --text: #131c24;
  --muted: #5d707f;
  --accent: #16786a;
  --accent-soft: rgba(22, 120, 106, .12);
  --skin: #f2e2d7;
  --skin-line: #c9a894;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -.015em; margin: 0; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1rem; letter-spacing: 0; }

button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ── Barre haute ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20; position: relative;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-main {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
}
.retour[hidden] ~ .topbar-main { padding-top: calc(10px + env(safe-area-inset-top)); }
.wordmark { font-size: 1.05rem; letter-spacing: .02em; }
.today { margin: 0; font-size: .78rem; color: var(--muted); font-family: var(--mono); }
.topbar-right { display: flex; gap: 6px; align-items: center; }
/* Barre de retour vers Quotizi : affichée seulement quand c'est pertinent (venue du site, ?de=quotizi, ou appli installée sans historique). Masquable d'un toucher, pour la session. */
.retour {
  box-sizing: content-box; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; height: 28px; padding: 0 16px; padding-top: env(safe-area-inset-top);
  background: var(--surface-2); border-bottom: 1px solid var(--line-soft); font-size: .85rem;
}
.retour a { color: var(--accent); text-decoration: none; font-weight: 700; }
.retour-x { border: 0; background: transparent; color: var(--muted); opacity: .85; cursor: pointer; font-size: 1rem; line-height: 1; padding: 2px 6px; border-radius: 8px; }
.retour-x:active { opacity: 1; }
.ghost-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; cursor: pointer;
}
.sync-pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding: 0 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; font-size: .76rem; font-family: var(--mono);
  color: var(--muted); white-space: nowrap; max-width: 46vw; overflow: hidden;
}
.sync-pill.on { border-color: color-mix(in srgb, var(--i1) 45%, var(--line)); color: var(--text); }
.sync-pill.busy { border-color: color-mix(in srgb, var(--i3) 55%, var(--line)); color: var(--text); }
.sync-pill.err { border-color: color-mix(in srgb, var(--i5) 55%, var(--line)); color: var(--i5); }

.sync-bar {
  position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: color-mix(in srgb, var(--accent) 22%, transparent); overflow: hidden;
}
.sync-bar::after {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 38%;
  background: var(--accent); animation: glisse 1.1s ease-in-out infinite;
}
@keyframes glisse { 0% { left: -38%; } 100% { left: 100%; } }

.dot { width: 9px; height: 9px; border-radius: 50%; display: block; flex: none; }
.dot-off { background: var(--muted); }
.dot-on { background: var(--i1); }
.dot-busy { background: var(--i3); animation: pulse 1s infinite; }
.dot-err { background: var(--i5); }
@keyframes pulse { 50% { opacity: .25; } }

/* ── Écrans ──────────────────────────────────────────────── */
main { padding: 16px 14px 8px; max-width: 640px; margin: 0 auto; }
.screen { display: flex; flex-direction: column; gap: var(--gap); }
.screen[hidden] { display: none; }
.screen-head { display: flex; align-items: baseline; justify-content: space-between; }

/* ── Cartes ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head + .card-head { margin-top: 16px; }
.card-note { font-size: .75rem; color: var(--muted); font-family: var(--mono); text-align: right; }
.card-text { margin: 0 0 12px; font-size: .87rem; color: var(--muted); max-width: 62ch; }
.sub-label { font-size: .8rem; color: var(--muted); margin: 12px 0 6px; }

/* ── Actions rapides ─────────────────────────────────────── */
.quick { display: flex; flex-direction: column; gap: 10px; }
.big-action {
  width: 100%; text-align: left; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 18px;
  display: flex; flex-direction: column; gap: 2px;
}
.big-action.urgent { border-color: color-mix(in srgb, var(--i5) 55%, var(--line)); background: linear-gradient(180deg, color-mix(in srgb, var(--i5) 9%, var(--surface)), var(--surface)); }
.big-action-title { font-family: var(--display); font-size: 1.2rem; font-weight: 700; }
.big-action-sub { font-size: .78rem; color: var(--muted); font-family: var(--mono); }
.quick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mid-action {
  cursor: pointer; padding: 14px; border-radius: var(--radius);
  border: 1px solid var(--line-soft); background: var(--surface);
  font-family: var(--display); font-weight: 500; font-size: 1rem;
}

/* ── Champs ──────────────────────────────────────────────── */
label { font-size: .78rem; color: var(--muted); display: block; }
label.full { display: block; margin-top: 10px; }
.inline-fields { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-fields label { flex: 1 1 130px; }
.inline-fields label.grow { flex: 1 1 100%; }
input[type=text], input[type=time], input[type=date], input[type=email],
input[type=password], input[type=number], textarea, select {
  width: 100%; margin-top: 4px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 10px 11px; font-size: 1rem;
}
input[type=time], input[type=date] { font-family: var(--mono); }
textarea { resize: vertical; line-height: 1.5; }
.switch-row { display: flex; align-items: center; gap: 10px; font-size: .95rem; color: var(--text); }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); }

.dictee { position: relative; }
.dictee textarea { padding-right: 50px; }
.mic {
  position: absolute; right: 8px; top: 12px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; font-size: 1rem; line-height: 1;
}
.mic.rec { background: var(--i5); border-color: var(--i5); animation: pulse 1s infinite; }

/* ── Chips ───────────────────────────────────────────────── */
.chipset { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.chip {
  cursor: pointer; padding: 8px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: .85rem; color: var(--muted);
}
.chip.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

/* ── Segments ────────────────────────────────────────────── */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 11px; border: 1px solid var(--line-soft); }
.seg-btn { flex: 1; cursor: pointer; border: 0; background: transparent; color: var(--muted); padding: 9px 4px; border-radius: 8px; font-size: .85rem; }
.seg-btn.is-on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.25); }

/* ── Cartes anatomiques ──────────────────────────────────── */
.orient { font-size: .74rem; color: var(--muted); margin: 10px 0 0; font-family: var(--mono); }
.map-wrap { margin-top: 6px; }
.map { width: 100%; max-width: 330px; display: block; margin: 0 auto; touch-action: manipulation; }
.map .skin { fill: var(--skin); stroke: var(--skin-line); stroke-width: 1.4; }
.map .hit {
  fill: var(--skin); stroke: var(--skin-line); stroke-width: 1.1;
  cursor: pointer; transition: fill .12s ease;
}
.map .hit:hover { fill: color-mix(in srgb, var(--accent) 22%, var(--skin)); }
.map .hit.on-G, .map .hit.on-E, .map .hit.on-GE { stroke: var(--text); stroke-width: 1.7; }
.map .hit.on-G { fill: var(--i3); }
.map .hit.on-E { fill: var(--i5); }
.map .hit.on-GE { fill: url(#motifMixte); }
.defs-only { position: absolute; width: 0; height: 0; overflow: hidden; }

.cycle-legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line-soft);
  font-size: .76rem; color: var(--muted);
}
.cycle-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 13px; height: 13px; border-radius: 4px; border: 1px solid var(--line); display: inline-block; }
.sw-G { background: var(--i3); border-color: var(--i3); }
.sw-E { background: var(--i5); border-color: var(--i5); }
.sw-GE { background: linear-gradient(45deg, var(--i5) 0 50%, var(--i3) 50% 100%); border-color: transparent; }
.sw-0 { background: var(--skin); }

.cycleset { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.cchip {
  cursor: pointer; padding: 8px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: .85rem; color: var(--muted);
}
.cchip.on-G { background: var(--i3); border-color: var(--i3); color: #0f1519; }
.cchip.on-E { background: var(--i5); border-color: var(--i5); color: #fff; }
.cchip.on-GE { background: linear-gradient(45deg, var(--i5) 0 50%, var(--i3) 50% 100%); border-color: transparent; color: #fff; }
.map .feature { fill: none; stroke: var(--skin-line); stroke-width: 1.6; stroke-linecap: round; pointer-events: none; }
.map .feature ellipse { fill: var(--surface-2); }
.map .reperes text {
  font-family: var(--mono); font-size: 9px; font-weight: 600;
  fill: var(--muted); text-anchor: middle; pointer-events: none;
}
.map-legend { font-size: .72rem; color: var(--muted); text-align: center; margin: 4px 0 0; }
.hidden-zones { margin-top: 14px; border-top: 1px solid var(--line-soft); padding-top: 10px; }

.selection { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 6px 5px 8px; font-size: .8rem;
}
.tag .sw { flex: none; }
.tag code { font-family: var(--mono); font-size: .72rem; color: var(--muted); }
.tag .cyc { border: 0; background: none; cursor: pointer; color: inherit; font: inherit; padding: 0; text-align: left; }
.tag .cyc em { font-style: normal; color: var(--muted); font-size: .72rem; }
.tag button.x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1rem; line-height: 1; padding: 0 3px; }

/* ── Échelle d'intensité ─────────────────────────────────── */
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale button {
  cursor: pointer; padding: 16px 0; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface-2);
  font-family: var(--mono); font-size: 1.25rem; font-weight: 600; color: var(--muted);
}
.scale button.on { color: #0f1519; border-color: transparent; }
.scale button[data-v="1"].on { background: var(--i1); }
.scale button[data-v="2"].on { background: var(--i2); }
.scale button[data-v="3"].on { background: var(--i3); }
.scale button[data-v="4"].on { background: var(--i4); }
.scale button[data-v="5"].on { background: var(--i5); color: #fff; }
.scale-help { font-size: .8rem; color: var(--muted); margin: 10px 0 0; min-height: 1.2em; }

/* ── Traitements ─────────────────────────────────────────── */
.med-list { display: flex; flex-direction: column; gap: 8px; }
.med-row { display: grid; grid-template-columns: 1fr 62px 74px 34px; gap: 6px; align-items: end; }
.med-row .rm { border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-s); height: 42px; cursor: pointer; color: var(--muted); }
.med-empty { font-size: .84rem; color: var(--muted); }

/* ── Boutons ─────────────────────────────────────────────── */
.form-actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.primary, .secondary, .danger-ghost {
  cursor: pointer; padding: 14px 18px; border-radius: var(--radius-s); font-size: .95rem;
  text-decoration: none; display: inline-block;
}
.primary { background: var(--accent); border: 1px solid var(--accent); color: #06110f; font-weight: 600; }
[data-theme="jour"] .primary { color: #fff; }
.secondary { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.danger-ghost { background: transparent; border: 1px solid color-mix(in srgb, var(--i5) 50%, var(--line)); color: var(--i5); }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: .85rem; padding: 0; }
.file-btn { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 14px 18px; cursor: pointer; font-size: .95rem; color: var(--text); display: inline-block; }

.photo-row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.photo-preview img { height: 84px; border-radius: var(--radius-s); border: 1px solid var(--line); display: block; }

/* ── Listes / journal ────────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.entry {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 11px; align-items: start;
  padding: 11px 0; border-top: 1px solid var(--line-soft); cursor: pointer;
}
.entry:first-child { border-top: 0; }
.entry-time { font-family: var(--mono); font-size: .72rem; color: var(--muted); line-height: 1.3; padding-top: 2px; }
.entry-title { font-size: .92rem; }
.entry-sub { font-size: .77rem; color: var(--muted); }
.badge {
  font-family: var(--mono); font-size: .72rem; font-weight: 600;
  border-radius: 6px; padding: 3px 7px; color: #0f1519; white-space: nowrap;
}
.badge.i1 { background: var(--i1); } .badge.i2 { background: var(--i2); }
.badge.i3 { background: var(--i3); } .badge.i4 { background: var(--i4); }
.badge.i5 { background: var(--i5); color: #fff; }
.badge.neutre { background: var(--surface-2); color: var(--muted); }
.empty { color: var(--muted); font-size: .87rem; padding: 6px 0; }

.open-episode {
  border: 1px solid var(--i5); border-radius: var(--radius); padding: 13px;
  background: color-mix(in srgb, var(--i5) 10%, var(--surface));
  display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px;
}
.open-episode strong { font-family: var(--display); }
.open-episode small { display: block; color: var(--muted); font-size: .76rem; font-family: var(--mono); }

/* ── Stats ───────────────────────────────────────────────── */
.stat-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: var(--radius-s); padding: 11px; }
.stat b { display: block; font-family: var(--display); font-size: 1.5rem; line-height: 1.1; }
.stat span { font-size: .72rem; color: var(--muted); }

.bars { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.bar { display: grid; grid-template-columns: 108px 1fr 34px; gap: 8px; align-items: center; font-size: .8rem; }
.bar-label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 15px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.bar-val { font-family: var(--mono); font-size: .75rem; color: var(--muted); text-align: right; }

.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 92px; margin-top: 6px; }
.hour-col { background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; }
.hours-axis { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; font-family: var(--mono); font-size: .55rem; color: var(--muted); text-align: center; margin-top: 3px; }

.kv { list-style: none; margin: 0; padding: 0; font-size: .84rem; }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line-soft); }
.kv li:first-child { border-top: 0; }
.kv span { color: var(--muted); font-family: var(--mono); font-size: .78rem; text-align: right; }

.fold summary { cursor: pointer; font-size: .88rem; color: var(--accent); padding: 6px 0; }
.fold[open] summary { margin-bottom: 8px; }

/* ── Onglets bas ─────────────────────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line-soft);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  font-size: .66rem; padding: 9px 2px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab-i { font-size: 1.05rem; line-height: 1; }
.tab.is-on { color: var(--accent); }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px); opacity: 0; pointer-events: none;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 18px; font-size: .85rem; z-index: 50;
  max-width: 88vw; text-align: center;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Mode d'emploi d'installation ────────────────────────── */
.install-overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(5,9,13,.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.install-modal {
  background: var(--bg); width: 100%; max-width: 520px; max-height: 88vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.install-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.install-head img { border-radius: 11px; flex: none; }
.install-head h3 { margin: 0; }
.install-addr { margin: 2px 0 0; font-size: .76rem; color: var(--muted); font-family: var(--mono); word-break: break-all; }
.install-steps { margin: 14px 0 16px; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; font-size: .92rem; }
.install-modal .primary { display: block; width: 100%; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media (min-width: 700px) {
  .med-row { grid-template-columns: 1fr 90px 100px 40px; }
}

.photo-preview { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.photo-preview figure { position: relative; margin: 0; }
.photo-preview .retirer-photo {
  position: absolute; top: -7px; right: -7px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0;
}

/* Bande des quatorze derniers jours de traitement de fond */
.quinzaine { display: grid; grid-template-columns: repeat(14, 1fr); gap: 3px; margin-top: 4px; }
.quinzaine .jour {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 0 6px; border-radius: 7px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--muted); font-family: var(--mono); line-height: 1;
}
.quinzaine .jour-l { font-size: .52rem; opacity: .75; }
.quinzaine .jour-n { font-size: .66rem; }
.quinzaine .jour.pris { background: var(--accent); border-color: var(--accent); color: #06110f; }
[data-theme="jour"] .quinzaine .jour.pris { color: #fff; }
