/* ==========================================================================
   Tether — modern messenger styles (light + dark, phone-first)
   ========================================================================== */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f1f4f8;
  --panel-3: #e8edf3;
  --line: #e4e9f0;
  --text: #0f1b24;
  --muted: #66768a;
  --accent: #0d9488;
  --accent-2: #0e7490;
  --accent-ink: #ffffff;
  --accent-soft: #dcf5f1;
  --grad: linear-gradient(135deg, #14b8a6 0%, #0891b2 100%);
  --mine-ink: #ffffff;
  --theirs: #ffffff;
  --theirs-ink: #0f1b24;
  --wallpaper: #eef2f6;
  --wall-dot: rgba(13, 148, 136, .07);
  --danger: #dc3b30;
  --ok: #16a34a;
  --online: #22c55e;
  --glass: rgba(255, 255, 255, .78);
  --shadow-sm: 0 1px 2px rgba(15, 27, 36, .06);
  --shadow: 0 1px 2px rgba(15, 27, 36, .05), 0 8px 24px rgba(15, 27, 36, .07);
  --shadow-lg: 0 24px 60px rgba(15, 27, 36, .22);
  --r-sm: 10px; --r: 18px; --r-lg: 24px;
  --app-h: 100dvh;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1418; --panel: #111c21; --panel-2: #17242b; --panel-3: #1e2e36; --line: #20313a;
    --text: #e7eef2; --muted: #8fa1ad; --accent: #2dd4bf; --accent-2: #22d3ee; --accent-ink: #04201d; --accent-soft: #123a37;
    --grad: linear-gradient(135deg, #0d9488 0%, #0e7490 100%);
    --theirs: #1a2a32; --theirs-ink: #e7eef2; --wallpaper: #0d181d; --wall-dot: rgba(45, 212, 191, .05);
    --danger: #f87171; --ok: #4ade80; --online: #34d399; --glass: rgba(17, 28, 33, .78);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1418; --panel: #111c21; --panel-2: #17242b; --panel-3: #1e2e36; --line: #20313a;
  --text: #e7eef2; --muted: #8fa1ad; --accent: #2dd4bf; --accent-2: #22d3ee; --accent-ink: #04201d; --accent-soft: #123a37;
  --grad: linear-gradient(135deg, #0d9488 0%, #0e7490 100%);
  --theirs: #1a2a32; --theirs-ink: #e7eef2; --wallpaper: #0d181d; --wall-dot: rgba(45, 212, 191, .05);
  --danger: #f87171; --ok: #4ade80; --online: #34d399; --glass: rgba(17, 28, 33, .78);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ----------------------------------------------------------------- base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.inline { width: 17px; height: 17px; vertical-align: -3px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { justify-content: center; }
.error { color: var(--danger); margin: 0; font-size: 14px; }
.ok { color: var(--ok); margin: 0; font-size: 14px; }
.error:empty, .ok:empty { display: none; }
code { font-size: .92em; background: var(--panel-2); padding: 1px 5px; border-radius: 6px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px;
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px;
  padding: 9px 16px; cursor: pointer; font-weight: 600; transition: transform .12s, background .15s, box-shadow .15s, filter .15s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: scale(.97); }
.btn .i { width: 18px; height: 18px; }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 6px 16px -6px rgba(13, 148, 136, .6); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 13.5px; border-radius: 10px; }
.btn.lg { min-height: 50px; font-size: 16px; border-radius: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s, transform .12s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn.tiny { width: 30px; height: 30px; }
.icon-btn.tiny .i { width: 16px; height: 16px; }
.round-btn {
  width: 46px; height: 46px; flex: none; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: #fff; background: var(--grad);
  box-shadow: 0 6px 16px -6px rgba(13, 148, 136, .7); transition: transform .12s, filter .15s;
}
.round-btn:hover { filter: brightness(1.08); }
.round-btn:active { transform: scale(.9); }

/* ----------------------------------------------------------------- forms */
label { display: grid; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
input:not([type=checkbox]), textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; background: var(--panel-2);
  padding: 11px 14px; font-weight: 400; color: var(--text); transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 4px var(--accent-soft); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

/* ----------------------------------------------------------------- auth */
.auth { position: relative; min-height: 100%; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) 16px 24px; overflow: hidden; }
.auth-glow {
  position: absolute; inset: -20%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(40% 35% at 20% 15%, rgba(20, 184, 166, .35), transparent 70%),
    radial-gradient(35% 30% at 85% 25%, rgba(8, 145, 178, .30), transparent 70%),
    radial-gradient(45% 40% at 60% 95%, rgba(99, 102, 241, .18), transparent 70%);
  filter: blur(20px);
}
.auth-card {
  position: relative; z-index: 1; width: 100%; max-width: 400px; display: grid; gap: 16px;
  background: var(--glass); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  padding: 30px 26px; border-radius: 26px; box-shadow: var(--shadow-lg); border: 1px solid var(--line);
  animation: rise .4s ease-out;
}
.auth-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.02em; }
.auth-card p { margin: 0; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 21px; letter-spacing: -.02em; }
.brand img { border-radius: 14px; box-shadow: 0 8px 20px -8px rgba(13, 148, 136, .7); }
.fine { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: flex-start; margin: 0; }
.fine .i { width: 14px; height: 14px; margin-top: 2px; }

/* ----------------------------------------------------------------- layout */
.app { height: var(--app-h); display: grid; grid-template-columns: minmax(300px, 380px) 1fr; overflow: hidden; }
.sidebar { position: relative; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding-top: env(safe-area-inset-top); }
.side-head { display: flex; align-items: center; gap: 6px; padding: 12px 10px 4px 14px; }
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; border: 0; background: none; padding: 4px; border-radius: 14px; cursor: pointer; text-align: left; }
.me:hover { background: var(--panel-2); }
.me .avatar { width: 36px; height: 36px; font-size: 13px; }
.me-text { display: grid; min-width: 0; line-height: 1.25; }
.me-text strong, .me-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text strong { font-size: 14px; }
.head-actions { display: flex; gap: 2px; }
.side-title { margin: 6px 18px 10px; font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.search { display: flex; align-items: center; gap: 8px; margin: 0 14px 10px; padding: 0 14px; border-radius: 14px; background: var(--panel-2); color: var(--muted); }
.search .i { width: 18px; height: 18px; }
.search input { border: 0; background: transparent !important; padding: 11px 0; box-shadow: none !important; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.chips { display: flex; gap: 8px; padding: 0 14px 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 0; border-radius: 999px; padding: 7px 14px; background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); color: var(--accent); }
.conn-banner { display: flex; align-items: center; gap: 10px; margin: 0 14px 10px; padding: 9px 12px; border-radius: 12px; background: #fff4d6; color: #7a5300; font-size: 13.5px; font-weight: 600; }
:root[data-theme="dark"] .conn-banner { background: #3a2f12; color: #f6d78b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .conn-banner { background: #3a2f12; color: #f6d78b; } }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
.side-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(90px + env(safe-area-inset-bottom)); }

/* install card */
.install-card {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  margin: 2px 14px 12px; padding: 14px 14px; border-radius: var(--r); color: #fff; background: var(--grad);
  box-shadow: 0 12px 28px -14px rgba(8, 145, 178, .8); animation: rise .35s ease-out;
}
.install-card img { border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, .2); }
.install-text { display: grid; gap: 2px; min-width: 0; padding-right: 18px; }
.install-text .small { opacity: .9; }
.install-card .btn.primary { background: #fff; color: #0e7490; box-shadow: none; }
.install-card .icon-btn.tiny { position: absolute; top: 4px; right: 4px; color: rgba(255, 255, 255, .85); }
.install-card .icon-btn.tiny:hover { background: rgba(255, 255, 255, .15); color: #fff; }

/* requests */
.requests { margin: 0 14px 12px; padding: 12px; border-radius: var(--r); background: var(--accent-soft); display: grid; gap: 10px; animation: rise .3s ease-out; }
.requests h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.req { display: flex; align-items: center; gap: 10px; }
.req .avatar { width: 40px; height: 40px; font-size: 14px; }
.req-text { flex: 1; min-width: 0; display: grid; font-size: 14px; }
.req-text strong, .req-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.req-actions { display: flex; gap: 6px; flex: none; }
.req-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.has-badge { position: relative; }
.dot-badge { position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--panel); }

/* contact list */
.contacts { list-style: none; margin: 0; padding: 0 8px; }
.contact {
  display: flex; align-items: center; gap: 13px; padding: 10px 10px; border-radius: 16px; cursor: pointer; width: 100%;
  border: 0; background: transparent; text-align: left; transition: background .15s, transform .1s;
}
.contact:hover { background: var(--panel-2); }
.contact:active { transform: scale(.985); }
.contact.active { background: var(--accent-soft); }
.contact .avatar { width: 50px; height: 50px; font-size: 17px; }
.contact-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.contact-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.contact-top strong { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 650; font-size: 15.5px; }
.contact-preview { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact.unread .contact-preview { color: var(--text); font-weight: 600; }
.contact.unread .time { color: var(--accent); font-weight: 700; }
.badge { background: var(--grad); color: #fff; border-radius: 999px; font-size: 11.5px; font-weight: 800; min-width: 21px; height: 21px; padding: 0 6px; display: grid; place-items: center; flex: none; }
.time { font-size: 12px; color: var(--muted); flex: none; }
.empty-list { color: var(--muted); padding: 36px 24px; font-size: 14.5px; text-align: center; line-height: 1.5; }
.empty-list .btn { margin-top: 14px; }

/* avatars */
.avatar {
  --hue: 170; position: relative; flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; letter-spacing: .02em; color: #fff;
  background: linear-gradient(135deg, hsl(var(--hue) 70% 62%), hsl(calc(var(--hue) + 35) 65% 45%));
  text-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.avatar.online::after { content: ""; position: absolute; right: 0; bottom: 0; width: 26%; height: 26%; min-width: 11px; min-height: 11px; border-radius: 50%; background: var(--online); border: 2.5px solid var(--panel); }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.avatar.xl { width: 96px; height: 96px; font-size: 32px; }

/* FAB (phones) */
.fab {
  display: none; position: absolute; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 5;
  width: 58px; height: 58px; border-radius: 18px; border: 0; cursor: pointer; color: #fff; background: var(--grad);
  box-shadow: 0 14px 30px -10px rgba(8, 145, 178, .8); place-items: center; transition: transform .15s;
}
.fab:active { transform: scale(.92); }
.fab .i { width: 26px; height: 26px; stroke-width: 2.4; }

/* ----------------------------------------------------------------- chat */
.chat {
  position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background-color: var(--wallpaper);
  background-image: radial-gradient(var(--wall-dot) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}
.empty-state { margin: auto; text-align: center; padding: 24px; max-width: 380px; display: grid; justify-items: center; gap: 4px; animation: rise .4s ease-out; }
.empty-art { width: 128px; height: 128px; border-radius: 40px; display: grid; place-items: center; background: var(--panel); box-shadow: var(--shadow); margin-bottom: 12px; }
.empty-art img { border-radius: 18px; }
.empty-state h2 { margin: 8px 0 2px; font-size: 22px; letter-spacing: -.02em; }
.empty-state p { margin: 4px 0; }
.chat-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head {
  position: relative; z-index: 2; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px 14px;
  background: var(--glass); backdrop-filter: blur(16px) saturate(1.5); -webkit-backdrop-filter: blur(16px) saturate(1.5);
  border-bottom: 1px solid var(--line);
}
.chat-head .avatar { width: 40px; height: 40px; }
.peer-text { flex: 1; display: grid; min-width: 0; line-height: 1.25; }
.peer-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
#peer-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .icon-btn { color: var(--accent); }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px clamp(10px, 4vw, 48px) 10px; display: flex; flex-direction: column; gap: 2px; }
.day { position: sticky; top: 6px; z-index: 1; align-self: center; margin: 14px 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow-sm); padding: 4px 12px; border-radius: 999px; }
.msg { max-width: min(560px, 78%); display: flex; flex-direction: column; animation: pop .18s ease-out; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.msg.gap { margin-top: 8px; }
.bubble {
  position: relative; padding: 8px 12px 8px; border-radius: var(--r); white-space: pre-wrap; overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm); font-size: 15px; line-height: 1.4;
}
.mine .bubble { background: var(--grad); color: var(--mine-ink); }
.theirs .bubble { background: var(--theirs); color: var(--theirs-ink); }
.mine.gap .bubble { border-top-right-radius: 6px; }
.theirs.gap .bubble { border-top-left-radius: 6px; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.meta { display: inline-flex; float: right; align-items: center; gap: 3px; margin: 6px -2px -3px 12px; font-size: 11px; line-height: 1; opacity: .72; white-space: nowrap; position: relative; top: 2px; }
.meta .i { width: 15px; height: 15px; }
.meta .read { color: #a5f3fc; opacity: 1; }
.theirs .meta .read { color: var(--accent); }
.msg.pending .bubble { opacity: .65; }
.msg.failed .bubble { box-shadow: 0 0 0 1.5px var(--danger); }
.msg.failed .meta { color: var(--danger); opacity: 1; }
.media { padding: 4px; overflow: hidden; }
.media img, .media video { display: block; max-width: 100%; max-height: 380px; border-radius: 14px; background: rgba(0, 0, 0, .15); }
.media img { cursor: zoom-in; min-width: 120px; min-height: 80px; object-fit: cover; }
.media video { width: 360px; }
.media .meta { position: absolute; right: 10px; bottom: 10px; float: none; margin: 0; top: auto; padding: 4px 8px; border-radius: 999px; background: rgba(0, 0, 0, .45); color: #fff; opacity: 1; backdrop-filter: blur(4px); }
.media video ~ .meta { bottom: auto; top: 10px; }
.filecard { display: flex; align-items: center; gap: 10px; text-decoration: none !important; padding: 2px 2px; }
.filecard .i { width: 30px; height: 30px; padding: 6px; border-radius: 10px; background: rgba(255, 255, 255, .2); box-sizing: content-box; }
.theirs .filecard .i { background: var(--accent-soft); color: var(--accent); }
.filecard span { display: grid; }
.filecard small { opacity: .8; }
.progress { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .3); overflow: hidden; margin-top: 8px; width: 200px; max-width: 100%; }
.progress > div { height: 100%; background: currentColor; width: 0; transition: width .2s; }
.callnote { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.callnote .i { width: 18px; height: 18px; }
.callnote.missed { color: var(--danger); }
.mine .callnote.missed { color: #ffe0dc; }
.voice { display: grid; gap: 6px; padding: 8px 10px; min-width: 240px; }
.voice .vlabel { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; opacity: .9; }
.voice .vlabel .i { width: 15px; height: 15px; }
.voice audio { width: 100%; min-width: 220px; height: 40px; border-radius: 999px; }
.voice .meta { margin: 0; float: none; top: 0; justify-self: end; }
.callnote + .meta { margin-top: 4px; }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding: 4px 6px; }
.load-older { align-self: center; margin-bottom: 8px; }
.is-typing { color: var(--accent) !important; font-weight: 600; font-style: italic; }
.typing-row { padding: 0 clamp(10px, 4vw, 48px) 6px; }
.typing-bubble { display: inline-flex; gap: 4px; align-items: center; padding: 12px 15px; border-radius: var(--r); border-top-left-radius: 6px; background: var(--theirs); box-shadow: var(--shadow-sm); animation: pop .18s ease-out; }
.typing-bubble i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing-bubble i:nth-child(2) { animation-delay: .15s; }
.typing-bubble i:nth-child(3) { animation-delay: .3s; }

/* composer */
.composer, .recorder {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}
.field {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 2px; padding: 3px 6px 3px 3px;
  background: var(--panel); border-radius: 24px; box-shadow: var(--shadow); border: 1px solid var(--line);
  transition: box-shadow .15s, border-color .15s;
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.field .icon-btn { width: 40px; height: 40px; }
.field textarea {
  resize: none; border: 0 !important; box-shadow: none !important; background: transparent !important;
  max-height: 160px; min-height: 40px; overflow-y: hidden; padding: 9px 6px; line-height: 1.4; border-radius: 0;
}
.composer.has-text #mic-btn, .composer:not(.has-text) #send-btn { display: none; }
.recorder { align-items: center; }
.rec-pill { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 16px; border-radius: 24px; background: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--line); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; }
.rec-hint { flex: 1; }
.recorder .icon-btn { color: var(--danger); }
.drop-hint { position: absolute; inset: 76px 14px 80px; z-index: 3; border: 2px dashed var(--accent); border-radius: var(--r-lg); display: grid; place-items: center; background: color-mix(in srgb, var(--panel) 85%, transparent); font-weight: 800; font-size: 18px; color: var(--accent); pointer-events: none; }

/* ----------------------------------------------------------------- calls */
.incoming {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 50; width: min(400px, calc(100% - 24px));
  background: var(--glass); backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--line); box-shadow: var(--shadow-lg); border-radius: 24px;
  padding: 14px 14px 14px 16px; display: flex; align-items: center; gap: 14px; animation: drop .3s cubic-bezier(.2, .9, .3, 1.2);
}
.incoming .avatar.xl { width: 54px; height: 54px; font-size: 19px; }
.incoming-text { flex: 1; min-width: 0; }
.incoming-text strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.incoming-actions { display: flex; gap: 10px; }
.round { width: 56px; height: 56px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; background: rgba(255, 255, 255, .16); color: #fff; backdrop-filter: blur(8px); transition: transform .12s, background .15s; }
.round:active { transform: scale(.92); }
.round .i { width: 24px; height: 24px; }
.round.accept { background: #22c55e; animation: ring 1.4s infinite; }
.round.decline { background: #ef4444; }
.round.off { background: #fff; color: #0f1b24; }
.incoming .round { width: 50px; height: 50px; }

.call { position: fixed; inset: 0; z-index: 40; color: #fff; display: grid; place-items: center; background: radial-gradient(120% 80% at 50% 0%, #134e4a 0%, #0b1418 60%); }
#remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #0b1418; }
.call.voice #remote-video, .call.voice #local-video { display: none; }
.call-info { position: relative; display: grid; justify-items: center; gap: 10px; text-align: center; text-shadow: 0 1px 6px rgba(0, 0, 0, .5); }
.call-info .avatar { box-shadow: 0 0 0 10px rgba(255, 255, 255, .06), 0 0 0 22px rgba(255, 255, 255, .03); }
.call-info strong { font-size: 26px; letter-spacing: -.02em; margin-top: 14px; }
#call-status { opacity: .85; font-variant-numeric: tabular-nums; }
.call.connected:not(.voice) .call-info { position: absolute; top: calc(18px + env(safe-area-inset-top)); left: 20px; justify-items: start; }
.call.connected:not(.voice) .call-info .avatar { display: none; }
.call.connected:not(.voice) .call-info strong { font-size: 17px; margin: 0; }
#local-video { position: absolute; right: 16px; top: calc(16px + env(safe-area-inset-top)); width: min(30vw, 190px); aspect-ratio: 3 / 4; object-fit: cover; border-radius: 18px; background: #222; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); border: 2px solid rgba(255, 255, 255, .2); transform: scaleX(-1); }
#local-video.rear { transform: none; }
.call-bar { position: absolute; bottom: calc(28px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 18px; padding: 14px 20px; border-radius: 999px; background: rgba(0, 0, 0, .35); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }

/* ----------------------------------------------------------------- overlays */
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .92); display: grid; place-items: center; padding: 24px; animation: fade .2s; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.lightbox .close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; color: #fff; background: rgba(255, 255, 255, .12); }

.dlg { width: min(480px, calc(100% - 32px)); max-height: min(88vh, 860px); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); color: var(--text); padding: 0; box-shadow: var(--shadow-lg); overflow-y: auto; overscroll-behavior: contain; }
.dlg[open] { animation: rise .25s ease-out; }
.dlg.wide { width: min(820px, calc(100% - 32px)); }
.dlg::backdrop { background: rgba(5, 15, 20, .5); backdrop-filter: blur(3px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 6px 22px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.dlg-head h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.grabber { display: none; }
.dlg section { padding: 10px 22px 20px; border-bottom: 1px solid var(--line); }
.dlg section:last-child { border-bottom: 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
.dlg h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 0 12px; }
.dlg p { margin: 0 0 12px; }
.profile-row { display: flex; align-items: center; gap: 14px; }
.profile-row strong { font-size: 17px; }
.share-me { margin-top: 16px !important; padding: 12px 14px; border-radius: 12px; background: var(--panel-2); font-size: 14px; }
.share-me strong { color: var(--accent); }
.stack { display: grid; gap: 14px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.grid-form .error, .grid-form .ok { grid-column: 1 / -1; }
.pw-row { display: flex; gap: 6px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--text); padding-bottom: 12px; }
.segmented { display: inline-flex; padding: 4px; border-radius: 14px; background: var(--panel-2); gap: 4px; }
.segmented button { border: 0; background: transparent; padding: 8px 18px; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button[aria-checked="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 12px; line-height: 1.5; }
.steps strong { color: var(--text); }
.media-intro { color: var(--muted); }
.media-intro:empty { display: none; }
.perm-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.perm-list li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--panel-2); }
.perm-list li .i { color: var(--accent); }
.perm-list li span { flex: 1; font-weight: 600; }
.perm { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--panel-3); color: var(--muted); }
.perm.good { background: #dcfce7; color: #166534; }
.perm.bad { background: #fee2e2; color: #991b1b; }
:root[data-theme="dark"] .perm.good { background: #14532d; color: #bbf7d0; }
:root[data-theme="dark"] .perm.bad { background: #7f1d1d; color: #fecaca; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .perm.good { background: #14532d; color: #bbf7d0; }
  :root:not([data-theme="light"]) .perm.bad { background: #7f1d1d; color: #fecaca; }
}
#media-preview { display: block; width: 100%; max-height: 220px; object-fit: cover; border-radius: 16px; background: #000; margin-bottom: 12px; transform: scaleX(-1); }
.meter { height: 8px; border-radius: 999px; background: var(--panel-3); overflow: hidden; margin-bottom: 12px; }
.meter > div { height: 100%; width: 0; background: var(--grad); transition: width .08s linear; }
#media-ok, #media-err { margin-bottom: 12px; }
.table-wrap { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.users-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.users-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.users-table td:last-child { text-align: right; }
.users-table td:last-child .btn { margin: 2px 0; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); margin: 3px 4px 0 0; }
.pill.admin { background: var(--accent-soft); color: var(--accent); }
.pill.off { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70;
  background: #0f1b24; color: #fff; padding: 11px 18px; border-radius: 14px; box-shadow: var(--shadow-lg);
  max-width: calc(100% - 32px); font-weight: 500; font-size: 14px; animation: rise .25s ease-out;
}

/* ----------------------------------------------------------------- motion */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes fade { from { opacity: 0; } }
@keyframes drop { from { transform: translate(-50%, -24px); opacity: 0; } }
@keyframes slide-in { from { transform: translateX(28%); opacity: .4; } }
@keyframes sheet { from { transform: translateY(100%); } }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes pulse { 50% { opacity: .3; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); } 100% { box-shadow: 0 0 0 16px rgba(34, 197, 94, 0); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ----------------------------------------------------------------- phones */
@media (max-width: 760px) {
  body { font-size: 16px; }
  input:not([type=checkbox]), textarea { font-size: 16px; } /* stops iOS zooming into fields */
  .app { grid-template-columns: 1fr; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .app.in-chat .chat { animation: slide-in .22s cubic-bezier(.2, .8, .3, 1); }
  .sidebar { border-right: 0; }
  .fab { display: grid; }
  .back { display: inline-grid; margin-left: -6px; }
  .chat-head { padding-left: 6px; gap: 6px; }
  .chat-head .icon-btn { width: 40px; height: 40px; }
  .msg { max-width: 84%; }
  .media video { width: 100%; }
  .voice { min-width: 0; width: 72vw; max-width: 300px; }
  .composer, .recorder { padding-left: 8px; padding-right: 8px; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
  .incoming { flex-wrap: wrap; }
  .incoming-actions { width: 100%; justify-content: space-around; padding-top: 4px; }

  /* dialogs become bottom sheets */
  .dlg, .dlg.wide {
    width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: 26px 26px 0 0; border-bottom: 0;
  }
  .dlg[open] { animation: sheet .28s cubic-bezier(.2, .8, .3, 1); }
  .dlg-head { padding-top: 22px; }
  .grabber { display: block; position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: 40px; height: 5px; border-radius: 3px; background: var(--panel-3); }
  .grid-form { grid-template-columns: 1fr; }

  /* admin table as cards */
  .users-table thead { display: none; }
  .users-table, .users-table tbody, .users-table tr, .users-table td { display: block; width: 100%; }
  .users-table tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  .users-table td { border: 0; padding: 2px 0; text-align: left !important; }
  .users-table td:last-child { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 8px; }
}
@media (max-width: 380px) {
  .side-title { font-size: 26px; }
  .contact .avatar { width: 46px; height: 46px; }
}
/* installed app: no browser chrome, a touch more breathing room at the top */
@media (display-mode: standalone) {
  .side-head { padding-top: 14px; }
}
