/* famchat — feuille de style. Look messagerie classique, rendu natif mobile + PC. */
:root {
  color-scheme: light dark;
  --brand: #008069;
  --brand-deep: #005c4b;
  --accent: #00a884;
  --bg-chat: #efeae2;
  --pattern: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='180'%20height='180'%20viewBox='0%200%20180%20180'%3E%3Cg%20fill='none'%20stroke='%234a5a63'%20stroke-width='1.5'%20stroke-linecap='round'%20stroke-linejoin='round'%20opacity='0.13'%3E%3Cpath%20transform='translate(14%2014)%20rotate(-12)'%20d='M12%2021s-7-4.5-7-10a4%204%200%200%201%207-2.5A4%204%200%200%201%2019%2011c0%205.5-7%2010-7%2010z'/%3E%3Cpath%20transform='translate(108%2020)%20rotate(10)'%20d='M12%202l2.9%206.3%206.9.7-5.2%204.7%201.5%206.8L12%2017l-6.1%203.5%201.5-6.8L2.2%209l6.9-.7z'/%3E%3Cpath%20transform='translate(58%2076)%20rotate(-6)'%20d='M3%2011l9-8%209%208v10h-6v-6H9v6H3z'/%3E%3Cpath%20transform='translate(126%20104)%20rotate(8)'%20d='M4%208h13v6a5%205%200%200%201-5%205H9a5%205%200%200%201-5-5zM17%209h2a2%202%200%200%201%200%204h-2M8%203v3M12%203v3'/%3E%3Cpath%20transform='translate(16%20118)%20rotate(-8)'%20d='M12%202a6%207%200%201%200%200%2014%206%207%200%200%200%200-14zm0%2014l-1%202h2zm0%202c0%203-2%203-2%205'/%3E%3Cpath%20transform='translate(84%20146)'%20d='M12%202a10%2010%200%201%200%200%2020%2010%2010%200%200%200%200-20zM8%2014s1.5%202%204%202%204-2%204-2M9%209h.01M15%209h.01'/%3E%3Cpath%20transform='translate(146%2056)%20rotate(6)'%20d='M4%204h16v11H9l-5%204z'/%3E%3Cpath%20transform='translate(60%2020)'%20d='M4%2012h6M7%209v6'/%3E%3Cpath%20transform='translate(150%20150)'%20d='M4%2012h6M7%209v6'/%3E%3C/g%3E%3C/svg%3E");
  --me: #d9fdd3;
  --other: #ffffff;
  --text: #111b21;
  --muted: #667781;
  --meta: #667781;
  --composer: #f0f2f5;
  --input: #ffffff;
  --border: #d1d7db;
  --pill: rgba(255,255,255,.92);
  --sheet: #ffffff;
  --card: #ffffff;
  --desk-bg: #d1d7db;
  --link: #027eb5;
  --danger: #c0392b;
  --banner-bg: #fff3cd;
  --banner-fg: #664d03;
  --shadow: 0 1px .5px rgba(11,20,26,.13);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #1f2c34;
    --brand-deep: #005c4b;
    --accent: #00a884;
    --bg-chat: #0b141a;
    --pattern: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='180'%20height='180'%20viewBox='0%200%20180%20180'%3E%3Cg%20fill='none'%20stroke='%23c9d4da'%20stroke-width='1.5'%20stroke-linecap='round'%20stroke-linejoin='round'%20opacity='0.06'%3E%3Cpath%20transform='translate(14%2014)%20rotate(-12)'%20d='M12%2021s-7-4.5-7-10a4%204%200%200%201%207-2.5A4%204%200%200%201%2019%2011c0%205.5-7%2010-7%2010z'/%3E%3Cpath%20transform='translate(108%2020)%20rotate(10)'%20d='M12%202l2.9%206.3%206.9.7-5.2%204.7%201.5%206.8L12%2017l-6.1%203.5%201.5-6.8L2.2%209l6.9-.7z'/%3E%3Cpath%20transform='translate(58%2076)%20rotate(-6)'%20d='M3%2011l9-8%209%208v10h-6v-6H9v6H3z'/%3E%3Cpath%20transform='translate(126%20104)%20rotate(8)'%20d='M4%208h13v6a5%205%200%200%201-5%205H9a5%205%200%200%201-5-5zM17%209h2a2%202%200%200%201%200%204h-2M8%203v3M12%203v3'/%3E%3Cpath%20transform='translate(16%20118)%20rotate(-8)'%20d='M12%202a6%207%200%201%200%200%2014%206%207%200%200%200%200-14zm0%2014l-1%202h2zm0%202c0%203-2%203-2%205'/%3E%3Cpath%20transform='translate(84%20146)'%20d='M12%202a10%2010%200%201%200%200%2020%2010%2010%200%200%200%200-20zM8%2014s1.5%202%204%202%204-2%204-2M9%209h.01M15%209h.01'/%3E%3Cpath%20transform='translate(146%2056)%20rotate(6)'%20d='M4%204h16v11H9l-5%204z'/%3E%3Cpath%20transform='translate(60%2020)'%20d='M4%2012h6M7%209v6'/%3E%3Cpath%20transform='translate(150%20150)'%20d='M4%2012h6M7%209v6'/%3E%3C/g%3E%3C/svg%3E");
    --me: #005c4b;
    --other: #202c33;
    --text: #e9edef;
    --muted: #8696a0;
    --meta: rgba(233,237,239,.6);
    --composer: #1f2c34;
    --input: #2a3942;
    --border: #2a3942;
    --pill: #182229;
    --sheet: #233138;
    --card: #202c33;
    --desk-bg: #0c1317;
    --link: #53bdeb;
    --danger: #f15c6d;
    --banner-bg: #3b2f00;
    --banner-fg: #ffe08a;
    --shadow: 0 1px .5px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
               "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  font-size: 16px;
  color: var(--text);
  background: var(--brand);
  overscroll-behavior: none;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  overflow: hidden;
  position: relative;
}
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.screen.center {
  align-items: center; justify-content: center;
  padding: max(24px, var(--safe-top)) max(20px, var(--safe-right)) max(24px, var(--safe-bottom)) max(20px, var(--safe-left));
  background-color: var(--bg-chat);
  background-image: linear-gradient(var(--brand) 0 calc(var(--safe-top) + 132px), transparent 0), var(--pattern);
  overflow-y: auto;
}

