
:root{
  --bg:#1f2937;
  --bg-accent:#111827;
  --panel:#1f2937;
  --card:#273449;
  --border:#334155;
  --text:#e5e7eb;
  --muted:#9ca3af;
  --primary:#2563eb;
  --danger:#ef4444;
  --shadow: 0 10px 30px rgba(0,0,0,.25);
  --radius: 16px;
  --font: system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;
}

:root[data-theme="dark"]{
  --bg:#0b1220;
  --bg-accent:#050814;
  --panel:#111827;
  --card:#0f172a;
  --border:#1f2a44;
  --text:#e5e7eb;
  --muted:#9ca3af;
  --primary:#2563eb;
  --danger:#ef4444;
}

:root[data-theme="medium"]{
  --bg:#1f2937;
  --bg-accent:#111827;
  --panel:#243041;
  --card:#2c3a4f;
  --border:#425168;
  --text:#edf2f7;
  --muted:#b8c2cf;
  --primary:#3b82f6;
  --danger:#ef4444;
}

:root[data-theme="light"]{
  --bg:#f4f7fb;
  --bg-accent:#e7edf6;
  --panel:#ffffff;
  --card:#ffffff;
  --border:#d8e0ec;
  --text:#0f172a;
  --muted:#64748b;
  --primary:#2563eb;
  --danger:#dc2626;
}
*{box-sizing:border-box}
html,body{height:100%; overflow:hidden}
body{
  margin:0;
  background:linear-gradient(135deg, var(--bg), var(--bg-accent));
  color:var(--text);
  font-family:var(--font);
}
a{color:inherit}
.hidden{display:none !important}

.app{
  display:grid;
  grid-template-columns: 360px 1fr;
  height:100vh;
  height:100dvh;
}
.sidebar{
  border-right:1px solid var(--border);
  background:color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
  display:flex;
  flex-direction:column;
  padding:12px;
  gap:12px;
}
.brand{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:var(--radius);
  background:color-mix(in srgb, var(--card) 88%, transparent);
}
.brand-title{font-weight:700; letter-spacing:.2px}
.brand-actions{display:flex; gap:8px}
.panel{
  border:1px solid var(--border);
  border-radius:var(--radius);
  background:color-mix(in srgb, var(--card) 72%, transparent);
  padding:12px;
  box-shadow:var(--shadow);
}
.tabs{display:flex; gap:8px; margin-bottom:10px}
.tab{
  flex:1;
  padding:10px;
  border-radius:12px;
  border:1px solid var(--border);
  background:transparent;
  color:var(--text);
  cursor:pointer;
}
.tab.active{background:color-mix(in srgb, var(--primary) 20%, transparent); border-color:color-mix(in srgb, var(--primary) 40%, transparent)}
.form{display:flex; flex-direction:column; gap:10px}
input,select,textarea{
  padding:12px;
  border-radius:12px;
  border:1px solid var(--border);
  background:color-mix(in srgb, var(--panel) 72%, transparent);
  color:var(--text);
  outline:none;
}
.password-wrap{
  position:relative;
  display:flex;
  align-items:center;
}
.password-wrap input{
  width:100%;
  padding-right:44px; /* space for eye */
}
.eye-btn{
  position:absolute;
  right:8px;
  top:50%;
  transform:translateY(-50%);
  width:34px;
  height:34px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:10px;
  background:color-mix(in srgb, var(--text) 8%, transparent);
}
.eye-btn:active{ transform:translateY(-50%) scale(.98); }

input::placeholder{color:rgba(156,163,175,.7)}
.btn{
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background:color-mix(in srgb, var(--panel) 72%, transparent);
  color:var(--text);
  cursor:pointer;

  touch-action: manipulation;

  -webkit-tap-highlight-color: transparent;
}
.btn.primary{background:color-mix(in srgb, var(--primary) 82%, transparent); border-color:color-mix(in srgb, var(--primary) 82%, transparent)}
.btn.danger{background:color-mix(in srgb, var(--danger) 85%, transparent); border-color:color-mix(in srgb, var(--danger) 85%, transparent)}
.icon-btn{
  border:1px solid var(--border);
  background:color-mix(in srgb, var(--panel) 72%, transparent);
  border-radius:12px;
  padding:8px 10px;
  color:var(--text);
  cursor:pointer;

  touch-action: manipulation;

  -webkit-tap-highlight-color: transparent;
}
.error{
  margin-top:10px;
  padding:10px;
  border-radius:12px;
  border:1px solid color-mix(in srgb, var(--danger) 50%, transparent);
  background:color-mix(in srgb, var(--danger) 15%, transparent);
}
.hint{color:var(--muted); font-size:12px}
.muted{color:var(--muted); font-size:12px}

