/* ============ Семья — modern theme ============ */
:root {
  --bg: #f2f3f8;
  --bg-2: #e9ebf3;
  --card: #ffffff;
  --glass: rgba(255, 255, 255, .78);
  --text: #121826;
  --muted: #6e7790;
  --line: rgba(18, 24, 38, .08);
  --accent: #5b6cff;
  --accent-2: #8b5cf6;
  --grad: linear-gradient(135deg, #5b7cff 0%, #8b5cf6 100%);
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --danger: #ef4c5a;
  --ok: #22c08a;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow: 0 8px 28px rgba(16, 24, 40, .12);
  --radius: 18px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --chat-bg:
    radial-gradient(circle at 12% 18%, rgba(91, 124, 255, .10) 0, transparent 38%),
    radial-gradient(circle at 88% 72%, rgba(139, 92, 246, .10) 0, transparent 40%),
    linear-gradient(180deg, #eef0fb, #f4f1fb);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1017;
    --bg-2: #151a24;
    --card: #171c27;
    --glass: rgba(20, 25, 36, .78);
    --text: #eef1f8;
    --muted: #8d96ad;
    --line: rgba(255, 255, 255, .07);
    --theirs: #1f2533;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    --chat-bg:
      radial-gradient(circle at 12% 18%, rgba(91, 124, 255, .14) 0, transparent 40%),
      radial-gradient(circle at 88% 72%, rgba(139, 92, 246, .12) 0, transparent 42%),
      linear-gradient(180deg, #0f1320, #120f1c);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 15.5px/1.42 -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
svg { display: block; }

#app {
  max-width: 860px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
  background: var(--bg);
  position: relative;
}
@media (min-width: 900px) {
  body { background: var(--bg-2); }
  #app { box-shadow: var(--shadow); }
}
body.with-tabs #app { height: 100dvh; padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 10px); }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; min-height: 60px;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.bar h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-bar h1 { font-size: 17px; font-weight: 700; letter-spacing: 0; }
.bar .sub { font-size: 12.5px; color: var(--muted); font-weight: 500; display: block; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; font-size: 20px;
  border-radius: 12px; cursor: pointer; display: grid; place-items: center; flex: none; color: var(--text);
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--line); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 22px; height: 22px; }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; }

/* ---------- floating bottom tabs ---------- */
#tabs {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(8px + var(--safe-b));
  width: min(560px, calc(100vw - 20px)); height: var(--tabs-h);
  display: flex; padding: 6px; gap: 4px;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); z-index: 10;
}
#tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 10.5px; font-weight: 600; position: relative; min-width: 0; white-space: nowrap;
  border-radius: 16px; transition: background .2s, color .2s;
}
#tabs a .ti svg { width: 23px; height: 23px; }
#tabs a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.badge {
  background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center;
}
#tabs .badge { position: absolute; top: 3px; left: calc(50% + 6px); box-shadow: 0 0 0 2px var(--card); }

/* ---------- common ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 11px 18px; cursor: pointer;
  background: var(--grad); color: #fff; font-weight: 650;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: transform .1s, filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(.97); }
.btn.secondary { background: var(--bg-2); color: var(--text); box-shadow: none; }
.btn.danger { background: var(--danger); box-shadow: none; }
.btn:disabled { opacity: .45; pointer-events: none; }
.input, textarea.input, select.input {
  width: 100%; padding: 12px 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--card); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.card { background: var(--card); border-radius: 20px; padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.avatar {
  --c: #8a94a8;
  width: 50px; height: 50px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--c) 75%, #fff), var(--c) 55%, color-mix(in srgb, var(--c) 70%, #000));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15);
}
.avatar.group { font-size: 22px; }
.avatar.sm { width: 36px; height: 36px; font-size: 14px; }
.avatar.sm.group { font-size: 17px; }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.fab {
  position: fixed; right: max(18px, calc(50% - 430px + 18px)); bottom: calc(var(--tabs-h) + var(--safe-b) + 24px);
  width: 58px; height: 58px; border-radius: 20px; border: 0; z-index: 9;
  background: var(--grad); color: #fff; cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .15s;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 26px; height: 26px; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--safe-b) + 28px);
  background: rgba(20, 24, 34, .88); backdrop-filter: blur(10px); color: #fff; padding: 11px 18px; border-radius: 14px; z-index: 300;
  max-width: 90vw; font-weight: 500; box-shadow: var(--shadow); animation: pop .2s ease-out;
}

@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px) scale(.97); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes sheet { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- login ---------- */
.login { margin: auto; width: min(380px, 92vw); background: var(--card); padding: 32px 26px; border-radius: 28px; box-shadow: var(--shadow); animation: rise .3s ease-out; }
.login .logo { font-size: 54px; text-align: center; width: 92px; height: 92px; margin: 0 auto; display: grid; place-items: center; border-radius: 28px; background: var(--grad); box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 40%, transparent); }
.login h1 { text-align: center; margin: 16px 0 22px; font-size: 28px; letter-spacing: -.02em; }