/* ---- cartes (login / clé) ---- */
.card {
  width: 100%; max-width: 400px;
  background: var(--card);
  border-radius: 18px;
  padding: 30px 24px 24px;
  box-shadow: 0 8px 28px rgba(11,20,26,.14);
  display: flex; flex-direction: column; gap: 14px;
  text-align: center;
}
.card .logo { width: 72px; height: 72px; margin: 0 auto 2px; }
.card .step { display: flex; flex-direction: column; gap: 14px; }
.card .lock { font-size: 44px; line-height: 1; margin: 0 auto 2px; }
.card h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.card .lead { margin: -6px 0 4px; color: var(--muted); font-size: 15px; line-height: 1.4; }
.card .hint {
  margin: 0; font-size: 14px; line-height: 1.4; text-align: left;
  background: rgba(0,168,132,.10); color: var(--text); border-radius: 12px; padding: 10px 12px;
}
.who { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 2px 0 4px; }
.who .busy { color: var(--muted); font-size: 14px; padding: 12px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 18px 8px 8px; min-height: 52px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--input); color: var(--text);
  font-size: 16px; font-weight: 600;
  transition: transform .05s, border-color .15s, box-shadow .15s;
}
.chip:hover { border-color: var(--accent); }
.chip:active { transform: scale(.96); }
.chip:disabled { opacity: .5; cursor: default; }
.chip.last { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,168,132,.18); }
.chip .av {
  width: 34px; height: 34px; border-radius: 50%; color: #fff; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field span { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }
.field input {
  height: 50px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--input); padding: 0 14px; font-size: 16px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,168,132,.2); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); text-align: left; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.error { margin: -6px 0 -4px; min-height: 1.3em; color: var(--danger); font-size: 13.5px; line-height: 1.3; }