.search-row{display:flex; gap:8px; margin-bottom:10px}
.list{
  display:flex;
  flex-direction:column;
  gap:8px;
  max-height: calc(100vh - 360px);
  overflow:auto;
  padding-right:4px;
}
.item{
  display:flex;
  gap:10px;
  align-items:center;
  padding:10px;
  border:1px solid var(--border);
  border-radius:14px;
  cursor:pointer;
  background:color-mix(in srgb, var(--panel) 45%, transparent);
}
.item:hover{background:color-mix(in srgb, var(--panel) 72%, transparent)}
.item.active{border-color:color-mix(in srgb, var(--primary) 60%, transparent); background:rgba(37,99,235,.12)}
.avatar{
  width:40px;
  height:40px;
  border-radius:14px;
  background:rgba(37,99,235,.25);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:700;
}
.item-title{font-weight:600}
.item-sub{color:var(--muted); font-size:12px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:220px}
.sidebar-footer{display:flex; gap:8px; margin-top:10px; flex-wrap:wrap}

.main{
  display:flex;
  flex-direction:column;
  min-height:0;
}
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  background:rgba(17,24,39,.85);
  backdrop-filter: blur(10px);
}
.topbar-left{display:flex; align-items:center; gap:10px; min-width:0}
.back-btn{display:none}
.msg.pending{opacity:.7}

.chat-title{display:flex; flex-direction:column}
.topbar-actions{display:flex; gap:8px}

.content{
  flex:1;
  position:relative;
  padding:14px;
  overflow:hidden;
  display:flex;
  flex-direction:column;
  min-height:0;
}
.empty{
  height:100%;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:10px;
  border:1px dashed rgba(31,42,68,.8);
  border-radius:var(--radius);
  background:rgba(15,23,42,.35);
}
.empty-title{font-size:22px; font-weight:800}

.chat{flex:1; min-height:0; display:flex; flex-direction:column}
.messages{
  flex:1;
  overflow:auto;
  padding:6px;
  min-height:0;
  border:1px solid var(--border);
  border-radius:var(--radius);
  background:rgba(15,23,42,.35);
}
.msg-row{display:flex; margin:10px 0}
.msg{
  max-width:min(680px, 92%);
  padding:10px 12px;
  border-radius:16px;
  border:1px solid var(--border);
  background:rgba(17,24,39,.7);
  box-shadow: 0 10px 20px rgba(0,0,0,.12);
}
.msg.me{
  background:rgba(37,99,235,.22);
  border-color:rgba(37,99,235,.3);
}
.msg-meta{margin-top:6px; font-size:11px; color:var(--muted)}
.msg a{color:#93c5fd; text-decoration:none}
.msg a:hover{text-decoration:underline}
.composer{
  display:flex;
  gap:8px;
  padding-top:10px;

  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
/* Multiline message composer */
#messageInput{
  flex:1;
  min-height:40px;
  max-height:140px;
  resize:none;
  overflow:auto;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--border);
  background:rgba(17,24,39,.7);
  color:var(--text);
  outline:none;
  line-height:1.25;
}
#messageInput:focus{ border-color: rgba(96,165,250,.65); }
.composer{ align-items:flex-end; }

.typing{margin-top:6px; color:var(--muted); font-size:12px}

.modal{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background:rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
  z-index: 1000;
}
.modal-card{
  width:min(560px, 94vw);
  border-radius:22px;
  border:1px solid var(--border);
  background:rgba(15,23,42,.95);
  box-shadow: var(--shadow);
  overflow:hidden;
}
.modal-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:12px 14px;
  border-bottom:1px solid var(--border);
}
.modal-body{padding:14px; display:flex; flex-direction:column; gap:10px}

.modal{
  padding:16px;
  overflow-y:auto;
}
.modal-card{
  max-height:min(90vh, calc(100dvh - 32px));
  display:flex;
  flex-direction:column;
}
.modal-body{
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}
@media (max-width: 920px){
  .modal{
    align-items:flex-start;
    padding:12px;
  }
  .modal-card{
    width:min(100%, 94vw);
    max-height:calc(100dvh - 24px);
    margin:auto 0;
  }
}

