/* ============ Nido — design system ============
   Warm "paper" aesthetic. Hand-crafted, not templated.
   Light + dark, mobile-first, safe-area aware.               */

:root {
  --brand-500: #ED744B;
  --brand-600: #E4633A;
  --brand-700: #C94F2B;
  --brand-900: #7A2D17;
  --egg: #FBE7C6;

  --bg: #F1E9DD;
  --bg-2: #E7DBC9;
  --surface: #FFFCF6;
  --surface-2: #F6EFE3;
  --ink: #2B2621;
  --muted: #8C8073;
  --line: rgba(43, 38, 33, .10);
  --line-2: rgba(43, 38, 33, .06);
  --bubble-me: #F6D9C6;
  --bubble-me-ink: #5A2B15;
  --bubble-you: #FFFFFF;
  --shadow-sm: 0 1px 2px rgba(60, 40, 20, .06), 0 1px 3px rgba(60, 40, 20, .05);
  --shadow-md: 0 6px 20px rgba(70, 45, 25, .12);
  --shadow-lg: 0 18px 50px rgba(50, 30, 15, .22);
  --ok: #3E9E6B;
  --danger: #D6473B;
  --online: #46C36A;

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 30px;

  --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

:root[data-theme="dark"] {
  --bg: #161310;
  --bg-2: #100E0B;
  --surface: #221D18;
  --surface-2: #2B241D;
  --ink: #F0E7DA;
  --muted: #A99C8B;
  --line: rgba(255, 250, 242, .10);
  --line-2: rgba(255, 250, 242, .05);
  --bubble-me: #7A3A1E;
  --bubble-me-ink: #FFE7D6;
  --bubble-you: #2B241D;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .4);
  --shadow-lg: 0 20px 55px rgba(0, 0, 0, .55);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161310; --bg-2: #100E0B; --surface: #221D18; --surface-2: #2B241D;
    --ink: #F0E7DA; --muted: #A99C8B; --line: rgba(255,250,242,.10); --line-2: rgba(255,250,242,.05);
    --bubble-me: #7A3A1E; --bubble-me-ink: #FFE7D6; --bubble-you: #2B241D;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow-md: 0 8px 24px rgba(0,0,0,.4); --shadow-lg: 0 20px 55px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
/* The root background paints the whole screen canvas, incl. iOS's reserved bottom strip below the app,
   so match it to the composer surface — the strip blends in instead of reading as a dark bar. */
html { background: var(--surface); }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  /* subtle warm paper grain */
  background-image:
    radial-gradient(120% 90% at 12% 0%, rgba(237,116,75,.07), transparent 60%),
    radial-gradient(120% 90% at 100% 100%, rgba(138,160,232,.06), transparent 55%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.028'/%3E%3C/svg%3E");
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
input, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
img, video { display: block; max-width: 100%; }
::selection { background: rgba(237,116,75,.28); }

/* Anchored to the ACTUAL visual viewport (top + height come from visualViewport in JS), so there is
   never a reserved strip below the app and the composer sits on the real screen bottom. The keyboard
   is handled automatically: visualViewport.height shrinks when it opens. Fallback: full height. */
.app { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vv-h, 100%); overflow: hidden; }

.hidden { display: none !important; }

/* ---------- generic bits ---------- */
.icon svg, svg.i { width: 100%; height: 100%; display: block; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 22px; border-radius: var(--r-md);
  background: var(--brand-600); color: #fff; font-weight: 650; font-size: 16px;
  box-shadow: var(--shadow-sm); transition: transform .12s ease, filter .15s ease;
  width: 100%;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:hover { filter: brightness(1.03); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: none; border: 1.5px solid var(--line); }
.btn.danger { background: var(--danger); }

.field { position: relative; margin-bottom: 14px; }
.field input, .field textarea {
  width: 100%; background: var(--surface); border: 1.6px solid var(--line);
  border-radius: var(--r-md); padding: 16px 16px 16px 16px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease; resize: none;
}
.field input:focus, .field textarea:focus {
  border-color: var(--brand-500); box-shadow: 0 0 0 4px rgba(237,116,75,.14);
}
.field label { display: block; font-size: 13.5px; font-weight: 600; color: var(--muted); margin: 0 4px 7px; }
.hint { color: var(--muted); font-size: 13px; }
.error-text { color: var(--danger); font-size: 13.5px; min-height: 18px; margin: 2px 4px; font-weight: 600; }

/* ================= AUTH ================= */
.auth {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 24px;
  padding-top: calc(24px + var(--safe-t)); overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-xl); padding: 30px 26px;
  box-shadow: var(--shadow-lg);
}
.brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 6px; }
.brand .word { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.brand .word b { color: var(--brand-600); }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: 14.5px; }
.tabs { display: flex; background: var(--surface-2); border-radius: 14px; padding: 5px; margin-bottom: 22px; }
.tabs button { flex: 1; height: 40px; border-radius: 10px; font-weight: 650; color: var(--muted); transition: .18s; }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.avatar-pick { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 18px; }
.avatar-pick .ring {
  width: 92px; height: 92px; border-radius: 50%; position: relative; cursor: pointer;
  border: 3px dashed var(--line); display: grid; place-items: center; overflow: hidden;
  background: var(--surface-2);
}
.avatar-pick .ring img { width: 100%; height: 100%; object-fit: cover; }
.avatar-pick .ring .plus { position: absolute; right: 2px; bottom: 2px; width: 28px; height: 28px; background: var(--brand-600); color: #fff; border-radius: 50%; display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.avatar-pick .ring .plus svg { width: 16px; height: 16px; }
.enc-note { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--muted); font-size: 12.5px; margin-top: 18px; }
.enc-note svg { width: 15px; height: 15px; }

/* ================= APP SHELL ================= */
/* Mobile: plain container + flex column (robust on iOS Safari, unlike nested grid `1fr` rows). */
.chat { position: absolute; inset: 0; }
@media (min-width: 920px) {
  .chat { display: grid; grid-template-columns: 340px 1fr; grid-template-rows: 1fr; max-width: 1240px; margin: 0 auto; box-shadow: var(--shadow-lg); }
  .rail { display: flex !important; position: static; }
  .chat-main { position: static !important; }
}
.rail {
  display: none; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line);
}
.rail-head { padding: calc(18px + var(--safe-t)) 20px 16px; border-bottom: 1px solid var(--line-2); }
.rail-head .brand { justify-content: flex-start; }
.rail-head .word { font-size: 22px; }
.rail-section { padding: 14px 16px 6px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.rail-members { overflow-y: auto; flex: 1; padding: 0 10px 16px; }
.rail-foot { padding: 12px 14px calc(14px + var(--safe-b)); border-top: 1px solid var(--line-2); display: flex; gap: 10px; align-items: center; }

.chat-main { position: absolute; inset: 0; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--chat-bg, radial-gradient(140% 60% at 50% -10%, rgba(237,116,75,.05), transparent 60%));
  background-size: cover; background-position: center; background-repeat: no-repeat; }