.btn {
  height: 50px; border: none; border-radius: 12px; background: var(--accent); color: #fff;
  font-size: 16px; font-weight: 600; width: 100%;
  transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.link { background: transparent; color: var(--accent); height: 40px; margin-top: -8px; font-weight: 500; }
.btn.small { height: 36px; font-size: 14px; width: auto; padding: 0 14px; border-radius: 10px; }

/* ---- spinner ---- */
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid rgba(0,168,132,.25); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-help {
  margin-top: 22px; font-size: 14px; color: var(--muted);
  opacity: 0; animation: appear .3s ease-in 8s forwards;   /* n'apparaît que si le JS ne démarre pas */
}
.loading-help a { color: var(--accent); font-weight: 600; }
@keyframes appear { to { opacity: 1; } }

/* ---- barre du haut ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 6px 8px 14px;
  padding-top: calc(8px + var(--safe-top));
  padding-left: calc(14px + var(--safe-left));
  padding-right: calc(6px + var(--safe-right));
  background: var(--brand); color: #fff;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(11,20,26,.18);
  z-index: 2;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,.18);
  display: grid; place-items: center; font-size: 22px;
}
.titles { flex: 1; min-width: 0; line-height: 1.25; }
.title { font-size: 17px; font-weight: 600; }
.subtitle { font-size: 12.5px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 50%; border: none; background: transparent; color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
}
.iconbtn:hover { background: rgba(255,255,255,.12); }

/* ---- bandeau reconnexion ---- */
.banner {
  background: var(--banner-bg); color: var(--banner-fg);
  font-size: 13px; text-align: center; padding: 6px 12px; flex-shrink: 0;
}

/* ---- messages ---- */
.msgs {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 8px;
  padding-left: var(--safe-left); padding-right: var(--safe-right);
  background-color: var(--bg-chat);
  background-image: var(--pattern);
  display: flex; flex-direction: column;
  scroll-behavior: auto;
  position: relative;
}
.msgs::before { content: ""; flex: 1 1 auto; }   /* pousse les messages vers le bas quand il y en a peu */
.msgs > * { flex-shrink: 0; }
.empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: max-content; max-width: 80%; text-align: center;
  color: var(--muted); font-size: 15px; line-height: 1.5;
  background: var(--pill); padding: 14px 20px; border-radius: 12px; box-shadow: var(--shadow);
}
.day { display: flex; justify-content: center; margin: 12px 0 6px; }
.day span {
  background: var(--pill); color: var(--muted); font-size: 12.5px; font-weight: 500;
  padding: 5px 12px; border-radius: 8px; box-shadow: var(--shadow);
  text-transform: capitalize;
}
.row { display: flex; padding: 1px 4% 1px; }
.row.first { margin-top: 7px; }
.row.me { justify-content: flex-end; }
.bubble {
  position: relative; max-width: 80%; min-width: 64px;
  padding: 6px 8px 8px 9px;
  border-radius: 9px;
  background: var(--other);
  box-shadow: var(--shadow);
  animation: pop .12s ease-out;
}
.row.me .bubble { background: var(--me); }
.row.first.other .bubble { border-top-left-radius: 0; }
.row.first.me .bubble { border-top-right-radius: 0; }
.row.first .bubble::before {
  content: ""; position: absolute; top: 0; width: 9px; height: 13px; background: inherit;
}
.row.first.other .bubble::before { left: -8px; clip-path: polygon(100% 0, 0 0, 100% 100%); }
.row.first.me .bubble::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.name { font-size: 12.8px; font-weight: 600; margin-bottom: 2px; line-height: 1.3; }
.text {
  font-size: 15.5px; line-height: 1.38;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.text::after { content: ""; display: inline-block; width: 46px; height: 1px; }
.text a { color: var(--link); text-decoration: underline; }
.text.locked { font-style: italic; color: var(--muted); }
.meta {
  position: absolute; right: 8px; bottom: 4px;
  font-size: 11px; color: var(--meta); line-height: 1; white-space: nowrap;
}
.row.emoji .text { font-size: 38px; line-height: 1.15; }
.row.emoji .text::after { width: 40px; }
@keyframes pop { from { transform: scale(.97); opacity: .6; } to { transform: none; opacity: 1; } }

/* ---- bouton "descendre" ---- */
.jump {
  position: absolute; right: calc(14px + var(--safe-right)); bottom: calc(76px + var(--safe-bottom));
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: var(--other); color: var(--muted);
  box-shadow: 0 2px 6px rgba(11,20,26,.25);
  display: grid; place-items: center; z-index: 3;
}
.jump .badge {
  position: absolute; top: -6px; left: -6px; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
}

/* ---- bannière « ajouter à l'écran d'accueil » ---- */
.install {
  position: relative; flex-shrink: 0;
  margin: 0 8px 6px; padding: 12px 14px 10px;
  background: var(--other); color: var(--text);
  border-radius: 14px; box-shadow: 0 2px 10px rgba(11,20,26,.18);
  font-size: 14.5px; line-height: 1.4;
  animation: slideup .2s ease-out;
}
.install-close {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%;
  border: none; background: transparent; color: var(--muted); font-size: 16px;
}
.install-head { display: flex; align-items: center; gap: 12px; padding-right: 28px; }
.install-head img { width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; }
.install-head span { color: var(--muted); }
.install-steps { margin: 10px 0 4px; padding-left: 22px; }
.install-steps li { margin: 6px 0; }
.install-steps .ico { width: 20px; height: 20px; vertical-align: -5px; margin: 0 2px; color: var(--link); }
.install-steps .dim { color: var(--muted); }
p.install-steps { padding-left: 0; }
.install-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.btn.ghost { background: transparent; color: var(--accent); }

/* ---- zone de saisie ---- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 6px 8px 6px;
  padding-bottom: calc(6px + var(--safe-bottom));
  padding-left: calc(8px + var(--safe-left)); padding-right: calc(8px + var(--safe-right));
  background: var(--composer);
  flex-shrink: 0;
}
.composer textarea {
  flex: 1; min-height: 44px; max-height: 140px; height: 44px;
  border-radius: 22px; border: none; outline: none; resize: none;
  background: var(--input); color: var(--text);
  padding: 11px 16px; font-size: 16px; line-height: 1.35;
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--muted); }
.sendbtn {
  width: 44px; height: 44px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  transition: opacity .15s, transform .05s;
}
.sendbtn svg { margin-left: 2px; }
.sendbtn:disabled { opacity: .45; cursor: default; }
.sendbtn:not(:disabled):active { transform: scale(.92); }

/* ---- menu (dialog) ---- */
.sheet {
  border: none; padding: 0; margin: 0;
  position: fixed; left: 0; right: 0; bottom: 0; top: auto;
  width: 100%; max-width: 100%; max-height: 90vh;
  background: var(--sheet); color: var(--text);
  border-radius: 18px 18px 0 0;
  padding-bottom: max(10px, var(--safe-bottom));
  box-shadow: 0 -4px 24px rgba(11,20,26,.25);
  animation: slideup .18s ease-out;
}
.sheet::backdrop { background: rgba(11,20,26,.45); }
@keyframes slideup { from { transform: translateY(24px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px 12px; }
.sheet-avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.sheet-name { font-size: 17px; font-weight: 600; }
.sheet-sub { font-size: 12.5px; color: var(--muted); }
.item {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 14px 20px; font-size: 16px; line-height: 1.2;
}
.item:hover { background: rgba(127,127,127,.10); }
.item.danger { color: var(--danger); }
.item.close { color: var(--muted); text-align: center; border-top: 1px solid var(--border); margin-top: 6px; }
.keybox {
  margin: 4px 20px 6px; padding: 10px 12px; border-radius: 12px; background: var(--input);
  display: flex; align-items: center; gap: 10px;
}
.keybox code { flex: 1; font-size: 14px; overflow-wrap: anywhere; user-select: all; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + var(--safe-bottom));
  background: #2a3942; color: #fff; padding: 10px 16px; border-radius: 24px;
  font-size: 14px; z-index: 50; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  max-width: min(90vw, 420px); text-align: center;
}

/* ---- PC ---- */
@media (min-width: 900px) {
  body { background: var(--desk-bg); overflow: hidden; }
  body::before {
    content: ""; position: fixed; top: 0; left: 0; right: 0; height: 127px;
    background: var(--brand); z-index: 0;
  }
  #app {
    position: relative; z-index: 1;
    height: calc(100vh - 38px); height: calc(100dvh - 38px);
    max-width: 1000px; margin: 19px auto;
    border-radius: 6px; overflow: hidden;
    box-shadow: 0 6px 18px rgba(11,20,26,.28);
  }
  .bubble { max-width: 65%; }
  .row { padding-left: 5%; padding-right: 5%; }
  .composer textarea { max-height: 200px; }
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%);
    width: 380px; border-radius: 16px; padding-bottom: 8px;
    animation: fadein .15s ease-out;
  }
  .toast { bottom: 40px; }
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

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