.call{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background:rgba(0,0,0,.7);
}
.call-card{
  width:min(820px, 96vw);
  border-radius:24px;
  border:1px solid var(--border);
  background:rgba(15,23,42,.95);
  box-shadow: var(--shadow);
  overflow:hidden;
  padding:14px;
  display:flex;
  flex-direction:column;
  gap:12px;
}
.call-title{font-weight:800}
.call-media{
  display:grid;
  grid-template-columns: 1fr 260px;
  gap:12px;
}
#remoteVideo{
  width:100%;
  border-radius:18px;
  border:1px solid var(--border);
  background:black;
  min-height:360px;
}
#localVideo{
  width:100%;
  border-radius:18px;
  border:1px solid var(--border);
  background:black;
  min-height:160px;
}
.call-actions{display:flex; justify-content:flex-end}

@media (max-width: 920px){
  /* Ensure no horizontal overflow on mobile */
  .app{ grid-template-columns: 1fr !important; width:100vw; max-width:100vw; overflow-x:hidden; }
  .sidebar, .main{ width:100%; max-width:100vw; min-width:0; }
  .content, .messages, .composer{ max-width:100vw; }
  .msg-row, .msg{ max-width:100%; }

  .app{grid-template-columns: 1fr}
  /* Mobile: WhatsApp-like navigation (list OR chat) */
  body:not(.chat-mode) .main{display:none}
  body.chat-mode .main{display:flex}
  .sidebar{position:relative; border-right:none; border-bottom:1px solid var(--border)}
  .list{max-height: 320px}
  .call-media{grid-template-columns: 1fr}
  #localVideo{min-height:200px}
}


/* Branding */
.brand-left{display:flex; align-items:center; gap:10px}
.brand-logo{width:28px; height:28px; display:block}
.sidebar-footer{
  margin-top: 10px;
  padding: 8px 6px 0;
  display:flex;
  justify-content:center;
  gap:10px;
  flex-wrap:wrap;
  color: var(--muted);
  font-size: 12px;
}
.sidebar-footer a{
  color: var(--muted);
  text-decoration:none;
}
.sidebar-footer a:hover{color: var(--text); text-decoration:underline}

/* Splash screen */
.splash{
  position:fixed;
  inset:0;
  z-index:9999;
  background: radial-gradient(1200px 600px at 20% 10%, rgba(37,99,235,.25), transparent 55%),
              radial-gradient(900px 500px at 90% 30%, rgba(34,197,94,.22), transparent 55%),
              rgba(2,6,23,.92);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 18px;
}
.splash-card{
  width:min(520px, 94vw);
  border:1px solid var(--border);
  border-radius: 22px;
  background: rgba(15,23,42,.65);
  box-shadow: var(--shadow);
  padding: 22px 18px;
  text-align:center;
}
.splash-logo{width:64px; height:64px; margin: 0 auto 10px; display:block}
.splash-title{font-size: 20px; font-weight: 800; margin-bottom: 6px}
.splash-sub{opacity:.9; line-height:1.55}
.splash-hint{margin-top: 14px; opacity: .7; font-size: 12px}
.splash.hide{animation: splashFade .45s ease forwards}
@keyframes splashFade{to{opacity:0; visibility:hidden}}


/* Footer legal links in sidebar */
.sidebar-legal{
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.4;
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  opacity: .9;
}
.sidebar-legal a{
  color: inherit;
  text-decoration: none;
}
.sidebar-legal a:hover{ text-decoration: underline; }
.sidebar-legal .sep{ opacity: .7; }


@media (max-width: 920px){
  body.chat-mode .sidebar{display:none}
  /* Mobile (chat): keep a single header (topbar) */
  body.chat-mode .topbar{display:flex}
  body.chat-mode .content{padding:10px}
  body.chat-mode .back-btn{display:inline-flex}
  body.chat-mode .topbar-actions{gap:6px}
}





/* Message deletion */
.msg-meta{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.msg-del{
  border:1px solid var(--border);
  background:color-mix(in srgb, var(--panel) 45%, transparent);
  color:var(--text);
  border-radius:10px;
  padding:2px 8px;
  font-size:12px;
  cursor:pointer;
}
.msg-del:active{transform:scale(.98)}

.msg-row.selected .msg{
  outline:2px solid rgba(59,130,246,.7);
}

.delete-toolbar{
  position:fixed;
  left:12px;
  right:12px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  z-index: 50;
}
.delete-toolbar-inner{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--border);
  background:rgba(17,24,39,.88);
  box-shadow: 0 10px 24px rgba(0,0,0,.25);
}
.delete-count{font-size:13px; color:var(--text)}
.delete-actions{display:flex; gap:8px}

