/* ==========================================================================
   Cocoon — messagerie familiale
   Les couleurs viennent des ambiances (assets/js/appearance.js), appliquées en
   variables CSS sur <html>. Les valeurs ci-dessous sont l'ambiance par défaut,
   utilisées avant le chargement du JavaScript.
   ========================================================================== */

:root {
  --brand: #0f766e;
  --brand-strong: #115e59;
  --brand-soft: #ccfbf1;
  --on-brand: #ffffff;
  --accent: #f59e0b;
  --danger: #dc2626;

  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f7f5f0;
  --border: #e4e0d6;
  --text: #1f2421;
  --text-2: #5f6661;
  --text-3: #8d938e;

  --chat-bg: #efe9dd;
  --bubble-in: #ffffff;
  --bubble-out: #d7f3ec;
  --bubble-text: #1f2421;
  --tick-read: #0e7490;
  --mention: #b45309;

  --topbar-bg: #0f766e;
  --topbar-fg: #ffffff;
  --tab-fg: rgba(255, 255, 255, .75);
  --tab-active: #ffffff;

  --chat-pattern: none;
  --chat-pattern-size: auto;
  --chat-pattern-repeat: repeat;

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-body);

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, .18);

  --font-scale: 1;
  --fs: calc(16px * var(--font-scale));
  --tap: 44px;
  --header-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Avant le JavaScript seulement : sombre si le téléphone est en mode sombre */
@media (prefers-color-scheme: dark) {
  :root:not([data-ambiance]) {
    --brand: #2dd4bf; --brand-strong: #5eead4; --brand-soft: #134e4a; --on-brand: #0b2e2a;
    --bg: #0f1413; --surface: #161c1b; --surface-2: #1c2322; --border: #2a3331;
    --text: #e8ecea; --text-2: #a5afab; --text-3: #75807c;
    --chat-bg: #0c1110; --bubble-in: #1c2423; --bubble-out: #14433d; --bubble-text: #e8ecea;
    --tick-read: #5eead4; --mention: #fbbf24;
    --topbar-bg: #161c1b; --topbar-fg: #e8ecea; --tab-fg: #a5afab; --tab-active: #2dd4bf;
  }
}

