:root {
  --bg: #05070b;
  --panel: rgba(10, 14, 20, 0.82);
  --panel-2: rgba(18, 24, 34, 0.88);
  --line: rgba(255, 255, 255, 0.08);
  --text: #edf1f7;
  --muted: #8b93a3;
  --accent: #86f6bc;
  --accent-strong: #b3ffd7;
  --danger: #ff5e76;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(59,130,246,.12), transparent 32%),
    radial-gradient(circle at 86% 14%, rgba(134,246,188,.08), transparent 22%),
    linear-gradient(180deg, #06080c, #08111a 58%, #06080d);
  overflow: hidden;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.i { width: 19px; height: 19px; display: block; }

/* ---------- Public ---------- */
.public-shell {
  min-height: 100vh;
  padding: 16px;
  display: grid;
}
.public-card {
  width: 100%;
  min-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 32px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(8,12,16,.2), rgba(8,12,16,.86)),
    radial-gradient(circle at 78% 18%, rgba(129,245,186,.13), transparent 28%),
    #12161d;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.public-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 24px 30px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; letter-spacing: -.04em; font-size: 24px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  overflow: hidden; flex: 0 0 auto;
  box-shadow: 0 8px 30px rgba(31, 166, 255, 0.25);
  background: rgba(15, 19, 28, 0.88);
  border: 1px solid rgba(255,255,255,.1);
}
.brand-mark img { width: 100%; height: 100%; display: block; object-fit: cover; }
.soft-btn, .primary-btn, .icon-btn, .login-btn {
  border: 0;
  color: var(--text);
  border-radius: 16px;
  transition: .2s ease;
}
.soft-btn { background: rgba(255,255,255,.06); border: 1px solid var(--line); padding: 11px 16px; }
.soft-btn:hover { background: rgba(255,255,255,.1); }
.public-hero {
  padding: clamp(44px, 8vw, 104px);
  display: grid;
  align-content: center;
  max-width: 1100px;
}
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .16em; }
.public-hero h1 {
  margin: 14px 0 20px;
  max-width: 900px;
  font-size: clamp(52px, 9vw, 118px);
  line-height: .9;
  letter-spacing: -.075em;
}
.public-hero p { max-width: 700px; color: #aeb5c3; font-size: clamp(18px, 2.3vw, 28px); line-height: 1.4; }
.hero-note {
  margin-top: 24px; display: inline-flex; align-items: center; gap: 10px;
  width: fit-content; padding: 12px 16px; border-radius: 16px; border: 1px solid var(--line);
  background: rgba(255,255,255,.04); color: #c9d1dd; font-size: 14px;
}
.hero-note strong { color: white; }
.hero-note .i { width: 18px; height: 18px; color: var(--accent); }
.recipe-strip { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); }
.recipe-card { padding: 24px 30px; border-right: 1px solid var(--line); min-height: 150px; }
.recipe-card:last-child { border-right: 0; }
.recipe-card span { color: var(--muted); font-size: 13px; }
.recipe-card h3 { margin: 14px 0 0; font-size: 22px; }