/* Slightly calmer splash hint */
.splash-hint{opacity:.85}


/* Alerts enable banner (mobile-friendly) */
.alerts-banner{
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 60;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(17,24,39,0.96);
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.alerts-banner .alerts-banner-text{
  font-size: 13px;
  line-height: 1.25;
}
.btn.small{
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 10px;
}
@media (min-width: 920px){
  .alerts-banner{ left: auto; right: 16px; width: 420px; }
}


body.modal-open{ overflow:hidden; }

/* Fullscreen modal on mobile for Status / Groups */
@media (max-width: 900px){
  .modal.modal--mobile-full{
    align-items: stretch;
    justify-content: stretch;
    background: rgba(0,0,0,.70);
  }
  .modal.modal--mobile-full .modal-card{
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    box-shadow: none;
    display:flex;
    flex-direction:column;
  }
  .modal.modal--mobile-full .modal-body{
    flex:1;
    overflow:auto;
    -webkit-overflow-scrolling: touch;
  }
}


/* Emoji picker */
.emoji-panel{
  position:fixed;
  left:0; right:0;
  bottom:56px;
  max-height:42vh;
  overflow:auto;
  background:rgba(17,24,39,.98);
  border-top:1px solid rgba(255,255,255,.08);
  padding:10px;
  display:grid;
  grid-template-columns:repeat(8, 1fr);
  gap:6px;
  z-index:1200;
}
@media (min-width: 820px){
  .emoji-panel{
    left:auto; right:auto;
    width:360px;
    bottom:74px;
    border:1px solid rgba(255,255,255,.12);
    border-radius:14px;
    margin-left:12px;
  }
}
.emoji-panel.hidden{display:none}
.emoji-btn{
  font-size:22px;
  line-height:1;
  padding:8px 0;
  border-radius:10px;
  border:1px solid rgba(255,255,255,.06);
  background:rgba(255,255,255,.03);
  cursor:pointer;
}
.emoji-btn:active{transform:scale(0.97)}

/* WhatsApp-like Status viewer */
.status-list{display:flex;flex-direction:column;gap:10px;margin-top:12px}
.status-item{
  display:flex; align-items:center; gap:12px;
  width:100%;
  padding:10px;
  background:rgba(255,255,255,.03);
  border:1px solid rgba(255,255,255,.06);
  border-radius:14px;
  cursor:pointer;
  text-align:left;
}
.status-avatar{
  width:46px; height:46px;
  border-radius:50%;
  position:relative;
  flex:0 0 auto;
  display:grid; place-items:center;
  background:color-mix(in srgb, var(--text) 8%, transparent);
}
.status-ring{
  position:absolute; inset:-2px;
  border-radius:50%;
  border:2px solid rgba(37,99,235,.85);
}
.status-initial{font-weight:700}
.status-meta{display:flex;flex-direction:column;gap:2px;min-width:0}
.status-name{font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.story-viewer{
  position:fixed; inset:0;
  background:#000;
  z-index:2000;
  display:flex;
  flex-direction:column;
}
.story-viewer.hidden{display:none}
.story-top{
  padding:10px 10px 0 10px;
}
.story-progress{
  display:flex;
  gap:2px;
  width:100%;
}
.story-seg{
  flex:1 1 auto;
  height:2px;
  background:rgba(255,255,255,.25);
  border-radius:999px;
  overflow:hidden;
}
.story-seg-fill{
  height:100%;
  width:0%;
  background:#fff;
}
.story-header{
  display:flex;
  align-items:center;
  gap:10px;
  margin-top:10px;
  color:#fff;
}
.story-user{
  font-weight:700;
  max-width:60vw;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
}
.story-time{opacity:.75;font-size:.92em}
.story-actions{margin-left:auto;display:flex;gap:8px;align-items:center}
.story-sound{
  background:rgba(255,255,255,.1);
  border:1px solid rgba(255,255,255,.12);
  color:#fff;
  border-radius:12px;
  width:40px;height:34px;
}
.story-sound.hidden{display:none}
.story-close{
  background:rgba(255,255,255,.1);
  border:1px solid rgba(255,255,255,.12);
  color:#fff;
  border-radius:12px;
  width:40px;height:34px;
}
.story-content{
  touch-action:none;
  position:relative;
  flex:1 1 auto;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.story-media{
  max-width:100%;
  max-height:100%;
  object-fit:contain;
}
.story-audio{
  width:min(92vw, 520px);
}
.story-text{
  padding:22px;
  font-size:24px;
  line-height:1.25;
  text-align:center;
  color:#fff;
  max-width:92vw;
  word-break:break-word;
}
.story-tap{
  position:absolute;
  top:0; bottom:0;
  width:40%;
}
.story-tap-left{left:0}
.story-tap-right{right:0}
.story-hint{
  position:absolute;
  bottom:18px;
  left:50%;
  transform:translateX(-50%);
  color:rgba(255,255,255,.75);
  font-size:12px;
  padding:6px 10px;
  border-radius:999px;
  background:rgba(0,0,0,.35);
  border:1px solid rgba(255,255,255,.10);
}


/* --- Mobile width safety (avoid horizontal scroll) --- */
html, body { max-width: 100%; overflow-x: hidden; }
* { box-sizing: border-box; }
.messages { overflow-x: hidden; }
.msg, .item-title, .item-sub { overflow-wrap: anywhere; word-break: break-word; }
.composer { width: 100%; }
#messageInput { min-width: 0; }

/* --- Avatars --- */
.avatar{
  width:40px;
  height:40px;
  border-radius: 999px;
  background: rgba(148,163,184,.18);
  border: 1px solid rgba(148,163,184,.22);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:700;
  flex:0 0 auto;
  overflow:hidden;
  user-select:none;
}
.avatar--lg{ width:42px; height:42px; }
.avatar.square{ border-radius: 12px; }
.avatar img{ width:100%; height:100%; object-fit:cover; display:block; }
.avatar .initials{ font-size:14px; letter-spacing:.5px; }

/* --- Avatar cropper (WhatsApp-like) --- */
.cropper{
  display:flex;
  flex-direction:column;
  gap:12px;
}
.cropper-top{
  display:flex;
  gap:12px;
  align-items:center;
  flex-wrap:wrap;
}
.cropper-viewport{
  width:min(280px, 80vw);
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  border:1px solid var(--border);
  background: rgba(15,23,42,.35);
  overflow:hidden;
  position:relative;
  touch-action:none;
}
.cropper-viewport.round{
  border-radius: 999px;
}
.cropper-viewport img{
  position:absolute;
  left:50%;
  top:50%;
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
  will-change: transform;
  max-width:none;
  max-height:none;
  user-select:none;
  -webkit-user-drag:none;
  pointer-events:none;
}
.cropper-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  flex-wrap:wrap;
}



/* Admin delete button in conversation list */
.item .item-actions{margin-left:auto;display:flex;gap:6px;align-items:center}
.item .item-del{border:1px solid #233253;background:#0f1a33;color:#e5e7eb;border-radius:10px;padding:6px 8px;cursor:pointer}
.item .item-del:active{transform:scale(0.98)}

/* Status feed avatar image */
.status-avatar img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;border-radius:999px}
.status-avatar .status-initial{position:relative;z-index:1}

/* Call modal */
.call-modal{display:flex;flex-direction:column;gap:10px}
.call-title{font-weight:900;font-size:18px}
.call-sub{color:#cbd5e1}
.call-actions{display:flex;gap:8px;justify-content:flex-end;flex-wrap:wrap}
.btn.danger{background:#b91c1c;border-color:#7f1d1d}

/* Modal without close button */
.modal.modal--no-close .modal-head{justify-content:space-between}

.chat-mobile-actions{margin-left:auto;display:flex;gap:8px;align-items:center}
.topbar-actions{display:flex;gap:8px;align-items:center}


.icon-btn.disabled{opacity:.5; cursor:not-allowed}
.icon-btn:disabled{opacity:.5; cursor:not-allowed}

@media (max-width: 920px){
  body.chat-mode .topbar{display:flex}
}



/* Splash close button (manual fallback) */
.splash-card{ position: relative; }
.splash-close{
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.25);
  color: rgba(255,255,255,.9);
  font-size: 20px;
  line-height: 28px;
  cursor: pointer;
}
.splash-close:active{ transform: scale(.98); }


/* Responsive search row (Android 11 small screens): keep Search + buttons inside frame */
.search-row{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
}
.search-row input{
  flex: 1 1 220px;
  min-width: 0; /* prevent overflow in flex containers */
}
.search-row .btn{
  flex: 0 0 auto;
  white-space: nowrap;
}
@media (max-width: 420px){
  .search-row{
    gap:8px;
  }
  .search-row input{
    flex: 1 1 100%;
  }
  /* Put buttons on the next line, side by side */
  #btnNewChat{
    flex: 1 1 0;
  }
}


.msg-text-original{
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.45;
  opacity: .75;
  padding-top: 6px;
  border-top: 1px dashed rgba(255,255,255,.12);
}


.topbar-actions{
  display:flex;
  align-items:center;
  gap:8px;
}

.call-modal{
  display:flex;
  flex-direction:column;
  gap:14px;
  min-height:56vh;
}
.call-head{
  display:flex;
  flex-direction:column;
  gap:4px;
}
.call-title{
  font-size:1.1rem;
  font-weight:800;
}
.call-sub{
  color:var(--muted);
}

.call-stage{
  position:relative;
  min-height:320px;
  border:1px solid var(--border);
  border-radius:18px;
  overflow:hidden;
  background:linear-gradient(180deg, rgba(15,23,42,.92), rgba(2,6,23,.96));
  display:flex;
  align-items:center;
  justify-content:center;
}
.call-stage video{
  width:100%;
  height:100%;
  object-fit:cover;
  background:#000;
}
.call-stage.audio-only #callRemoteVideo{
  display:none;
}
.call-remote-fallback{
  position:absolute;
  width:92px;
  height:92px;
  border-radius:999px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:2rem;
  font-weight:800;
  background:rgba(255,255,255,.12);
  color:#fff;
  border:1px solid rgba(255,255,255,.14);
  box-shadow:var(--shadow);
}
.call-local-preview{
  position:absolute;
  right:14px;
  bottom:14px;
  width:116px;
  height:154px;
  border-radius:16px;
  overflow:hidden;
  border:1px solid rgba(255,255,255,.16);
  background:#000;
  box-shadow:var(--shadow);
}
.call-local-preview video{
  width:100%;
  height:100%;
  object-fit:cover;
}
.call-actions{
  display:flex;
  gap:10px;
  justify-content:center;
  flex-wrap:wrap;
}
.call-actions .btn.active{
  border-color:color-mix(in srgb, var(--danger) 55%, transparent);
}

@media (max-width: 640px){
  .call-modal{
    min-height:72vh;
  }
  .call-stage{
    min-height:54vh;
  }
  .call-local-preview{
    width:92px;
    height:124px;
    right:10px;
    bottom:10px;
  }
  .call-actions{
    position:sticky;
    bottom:0;
    padding-top:8px;
    background:linear-gradient(180deg, transparent, color-mix(in srgb, var(--panel) 92%, transparent) 24%);
  }
}


/* Accessibility and usability refinements */
:root{ --accent: var(--primary); }
html{ font-size:16px; }
button, .btn, .icon-btn, input, select, textarea{ font: inherit; }
button, .btn, .icon-btn{ min-height:44px; min-width:44px; }
input, select, textarea{ min-height:44px; }
textarea{ resize: vertical; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible{
  outline:3px solid color-mix(in srgb, var(--primary) 72%, white);
  outline-offset:3px;
}
.btn:disabled, .btn.disabled, button:disabled{
  opacity:.62;
  cursor:not-allowed;
}
.sr-only{
  position:absolute !important;
  width:1px !important;
  height:1px !important;
  padding:0 !important;
  margin:-1px !important;
  overflow:hidden !important;
  clip:rect(0,0,0,0) !important;
  white-space:nowrap !important;
  border:0 !important;
}
.modal{ padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.modal-card{ max-height: min(88dvh, 760px); overflow:auto; }
.msg-text, .msg-text-original, .item-title, .item-sub{ overflow-wrap:anywhere; }
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration:.01ms !important;
    animation-iteration-count:1 !important;
    scroll-behavior:auto !important;
    transition-duration:.01ms !important;
  }
}


/* Light theme readability fixes for conversations and call UI */
:root[data-theme="light"] .topbar{
  background:rgba(255,255,255,.94);
  color:#0f172a;
}
:root[data-theme="light"] .empty,
:root[data-theme="light"] .messages{
  background:#f8fafc;
  border-color:#d8e0ec;
}
:root[data-theme="light"] .msg{
  background:#ffffff;
  color:#0f172a;
  border-color:#d8e0ec;
  box-shadow:0 8px 18px rgba(15,23,42,.08);
}
:root[data-theme="light"] .msg.me{
  background:#dbeafe;
  color:#082f49;
  border-color:#bfdbfe;
}
:root[data-theme="light"] .msg-meta{
  color:#475569;
}
:root[data-theme="light"] .msg a{
  color:#1d4ed8;
}
:root[data-theme="light"] .msg-text-original{
  border-top-color:rgba(15,23,42,.18);
  color:#334155;
}
:root[data-theme="light"] #messageInput{
  background:#ffffff;
  color:#0f172a;
  border-color:#cbd5e1;
}
:root[data-theme="light"] #messageInput::placeholder{
  color:#64748b;
}
:root[data-theme="light"] .modal-card{
  background:#ffffff;
  color:#0f172a;
}
:root[data-theme="light"] .emoji-panel,
:root[data-theme="light"] .delete-toolbar-inner{
  background:#ffffff;
  color:#0f172a;
  border-color:#d8e0ec;
}
:root[data-theme="light"] .call-stage{
  background:linear-gradient(180deg, #e0f2fe, #f8fafc);
}
.call-remote-fallback img{
  width:100%;
  height:100%;
  border-radius:inherit;
  object-fit:cover;
  display:block;
}


/* Messages vocaux */
#btnVoice.recording{
  background: color-mix(in srgb, var(--danger) 30%, transparent);
  border-color: color-mix(in srgb, var(--danger) 65%, transparent);
  animation: voicePulse 1.2s infinite;
}
@keyframes voicePulse{
  0%,100%{ transform: scale(1); }
  50%{ transform: scale(1.06); }
}
.voice-recorder{
  display:flex;
  align-items:center;
  gap:10px;
  margin-top:8px;
  padding:8px 10px;
  border:1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  border-radius:14px;
  background:color-mix(in srgb, var(--danger) 12%, var(--card));
}
.voice-dot{
  width:10px;
  height:10px;
  border-radius:50%;
  background:var(--danger);
  box-shadow:0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent);
  animation: voiceDot 1.2s infinite;
}
@keyframes voiceDot{
  0%{ box-shadow:0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); }
  70%{ box-shadow:0 0 0 8px transparent; }
  100%{ box-shadow:0 0 0 0 transparent; }
}