/* ---------- list rows ---------- */
.list-item {
  display: flex; gap: 14px; align-items: center; padding: 10px 16px;
  text-decoration: none; color: inherit; cursor: pointer; position: relative; transition: background .15s;
}
.list-item::after { content: ""; position: absolute; left: 80px; right: 16px; bottom: 0; height: 1px; background: var(--line); }
.list-item:last-child::after { display: none; }
.list-item:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.list-item:active { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .preview { color: var(--muted); font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.list-item .side { text-align: right; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; align-self: flex-start; padding-top: 4px; }
.list-item .side .badge { background: var(--grad); }

/* ---------- chat ---------- */
.chat-bg { background: transparent; }
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 3px; }
.day-sep {
  align-self: center; font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: var(--glass); backdrop-filter: blur(8px); padding: 4px 12px; border-radius: 12px; margin: 10px 0 6px;
  position: sticky; top: 4px; z-index: 1; box-shadow: var(--shadow-sm);
}
.msg-row { display: flex; transition: transform .15s; position: relative; animation: rise .18s ease-out; }
.msg-row.mine { justify-content: flex-end; }
.msg-row::before {
  content: ""; position: absolute; right: -36px; top: 50%; width: 28px; height: 28px; margin-top: -14px; border-radius: 50%;
  background: var(--glass) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6cff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 17l-5-5 5-5'/%3E%3Cpath d='M20 18v-2a4 4 0 00-4-4H4'/%3E%3C/svg%3E") center / 16px no-repeat;
  opacity: 0; transition: opacity .15s;
}
.msg-row.swipe-ready::before { opacity: 1; }
.msg-row.pressed .msg { transform: scale(.98); filter: brightness(.95); }
.msg-row.flash .msg { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 45%, transparent); } }

.msg {
  max-width: min(80%, 540px); padding: 7px 12px 6px; border-radius: 20px 20px 20px 6px;
  background: var(--theirs); position: relative; word-wrap: break-word; overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm); cursor: pointer; user-select: text; transition: transform .12s, filter .12s;
}
.msg.mine { background: var(--grad); color: var(--mine-text); border-radius: 20px 20px 6px 20px; }
.msg.mine a { color: #fff; }
.msg .who { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; }
.msg.emoji-only { background: transparent; box-shadow: none; padding: 0 4px; }
.msg .text.big { font-size: 46px; line-height: 1.12; }
.msg.emoji-only .meta { color: var(--muted); opacity: 1; }
.msg .meta { font-size: 11px; opacity: .72; text-align: right; margin-top: 2px; display: flex; gap: 4px; justify-content: flex-end; align-items: center; font-variant-numeric: tabular-nums; }
.msg .tick { font-size: 12px; letter-spacing: -3px; padding-right: 3px; }
.msg .tick.read { color: #b8f5dc; }
.msg img, .msg video { display: block; max-width: 100%; max-height: 380px; border-radius: 14px; margin: 3px 0 4px; background: rgba(0, 0, 0, .1); }
.msg img { cursor: zoom-in; }
.msg.media-only { padding: 4px; }
.msg.media-only img, .msg.media-only video { margin: 0; border-radius: 16px; }
.msg.media-only .meta { position: absolute; right: 12px; bottom: 10px; background: rgba(0, 0, 0, .45); color: #fff; padding: 2px 7px; border-radius: 10px; opacity: 1; }
.msg.media-only .who, .msg.media-only .fwd, .msg.media-only .quote { margin-left: 8px; margin-right: 8px; }
.msg .file { display: inline-flex; gap: 6px; align-items: center; color: inherit; font-weight: 600; }
.fwd { display: flex; align-items: center; gap: 5px; font-size: 12.5px; opacity: .85; margin: 1px 0 3px; }
.fwd svg { width: 14px; height: 14px; }
.quote {
  border-left: 3px solid var(--qc); background: color-mix(in srgb, var(--qc) 12%, transparent);
  border-radius: 8px; padding: 4px 9px; margin: 2px 0 5px; font-size: 13.5px; cursor: pointer; max-width: 100%;
}
.msg.mine .quote { border-left-color: rgba(255, 255, 255, .85); background: rgba(255, 255, 255, .16); }
.quote b { display: block; font-size: 12.5px; color: var(--qc); }
.msg.mine .quote b { color: #fff; }
.quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }
.typing { font-size: 12.5px; color: var(--accent); font-weight: 600; padding: 0 18px 2px; min-height: 18px; background: transparent; }

.reply-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px 6px 14px;
  background: var(--glass); backdrop-filter: blur(16px); border-top: 1px solid var(--line); animation: rise .15s ease-out;
}
.reply-bar .rb-icon { color: var(--accent); }
.reply-bar .rb-main { flex: 1; min-width: 0; border-left: 3px solid var(--qc); padding-left: 9px; font-size: 13.5px; }
.reply-bar .rb-main b { display: block; color: var(--qc); font-size: 13px; }
.reply-bar .rb-main span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--glass); backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.composer .icon-btn { color: var(--muted); }
.input-wrap { flex: 1; display: flex; align-items: flex-end; background: var(--card); border: 1.5px solid var(--line); border-radius: 22px; padding-left: 14px; transition: border-color .15s; }
.input-wrap:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.input-wrap textarea { flex: 1; resize: none; max-height: 140px; border: 0; background: transparent; outline: none; padding: 10px 0; line-height: 1.35; }
.input-wrap .emoji-btn { width: 40px; height: 42px; border-radius: 20px; }
.composer .send {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; flex: none;
  background: var(--grad); color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent); transition: transform .1s;
}
.composer .send svg { width: 20px; height: 20px; margin-left: -2px; }
.composer .send:active { transform: scale(.9); }
.emoji-panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); max-height: 240px; overflow-y: auto; background: var(--card); border-top: 1px solid var(--line); padding: 8px; animation: rise .15s ease-out; }
.emoji-panel button { border: 0; background: none; font-size: 27px; padding: 5px; cursor: pointer; border-radius: 12px; transition: transform .1s; }
.emoji-panel button:hover { background: var(--bg-2); transform: scale(1.15); }
.upload-progress { height: 3px; background: var(--grad); transition: width .2s; }