/* ---- Mode senior : tout plus grand, plus contrasté, plus espacé ---- */
body.senior {
  --fs: calc(20px * var(--font-scale));
  --tap: 58px;
  --header-h: 68px;
  --text-2: color-mix(in srgb, var(--text) 85%, var(--surface));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  font-size: var(--fs);
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
img { max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

#app { height: 100%; display: flex; flex-direction: column; max-width: 900px; margin: 0 auto; background: var(--surface); position: relative; }
@media (min-width: 900px) { #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); } }

/* ---------------------------------------------------------------- En-têtes */
.topbar {
  flex: none;
  min-height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 6px 0;
  display: flex; align-items: center; gap: 4px;
  background: var(--topbar-bg); color: var(--topbar-fg);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-family: var(--font-display); font-size: 1.15em; margin: 0; font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 8px; }
.topbar .title-block { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; border: 0; text-align: left; padding: 4px; color: inherit; }
.topbar .title-block .t { font-family: var(--font-display); font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title-block .s { font-size: .78em; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex: none; width: var(--tap); height: var(--tap);
  display: inline-grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: inherit;
}
.icon-btn:hover { background: rgba(127, 127, 127, .15); }
.icon-btn svg { width: 24px; height: 24px; }
body.senior .icon-btn svg { width: 30px; height: 30px; }

.tabs { display: flex; background: var(--topbar-bg); color: var(--tab-fg); flex: none; }
.tabs button { flex: 1; background: none; border: 0; padding: 12px 4px; font-weight: 600; border-bottom: 3px solid transparent; color: inherit; font-size: .92em; }
.tabs button[aria-selected="true"] { color: var(--tab-active); border-bottom-color: var(--tab-active); }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page-pad { padding: 16px; }

/* ---------------------------------------------------------------- Avatars */
.avatar {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; color: #fff;
  font-size: 1.05em; letter-spacing: .02em; user-select: none;
}
.avatar.sm { width: 36px; height: 36px; font-size: .85em; }
.avatar.lg { width: 88px; height: 88px; font-size: 2em; }
body.senior .avatar { width: 60px; height: 60px; }
body.senior .avatar.sm { width: 44px; height: 44px; }

/* ---------------------------------------------------------------- Listes */
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; min-height: 72px;
  border: 0; background: none; width: 100%; text-align: left;
  border-bottom: 1px solid var(--border);
}
.row:hover, .row:focus-visible { background: var(--surface-2); }
body.senior .row { min-height: 88px; padding: 14px 16px; }
.row .main { flex: 1; min-width: 0; }
.row .line1, .row .line2 { display: flex; align-items: center; gap: 8px; }
.row .name { font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: .76em; color: var(--text-3); flex: none; }
.row .time.unread { color: var(--brand); font-weight: 700; }
.row .preview { flex: 1; min-width: 0; color: var(--text-2); font-size: .9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .icons { display: flex; gap: 4px; align-items: center; color: var(--text-3); flex: none; }
.row .icons svg { width: 16px; height: 16px; }
.badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--brand); color: var(--on-brand); font-size: .75em; font-weight: 700;
  display: inline-grid; place-items: center; flex: none;
}
.badge.mention { background: var(--accent); }
body.senior .badge { min-width: 30px; height: 30px; border-radius: 15px; font-size: .85em; }

.section-title { font-size: .8em; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); font-weight: 700; padding: 18px 16px 6px; margin: 0; }
.empty { text-align: center; color: var(--text-2); padding: 48px 24px; }
.empty .big { font-size: 3em; }

/* ---------------------------------------------------------------- Boutons & champs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border-radius: 999px; border: 0;
  background: var(--brand); color: var(--on-brand); font-weight: 650;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn.ghost { background: none; color: var(--brand); }
.fab {
  position: absolute; right: 18px; bottom: calc(18px + var(--safe-bottom));
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-lg);
  display: grid; place-items: center; z-index: 4;
}
body.senior .fab { width: 72px; height: 72px; border-radius: 22px; }
.fab svg { width: 28px; height: 28px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: .85em; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
}
.input:focus { border-color: var(--brand); }
textarea.input { resize: vertical; min-height: 90px; }
.hint { font-size: .82em; color: var(--text-2); margin: 6px 0 0; }
.error-text { color: var(--danger); font-size: .88em; margin: 6px 0 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); min-height: 64px; }
.switch-row .lbl { flex: 1; }
.switch-row .lbl small { display: block; color: var(--text-2); font-size: .82em; }
.switch { appearance: none; width: 52px; height: 30px; border-radius: 15px; background: var(--border); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); transition: transform .2s; }
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(22px); }

/* ---------------------------------------------------------------- Connexion */
.auth { flex: 1; overflow-y: auto; display: flex; flex-direction: column; justify-content: center; padding: 32px 22px calc(32px + var(--safe-bottom)); background: var(--bg); }
.auth .logo { width: 84px; height: 84px; margin: 0 auto 12px; display: block; border-radius: 22px; }
.auth h1 { font-family: var(--font-display); text-align: center; margin: 0 0 4px; font-size: 1.7em; }
.auth .tagline { text-align: center; color: var(--text-2); margin: 0 0 28px; }
.auth .card { background: var(--surface); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); max-width: 440px; width: 100%; margin: 0 auto; }
.segmented { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; margin-bottom: 20px; }
.segmented button { flex: 1; border: 0; background: none; border-radius: 999px; padding: 10px; font-weight: 600; color: var(--text-2); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------------------------------------------------------------- Conversation */
.chat {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  background-color: var(--chat-bg);
  background-image: var(--chat-pattern);
  background-size: var(--chat-pattern-size);
  background-repeat: var(--chat-pattern-repeat);
  background-position: center;
}
.messages { flex: 1; overflow-y: auto; padding: 10px 10px 6px; display: flex; flex-direction: column; gap: 2px; }
.load-more { align-self: center; margin: 6px 0 10px; }
.day-sep { align-self: center; background: var(--surface); color: var(--text-2); font-size: .76em; font-weight: 600; padding: 5px 12px; border-radius: 8px; margin: 12px 0 8px; box-shadow: var(--shadow); }
.unread-sep { align-self: stretch; text-align: center; background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); font-size: .8em; font-weight: 700; padding: 6px; margin: 8px -10px; }
.system { align-self: center; max-width: 85%; text-align: center; background: var(--surface); color: var(--text-2); font-size: .82em; padding: 6px 12px; border-radius: 8px; margin: 6px 0; box-shadow: var(--shadow); }