/* header */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; padding-top: calc(10px + var(--safe-t));
  background: color-mix(in srgb, var(--surface) 86%, transparent); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line); position: relative; z-index: 5;
}
.topbar .back { display: none; width: 40px; height: 40px; border-radius: 12px; padding: 9px; color: var(--ink); }
@media (max-width: 919px) { .topbar .back.show { display: block; } }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title h1 { margin: 0; font-size: 16.5px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title p { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title p .dot { color: var(--online); }
.iconbtn {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; color: var(--ink);
  transition: background .15s ease, transform .1s ease;
}
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn:hover { background: var(--surface-2); }
.iconbtn:active { transform: scale(.92); }
.iconbtn.accent { color: var(--brand-600); }

/* messages */
.messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 3px; scroll-behavior: smooth; }
.day-sep { align-self: center; margin: 12px 0 6px; font-size: 12px; font-weight: 650; color: var(--muted); background: var(--surface-2); padding: 5px 12px; border-radius: 20px; }
.sys-msg { align-self: center; font-size: 12.5px; color: var(--muted); padding: 4px 12px; }

.row { display: flex; gap: 8px; align-items: flex-end; max-width: 82%; }
.row.me { align-self: flex-end; flex-direction: row-reverse; }
.row .av { flex: 0 0 auto; }
.row.me .av { display: none; }
.row.grouped .av { visibility: hidden; }

.bubble {
  background: var(--bubble-you); color: var(--ink); padding: 9px 13px; border-radius: 18px;
  border-top-left-radius: 8px; box-shadow: var(--shadow-sm); position: relative; min-width: 44px;
  word-break: break-word; overflow-wrap: anywhere; line-height: 1.4; font-size: 15.5px;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.row.me .bubble { background: var(--bubble-me); color: var(--bubble-me-ink); border-radius: 18px; border-top-right-radius: 8px; }
.row.grouped .bubble { border-top-left-radius: 18px; }
.row.me.grouped .bubble { border-top-right-radius: 18px; }
.bubble .who { font-size: 12.5px; font-weight: 700; margin-bottom: 2px; }
.bubble .meta { display: flex; gap: 4px; align-items: center; justify-content: flex-end; font-size: 10.5px; color: var(--muted); margin-top: 3px; user-select: none; }
.row.me .bubble .meta { color: color-mix(in srgb, var(--bubble-me-ink) 60%, transparent); }
.bubble .meta svg { width: 15px; height: 15px; }
.bubble.media { padding: 5px; overflow: hidden; }
.bubble.media img, .bubble.media video { border-radius: 14px; max-height: 340px; width: auto; max-width: 100%; cursor: pointer; }
.bubble.media .cap { padding: 5px 8px 3px; }
.bubble.sticker-b { background: transparent !important; box-shadow: none; padding: 0; }
.bubble.sticker-b .sticker-media { line-height: 0; }
.bubble.sticker-b .sticker-media svg, .bubble.sticker-b .sticker-media img, .bubble.sticker-b .sticker-media video { width: 140px; height: 140px; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0,0,0,.16)); }
.bubble.sticker-b .meta { justify-content: flex-end; margin-top: 4px; opacity: .8; }
.bubble.sticker-b .meta svg { width: 14px; height: 14px; }

