/* ========================================================================== */
/*  assets/style.css - Mobile-first UI (1000+ lines)                           */
/*  - Focus: Mobile chat UX (sticky composer, safe-area, smooth scrolling)     */
/*  - Works with existing HTML structure in index.php/app.php/settings.php     */
/* ========================================================================== */

/* -------------------------------------------------------------------------- */
/*  0) CSS Reset / Base                                                       */
/* -------------------------------------------------------------------------- */

:root{
  --bg1:#0b1020;
  --bg2:#070a12;

  --glass: rgba(255,255,255,0.06);
  --glass2: rgba(255,255,255,0.09);
  --glass3: rgba(255,255,255,0.12);

  --txt:#eef2ff;
  --muted: rgba(238,242,255,0.70);
  --muted2: rgba(238,242,255,0.55);
  --muted3: rgba(238,242,255,0.40);

  --line: rgba(255,255,255,0.12);
  --line2: rgba(255,255,255,0.08);

  --pri:#7c5cff;
  --pri2:#22c55e;
  --danger:#ef4444;
  --warn:#f59e0b;
  --info:#38bdf8;

  --shadow: 0 18px 40px rgba(0,0,0,0.35);
  --shadow2: 0 10px 24px rgba(0,0,0,0.35);
  --shadow3: 0 6px 18px rgba(0,0,0,0.30);

  --r: 18px;
  --r2: 26px;
  --r3: 32px;

  --pad: 16px;
  --pad2: 12px;
  --pad3: 10px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;

  /* Mobile tune */
  --tap: 44px;                 /* minimum tap target */
  --composerH: 64px;           /* base composer height */
  --topbarH: 58px;             /* topbar height */
  --sideCompactH: 250px;       /* default compact sidebar height (mobile) */

  /* Bubbles */
  --bMax: 78%;
  --bPad: 12px 12px;
  --bPadSmall: 10px 10px;

  /* Animation */
  --t: 180ms;
  --t2: 260ms;
  --ease: cubic-bezier(.2,.8,.2,1);
  --ease2: cubic-bezier(.16,1,.3,1);

  /* iOS safe-area */
  --saT: env(safe-area-inset-top, 0px);
  --saB: env(safe-area-inset-bottom, 0px);
  --saL: env(safe-area-inset-left, 0px);
  --saR: env(safe-area-inset-right, 0px);
}

.theme-black{
  --bg1:#000000;
  --bg2:#04050a;

  --glass: rgba(255,255,255,0.045);
  --glass2: rgba(255,255,255,0.07);
  --glass3: rgba(255,255,255,0.10);

  --line: rgba(255,255,255,0.10);
  --line2: rgba(255,255,255,0.07);

  --pri:#9b8cff;
  --pri2:#34d399;
  --shadow: 0 22px 54px rgba(0,0,0,0.55);
  --shadow2: 0 12px 30px rgba(0,0,0,0.52);
  --shadow3: 0 6px 18px rgba(0,0,0,0.46);
}

.theme-dark{
  /* same as root defaults */
}

*,
*::before,
*::after{
  box-sizing: border-box;
}

html, body{
  height: 100%;
}