/* Réactions aux messages */
.msg-actions{
  display:inline-flex;
  align-items:center;
  gap:4px;
  margin-left:6px;
}
.msg-react-btn{
  border:1px solid var(--border);
  background:color-mix(in srgb, var(--panel) 42%, transparent);
  color:var(--text);
  border-radius:10px;
  padding:2px 7px;
  font-size:12px;
  cursor:pointer;
}
.msg-react-btn:active{transform:scale(.98)}
.msg-reactions{
  display:flex;
  flex-wrap:wrap;
  gap:5px;
  margin-top:7px;
}
.reaction-pill{
  display:inline-flex;
  align-items:center;
  gap:4px;
  border:1px solid color-mix(in srgb, var(--text) 12%, transparent);
  background:color-mix(in srgb, var(--text) 7%, transparent);
  color:var(--text);
  border-radius:999px;
  padding:3px 7px;
  font-size:13px;
  cursor:pointer;
}
.reaction-pill.mine{
  border-color:color-mix(in srgb, var(--primary) 55%, transparent);
  background:color-mix(in srgb, var(--primary) 22%, transparent);
}
.reaction-picker{
  position:fixed;
  z-index:1300;
  display:flex;
  gap:6px;
  align-items:center;
  padding:8px;
  border:1px solid var(--border);
  border-radius:999px;
  background:color-mix(in srgb, var(--card) 96%, transparent);
  box-shadow:var(--shadow);
}
.reaction-picker.hidden{display:none}
.reaction-picker button{
  border:0;
  background:transparent;
  color:var(--text);
  border-radius:999px;
  padding:6px 8px;
  cursor:pointer;
  font-size:20px;
  line-height:1;
}
.reaction-picker button:hover{
  background:color-mix(in srgb, var(--text) 9%, transparent);
}
.reaction-picker .reaction-clear{
  font-size:13px;
  border-left:1px solid var(--border);
  border-radius:12px;
  padding:7px 9px;
}