.msg { display: flex; flex-direction: column; max-width: min(78%, 520px); margin-top: 2px; position: relative; }
.msg.first { margin-top: 8px; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in { align-self: flex-start; align-items: flex-start; }
body.senior .msg { max-width: 88%; }
.bubble {
  position: relative; background: var(--bubble-in); color: var(--bubble-text);
  border-radius: var(--radius); padding: 6px 10px 6px; box-shadow: var(--shadow);
  word-wrap: break-word; overflow-wrap: anywhere; min-width: 60px;
}
.msg.out .bubble { background: var(--bubble-out); }
.msg.in.first .bubble { border-top-left-radius: 4px; }
.msg.out.first .bubble { border-top-right-radius: 4px; }
.msg.highlight .bubble { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--shadow); } }
.bubble .sender { font-size: .8em; font-weight: 700; margin-bottom: 2px; }
.bubble .text { white-space: pre-wrap; }
.bubble .text .mention { color: var(--mention); font-weight: 650; }
.bubble .meta { float: right; margin: 6px 0 -4px 10px; font-size: .7em; color: var(--text-3); display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.bubble .meta svg { width: 16px; height: 16px; }
.bubble .meta .read { color: var(--tick-read); }
.bubble.deleted .text { font-style: italic; color: var(--text-3); }
.bubble .edited { font-style: italic; }
.bubble .pin-flag { color: var(--text-3); }
.quote {
  border-left: 4px solid var(--brand); background: rgba(127, 127, 127, .1);
  border-radius: 6px; padding: 4px 8px; margin: 2px 0 6px; font-size: .86em; cursor: pointer;
}
.quote .who { font-weight: 700; color: var(--brand); font-size: .92em; }
.quote .what { color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-chip { display: block; margin-top: 4px; font-size: .8em; color: var(--text-2); }

.reactions { display: flex; gap: 4px; margin: -6px 8px 2px; z-index: 1; flex-wrap: wrap; }
.reactions button { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; font-size: .82em; box-shadow: var(--shadow); }
.reactions button.mine { border-color: var(--brand); }

.media-img { display: block; border-radius: 10px; margin: -2px -6px 4px; max-height: 360px; width: calc(100% + 12px); max-width: 320px; object-fit: cover; background: var(--surface-2); cursor: zoom-in; }
body.senior .media-img { max-width: 100%; }
.file-card { display: flex; align-items: center; gap: 10px; padding: 8px; background: rgba(127, 127, 127, .1); border-radius: 10px; text-decoration: none; color: inherit; margin-bottom: 4px; }
.file-card svg { width: 32px; height: 32px; flex: none; color: var(--brand); }
.file-card .n { font-weight: 600; font-size: .9em; word-break: break-all; }
.file-card .z { font-size: .75em; color: var(--text-2); }
video.media-video { max-width: 320px; width: 100%; border-radius: 10px; }

.voice { display: flex; align-items: center; gap: 8px; min-width: 220px; padding: 2px 0; }
.voice .play { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; flex: none; }
body.senior .voice .play { width: 54px; height: 54px; }
.voice .play svg { width: 20px; height: 20px; }
.voice .bar { flex: 1; height: 4px; background: var(--border); border-radius: 2px; position: relative; cursor: pointer; }
.voice .bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--brand); border-radius: 2px; }
.voice .dur { font-size: .75em; color: var(--text-2); min-width: 34px; }

.tts-btn { border: 0; background: none; color: var(--brand); font-size: .8em; font-weight: 700; padding: 6px 0 0; display: inline-flex; align-items: center; gap: 4px; }
.tts-btn svg { width: 18px; height: 18px; }