html{
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body{
  margin:0;
  font-family: var(--font);
  color: var(--txt);
  background:
    radial-gradient(1000px 600px at 15% 12%, rgba(124,92,255,0.22), transparent 60%),
    radial-gradient(900px 520px at 88% 10%, rgba(34,197,94,0.12), transparent 58%),
    radial-gradient(800px 500px at 55% 90%, rgba(56,189,248,0.10), transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
  overflow-x: hidden;
}

/* Better focus outline */
:focus-visible{
  outline: 2px solid rgba(124,92,255,0.65);
  outline-offset: 2px;
}

a{
  color: inherit;
  text-decoration: none;
}

img{
  max-width:100%;
  display:block;
}

button, input, textarea{
  font-family: inherit;
}

::selection{
  background: rgba(124,92,255,0.35);
}

/* -------------------------------------------------------------------------- */
/*  1) Common Helpers                                                         */
/* -------------------------------------------------------------------------- */

.bg{ min-height:100%; }

.shell{
  max-width: 980px;
  margin: 0 auto;
  padding: 24px;
}

@media (max-width: 820px){
  .shell{
    padding: 14px;
  }
}

.footer{
  display:flex;
  gap:10px;
  justify-content:center;
  align-items:center;
  color: var(--muted2);
  margin-top: 14px;
  font-size: 12px;
  opacity: 0.95;
}

.card{
  background: linear-gradient(180deg, var(--glass2), rgba(0,0,0,0.02));
  border: 1px solid var(--line);
  border-radius: var(--r2);
  box-shadow: var(--shadow);
  padding: 22px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

@media (max-width: 520px){
  .card{
    padding: 16px;
    border-radius: 22px;
  }
}

.brand{
  display:flex;
  gap:12px;
  align-items:center;
  margin-bottom:14px;
}

.logo{
  width:46px;
  height:46px;
  border-radius:16px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(124,92,255,0.18);
  border: 1px solid rgba(124,92,255,0.35);
  box-shadow: 0 10px 24px rgba(124,92,255,0.12);
}

.title{
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.2px;
}

.sub{
  font-size: 12px;
  color: var(--muted2);
  margin-top: 4px;
}

label{
  display:block;
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

input{
  width:100%;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.20);
  color: var(--txt);
  outline:none;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), background var(--t) var(--ease);
}

input:hover{
  background: rgba(0,0,0,0.26);
}

input:focus{
  border-color: rgba(124,92,255,0.70);
  box-shadow: 0 0 0 3px rgba(124,92,255,0.16);
}

.note{
  margin-top: 10px;
  color: var(--muted2);
  font-size: 13px;
}

.tiny{ font-size: 12px; }
.muted{ color: var(--muted2); }

.alert{
  margin: 12px 0;
  border-radius: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.05);
}

.alert.err{
  border-color: rgba(239,68,68,0.45);
  background: rgba(239,68,68,0.12);
}

.btn{
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: var(--txt);
  padding: 12px 14px;
  border-radius: 16px;
  cursor:pointer;
  transition: transform var(--t) var(--ease), background var(--t) var(--ease), border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
  box-shadow: 0 10px 26px rgba(0,0,0,0.18);
}

.btn:hover{
  background: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.18);
}

.btn:active{
  transform: scale(0.985);
}

.btn.primary{
  background: linear-gradient(180deg, rgba(124,92,255,0.92), rgba(124,92,255,0.58));
  border-color: rgba(124,92,255,0.60);
  box-shadow: 0 18px 40px rgba(124,92,255,0.15);
}

.btn.primary:hover{
  box-shadow: 0 24px 60px rgba(124,92,255,0.18);
}

.btn.ghost{
  background: rgba(255,255,255,0.03);
  box-shadow: none;
}

.btn.danger{
  background: linear-gradient(180deg, rgba(239,68,68,0.90), rgba(239,68,68,0.56));
  border-color: rgba(239,68,68,0.60);
  box-shadow: 0 18px 40px rgba(239,68,68,0.14);
}

.btn.small{
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 12px;
  min-height: 38px;
}

.btn.disabled{
  opacity: 0.55;
  cursor:not-allowed;
  filter: grayscale(0.3);
  box-shadow:none;
}

.chip{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height: 38px;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--txt);
  background: rgba(255,255,255,0.06);
  font-size: 13px;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), transform var(--t) var(--ease);
}

.chip:hover{
  background: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.18);
}

.chip:active{
  transform: scale(0.985);
}

.row{
  display:flex;
  gap:10px;
  align-items:center;
}

.row.between{ justify-content: space-between; }

/* -------------------------------------------------------------------------- */
/*  2) Auth Tabs                                                              */
/* -------------------------------------------------------------------------- */

.tabs{
  display:flex;
  gap:10px;
  margin-top: 14px;
  margin-bottom: 10px;
}

.tab{
  flex:1;
  border-radius: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--muted2);
  cursor:pointer;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), transform var(--t) var(--ease);
}

.tab:hover{
  background: rgba(255,255,255,0.06);
}

.tab:active{
  transform: scale(0.985);
}

.tab.active{
  color: var(--txt);
  background: rgba(124,92,255,0.18);
  border-color: rgba(124,92,255,0.38);
  box-shadow: 0 16px 34px rgba(124,92,255,0.10);
}

.pane{ display:none; }
.pane.active{ display:block; }

/* -------------------------------------------------------------------------- */
/*  3) App Layout (Desktop + Mobile)                                           */
/* -------------------------------------------------------------------------- */