/* Émojis + stickers */
.emoji-panel{
  display:block;
}
.emoji-panel.hidden{display:none}
.emoji-tabs{
  display:flex;
  gap:6px;
  margin-bottom:8px;
}
.emoji-tab{
  flex:1;
  border:1px solid var(--border);
  border-radius:999px;
  background:color-mix(in srgb, var(--panel) 55%, transparent);
  color:var(--text);
  padding:7px 10px;
  cursor:pointer;
  font-size:13px;
}
.emoji-tab.active{
  background:color-mix(in srgb, var(--primary) 25%, transparent);
  border-color:color-mix(in srgb, var(--primary) 55%, transparent);
}
.emoji-grid{
  display:grid;
  grid-template-columns:repeat(8, 1fr);
  gap:6px;
}
.sticker-grid{
  display:grid;
  grid-template-columns:repeat(4, 1fr);
  gap:8px;
}
.sticker-btn{
  min-height:56px;
  font-size:32px;
  line-height:1;
  padding:8px 0;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.04);
  cursor:pointer;
}
.sticker-btn:active{transform:scale(.97)}
.msg-sticker{
  font-size:56px;
  line-height:1.05;
  text-align:center;
  padding:4px 8px;
  min-width:80px;
}
@media (max-width: 520px){
  .emoji-grid{grid-template-columns:repeat(7, 1fr)}
  .sticker-grid{grid-template-columns:repeat(3, 1fr)}
  .msg-sticker{font-size:48px}
  .voice-recorder{flex-wrap:wrap}
}


