/* ════════════════════════════════════════════════════════════
   Private Chat — mobile-first stylesheet
   ════════════════════════════════════════════════════════════ */
:root {
  --bg:        #f2f2f2;
  --wall:      #f2f2f2;
  --panel:     #ffffff;
  --panel2:    #c8d8e4;
  --panel3:    #f2f2f2;
  --bubble-me:   #2b6777;
  --bubble-them: #ffffff;
  --ink:       #1d3c46;
  --blush:     #2b6777;
  --lilac:     #52ab98;
  --taupe:     #5d7c86;
  --accent:    #2b6777;
  --accent-ink:#ffffff;
  --accent-h:  #52ab98;
  --text:      #1d3c46;
  --text2:     #5d7c86;
  --meta:      #6d8b94;
  --tick-read: #52ab98;
  --border:    rgba(43,103,119,.12);
  --divider:   rgba(43,103,119,.12);
  --danger:    #c45464;
  --field:     #ffffff;
  --field-border: #d5e2ea;
  --on-me:     #ffffff;
  --on-me-soft:#d7f3ec;
  --pad-key:   #ffffff;
  --day-bg:    #ffffff;
  --send:      #52ab98;
  --send-ink:  #14343c;
  --them-border:#d7e3ea;
  --banner:    #e7f3ef;
  --toast:     #2b6777;
  --wide:      #c8d8e4;
  --dot:       #9eb4be;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --ease-out: cubic-bezier(.16, .84, .32, 1);
  --ease-inout: cubic-bezier(.4, 0, .2, 1);
  --ease: var(--ease-out);
  --t-in: 220ms;
  --t-out: 180ms;
}
html[data-theme="night"] {
  --bg:#101614; --wall:#101614; --panel:#18211c; --panel2:#24302a; --panel3:#141c18;
  --bubble-me:#1f6b52; --bubble-them:#1c2822; --ink:#e7f3ee; --blush:#1f6b52; --lilac:#7dcea0;
  --taupe:#8eaea0; --accent:#7dcea0; --accent-ink:#062018; --accent-h:#7dcea0;
  --text:#e7f3ee; --text2:#8eaea0; --meta:#8eaea0; --tick-read:#7dcea0; --danger:#e07a86;
  --field:#1c2822; --field-border:#2c4036; --on-me:#f3fff8; --on-me-soft:#d7f3ec;
  --pad-key:#24302a; --day-bg:#1c2822; --send:#3dbe8b; --send-ink:#062018;
  --them-border:#2c4036; --banner:#163028; --toast:#1f6b52; --wide:#0c1210; --dot:#5d7c70;
  color-scheme: dark;
}
html[data-theme="forest"] {
  --bg:#0c1610; --wall:#0c1610; --panel:#132118; --panel2:#1d3326; --panel3:#101c14;
  --bubble-me:#2f7d46; --bubble-them:#17261c; --ink:#e5f6ea; --blush:#2f7d46; --lilac:#8fd19a;
  --taupe:#8aab92; --accent:#8fd19a; --accent-ink:#062010; --accent-h:#8fd19a;
  --text:#e5f6ea; --text2:#8aab92; --meta:#8aab92; --tick-read:#8fd19a; --danger:#e07a86;
  --field:#17261c; --field-border:#2a4634; --on-me:#f4fff6; --on-me-soft:#d9f5df;
  --pad-key:#1d3326; --day-bg:#17261c; --send:#46b864; --send-ink:#062010;
  --them-border:#2a4634; --banner:#143222; --toast:#2f7d46; --wide:#08110c; --dot:#5d7c68;
  color-scheme: dark;
}
html[data-theme="ocean"] {
  --bg:#0c1420; --wall:#0c1420; --panel:#142033; --panel2:#1d2e4a; --panel3:#10192a;
  --bubble-me:#2a6fbf; --bubble-them:#18263c; --ink:#e7f0fb; --blush:#2a6fbf; --lilac:#8eb6ef;
  --taupe:#8ea4c4; --accent:#8eb6ef; --accent-ink:#061428; --accent-h:#8eb6ef;
  --text:#e7f0fb; --text2:#8ea4c4; --meta:#8ea4c4; --tick-read:#8eb6ef; --danger:#e07a86;
  --field:#18263c; --field-border:#2a4060; --on-me:#f4f8ff; --on-me-soft:#d6e6ff;
  --pad-key:#1d2e4a; --day-bg:#18263c; --send:#4c8fe8; --send-ink:#061428;
  --them-border:#2a4060; --banner:#152840; --toast:#2a6fbf; --wide:#080e18; --dot:#5d7090;
  color-scheme: dark;
}
html[data-theme="ember"] {
  --bg:#160e0e; --wall:#160e0e; --panel:#241616; --panel2:#3a2222; --panel3:#1c1212;
  --bubble-me:#a33b45; --bubble-them:#2a1a1a; --ink:#fbeceb; --blush:#a33b45; --lilac:#f0a0a4;
  --taupe:#c4a0a0; --accent:#f0a0a4; --accent-ink:#28080c; --accent-h:#f0a0a4;
  --text:#fbeceb; --text2:#c4a0a0; --meta:#c4a0a0; --tick-read:#f0a0a4; --danger:#ff8b96;
  --field:#2a1a1a; --field-border:#4a2c2c; --on-me:#fff6f6; --on-me-soft:#ffd6d8;
  --pad-key:#3a2222; --day-bg:#2a1a1a; --send:#d25a64; --send-ink:#28080c;
  --them-border:#4a2c2c; --banner:#3a181c; --toast:#a33b45; --wide:#100a0a; --dot:#8a6060;
  color-scheme: dark;
}
html[data-theme="dusk"] {
  --bg:#14110e; --wall:#14110e; --panel:#221c16; --panel2:#342a22; --panel3:#1a1612;
  --bubble-me:#3d6e9a; --bubble-them:#2a241c; --ink:#f6f0e8; --blush:#3d6e9a; --lilac:#9ec0e4;
  --taupe:#b4a494; --accent:#9ec0e4; --accent-ink:#101820; --accent-h:#9ec0e4;
  --text:#f6f0e8; --text2:#b4a494; --meta:#b4a494; --tick-read:#9ec0e4; --danger:#e07a86;
  --field:#2a241c; --field-border:#463c32; --on-me:#f4f8ff; --on-me-soft:#d6e6ff;
  --pad-key:#342a22; --day-bg:#2a241c; --send:#5b93c9; --send-ink:#101820;
  --them-border:#463c32; --banner:#243044; --toast:#3d6e9a; --wide:#100e0c; --dot:#7a6c5c;
  color-scheme: dark;
}
html, body { transition: background-color 220ms var(--ease-out), color 220ms var(--ease-out); }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