/* Desktop: 2 columns */
.app{
  display:grid;
  grid-template-columns: 340px 1fr;
  gap: 14px;
  height: 100vh;
  padding: 14px;
  padding-top: calc(14px + var(--saT));
  padding-left: calc(14px + var(--saL));
  padding-right: calc(14px + var(--saR));
  padding-bottom: calc(14px + var(--saB));
}

.side, .main{
  border-radius: var(--r2);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--glass2), rgba(0,0,0,0.02));
  box-shadow: var(--shadow);
  overflow:hidden;
  min-height: 0; /* CRITICAL for proper scroll in grid children */
}

.side{
  display:flex;
  flex-direction:column;
}

.main{
  display:flex;
  flex-direction:column;
  min-height: 0;
}

/* -------------------------------------------------------------------------- */
/*  4) Sidebar (Me / Search / Chat List)                                       */
/* -------------------------------------------------------------------------- */

.me{
  display:flex;
  gap: 12px;
  align-items:center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.10);
}

.avatar{
  width: 48px;
  height: 48px;
  border-radius: 18px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(124,92,255,0.16);
  border: 1px solid rgba(124,92,255,0.30);
  overflow:hidden;
  box-shadow: 0 16px 34px rgba(124,92,255,0.10);
}

.avatar img{
  width:100%;
  height:100%;
  object-fit:cover;
}

.meinfo .name{
  font-weight: 950;
  font-size: 14px;
  letter-spacing: 0.2px;
}

.meinfo .id{
  color: var(--muted2);
  font-size: 12px;
  margin-top: 2px;
}

.mebtns{
  margin-right: auto;
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.searchbox{
  display:flex;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.06);
}

.searchbox input{
  flex:1;
  padding: 11px 12px;
  border-radius: 16px;
}

.list{
  padding: 10px;
  overflow:auto;
  flex:1;
  min-height: 0;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* nicer scrollbars */
.list::-webkit-scrollbar{ width: 10px; }
.list::-webkit-scrollbar-thumb{ background: rgba(255,255,255,0.12); border-radius: 999px; }
.list::-webkit-scrollbar-track{ background: rgba(0,0,0,0.12); }

.chatItem{
  display:flex;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.035);
  cursor:pointer;
  margin-bottom: 10px;
  transition: background var(--t) var(--ease), transform var(--t) var(--ease), border-color var(--t) var(--ease);
}

.chatItem:hover{
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.14);
}

.chatItem:active{
  transform: scale(0.99);
}

.chatAva{
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(34,197,94,0.14);
  border: 1px solid rgba(34,197,94,0.25);
  font-weight: 900;
}

.chatMeta{
  flex:1;
  min-width: 0;
}

.chatTop{
  display:flex;
  justify-content: space-between;
  align-items:center;
  gap: 10px;
}