.reply-quote { border-left: 3px solid var(--brand-500); padding: 3px 9px; margin: 0 0 5px; background: rgba(237,116,75,.10); border-radius: 8px; font-size: 13px; }
.reply-quote b { display: block; color: var(--brand-700); font-size: 12px; }
.reply-quote span { color: var(--muted); }

/* file card */
.file-card { display: flex; align-items: center; gap: 11px; min-width: 200px; padding: 4px 2px; }
.file-card .fi { width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; color: var(--brand-600); flex: 0 0 auto; }
.file-card .fi svg { width: 22px; height: 22px; }
.file-card .fm { min-width: 0; flex: 1; }
.file-card .fm b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .fm span { font-size: 12px; color: var(--muted); }
.file-card .dl { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-600); color: #fff; flex: 0 0 auto; }
.file-card .dl svg { width: 20px; height: 20px; }

/* audio */
.audio-msg { display: flex; align-items: center; gap: 10px; min-width: 190px; padding: 3px 2px; }
.audio-msg .pp { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-600); color: #fff; display: grid; place-items: center; flex: 0 0 auto; }
.audio-msg .pp svg { width: 20px; height: 20px; }
.audio-msg .wave { flex: 1; height: 30px; display: flex; align-items: center; gap: 2.5px; }
.audio-msg .wave i { flex: 1; background: currentColor; opacity: .35; border-radius: 2px; min-height: 4px; }
.audio-msg .wave i.on { opacity: .9; }
.audio-msg .t { font-size: 12px; color: var(--muted); min-width: 34px; text-align: right; }