/* Cartes : sondage, liste, événement */
.card { min-width: 240px; }
.card .card-title { font-weight: 700; margin: 2px 0 8px; display: flex; gap: 6px; align-items: flex-start; }
.card .card-sub { font-size: .78em; color: var(--text-2); margin: -4px 0 8px; }
.poll-opt { display: block; width: 100%; text-align: left; border: 1.5px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; position: relative; overflow: hidden; }
.poll-opt .fill { position: absolute; inset: 0 auto 0 0; background: var(--brand-soft); z-index: 0; transition: width .3s; }
.poll-opt .lbl, .poll-opt .cnt { position: relative; z-index: 1; }
.poll-opt .cnt { float: right; font-weight: 700; font-size: .85em; color: var(--text-2); }
.poll-opt.mine { border-color: var(--brand); }
.poll-opt:disabled { cursor: default; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.list-item input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
body.senior .list-item input[type=checkbox] { width: 30px; height: 30px; }
.list-item.done .l { text-decoration: line-through; color: var(--text-3); }
.list-item .by { font-size: .7em; color: var(--text-3); }
.list-add { display: flex; gap: 6px; margin-top: 8px; }
.list-add button { flex: none; white-space: nowrap; }
.list-add input { flex: 1; min-height: 36px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.event-when { font-weight: 650; }
.rsvp { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.rsvp button { flex: 1; border: 1.5px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 8px; font-size: .85em; font-weight: 600; min-width: 70px; }
.rsvp button.on { border-color: var(--brand); background: var(--brand-soft); }
.rsvp-sum { font-size: .78em; color: var(--text-2); margin-top: 6px; }

/* Barre de saisie */
.typing { font-size: .8em; color: var(--brand); padding: 0 16px 4px; font-style: italic; min-height: 1.2em; }
.composer { flex: none; display: flex; align-items: flex-end; gap: 6px; padding: 6px 8px calc(8px + var(--safe-bottom)); background: var(--chat-bg); }
.composer .box { flex: 1; display: flex; align-items: flex-end; background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); min-height: 48px; padding: 0 4px; }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; background: none; padding: 12px 6px; max-height: 140px; line-height: 1.35; }
.composer .send { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; flex: none; }
body.senior .composer .send { width: 62px; height: 62px; }
body.senior .composer .box { min-height: 62px; }
.composer .send svg { width: 24px; height: 24px; }
.reply-bar { display: flex; align-items: center; gap: 8px; margin: 0 8px; padding: 8px 10px; background: var(--surface); border-radius: 12px 12px 0 0; border-left: 4px solid var(--brand); }
.reply-bar .quote { flex: 1; margin: 0; background: none; border: 0; padding: 0; }
.recording { flex: 1; display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 24px; min-height: 48px; padding: 0 12px; box-shadow: var(--shadow); }
.recording .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.recording .t { flex: 1; font-variant-numeric: tabular-nums; }

.mention-pop { position: absolute; left: 8px; right: 8px; bottom: 100%; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 220px; overflow-y: auto; }
.mention-pop button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 8px 12px; text-align: left; }
.mention-pop button:hover { background: var(--surface-2); }

.jump-down { position: absolute; right: 14px; bottom: 90px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface); color: var(--text-2); box-shadow: var(--shadow-lg); display: grid; place-items: center; z-index: 3; }
.jump-down .badge { position: absolute; top: -6px; right: -4px; }