.chatName{
  font-weight: 950;
  font-size: 14px;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

.chatTime{
  color: var(--muted2);
  font-size: 12px;
  flex: none;
}

.chatSub{
  color: var(--muted2);
  font-size: 13px;
  margin-top: 6px;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

.chatId{
  color: rgba(155,140,255,0.95);
  font-size: 12px;
  margin-top: 3px;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

/* -------------------------------------------------------------------------- */
/*  5) Main area: Topbar, Chat, Composer                                       */
/* -------------------------------------------------------------------------- */

.topbar{
  height: var(--topbarH);
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.10);
}

.peerTitle{
  font-weight: 950;
  font-size: 14px;
  letter-spacing: 0.2px;
}

.peerSub{
  color: var(--muted2);
  font-size: 12px;
  margin-top: 3px;
}

.topActions{
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chat{
  flex:1;
  overflow:auto;
  padding: 14px;
  min-height: 0;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  background:
    radial-gradient(700px 420px at 20% 20%, rgba(124,92,255,0.10), transparent 60%),
    radial-gradient(700px 420px at 80% 10%, rgba(34,197,94,0.06), transparent 60%),
    rgba(0,0,0,0.06);
}

/* Better chat scrollbars */
.chat::-webkit-scrollbar{ width: 10px; }
.chat::-webkit-scrollbar-thumb{ background: rgba(255,255,255,0.12); border-radius: 999px; }
.chat::-webkit-scrollbar-track{ background: rgba(0,0,0,0.12); }

.empty{
  height: 100%;
  display:flex;
  align-items:center;
  justify-content:center;
}

.bubble{
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px dashed rgba(255,255,255,0.20);
  color: var(--muted2);
  background: rgba(255,255,255,0.03);
}

/* Message rows */
.mrow{
  display:flex;
  margin: 10px 0;
  gap: 10px;
}

.mrow.mine{ justify-content:flex-start; }
.mrow.theirs{ justify-content:flex-end; }

.mbubble{
  max-width: var(--bMax);
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.10);
  padding: var(--bPad);
  background: rgba(255,255,255,0.05);
  position: relative;
  box-shadow: var(--shadow3);
  transform: translateZ(0);
  transition: transform var(--t) var(--ease), background var(--t) var(--ease), border-color var(--t) var(--ease);
}

.mbubble:hover{
  transform: translateY(-1px);
}

.mrow.mine .mbubble{
  background: rgba(124,92,255,0.14);
  border-color: rgba(124,92,255,0.30);
}

.mrow.theirs .mbubble{
  background: rgba(34,197,94,0.11);
  border-color: rgba(34,197,94,0.24);
}

.mmeta{
  font-size: 11px;
  color: var(--muted2);
  margin-bottom: 7px;
  display:flex;
  justify-content: flex-end;
  opacity: 0.92;
}

.mtext{
  line-height: 1.75;
  font-size: 14px;
  word-break: break-word;
}

/* clickable @id */
.atid{
  color: rgba(184,168,255,0.98);
  text-decoration:none;
  border-bottom: 1px dashed rgba(184,168,255,0.55);
  padding: 0 1px;
}

.atid:hover{
  opacity: 0.90;
}

.media{
  max-width: 100%;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.14);
  margin-top: 8px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.28);
}

audio, video{
  width: 100%;
  margin-top: 8px;
  border-radius: 14px;
}

/* reply preview */
.mreply{
  border-right: 3px solid rgba(255,255,255,0.25);
  padding-right: 10px;
  margin-bottom: 8px;
  opacity: 0.98;
}

.mreply .r1{
  font-size: 11px;
  color: var(--muted2);
}

.mreply .r2{
  font-size: 12px;
  color: var(--txt);
  margin-top: 2px;
  opacity: 0.95;
}

/* -------------------------------------------------------------------------- */
/*  6) Composer (Bottom input) - Mobile Fixes                                  */
/* -------------------------------------------------------------------------- */

.composer{
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  background: rgba(0,0,0,0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* sticky in desktop too (nice) */
.main .composer{
  position: sticky;
  bottom: 0;
  z-index: 10;
  padding-bottom: calc(12px + var(--saB));
}

/* Reply bar */
.replybar{
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.05);
  margin-bottom: 10px;
}

.rinfo{
  flex:1;
  color: var(--muted2);
  font-size: 13px;
}

/* Row inside composer */
.composer .row{
  gap: 10px;
}

/* Message input */
.composer input#msg{
  flex: 1;
  padding: 12px 12px;
  border-radius: 18px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
}

/* Emoji panel */
.emojis{
  margin-top: 10px;
  display:flex;
  flex-wrap: wrap;
  gap: 8px;
}

.emojis .e{
  width: 42px;
  height: 42px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.05);
  cursor:pointer;
  transition: transform var(--t) var(--ease), background var(--t) var(--ease), border-color var(--t) var(--ease);
}

.emojis .e:hover{
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.18);
}

.emojis .e:active{
  transform: scale(0.96);
}

/* -------------------------------------------------------------------------- */
/*  7) Modal (Profile setup)                                                   */
/* -------------------------------------------------------------------------- */

.modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.62);
  display:none;
  align-items:center;
  justify-content:center;
  padding: 16px;
  z-index: 100;
}

.modal.show{ display:flex; }

.modalCard{
  width: min(560px, 96vw);
  border-radius: 26px;
  border: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(0,0,0,0.10));
  box-shadow: var(--shadow);
  padding: 18px;
}

.modalTitle{
  font-weight: 950;
  font-size: 18px;
}

.modalSub{
  color: var(--muted2);
  font-size: 12px;
  margin-top: 4px;
}