/* ---------- Login ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  padding: 20px; background: rgba(0,0,0,.64); backdrop-filter: blur(16px);
}
.login-card {
  width: min(440px, 100%); padding: 28px; border: 1px solid var(--line);
  border-radius: 28px; background: rgba(17,20,27,.96); box-shadow: var(--shadow);
}
.login-card h2 { margin: 18px 0 8px; font-size: 34px; letter-spacing: -.045em; }
.login-card p { color: var(--muted); line-height: 1.55; }
.field { display: grid; gap: 8px; margin-top: 18px; }
.field label { color: #a7adba; font-size: 13px; font-weight: 700; }
.field input {
  width: 100%; background: #0c0f15; border: 1px solid var(--line); color: var(--text);
  border-radius: 15px; padding: 14px 15px; outline: none;
}
.field input:focus { border-color: rgba(130,246,188,.5); box-shadow: 0 0 0 3px rgba(130,246,188,.08); }
.primary-btn { width: 100%; margin-top: 20px; padding: 14px 18px; color: #07110c; background: var(--accent); font-weight: 900; }
.primary-btn:hover { background: var(--accent-strong); transform: translateY(-1px); }
.login-hint { margin-top: 14px; color: #6f7684; font-size: 12px; }
.close-login {
  float: right; width: 38px; height: 38px; border-radius: 12px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line); color: white;
  display: grid; place-items: center;
}

/* ---------- Messenger ---------- */
.messenger-shell {
  width: 100vw; height: 100vh; padding: 14px;
  display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 12px;
}
.sidebar, .conversation {
  border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(22px);
  box-shadow: var(--shadow); overflow: hidden;
}
.sidebar { border-radius: 26px; display: grid; grid-template-rows: auto auto 1fr auto; }
.side-top { padding: 18px 18px 12px; display: flex; align-items: center; justify-content: space-between; }
.side-top .brand { font-size: 22px; }
.side-top .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px rgba(130,246,188,.08); }
.search-wrap { padding: 8px 14px 12px; }
.search-wrap input {
  width: 100%; border: 1px solid var(--line); background: rgba(255,255,255,.045);
  border-radius: 14px; padding: 12px 14px; color: white; outline: none;
}
.chat-list { overflow: auto; padding: 4px 8px 12px; }
.chat-item {
  width: 100%; border: 0; background: transparent; color: white; padding: 10px;
  display: grid; grid-template-columns: 50px 1fr auto; gap: 11px; align-items: center;
  border-radius: 18px; text-align: left;
}
.chat-item:hover, .chat-item.active { background: rgba(255,255,255,.065); }
.avatar {
  width: 50px; height: 50px; border-radius: 17px; display: grid; place-items: center;
  background: linear-gradient(145deg, rgba(130,246,188,.28), rgba(112,140,255,.15));
  border: 1px solid rgba(255,255,255,.09); font-weight: 900;
}
.chat-name { font-weight: 820; letter-spacing: -.01em; }
.chat-preview { color: var(--muted); font-size: 13px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.chat-time { color: #686f7d; font-size: 11px; align-self: start; padding-top: 4px; }
.side-bottom { padding: 12px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.user-mini { border-radius: 16px; padding: 10px 12px; background: rgba(255,255,255,.04); }
.user-mini strong { display:block; font-size: 13px; }
.user-mini span { color: var(--muted); font-size: 11px; }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center;
  background: rgba(255,255,255,.055); border: 1px solid var(--line);
}
.icon-btn:hover { background: rgba(255,255,255,.1); }
.icon-btn .i { width: 18px; height: 18px; }

.conversation { border-radius: 26px; display: grid; grid-template-rows: auto 1fr auto; min-width: 0; }
.conversation-head {
  min-height: 76px; padding: 12px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.person-head { display:flex; align-items:center; gap: 12px; min-width: 0; }
.person-head .avatar { width: 46px; height: 46px; border-radius: 15px; }
.person-head h2 { margin: 0; font-size: 17px; }
.person-head p { margin: 3px 0 0; color: var(--accent); font-size: 12px; }
.head-actions { display:flex; gap: 8px; }
.messages {
  overflow: auto; padding: 28px clamp(16px, 4vw, 54px);
  display: flex; flex-direction: column; gap: 9px;
}
.day-label { align-self: center; color: #707887; font-size: 11px; margin: 8px 0 16px; }
.msg {
  max-width: min(72%, 620px); padding: 11px 13px 8px; border-radius: 18px;
  line-height: 1.42; box-shadow: 0 4px 14px rgba(0,0,0,.08); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.them { align-self: flex-start; background: rgba(255,255,255,.075); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: #dffced; color: #0a1710; border-bottom-right-radius: 6px; }
.msg-meta { display: block; font-size: 10px; opacity: .55; text-align: right; margin-top: 5px; }
.composer {
  padding: 12px 16px 16px; border-top: 1px solid var(--line); display: grid;
  grid-template-columns: auto 1fr auto; gap: 10px; align-items: end;
}

.composer textarea {
  resize: none; min-height: 46px; max-height: 130px; border: 1px solid var(--line);
  background: rgba(255,255,255,.05); color: white; outline: none; border-radius: 17px;
  padding: 13px 14px; line-height: 1.35;
}
.send-btn {
  background: var(--accent); color: #07110c; font-weight: 900; border: 0;
  border-radius: 16px; width: 46px; height: 46px; display: grid; place-items: center;
}
.send-btn .i { width: 18px; height: 18px; }

.empty-state { height: 100%; display: grid; place-items: center; color: var(--muted); text-align:center; padding: 30px; }
.empty-state strong { color: var(--text); display:block; font-size: 28px; margin-bottom: 8px; }

/* ---------- Call ---------- */
.call-overlay {
  position: fixed; inset: 0; z-index: 30; background: rgba(3,5,8,.88); backdrop-filter: blur(22px);
  display: grid; place-items: center; padding: 20px;
}
.call-card { width: min(520px, 100%); border: 1px solid var(--line); border-radius: 34px; background: #11151d; padding: 34px; text-align:center; box-shadow: var(--shadow); }
.call-card .avatar { margin: 0 auto; width: 96px; height: 96px; border-radius: 30px; font-size: 28px; }
.call-card h2 { margin: 22px 0 6px; font-size: 30px; }
.call-card p { margin: 0; color: var(--muted); }
.call-status { margin-top: 18px; color: var(--accent); font-size: 13px; }
.call-actions { margin-top: 28px; display:flex; justify-content:center; gap: 12px; }
.call-action {
  width: 58px; height: 58px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255,255,255,.07); color:white; display:grid; place-items:center;
}
.call-action .i { width: 22px; height: 22px; }
.call-action.hang { background: var(--danger); border-color: transparent; }

.toast { position: fixed; z-index: 60; right: 18px; bottom: 18px; max-width: min(390px, calc(100vw - 36px)); background: #181d26; border:1px solid var(--line); border-radius: 16px; padding: 13px 15px; box-shadow: var(--shadow); color:#dce1ea; font-size:13px; }

@media (max-width: 760px) {
  body { overflow: hidden; }
  .public-shell { padding: 10px; }
  .public-card { min-height: calc(100vh - 20px); border-radius: 24px; }
  .public-nav { padding: 18px; }
  .public-hero { padding: 46px 22px; }
  .recipe-strip { grid-template-columns: 1fr; }
  .recipe-card { border-right: 0; border-top: 1px solid var(--line); min-height: 110px; }
  .messenger-shell { padding: 0; grid-template-columns: 1fr; gap:0; }
  .sidebar, .conversation { border-radius: 0; border-left:0; border-right:0; }
  .sidebar { display: grid; }
  .messenger-shell.chat-open .sidebar { display:none; }
  .conversation { display:none; }
  .messenger-shell.chat-open .conversation { display:grid; }
  .msg { max-width: 86%; }
  .mobile-back { display: grid !important; }
  .composer { grid-template-columns: auto 1fr auto; }
}

.mobile-back { display:none; }


/* ---------- Attachments ---------- */
.hidden-file-input { display: none; }
.attach-btn { align-self: end; }
.composer.drag-active {
  background: rgba(134,246,188,.06);
  box-shadow: inset 0 0 0 1px rgba(134,246,188,.25);
}
.msg.has-attachment { padding: 7px; }
.msg.has-attachment .msg-text { padding: 7px 7px 2px; }
.msg.has-attachment .msg-meta { padding: 0 5px 2px; }
.attachment-photo {
  display: block; border: 0; padding: 0; margin: 0; width: min(360px, 54vw);
  max-height: 420px; border-radius: 14px; overflow: hidden; background: rgba(255,255,255,.06);
  color: inherit; text-align: left;
}
.attachment-photo img { display: block; width: 100%; max-height: 420px; object-fit: cover; }
.attachment-placeholder {
  min-height: 150px; display: grid; place-items: center; align-content: center; gap: 8px;
  color: var(--muted); font-size: 12px;
}
.attachment-placeholder .i { width: 25px; height: 25px; }
.attachment-file {
  width: min(360px, 56vw); min-height: 66px; border: 0; border-radius: 13px;
  display: grid; grid-template-columns: 42px minmax(0,1fr) 34px; gap: 10px; align-items: center;
  padding: 10px; text-align: left; color: inherit; background: rgba(255,255,255,.08);
}
.msg.me .attachment-file { background: rgba(7,24,15,.08); }
.file-icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: rgba(134,246,188,.12); color: #65dca0;
}
.file-icon .i { width: 20px; height: 20px; }
.file-info { min-width: 0; display: grid; gap: 3px; }
.file-info strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
.file-info small { opacity: .55; font-size: 11px; }
.file-download { display: grid; place-items: center; opacity: .55; }
.file-download .i { width: 18px; height: 18px; }
.attachment-missing { opacity: .5; }

@media (max-width: 760px) {
  .attachment-photo, .attachment-file { width: min(72vw, 330px); }
}

/* ---------- Realtime LAN MVP ---------- */
.boot-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  color: var(--muted);
}
.boot-screen .brand { color: var(--text); }
.field select {
  width: 100%;
  background: #0c0f15;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 15px;
  padding: 14px 15px;
  outline: none;
}
.demo-pins {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 12px;
  padding: 12px;
  border-radius: 15px;
  background: rgba(255,255,255,.035);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}
.demo-pins span { display: flex; justify-content: space-between; gap: 10px; }
.demo-pins b { color: var(--text); letter-spacing: .08em; }
.server-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #6f7888;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.server-state .status-dot { background: #7a8495; box-shadow: 0 0 0 5px rgba(122,132,149,.07); }
.server-state.online { color: var(--accent); }
.server-state.online .status-dot { background: var(--accent); box-shadow: 0 0 0 5px rgba(130,246,188,.08); }
.chat-side {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  padding: 3px 0;
}
.presence-mini {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #596170;
}
.presence-mini.online { background: var(--accent); box-shadow: 0 0 0 3px rgba(130,246,188,.07); }
.peer-status { color: #767f8e !important; }
.peer-status.online { color: var(--accent) !important; }
.conversation-hint {
  align-self: center;
  margin: auto;
  max-width: 460px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.035);
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
  font-size: 13px;
}
.conversation-hint strong { color: var(--text); }
.msg.failed { box-shadow: 0 0 0 1px rgba(255,94,118,.35); }
.msg.failed .msg-meta { color: #cc304c; opacity: .9; }

@media (max-width: 760px) {
  .demo-pins { grid-template-columns: 1fr; }
  .server-state span:last-child { display: none; }
}

/* ---------- v5 polish: media bounds, scroll stability & motion ---------- */
.msg {
  min-width: 0;
  overflow: hidden;
  transform-origin: 50% 100%;
}

.msg.has-attachment {
  min-width: 0;
  overflow: hidden;
}

.attachment-photo,
.attachment-file {
  max-width: 100%;
  min-width: 0;
}

.attachment-photo {
  width: 360px;
}

.attachment-photo img {
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: min(56vh, 520px);
  object-fit: contain;
  animation: mediaReveal .28s ease-out both;
}

.attachment-file {
  width: 360px;
}

.msg-new.me {
  animation: messageInMe .34s cubic-bezier(.2,.9,.25,1.15) both;
}

.msg-new.them {
  animation: messageInThem .34s cubic-bezier(.2,.9,.25,1.15) both;
}

.icon-btn,
.send-btn,
.chat-item,
.attachment-photo,
.attachment-file,
.soft-btn,
.primary-btn,
.call-action {
  transition: transform .16s ease, background-color .18s ease, border-color .18s ease, opacity .18s ease, box-shadow .18s ease;
}

.icon-btn:active,
.call-action:active {
  transform: scale(.88);
}

.send-btn:active {
  transform: scale(.9) rotate(-5deg);
}

.chat-item:active {
  transform: scale(.985);
}

.attachment-photo:hover,
.attachment-file:hover {
  transform: translateY(-1px);
}

.server-state.online .status-dot,
.presence-mini.online {
  animation: onlinePulse 2.2s ease-in-out infinite;
}

.modal-backdrop {
  animation: backdropIn .2s ease-out both;
}

.login-card,
.call-card {
  animation: cardIn .3s cubic-bezier(.2,.85,.25,1.08) both;
}

.toast {
  animation: toastIn .25s cubic-bezier(.2,.85,.25,1.08) both;
}

@keyframes messageInMe {
  from { opacity: 0; transform: translate3d(18px, 10px, 0) scale(.94); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes messageInThem {
  from { opacity: 0; transform: translate3d(-18px, 10px, 0) scale(.94); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes mediaReveal {
  from { opacity: 0; transform: scale(1.025); filter: blur(3px); }
  to   { opacity: 1; transform: scale(1); filter: blur(0); }
}

@keyframes onlinePulse {
  0%, 100% { opacity: .75; box-shadow: 0 0 0 3px rgba(130,246,188,.05); }
  50% { opacity: 1; box-shadow: 0 0 0 6px rgba(130,246,188,.10); }
}

@keyframes backdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 760px) {
  .msg {
    max-width: 86%;
  }

  .msg.has-attachment {
    max-width: 86%;
  }

  .attachment-photo,
  .attachment-file {
    width: min(330px, 100%);
    max-width: 100%;
  }

  .attachment-photo img {
    max-height: 48vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- v6 layout fix: fixed viewport + real message scrolling ---------- */
html,
body,
#app {
  width: 100%;
  height: 100%;
  min-height: 0;
}

#app {
  overflow: hidden;
}

.messenger-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  grid-template-rows: minmax(0, 1fr);
}

.sidebar,
.conversation {
  height: 100%;
  min-height: 0;
  min-width: 0;
}

.sidebar {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.chat-list {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.conversation {
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.conversation-head,
.composer {
  min-height: 0;
  flex: 0 0 auto;
}

.messages {
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

/* A column flexbox otherwise tries to squeeze the entire history into one viewport. */
.messages > *,
.msg,
.day-label,
.conversation-hint {
  flex: 0 0 auto;
  flex-shrink: 0;
}

.msg {
  height: auto;
}

@media (max-width: 760px) {
  .messenger-shell,
  .conversation,
  .sidebar {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .messenger-shell.chat-open .conversation {
    min-height: 0;
    overflow: hidden;
  }

  .messages {
    min-height: 0;
    max-height: none;
  }
}

/* ===== v7 light theme + media actions ===== */
:root {
  --bg: #eef5f9;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-2: rgba(255, 255, 255, 0.94);
  --line: rgba(41, 72, 106, 0.12);
  --text: #183045;
  --muted: #718398;
  --accent: #69e6c2;
  --accent-strong: #8ef0d2;
  --danger: #ef5d73;
  --shadow: 0 18px 48px rgba(69, 92, 122, 0.16);
}

body {
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(70,160,220,.16), transparent 34%),
    radial-gradient(circle at 88% 14%, rgba(105,230,194,.18), transparent 22%),
    linear-gradient(180deg, #f5fafc, #e9f1f6 58%, #f2f8fb);
}
.public-card,
.login-card,
.sidebar,
.conversation,
.call-card,
.forward-sheet,
.media-modal,
.toast {
  background: var(--panel-2);
  color: var(--text);
}
.public-card {
  background:
    linear-gradient(180deg, rgba(255,255,255,.76), rgba(244,249,252,.98)),
    radial-gradient(circle at 78% 18%, rgba(105,230,194,.12), transparent 28%),
    #f4f9fc;
}
.soft-btn,
.icon-btn,
.close-login,
.search-wrap input,
.composer textarea,
.user-mini,
.field input,
.field select,
.composer,
.hero-note,
.attachment-file,
.attachment-photo,
.composer.drag-active {
  background: rgba(255,255,255,.82);
}
.soft-btn,
.icon-btn,
.close-login,
.field input,
.field select,
.search-wrap input,
.composer textarea,
.attachment-action-btn,
.forward-contact,
.media-close,
.attachment-file,
.user-mini,
.hero-note {
  border: 1px solid var(--line);
}
.brand-mark {
  background: rgba(255,255,255,.95);
  border: 1px solid rgba(41,72,106,.1);
  box-shadow: 0 10px 24px rgba(74, 161, 220, 0.18);
}
.public-hero p,
.recipe-card span,
.login-card p,
.user-mini span,
.chat-preview,
.chat-time,
.file-info small,
.toast,
.hero-note,
.login-hint,
.call-card p,
.chat-side,
.field label {
  color: var(--muted);
}
.primary-btn,
.send-btn {
  color: #0c4233;
}
.chat-item,
.icon-btn,
.soft-btn,
.close-login,
.field input,
.field select,
.search-wrap input,
.composer textarea,
.attachment-action-btn,
.forward-contact,
.media-close {
  color: var(--text);
}
.chat-item:hover,
.chat-item.active,
.icon-btn:hover,
.soft-btn:hover,
.forward-contact:hover {
  background: rgba(103, 154, 196, 0.10);
}
.status-dot,
.presence-mini.online,
.peer-status.online,
.server-state.online .status-dot { background: var(--accent); }
.server-state,
.user-mini,
.hero-note {
  color: var(--text);
}
.server-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  font-size: 12px;
}
.presence-mini {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: #c7d4e0;
}
.search-wrap input::placeholder,
.composer textarea::placeholder,
.field input::placeholder {
  color: #8a9aac;
}
.msg {
  box-shadow: 0 8px 18px rgba(79, 107, 141, 0.10);
}
.msg.them {
  background: rgba(255,255,255,.96);
  color: var(--text);
}
.msg.me {
  background: #dff8ef;
  color: #183a2f;
}
.day-label,
.conversation-hint { color: #7a8c9f; }
.attachment-photo-card {
  display: grid;
  gap: 8px;
}
.attachment-photo {
  display: block;
  border: 1px solid var(--line);
  padding: 0;
  margin: 0;
  width: min(100%, 360px);
  max-width: 100%;
  max-height: 420px;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255,255,255,.88);
  color: inherit;
  text-align: left;
}
.attachment-photo img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 420px;
  object-fit: cover;
}
.attachment-photo-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.attachment-action-btn {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,.92);
  color: var(--text);
}
.attachment-action-btn .i,
.media-close .i { width: 16px; height: 16px; }
.attachment-file {
  width: min(100%, 360px);
  max-width: 100%;
  background: rgba(255,255,255,.92);
}
.file-icon {
  background: rgba(105,230,194,.16);
  color: #37b78d;
}
.file-download { opacity: .72; }
.attachment-placeholder {
  min-height: 150px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
}
.attachment-placeholder-large {
  min-height: 320px;
}
.media-overlay,
.forward-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(228, 238, 246, 0.72);
  backdrop-filter: blur(16px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.media-modal {
  position: relative;
  width: min(980px, 100%);
  max-height: min(92vh, 980px);
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.media-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.92);
}
.media-stage {
  min-height: 420px;
  max-height: min(92vh, 900px);
  display: grid;
  place-items: center;
  padding: 52px 22px 22px;
  background: linear-gradient(180deg, rgba(247,250,253,.9), rgba(236,244,249,.98));
}
.media-image {
  display: block;
  max-width: 100%;
  max-height: calc(92vh - 90px);
  border-radius: 18px;
  object-fit: contain;
  box-shadow: 0 14px 36px rgba(69, 92, 122, 0.18);
}
.forward-sheet {
  width: min(460px, 100%);
  border-radius: 26px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.forward-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.forward-head h3 {
  margin: 0;
  font-size: 22px;
}
.forward-list {
  padding: 10px;
  display: grid;
  gap: 8px;
  max-height: min(70vh, 560px);
  overflow: auto;
}
.forward-contact {
  width: 100%;
  border-radius: 18px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 50px 1fr;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: rgba(255,255,255,.84);
}
.forward-contact .avatar { width: 50px; height: 50px; }
.forward-contact-meta { min-width: 0; display: grid; gap: 3px; }
.forward-contact-meta strong { color: var(--text); }
.forward-contact-meta small { color: var(--muted); }
.call-overlay {
  background: rgba(231, 239, 245, 0.72);
}
.call-card { background: rgba(255,255,255,.96); }
.toast {
  background: rgba(255,255,255,.96);
  color: var(--text);
}

@media (max-width: 760px) {
  .attachment-photo,
  .attachment-file { width: min(72vw, 330px); }
  .media-modal {
    width: 100%;
    max-height: 100%;
    border-radius: 20px;
  }
  .media-stage {
    min-height: 300px;
    padding: 56px 12px 12px;
  }
  .forward-sheet {
    width: 100%;
    border-radius: 20px;
  }
}

/* ===== v8 premium light / media viewer ===== */
:root {
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.90);
  --blue-soft: #dceef9;
  --blue: #4e9fd2;
}

.sidebar,
.conversation {
  background: var(--glass);
  backdrop-filter: blur(28px) saturate(135%);
  -webkit-backdrop-filter: blur(28px) saturate(135%);
  box-shadow: 0 22px 60px rgba(57, 84, 112, 0.13);
}
.conversation-head,
.side-top,
.side-bottom,
.composer {
  background: rgba(255,255,255,.56);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.conversation-head {
  box-shadow: 0 1px 0 rgba(255,255,255,.72) inset;
}
.chat-item,
.icon-btn,
.send-btn,
.attachment-action-btn,
.media-tool,
.media-scale,
.forward-contact {
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.chat-item:active,
.icon-btn:active,
.send-btn:active,
.attachment-action-btn:active,
.media-tool:active,
.media-scale:active,
.forward-contact:active {
  transform: scale(.97);
}
.icon-btn,
.attachment-action-btn,
.media-tool,
.media-scale {
  box-shadow: 0 5px 16px rgba(68, 98, 128, .07);
}
.send-btn {
  box-shadow: 0 8px 22px rgba(70, 196, 157, .22);
}
.avatar {
  box-shadow: 0 5px 16px rgba(67, 101, 137, .09);
}

.attachment-photo-card,
.attachment-file-card {
  display: grid;
  gap: 8px;
  max-width: 100%;
}
.attachment-actions,
.attachment-photo-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  padding: 0 1px;
}
.attachment-file-actions {
  padding-top: 1px;
}
.attachment-action-btn {
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: rgba(255,255,255,.84);
  color: var(--text);
}
.attachment-action-btn:hover {
  background: #fff;
  box-shadow: 0 8px 20px rgba(68, 98, 128, .10);
}
.attachment-photo {
  cursor: zoom-in;
}
.attachment-photo img {
  transition: transform .26s ease, filter .26s ease;
}
.attachment-photo:hover img {
  transform: scale(1.012);
  filter: saturate(1.03);
}
.attachment-file {
  cursor: pointer;
}

.media-overlay,
.forward-overlay {
  animation: nemaxFadeIn .20s ease both;
}
.media-modal {
  animation: nemaxMediaIn .28s cubic-bezier(.2,.8,.2,1) both;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1080px, 96vw);
  height: min(900px, 92dvh);
  max-height: 92dvh;
  overflow: hidden;
  background: rgba(250,253,255,.91);
  backdrop-filter: blur(32px) saturate(135%);
  -webkit-backdrop-filter: blur(32px) saturate(135%);
}
.media-topbar {
  min-height: 58px;
  padding: 10px 12px 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.72);
  z-index: 3;
}
.media-hint {
  color: var(--muted);
  font-size: 12px;
}
.media-close {
  position: static;
  flex: 0 0 auto;
}
.media-stage {
  position: relative;
  min-height: 0;
  max-height: none;
  overflow: hidden;
  padding: 22px;
  touch-action: none;
  user-select: none;
  cursor: default;
  background:
    radial-gradient(circle at 50% 38%, rgba(255,255,255,.98), rgba(231,241,247,.92)),
    linear-gradient(180deg, #f5fafc, #eaf3f8);
}
.media-stage:has(.media-image.is-zoomed) {
  cursor: grab;
}
.media-stage:has(.media-image.is-zoomed):active {
  cursor: grabbing;
}
.media-image {
  max-width: calc(100% - 8px);
  max-height: calc(100% - 8px);
  transform-origin: center center;
  transition: transform .14s ease-out;
  will-change: transform;
  pointer-events: none;
}
.media-image.is-zoomed {
  transition: none;
}
.media-toolbar {
  min-height: 64px;
  padding: 10px 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.76);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.media-tool,
.media-scale {
  height: 40px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.90);
  color: var(--text);
  border-radius: 12px;
}
.media-tool {
  min-width: 40px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.media-tool-wide {
  padding-inline: 14px;
}
.media-scale {
  min-width: 66px;
  padding: 0 10px;
  font-weight: 700;
  font-size: 12px;
}
.media-tool:hover,
.media-scale:hover {
  background: #fff;
  box-shadow: 0 7px 18px rgba(66, 98, 129, .10);
}
.media-tool-separator {
  width: 1px;
  height: 26px;
  background: var(--line);
  margin: 0 3px;
}
.forward-sheet {
  animation: nemaxSheetIn .25s cubic-bezier(.2,.8,.2,1) both;
  background: rgba(250,253,255,.94);
  backdrop-filter: blur(30px) saturate(135%);
  -webkit-backdrop-filter: blur(30px) saturate(135%);
}
.forward-contact:hover {
  transform: translateY(-1px);
  background: #fff;
  box-shadow: 0 9px 24px rgba(63, 92, 122, .09);
}

@keyframes nemaxFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes nemaxMediaIn {
  from { opacity: 0; transform: scale(.965) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes nemaxSheetIn {
  from { opacity: 0; transform: scale(.975) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (max-width: 760px) {
  .media-overlay,
  .forward-overlay { padding: 8px; }
  .media-modal {
    width: 100%;
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 22px;
  }
  .media-hint { display: none; }
  .media-stage { padding: 10px; }
  .media-toolbar {
    min-height: 62px;
    padding: 8px;
    gap: 6px;
  }
  .media-tool-wide span { display: none; }
  .media-tool-wide { padding-inline: 10px; }
  .media-tool-separator { margin-inline: 0; }
  .attachment-actions { gap: 6px; }
  .attachment-action-btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .media-overlay,
  .media-modal,
  .forward-overlay,
  .forward-sheet { animation: none !important; }
  .media-image { transition: none !important; }
}

/* ===== v9 real WebRTC calls ===== */
.call-overlay {
  z-index: 110;
  background: rgba(232, 241, 247, 0.76);
  backdrop-filter: blur(22px) saturate(1.15);
}
.call-card {
  width: min(520px, 100%);
  min-height: 430px;
  display: grid;
  justify-items: center;
  align-content: center;
  border-radius: 34px;
  padding: 34px;
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(54, 91, 124, 0.12);
  box-shadow: 0 30px 90px rgba(70, 96, 128, 0.20);
  animation: callCardIn .28s cubic-bezier(.2,.8,.2,1);
}
.call-avatar {
  width: 108px !important;
  height: 108px !important;
  border-radius: 34px !important;
  font-size: 30px !important;
  box-shadow: 0 16px 36px rgba(76, 117, 147, .16);
}
.call-card h2 {
  margin: 24px 0 6px;
  color: var(--text);
}
.call-card > p {
  margin: 0;
  color: var(--muted);
}
.call-status {
  margin-top: 18px;
  min-height: 20px;
  color: #537086;
  font-size: 14px;
  font-weight: 650;
}
.call-duration {
  min-height: 22px;
  margin-top: 4px;
  color: #8a9aac;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.call-actions {
  margin-top: 26px;
  display: flex;
  justify-content: center;
  gap: 14px;
}
.call-action {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid rgba(58, 86, 112, .12);
  background: rgba(239,245,249,.96);
  color: #345267;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 22px rgba(73, 103, 132, .10);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.call-action:hover {
  transform: translateY(-2px);
  box-shadow: 0 11px 28px rgba(73, 103, 132, .15);
}
.call-action:active { transform: scale(.96); }
.call-action.accept {
  background: #68e5b0;
  color: #0e4938;
  border-color: transparent;
  box-shadow: 0 12px 30px rgba(59, 197, 146, .28);
}
.call-action.hang {
  background: #f06378;
  color: #fff;
  border-color: transparent;
  box-shadow: 0 12px 30px rgba(240, 99, 120, .24);
}
.call-action.hang .i { transform: rotate(135deg); }
.call-action.reject .i { transform: rotate(135deg); }
.call-action.close-call {
  background: rgba(232,239,244,.98);
}
.incoming-actions { gap: 26px; }
.call-card:has(.incoming-actions) .call-avatar {
  animation: incomingAvatarPulse 1.7s ease-in-out infinite;
}

.call-video-stage {
  position: relative;
  width: min(430px, 82vw);
  aspect-ratio: 4 / 3;
  border-radius: 26px;
  overflow: hidden;
  background: linear-gradient(145deg, #dfeaf2, #edf5f8);
  box-shadow: inset 0 0 0 1px rgba(47,78,106,.09), 0 18px 42px rgba(72, 99, 128, .15);
}
.call-video-stage #remote-video,
.call-video-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.call-video-stage #remote-video {
  object-fit: cover;
  z-index: 2;
  background: transparent;
}
.call-video-fallback {
  z-index: 1;
  display: grid;
  place-items: center;
}
.call-video-fallback.hidden { display: none; }
.call-video-fallback .avatar {
  width: 98px;
  height: 98px;
  border-radius: 32px;
  font-size: 28px;
}
.call-video-stage #local-video {
  position: absolute;
  z-index: 3;
  right: 12px;
  bottom: 12px;
  width: 30%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,.88);
  background: #dbe7ee;
  box-shadow: 0 9px 24px rgba(31, 51, 72, .24);
}
.video-call-card {
  width: min(560px, 100%);
  min-height: auto;
  padding: 24px;
}
.video-call-card h2 { margin-top: 18px; }
#remote-audio { display: none; }

@keyframes callCardIn {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes incomingAvatarPulse {
  0%, 100% { box-shadow: 0 16px 36px rgba(76,117,147,.16), 0 0 0 0 rgba(105,230,194,.28); }
  50% { box-shadow: 0 16px 36px rgba(76,117,147,.16), 0 0 0 16px rgba(105,230,194,0); }
}

@media (max-width: 760px) {
  .call-overlay { padding: 12px; }
  .call-card {
    width: 100%;
    min-height: min(620px, calc(100dvh - 24px));
    border-radius: 28px;
    padding: 24px 18px;
  }
  .video-call-card { min-height: auto; }
  .call-video-stage {
    width: 100%;
    aspect-ratio: 3 / 4;
    max-height: 58dvh;
  }
  .call-actions { margin-top: 22px; }
}

/* ===== v11 compact bubbles + grouped photo albums ===== */
.msg {
  width: fit-content;
  min-width: 0;
  min-height: 0;
  white-space: normal;
  padding: 9px 11px 7px;
}
.msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.has-attachment {
  width: fit-content;
  min-width: 0;
  min-height: 0;
  padding: 5px;
}
.msg.has-attachment .msg-text {
  padding: 6px 6px 1px;
}
.msg.has-attachment .msg-meta {
  padding: 0 5px 1px;
  margin-top: 4px;
  line-height: 1.1;
}
.msg-meta {
  margin-top: 3px;
  line-height: 1.1;
}
.attachment-photo-card,
.attachment-file-card,
.attachment-gallery-card {
  width: fit-content;
  max-width: 100%;
  gap: 6px;
}
.attachment-actions,
.attachment-photo-actions {
  gap: 6px;
  padding: 0;
}
.attachment-action-btn {
  min-height: 32px;
  padding: 6px 10px;
}
.attachment-photo {
  width: min(360px, 54vw);
  max-width: 100%;
}

.attachment-gallery {
  width: min(420px, 58vw);
  max-width: 100%;
  display: grid;
  gap: 3px;
  overflow: hidden;
  border-radius: 14px;
  background: #e7eef3;
}
.gallery-photo {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
  background: #e7eef3;
  color: inherit;
}
.gallery-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gallery-photo .attachment-placeholder {
  min-height: 100%;
  height: 100%;
}
.attachment-gallery.gallery-count-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  aspect-ratio: 2 / 1;
}
.attachment-gallery.gallery-count-3 {
  grid-template-columns: 1.35fr .85fr;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  aspect-ratio: 1.55 / 1;
}
.gallery-count-3 .gallery-photo-1 { grid-row: 1 / 3; }
.attachment-gallery.gallery-count-4,
.attachment-gallery.gallery-count-5 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  aspect-ratio: 1.45 / 1;
}
.gallery-more {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(21, 42, 59, .48);
  color: #fff;
  font-size: 28px;
  font-weight: 750;
  letter-spacing: -.04em;
  backdrop-filter: blur(2px);
}
.gallery-actions {
  display: flex;
  flex-wrap: nowrap;
}
.gallery-actions .attachment-action-btn {
  flex: 0 0 auto;
}

@media (max-width: 760px) {
  .msg {
    max-width: 88%;
  }
  .msg.has-attachment {
    max-width: 92%;
  }
  .attachment-gallery {
    width: min(78vw, 390px);
  }
  .attachment-photo {
    width: min(76vw, 350px);
  }
  .gallery-actions .attachment-action-btn {
    flex: 1 1 0;
  }
}

/* ===== v12 forwarding attribution ===== */
.forwarded-from {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px 5px;
  color: #6b8193;
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
}
.forwarded-from .i {
  width: 13px;
  height: 13px;
  color: #55b89a;
  flex: 0 0 auto;
}
.forwarded-from strong {
  color: #3a6279;
  font-weight: 750;
}
.msg.me .forwarded-from {
  color: #5a7b6e;
}
.msg.me .forwarded-from strong {
  color: #28624f;
}
.forward-origin-preview {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}
.forward-origin-preview strong {
  color: var(--text);
  font-weight: 750;
}
.forward-head > div:first-child {
  min-width: 0;
}

@media (max-width: 760px) {
  .forwarded-from {
    white-space: normal;
  }
}

/* ===== v13 album viewer ===== */
.media-modal.media-modal-album {
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}
.media-topbar-left {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.media-counter {
  flex: 0 0 auto;
  min-width: 54px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(233, 241, 247, .92);
  border: 1px solid var(--line);
  color: #536b80;
  font-size: 12px;
  font-weight: 750;
}
.media-stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
}
.media-stage-wrap .media-stage {
  min-width: 0;
  min-height: 0;
  height: 100%;
}
.media-nav {
  position: absolute;
  top: 50%;
  z-index: 5;
  width: 48px;
  height: 64px;
  margin-top: -32px;
  border: 1px solid rgba(57, 87, 115, .12);
  border-radius: 17px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.86);
  color: #28465d;
  box-shadow: 0 10px 28px rgba(61, 87, 114, .14);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 34px;
  line-height: 1;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.media-nav:hover {
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 14px 34px rgba(61, 87, 114, .18);
}
.media-nav:active {
  transform: scale(.96);
}
.media-nav-prev { left: 14px; }
.media-nav-next { right: 14px; }
.media-thumbnails {
  min-height: 86px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  border-top: 1px solid var(--line);
  background: rgba(247,251,253,.86);
}
.media-thumb {
  position: relative;
  flex: 0 0 66px;
  width: 66px;
  height: 66px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 13px;
  overflow: hidden;
  background: #e6eef3;
  color: #6c8091;
  box-shadow: none;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.media-thumb:hover {
  transform: translateY(-1px);
}
.media-thumb.active {
  border-color: #63d5b3;
  box-shadow: 0 0 0 2px rgba(99,213,179,.16);
}
.media-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.media-thumb > span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}
.media-modal-album .media-toolbar {
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .media-modal.media-modal-album {
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }
  .media-topbar-left { gap: 8px; }
  .media-counter {
    height: 28px;
    min-width: 50px;
  }
  .media-nav {
    width: 42px;
    height: 56px;
    margin-top: -28px;
    border-radius: 14px;
    font-size: 30px;
  }
  .media-nav-prev { left: 7px; }
  .media-nav-next { right: 7px; }
  .media-thumbnails {
    min-height: 72px;
    padding: 7px 8px;
    gap: 6px;
  }
  .media-thumb {
    flex-basis: 56px;
    width: 56px;
    height: 56px;
    border-radius: 11px;
  }
  .media-modal-album .media-toolbar {
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .media-modal-album .media-tool,
  .media-modal-album .media-scale {
    flex: 0 0 auto;
  }
}

/* v17 — login/password + admin device approval */
.approval-wait-card { text-align: center; }
.approval-wait-card .brand { justify-content: center; }
.approval-spinner { width: 46px; height: 46px; margin: 24px auto 18px; border: 4px solid rgba(40,70,110,.12); border-top-color: currentColor; border-radius: 50%; animation: approval-spin .9s linear infinite; }
@keyframes approval-spin { to { transform: rotate(360deg); } }
.admin-overlay { z-index: 125; }
.admin-card { width: min(760px, calc(100vw - 28px)); max-height: min(760px, calc(100vh - 28px)); overflow: auto; background: rgba(255,255,255,.96); backdrop-filter: blur(24px); border: 1px solid rgba(20,40,70,.08); border-radius: 28px; box-shadow: 0 30px 90px rgba(20,40,70,.18); padding: 24px; }
.admin-head { display:flex; align-items:center; justify-content:space-between; gap:18px; margin-bottom:18px; }
.admin-head h2 { margin: 3px 0 0; font-size: 30px; letter-spacing: -.04em; }
.admin-section { border-top: 1px solid rgba(20,40,70,.08); padding-top: 18px; margin-top: 18px; }
.admin-section h3 { margin:0 0 12px; display:flex; align-items:center; gap:8px; font-size:17px; }
.admin-badge { display:inline-grid; place-items:center; min-width:24px; height:24px; border-radius:99px; background:#111827; color:white; font-size:12px; padding:0 7px; }
.device-row { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:14px 0; border-bottom:1px solid rgba(20,40,70,.07); }
.device-row:last-child { border-bottom:0; }
.device-row > div:first-child { min-width:0; display:flex; flex-direction:column; gap:3px; }
.device-row strong { font-size:15px; }
.device-row span, .device-row small { color:var(--muted); overflow-wrap:anywhere; }
.device-row small { font-size:11px; }
.device-actions { display:flex; align-items:center; gap:8px; flex:0 0 auto; }
.primary-btn.compact, .soft-btn.compact { width:auto; min-width:0; padding:9px 12px; font-size:13px; }
.danger-soft { color:#a32929; }
.admin-empty { color:var(--muted); padding:12px 0; }
@media (max-width: 620px) {
  .admin-card { width:calc(100vw - 16px); max-height:calc(100vh - 16px); border-radius:22px; padding:18px; }
  .device-row { align-items:flex-start; flex-direction:column; }
  .device-actions { width:100%; }
  .device-actions .compact { flex:1; }
}

/* v18 — first-login onboarding + profile photo */
.avatar.has-photo { overflow: hidden; padding: 0; background: #e8eef2; }
.avatar.has-photo img { width: 100%; height: 100%; display: block; object-fit: cover; }
.onboarding-shell {
  width: 100vw; min-height: 100vh; padding: 28px 16px;
  display: grid; place-items: center; overflow: auto;
}
.onboarding-card {
  width: min(680px, 100%); padding: clamp(22px, 4vw, 38px);
  background: rgba(255,255,255,.94); border: 1px solid rgba(36,64,92,.09);
  border-radius: 30px; box-shadow: 0 30px 90px rgba(38,67,96,.16);
  backdrop-filter: blur(26px); color: var(--text);
}
.onboarding-brand { margin-bottom: 26px; }
.onboarding-card h1 { margin: 6px 0 8px; font-size: clamp(30px, 5vw, 46px); letter-spacing: -.05em; }
.onboarding-lead { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }
.onboarding-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.onboarding-card .field { margin: 12px 0; }
.onboarding-card .field label { display: block; margin: 0 0 7px; font-size: 13px; font-weight: 750; }
.onboarding-card .field input {
  width: 100%; min-height: 48px; border-radius: 14px; border: 1px solid rgba(42,72,102,.13);
  padding: 12px 14px; outline: none; background: rgba(246,249,251,.92); color: var(--text);
}
.onboarding-card .field input:focus { border-color: rgba(60,190,150,.7); box-shadow: 0 0 0 4px rgba(60,190,150,.09); }
.onboarding-card .field small { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }
.profile-photo-picker {
  margin: 20px 0 16px; padding: 14px; display: flex; align-items: center; gap: 14px;
  border: 1px dashed rgba(42,72,102,.2); background: rgba(246,249,251,.7); border-radius: 20px;
  cursor: pointer; transition: background .16s ease, transform .16s ease;
}
.profile-photo-picker:hover { background: rgba(241,247,249,.98); }
.profile-photo-picker:active { transform: scale(.99); }
.profile-photo-preview {
  width: 76px; height: 76px; flex: 0 0 76px; border-radius: 24px; overflow: hidden;
  display: grid; place-items: center; background: linear-gradient(145deg, rgba(99,213,179,.28), rgba(110,145,255,.18));
  font-size: 22px; box-shadow: 0 8px 24px rgba(55,84,110,.1);
}
.profile-photo-preview img { width: 100%; height: 100%; display: block; object-fit: cover; }
.profile-photo-picker > span:last-child { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.profile-photo-picker small { color: var(--muted); font-size: 11px; }
.onboarding-submit { margin-top: 10px; width: 100%; min-height: 50px; }
.onboarding-submit:disabled { opacity: .6; cursor: wait; }
.onboarding-note {
  margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: rgba(99,213,179,.08);
  color: var(--muted); font-size: 12px; line-height: 1.5;
}
@media (max-width: 620px) {
  .onboarding-shell { padding: 8px; align-items: start; }
  .onboarding-card { border-radius: 22px; padding: 20px 16px; min-height: calc(100vh - 16px); }
  .onboarding-grid { grid-template-columns: 1fr; gap: 0; }
  .profile-photo-preview { width: 68px; height: 68px; flex-basis: 68px; border-radius: 21px; }
}


/* ===== v19 install / notifications / attachment picker ===== */
.public-nav-actions,
.side-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.install-inline-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.install-inline-btn .i { width: 17px; height: 17px; }

.side-bottom {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}
.side-actions {
  flex-wrap: nowrap;
}
.side-actions .icon-btn {
  width: 40px;
  height: 40px;
}

.attachment-overlay {
  position: fixed;
  inset: 0;
  z-index: 118;
  display: grid;
  place-items: end center;
  padding: 20px;
  background: rgba(42, 55, 68, .18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.attachment-sheet {
  width: min(440px, 100%);
  padding: 10px 12px 12px;
  border-radius: 26px;
  border: 1px solid rgba(85, 110, 132, .13);
  background: rgba(250, 252, 254, .97);
  box-shadow: 0 24px 70px rgba(53, 75, 96, .2);
  animation: attachmentSheetIn .22s cubic-bezier(.2,.8,.2,1) both;
}
.attachment-sheet-handle {
  width: 42px;
  height: 5px;
  margin: 2px auto 10px;
  border-radius: 999px;
  background: #c9d3db;
}
.attachment-sheet-title {
  padding: 5px 8px 10px;
  color: #385266;
  font-size: 14px;
  font-weight: 800;
}
.attachment-choice {
  width: 100%;
  min-height: 68px;
  padding: 9px 10px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
  color: #183245;
  text-align: left;
}
.attachment-choice:hover {
  background: #edf5fa;
}
.attachment-choice:active {
  transform: scale(.985);
}
.attachment-choice-icon {
  width: 48px;
  height: 48px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: #e4f1f8;
  color: #3f89b5;
}
.attachment-choice-icon .i { width: 23px; height: 23px; }
.attachment-choice strong,
.attachment-choice small { display: block; }
.attachment-choice strong { font-size: 14px; }
.attachment-choice small {
  margin-top: 3px;
  color: #7890a1;
  font-size: 11px;
}
.attachment-cancel {
  width: 100%;
  margin-top: 5px;
}
@keyframes attachmentSheetIn {
  from { opacity: 0; transform: translateY(24px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.install-guide-card {
  position: relative;
  width: min(430px, calc(100vw - 28px));
  padding: 30px;
  border: 1px solid rgba(71, 97, 120, .14);
  border-radius: 30px;
  background: rgba(250,252,254,.97);
  color: #183245;
  box-shadow: 0 26px 80px rgba(48,70,89,.22);
  text-align: center;
}
.install-guide-card h2 {
  margin: 8px 0 8px;
  font-size: 26px;
  letter-spacing: -.03em;
}
.install-guide-card p {
  margin: 0 auto 20px;
  max-width: 340px;
  color: #698195;
  line-height: 1.55;
}
.install-app-icon {
  width: 92px;
  height: 92px;
  margin: 0 auto 16px;
  border-radius: 25px;
  overflow: hidden;
  box-shadow: 0 14px 32px rgba(23,46,66,.2);
}
.install-app-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.install-steps {
  margin: 4px 0 20px;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px 10px;
  text-align: left;
  color: #47667c;
}
.install-steps span {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e4f1f8;
  color: #377ea9;
  font-weight: 850;
  font-size: 12px;
}

.call-action.audio-needs-tap,
.notification-btn,
.install-app-btn {
  position: relative;
}
.call-action.audio-needs-tap::after,
.notification-btn::after,
.install-app-btn::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4fa2d4;
  box-shadow: 0 0 0 4px rgba(79,162,212,.13);
}
.call-action.audio-needs-tap {
  animation: audioNeedTap 1.1s ease-in-out infinite alternate;
}
@keyframes audioNeedTap {
  from { box-shadow: 0 0 0 0 rgba(79,162,212,.18); }
  to { box-shadow: 0 0 0 8px rgba(79,162,212,0); }
}

@media (max-width: 760px) {
  .attachment-overlay {
    padding: 10px;
  }
  .attachment-sheet {
    border-radius: 24px 24px 18px 18px;
  }
  .side-bottom {
    grid-template-columns: 1fr;
  }
  .side-actions {
    justify-content: flex-start;
  }
  .public-nav-actions {
    gap: 6px;
  }
  .install-inline-btn span {
    display: none;
  }
}
