* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

/* iPhone, app installée : avec la barre d'état translucide, iOS raccourcit la page de la hauteur de cette barre
   et laisse une bande vide en bas. Rallonger le document d'autant la comble. Le fond du document prend la couleur
   de l'écran affiché, pour qu'aucune bande claire ne puisse apparaître. */
html { min-height: calc(100% + env(safe-area-inset-top)); background: #8fbdf0; }

html:has(body.night) { background: #34487a; }

html:has(body.on-news) { background: #0f1115; }

html:has(#chat:not([hidden])) { background: #000; }

/* Conversation ouverte : la page elle-même ne défile plus. Sinon iOS confie parfois le geste à la page
   (rallongée pour la barre d'état) au lieu de la liste des messages, qui semble alors ne pas accrocher. */
html:has(#chat:not([hidden])), html:has(#chat:not([hidden])) body { height: 100%; min-height: 0; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #fff;
  background: linear-gradient(180deg, #2f6fc9 0%, #5b9be6 55%, #8fbdf0 100%) fixed;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body.night { background: linear-gradient(180deg, #0a1730 0%, #1d2f57 60%, #34487a 100%) fixed; }

[hidden] { display: none !important; }

ol { list-style: none; margin: 0; padding: 0; }

button, select, input, textarea { font: inherit; color: inherit; }

/* ---------- Météo ---------- */

#weather {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

#search input {
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 16px;
  outline: none;
}

#search input::placeholder { color: rgba(255, 255, 255, 0.75); }

.now { text-align: center; padding: 28px 0 20px; }

.now h1 { margin: 0; font-size: 30px; font-weight: 500; }

.temperature {
  margin: 0;
  font-size: 96px;
  font-weight: 200;
  line-height: 1.1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.condition { margin: 0; font-size: 20px; }

.range { margin: 4px 0 0; font-size: 17px; opacity: 0.9; }

.card {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.hourly { display: flex; gap: 18px; overflow-x: auto; scrollbar-width: none; }

.hourly::-webkit-scrollbar { display: none; }

.hourly li { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 40px; font-size: 15px; }

.hourly .glyph { font-size: 22px; }

.daily li {
  display: grid;
  grid-template-columns: 1fr 40px 44px 44px;
  align-items: center;
  padding: 8px 0;
  font-size: 17px;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.daily li:first-child { border-top: 0; }

.daily .glyph { font-size: 20px; text-align: center; }

.daily .min { text-align: right; opacity: 0.7; }

.daily .max { text-align: right; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.tile { display: flex; flex-direction: column; gap: 6px; }

.tile span { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.75; }

.tile strong { font-size: 22px; font-weight: 400; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 15px;
  white-space: nowrap;
}

/* ---------- Onglets du leurre ---------- */

#weather { padding-bottom: calc(env(safe-area-inset-bottom) + 84px); }

body.on-news { background: #0f1115; color: #f2f3f5; }

/* Sous la barre d'état de l'iPhone, une bande opaque : la recherche cachée ne transparaît pas derrière l'heure. */
body.on-news::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1;
  height: env(safe-area-inset-top);
  background: #0f1115;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  display: flex;
  justify-content: space-around;
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 4px);
  background: rgba(16, 19, 24, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 88px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  font-weight: 500;
}

.tab-btn .ico { width: 26px; height: 26px; }

.tab-btn.active { color: #fff; }

body.on-news .tab-btn.active { color: #ff4f5e; }

/* ---------- Actu ---------- */

/* La recherche est au-dessus du titre ; l'onglet s'ouvre défilé juste en dessous, et la place minimale
   garantit qu'on puisse toujours la faire apparaître en tirant vers le bas. */
.news-tab { min-height: calc(100vh + 64px); }

.news-search { padding: 4px 0 8px; }

.news-search input {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: #1f232b;
  color: inherit;
  font-size: 17px;
  outline: none;
  -webkit-appearance: none;
}

.news-search input::placeholder { color: rgba(255, 255, 255, 0.45); }

.news-list li[hidden] { display: none; }

.news-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 0 6px; }

.news-head h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }

.news-updated { font-size: 13px; opacity: 0.55; }

.news-list li { border-top: 1px solid rgba(255, 255, 255, 0.08); }

.news-list li:first-child { border-top: 0; }

.news-list a, .news-list div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 0;
  color: inherit;
  text-decoration: none;
}

.news-list .kicker { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #ff4f5e; }

.news-list strong { font-size: 17px; font-weight: 600; line-height: 1.3; }

.news-list .lead strong { font-size: 24px; font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }

.news-list .time { font-size: 13px; opacity: 0.5; }

.news-status { margin: 0; padding: 24px 0; text-align: center; font-size: 15px; opacity: 0.6; }

.news-status:empty { display: none; }

.news-credit { margin: 12px 0 0; text-align: center; font-size: 11px; opacity: 0.4; }

/* ---------- Conversation ---------- */

/* --viewport-gap : hauteur qu'iOS retire à tort à l'écran d'une app installée (voir app.js).
   La conversation descend d'autant, jusqu'au vrai bas de l'écran. */
#chat { position: fixed; inset: 0 0 calc(-1 * var(--viewport-gap, 0px)); background: #000; color: #e9ecf1; }

.thread { position: absolute; inset: 0; display: flex; flex-direction: column; background: #101318; }

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: #171b22;
  font-size: 15px;
}


/* Menu de l'administrateur, sous l'en-tête. */
.admin-sheet { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px; background: #171b22; }

.sheet-btn {
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: #252b35;
  color: #fff;
  font-size: 16px;
  text-align: left;
}

.sheet-btn.danger { color: #ff6b6b; font-weight: 600; }

.icon.active-admin { background: #2f6fc9; }

.pending { flex: 1; text-align: center; font-size: 13px; opacity: 0.7; }

.items {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Le geste vertical appartient à la liste, et ne se propage pas à la page arrivé en butée. */
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  font-size: 16px;
  line-height: 1.3;
  -webkit-overflow-scrolling: touch;
}

/* Bulles : mes messages à droite, ceux de l'autre à gauche. Les messages d'une même série se suivent de près. */
.items li {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  align-self: flex-start;
  max-width: 80%;
  margin-top: 10px;
}

.items li.mine { align-items: flex-end; align-self: flex-end; }

.items li.mine + li.mine, .items li.theirs + li.theirs { margin-top: 2px; }

.items li p {
  margin: 0;
  padding: 7px 12px;
  border-radius: 18px;
  background: #252b35;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.items li.mine p { background: #2f6fc9; color: #fff; }

.items li p { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* Photo ou vidéo : une pastille rouge et un libellé, sans aperçu. Pastille pleine tant que l'envoi
   n'a pas été ouvert par son destinataire, simple contour ensuite. */
.items li .media-tile {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: 16px;
}

.media-tile .dot {
  flex: none;
  width: 15px;
  height: 15px;
  border: 2.5px solid #ff3b4e;
  border-radius: 50%;
  background: #ff3b4e;
}

.items li.opened .dot { background: none; }

/* Le rouge se lit mal sur le bleu : la bulle d'une photo ou d'une vidéo que j'envoie reste sombre. */
.items li.mine.media:not(.voice) p { background: #252b35; }

.media-tile:disabled { opacity: 0.6; }

/* Reçu, pas encore ouvert : le libellé est en gras. Un vocal non écouté garde une bulle claire. */
.items li.fresh .media-tile { font-weight: 700; }

.items li.voice p { padding: 4px; }

.items li.fresh.voice p { background: #5b9be6; color: #fff; }

/* Enregistré dans la conversation : liseré et mention dorés. */
.items li.saved p { box-shadow: inset 0 0 0 2px #f1c24b; }

.items li.saved::after { content: 'Enregistré'; margin: 2px 6px 0; font-size: 11px; color: #f1c24b; }

/* L'état (« Remis », « Ouvert ») ne s'affiche que sous le dernier message d'une série ;
   une photo, une vidéo ou un vocal garde toujours le sien. */
.items li small { margin: 2px 6px 0; font-size: 11px; opacity: 0.55; }

.items li.mine:not(.media):has(+ li.mine) small { display: none; }

.items li.notice, .items li.time {
  align-self: center;
  max-width: 100%;
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  opacity: 0.55;
}

.items li.notice p { padding: 0; background: none; }

.items li.notice:first-child { margin-top: 0; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  background: #171b22;
}

/* Clavier ouvert : la marge de la barre d'accueil de l'iPhone n'a plus lieu d'être. */
.thread.keyboard .composer { padding-bottom: 8px; }

.composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border: 0;
  border-radius: 18px;
  background: #252b35;
  font-size: 16px;
  resize: none;
  outline: none;
}

.voice { align-items: center; }

.voice-clock { min-width: 44px; font-size: 17px; font-variant-numeric: tabular-nums; }

.voice-preview { flex: 1; min-width: 0; padding: 4px 10px; border-radius: 20px; background: #252b35; }

/* Pendant l'enregistrement, il n'y a pas encore de lecteur : le bouton d'arrêt part à droite. */
.voice-preview[hidden] + #voice-stop { margin-left: auto; }

/* Lecteur d'un vocal : lecture, onde, vitesse, durée. */
.voice-player { display: flex; align-items: center; gap: 10px; min-width: 0; }

.items .voice-player { width: 236px; max-width: 100%; padding: 2px 6px 2px 2px; }

.voice-player button { flex: none; padding: 0; border: 0; background: none; color: inherit; }

.voice-play { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; }

.voice-play .ico { width: 26px; height: 26px; }

.voice-wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; min-width: 0; }

.voice-wave span { flex: 1; min-width: 1px; min-height: 3px; border-radius: 2px; background: currentColor; opacity: 0.38; }

.voice-wave span.played { opacity: 1; }

.voice-player .voice-speed {
  padding: 3px 7px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 12px;
  font-weight: 600;
}

.voice-time { flex: none; min-width: 32px; font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; opacity: 0.85; }

.voice-player.loading { opacity: 0.6; }

.voice-player.failed { opacity: 0.4; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.ico {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #252b35;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.icon.send, .icon.shoot { background: #2f6fc9; }

.icon.send .ico { stroke-width: 2.2; }

.icon.recording, .icon.active { background: #c23b3b; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: rgba(40, 44, 52, 0.85);
  color: #fff;
  font-size: 15px;
}

.pill.primary { background: #2f6fc9; font-weight: 600; }

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  background: #e0566b;
  font-size: 11px;
  font-weight: 700;
}

/* ---------- Appareil photo ---------- */

.camera, .editor, .viewer { position: absolute; inset: 0; background: #000; overflow: hidden; }

/* La vidéo elle-même reste invisible : elle ne sert que de source. C'est le canevas, dessiné par camera.js,
   qui montre la caméra en plein écran. */
.camera > video { position: absolute; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }

.camera-view { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; }

.camera-top, .camera-bottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
}

.camera-top { top: env(safe-area-inset-top); }

.camera-bottom { bottom: calc(env(safe-area-inset-bottom) + 16px); }

.camera .icon, .editor .icon, .viewer .icon { background: rgba(20, 22, 28, 0.55); }

.camera-clock {
  padding: 4px 12px;
  border-radius: 999px;
  background: #c23b3b;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.shutter {
  width: 76px;
  height: 76px;
  padding: 0;
  border: 5px solid #fff;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.15s, background 0.15s;
}

.shutter.recording { transform: scale(1.2); background: #c23b3b; }

/* ---------- Éditeur (après la prise) ---------- */

.editor-media, .editor-media > *, .editor-draw { position: absolute; inset: 0; width: 100%; height: 100%; }

.editor-media > .cover, .stage > .cover { object-fit: cover; }

.editor-media > .contain, .stage > .contain { object-fit: contain; }

.editor-draw { pointer-events: none; touch-action: none; }

.editor.drawing .editor-draw { pointer-events: auto; }

.editor.drawing .caption { pointer-events: none; }

.caption {
  position: absolute;
  left: 0;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 17px;
  text-align: center;
  outline: none;
  touch-action: none;
}

.editor-discard { position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 20px; }

.editor-tools {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Durée d'affichage d'une photo : bien visible, en bas à gauche, à l'opposé du bouton d'envoi. */
.timer-pill {
  position: absolute;
  left: 20px;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 24px;
  background: rgba(20, 22, 28, 0.6);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
}

.timer-pill .ico { width: 24px; height: 24px; }

.send-round {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #2f6fc9;
  color: #fff;
}

.send-round .ico { width: 26px; height: 26px; stroke-width: 2.2; }

.editor-tools .icon.active { background: #2f6fc9; }

.colors { display: flex; flex-direction: column; gap: 8px; }

.colors button { width: 26px; height: 26px; padding: 0; border: 2px solid #fff; border-radius: 50%; }

.colors button.active { transform: scale(1.3); }

.editor-send { position: absolute; right: 20px; bottom: calc(env(safe-area-inset-bottom) + 24px); }

/* ---------- Lecture plein écran ---------- */

.viewer { z-index: 2; }

.viewer-content {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Le doigt maintenu sur une photo ne doit ni la sélectionner ni ouvrir le menu d'iOS. */
.viewer-content { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

.viewer-content video { pointer-events: none; }

/* Photo, calque et autocollants sont des blocs peints en fond, pas des balises image (voir chat.js). */
.stage > div { background: center / cover no-repeat; }

.stage > div.contain { background-size: contain; }

.stage > div.layer { background-size: 100% 100%; }

.stage > div.sticker { background-size: contain; aspect-ratio: 1; }

/* La scène reprend les proportions de l'écran de l'expéditeur : le texte et le dessin restent à leur place. */
.stage { position: relative; flex: none; }

.stage > * { position: absolute; inset: 0; width: 100%; height: 100%; }

.viewer-content audio { width: 90%; }

.viewer-bar {
  position: absolute;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  height: 3px;
  background: #fff;
  transform: scaleX(0);
  transform-origin: left;
}

.viewer-close { position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 20px; }

/* ---------- Autocollants ---------- */

.camera-side { display: flex; gap: 10px; width: 96px; }

.camera-side.end { justify-content: flex-end; }

.editor-stickers { position: absolute; inset: 0; pointer-events: none; }

.sticker {
  position: absolute;
  height: auto;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  cursor: grab;
}

.sticker.emoji { line-height: 1; white-space: nowrap; }

.editor.drawing .sticker { pointer-events: none; }

/* À la lecture, un autocollant garde sa place dans la scène et ne capte pas le toucher. */
.stage > .sticker { inset: auto; height: auto; pointer-events: none; }

.trash {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(20, 22, 28, 0.55);
  color: #fff;
  transition: transform 0.15s, background 0.15s;
}

.trash .ico { width: 26px; height: 26px; }

.trash.hot { transform: translateX(-50%) scale(1.3); background: #c23b3b; }

.stickers { position: absolute; inset: 0; display: flex; flex-direction: column; background: #101318; z-index: 1; }

.stickers-top { display: flex; gap: 10px; padding: calc(env(safe-area-inset-top) + 10px) 12px 10px; min-height: 40px; }

.stickers-top input {
  flex: 1;
  min-width: 0;
  padding: 0 14px;
  border: 0;
  border-radius: 20px;
  background: #252b35;
  font-size: 16px;
  outline: none;
}

.stickers-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.stickers-emoji { display: grid; grid-template-columns: repeat(8, 1fr); padding: 0 6px 8px; }

.stickers-emoji button { padding: 6px 0; border: 0; background: none; font-size: 28px; line-height: 1; }

.stickers-grid { columns: 3; column-gap: 6px; padding: 0 6px; }

.stickers-grid button {
  display: block;
  width: 100%;
  margin: 0 0 6px;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  background: #1b2029;
  break-inside: avoid;
}

.stickers-grid img { display: block; width: 100%; height: 100%; object-fit: contain; }

.stickers-status { margin: 0; padding: 8px 12px; text-align: center; font-size: 14px; opacity: 0.7; }

.stickers-status:empty { display: none; }

.stickers-credit {
  margin: 0;
  padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px);
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  opacity: 0.6;
}