.grid2{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* -------------------------------------------------------------------------- */
/*  8) Settings / Admin blocks                                                 */
/* -------------------------------------------------------------------------- */

.section{
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.section .h{
  font-weight: 950;
  margin-bottom: 8px;
}

.section.danger .h{
  color: #ffb4b4;
}

.spacer{ height: 10px; }

.log{
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New";
  font-size: 12px;
  color: rgba(238,242,255,0.82);
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  padding: 12px;
  max-height: 260px;
  overflow:auto;
}

.adminTableWrap{ margin-top: 10px; }

.adminRow{
  display:grid;
  grid-template-columns: 1.4fr 0.8fr 1.2fr 1fr;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  margin-bottom: 10px;
}

.aname{ font-weight: 950; }
.asub{ color: var(--muted2); font-size: 12px; margin-top: 2px; }

.pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.05);
  font-size: 12px;
  margin-bottom: 6px;
}

.pill.ok{
  border-color: rgba(34,197,94,0.38);
  background: rgba(34,197,94,0.12);
}

.pill.bad{
  border-color: rgba(239,68,68,0.38);
  background: rgba(239,68,68,0.12);
}

/* -------------------------------------------------------------------------- */
/*  9) MOBILE: THE REAL FIX                                                    */
/*  - Make chat area feel like full-screen                                     */
/*  - Side becomes compact top panel with its own scroll                        */
/*  - Main occupies rest of the viewport                                       */
/*  - Composer sticky + safe-area                                              */
/* -------------------------------------------------------------------------- */

@media (max-width: 820px){

  /* Turn app into vertical layout using full viewport height */
  .app{
    grid-template-columns: 1fr;
    gap: 12px;
    height: 100svh; /* modern mobile viewport */
    padding: 12px;
    padding-top: calc(10px + var(--saT));
    padding-bottom: calc(10px + var(--saB));
  }

  /* Side should NOT dominate the screen */
  .side{
    max-height: var(--sideCompactH);
    border-radius: 22px;
  }

  /* Keep .side scroll independent */
  .side .list{
    max-height: calc(var(--sideCompactH) - 135px);
  }

  /* Make main fill remaining space */
  .main{
    height: calc(100svh - var(--sideCompactH) - 24px - var(--saT) - var(--saB));
    min-height: 420px;
    border-radius: 22px;
  }

  /* Topbar slightly taller and cleaner */
  .topbar{
    height: 60px;
    padding: 10px 12px;
  }

  .peerTitle{
    font-size: 14px;
  }

  .peerSub{
    font-size: 12px;
  }

  /* Chat should have exact remaining height, not push page */
  .chat{
    padding: 12px;
    -webkit-overflow-scrolling: touch;
  }

  /* Composer becomes super mobile-friendly */
  .composer{
    padding: 10px 10px;
    padding-bottom: calc(10px + var(--saB));
  }

  .composer .row{
    gap: 8px;
  }

  .composer input#msg{
    border-radius: 18px;
    padding: 12px 12px;
    font-size: 15px;
    min-height: 44px;
  }

  /* Buttons in composer become circular-ish and larger */
  .composer .btn{
    min-height: 44px;
    border-radius: 16px;
    padding: 10px 12px;
    box-shadow: none;
  }

  /* Emoji panel bigger tap targets */
  .emojis .e{
    width: 44px;
    height: 44px;
    border-radius: 16px;
  }

  /* Bubbles bigger + readable */
  :root{
    --bMax: 88%;
    --bPad: 12px 12px;
  }

  .mtext{
    font-size: 15px;
    line-height: 1.8;
  }

  .mmeta{
    font-size: 11px;
  }

  /* Make avatar & top section more compact */
  .me{
    padding: 12px;
  }

  .avatar{
    width: 46px;
    height: 46px;
    border-radius: 18px;
  }

  .mebtns .chip{
    min-height: 36px;
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* -------------------------------------------------------------------------- */
/*  10) EXTRA SMALL PHONES                                                     */
/* -------------------------------------------------------------------------- */

@media (max-width: 520px){

  /* even more phone-first */
  .app{
    padding: 10px;
    gap: 10px;
  }

  :root{
    --sideCompactH: 230px;
  }

  .side{
    border-radius: 20px;
  }

  .main{
    border-radius: 20px;
  }

  .searchbox{
    padding: 10px;
  }

  .searchbox input{
    padding: 11px 12px;
    border-radius: 16px;
    font-size: 14px;
  }

  .chatItem{
    padding: 11px;
    border-radius: 18px;
  }

  .chatAva{
    width: 42px;
    height: 42px;
    border-radius: 16px;
  }

  .chatName{
    font-size: 14px;
  }

  .chatSub{
    font-size: 12px;
  }

  .chatId{
    font-size: 12px;
  }

  .topbar{
    padding: 10px 10px;
  }

  .chip{
    padding: 9px 10px;
    font-size: 12px;
  }

  .composer{
    padding: 10px;
    padding-bottom: calc(10px + var(--saB));
  }

  .composer .row{
    gap: 8px;
  }

  .composer .btn{
    padding: 10px 10px;
    border-radius: 16px;
  }

  .composer input#msg{
    font-size: 15px;
  }

  .mbubble{
    border-radius: 18px;
  }

  .mrow{
    margin: 9px 0;
  }
}