/* typing indicator */
.typing-row { display: flex; gap: 8px; align-items: center; align-self: flex-start; margin: 2px 0 4px; }
.typing { display: inline-flex; gap: 4px; background: var(--bubble-you); padding: 11px 14px; border-radius: 16px; box-shadow: var(--shadow-sm); }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2){ animation-delay: .2s; } .typing i:nth-child(3){ animation-delay: .4s; }
@keyframes blink { 0%,60%,100%{ transform: translateY(0); opacity:.4;} 30%{ transform: translateY(-4px); opacity:1;} }

/* avatars */
.avatar { border-radius: 50%; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; flex: 0 0 auto; font-weight: 750; color: #fff; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.s28 { width: 28px; height: 28px; font-size: 12px; }
.avatar.s40 { width: 40px; height: 40px; font-size: 15px; }
.avatar.s48 { width: 48px; height: 48px; font-size: 17px; }
.avatar.s96 { width: 96px; height: 96px; font-size: 34px; }
.avatar.s120 { width: 120px; height: 120px; font-size: 42px; }
.pres { position: relative; }
.pres .dot { position: absolute; right: -1px; bottom: -1px; width: 13px; height: 13px; border-radius: 50%; background: var(--muted); border: 2.5px solid var(--surface); }
.pres.online .dot { background: var(--online); }

/* member rows */
.mrow { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 14px; transition: background .15s; cursor: pointer; }
.mrow:hover { background: var(--surface-2); }
.mrow .mm { min-width: 0; flex: 1; }
.mrow .mm b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mrow .mm span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* ================= COMPOSER ================= */
.composer { flex: 0 0 auto; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); padding: 10px 10px; padding-bottom: max(10px, calc(var(--safe-b) - 16px)); }
/* keyboard open: the home indicator is hidden behind the keyboard, so no bottom cushion needed */
html.kb-open .composer { padding-bottom: 10px; }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 7px 10px; margin-bottom: 6px; background: var(--surface-2); border-radius: 12px; border-left: 3px solid var(--brand-500); }
.reply-bar .rb { flex: 1; min-width: 0; font-size: 13px; }
.reply-bar .rb b { color: var(--brand-700); display: block; font-size: 12px; }
.reply-bar .rb span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.composer-row { display: flex; align-items: flex-end; gap: 7px; }
.composer-input {
  flex: 1; display: flex; align-items: flex-end; gap: 4px; background: var(--surface);
  border: 1.6px solid var(--line); border-radius: var(--r-lg); padding: 3px 6px 3px 6px; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.composer-input:focus-within { border-color: var(--brand-500); box-shadow: 0 0 0 4px rgba(237,116,75,.12); }
.composer-input textarea {
  flex: 1; border: none; background: none; outline: none; resize: none; padding: 10px 4px; max-height: 130px;
  line-height: 1.35; min-width: 0;
}
/* side buttons: fixed square, centered on their own line so they sit level with a single-line input */
.composer .iconbtn { width: 44px; height: 44px; flex: 0 0 auto; align-self: flex-end; }
.composer-input .iconbtn { width: 40px; height: 40px; align-self: flex-end; }
.composer .iconbtn.plus svg { width: 24px; height: 24px; }
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; background: var(--brand-600); color: #fff;
  display: grid; place-items: center; box-shadow: var(--shadow-md); transition: transform .12s, background .2s;
  flex: 0 0 auto; align-self: flex-end;
}
.send-btn svg { width: 23px; height: 23px; }
.send-btn:active { transform: scale(.9); }
.send-btn.rec { background: var(--danger); animation: recpulse 1.2s infinite; }
@keyframes recpulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(214,71,59,.5);} 50%{ box-shadow: 0 0 0 10px rgba(214,71,59,0);} }

.rec-bar { display: flex; align-items: center; gap: 12px; padding: 6px 8px; }
.rec-bar .rdot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink2 1s infinite; }
@keyframes blink2 { 50% { opacity: .25; } }
.rec-bar .rt { font-variant-numeric: tabular-nums; font-weight: 650; }
.rec-bar .cancel { margin-left: auto; color: var(--danger); font-weight: 650; padding: 8px 12px; }