.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 200; display: grid; place-items: center; animation: fade .15s; }
.viewer img { max-width: 100vw; max-height: 100dvh; }
.viewer .icon-btn { position: absolute; top: calc(12px + var(--safe-t)); color: #fff; background: rgba(255, 255, 255, .14); border-radius: 50%; }
.viewer .close { right: 12px; }
.viewer .dl { right: 62px; text-decoration: none; }

.pick-user { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick-user:last-child { border-bottom: 0; }
.pick-user input { width: 22px; height: 22px; accent-color: var(--accent); }
.fwd-list { max-height: 55dvh; overflow-y: auto; }

/* "Share → Семья" screen */
.share-page textarea { resize: vertical; }
.sh-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.sh-thumb { flex: none; width: 96px; height: 96px; object-fit: cover; border-radius: 14px; background: var(--bg-2); scroll-snap-align: start; }
.sh-file { flex: none; width: 120px; height: 96px; border-radius: 14px; background: var(--bg-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px; font-size: 26px; text-align: center; }
.sh-file span { font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sh-file small { font-size: 11px; color: var(--muted); }
.sh-list { margin: 10px 0 14px; background: var(--card, transparent); border-radius: 14px; }
.sh-prog { margin-bottom: 6px; }
#shLib { display: flex; align-items: center; justify-content: center; gap: 8px; }
#shLib svg { width: 20px; height: 20px; flex: none; }

.viewer video { max-width: 100vw; max-height: 100dvh; }

/* ---------- chat header + info panel ---------- */
.chat-head { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: 14px; padding: 4px 6px; margin: -4px -6px; transition: background .15s; }
.chat-head:hover { background: var(--line); }
.chat-head h1 { min-width: 0; }
.panel {
  position: fixed; top: 0; bottom: 0; left: 0; right: 0; margin: 0 auto; width: min(860px, 100vw); z-index: 120;
  background: var(--bg); display: flex; flex-direction: column; padding-top: var(--safe-t);
  animation: slide-in .25s cubic-bezier(.2, .9, .3, 1);
}
.panel.closing { animation: slide-out .2s ease-in forwards; }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
@keyframes slide-out { to { transform: translateX(40px); opacity: 0; } }
.panel .scroll { padding-bottom: calc(20px + var(--safe-b)); }
.info-head { display: flex; flex-direction: column; align-items: center; padding: 22px 16px 14px; text-align: center; }
.info-head h2 { margin: 12px 0 2px; font-size: 22px; letter-spacing: -.01em; }
.avatar.xl { width: 96px; height: 96px; font-size: 36px; box-shadow: var(--shadow); }
.avatar.xl.group { font-size: 44px; }
.seg .cnt { font-size: 12px; opacity: .6; font-weight: 600; }
.month { grid-column: 1 / -1; font-size: 13px; font-weight: 700; color: var(--muted); padding: 14px 4px 6px; }
.month::first-letter { text-transform: uppercase; }
#libBody > .month { padding-left: 16px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 3px; padding: 0 12px; }
.mg { position: relative; aspect-ratio: 1 / 1; border: 0; padding: 0; cursor: pointer; overflow: hidden; border-radius: 6px; background: var(--bg-2); }
.mg img, .mg video { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.mg:hover img, .mg:hover video { transform: scale(1.04); }
.mg .play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 34px; height: 34px; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; display: grid; place-items: center; font-size: 13px; padding-left: 2px; }
.shared-row { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: var(--card); border-radius: 14px; margin-bottom: 8px; text-decoration: none; color: inherit; box-shadow: var(--shadow-sm); }
.shared-row:hover { background: color-mix(in srgb, var(--accent) 6%, var(--card)); }
.shared-row b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shared-row span { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shared-row span.url { color: var(--accent); }
.sr-icon { width: 44px; height: 44px; border-radius: 12px; flex: none; display: grid; place-items: center; font-size: 22px; background: var(--bg-2); }
.sr-icon.link { background: var(--grad); color: #fff; font-weight: 800; font-size: 19px; }

/* ---------- library ---------- */
.crumbs { padding: 8px 16px 2px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow-x: auto; }
.crumbs a { color: var(--accent); text-decoration: none; font-weight: 600; }
.crumbs span { margin: 0 2px; }
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 14px 16px 4px; }
.folder {
  display: flex; align-items: center; gap: 10px; padding: 12px; background: var(--card); border-radius: 16px;
  text-decoration: none; color: inherit; font-weight: 600; font-size: 14.5px; box-shadow: var(--shadow-sm); transition: transform .12s;
}
.folder:active { transform: scale(.97); }
.folder span { min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; word-break: break-word; }
.folder-ic { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #ffb84d, #f08a24); }
.folder-ic svg { width: 22px; height: 22px; }
.mg-ph { width: 100%; height: 100%; display: grid; place-items: center; font-size: 30px; background: var(--bg-2); }
.gallery img, .gallery video { max-width: 100vw; max-height: calc(100dvh - 70px); object-fit: contain; }
.gallery .g-cap { position: absolute; left: 0; right: 0; bottom: calc(14px + var(--safe-b)); text-align: center; color: #fff; font-size: 13px; opacity: .8; padding: 0 70px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery .g-prev, .gallery .g-next { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; color: #fff; background: rgba(255, 255, 255, .14); border-radius: 50%; }
.gallery .g-prev { left: 12px; }
.gallery .g-next { right: 12px; }
.viewer .dl svg, .viewer .close svg { width: 22px; height: 22px; }

/* ---------- action sheet (message menu) ---------- */
.sheet-bg .modal { background: transparent; box-shadow: none; padding: 0 10px calc(12px + var(--safe-b)); }
.sheet-preview {
  background: var(--card); border-radius: 18px; padding: 12px 16px; margin-bottom: 8px; color: var(--muted); font-size: 14px;
  white-space: pre-wrap; max-height: 120px; overflow: hidden; box-shadow: var(--shadow);
}
.action-list { background: var(--card); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.action-list button {
  width: 100%; display: flex; align-items: center; gap: 14px; padding: 15px 18px; border: 0; background: none; cursor: pointer;
  font-size: 16px; font-weight: 550; text-align: left; border-bottom: 1px solid var(--line);
}
.action-list button:last-child { border-bottom: 0; }
.action-list button:hover { background: var(--bg-2); }
.action-list button svg { width: 21px; height: 21px; color: var(--accent); }
.action-list button.danger, .action-list button.danger svg { color: var(--danger); }

/* ---------- notes ---------- */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; padding: 16px; }
.note-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 14px; cursor: pointer; min-height: 110px; overflow: hidden;
  box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s; animation: rise .2s ease-out;
}
.note-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.note-card b { display: block; margin-bottom: 6px; font-size: 15.5px; }
.note-card p { margin: 0; color: var(--muted); font-size: 14px; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.note-editor { display: flex; flex-direction: column; flex: 1; padding: 16px 18px; gap: 10px; }
.note-editor input { font-size: 24px; font-weight: 800; letter-spacing: -.01em; border: 0; background: transparent; outline: none; }
.note-editor textarea { flex: 1; border: 0; background: transparent; outline: none; resize: none; font-size: 16.5px; line-height: 1.55; }

/* ---------- calendar ---------- */
.seg { display: flex; background: var(--bg-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 11px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }
.cal-head { display: flex; align-items: center; gap: 6px; padding: 12px 16px 4px; }
.cal-head h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 800; text-transform: capitalize; letter-spacing: -.01em; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; padding: 6px 12px; }
.cal-grid .dow { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; text-transform: uppercase; }
.cal-day {
  aspect-ratio: 1 / 1; max-height: 78px; border-radius: 14px; background: var(--card); padding: 5px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; position: relative; box-shadow: var(--shadow-sm); transition: transform .1s;
}
.cal-day:active { transform: scale(.94); }
.cal-day.other { opacity: .35; }
.cal-day.today .n { background: var(--grad); color: #fff; border-radius: 50%; }
.cal-day.sel { box-shadow: 0 0 0 2px var(--accent); }
.cal-day.weekend .n { color: var(--danger); }
.cal-day.today.weekend .n { color: #fff; }
.cal-day .n { font-size: 14px; font-weight: 700; width: 26px; height: 26px; display: grid; place-items: center; }
.cal-day .dots { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; margin-top: auto; }
.cal-day .dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.cal-day.marked { background: color-mix(in srgb, var(--mark) 26%, var(--card)); }
.event {
  display: flex; gap: 12px; padding: 12px 14px; background: var(--card); border-radius: 16px; margin-bottom: 10px; cursor: pointer;
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden; animation: rise .2s ease-out;
}
.event::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.event .t { font-size: 13px; font-weight: 700; color: var(--muted); min-width: 52px; padding-left: 4px; }
.event .info { flex: 1; min-width: 0; }
.event .info b { display: block; margin-bottom: 3px; }
.chip { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 8px; background: var(--bg-2); color: var(--muted); margin-right: 4px; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.colors button { width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25); transition: transform .1s; }
.colors button.on { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--text); transform: scale(1.05); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 10, 18, .45); backdrop-filter: blur(3px); z-index: 150; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.modal {
  background: var(--bg); width: min(560px, 100vw); max-height: 92dvh; overflow-y: auto;
  border-radius: 26px 26px 0 0; padding: 20px 18px calc(18px + var(--safe-b)); animation: sheet .25s cubic-bezier(.2, .9, .3, 1); box-shadow: var(--shadow);
}
.modal-bg.closing { opacity: 0; transition: opacity .18s; }
@media (min-width: 700px) {
  .modal-bg { align-items: center; }
  .modal { border-radius: 26px; animation: rise .2s ease-out; }
  .sheet-bg .modal { width: 380px; }
}
.modal h2 { margin: 0 0 16px; font-size: 20px; font-weight: 800; }

/* ============ wallpapers (chat + whole app) ============
   gradient + an original doodle pattern drawn through a CSS mask so it can be tinted per theme */
:root, [data-wall="doodle"] {
  --wall-grad: linear-gradient(160deg, #dfe7fb 0%, #e9e4fb 55%, #f3e6f6 100%);
  --wall-ink: #34407a;
  --wall-op: .10;
}
[data-wall="sunset"] { --wall-grad: linear-gradient(160deg, #ffe4d2 0%, #fbd9e6 60%, #efd9f7 100%); --wall-ink: #9b3a63; --wall-op: .11; }
[data-wall="mint"]   { --wall-grad: linear-gradient(160deg, #d8f4ea 0%, #dcefef 50%, #e1ecfb 100%); --wall-ink: #1d6b5b; --wall-op: .11; }
[data-wall="ocean"]  { --wall-grad: linear-gradient(160deg, #d3e8ff 0%, #d9e2ff 50%, #e6dcff 100%); --wall-ink: #1f4f9a; --wall-op: .11; }
[data-wall="plain"]  { --wall-grad: linear-gradient(180deg, #eef0f8, #f3f1f8); --wall-op: 0; }
@media (prefers-color-scheme: dark) {
  :root, [data-wall="doodle"] { --wall-grad: linear-gradient(160deg, #0e1426 0%, #141530 55%, #1a1230 100%); --wall-ink: #b6c3ff; --wall-op: .065; }
  [data-wall="sunset"] { --wall-grad: linear-gradient(160deg, #2a1520 0%, #24132b 60%, #1a1233 100%); --wall-ink: #ffb8cf; --wall-op: .065; }
  [data-wall="mint"]   { --wall-grad: linear-gradient(160deg, #0c211e 0%, #0d1d22 50%, #0f1828 100%); --wall-ink: #93f0d6; --wall-op: .06; }
  [data-wall="ocean"]  { --wall-grad: linear-gradient(160deg, #0a1a33 0%, #0e1838 50%, #16122e 100%); --wall-ink: #9cc4ff; --wall-op: .065; }
  [data-wall="plain"]  { --wall-grad: linear-gradient(180deg, #0f131c, #111420); --wall-op: 0; }
}

#app { background: var(--wall-grad); isolation: isolate; }
#app::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: var(--wall-ink);
  -webkit-mask: url("/bg/doodles.svg") 0 0 / 380px 380px repeat;
          mask: url("/bg/doodles.svg") 0 0 / 380px 380px repeat;
  opacity: calc(var(--wall-op) * .55); /* calmer on lists, notes, calendar */
  transition: opacity .25s;
}
body.in-chat #app::before { opacity: var(--wall-op); }

/* wallpaper picker */
.walls { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.wall-opt { border: 0; padding: 0; cursor: pointer; background: none; text-align: center; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.wall-opt .sw {
  display: block; height: 104px; border-radius: 16px; margin-bottom: 6px; position: relative; overflow: hidden; background: var(--wall-grad);
  box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .15s;
}
.wall-opt .sw::before {
  content: ""; position: absolute; inset: 0; background: var(--wall-ink);
  -webkit-mask: url("/bg/doodles.svg") 0 0 / 190px 190px repeat; mask: url("/bg/doodles.svg") 0 0 / 190px 190px repeat;
  opacity: calc(var(--wall-op) * 1.6);
}
.wall-opt .sw::after { content: ""; position: absolute; right: 10px; bottom: 12px; width: 38px; height: 16px; border-radius: 8px 8px 3px 8px; background: var(--grad); }
.wall-opt .sw i { position: absolute; left: 10px; top: 14px; width: 44px; height: 16px; border-radius: 8px 8px 8px 3px; background: var(--card); z-index: 1; }
.wall-opt.on { color: var(--accent); }
.wall-opt.on .sw { box-shadow: 0 0 0 3px var(--accent); }
.wall-opt:active .sw { transform: scale(.96); }

/* ---------- pinned messages ---------- */
.pin-bar {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px; cursor: pointer;
  background: var(--glass); backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line); position: relative; z-index: 4; animation: rise .15s ease-out;
}
.pb-segs { display: flex; flex-direction: column; gap: 2px; height: 34px; width: 3px; }
.pb-segs i { flex: 1; border-radius: 2px; background: color-mix(in srgb, var(--accent) 30%, transparent); }
.pb-segs i.on { background: var(--accent); }
.pb-main { flex: 1; min-width: 0; font-size: 13.5px; }
.pb-main b { display: block; color: var(--accent); font-size: 13px; }
.pb-main b span { opacity: .7; font-weight: 600; }
.pb-main > span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-bar .pb-close { color: var(--muted); width: 34px; height: 34px; }
.pin-bar .pb-close svg { width: 18px; height: 18px; }
.msg .pin-ic svg { width: 12px; height: 12px; }
.msg .pin-ic { display: inline-flex; }
.msg .pin-ic[hidden] { display: none; }
/* ---------- library: editing, drag & drop, access, player ---------- */
.lib-body .folder, .lib-body .mg, .lib-body .shared-row { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.lib-body img, .lib-body video { -webkit-touch-callout: none; }
.folder { position: relative; cursor: pointer; padding-right: 36px; }
.folder .more, .shared-row .more { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border: 0; background: none; color: var(--muted); border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.folder .more:hover, .shared-row .more:hover { background: var(--bg-2); }
.folder .more svg, .shared-row .more svg { width: 18px; height: 18px; }
.shared-row { position: relative; padding-right: 42px; cursor: pointer; }
.mg .mg-more { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border: 0; border-radius: 50%; background: rgba(0,0,0,.45); color: #fff; display: grid; place-items: center; cursor: pointer; opacity: .85; }
.mg .mg-more svg { width: 16px; height: 16px; }
@media (hover: hover) { .mg .mg-more { opacity: 0; transition: opacity .15s; } .mg:hover .mg-more { opacity: 1; } }
.folder-ic { position: relative; }
.lock-badge { position: absolute; right: -4px; bottom: -4px; width: 18px; height: 18px; border-radius: 50%; background: var(--card); color: var(--danger); display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.lock-badge svg { width: 11px; height: 11px; }
.folder-ic.sm { width: 30px; height: 30px; border-radius: 9px; }
.folder-ic.sm svg { width: 16px; height: 16px; }
.drop-over.folder, a.drop-over { box-shadow: 0 0 0 3px var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
.lib-body.drop-over { outline: 3px dashed var(--accent); outline-offset: -10px; border-radius: 18px; }
.dragging { opacity: .45; }
.sr-icon.audio { background: linear-gradient(135deg, #ff7eb3, #8b5cf6); color: #fff; font-size: 22px; font-weight: 700; }

.fp-list { max-height: 50dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.fp-row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; border-radius: 12px; background: var(--card); cursor: pointer; text-align: left; font-weight: 600; box-shadow: var(--shadow-sm); }
.fp-row > span:not(.folder-ic) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-row svg { width: 18px; height: 18px; color: var(--muted); }
.fp-row:disabled { opacity: .4; cursor: default; }

.acl-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.acl-row:last-of-type { border-bottom: 0; }
.acl-sel { width: auto; max-width: 56%; padding: 8px 10px; font-size: 14px; }

.up-panel { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--safe-b) + 24px); width: min(520px, calc(100vw - 24px)); z-index: 160; background: var(--card); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); animation: rise .2s ease-out; }
.up-text { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 8px; }
.up-bar { height: 6px; border-radius: 3px; background: var(--bg-2); overflow: hidden; }
.up-bar i { display: block; height: 100%; background: var(--grad); transition: width .2s; }

.player {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--safe-b) + 16px); z-index: 11;
  width: min(560px, calc(100vw - 20px)); display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 10px;
  background: var(--glass); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); animation: rise .2s ease-out;
}
body:not(.with-tabs) .player { bottom: calc(var(--safe-b) + 84px); }
.pl-ic { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff; font-size: 20px; background: linear-gradient(135deg, #ff7eb3, #8b5cf6); }
.pl-main { flex: 1; min-width: 0; padding: 0 6px; }
.pl-main b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-row { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pl-row input { flex: 1; min-width: 0; accent-color: var(--accent); height: 14px; }
.player .icon-btn { width: 34px; height: 34px; font-size: 15px; }
.player .pl-play { background: var(--grad); color: #fff; border-radius: 50%; }
.player .icon-btn:disabled { opacity: .35; }
body.with-tabs .fab { bottom: calc(var(--tabs-h) + var(--safe-b) + 24px); }
body.has-player .fab { bottom: calc(var(--tabs-h) + var(--safe-b) + 92px); }
/* ---------- chat search ---------- */
.search-bar input { flex: 1; border-radius: 14px; }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(60px + var(--safe-t)); bottom: 0; z-index: 6; overflow-y: auto;
  background: var(--bg); padding: 6px 10px 20px; animation: fade .15s;
}
.sr-count { font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 6px 6px 8px; }
.sr-item { width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; border: 0; background: var(--card); border-radius: 14px; padding: 10px 12px; margin-bottom: 6px; cursor: pointer; box-shadow: var(--shadow-sm); }
.sr-item:hover { background: color-mix(in srgb, var(--accent) 6%, var(--card)); }
.sr-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.sr-top span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.sr-text { font-size: 14px; color: var(--text); margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sr-text mark { background: color-mix(in srgb, #ffd43b 70%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- composer: mic ↔ send, recording ---------- */
.composer { position: relative; }
.composer #sendBtn { display: none; }
.composer.has-text #sendBtn { display: grid; }
.composer.has-text #micBtn { display: none; }
.composer .mic { background: var(--grad); }
.composer.recording > :not(.rec-bar) { visibility: hidden; }
.rec-bar { position: absolute; inset: 8px 10px calc(8px + var(--safe-b)); display: flex; align-items: center; gap: 10px; }
.rec-bar .btn { padding: 8px 14px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; flex: none; }
#recTime { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 40px; }
.rec-hint { flex: 1; color: var(--muted); font-size: 14px; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- voice messages ---------- */
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 2px 0; --p: 0; }
.vplay { width: 42px; height: 42px; border-radius: 50%; border: 0; flex: none; cursor: pointer; display: grid; place-items: center; background: var(--grad); color: #fff; }
.msg.mine .vplay { background: #fff; color: var(--accent); }
.vplay svg { width: 18px; height: 18px; margin-left: 2px; }
.voice.playing .vplay svg { margin-left: 0; }
.vwave { flex: 1; height: 30px; display: flex; align-items: center; gap: 2px; cursor: pointer;
  -webkit-mask: linear-gradient(90deg, #000 calc(var(--p) * 100%), rgba(0,0,0,.35) calc(var(--p) * 100%));
          mask: linear-gradient(90deg, #000 calc(var(--p) * 100%), rgba(0,0,0,.35) calc(var(--p) * 100%)); }
.vwave i { flex: 1; min-width: 2px; border-radius: 2px; background: currentColor; }
.msg:not(.mine) .vwave { color: var(--accent); }
.vdur { font-size: 12px; font-variant-numeric: tabular-nums; opacity: .8; min-width: 32px; }
.vtr { display: inline-flex; align-items: center; gap: 5px; margin: 4px 0 0; border: 0; background: color-mix(in srgb, currentColor 12%, transparent); color: inherit; border-radius: 10px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.vtr svg { width: 14px; height: 14px; }
.vtr:disabled { opacity: .7; }
.vtext { margin-top: 6px; padding: 6px 10px; border-radius: 10px; font-size: 14px; background: color-mix(in srgb, currentColor 9%, transparent); white-space: pre-wrap; }

/* ---------- stickers in chat ---------- */
.sticker-img { width: 170px !important; height: 170px; max-height: none !important; object-fit: contain; background: none !important; margin: 0 !important; cursor: pointer; }
.msg.emoji-only .sticker-img { filter: drop-shadow(0 4px 10px rgba(0,0,0,.15)); }

/* ---------- emoji & sticker panel ---------- */
.emoji-panel { display: flex !important; flex-direction: column; padding: 0; max-height: 300px; height: 300px; grid-template-columns: none; }
.emoji-panel[hidden] { display: none !important; }
.ep-tabs { display: flex; gap: 6px; padding: 8px 10px 4px; }
.ep-tabs button { flex: 1; border: 0; border-radius: 12px; padding: 7px; background: var(--bg-2); font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); }
.ep-tabs button.on { background: var(--grad); color: #fff; }
.ep-cats { display: flex; gap: 2px; padding: 2px 8px; overflow-x: auto; border-bottom: 1px solid var(--line); flex: none; }
.ep-cats button { border: 0; background: none; font-size: 20px; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.ep-cats button:hover { background: var(--bg-2); }
.ep-scroll { flex: 1; overflow-y: auto; padding: 0 8px 10px; }
.ep-title { font-size: 12px; font-weight: 700; color: var(--muted); padding: 10px 4px 4px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.ep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
.ep-grid button { border: 0; background: none; font-size: 27px; padding: 4px; cursor: pointer; border-radius: 10px; transition: transform .1s; }
.ep-grid button:hover { background: var(--bg-2); transform: scale(1.15); }
.st-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; }
.st-grid .st { border: 0; background: none; padding: 4px; border-radius: 14px; cursor: pointer; aspect-ratio: 1 / 1; transition: transform .12s, background .12s; }
.st-grid .st:hover { background: var(--bg-2); transform: scale(1.06); }
.st-grid .st img { width: 100%; height: 100%; object-fit: contain; }
.st-add { border: 2px dashed var(--line); background: none; border-radius: 14px; aspect-ratio: 1 / 1; cursor: pointer; color: var(--accent); font-size: 28px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.st-add span { font-size: 11px; font-weight: 600; }

/* ---------- webcam ---------- */
.cam-view { width: 100%; max-height: 60dvh; border-radius: 16px; background: #000; display: block; }
/* ---- round video messages ("кружки") ---- */
.composer.has-text #circleBtn { display: none; }
.composer #circleBtn { width: 44px; height: 44px; flex: none; }
.composer #circleBtn svg { width: 26px; height: 26px; }
.msg.circle-only { background: transparent !important; box-shadow: none; padding: 0; }
.msg.circle-only .meta { color: var(--muted); opacity: 1; justify-content: flex-end; }
.msg.circle-only .quote, .msg.circle-only .fwd, .msg.circle-only .who { background: var(--card); border-radius: 10px; padding: 4px 9px; }
.circle { position: relative; width: min(240px, 64vw); aspect-ratio: 1; border-radius: 50%; cursor: pointer; margin: 2px 0; }
.msg .circle video { width: 100%; height: 100%; max-height: none; object-fit: cover; border-radius: 50%; margin: 0; background: #111; display: block; }
.cring { position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px); transform: rotate(-90deg); pointer-events: none; }
.cring circle { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; opacity: 0; transition: stroke-dashoffset .25s linear, opacity .2s; }
.circle.playing .cring circle { opacity: .95; }
.cplay { position: absolute; inset: 0; margin: auto; width: 52px; height: 52px; border-radius: 50%; background: rgba(0, 0, 0, .45); color: #fff; display: grid; place-items: center; pointer-events: none; transition: opacity .2s; }
.cplay svg { width: 24px; height: 24px; margin-left: 3px; }
.circle.playing .cplay { opacity: 0; }
.cdur { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); background: rgba(0, 0, 0, .5); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 10px; font-variant-numeric: tabular-nums; pointer-events: none; }

.circle-rec { position: fixed; inset: 0; z-index: 60; background: rgba(5, 10, 30, .82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; animation: fade .15s; padding-bottom: var(--safe-b); }
.cr-stage { position: relative; width: min(78vw, 340px); aspect-ratio: 1; }
.cr-view { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #000; display: block; }
.cr-view.mirror { transform: scaleX(-1); }
.cr-ring { position: absolute; inset: -7px; width: calc(100% + 14px); height: calc(100% + 14px); transform: rotate(-90deg); }
.cr-ring circle { fill: none; stroke: #ff4d5e; stroke-width: 2.4; stroke-linecap: round; transition: stroke-dashoffset .1s linear; }
.cr-time { color: #fff; display: flex; align-items: center; gap: 8px; font-size: 17px; font-variant-numeric: tabular-nums; }
.cr-time .muted { color: rgba(255, 255, 255, .6); }
.cr-actions { display: flex; align-items: center; gap: 34px; }
.cr-btn { border: 0; background: rgba(255, 255, 255, .14); color: #fff; width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; position: relative; }
.cr-btn svg { width: 24px; height: 24px; }
.cr-btn span { position: absolute; top: 64px; font-size: 12px; white-space: nowrap; color: rgba(255, 255, 255, .8); }
.cr-btn.send-big { width: 76px; height: 76px; background: var(--grad); box-shadow: 0 8px 24px rgba(79, 124, 255, .5); }
.cr-btn.send-big svg { width: 30px; height: 30px; margin-left: -3px; }

/* ---- calls ---- */
.call-screen { position: fixed; inset: 0; z-index: 70; background: radial-gradient(120% 80% at 50% 0%, #2a3f9e 0%, #0b1440 55%, #050916 100%); color: #fff; display: flex; flex-direction: column; align-items: center; animation: fade .2s; overflow: hidden; }
.call-screen.closing { opacity: 0; transition: opacity .2s; }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; opacity: 0; transition: opacity .3s; }
.call-screen.has-video .call-remote { opacity: 1; }
.call-peer { position: relative; margin-top: calc(14dvh + env(safe-area-inset-top)); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 0 20px; }
.call-screen.has-video .call-peer { margin-top: calc(18px + env(safe-area-inset-top)); flex-direction: row; gap: 10px; background: rgba(0, 0, 0, .35); padding: 6px 14px 6px 6px; border-radius: 30px; }
.call-avatar .avatar { width: 120px; height: 120px; font-size: 44px; box-shadow: 0 0 0 10px rgba(255, 255, 255, .06), 0 0 0 22px rgba(255, 255, 255, .03); }
.call-screen:not(.has-video) .call-avatar .avatar { animation: callpulse 2s infinite; }
.call-screen.has-video .call-avatar .avatar { width: 34px; height: 34px; font-size: 14px; box-shadow: none; animation: none; }
.call-screen.has-video .call-avatar + .call-name { font-size: 15px; }
.call-name { font-size: 26px; font-weight: 700; }
.call-status { font-size: 15px; color: rgba(255, 255, 255, .75); font-variant-numeric: tabular-nums; }
.call-screen.has-video .call-name, .call-screen.has-video .call-status { font-size: 14px; }
.call-local { position: absolute; right: 14px; bottom: calc(150px + var(--safe-b)); width: 28vw; max-width: 160px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 16px; background: #222; box-shadow: 0 6px 24px rgba(0, 0, 0, .5); z-index: 2; }
.call-local.mirror { transform: scaleX(-1); }
.call-ctrls { position: absolute; left: 0; right: 0; bottom: calc(34px + var(--safe-b)); display: flex; justify-content: center; gap: 22px; z-index: 3; flex-wrap: wrap; padding: 0 12px; }
.call-btn { width: 62px; height: 62px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .16); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); color: #fff; display: grid; place-items: center; cursor: pointer; position: relative; margin-bottom: 22px; transition: transform .1s; }
.call-btn:active { transform: scale(.92); }
.call-btn svg { width: 26px; height: 26px; }
.call-btn span { position: absolute; top: 68px; font-size: 12px; white-space: nowrap; color: rgba(255, 255, 255, .85); }
.call-btn.off { background: #fff; color: #111; }
.call-btn.red { background: #ef3b4b; }
.call-btn.green { background: #22b35e; }
.call-btn.hang svg { transform: rotate(135deg); }
.call-btn.green:first-of-type, .call-ctrls .green { animation: callpulse 1.6s infinite; }
@keyframes callpulse { 0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .35); } 70% { box-shadow: 0 0 0 18px rgba(255, 255, 255, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); } }

.call-log { display: flex; align-items: center; gap: 10px; border: 0; background: none; color: inherit; padding: 2px 4px 2px 0; cursor: pointer; text-align: left; font: inherit; }
.call-log .cl-ic { width: 38px; height: 38px; border-radius: 50%; background: rgba(255, 255, 255, .2); display: grid; place-items: center; flex: none; }
.msg:not(.mine) .call-log .cl-ic { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.call-log.bad .cl-ic { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.call-log .cl-ic svg { width: 19px; height: 19px; }
.call-log .cl-main { display: flex; flex-direction: column; }
.call-log small { opacity: .75; font-size: 12.5px; }