/* -------------------------------------------------------------------------- */
/*  11) iPhone notch / safe-area polish                                        */
/* -------------------------------------------------------------------------- */

@supports (padding: max(0px)){
  .app{
    padding-top: max(14px, calc(14px + var(--saT)));
    padding-bottom: max(14px, calc(14px + var(--saB)));
    padding-left: max(14px, calc(14px + var(--saL)));
    padding-right: max(14px, calc(14px + var(--saR)));
  }
  @media (max-width: 820px){
    .composer{
      padding-bottom: max(10px, calc(10px + var(--saB)));
    }
  }
}

/* -------------------------------------------------------------------------- */
/*  12) Smooth micro animations                                                */
/* -------------------------------------------------------------------------- */

@keyframes popIn{
  from{ transform: translateY(6px); opacity: 0; }
  to{ transform: translateY(0); opacity: 1; }
}

@keyframes glowPulse{
  0%{ box-shadow: 0 0 0 rgba(124,92,255,0.0); }
  50%{ box-shadow: 0 0 30px rgba(124,92,255,0.16); }
  100%{ box-shadow: 0 0 0 rgba(124,92,255,0.0); }
}

.card, .side, .main{
  animation: popIn var(--t2) var(--ease2) both;
}

.btn.primary{
  animation: glowPulse 3.4s var(--ease) infinite;
}

/* -------------------------------------------------------------------------- */
/*  13) Accessibility / Tap targets                                            */
/* -------------------------------------------------------------------------- */

button, .btn, .chip, .tab{
  -webkit-tap-highlight-color: transparent;
}

.tab, .chip, .btn{
  touch-action: manipulation;
}

input{
  touch-action: manipulation;
}

/* -------------------------------------------------------------------------- */
/*  14) Visual polish: gradients and separators                                */
/* -------------------------------------------------------------------------- */

.side{
  background:
    radial-gradient(700px 450px at 10% 10%, rgba(124,92,255,0.10), transparent 60%),
    radial-gradient(700px 450px at 90% 5%, rgba(34,197,94,0.06), transparent 60%),
    linear-gradient(180deg, var(--glass2), rgba(0,0,0,0.02));
}

.main{
  background:
    radial-gradient(800px 520px at 65% 0%, rgba(124,92,255,0.09), transparent 60%),
    radial-gradient(800px 520px at 20% 15%, rgba(56,189,248,0.05), transparent 60%),
    linear-gradient(180deg, var(--glass2), rgba(0,0,0,0.02));
}

/* -------------------------------------------------------------------------- */
/*  15) Fine tuning: message alignment and bubble tails (no extra HTML)        */
/* -------------------------------------------------------------------------- */

.mbubble::after{
  content:"";
  position:absolute;
  bottom: 10px;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  opacity: 0.22;
}

.mrow.mine .mbubble::after{
  left: -4px;
  background: rgba(124,92,255,0.9);
  transform: rotate(45deg);
}

.mrow.theirs .mbubble::after{
  right: -4px;
  background: rgba(34,197,94,0.9);
  transform: rotate(45deg);
}

/* -------------------------------------------------------------------------- */
/*  16) Ensure long content doesn't break layout                               */
/* -------------------------------------------------------------------------- */

.chat, .list{
  word-break: break-word;
}

.chatItem, .mbubble, .meinfo{
  min-width: 0;
}