/* attach menu */
.attach-menu { position: absolute; bottom: 100%; left: 8px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 8px; box-shadow: var(--shadow-lg); display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; z-index: 30; animation: rise .18s ease; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.attach-menu button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 14px; border-radius: 14px; font-size: 12px; font-weight: 600; color: var(--ink); transition: background .15s; }
.attach-menu button:hover { background: var(--surface-2); }
.attach-menu button .ci { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; color: #fff; }
.attach-menu button .ci svg { width: 24px; height: 24px; }

/* ================= MEDIA EDITOR ================= */
.ed { position: fixed; inset: 0; z-index: 200; background: #0c0a08; color: #fff;
  display: flex; flex-direction: column; padding: calc(10px + var(--safe-t)) 12px calc(12px + var(--safe-b)); gap: 12px; }
.ed-head { text-align: center; font-weight: 700; font-size: 16px; opacity: .95; }
.ed-stage { flex: 1 1 auto; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.ed-cwrap { position: relative; display: inline-block; line-height: 0; max-width: 100%; max-height: 100%; }
.ed-canvas { display: block; max-width: 100%; max-height: 72vh; border-radius: 8px; touch-action: none; }
.ed-video { display: block; max-width: 100%; max-height: 62vh; border-radius: 10px; background: #000; }
.ed-crop { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 2000px rgba(0,0,0,.5); box-sizing: border-box; touch-action: none; cursor: move; }
.ed-crop::before, .ed-crop::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.ed-crop::before { border-left: 1px solid rgba(255,255,255,.35); border-right: 1px solid rgba(255,255,255,.35); left: 33.33%; right: 33.33%; }
.ed-crop::after { border-top: 1px solid rgba(255,255,255,.35); border-bottom: 1px solid rgba(255,255,255,.35); top: 33.33%; bottom: 33.33%; }
.ed-h { position: absolute; width: 26px; height: 26px; touch-action: none; }
.ed-h::after { content: ''; position: absolute; width: 16px; height: 16px; border: 3px solid #fff; }
.ed-h-tl { top: -13px; left: -13px; cursor: nwse-resize; } .ed-h-tl::after { top: 8px; left: 8px; border-right: 0; border-bottom: 0; border-radius: 4px 0 0 0; }
.ed-h-tr { top: -13px; right: -13px; cursor: nesw-resize; } .ed-h-tr::after { top: 8px; right: 8px; border-left: 0; border-bottom: 0; border-radius: 0 4px 0 0; }
.ed-h-bl { bottom: -13px; left: -13px; cursor: nesw-resize; } .ed-h-bl::after { bottom: 8px; left: 8px; border-right: 0; border-top: 0; border-radius: 0 0 0 4px; }
.ed-h-br { bottom: -13px; right: -13px; cursor: nwse-resize; } .ed-h-br::after { bottom: 8px; right: 8px; border-left: 0; border-top: 0; border-radius: 0 0 4px 0; }
.ed-chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ed-chip { padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.12); color: #fff; font-weight: 650; font-size: 13px; }
.ed-chip.on { background: #fff; color: #111; }
.ed-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ed-btn { padding: 12px 22px; border-radius: 999px; font-weight: 750; font-size: 15px; }
.ed-btn.ghost { background: rgba(255,255,255,.14); color: #fff; }
.ed-btn.send { background: var(--brand-600); color: #fff; box-shadow: var(--shadow-md); }
.ed-btn:disabled { opacity: .6; }
.ed-icon { width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; }
.ed-icon svg { width: 24px; height: 24px; }
.ed-times { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; font-size: 12.5px; opacity: .85; padding: 0 6px; }
.ed-trim { position: relative; height: 40px; border-radius: 10px; background: rgba(255,255,255,.12); margin: 0 6px; touch-action: none; }
.ed-trim-sel { position: absolute; top: 0; bottom: 0; background: rgba(237,116,75,.28); border-top: 2px solid var(--brand-500); border-bottom: 2px solid var(--brand-500); }
.ed-thumb { position: absolute; top: 50%; transform: translate(-50%,-50%); width: 16px; height: 46px; border-radius: 6px; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); touch-action: none; }
.ed-toggles { display: flex; gap: 10px; justify-content: center; }
.ed-tg { padding: 9px 16px; border-radius: 999px; background: rgba(255,255,255,.12); color: #fff; font-weight: 650; font-size: 13px; }
.ed-tg.on { background: var(--brand-600); color: #fff; }

/* ================= SHEETS / MODALS ================= */
.scrim { position: absolute; inset: 0; background: rgba(20,14,8,.5); backdrop-filter: blur(2px); z-index: 60; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--surface); z-index: 61;
  border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-lg);
  padding: 10px 18px calc(20px + var(--safe-b)); max-height: 86dvh; overflow-y: auto;
  animation: sheetUp .28s cubic-bezier(.16,1,.3,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } }
@media (min-width: 620px) {
  .sheet { left: 50%; right: auto; bottom: 50%; transform: translate(-50%, 50%); width: 460px; max-width: 92vw; border-radius: var(--r-xl); animation: sheetPop .24s ease; }
  @keyframes sheetPop { from { transform: translate(-50%, 50%) scale(.94); opacity: 0; } }
}
.sheet .grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 6px; border-bottom: 1px solid var(--line-2); }
.list-item:last-child { border-bottom: none; }
.list-item .li-ic { color: var(--brand-600); width: 24px; height: 24px; }
.list-item.danger .li-ic, .list-item.danger b { color: var(--danger); }

/* picker (sticker / gif) */
.picker { position: absolute; left: 6px; right: 6px; bottom: calc(100% + 8px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); z-index: 30; max-height: 46dvh; display: flex; flex-direction: column; animation: rise .18s ease; }
@media (min-width: 620px) { .picker { left: auto; width: 360px; } }
.picker-tabs { display: flex; gap: 4px; padding: 8px 8px 0; }
.picker-tabs button { flex: 1; height: 34px; border-radius: 10px; font-weight: 650; font-size: 13px; color: var(--muted); }
.picker-tabs button.active { background: var(--surface-2); color: var(--ink); }
.picker-body { overflow-y: auto; padding: 10px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.picker-body.emoji-grid { grid-template-columns: repeat(7, 1fr); }
.picker-body button { aspect-ratio: 1; border-radius: 14px; display: grid; place-items: center; transition: background .12s, transform .1s; touch-action: manipulation; }
.picker-body button:hover { background: var(--surface-2); }
.picker-body button:active { transform: scale(.9); }
.picker-body.emoji-grid button { font-size: 24px; }
.picker-body svg { width: 100%; height: 100%; }
.picker-body img { width: 100%; height: 100%; object-fit: contain; border-radius: 12px; }
.picker-body .cust video { width: 100%; height: 100%; object-fit: contain; border-radius: 12px; }
.picker-body .cust { position: relative; }
.picker-body .cust .del { position: absolute; top: -4px; right: -4px; width: 20px; height: 20px; border-radius: 50%; background: var(--danger); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow-sm); opacity: 0; transition: opacity .15s; }
.picker-body .cust .del svg { width: 12px; height: 12px; }
.picker-body .cust:hover .del { opacity: 1; }
@media (hover: none) { .picker-body .cust .del { opacity: 1; } }
.picker-add { aspect-ratio: 1; border-radius: 14px; display: grid; place-items: center; border: 2px dashed var(--line); color: var(--muted); flex-direction: column; gap: 2px; font-size: 11px; }
.picker-add svg { width: 22px; height: 22px; }
.picker-add:hover { border-color: var(--brand-500); color: var(--brand-600); }
.picker-empty { grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 13px; padding: 18px 8px; }
.gif-search { padding: 8px; }
.gif-search input { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1.4px solid var(--line); background: var(--surface-2); outline: none; }

/* profile view */
.profile-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 8px 0 16px; }
.profile-hero h2 { margin: 6px 0 0; }
.profile-hero .bio { color: var(--muted); font-size: 14.5px; max-width: 320px; line-height: 1.45; }

/* toast */
.toast-wrap { position: absolute; top: calc(14px + var(--safe-t)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 90; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 30px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); animation: toastIn .25s ease; max-width: 90%; }
@keyframes toastIn { from { transform: translateY(-14px); opacity: 0; } }

/* lightbox */
.lightbox { position: absolute; inset: 0; background: rgba(0,0,0,.92); z-index: 80; display: grid; place-items: center; animation: fade .2s; }
.lightbox img, .lightbox video { max-width: 96vw; max-height: 90dvh; border-radius: 10px; }
.lightbox .close { position: absolute; top: calc(14px + var(--safe-t)); right: 16px; width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; }
.lightbox .close svg { width: 24px; height: 24px; }

/* ================= CALL ================= */
.call { position: absolute; inset: 0; z-index: 70; background: #0d0b09; color: #fff; display: grid; grid-template-rows: auto 1fr auto; }
.call-top { padding: calc(16px + var(--safe-t)) 20px 10px; text-align: center; }
.call-top h2 { margin: 0; font-size: 18px; }
.call-top p { margin: 3px 0 0; color: rgba(255,255,255,.6); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.call-grid { display: grid; gap: 8px; padding: 8px; overflow: hidden; min-height: 0; height: 100%; }
.call-grid.g1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.call-grid.g2 { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.call-grid.g3, .call-grid.g4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
@media (min-width: 720px) { .call-grid.g2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; } }
.tile { position: relative; background: #000; border-radius: 20px; overflow: hidden; min-height: 0; min-width: 0; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.tile-av { position: absolute; inset: 0; display: grid; place-items: center; }
.tile .name { position: absolute; left: 10px; bottom: 10px; font-size: 13px; font-weight: 650; background: rgba(0,0,0,.4); padding: 4px 10px; border-radius: 20px; backdrop-filter: blur(6px); }
.tile .muted-ic { position: absolute; right: 10px; bottom: 10px; width: 26px; height: 26px; border-radius: 50%; background: rgba(0,0,0,.5); display: grid; place-items: center; }
.tile .muted-ic svg { width: 15px; height: 15px; }
.tile.audio-only .avatar { box-shadow: 0 0 0 6px rgba(255,255,255,.06); }
.tile.speaking { outline: 3px solid var(--online); outline-offset: -3px; }
.call-controls { display: flex; justify-content: center; gap: 16px; padding: 18px 0 calc(28px + var(--safe-b)); }
.cc { width: 60px; height: 60px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; transition: transform .1s, background .2s; }
.cc svg { width: 26px; height: 26px; }
.cc:active { transform: scale(.9); }
.cc.off { background: #fff; color: #111; }
.cc.on { background: #fff; color: #111; }
.cc.hang { background: var(--danger); }

/* incoming call */
.incoming { position: absolute; inset: 0; z-index: 75; background: linear-gradient(160deg, #241611, #0d0b09); color: #fff; display: grid; grid-template-rows: 1fr auto; place-items: center; }
.incoming .who { text-align: center; display: flex; flex-direction: column; align-items: center; }
.incoming .who h2 { margin: 16px 0 4px; font-size: 24px; }
.incoming .who p { color: rgba(255,255,255,.65); }
.incoming .who .avatar { animation: ripple 2s infinite; }
@keyframes ripple { 0%{ box-shadow: 0 0 0 0 rgba(70,195,106,.4);} 100%{ box-shadow: 0 0 0 30px rgba(70,195,106,0);} }
.incoming .actions { display: flex; gap: 60px; padding-bottom: calc(50px + var(--safe-b)); }
.incoming .actions .lab { text-align: center; font-size: 13px; color: rgba(255,255,255,.7); }
.incoming .actions .cc { width: 68px; height: 68px; }
.incoming .accept { background: var(--online); }

/* empty state */
.empty-chat { display: grid; place-items: center; padding: 40px; text-align: center; color: var(--muted); }
.empty-chat svg { width: 120px; height: 120px; opacity: .9; margin-bottom: 12px; }
.empty-chat p { max-width: 280px; line-height: 1.5; }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