@font-face {
  font-family: "Phoenix Arabic";
  src: url("fonts/NotoSansArabic-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-089F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Phoenix Arabic", system-ui, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }
.file-off { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.ic { width: 24px; height: 24px; fill: currentColor; flex: none; display: block; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: var(--panel2); border-radius: 9px; }

/* ═══════════════ Auth (login / register) ═══════════════ */
.auth-bg {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: calc(20px + var(--safe-t)) 18px calc(20px + var(--safe-b));
  background:
    radial-gradient(ellipse 90% 40% at 50% -12%, rgba(82,171,152,.16), transparent 68%),
    var(--bg);
  overflow-y: auto;
  position: fixed; inset: 0;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 30px 24px 26px;
  box-shadow: 0 16px 40px rgba(43,103,119,.12);
  animation: rise var(--t-in) var(--ease-out) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.auth-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.auth-logo-icon {
  width: 56px; height: 56px; border-radius: 16px; flex: none;
  background: var(--blush); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
}
.auth-logo h1 { font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.auth-logo p { font-size: 13px; color: var(--text2); margin-top: 2px; }
.auth-tabs { display: flex; background: var(--panel3); border-radius: 13px; padding: 4px; margin-bottom: 22px; gap: 4px; }
.auth-tab { flex: 1; padding: 11px; border-radius: 10px; color: var(--text2); font-weight: 600; font-size: 14.5px; transition: background var(--t-out) var(--ease-out), color var(--t-out) var(--ease-out), transform 90ms var(--ease-out); }
.auth-tab:active { transform: scale(.97); }
.auth-tab.active { background: var(--blush); color: var(--accent-ink); }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 7px; }
.form-group label { font-size: 12.5px; color: var(--text2); font-weight: 600; letter-spacing: .3px; text-transform: uppercase; }
.form-group input, .field-input {
  width: 100%; background: var(--panel3); border: 1.5px solid transparent; border-radius: 13px;
  padding: 14px 15px; font-size: 16px; outline: none; transition: border-color .2s, background .2s;
}
.form-group input:focus, .field-input:focus { border-color: var(--accent-h); background: var(--field); }
.auth-msg { min-height: 18px; font-size: 13.5px; text-align: center; }
.auth-msg.error { color: var(--danger); }
.auth-msg.success { color: var(--accent-h); }
.btn-primary {
  background: var(--blush); color: var(--accent-ink); font-weight: 700;
  padding: 15px; border-radius: 14px; font-size: 16px; width: 100%;
  transition: transform 90ms var(--ease-out), opacity .2s;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .6; }
.btn-ghost { padding: 13px 16px; border-radius: 13px; background: var(--panel2); font-weight: 600; font-size: 15px; }
label.btn-primary, label.btn-ghost { display: flex; align-items: center; justify-content: center; cursor: pointer; }
.btn-danger { background: rgba(241,92,109,.15); color: var(--danger); }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.install-hint { margin-top: 14px; font-size: 12.5px; color: var(--text2); text-align: center; line-height: 1.5; }

/* ═══════════════ PIN lock ═══════════════ */
.lock {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-t)) 20px calc(16px + var(--safe-b));
  background:
    radial-gradient(ellipse 90% 36% at 50% -12%, rgba(82,171,152,.14), transparent 68%),
    var(--bg);
  height: var(--app-h, 100dvh);
}
.lock-avatar {
  width: 76px; height: 76px; border-radius: 22px; margin-bottom: 14px;
  background: var(--blush);
  display: flex; align-items: center; justify-content: center;
}
.lock-avatar::before { content: "🕊️"; font-size: 36px; }
.lock-title { font-size: 20px; font-weight: 700; }
.lock-sub { font-size: 14px; color: var(--text2); margin-top: 6px; min-height: 20px; text-align: center; }
.lock-sub.error { color: var(--danger); }
.dots { display: flex; gap: 18px; margin: 26px 0 26px; }
.dot { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--dot); transition: background 140ms var(--ease-out), border-color 140ms var(--ease-out), transform 140ms var(--ease-out); }
.dot.filled { background: var(--accent-h); border-color: var(--accent-h); transform: scale(1.12); }
.dots.shake { animation: shake .45s; }
@keyframes shake { 20%,60% { transform: translateX(-10px); } 40%,80% { transform: translateX(10px); } }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 22px; width: min(300px, 82vw); }
.pad button {
  aspect-ratio: 1; border-radius: 50%; background: var(--pad-key); color: var(--text);
  font-size: 28px; font-weight: 500; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 0 rgba(43,103,119,.08);
  transition: background 120ms var(--ease-out), transform 90ms var(--ease-out); user-select: none;
}
.pad button:active { background: var(--panel2); transform: scale(.97); }
.pad .pad-empty { background: none; pointer-events: none; }
.pad .pad-del { background: none; color: var(--text2); }
.lock-link { margin-top: 22px; color: var(--accent-h); font-size: 14.5px; font-weight: 600; padding: 8px 12px; }
.lock-forgot { width: min(320px, 86vw); display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
@media (max-height: 640px) {
  .lock-avatar { width: 56px; height: 56px; margin-bottom: 8px; }
  .dots { margin: 14px 0; }
  .pad { gap: 8px 18px; width: min(250px, 70vw); }
  .pad button { font-size: 24px; }
}

/* ═══════════════ App shell ═══════════════ */
.app {
  position: fixed; inset: 0;
  height: var(--app-h, 100dvh);
  display: flex; flex-direction: column;
  background: var(--wall);
  background-image: radial-gradient(ellipse 100% 32% at 50% -10%, rgba(200,216,228,.85), transparent 70%);
}
.topbar {
  display: flex; align-items: center; gap: 12px; flex: none;
  padding: calc(8px + var(--safe-t)) calc(8px + var(--safe-r)) 8px calc(14px + var(--safe-l));
  background: var(--panel);
  box-shadow: 0 1px 0 var(--border);
  z-index: 5; min-height: calc(60px + var(--safe-t));
}
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--blush); color: var(--accent-ink); font-weight: 600; font-size: 18px; text-transform: uppercase;
}
.top-info { flex: 1; min-width: 0; }
.top-name { font-weight: 600; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-status { font-size: 12.5px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.top-status.online, .top-status.typing { color: var(--accent-h); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text2); transition: background 120ms var(--ease-out), transform 90ms var(--ease-out); }
.icon-btn:active { background: rgba(43,103,119,.08); transform: scale(.97); }

.banner {
  display: flex; align-items: center; gap: 10px; flex: none;
  background: var(--banner); color: var(--text); padding: 10px 12px 10px 16px; font-size: 14px; border-bottom: 1px solid var(--border);
  animation: rise var(--t-in) var(--ease-out);
}
.banner span { flex: 1; line-height: 1.35; }
.banner button.act { background: var(--blush); color: var(--accent-ink); padding: 8px 14px; border-radius: 18px; font-weight: 600; font-size: 13.5px; }
.banner button.act:active { transform: scale(.97); }
.banner button.x { color: var(--text2); padding: 6px; }

/* ═══════════════ Messages ═══════════════ */
.messages {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; position: relative;
  padding: 10px calc(10px + var(--safe-r)) 8px calc(10px + var(--safe-l));
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  scroll-behavior: auto;
}
.loader { display: flex; justify-content: center; padding: 14px; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(43,103,119,.15); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-chat { text-align: center; color: var(--text2); font-size: 14px; padding: 40px 30px; line-height: 1.6; }
.empty-chat b { display: block; font-size: 17px; color: var(--text); margin-bottom: 6px; }

.day { display: flex; justify-content: center; margin: 12px 0 8px; position: sticky; top: 0; z-index: 2; pointer-events: none; }
.day span { background: var(--day-bg); color: var(--accent); font-size: 12.5px; padding: 5px 12px; border-radius: 9px; border: 1px solid var(--panel2); }

.row { display: flex; margin-top: 2px; }
.row.first { margin-top: 9px; }
.row.mine { justify-content: flex-end; }
.row.in { animation: none; }

.bubble {
  position: relative; max-width: min(82%, 520px); display: flow-root;
  padding: 6px 9px 7px; border-radius: 17px;
  font-size: 15.5px; line-height: 1.33;
  box-shadow: 0 1px 1px rgba(43,103,119,.05);
  border: 1px solid transparent;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.mine .bubble { background: var(--bubble-me); color: var(--on-me); border-color: transparent; }
.theirs .bubble { background: var(--bubble-them); color: var(--text); border-color: var(--them-border); }
.mine .meta { color: rgba(255,255,255,.78); }
.theirs .meta { color: #6d8b94; }
.mine .tick { fill: rgba(255,255,255,.8); }
.mine .tick.read { fill: var(--on-me-soft); }
.theirs .tick.read { fill: var(--tick-read); }
.mine .txt a { color: var(--on-me-soft); }
.theirs .txt a { color: var(--accent); }
.mine.first .bubble { border-top-right-radius: 5px; }
.theirs.first .bubble { border-top-left-radius: 5px; }
.bubble.pressed { filter: brightness(.96); }
.txt { font-family: "Phoenix Arabic", system-ui, sans-serif; white-space: pre-wrap; word-break: normal; overflow-wrap: break-word; text-align: start; -webkit-user-select: text; user-select: text; }
.txt a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.meta {
  display: inline-flex; align-items: center; gap: 3px; float: none;
  margin: 0 0 0 0; margin-inline-start: 8px; vertical-align: bottom; position: relative; top: 4px;
  font-size: 11px; line-height: 1; color: var(--meta); white-space: nowrap;
}
.tick { width: 17px; height: 17px; fill: var(--meta); }
.tick.read { fill: var(--tick-read); }
.tick.pending { width: 13px; height: 13px; }

/* image */
.bubble.image { padding: 3px; }
.img-wrap {
  position: relative; display: inline-block; max-width: min(72vw, 320px);
  border-radius: 14px; overflow: hidden; background: rgba(0,0,0,.25); line-height: 0;
}
.img-wrap img {
  display: block; width: auto; height: auto;
  max-width: min(72vw, 320px); max-height: min(52vh, 480px);
  object-fit: contain;
}
.bubble.image .caption { display: block; padding: 6px 6px 2px; }
.bubble.image .meta { display: flex; justify-content: flex-end; width: 100%; margin: 2px 4px 1px; top: 0; box-sizing: border-box; }
.bubble.image.nocap .meta {
  position: absolute; right: 8px; bottom: 8px; top: auto; width: auto; margin: 0; padding: 3px 7px; border-radius: 10px; float: none;
  background: rgba(0,0,0,.45); color: #fff;
}
.bubble.image.nocap .tick { fill: #fff; } .bubble.image.nocap .tick.read { fill: var(--tick-read); }
.uploading::after {
  content: ''; position: absolute; inset: 0; background: rgba(0,0,0,.35);
  display: block;
}
.uploading::before {
  content: ''; position: absolute; z-index: 1; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .8s linear infinite;
}

/* sticker */
.row.sticker .bubble { background: none; box-shadow: none; padding: 0; border: 0; }
.sticker-img { width: 140px; height: 140px; object-fit: contain; display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); }
.row.sticker .meta {
  float: none; position: absolute; top: auto; right: 2px; bottom: 2px; margin: 0; padding: 3px 7px; border-radius: 10px; background: rgba(0,0,0,.45); color: #fff;
}
.row.sticker .tick { fill: #fff; } .row.sticker .tick.read { fill: var(--tick-read); }

/* voice */
.voice { display: flex; align-items: center; gap: 8px; width: min(64vw, 270px); padding: 2px 0 2px; }
.vbtn { width: 40px; height: 40px; border-radius: 50%; background: rgba(43,103,119,.1); display: flex; align-items: center; justify-content: center; flex: none; transition: transform 90ms var(--ease-out), background 120ms var(--ease-out); }
.vbtn:active { background: rgba(43,103,119,.18); transform: scale(.97); }
.mine .vbtn { background: rgba(255,255,255,.18); }
.vmid { flex: 1; min-width: 0; }
.wave { display: flex; align-items: center; gap: 2px; height: 28px; cursor: pointer; touch-action: none; }
.wave i { flex: 1; min-width: 2px; border-radius: 2px; background: rgba(43,103,119,.22); transition: background .12s var(--ease-out); }
.wave i.on { background: var(--accent); }
.mine .wave i { background: rgba(255,255,255,.35); }
.mine .wave i.on { background: var(--on-me); }
.vdur { font-size: 11.5px; color: var(--meta); margin-top: 1px; }
.bubble.voicemsg .meta { display: flex; justify-content: flex-end; width: 100%; margin: 2px 0 0; top: 0; }

/* deleted */
.bubble.deleted { background: var(--field) !important; color: var(--text2); font-style: italic; box-shadow: none; border: 1px dashed var(--field-border); }
.mine .bubble.deleted { background: #e7eef1 !important; color: #4d6b74; }
.reveal-btn {
  display: inline-flex; align-items: center; gap: 5px; margin-left: 8px; font-style: normal; font-size: 12.5px; font-weight: 600;
  color: var(--accent); background: rgba(82,171,152,.16); padding: 4px 9px; border-radius: 12px;
}
.reveal-btn .ic { width: 15px; height: 15px; }
.orig { margin-top: 8px; padding: 8px; border-radius: 12px; background: #f2f2f2; border-left: 3px solid var(--danger); font-style: normal; color: var(--text); }
.orig .tag { font-size: 11px; color: var(--danger); margin-bottom: 4px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; }
.orig .img-wrap { width: min(60vw, 240px); }
.orig .sticker-img { width: 110px; height: 110px; }
.orig audio { width: min(60vw, 240px); height: 36px; }

.fab {
  position: absolute; right: 14px; bottom: 12px; z-index: 6; width: 44px; height: 44px; border-radius: 50%;
  background: var(--panel); color: var(--text2); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(43,103,119,.16); transition: transform 160ms var(--ease-out), opacity 160ms var(--ease-out);
}
.fab.hide { opacity: 0; transform: scale(.6); pointer-events: none; }
.fab .badge { position: absolute; top: -7px; right: -2px; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 5px; background: var(--blush); color: var(--accent-ink); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.fab .badge:empty { display: none; }
.messages-wrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }

/* ═══════════════ Composer ═══════════════ */
.composer-wrap { flex: none; position: relative; z-index: 4; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 6px calc(8px + var(--safe-r)) 6px calc(8px + var(--safe-l)); min-width: 0; }
.composer-wrap.no-panel .composer { padding-bottom: calc(6px + var(--safe-b)); }
.field { flex: 1; min-width: 0; display: flex; align-items: flex-end; background: var(--field); border: 1px solid var(--field-border); border-radius: 26px; transition: border-color 180ms var(--ease-out); }
.field:focus-within { border-color: var(--accent-h); }
.field textarea {
  flex: 1; min-width: 0; resize: none; background: none; border: 0; outline: none; padding: 12px 2px;
  font-size: 16.5px; line-height: 1.3; max-height: 130px; overflow-y: auto; caret-color: var(--accent-h);
}
.field textarea::placeholder { color: var(--text2); }
.tool-btn { width: 46px; height: 48px; display: flex; align-items: center; justify-content: center; color: var(--text2); flex: none; transition: color .15s; }
.tool-btn.active { color: var(--accent-h); }
.tool-btn:active { color: var(--text); }
.round-btn {
  width: 50px; height: 50px; border-radius: 50%; flex: 0 0 50px; background: var(--send); color: var(--send-ink);
  display: flex; align-items: center; justify-content: center; transition: transform 90ms var(--ease-out), background var(--t-out) var(--ease-out);
}
.round-btn:active { transform: scale(.97); }
.round-btn .ic { position: absolute; transition: transform var(--t-out) var(--ease-out), opacity 160ms var(--ease-out), filter 160ms var(--ease-out); }
.round-btn { position: relative; }
.round-btn .i-send { transform: scale(.92); opacity: 0; filter: blur(2px); }
.composer.has-text .round-btn .i-mic, .composer.recording .round-btn .i-mic { transform: scale(.92); opacity: 0; filter: blur(2px); }
.composer.has-text .round-btn .i-send, .composer.recording .round-btn .i-send { transform: none; opacity: 1; filter: none; }

.rec-bar { flex: 1; min-width: 0; display: none; align-items: center; gap: 10px; background: var(--field); border: 1px solid var(--field-border); border-radius: 26px; padding: 0 6px 0 4px; height: 50px; }
.composer.recording .field { display: none; }
.composer.recording .rec-bar { display: flex; }
.rec-bar .del { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--danger); }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.rec-time { font-variant-numeric: tabular-nums; font-size: 16px; min-width: 42px; }
.rec-level { flex: 1; min-width: 0; height: 26px; display: flex; align-items: center; gap: 3px; overflow: hidden; justify-content: flex-end; }
.rec-level i { width: 3px; min-height: 3px; border-radius: 2px; background: var(--accent-h); flex: none; }

/* ═══════════════ Emoji / sticker panel ═══════════════ */
.panel {
  height: 0; overflow: hidden; background: var(--panel); border-radius: 18px 18px 0 0;
  transition: height var(--t-in) var(--ease-out); display: flex; flex-direction: column;
  box-shadow: 0 -8px 24px rgba(43,103,119,.08);
}
.panel.open { height: min(46vh, 360px); height: min(46dvh, 360px); padding-bottom: var(--safe-b); }
.panel-tabs { display: flex; align-items: center; flex: none; height: 46px; padding: 0 6px; border-bottom: 1px solid var(--border); }
.ptab { width: 56px; height: 46px; display: flex; align-items: center; justify-content: center; color: var(--text2); position: relative; filter: grayscale(1); }
.ptab.active { color: var(--accent-h); filter: none; }
.ptab.active::after { content: ''; position: absolute; left: 12px; right: 12px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent-h); }
.ptab-space { flex: 1; }
.pane { flex: 1; min-height: 0; display: none; flex-direction: column; }
.pane.active { display: flex; }

.cat-strip, .pack-strip { display: flex; gap: 2px; padding: 4px 6px; overflow-x: auto; flex: none; scrollbar-width: none; align-items: center; }
.cat-strip::-webkit-scrollbar, .pack-strip::-webkit-scrollbar { display: none; }
.cat-btn { min-width: 40px; height: 36px; border-radius: 10px; font-size: 20px; filter: grayscale(1) opacity(.7); display: flex; align-items: center; justify-content: center; flex: none; color: var(--text2); }
.cat-btn.active { background: var(--panel2); filter: none; }
.emoji-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 6px 8px; }
.emoji-sec h4 { font-size: 12.5px; font-weight: 600; color: var(--text2); padding: 10px 6px 4px; letter-spacing: .3px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
.emoji-grid button { height: 44px; font-size: 27px; border-radius: 10px; display: flex; align-items: center; justify-content: center; transition: transform 90ms var(--ease-out), background 120ms var(--ease-out); }
.emoji-grid button:active { background: var(--panel2); transform: scale(.92); }

.pack-btn { width: 46px; height: 42px; border-radius: 10px; flex: none; display: flex; align-items: center; justify-content: center; color: var(--text2); position: relative; }
.pack-btn img { width: 30px; height: 30px; object-fit: contain; filter: grayscale(.8) opacity(.7); transition: filter .15s; }
.pack-btn.active { background: var(--panel2); color: var(--accent-h); }
.pack-btn.active img { filter: none; }
.pack-sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; flex: none; }
.pack-head { display: flex; align-items: center; padding: 2px 6px 2px 14px; flex: none; }
.pack-head b { flex: 1; font-size: 13px; color: var(--text2); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pack-head button { width: 38px; height: 34px; color: var(--text2); display: flex; align-items: center; justify-content: center; }
.sticker-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 8px 10px; }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
@media (min-width: 560px) { .sticker-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); } }
.sticker-cell { aspect-ratio: 1; border-radius: 12px; display: flex; align-items: center; justify-content: center; padding: 4px; user-select: none; -webkit-touch-callout: none; transition: transform 90ms var(--ease-out), background 140ms var(--ease-out); }
.sticker-cell:active { background: var(--panel2); transform: scale(.94); }
.sticker-cell img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.sticker-empty { margin: auto; text-align: center; padding: 18px 26px; color: var(--text2); font-size: 14px; line-height: 1.5; }
.sticker-empty .big { font-size: 40px; margin-bottom: 6px; filter: grayscale(1); }
.sticker-empty button { margin-top: 14px; background: var(--blush); color: var(--accent-ink); padding: 11px 22px; border-radius: 22px; font-weight: 600; }
.sticker-empty button:active { transform: scale(.97); }
.emoji-search { margin: 6px 8px 0; background: var(--field); border: 1px solid var(--field-border); border-radius: 12px; padding: 8px 12px; font-size: 15px; outline: none; width: calc(100% - 16px); }
.emoji-search:focus { border-color: var(--accent-h); }
.auth-card .pad { margin: 4px auto 0; }
.auth-card .dots { margin: 14px auto 10px; }
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px; }
.theme-swatch { border-radius: 14px; padding: 10px 8px; border: 2px solid transparent; background: var(--panel2); font-size: 13px; font-weight: 650; }
.theme-swatch.on { border-color: var(--accent-h); }
.theme-swatch i { display: block; width: 28px; height: 28px; border-radius: 50%; margin: 0 auto 6px; }
.maker { position: fixed; inset: 0; z-index: 190; background: #0c0c0c; display: none; flex-direction: column; height: var(--app-h, 100dvh); }
.maker.open { display: flex; }
.maker-top, .maker-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; color: #fff; }
.maker-top { padding-top: calc(8px + var(--safe-t)); }
.maker-bar { padding-bottom: calc(10px + var(--safe-b)); }
.maker-stage { flex: 1; display: flex; align-items: center; justify-content: center; touch-action: none; }
.maker canvas { width: min(86vw, 420px); height: min(86vw, 420px); border-radius: 18px; background: transparent; box-shadow: 0 0 0 1px rgba(255,255,255,.2); }
.maker input[type=range] { flex: 1; }
.maker .round-btn { background: var(--send); color: var(--send-ink); }

/* ═══════════════ Sheets / modals / pages ═══════════════ */
.backdrop { position: fixed; inset: 0; z-index: 150; background: rgba(29,60,70,.28); opacity: 0; pointer-events: none; transition: opacity var(--t-out) ease; display: flex; align-items: flex-end; justify-content: center; }
.backdrop.open { opacity: 1; pointer-events: auto; transition: opacity var(--t-in) var(--ease-out); }
.sheet {
  width: 100%; max-width: 520px; background: var(--panel); border-radius: 22px 22px 0 0;
  padding: 8px 8px calc(10px + var(--safe-b)); transform: translateY(100%); transition: transform var(--t-out) var(--ease-inout);
  max-height: 88vh; max-height: 88dvh; overflow-y: auto;
}
.backdrop.open .sheet { transform: none; transition: transform var(--t-in) var(--ease-out); }
.sheet::before { content: ''; display: block; width: 38px; height: 4px; border-radius: 4px; background: var(--panel2); margin: 4px auto 8px; }
.sheet-title { padding: 6px 14px 10px; font-weight: 700; font-size: 16px; }
.sheet-item { display: flex; align-items: center; gap: 16px; width: 100%; padding: 15px 14px; border-radius: 14px; font-size: 16px; text-align: left; }
.sheet-item:active { background: var(--panel2); }
.sheet-item .ic { color: var(--text2); }
.sheet-item.danger, .sheet-item.danger .ic { color: var(--danger); }
.sheet-note { padding: 4px 14px 10px; font-size: 13px; color: var(--text2); line-height: 1.5; }
.sheet form, .sheet .pad-y { padding: 4px 8px 6px; display: flex; flex-direction: column; gap: 12px; }

.page {
  position: fixed; inset: 0; z-index: 120; background: var(--bg); display: flex; flex-direction: column;
  height: var(--app-h, 100dvh); transform: translateX(100%); transition: transform var(--t-out) var(--ease-inout), visibility var(--t-out); visibility: hidden;
}
.page.open { transform: none; visibility: visible; transition: transform var(--t-in) var(--ease-out), visibility 0s; }
.page-head { display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--safe-t)) 8px 6px 6px; background: var(--panel); flex: none; min-height: calc(58px + var(--safe-t)); }
.page-head h2 { font-size: 19px; font-weight: 600; flex: 1; }
.page-body { flex: 1; overflow-y: auto; padding: 14px 14px calc(24px + var(--safe-b)); overscroll-behavior: contain; }
.card { background: var(--panel); border-radius: 18px; padding: 6px; margin-bottom: 14px; }
.card h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent-h); padding: 12px 12px 6px; }
.item { display: flex; align-items: center; gap: 14px; padding: 13px 12px; border-radius: 13px; width: 100%; text-align: left; }
button.item:active { background: var(--panel2); }
.item .ic { color: var(--text2); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-size: 16px; } .item .s { font-size: 13px; color: var(--text2); margin-top: 2px; line-height: 1.35; }
.item.danger .t, .item.danger .ic { color: var(--danger); }
.inline-form { padding: 6px 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.profile { display: flex; align-items: center; gap: 16px; padding: 16px 12px; }
.profile .avatar { width: 62px; height: 62px; font-size: 26px; }
.chip { font-size: 11px; background: rgba(82,171,152,.16); color: var(--accent); padding: 3px 8px; border-radius: 9px; font-weight: 700; margin-left: 8px; vertical-align: middle; }
.switch { width: 46px; height: 26px; border-radius: 13px; background: var(--panel2); position: relative; flex: none; transition: background var(--t-out) var(--ease-inout); }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--taupe); transition: transform var(--t-out) var(--ease-inout), background var(--t-out) var(--ease-inout); }
.switch.on { background: var(--blush); } .switch.on::after { transform: translateX(20px); background: var(--accent-ink); }