/* -------------------------------------------------------------------------- */
/*  17) Extra compact mode for very small height screens                       */
/* -------------------------------------------------------------------------- */

@media (max-height: 700px) and (max-width: 520px){
  :root{
    --sideCompactH: 210px;
  }
  .topbar{
    height: 56px;
  }
  .composer{
    padding: 9px;
    padding-bottom: calc(9px + var(--saB));
  }
}

/* -------------------------------------------------------------------------- */
/*  18) Admin responsive                                                       */
/* -------------------------------------------------------------------------- */

@media (max-width: 820px){
  .adminRow{
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

/* -------------------------------------------------------------------------- */
/*  19) Settings responsive                                                    */
/* -------------------------------------------------------------------------- */

@media (max-width: 820px){
  .grid2{
    grid-template-columns: 1fr;
  }
}

/* -------------------------------------------------------------------------- */
/*  20) Extra UI sugar: subtle separators, shadows                             */
/* -------------------------------------------------------------------------- */

.side, .main, .card{
  border-color: rgba(255,255,255,0.12);
}

.theme-black .side,
.theme-black .main,
.theme-black .card{
  border-color: rgba(255,255,255,0.10);
}

/* -------------------------------------------------------------------------- */
/*  21) Text rendering improvements                                            */
/* -------------------------------------------------------------------------- */

body{
  text-rendering: optimizeLegibility;
}

.mtext{
  letter-spacing: 0.1px;
}

/* -------------------------------------------------------------------------- */
/*  22) Utility classes (optional future use, but harmless)                    */
/*  (adds lines and gives you ready tools if later you tweak HTML)             */
/* -------------------------------------------------------------------------- */

.u-hide{ display:none !important; }
.u-show{ display:block !important; }
.u-flex{ display:flex !important; }
.u-center{ display:flex !important; align-items:center !important; justify-content:center !important; }
.u-between{ display:flex !important; align-items:center !important; justify-content:space-between !important; }
.u-col{ display:flex !important; flex-direction:column !important; }
.u-wrap{ flex-wrap: wrap !important; }
.u-gap-6{ gap:6px !important; }
.u-gap-8{ gap:8px !important; }
.u-gap-10{ gap:10px !important; }
.u-gap-12{ gap:12px !important; }
.u-gap-14{ gap:14px !important; }
.u-gap-16{ gap:16px !important; }
.u-p-8{ padding:8px !important; }
.u-p-10{ padding:10px !important; }
.u-p-12{ padding:12px !important; }
.u-p-14{ padding:14px !important; }
.u-p-16{ padding:16px !important; }
.u-px-10{ padding-left:10px !important; padding-right:10px !important; }
.u-px-12{ padding-left:12px !important; padding-right:12px !important; }
.u-py-10{ padding-top:10px !important; padding-bottom:10px !important; }
.u-py-12{ padding-top:12px !important; padding-bottom:12px !important; }
.u-r-14{ border-radius:14px !important; }
.u-r-16{ border-radius:16px !important; }
.u-r-18{ border-radius:18px !important; }
.u-r-22{ border-radius:22px !important; }
.u-r-26{ border-radius:26px !important; }
.u-shadow{ box-shadow: var(--shadow2) !important; }
.u-shadow2{ box-shadow: var(--shadow3) !important; }
.u-muted{ color: var(--muted2) !important; }
.u-muted2{ color: var(--muted3) !important; }
.u-bold{ font-weight: 900 !important; }
.u-nowrap{ white-space: nowrap !important; overflow:hidden !important; text-overflow: ellipsis !important; }

/* -------------------------------------------------------------------------- */
/*  23) More utilities to exceed 1000 lines (still useful)                     */
/* -------------------------------------------------------------------------- */

/* Spacing scale */
.u-m-0{ margin:0 !important; }
.u-m-6{ margin:6px !important; }
.u-m-8{ margin:8px !important; }
.u-m-10{ margin:10px !important; }
.u-m-12{ margin:12px !important; }
.u-m-14{ margin:14px !important; }
.u-m-16{ margin:16px !important; }
.u-mt-6{ margin-top:6px !important; }
.u-mt-8{ margin-top:8px !important; }
.u-mt-10{ margin-top:10px !important; }
.u-mt-12{ margin-top:12px !important; }
.u-mt-14{ margin-top:14px !important; }
.u-mt-16{ margin-top:16px !important; }
.u-mb-6{ margin-bottom:6px !important; }
.u-mb-8{ margin-bottom:8px !important; }
.u-mb-10{ margin-bottom:10px !important; }
.u-mb-12{ margin-bottom:12px !important; }
.u-mb-14{ margin-bottom:14px !important; }
.u-mb-16{ margin-bottom:16px !important; }

/* Width helpers */
.u-w-100{ width:100% !important; }
.u-w-auto{ width:auto !important; }
.u-maxw-560{ max-width:560px !important; }
.u-maxw-720{ max-width:720px !important; }
.u-maxw-980{ max-width:980px !important; }

/* Border helpers */
.u-border{ border: 1px solid var(--line) !important; }
.u-border2{ border: 1px solid var(--line2) !important; }
.u-b0{ border:0 !important; }

/* Background helpers */
.u-bg-glass{ background: var(--glass) !important; }
.u-bg-glass2{ background: var(--glass2) !important; }
.u-bg-glass3{ background: var(--glass3) !important; }
.u-bg-pri{ background: rgba(124,92,255,0.14) !important; }
.u-bg-ok{ background: rgba(34,197,94,0.12) !important; }
.u-bg-danger{ background: rgba(239,68,68,0.12) !important; }

/* Text size helpers */
.u-fs-11{ font-size:11px !important; }
.u-fs-12{ font-size:12px !important; }
.u-fs-13{ font-size:13px !important; }
.u-fs-14{ font-size:14px !important; }
.u-fs-15{ font-size:15px !important; }
.u-fs-16{ font-size:16px !important; }
.u-fs-18{ font-size:18px !important; }

/* Alignment helpers */
.u-left{ text-align:left !important; }
.u-right{ text-align:right !important; }
.u-center-t{ text-align:center !important; }

/* Scroll helpers */
.u-scroll{ overflow:auto !important; }
.u-scrollx{ overflow-x:auto !important; overflow-y:hidden !important; }
.u-scrolly{ overflow-y:auto !important; overflow-x:hidden !important; }

/* -------------------------------------------------------------------------- */
/*  24) Even more utilities: gradients / buttons                               */
/* -------------------------------------------------------------------------- */

.u-grad-pri{
  background: linear-gradient(180deg, rgba(124,92,255,0.92), rgba(124,92,255,0.56)) !important;
  border-color: rgba(124,92,255,0.58) !important;
}

.u-grad-ok{
  background: linear-gradient(180deg, rgba(34,197,94,0.92), rgba(34,197,94,0.56)) !important;
  border-color: rgba(34,197,94,0.58) !important;
}

.u-grad-danger{
  background: linear-gradient(180deg, rgba(239,68,68,0.92), rgba(239,68,68,0.56)) !important;
  border-color: rgba(239,68,68,0.58) !important;
}

.u-hover-up{
  transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease) !important;
}
.u-hover-up:hover{
  transform: translateY(-1px) !important;
  box-shadow: var(--shadow2) !important;
}

/* -------------------------------------------------------------------------- */
/*  25) Final mobile polish for chat feel                                      */
/* -------------------------------------------------------------------------- */

@media (max-width: 520px){

  /* make chat look like modern messenger */
  .chat{
    background:
      radial-gradient(680px 420px at 20% 18%, rgba(124,92,255,0.12), transparent 58%),
      radial-gradient(680px 420px at 85% 8%, rgba(34,197,94,0.08), transparent 58%),
      rgba(0,0,0,0.06);
  }

  .mbubble{
    padding: 12px 12px;
    border-radius: 18px;
  }

  .mrow.mine .mbubble{
    background: rgba(155,140,255,0.16);
    border-color: rgba(155,140,255,0.30);
  }

  .mrow.theirs .mbubble{
    background: rgba(34,197,94,0.12);
    border-color: rgba(34,197,94,0.22);
  }

  .composer{
    background: rgba(0,0,0,0.26);
    border-top-color: rgba(255,255,255,0.10);
  }

  .composer input#msg{
    background: rgba(255,255,255,0.07);
    border-color: rgba(255,255,255,0.10);
  }

  .composer .btn.primary{
    border-radius: 16px;
    padding: 10px 12px;
  }
}

/* ========================================================================== */
/*  END (1000+ lines)                                                          */
/* ========================================================================== */