/* Monetization / Freemium */
.money-summary{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;margin-bottom:14px}
.money-stat,.money-card{border:1px solid var(--border);background:rgba(15,23,42,.58);border-radius:16px;padding:12px}
.money-label{font-size:12px;color:var(--muted);font-weight:700;text-transform:uppercase;letter-spacing:.04em}
.money-value{font-weight:900;font-size:18px;margin-top:4px}
.money-section{margin-top:16px}
.money-section h3{margin:0 0 10px 0;font-size:16px}
.money-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.money-title{font-weight:900;margin-bottom:6px}
.money-price{font-size:13px;color:var(--muted);margin:8px 0}
.money-actions{display:flex;gap:8px;flex-wrap:wrap}
.money-stickers{display:flex;gap:6px;flex-wrap:wrap;font-size:24px;margin:8px 0}
.money-stickers span{display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:12px;background:rgba(255,255,255,.06)}
.money-mm-list{display:flex;flex-direction:column;gap:8px;margin:12px 0}
.money-mm-line{display:grid;grid-template-columns:110px 1fr auto;gap:8px;align-items:center;padding:8px;border:1px solid var(--border);border-radius:12px}
.money-mm-line code{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;background:rgba(255,255,255,.08);border-radius:8px;padding:4px 6px}
.money-field{display:flex;flex-direction:column;gap:6px;margin:10px 0}
.money-field span{font-size:12px;color:var(--muted);font-weight:700}
.money-field input,.money-field textarea{width:100%;box-sizing:border-box}
.sponsored-pill{font-size:11px;border:1px solid var(--border);border-radius:999px;padding:2px 6px;color:var(--muted);margin-left:4px}
.sticker-pack{grid-column:1/-1;border:1px solid var(--border);border-radius:14px;padding:8px;background:rgba(15,23,42,.46)}
.sticker-pack.locked{opacity:.92}
.sticker-pack-head{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:12px;font-weight:800;margin-bottom:8px;color:var(--muted)}
.sticker-pack-items{display:grid;grid-template-columns:repeat(6,1fr);gap:8px}
.sticker-owned{font-size:11px;border:1px solid var(--border);border-radius:999px;padding:2px 6px}
.sticker-btn.locked{filter:grayscale(.25);position:relative}
.sticker-btn.locked::after{content:"🔒";font-size:12px;position:absolute;right:2px;bottom:1px}
@media(max-width:700px){
  .money-summary,.money-grid{grid-template-columns:1fr}
  .money-mm-line{grid-template-columns:1fr}
  .sticker-pack-items{grid-template-columns:repeat(4,1fr)}
}


.money-summary.subscription-required{
  border-color: rgba(239, 68, 68, .45);
  background: rgba(127, 29, 29, .18);
}
.money-card.money-card-muted{
  opacity: .82;
}
#paypal-button-container{
  min-height: 44px;
}


/* Admin access button shown only for users with role=admin */
.admin-access-btn{
  background:linear-gradient(135deg,#38bdf8,#a78bfa) !important;
  color:#06111f !important;
  border:0 !important;
  font-weight:900;
  box-shadow:0 10px 25px rgba(56,189,248,.22);
}
.admin-access-btn::before{content:"🛡️";}
