:root {
  --primary: #3F51B5;
  --primary-dark: #303F9F;
  --background: #EEF1F7;
  --card: #FFFFFF;
  --card-pressed: #DDE3F3;
  --text: #212121;
  --text-secondary: #757575;
  --bubble-me: #D6F5C9;
  --bubble-other: #FFFFFF;
  --record: #E53935;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--background);
  color: var(--text);
  font: 18px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.view { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--primary); color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 14px calc(16px + env(safe-area-inset-left));
}
.bar h1 { margin: 0; font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-bar { padding-left: calc(4px + env(safe-area-inset-left)); }
.pad { padding: 16px calc(12px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); }
.list { flex: 1; overflow-y: auto; }
.center { text-align: center; }
.big { font-size: 20px; }
.error { color: var(--record); min-height: 1.4em; }
.offline { background: #FFF3E0; color: #E65100; text-align: center; padding: 6px; font-size: 14px; }

.hint { background: #FFF8E1; border-radius: 16px; padding: 8px 16px; margin-bottom: 16px; font-size: 16px; }
.hint ol { padding-left: 20px; }

.code {
  display: block; width: 100%; margin: 16px 0; padding: 14px; border: 0; border-radius: 16px;
  background: var(--card); text-align: center; font: bold 30px/1.2 ui-monospace, Menlo, monospace;
  text-transform: uppercase; color: var(--text);
}
.pill {
  display: block; width: 100%; height: 64px; border-radius: 32px;
  background: var(--primary); color: #fff; font-size: 24px; font-weight: bold;
}
.pill:disabled { background: var(--text-secondary); }

.tile {
  display: flex; align-items: center; gap: 16px; width: 100%; margin: 6px 0; padding: 12px;
  min-height: 76px; border-radius: 16px; background: var(--card); text-align: left;
  font-size: 24px; font-weight: bold; color: var(--text);
}
.tile:active { background: var(--card-pressed); }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 56px; height: 56px; border-radius: 50%; color: #fff; font-size: 26px; font-weight: bold;
}
.avatar.small { width: 40px; height: 40px; font-size: 20px; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; }

.icon-button { width: 52px; height: 52px; background: transparent; color: #fff; font-size: 28px; border-radius: 50%; }
.icon-button:active { background: var(--primary-dark); }
.icon-button.light { color: var(--text-secondary); font-size: 24px; }
.icon-button.light:active { background: var(--card-pressed); }

#messages { flex: 1; overflow-y: auto; padding: 4px calc(8px + env(safe-area-inset-right)) 8px calc(8px + env(safe-area-inset-left)); }
.day { display: table; margin: 10px auto 4px; padding: 3px 12px; border-radius: 10px; background: #DCE2EE; color: var(--text-secondary); font-size: 13px; }
.row { display: flex; margin: 3px 0; }
.row.mine { justify-content: flex-end; padding-left: 56px; }
.row.other { justify-content: flex-start; padding-right: 56px; }
.bubble { padding: 7px 12px 6px; border-radius: 14px; max-width: 100%; overflow-wrap: anywhere; white-space: pre-wrap; }
.mine .bubble { background: var(--bubble-me); border-bottom-right-radius: 4px; }
.other .bubble { background: var(--bubble-other); border-bottom-left-radius: 4px; }
.sender { font-size: 14px; font-weight: bold; }
.meta { text-align: right; color: var(--text-secondary); font-size: 12px; }
.voice { background: transparent; padding: 0; color: var(--text); text-align: left; }

.composer {
  display: flex; align-items: center; gap: 6px; background: var(--card);
  padding: 6px calc(6px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left));
}
#input {
  flex: 1; min-height: 48px; max-height: 120px; resize: none; border: 0; border-radius: 24px;
  padding: 12px 16px; background: var(--background); font: inherit; color: var(--text);
}
.round { flex: none; width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 26px; }
.round:active { background: var(--primary-dark); }
.round.red { background: var(--record); width: 64px; height: 64px; }
.timer { flex: 1; text-align: center; color: var(--record); font-size: 24px; font-weight: bold; }
.review-play { flex: 1; height: 48px; border-radius: 24px; background: var(--background); color: var(--text); font-size: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: 90%; padding: 12px 18px; border-radius: 20px; background: rgba(33, 33, 33, 0.9); color: #fff;
  font-size: 16px; text-align: center; z-index: 10;
}

.notif-button {
  margin: 12px calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
  padding: 14px; border-radius: 16px; background: #FFF3E0; color: #E65100; font-size: 18px; font-weight: bold;
}

/* Répondre à un message : citation dans la bulle et barre au-dessus de la saisie. */
.quote {
  border-left: 4px solid var(--primary); border-radius: 6px; background: rgba(63, 81, 181, 0.08);
  padding: 4px 8px; margin-bottom: 4px; font-size: 15px; min-width: 0;
}
.quote-name { font-weight: bold; font-size: 14px; }
.quote-text { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw; }
.reply-bar {
  display: flex; align-items: center; gap: 6px; background: var(--card); border-top: 1px solid var(--background);
  padding: 6px calc(6px + env(safe-area-inset-right)) 0 calc(10px + env(safe-area-inset-left));
}
.reply-bar .quote { flex: 1; margin: 0; }
.row { transition: transform 0.15s ease-out; touch-action: pan-y; }
.row.swiping { transition: none; }

/* Accueil façon WhatsApp : conversations commencées, la plus récente en haut. */
.chats { padding: 4px 0 calc(96px + env(safe-area-inset-bottom)); }
.chat-row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px calc(14px + env(safe-area-inset-right)) 10px calc(14px + env(safe-area-inset-left));
  background: var(--card); border-bottom: 1px solid var(--background); text-align: left; color: var(--text);
}
.chat-row:active { background: var(--card-pressed); }
.chat-main { flex: 1; min-width: 0; }
.chat-title { font-size: 20px; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview { color: var(--text-secondary); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.chat-time { color: var(--text-secondary); font-size: 13px; }
.chat-row.unread .chat-time { color: #2E7D32; font-weight: bold; }
.badge { min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: #2E7D32; color: #fff; font-size: 14px; font-weight: bold; line-height: 24px; text-align: center; }
.empty { text-align: center; color: var(--text-secondary); padding: 32px 24px; }
.fab {
  position: fixed; right: calc(20px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 20px; background: var(--primary); color: #fff; font-size: 28px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.fab:active { background: var(--primary-dark); }

.banner {
  position: fixed; left: 10px; right: 10px; top: calc(8px + env(safe-area-inset-top)); z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 16px;
  background: #fff; color: var(--text); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); text-align: left; font-size: 16px;
}
.banner .avatar { width: 40px; height: 40px; font-size: 20px; }
.banner-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Réactions */
.reactions { display: flex; justify-content: flex-end; margin-top: -6px; position: relative; z-index: 1; }
.other .reactions { justify-content: flex-start; }
.reaction-chip { background: #fff; border-radius: 12px; padding: 1px 7px; font-size: 15px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.reaction-chip.mine { background: #E8EAF6; }
.picker-overlay { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.25); display: flex; align-items: center; justify-content: center; }
.picker { background: #fff; border-radius: 24px; padding: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }
.picker-emojis { display: flex; gap: 4px; }
.picker-emojis button { width: 48px; height: 48px; border-radius: 50%; background: transparent; font-size: 28px; }
.picker-emojis button.chosen { background: #E8EAF6; }
.picker-reply { display: block; width: 100%; margin-top: 8px; padding: 10px; border-radius: 16px; background: var(--background); color: var(--text); font-size: 17px; }

.bubble-column { display: flex; flex-direction: column; max-width: 100%; }
.mine .bubble.sticker, .other .bubble.sticker { background: transparent; padding: 0 4px; }
.sticker-text { font-size: 56px; line-height: 1.15; }
.mine .bubble-column { align-items: flex-end; }
.other .bubble-column { align-items: flex-start; }

.chat-heading { min-width: 0; display: flex; flex-direction: column; }
.chat-sub { font-size: 14px; color: #E8EAF6; font-style: italic; min-height: 0; }
.chat-sub:empty { display: none; }
.avatar-zoom { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.9); display: flex; align-items: center; justify-content: center; padding: 16px; }
.avatar-zoom img { width: min(88vw, 80vh); height: auto; aspect-ratio: 1; border-radius: 50%; }
.photo { display: block; width: 240px; max-width: 100%; height: auto; border-radius: 10px; margin: 2px 0; background: #E0E0E0; cursor: pointer; object-fit: cover; }
.video { display: block; width: 240px; max-width: 100%; border-radius: 10px; margin: 2px 0; background: #000; }
.photo-loading { display: flex; align-items: center; justify-content: center; color: var(--text-secondary, #666); font-size: 14px; }
.photo-view { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; gap: 16px; }
.photo-view img { max-width: 100%; max-height: calc(100% - 80px); object-fit: contain; touch-action: none; transform-origin: center; user-select: none; -webkit-user-select: none; }
.photo-close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 1; width: 44px; height: 44px; border-radius: 22px; border: none; background: rgba(255, 255, 255, 0.2); color: #fff; font-size: 20px; }
.photo-view a { color: #fff; background: rgba(255, 255, 255, 0.15); padding: 12px 24px; border-radius: 24px; text-decoration: none; font-size: 17px; }
.read { color: #1E88E5; font-weight: bold; }
.deleted { color: var(--text-secondary); font-style: italic; }
.chat-preview.typing { color: #2E7D32; font-style: italic; }
.picker-reply.danger { color: var(--record); }

/* Appel vocal */
/* Combiné blanc dessiné (l'émoji 📞 se voyait mal sur le bleu) ; rond vert dans l'en-tête. */
.call-button { margin-left: auto; flex: none; display: flex; align-items: center; justify-content: center; }
.call-button svg { width: 40px; height: 40px; padding: 9px; border-radius: 50%; background: #43A047; fill: #fff; }
.call-button:active svg { background: #2E7D32; }
.call-round svg { width: 38px; height: 38px; fill: #fff; vertical-align: middle; }
.call-screen {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center;
  background: #1A237E; color: #fff; text-align: center;
  padding: calc(12vh + env(safe-area-inset-top)) 24px calc(40px + env(safe-area-inset-bottom));
}
.call-avatar { width: 150px; height: 150px; font-size: 68px; }
.call-screen h1 { margin: 20px 0 6px; font-size: 32px; overflow-wrap: anywhere; }
.call-status { margin: 0; min-height: 1.4em; font-size: 21px; color: #C5CAE9; }
.call-hint { margin: 18px 8px 0; padding: 10px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.12); font-size: 15px; color: #E8EAF6; }
.call-buttons { margin-top: auto; display: flex; align-items: center; justify-content: center; gap: 32px; }
.call-round { width: 78px; height: 78px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 34px; }
.call-round.on { background: #fff; }
.call-round.green { background: #2E7D32; }
.call-round.red { background: var(--record); }
.call-round.red svg { transform: rotate(135deg); }

/* Espace parents */
.home-bar h1 { flex: 1; }
.card { background: var(--card); border-radius: 16px; padding: 14px; margin: 8px 0; }
.card h2 { margin: 0 0 8px; font-size: 19px; }
.muted { color: var(--text-secondary); font-size: 15px; }
.row-line { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.row-line .grow { flex: 1; min-width: 0; }
.action { display: block; width: 100%; margin-top: 8px; padding: 12px; border-radius: 14px; background: var(--background); color: var(--text); font-size: 17px; text-align: center; }
.action.primary { background: var(--primary); color: #fff; font-weight: bold; }
.action.danger { color: var(--record); }
.small-action { padding: 6px 10px; border-radius: 10px; background: var(--background); color: var(--record); font-size: 14px; }
.field { width: 100%; padding: 12px; margin-top: 8px; border: 1px solid #DCE2EE; border-radius: 12px; font: inherit; background: #fff; color: var(--text); }
textarea.field { min-height: 90px; }
.code-box { margin-top: 10px; padding: 14px; border-radius: 14px; background: #E8F5E9; text-align: center; }
.code-box .code-value { font: bold 30px ui-monospace, Menlo, monospace; letter-spacing: 2px; user-select: all; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.colors button { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; }
.colors button.chosen { border-color: var(--text); }