/* ---------------------------------------------------------------- Feuilles (bottom sheets) & dialogues */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; border-radius: 20px 20px 0 0; overflow-y: auto; padding: 8px 0 calc(12px + var(--safe-bottom)); animation: up .2s ease; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }
.sheet .grab { width: 40px; height: 5px; background: var(--border); border-radius: 3px; margin: 4px auto 8px; }
.sheet h2 { font-size: 1.1em; margin: 4px 20px 12px; }
.sheet .body { padding: 0 20px; }
.sheet .actions { display: flex; gap: 10px; padding: 12px 20px 0; }
.sheet .actions .btn { flex: 1; }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: calc(var(--tap) + 8px); padding: 8px 20px; border: 0; background: none; text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.menu-item svg { width: 24px; height: 24px; color: var(--text-2); flex: none; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger svg { color: var(--danger); }
.emoji-bar { display: flex; justify-content: space-around; padding: 4px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.emoji-bar button { font-size: 1.7em; border: 0; background: none; width: 52px; height: 52px; border-radius: 50%; }
.emoji-bar button:hover, .emoji-bar button.on { background: var(--surface-2); }
.attach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 8px 20px 12px; }
.attach-grid button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .82em; color: var(--text-2); }
.attach-grid .ic { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.attach-grid .ic svg { width: 26px; height: 26px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 100; max-width: 90%; box-shadow: var(--shadow-lg); animation: fade .2s; font-size: .92em; }
.banner { display: flex; align-items: center; gap: 12px; margin: 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--brand-soft); color: var(--text); border: 0; width: calc(100% - 20px); text-align: left; }
.banner .ico { font-size: 1.5em; }
.banner .t { flex: 1; }
.banner .t b { display: block; }
.banner .t small { color: var(--text-2); }
.offline-bar { background: #92400e; color: #fff; text-align: center; font-size: .8em; padding: 4px; flex: none; }

/* ---------------------------------------------------------------- Galerie & visionneuse */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 3px; padding: 3px; }
.grid button { border: 0; padding: 0; background: var(--surface-2); aspect-ratio: 1; overflow: hidden; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 12px; }
.album { border: 0; background: none; text-align: left; padding: 0; }
.album .cover { aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; font-size: 2em; }
.album .cover img { width: 100%; height: 100%; object-fit: cover; }
.album .t { font-weight: 650; margin-top: 6px; font-size: .92em; }
.album .c { font-size: .78em; color: var(--text-2); }
.viewer { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; flex-direction: column; }
.viewer .vbar { display: flex; align-items: center; color: #fff; padding: var(--safe-top) 6px 0; min-height: 56px; }
.viewer .vbar .t { flex: 1; font-size: .9em; }
.viewer .stage { flex: 1; display: grid; place-items: center; overflow: hidden; touch-action: pan-y; }
.viewer .stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .caption { color: #fff; text-align: center; padding: 10px 16px calc(14px + var(--safe-bottom)); }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; background: rgba(0, 0, 0, .35); }
.viewer .nav.prev { left: 6px; } .viewer .nav.next { right: 6px; }

/* ---------------------------------------------------------------- Pendant ton absence */
.digest-card { margin: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.digest-card header { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.digest-card header .n { flex: 1; font-weight: 700; }
.digest-card .stats { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px 0; font-size: .85em; color: var(--text-2); }
.digest-card .stats span { background: var(--surface-2); border-radius: 999px; padding: 3px 10px; }
.digest-card .item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 14px; border-top: 1px dashed var(--border); }
.digest-card .item .k { font-size: .75em; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
.digest-card .item .v { color: var(--text); }
.digest-card footer { padding: 10px 14px 14px; }

/* ---------------------------------------------------------------- Recherche */
.search-bar { display: flex; gap: 8px; padding: 10px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.search-bar .input { flex: 1 1 200px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 10px 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
.chips button, .chips select { flex: none; border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: .85em; }
.chips button[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.result { display: block; width: 100%; text-align: left; border: 0; background: none; border-bottom: 1px solid var(--border); padding: 12px 16px; }
.result .h { display: flex; justify-content: space-between; font-size: .8em; color: var(--text-2); margin-bottom: 4px; }
.result mark { background: #fde68a; color: inherit; border-radius: 3px; }

/* ---------------------------------------------------------------- Agenda */
.agenda-day { padding: 12px 16px 4px; font-weight: 700; color: var(--brand); font-size: .9em; text-transform: capitalize; }
.agenda-item { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border: 0; background: none; width: 100%; text-align: left; border-bottom: 1px solid var(--border); }
.agenda-item .when { width: 64px; flex: none; font-weight: 700; color: var(--text-2); font-size: .9em; }
.agenda-item .what { flex: 1; }
.agenda-item .what small { display: block; color: var(--text-2); }

/* ---------------------------------------------------------------- Divers */
.profile-head { text-align: center; padding: 24px 16px 12px; }
.profile-head .avatar { margin: 0 auto 10px; }
.profile-head h2 { margin: 0; }
.profile-head p { margin: 4px 0 0; color: var(--text-2); }
.code-box { font-family: ui-monospace, monospace; font-size: 1.3em; letter-spacing: .15em; background: var(--surface-2); padding: 12px; border-radius: 10px; text-align: center; user-select: all; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.pending-dot { width: 14px; height: 14px; }
.upload-progress { height: 3px; background: var(--border); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.upload-progress i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }
.retry { color: var(--danger); font-size: .78em; font-weight: 700; border: 0; background: none; padding: 2px 0; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ================================================================ Écran d'accueil */
#splash {
  position: fixed; inset: 0; z-index: 200; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(28px + env(safe-area-inset-bottom));
  color: #fff; text-align: center; cursor: pointer; user-select: none; -webkit-user-select: none;
  background:
    radial-gradient(120% 80% at 50% 38%, rgba(94, 234, 212, .35) 0%, transparent 60%),
    radial-gradient(90% 60% at 80% 100%, rgba(245, 158, 11, .22) 0%, transparent 65%),
    linear-gradient(165deg, #115e59 0%, #0f766e 45%, #0b3f3b 100%);
  transition: opacity .55s ease, transform .55s ease, visibility 0s linear .55s;
  animation: splash-failsafe .5s ease 9s forwards; /* au cas où le JS ne se chargerait pas */
}
#splash.hide { opacity: 0; transform: scale(1.06); visibility: hidden; pointer-events: none; }
.splash-halo {
  position: absolute; left: 50%; top: 40%; width: min(150vw, 150vh, 1100px); aspect-ratio: 1;
  transform: translate(-50%, -50%); pointer-events: none;
}
.splash-halo svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.splash-m1 { animation: splash-fade 1.4s ease both, splash-spin 120s linear infinite; }
.splash-m2 { inset: 22% !important; width: 56% !important; height: 56% !important;
  animation: splash-fade 1.2s ease .2s both, splash-spin 80s linear infinite reverse; }
.splash-center { position: relative; display: flex; flex-direction: column; align-items: center; margin-top: -6vh; }
.splash-logo {
  width: 112px; height: 112px; border-radius: 28px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35), 0 0 0 6px rgba(255, 255, 255, .12);
  animation: splash-pop .9s cubic-bezier(.2, 1.4, .4, 1) .15s both, splash-breathe 4s ease-in-out 1.2s infinite;
}
.splash-title {
  margin: 22px 0 4px; font-size: 44px; font-weight: 700; letter-spacing: .02em;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .25);
  animation: splash-up .8s ease .45s both;
}
.splash-tagline { margin: 0; font-size: 16px; opacity: .88; animation: splash-up .8s ease .6s both; }
.splash-promises {
  position: relative; list-style: none; margin: 9vh 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 10px; align-items: stretch; width: min(340px, 100%);
}
.splash-promises li {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 999px;
  font-size: 14.5px; text-align: left;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: splash-up .7s ease both;
}
.splash-promises li:nth-child(1) { animation-delay: .9s; }
.splash-promises li:nth-child(2) { animation-delay: 1.1s; }
.splash-promises li:nth-child(3) { animation-delay: 1.3s; }
.splash-promises .ico { width: 24px; text-align: center; font-size: 17px; }
.splash-promises .fr { display: inline-flex; width: 24px; height: 16px; border-radius: 3px; overflow: hidden; flex: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .5); }
.splash-promises .fr i, .splash-bar i { flex: 1; }
.splash-promises .fr i:nth-child(1), .splash-bar i:nth-child(1) { background: #002395; }
.splash-promises .fr i:nth-child(2), .splash-bar i:nth-child(2) { background: #ffffff; }
.splash-promises .fr i:nth-child(3), .splash-bar i:nth-child(3) { background: #ed2939; }
.splash-bar {
  position: absolute; left: 0; right: 0; bottom: 0; height: 4px; display: flex;
  transform-origin: left; animation: splash-grow 1.6s cubic-bezier(.6, 0, .2, 1) .3s both;
}
@keyframes splash-pop { from { opacity: 0; transform: scale(.4) rotate(-12deg); } to { opacity: 1; transform: none; } }
@keyframes splash-up { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes splash-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes splash-spin { to { rotate: 360deg; } }
@keyframes splash-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes splash-failsafe { to { opacity: 0; visibility: hidden; pointer-events: none; } }
@keyframes splash-breathe { 50% { transform: scale(1.04); } }
@media (max-height: 560px) { .splash-promises { margin-top: 4vh; } .splash-logo { width: 84px; height: 84px; } .splash-title { font-size: 34px; margin-top: 14px; } }
@media (prefers-reduced-motion: reduce) {
  #splash *, #splash { animation: none !important; transition: opacity .3s !important; }
}

/* ================================================================ Réglages : apparence */
.appear-preview {
  margin: 0 16px; height: 150px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.appear-preview .pv-top { background: var(--topbar-bg); color: var(--topbar-fg); padding: 10px 14px; font-weight: 600;
  font-family: var(--font-display); font-size: 15px; }
.appear-preview .pv-chat { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 10px 12px;
  background-color: var(--chat-bg); background-image: var(--chat-pattern); background-size: var(--chat-pattern-size);
  background-repeat: var(--chat-pattern-repeat); background-position: center; }
.pv-b { max-width: 70%; padding: 6px 10px; border-radius: 12px; font-size: 13.5px; color: var(--bubble-text);
  box-shadow: 0 1px 1px rgba(0, 0, 0, .08); }
.pv-b.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 4px; }
.pv-b.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 4px; }

.amb-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 4px 16px 8px; }
.amb-card {
  display: flex; flex-direction: column; padding: 0; border-radius: 14px; overflow: hidden; text-align: left;
  border: 2px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit;
  transition: transform .15s, border-color .15s;
}
.amb-card:active { transform: scale(.97); }
.amb-card[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.amb-card .mini { height: 74px; display: flex; flex-direction: column; }
.amb-card .mini-top { height: 18px; }
.amb-card .mini-chat { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 5px; padding: 6px 8px; }
.amb-card .mini-chat i { display: block; height: 11px; border-radius: 6px; box-shadow: 0 1px 2px rgba(0, 0, 0, .15); }
.amb-card .mini-chat i:nth-child(1) { width: 60%; }
.amb-card .mini-chat i:nth-child(2) { width: 50%; align-self: flex-end; }
.amb-card .meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.amb-card .meta b { font-size: 14.5px; }
.amb-card .meta small { font-size: 12px; color: var(--text-3); line-height: 1.3; }

.segmented { display: flex; margin: 4px 16px 10px; padding: 3px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--text-2);
  font: inherit; font-size: 14px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.pattern-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; padding: 4px 16px 10px; }
.pattern-card { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 0; border: 0; background: none;
  color: var(--text-2); font: inherit; font-size: 12.5px; cursor: pointer; }
.pattern-card .sw { width: 100%; aspect-ratio: 1; border-radius: 12px; border: 2px solid var(--border);
  background-color: var(--chat-bg); background-size: 100% 100%; background-position: center; background-repeat: no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--text-3); }
.pattern-card[aria-pressed="true"] { color: var(--text); font-weight: 600; }
.pattern-card[aria-pressed="true"] .sw { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* ================================================================ Bienvenue */
.welcome { padding: 4px 18px 18px; }
.wl-title { margin: 4px 0 6px; font-family: var(--font-display); font-size: 1.35em; }
.wl-text { margin: 0 0 14px; color: var(--text-2); line-height: 1.45; }
.wl-sub { margin: 14px 0 6px; font-size: .9em; color: var(--text-2); }
.wl-swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wl-swatch { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.wl-swatch .dot { width: 38px; height: 38px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.wl-swatch[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); font-weight: 600; }
.wl-patterns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.wl-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.wl-option { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 110px;
  border-radius: 14px; border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.wl-option .big { font-weight: 700; font-family: var(--font-display); }
.wl-option[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.wl-nav { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.wl-dots { display: flex; gap: 6px; flex: 1; }
.wl-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border); transition: width .2s; }
.wl-dots i.on { width: 20px; border-radius: 4px; background: var(--brand); }
.notif-banner { position: relative; padding-right: 8px; }
.notif-banner .t { background: none; border: 0; padding: 0; text-align: left; color: inherit; font: inherit; cursor: pointer; }
.notif-banner .close { border: 0; background: none; color: var(--text-2); font-size: 22px; line-height: 1; width: 36px; height: 36px; cursor: pointer; border-radius: 50%; }
