/* ============================================================
   Family Chat — visual identity
   Warm, intimate, hand-made feeling. Deep teal anchor,
   coral accent for "you", soft paper background.
   ============================================================ */
:root{
  --paper:#f6f1e7;
  --ink:#23211c;
  --teal:#0f5e5a;
  --teal-dark:#0a4744;
  --coral:#e0654a;
  --muted:#7c766a;
  --line:#e3dccd;
  --bubble-them:#ffffff;
  --bubble-you:#0f5e5a;
  --radius:18px;
  --shadow:0 1px 2px rgba(35,33,28,.06),0 8px 24px rgba(35,33,28,.06);
  font-size:16px;
}
/* ---- Color themes (per-user). Each sets the accent trio together. ---- */
html.theme-ocean    {--teal:#12657e;--teal-dark:#0c4a5e;--bubble-you:#12657e}
html.theme-indigo   {--teal:#3f4ba3;--teal-dark:#2c357a;--bubble-you:#3f4ba3}
html.theme-plum     {--teal:#7a3f8f;--teal-dark:#5c2e6d;--bubble-you:#7a3f8f}
html.theme-rose     {--teal:#b5426f;--teal-dark:#8d3255;--bubble-you:#b5426f}
html.theme-crimson  {--teal:#b23a3a;--teal-dark:#8a2a2a;--bubble-you:#b23a3a}
html.theme-sunset   {--teal:#c2661e;--teal-dark:#9a4f15;--bubble-you:#c2661e}
html.theme-forest   {--teal:#2f7d44;--teal-dark:#245f34;--bubble-you:#2f7d44}
html.theme-graphite {--teal:#3f4650;--teal-dark:#2b3038;--bubble-you:#3f4650}
html.theme-slate    {--teal:#4a5b6e;--teal-dark:#374553;--bubble-you:#4a5b6e}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
/* On the chat screen, prevent the PAGE itself from scrolling, so the on-screen
   keyboard can't push the app up and leave an empty gap. We don't use fixed
   positioning: with the viewport meta's interactive-widget=resizes-content, the
   layout shrinks to fit above the keyboard on its own, and our 100dvh app height
   follows it. Locking overflow just stops any stray page scroll; only the
   messages list inside scrolls. Auth pages don't get this class. */
body.chat-app{
  height:100%;overflow:hidden;overscroll-behavior:none;position:relative;
}
/* Block pinch-zoom of the chat interface (toolbar etc. should never scale),
   while still allowing normal vertical/horizontal scrolling of message lists. */
html{touch-action:pan-x pan-y;-ms-touch-action:pan-x pan-y}
body{
  background:var(--paper);
  color:var(--ink);
  font-family:"Segoe UI",system-ui,-apple-system,Roboto,Helvetica,Arial,sans-serif;
  -webkit-font-smoothing:antialiased;
}

/* ---------- Auth screens ---------- */
.auth-card{
  max-width:380px;margin:8vh auto;padding:32px 28px;
  background:#fff;border-radius:var(--radius);box-shadow:var(--shadow);
}
.auth-title{margin:0 0 4px;font-size:1.7rem;color:var(--teal);letter-spacing:-.01em}
.auth-sub{margin:0 0 22px;color:var(--muted)}
.auth-form label{display:block;margin-bottom:14px;font-size:.82rem;color:var(--muted);font-weight:600}
.auth-form input{
  width:100%;margin-top:6px;padding:12px 14px;font-size:1rem;
  border:1.5px solid var(--line);border-radius:12px;background:#fcfaf5;color:var(--ink);
}
.auth-form input:focus{outline:none;border-color:var(--teal);background:#fff}
.btn-primary{
  width:100%;margin-top:6px;padding:13px;font-size:1rem;font-weight:700;
  color:#fff;background:var(--teal);border:none;border-radius:12px;cursor:pointer;
  transition:background .15s;
}
.btn-primary:hover{background:var(--teal-dark)}
.auth-alt{margin:18px 0 0;text-align:center;color:var(--muted);font-size:.9rem}
.auth-alt a,.alert a{color:var(--coral);font-weight:600;text-decoration:none}
.alert{
  margin-bottom:18px;padding:11px 14px;border-radius:12px;font-size:.9rem;
  background:#fdeae6;color:#a23a26;border:1px solid #f3c9bf;
}

/* ---------- App shell ---------- */
.app{display:flex;height:100vh;height:100svh;height:100dvh;overflow:hidden}
.sidebar{
  width:260px;flex-shrink:0;background:var(--teal);color:#eafaf8;
  display:flex;flex-direction:column;height:100vh;height:100svh;height:100dvh;
}
.brand{
  padding:20px 20px 14px;font-size:1.2rem;font-weight:800;letter-spacing:-.01em;
  border-bottom:1px solid rgba(255,255,255,.12);
  display:flex;align-items:center;gap:10px;
}
.brand-name{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.sidebar-close{
  display:none;background:rgba(255,255,255,.16);border:none;color:#fff;
  width:34px;height:34px;border-radius:9px;cursor:pointer;font-size:1.1rem;flex-shrink:0;
}
.sidebar-close:hover{background:rgba(255,255,255,.26)}
.rooms{flex:1;overflow-y:auto;padding:10px 8px}
.rooms-label{padding:8px 12px 4px;font-size:.7rem;text-transform:uppercase;
  letter-spacing:.08em;color:rgba(255,255,255,.55)}
.room{
  display:flex;align-items:center;gap:9px;padding:11px 12px;margin:2px 0;
  border-radius:11px;color:#dff5f2;text-decoration:none;font-weight:600;font-size:.95rem;
  cursor:pointer;transition:background .12s;
}
.room:hover{background:rgba(255,255,255,.08)}
.room.active{background:rgba(255,255,255,.16);color:#fff}
.room .hash{opacity:.55;font-weight:700}
.sidebar-foot{
  padding:12px 14px;border-top:1px solid rgba(255,255,255,.12);
  display:flex;flex-direction:column;gap:10px;font-size:.9rem;
}
.me-row{display:flex;align-items:center;gap:10px;min-width:0}
.me-avatar{width:38px;height:38px;border-radius:50%;flex-shrink:0;object-fit:cover}
.me-avatar-i{display:inline-flex;align-items:center;justify-content:center;
  background:var(--coral);color:#fff;font-weight:700;font-size:1rem;text-transform:uppercase}
.sidebar-foot .me{flex:1;min-width:0}
.sidebar-foot .me b{display:block;color:#fff;font-size:.95rem;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.sidebar-foot .me span{display:block;color:rgba(255,255,255,.6);font-size:.76rem;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.foot-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.icon-btn{
  background:rgba(255,255,255,.12);border:none;color:#fff;width:36px;height:36px;
  border-radius:9px;cursor:pointer;font-size:1rem;line-height:1;flex-shrink:0;
  display:inline-flex;align-items:center;justify-content:center;text-decoration:none;
}
.icon-btn:hover{background:rgba(255,255,255,.22)}
.icon-btn[hidden]{display:none !important}
/* avatar photo in the private-chat list */
.dm-avatar-img{object-fit:cover;padding:0}

/* ---------- Chat area ---------- */
.chat{
  flex:1;display:flex;flex-direction:column;min-width:0;background:var(--paper);
  height:100vh;height:100svh;height:100dvh;position:relative;overflow:hidden;
}
.chat-head{
  flex:0 0 auto;
  padding:16px 22px;border-bottom:1px solid var(--line);background:#fbf8f1;
  display:flex;align-items:center;gap:12px;
  padding-top:calc(16px + env(safe-area-inset-top, 0px));
}
.chat-head .back{display:none;background:none;border:none;font-size:1.4rem;
  color:var(--teal);cursor:pointer;padding:0 4px 0 0}
.chat-head h2{margin:0;font-size:1.1rem;color:var(--ink)}
.chat-head .hash{color:var(--muted)}

/* Only this middle area scrolls; header and composer never move. */
.messages{flex:1 1 auto;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;
  padding:22px;display:flex;flex-direction:column;gap:3px;
  /* Chrome on Android starts text selection on long-press; disable it across
     the whole message list so only our own message menu appears. */
  -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;
  -webkit-touch-callout:none;}
.msg{display:flex;flex-direction:column;max-width:74%;margin-bottom:6px;
  -webkit-user-select:none;-moz-user-select:none;user-select:none;-webkit-touch-callout:none;}
.msg.them{align-self:flex-start}
.msg.you{align-self:flex-end;align-items:flex-end}
.msg .who{display:flex;align-items:center;gap:7px;font-size:.74rem;font-weight:700;color:var(--teal);margin:0 0 3px 6px}
.msg.you .who{display:none}
.msg-avatar{width:22px;height:22px;border-radius:50%;object-fit:cover;flex-shrink:0;cursor:pointer}
.msg-avatar-i{display:inline-flex;align-items:center;justify-content:center;
  background:var(--coral);color:#fff;font-size:.7rem;text-transform:uppercase}
.bubble{
  padding:10px 14px;border-radius:16px;line-height:1.4;font-size:.97rem;
  box-shadow:var(--shadow);word-wrap:break-word;overflow-wrap:anywhere;
  /* stop the browser's long-press text selection (blue handles) so our
     own message menu is the only thing that appears on long-press */
  -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;
  -webkit-touch-callout:none;
}
.msg.them .bubble{background:var(--bubble-them);border-bottom-left-radius:5px}
.msg.you .bubble{background:var(--bubble-you);color:#fff;border-bottom-right-radius:5px}
.msg .time{font-size:.68rem;color:var(--muted);margin:3px 12px 0}
.msg.you .time{text-align:right}

.bubble a{color:inherit;text-decoration:underline}
.attach{display:flex;align-items:center;gap:10px;text-decoration:none;color:inherit}
.attach-wrap{display:flex;flex-direction:column;gap:4px}
.dl-file{align-self:flex-end;text-decoration:none;font-size:1.1rem;color:inherit;opacity:.7;margin-top:-2px}
.dl-file:hover{opacity:1}
.attach .ext{
  flex-shrink:0;width:38px;height:38px;border-radius:9px;display:grid;place-items:center;
  background:rgba(15,94,90,.1);color:var(--teal);font-size:.62rem;font-weight:800;
  text-transform:uppercase;
}
.msg.you .attach .ext{background:rgba(255,255,255,.2);color:#fff}
.attach .meta{min-width:0}
.attach .meta b{display:block;font-size:.86rem;white-space:nowrap;overflow:hidden;
  text-overflow:ellipsis;max-width:180px}
.attach .meta span{font-size:.72rem;opacity:.75}
.attach-img{display:block;max-width:240px;border-radius:12px;margin-top:2px}
.player.img-wrap{max-width:260px}
.player.img-wrap .attach-img{max-width:100%}

.day-sep{align-self:center;margin:10px 0;padding:3px 12px;font-size:.72rem;
  color:var(--muted);background:#efe8d8;border-radius:20px}

/* ---------- Composer ---------- */
.composer{
  flex:0 0 auto;
  padding:12px 16px;border-top:1px solid var(--line);background:#fbf8f1;
  display:flex;align-items:flex-end;gap:10px;
  /* keep the input above the Android/iOS bottom navigation bar */
  padding-bottom:calc(12px + env(safe-area-inset-bottom, 0px));
}
.composer textarea{
  flex:1;resize:none;max-height:140px;padding:11px 14px;font-size:1rem;font-family:inherit;
  border:1.5px solid var(--line);border-radius:14px;background:#fff;color:var(--ink);line-height:1.4;
  /* Hide the scrollbar gutter/track, which some Android keyboards render as a
     thin vertical line on the edge of the box. The field still scrolls when the
     text is long; only the visible scrollbar is removed. */
  scrollbar-width:none;              /* Firefox */
  -ms-overflow-style:none;           /* old Edge */
  overflow-y:auto;
}
.composer textarea::-webkit-scrollbar{width:0;height:0;display:none} /* Chrome/WebView */
.composer textarea:focus{outline:none;border-color:var(--teal)}
.composer .send,.composer .clip{
  flex-shrink:0;width:44px;height:44px;border-radius:12px;border:none;cursor:pointer;
  font-size:1.15rem;display:grid;place-items:center;
}
.composer .clip{background:#ece4d4;color:var(--teal)}
.composer .clip:hover{background:#e2d9c5}
.composer .send{background:var(--coral);color:#fff}
.composer .send:hover{background:#c9543b}
.composer .send:disabled{opacity:.5;cursor:default}
.file-chip{
  display:none;align-items:center;gap:8px;margin:0 16px;padding:8px 12px;
  background:#fff;border:1px solid var(--line);border-radius:10px;font-size:.85rem;
}
.file-chip.show{display:flex}
.file-chip button{background:none;border:none;color:var(--coral);cursor:pointer;font-size:1rem}
.empty{margin:auto;color:var(--muted);text-align:center;font-size:.95rem}

/* ---------- Mobile ---------- */
@media(max-width:720px){
  .sidebar{position:absolute;z-index:30;height:100vh;height:100svh;height:100dvh;
    width:84%;max-width:340px;
    transform:translateX(-100%);
    transition:transform .2s;box-shadow:8px 0 30px rgba(0,0,0,.2)}
  .app.show-rooms .sidebar{transform:translateX(0)}
  .chat-head .back{display:block}
  .sidebar-close{display:inline-flex;align-items:center;justify-content:center}
  .msg{max-width:86%}
  .attach .meta b{max-width:130px}
}
/* dim layer behind the open sidebar (created in JS, tap it to close) */
#sidebarScrim{position:fixed;inset:0;z-index:25;background:rgba(20,18,14,.35);
  border:none;margin:0;padding:0;width:100%;height:100%;cursor:pointer;display:none}
.app.show-rooms #sidebarScrim{display:block}

/* ---------- Admin ---------- */
.admin-wrap{max-width:680px;margin:0 auto;padding:24px 18px 60px}
.admin-top{margin-bottom:18px}
.back-link{color:var(--coral);text-decoration:none;font-weight:600;font-size:.9rem}
.admin-top h1{margin:8px 0 0;color:var(--teal);font-size:1.5rem}
.alert.ok{background:#e3f3ec;color:#1d6b4c;border-color:#c2e6d5}
.panel{background:#fff;border-radius:var(--radius);box-shadow:var(--shadow);
  padding:20px 22px;margin-bottom:18px}
.panel.soft{background:#fbf6ec}
.panel h2{margin:0 0 14px;font-size:1.05rem;color:var(--ink)}
.rowlist{list-style:none;margin:0 0 14px;padding:0}
.rowlist li{display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:11px 0;border-bottom:1px solid var(--line);flex-wrap:wrap}
.rowlist li:last-child{border-bottom:none}
.rowlist .tag{font-style:normal;font-size:.7rem;background:rgba(15,94,90,.12);color:var(--teal);
  padding:2px 7px;border-radius:20px;margin-left:6px}
.rowlist .tag.you{background:rgba(224,101,74,.15);color:var(--coral)}
.rowlist .actions{display:flex;gap:8px}
.rowlist form{display:inline}

/* admin: member rows — stack name, actions, and password reset cleanly */
.member-row{display:flex;flex-direction:column;align-items:stretch;gap:9px}
.member-name{font-size:1rem}
.member-actions{display:flex;gap:8px;flex-wrap:wrap}
.member-actions form{display:flex}
.member-actions .ghost,.member-actions .danger{white-space:nowrap}
.pw-reset-form{display:flex;gap:8px;width:100%;flex-wrap:wrap}
.pw-reset-input{flex:1 1 160px;min-width:0;padding:9px 11px;border:1.5px solid var(--line);
  border-radius:9px;font-size:.92rem;background:#fcfaf5;color:var(--ink)}
.pw-reset-input:focus{outline:none;border-color:var(--teal);background:#fff}
.pw-reset-form .ghost{flex-shrink:0;white-space:nowrap}
.inline-add{display:flex;gap:8px;flex-wrap:wrap}
.inline-add input{flex:1 1 160px;min-width:0;padding:10px 12px;border:1.5px solid var(--line);
  border-radius:11px;font-size:.95rem;background:#fcfaf5}
.inline-add input:focus{outline:none;border-color:var(--teal);background:#fff}
.btn-primary.small{width:auto;margin:0;padding:10px 16px;font-size:.92rem;
  white-space:nowrap;flex-shrink:0}
@media(max-width:520px){
  .inline-add .btn-primary.small{flex:1 1 100%}
}
button.danger,button.ghost{padding:7px 12px;border-radius:9px;font-size:.85rem;
  font-weight:600;cursor:pointer;border:1.5px solid transparent}
button.danger{background:#fdeae6;color:#b03f29;border-color:#f3c9bf}
button.danger:hover{background:#fbdcd5}
button.ghost{background:#f1ece1;color:var(--ink)}
button.ghost:hover{background:#e8e1d3}
.code-box{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:1.1rem;
  background:#fff;border:1.5px dashed var(--teal);color:var(--teal);
  padding:12px 16px;border-radius:11px;text-align:center;font-weight:700;letter-spacing:.04em}
.hint{font-size:.82rem;color:var(--muted);margin:10px 0 0}
.hint code,.panel code{background:#efe8d8;padding:1px 6px;border-radius:5px;font-size:.85em}

/* ============================================================
   Batch 1 additions: player, actions, replies, RTL, toast
   ============================================================ */

.msg{position:relative}
/* the ⋯ options button under each message */
.time-row{display:flex;align-items:center;gap:6px;margin:3px 12px 0}
.msg.you .time-row{flex-direction:row-reverse}
.menu-btn{
  border:none;background:#ece4d4;color:var(--teal);cursor:pointer;
  width:26px;height:22px;border-radius:7px;font-size:1rem;line-height:1;
  display:inline-flex;align-items:center;justify-content:center;padding:0;
  flex-shrink:0;
}
.menu-btn:hover,.menu-btn:active{background:#ddd2bd}
.msg.you .menu-btn{background:rgba(255,255,255,.25);color:#fff}
.msg.you .menu-btn:hover{background:rgba(255,255,255,.4)}

/* full-screen overlay + bottom sheet menu (foolproof on mobile) */
.menu-overlay{
  position:fixed;inset:0;z-index:200;background:rgba(20,18,14,.45);
  display:flex;align-items:flex-end;justify-content:center;
  animation:ovIn .15s ease;
}
@keyframes ovIn{from{opacity:0}to{opacity:1}}
.menu-sheet{
  width:100%;max-width:460px;background:#fff;border-radius:18px 18px 0 0;
  padding:8px;box-shadow:0 -8px 30px rgba(0,0,0,.2);
  animation:sheetUp .2s cubic-bezier(.2,.8,.2,1);
}
@keyframes sheetUp{from{transform:translateY(100%)}to{transform:translateY(0)}}
.menu-sheet-head{
  text-align:center;font-size:.8rem;color:var(--muted);font-weight:600;
  padding:10px 0 8px;border-bottom:1px solid var(--line);margin-bottom:6px;
}
.menu-sheet button{
  display:flex;align-items:center;gap:14px;width:100%;padding:15px 16px;
  border:none;background:none;cursor:pointer;border-radius:11px;
  font-size:1.05rem;color:var(--ink);text-align:left;
}
.menu-sheet button:active{background:#f1ece1}
.menu-sheet button .ic{width:22px;text-align:center;font-size:1.15rem;opacity:.8}
.menu-sheet button[data-act="delete"]{color:#b03f29}
.menu-sheet .menu-cancel{
  justify-content:center;margin-top:6px;border-top:1px solid var(--line);
  border-radius:0 0 12px 12px;color:var(--muted);font-weight:600;
}
@media(min-width:600px){
  .menu-overlay{align-items:center}
  .menu-sheet{border-radius:16px;max-width:300px}
}

/* message being sent (optimistic) */
.msg.pending .bubble{opacity:.65}
.msg.pending .time{color:var(--muted);font-style:italic}
.msg.failed .bubble{opacity:1}
.msg.failed .time{color:var(--coral)}
.resend-btn{display:inline-block;margin-top:3px;padding:5px 12px;border:1px solid var(--coral);
  background:rgba(224,101,74,.08);color:var(--coral);border-radius:9px;font-size:.8rem;
  font-weight:600;cursor:pointer;align-self:flex-end}
.resend-btn:hover{background:rgba(224,101,74,.16)}

/* persistent mini audio player (keeps music playing across chats) — sits at the
   top of the chat, just under the header toolbar */
.mini-player{display:none;align-items:center;gap:10px;padding:8px 12px;
  background:#fff;border-bottom:1px solid var(--line);box-shadow:0 3px 12px rgba(35,33,28,.07);
  flex-shrink:0}
.mini-player.show{display:flex}
.mini-player .mp-icon{font-size:18px;flex-shrink:0}
.mini-player .mp-holder{flex:1;min-width:0}
.mini-player .mp-holder audio{width:100%;height:38px;display:block}
.mini-player .mp-close{flex-shrink:0;width:32px;height:32px;border:none;border-radius:50%;
  background:#ece4d4;color:var(--teal);cursor:pointer;font-size:14px}
.mini-player .mp-close:hover{background:#e2d9c5}

/* floating "scroll to latest" button */
.scroll-bottom-btn{position:absolute;right:16px;bottom:84px;z-index:40;width:46px;height:46px;
  border:none;border-radius:50%;background:#fff;color:var(--teal);cursor:pointer;
  box-shadow:0 3px 14px rgba(35,33,28,.22);font-size:22px;display:none;
  align-items:center;justify-content:center;transition:opacity .15s ease,bottom .18s ease}
.scroll-bottom-btn.show{display:flex}
/* when a reply is being composed, lift the button so it never covers the ✕ */
.chat.replying .scroll-bottom-btn{bottom:140px}
.scroll-bottom-btn .sb-badge{position:absolute;top:-4px;right:-4px;min-width:20px;height:20px;
  padding:0 5px;border-radius:10px;background:var(--coral);color:#fff;font-size:.72rem;
  font-weight:700;display:none;align-items:center;justify-content:center}
.scroll-bottom-btn.has-unread .sb-badge{display:flex}

/* keep message text selectable */
.bubble .text{user-select:text;-webkit-user-select:text}

/* deleted message */
.text.deleted{color:var(--muted);font-style:italic}
.msg.is-deleted .bubble{background:#f0ebe0!important;color:var(--muted);box-shadow:none}

/* edited tag already handled inline in .time text */

/* reply quote inside a bubble */
.reply-quote{
  display:block;border-left:3px solid var(--coral);padding:4px 8px;margin-bottom:6px;
  background:rgba(0,0,0,.04);border-radius:6px;font-size:.82rem;cursor:pointer;
  max-width:100%;overflow:hidden;
}
.msg.you .reply-quote{background:rgba(255,255,255,.16);border-left-color:#ffd9cf}
.reply-quote b{display:block;color:inherit;opacity:.9}
.reply-quote span{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;opacity:.75}

/* reply bar above composer */
.reply-bar{
  display:none;align-items:center;gap:10px;margin:0 16px;padding:8px 12px;
  background:#fff;border:1px solid var(--line);border-left:3px solid var(--coral);
  border-radius:10px;font-size:.85rem;
}
.reply-bar.show{display:flex}
.reply-bar-text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.reply-bar button{background:none;border:none;color:var(--coral);font-size:1.1rem;cursor:pointer}

/* editing mode highlight */
.composer.editing textarea{border-color:var(--coral);background:#fff7f4}
.composer.editing .send{background:var(--teal)}

/* audio / video player */
.player{display:flex;flex-direction:column;gap:6px;width:100%;max-width:280px}
.player audio{width:100%;height:40px;max-width:100%}
.player video{width:100%;max-width:100%;max-height:46vh;border-radius:10px;background:#000;display:block}
.player .dl{align-self:flex-end;text-decoration:none;font-size:1.1rem;
  color:inherit;opacity:.7;margin-top:-2px}
.player .dl:hover{opacity:1}
.player .fname{font-size:.72rem;opacity:.7;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.msg.you .player audio{filter:none}
/* keep media bubbles from overflowing the chat width on mobile */
.msg .bubble{max-width:100%}
.attach-img{max-width:min(240px,72vw)}

/* flash when jumping to a replied message */
.msg.flash .bubble{animation:flash 1.2s ease}
@keyframes flash{0%,100%{box-shadow:var(--shadow)}30%{box-shadow:0 0 0 3px var(--coral)}}

/* toast */
#toast{
  position:fixed;left:50%;bottom:90px;transform:translateX(-50%) translateY(20px);
  background:var(--ink);color:#fff;padding:9px 18px;border-radius:20px;font-size:.85rem;
  opacity:0;pointer-events:none;transition:opacity .2s,transform .2s;z-index:50;
}
#toast.show{opacity:.95;transform:translateX(-50%) translateY(0)}

/* RTL message text: align naturally */
.text[dir="rtl"]{text-align:right}

/* ---------- upload progress rows ---------- */
/* upload shown as a message bubble inside the chat */
.up-bubble{align-self:flex-end}
.up-bubble-inner{min-width:210px;max-width:300px}
.up-top{display:flex;justify-content:space-between;gap:8px;font-size:.82rem;margin-bottom:6px}
.up-name{font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;color:#fff}
.up-pct{color:#fff;font-weight:700;flex-shrink:0;opacity:.95}
.up-track{height:6px;background:rgba(255,255,255,.3);border-radius:6px;overflow:hidden}
.up-fill{height:100%;width:0;background:#fff;border-radius:6px;transition:width .2s}
.up-sub{font-size:.72rem;color:rgba(255,255,255,.85);margin-top:5px}
.up-bubble .up-dismiss{margin-top:8px;width:100%;padding:6px;border:1px solid rgba(255,255,255,.4);
  background:rgba(255,255,255,.15);color:#fff;border-radius:8px;font-size:.8rem;cursor:pointer}
.up-bubble .up-actions{display:flex;gap:8px;margin-top:8px}
.up-bubble .up-actions .up-resend{flex:1;margin-top:0;padding:7px;border:1px solid #fff;
  background:rgba(255,255,255,.92);color:var(--coral);border-radius:8px;font-size:.82rem;
  font-weight:700;cursor:pointer}
.up-bubble .up-actions .up-resend:hover{background:#fff}
.up-bubble .up-actions .up-dismiss{flex:1;margin-top:0}
.up-bubble .up-cancel{margin-top:8px;width:100%;padding:7px;border:1px solid rgba(255,255,255,.5);
  background:rgba(255,255,255,.16);color:#fff;border-radius:8px;font-size:.82rem;font-weight:600;cursor:pointer}
.up-bubble .up-cancel:hover{background:rgba(255,255,255,.28)}
.up-bubble .up-cancel:disabled{opacity:.6;cursor:default}

/* tiny corner chip shown from any chat while uploads run */
.up-chip{position:fixed;right:14px;bottom:78px;z-index:55;display:flex;align-items:center;gap:8px;
  padding:8px 14px;border:none;border-radius:22px;cursor:pointer;
  background:var(--teal);color:#fff;font-size:.82rem;font-weight:600;
  box-shadow:0 3px 14px rgba(35,33,28,.28)}
.up-chip:hover{background:#0c4f4b}
.up-chip-spin{width:13px;height:13px;border:2px solid rgba(255,255,255,.4);border-top-color:#fff;
  border-radius:50%;animation:up-chip-spin .7s linear infinite;flex-shrink:0}
@keyframes up-chip-spin{to{transform:rotate(360deg)}}

/* ============================================================
   Batch 2: private chats, find-user, search, receipts
   ============================================================ */

/* find-someone box at top of sidebar */
.side-search{padding:10px 12px;border-bottom:1px solid rgba(255,255,255,.12)}
.side-search input{
  width:100%;padding:9px 11px;border:none;border-radius:9px;font-size:.85rem;
  background:rgba(255,255,255,.14);color:#fff;
}
.side-search input::placeholder{color:rgba(255,255,255,.55)}
.side-search input:focus{outline:none;background:rgba(255,255,255,.22)}
.find-result{margin-top:8px}
.find-hit{
  display:flex;align-items:center;gap:9px;width:100%;padding:8px;border:none;cursor:pointer;
  background:rgba(255,255,255,.1);border-radius:9px;color:#fff;text-align:left;
}
.find-hit:hover{background:rgba(255,255,255,.18)}
.find-hit b{display:block;font-size:.9rem}
.find-hit .uid{font-size:.72rem;color:rgba(255,255,255,.6)}
.find-hit .start-chat{margin-left:auto;font-size:.75rem;color:#ffd9cf;white-space:nowrap}
.find-none{padding:8px;font-size:.78rem;color:rgba(255,255,255,.6)}

/* dm avatar + conversation rows */
.dm-label{margin-top:6px}
.dm-empty{padding:8px 12px;font-size:.78rem;color:rgba(255,255,255,.45)}
.room.dm{gap:9px}
.dm-avatar{
  width:26px;height:26px;border-radius:50%;background:var(--coral);color:#fff;
  display:inline-flex;align-items:center;justify-content:center;font-weight:700;
  font-size:.8rem;flex-shrink:0;text-transform:uppercase;
}
.room .room-name{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* unread badge */
.badge{
  background:var(--coral);color:#fff;font-size:.7rem;font-weight:700;
  min-width:18px;height:18px;border-radius:10px;padding:0 5px;
  display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;
}

/* read receipts */
.older-hint{text-align:center;font-size:.78rem;color:var(--muted);padding:10px;opacity:.8}

/* ===== message reactions ===== */
.reactions{display:flex;flex-wrap:wrap;gap:4px}
.msg.you .reactions{justify-content:flex-end}
.react-chip{display:inline-flex;align-items:center;gap:3px;padding:2px 8px;border-radius:12px;
  border:1px solid var(--line);background:#fff;cursor:pointer;font-size:.82rem;line-height:1.4;
  box-shadow:0 1px 2px rgba(35,33,28,.06)}
.react-chip .rc-emoji{font-size:.95rem}
.react-chip .rc-count{font-weight:600;color:var(--muted)}
.react-chip.mine{background:rgba(28,138,219,.12);border-color:rgba(28,138,219,.5)}
.react-chip.mine .rc-count{color:#1c8adb}
.react-chip:active{transform:scale(.94)}
.react-pick:active{transform:scale(1.2)}
@keyframes heart-pop{0%{opacity:0;transform:translate(-50%,-50%) scale(.4)}
  30%{opacity:1;transform:translate(-50%,-50%) scale(1.3)}
  100%{opacity:0;transform:translate(-50%,-140%) scale(1)}}

/* per-message comment button (channels) */
.cmt-row{}
.cmt-btn{border:none;background:none;cursor:pointer;font-size:.78rem;color:var(--muted);
  padding:2px 6px;border-radius:10px;font-weight:600}
.cmt-btn.has{color:#0d5c57}
.cmt-btn:active{transform:scale(.96)}
.cmt-send:disabled{opacity:.6;cursor:default}

/* other person's profile photo in the chat header */
.head-avatar{border:none;background:none;padding:0;margin:0;cursor:pointer;flex-shrink:0;
  width:38px;height:38px;border-radius:50%;overflow:hidden;line-height:0}
.head-avatar img{width:38px;height:38px;object-fit:cover;border-radius:50%;display:block}
.head-avatar-i{display:flex;align-items:center;justify-content:center;width:38px;height:38px;
  border-radius:50%;background:#d9cfba;color:#5c4a2f;font-weight:700;font-size:1rem}
.head-avatar:active{transform:scale(.94)}

/* channel photo in the sidebar list */
.room-avatar{width:24px;height:24px;border-radius:50%;object-fit:cover;flex-shrink:0}

/* ===== Stories bar ===== */
.stories-bar{display:flex;gap:12px;overflow-x:auto;padding:12px 14px;border-bottom:1px solid var(--line);
  scrollbar-width:none}
.stories-bar::-webkit-scrollbar{display:none}
.story-bubble{flex-shrink:0;border:none;background:none;cursor:pointer;display:flex;
  flex-direction:column;align-items:center;gap:4px;width:64px;padding:0}
.st-ring{position:relative;width:58px;height:58px;border-radius:50%;display:flex;align-items:center;
  justify-content:center;padding:3px}
.st-ring.unseen{background:linear-gradient(135deg,#e0654a,#c77b1e,#0d5c57)}
.st-ring.seen{background:#cfc7b6}
.st-ring.none{background:#cfc7b6}
.st-ring img,.st-ring .st-i{width:100%;height:100%;border-radius:50%;object-fit:cover;
  border:2px solid var(--paper);display:flex;align-items:center;justify-content:center;
  background:#d9cfba;color:#5c4a2f;font-weight:700;font-size:1.2rem}
.st-plus{position:absolute;bottom:-2px;right:-2px;width:20px;height:20px;border-radius:50%;
  background:var(--teal);color:#fff;font-size:15px;font-weight:700;display:flex;align-items:center;
  justify-content:center;border:2px solid var(--paper)}
.st-name{font-size:.7rem;color:var(--ink);max-width:64px;overflow:hidden;text-overflow:ellipsis;
  white-space:nowrap;text-align:center}

/* red activity dot on the activity bell */
.notif-dot{position:absolute;top:2px;right:2px;min-width:16px;height:16px;padding:0 4px;
  border-radius:9px;background:#e0654a;color:#fff;font-size:.62rem;font-weight:700;
  display:flex;align-items:center;justify-content:center;line-height:1;border:2px solid #0d5c57}
.act-item:hover{background:#efe9dd !important}

/* "HD" hint on thumbnails — tap loads the full-resolution image */
.img-wrap{position:relative}
.img-hd{position:absolute;top:8px;left:8px;background:rgba(20,18,14,.62);color:#fff;
  font-size:.62rem;font-weight:800;letter-spacing:.04em;padding:2px 6px;border-radius:6px;
  pointer-events:none}

/* ===== multiple message selection ===== */
.sel-bar{position:fixed;top:0;left:0;right:0;z-index:2147483646;display:flex;align-items:center;gap:12px;
  padding:12px 14px;padding-top:calc(12px + env(safe-area-inset-top,0px));
  background:var(--teal);color:#fff;box-shadow:0 2px 12px rgba(0,0,0,.2)}
.sel-bar .sel-x{width:34px;height:34px;border:none;border-radius:50%;cursor:pointer;
  background:rgba(255,255,255,.18);color:#fff;font-size:16px;flex-shrink:0}
.sel-bar .sel-count{font-weight:700;font-size:1rem;flex:1}
.sel-bar .sel-more{border:none;border-radius:9px;cursor:pointer;padding:10px 16px;
  background:rgba(255,255,255,.2);color:#fff;font-size:.92rem;font-weight:700;white-space:nowrap}
.sel-bar .sel-more:hover{background:rgba(255,255,255,.32)}
/* highlight selected messages + show a tick */
.messages.selecting .msg{cursor:pointer}
.messages.selecting .msg.selected{outline:2.5px solid var(--teal);outline-offset:1px;border-radius:14px}
.messages.selecting .msg.selected::after{content:'✓';position:absolute;top:-8px;right:-8px;
  width:22px;height:22px;border-radius:50%;background:var(--teal);color:#fff;font-size:13px;
  display:flex;align-items:center;justify-content:center;box-shadow:0 1px 4px rgba(0,0,0,.3)}
.messages.selecting .msg{position:relative}
/* nudge the message list down a little so the bar doesn't cover the top row */
body.select-mode .chat-head{visibility:hidden}

/* "X is typing…" line under the chat header */
.typing-line{font-size:.72rem;font-weight:500;color:#1c9c6b;margin-top:1px;display:flex;align-items:center;gap:5px}
.typing-dots{display:inline-flex;gap:2px}
.typing-dots i{width:4px;height:4px;border-radius:50%;background:#1c9c6b;display:inline-block;
  animation:typing-bounce 1.1s infinite ease-in-out}
.typing-dots i:nth-child(2){animation-delay:.15s}
.typing-dots i:nth-child(3){animation-delay:.3s}
@keyframes typing-bounce{0%,60%,100%{transform:translateY(0);opacity:.5}30%{transform:translateY(-3px);opacity:1}}

/* "Forwarded" label at the top of a forwarded message */
.fwd-label{font-size:.74rem;font-style:italic;opacity:.7;margin-bottom:3px;
  display:flex;align-items:center;gap:3px}
.msg.you .fwd-label{color:rgba(255,255,255,.85)}
.msg.them .fwd-label{color:var(--muted)}

/* Read-receipt checkmarks under your own messages.
   Sent/delivered = a clear medium grey; Seen = a strong, easy-to-see blue. */
.rcpt{font-size:.92rem;color:#9a9488;margin-left:3px;font-weight:700;letter-spacing:-1px}
.msg.you .rcpt{color:#8a857a}
.rcpt.seen{color:#1c8adb}
.msg.you .rcpt.seen{color:#1c8adb}

/* search overlay */
.search-overlay{
  position:fixed;inset:0;z-index:300;background:rgba(20,18,14,.5);
  display:flex;align-items:flex-start;justify-content:center;padding:8vh 12px 12px;
}
.search-panel{
  width:100%;max-width:520px;background:#fff;border-radius:16px;overflow:hidden;
  box-shadow:0 20px 50px rgba(0,0,0,.3);display:flex;flex-direction:column;max-height:80vh;
}
.search-top{display:flex;gap:8px;padding:12px;border-bottom:1px solid var(--line)}
.search-top input{
  flex:1;padding:11px 14px;border:1.5px solid var(--line);border-radius:11px;font-size:1rem;
  background:#fcfaf5;
}
.search-top input:focus{outline:none;border-color:var(--teal);background:#fff}
.search-top button{background:none;border:none;font-size:1.5rem;color:var(--muted);cursor:pointer;width:42px}
.search-results{overflow-y:auto;padding:8px}
.sr{
  display:block;width:100%;text-align:left;border:none;background:none;cursor:pointer;
  padding:11px 12px;border-radius:10px;border-bottom:1px solid var(--line);
}
.sr:hover{background:#f6f1e7}
.sr-top{display:flex;justify-content:space-between;font-size:.78rem;color:var(--teal);margin-bottom:3px}
.sr-top span{color:var(--muted)}
.sr-body{font-size:.9rem;color:var(--ink);line-height:1.35}

/* active dm highlight already covered by .room.active */

/* admin: channel membership */
.member-block{padding:14px 0;border-bottom:1px solid var(--line)}
.member-block:last-child{border-bottom:none}
.member-head{font-weight:700;color:var(--teal);margin-bottom:8px}
.member-grid{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:10px}
.member-chk{
  display:flex;align-items:center;gap:6px;padding:7px 11px;background:#f6f1e7;
  border:1px solid var(--line);border-radius:9px;font-size:.88rem;cursor:pointer;
}
.member-chk.is-admin{opacity:.6;cursor:default}
.member-chk input{accent-color:var(--teal)}

/* admin: search boxes */
.admin-search{width:100%;padding:11px 13px;margin:0 0 14px;border:1.5px solid var(--line);
  border-radius:11px;font-size:.95rem;background:#fcfaf5;color:var(--ink);box-sizing:border-box}
.admin-search:focus{outline:none;border-color:var(--teal);background:#fff}
.chk-search{margin-bottom:10px}
/* the user-ID badge in the membership checkboxes (now leads: "1024 # Name") */
.uid{font-size:.78rem;color:var(--teal);font-weight:700;margin-right:2px}
.member-chk.is-admin .uid{color:rgba(15,94,90,.6)}
.uname{font-size:.78rem;color:var(--muted);font-weight:600;margin-left:2px}
/* admin: phone number under a member */
.phone-line{font-size:.82rem;color:var(--muted);margin-top:3px;font-weight:600}
.phone-tag{font-size:.8rem;color:var(--muted);margin-left:8px}
/* admin: approval mode + pending */
.approval-form{display:flex;flex-direction:column;gap:10px}
.approval-state{font-size:.9rem;color:var(--ink);line-height:1.5}
.approval-form .small-btn{align-self:flex-start;white-space:normal}
.pending-panel{border:2px solid #f0c98a;background:#fdf6e8}
.pending-panel h2{color:#b9791b}

/* admin: invite code panel */
.panel-note{font-size:.85rem;color:var(--muted);margin:0 0 12px;line-height:1.5}
.invite-form{display:flex;gap:8px;flex-wrap:wrap}
.invite-input{flex:1 1 180px;min-width:0;padding:10px 12px;border:1.5px solid var(--line);
  border-radius:11px;font-size:1rem;background:#fcfaf5;color:var(--ink);font-weight:600;
  letter-spacing:.5px}
.invite-input:focus{outline:none;border-color:var(--teal);background:#fff}
@media(max-width:520px){ .invite-form .btn-primary.small{flex:1 1 100%} }

/* admin: channel rows — stack cleanly, no overlap */
.chan-row{display:flex;flex-direction:column;align-items:stretch;gap:10px;
  padding:14px 0;border-bottom:1px solid var(--line)}
.chan-row:last-child{border-bottom:none}
.rename-form{display:flex;align-items:center;gap:8px;width:100%}
.rename-form .hashmark{color:var(--muted);font-weight:700;flex-shrink:0}
.rename-input{flex:1 1 auto;min-width:0;padding:9px 11px;border:1.5px solid var(--line);
  border-radius:9px;font-size:.95rem;background:#fcfaf5;color:var(--ink)}
.rename-input:focus{outline:none;border-color:var(--teal);background:#fff}
.small-btn{padding:9px 14px;border-radius:8px;font-size:.88rem;border:none;cursor:pointer;
  background:#e6ddcb;color:var(--teal);font-weight:600;white-space:nowrap;flex-shrink:0}
.small-btn:hover{background:#dccdb2}
.chan-row .policy-form{width:100%;margin:0}
.chan-row .policy-form .small-btn{width:100%;text-align:center;padding:11px 14px;
  background:#f1ece1;white-space:normal}
.chan-row > form:last-child{width:100%}
.chan-row > form:last-child .danger{width:100%;padding:10px;text-align:center}

/* AI-shared message block (icon + question + answer). Shown when a family member
   taps "Send to chat" from the Ask AI panel. Works inside both my own (you) and
   others' (them) bubbles. */
.ai-msg{display:flex;flex-direction:column;gap:6px}
.ai-msg-head{display:flex;align-items:center;gap:6px;margin-bottom:1px}
.ai-msg-badge{width:20px;height:20px;border-radius:50%;background:rgba(255,255,255,.22);
  display:inline-flex;align-items:center;justify-content:center;font-size:12px;flex:0 0 auto}
.msg.them .ai-msg-badge{background:#eef3ec}
.ai-msg-title{font-size:.72rem;font-weight:700;letter-spacing:.04em;opacity:.85;text-transform:uppercase}
.ai-msg-q{font-weight:600;opacity:.9;line-height:1.4}
.ai-msg-q::before{content:"\201C"}
.ai-msg-q::after{content:"\201D"}
.ai-msg-a{line-height:1.5;padding-top:4px;border-top:1px solid rgba(255,255,255,.18)}
.msg.them .ai-msg-a{border-top-color:rgba(0,0,0,.10)}