.del-item { background: var(--panel); border-radius: 16px; padding: 12px; margin-bottom: 12px; border-left: 4px solid var(--danger); }
.del-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 12.5px; color: var(--text2); margin-bottom: 8px; flex-wrap: wrap; }
.del-head b { color: var(--text); font-size: 14.5px; }
.del-body .txt { font-size: 15.5px; }
.del-body img.thumb { max-width: 100%; max-height: 300px; border-radius: 12px; display: block; }
.del-body img.stk { width: 120px; height: 120px; object-fit: contain; }
.del-body audio { width: 100%; }
.muted { color: var(--text2); font-size: 14px; text-align: center; padding: 30px 16px; }

/* image preview + lightbox */
.viewer { position: fixed; inset: 0; z-index: 180; background: #000; display: none; flex-direction: column; height: var(--app-h, 100dvh); }
.viewer.open { display: flex; }
.viewer-top { display: flex; align-items: center; padding: calc(6px + var(--safe-t)) 8px 6px; flex: none; }
.viewer-top .spacer { flex: 1; }
.viewer-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: auto; touch-action: pinch-zoom pan-x pan-y; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-bar { display: none; align-items: flex-end; gap: 8px; padding: 8px calc(8px + var(--safe-r)) calc(8px + var(--safe-b)) calc(8px + var(--safe-l)); background: rgba(0,0,0,.6); }
.viewer.compose .viewer-bar { display: flex; }
.viewer-bar textarea { flex: 1; background: var(--panel); border: 0; outline: none; border-radius: 24px; padding: 13px 16px; resize: none; max-height: 110px; font-size: 16px; }

.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(86px + var(--safe-b)); z-index: 300; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--toast); color: var(--on-me); padding: 10px 16px; border-radius: 22px; font-size: 14px; box-shadow: 0 8px 24px rgba(43,103,119,.2); max-width: 86vw; animation: rise var(--t-in) var(--ease-out); }
.toast.error { background: #8d3d4a; }
.toast.out { opacity: 0; transition: opacity .3s; }

#privacy { position: fixed; inset: 0; z-index: 250; background: var(--bg); display: none; align-items: center; justify-content: center; }
body.is-hidden #privacy { display: flex; }
#privacy .lock-avatar { margin: 0; }

/* wide screens: keep the chat as a centred phone-like column */
@media (min-width: 700px) {
  .app, .lock-wide { max-width: 760px; left: 50%; transform: translateX(-50%); width: 100%; box-shadow: 0 0 0 1px rgba(43,103,119,.1); }
  body { background: var(--wide); }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ══ Settings page ══════════════════════════════════════════════════════════ */
.s-profile {
  display: flex; flex-direction: column; align-items: center;
  padding: 28px 16px 20px; gap: 6px;
}
.s-avatar {
  width: 72px; height: 72px; font-size: 30px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
.s-username { font-size: 20px; font-weight: 700; color: var(--text); }
.s-role { font-size: 13px; color: var(--text2); }

.s-divider {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 6px; font-size: 12px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--accent-h);
}
.s-divider::before, .s-divider::after { content: ''; flex: 1; height: 1px; background: var(--divider); }
.s-divider:empty::before { flex: 0; } .s-divider:empty::after { flex: 1; }

.s-row {
  padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  border-bottom: 1px solid rgba(43,103,119,.08);
}
.s-label { font-size: 15px; color: var(--text2); flex: 1 1 120px; }
.s-value { display: flex; align-items: center; gap: 8px; }
.s-note { flex: 1 1 100%; font-size: 12px; color: var(--text2); opacity: .7; padding-top: 2px; }
.s-note-inline { font-size: 13.5px; color: var(--text2); }

.s-btn {
  background: var(--panel2); border: 0; border-radius: 20px;
  color: var(--text); padding: 8px 18px; font-size: 14px; cursor: pointer;
  transition: background .15s;
}
.s-btn:hover { background: var(--panel3); }
.s-btn.active { background: var(--accent); color: #fff; }
.s-btn.danger { color: var(--danger); }
.s-btn.full-width { width: calc(100% - 32px); margin: 0 16px; border-radius: 12px; padding: 13px; font-size: 15.5px; font-weight: 600; }
.s-btn:disabled { opacity: .45; cursor: default; }

.s-inline-btn {
  background: none; border: 0; padding: 6px; color: var(--text2); cursor: pointer;
  display: flex; align-items: center; border-radius: 50%;
}
.s-inline-btn:hover { background: var(--panel2); }

.s-inline-form {
  padding: 10px 16px 16px; display: flex; flex-direction: column; gap: 10px;
  border-bottom: 1px solid rgba(43,103,119,.08);
}
.s-err { color: var(--danger); font-size: 13px; min-height: 18px; }
.s-empty { text-align: center; padding: 48px 16px; color: var(--text2); font-size: 15px; }

/* ══ Admin: deleted message cards ═══════════════════════════════════════════ */
.del-card {
  background: var(--panel); border-radius: 16px; margin: 10px 12px;
  overflow: hidden; border-left: 4px solid var(--danger);
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.del-meta {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px;
  padding: 10px 14px 6px; border-bottom: 1px solid var(--border);
}
.del-sender { font-weight: 700; font-size: 14px; color: var(--text); }
.del-time { font-size: 12px; color: var(--text2); }
.del-badge {
  font-size: 11.5px; background: rgba(224,154,166,.16); color: var(--danger);
  padding: 2px 8px; border-radius: 9px; font-weight: 600;
}
.del-text { padding: 10px 14px; font-size: 15.5px; line-height: 1.5; word-break: break-word; }
.del-img { display: block; max-width: 100%; max-height: 320px; object-fit: cover; border-radius: 0 0 12px 12px; }
.del-sticker { display: block; width: 120px; height: 120px; object-fit: contain; margin: 10px 14px; }
.del-audio { display: block; width: calc(100% - 28px); margin: 10px 14px; }
.del-caption { padding: 6px 14px 10px; font-size: 14px; color: var(--text2); }
.del-err { color: var(--danger); }
