:root {
  --bg: #ffffff;
  --panel: #f6f6f7;
  --line: #e4e4e7;
  --text: #111113;
  --muted: #6b6b73;
  --in: #f1f1f3;
  --out: #111113;
  --out-text: #ffffff;
  --accent: #111113;
  --ok: #157f3b;
  --warn: #b45309;
  --danger: #c0262d;
  --read: #7cc4ff;
  --accent-text: #ffffff;
  --accent-hover: #333336;
  --active: #ececee;
  --veil: rgb(255 255 255 / .9);
  --note-bg: #fff7ed;
  --note-text: #7c2d12;
  --note-line: #fed7aa;
  --media: #d4d4d8;
  --focus-line: #a1a1aa;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Темна тема: автоматично за налаштуванням системи або вибором у меню */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f11;
    --panel: #1b1b1f;
    --line: #2a2a2f;
    --text: #ececf0;
    --muted: #9a9aa4;
    --in: #1f1f24;
    --out: #ececf0;
    --out-text: #111113;
    --accent: #ececf0;
    --accent-text: #111113;
    --accent-hover: #ffffff;
    --active: #26262c;
    --ok: #4ade80;
    --warn: #f59e0b;
    --danger: #ef4444;
    --read: #2563eb;
    --veil: rgb(15 15 17 / .9);
    --note-bg: #2b1d0e;
    --note-text: #fcd9a8;
    --note-line: #4a3216;
    --media: #2a2a2f;
    --focus-line: #52525b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f11;
  --panel: #1b1b1f;
  --line: #2a2a2f;
  --text: #ececf0;
  --muted: #9a9aa4;
  --in: #1f1f24;
  --out: #ececf0;
  --out-text: #111113;
  --accent: #ececf0;
  --accent-text: #111113;
  --accent-hover: #ffffff;
  --active: #26262c;
  --ok: #4ade80;
  --warn: #f59e0b;
  --danger: #ef4444;
  --read: #2563eb;
  --veil: rgb(15 15 17 / .9);
  --note-bg: #2b1d0e;
  --note-text: #fcd9a8;
  --note-line: #4a3216;
  --media: #2a2a2f;
  --focus-line: #52525b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
a { color: inherit; }
.ic { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); }
.center { text-align: center; }

#app { height: 100dvh; }
#app.boot { display: grid; place-items: center; color: var(--muted); }

/* ---------- кнопки ---------- */
.btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 10px 16px; font-weight: 600;
}
.btn:hover:not(:disabled) { background: var(--panel); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.wide { width: 100%; padding: 12px; }
.btn.small { padding: 5px 10px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.btn.small .ic { width: 16px; height: 16px; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center; flex: none; color: var(--text);
}
.icon-btn:hover { background: var(--panel); }
.link { border: 0; background: none; padding: 0; font-weight: 600; text-decoration: underline; }
.theme-link { align-self: center; font-weight: 400; color: var(--muted); font-size: 13px; }

/* ---------- вхід ---------- */
#app.auth { display: grid; place-items: center; overflow-y: auto; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.brand { text-align: center; margin-bottom: 6px; }
.brand h1 { margin: 10px 0 4px; font-size: 28px; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); }
.logo {
  width: 64px; height: 64px; border-radius: 20px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; margin: 0 auto;
}
.logo .ic { width: 30px; height: 30px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel); border-radius: 12px; padding: 4px; }
.tabs button { border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .08); }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.auth-card input, .dialog input[type=text] {
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 16px; font-weight: 400; background: var(--bg); width: 100%;
}
.auth-card input:focus, .dialog input:focus { outline: none; border-color: var(--accent); }
.error { color: var(--danger); margin: 0; min-height: 1em; font-size: 14px; }
.error:empty { display: none; }
.facts { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
.facts li { padding-left: 18px; position: relative; }
.facts li::before { content: "•"; position: absolute; left: 4px; }

/* ---------- каркас ---------- */
#app.shell { display: grid; grid-template-columns: 340px 1fr; }
.side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-height: 60px;
  border-bottom: 1px solid var(--line); background: var(--bg);
  padding-top: max(10px, env(safe-area-inset-top));
}
.bar .title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.bar .title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn, .status { font-size: 12.5px; color: var(--muted); }
.conn[data-state="online"]::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 5px; vertical-align: 1px; }
.conn[data-state="offline"] { color: var(--danger); }
.status.on { color: var(--ok); }

.avatar {
  --h: #3f3f46;
  width: 42px; height: 42px; border-radius: 50%; flex: none; position: relative;
  display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--h);
}
.avatar[data-hue="0"] { --h: #27272a; } .avatar[data-hue="1"] { --h: #1d4ed8; }
.avatar[data-hue="2"] { --h: #047857; } .avatar[data-hue="3"] { --h: #b45309; }
.avatar[data-hue="4"] { --h: #7c3aed; } .avatar[data-hue="5"] { --h: #be123c; }
.avatar[data-hue="6"] { --h: #0e7490; } .avatar[data-hue="7"] { --h: #4d7c0f; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar-btn { border: 0; background: none; padding: 0; border-radius: 50%; flex: none; }
.profile-avatar { display: grid; place-items: center; margin-top: 4px; }
.profile-avatar .avatar { width: 120px; height: 120px; font-size: 46px; }
.code-box .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.code-box input, .code-input { letter-spacing: .25em; font-size: 20px !important; text-align: center; }
.info input[type=password], .info input[type=text] {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 16px; background: var(--bg); width: 100%; font-weight: 400;
}
.qr { width: 220px; max-width: 100%; margin: 0 auto; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.qr svg { display: block; width: 100%; height: auto; }
.secret { display: block; text-align: center; font-size: 15px !important; letter-spacing: .05em; padding: 8px !important; user-select: all; overflow-wrap: anywhere; }
.recovery { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--panel); padding: 12px; border-radius: 12px; }
.recovery code { text-align: center; font-size: 15px !important; background: none !important; letter-spacing: .06em; }
.progress { height: 8px; border-radius: 4px; background: var(--panel); overflow: hidden; margin: 14px 0 10px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.dialog.center { text-align: center; }
.select { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; font-weight: 400; background: var(--bg); color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.info label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.dialog input[type=text] { font-weight: 400; }
.login { font-weight: 400; color: var(--muted); font-size: .9em; }
.profile-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.avatar .dot { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%; background: #22c55e; border: 2px solid var(--bg); }

.search { margin: 10px 12px; display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 12px; padding: 0 12px; }
.search .ic { width: 18px; height: 18px; color: var(--muted); }
.search input { border: 0; background: none; padding: 10px 0; flex: 1; min-width: 0; outline: none; font-size: 16px; }

.list { flex: 1; overflow-y: auto; padding: 0 6px 10px; }
.list-head { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 14px 10px 6px; }
.list-empty { color: var(--muted); text-align: center; padding: 24px 16px; margin: 0; font-size: 14px; }
.item {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  border: 0; background: none; padding: 9px 10px; border-radius: 12px;
}
.item:hover { background: var(--panel); }
.item.active { background: var(--active); }
.item-body { flex: 1; min-width: 0; }
.item-top, .item-sub { display: flex; align-items: center; gap: 6px; }
.item-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-top .ic { width: 15px; height: 15px; }
.when { margin-left: auto; font-size: 12px; color: var(--muted); flex: none; }
.item-sub { color: var(--muted); font-size: 14px; }
.item-sub > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.typing { color: var(--ok); }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; font-size: 12px; font-weight: 700; padding: 1px 7px; flex: none; }
.ic.ok { color: var(--ok); } .ic.warn { color: var(--warn); }

.empty { margin: auto; text-align: center; max-width: 360px; padding: 24px; }
.empty h2 { margin: 14px 0 6px; }
.empty p { margin: 6px 0; }

/* ---------- чат ---------- */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }
.chat.drop::after {
  content: "Відпустіть, щоб надіслати"; position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 16px;
  background: var(--veil); display: grid; place-items: center; font-weight: 600; z-index: 5;
}
.back { display: none; }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--note-bg); color: var(--note-text); font-size: 14px; border-bottom: 1px solid var(--note-line); }
.banner span { flex: 1; }
.box-wrap { flex: 1; position: relative; min-height: 0; }
.messages { position: absolute; inset: 0; overflow-y: auto; padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain; }
.day { text-align: center; margin: 12px 0 6px; font-size: 12.5px; color: var(--muted); }
.day span { background: var(--panel); border-radius: 10px; padding: 3px 10px; display: inline-flex; gap: 4px; align-items: center; }
.day.hint { margin-top: auto; }
.day .ic { width: 14px; height: 14px; }

.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 520px); padding: 7px 10px 5px; border-radius: var(--radius);
  background: var(--in); position: relative; overflow-wrap: anywhere;
}
.msg.out .bubble { background: var(--out); color: var(--out-text); }
.msg.in .bubble { border-bottom-left-radius: 6px; }
.msg.out .bubble { border-bottom-right-radius: 6px; }
.text { white-space: pre-wrap; }
.meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 6px 0 -2px 10px; font-size: 11.5px; opacity: .65; }
.tick .ic { width: 15px; height: 15px; }
.tick.read { color: var(--read); opacity: 1; }
.msg.out .meta:has(.tick.read) { opacity: 1; }
.tick.failed { color: #ff8a8a; }
.msg.system { justify-content: center; margin: 6px 0; }
.msg.system span { background: var(--note-bg); color: var(--note-text); border-radius: 10px; padding: 5px 12px; font-size: 13px; max-width: 520px; text-align: center; }

.msg.media .bubble { padding: 3px; }
.msg.media .meta {
  position: absolute; right: 10px; bottom: 8px; margin: 0; float: none; opacity: 1;
  background: rgb(0 0 0 / .5); color: #fff; border-radius: 9px; padding: 1px 6px;
}
.file.image .media-box, .file.video .media-box {
  position: relative; width: min(300px, 64vw); max-height: 380px; border-radius: 13px; overflow: hidden; background: var(--media);
  aspect-ratio: 4 / 3;
}
.media-box img, .media-box video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.media-box img { cursor: zoom-in; background: transparent; }
.media-box img.blur { filter: blur(6px); transform: scale(1.06); cursor: default; }
.media-state { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; text-align: center; }
.media-state .state { background: rgb(0 0 0 / .62); color: #fff; padding: 6px 10px; border-radius: 10px; font-size: 13px; }
.media-chip { position: absolute; left: 8px; top: 8px; }
.media-chip .state { background: rgb(0 0 0 / .62); color: #fff; padding: 3px 8px; border-radius: 9px; font-size: 12px; }
.media-chip .state:empty { display: none; }
.dur { position: absolute; left: 8px; bottom: 8px; background: rgb(0 0 0 / .5); color: #fff; font-size: 12px; border-radius: 8px; padding: 1px 6px; }
.media-state .btn.small { background: rgb(0 0 0 / .62); color: #fff; border: 0; }

.file:not(.image):not(.video) { display: flex; gap: 10px; align-items: center; min-width: 220px; padding: 3px 0; }
.file-ic { width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgb(127 127 127 / .2); color: inherit; flex: none; }
.file-info { min-width: 0; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { font-size: 13px; opacity: .75; }
.file.audio { flex-direction: column; align-items: stretch; }
.file.audio audio { width: min(300px, 64vw); }
.bar-p { display: inline-block; width: 90px; height: 5px; border-radius: 3px; background: rgb(255 255 255 / .35); vertical-align: middle; overflow: hidden; }
.bar-p i { display: block; height: 100%; background: #fff; }
.file-sub .bar-p { background: rgb(127 127 127 / .3); }
.file-sub .bar-p i { background: currentColor; }

.down-btn {
  position: absolute; right: 16px; bottom: 12px; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg); box-shadow: 0 2px 8px rgb(0 0 0 / .12); display: grid; place-items: center;
}

.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); background: var(--bg);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; max-height: 160px;
  background: var(--panel); outline: none; font-size: 16px; line-height: 1.35;
}
.composer textarea:focus { border-color: var(--focus-line); background: var(--bg); }
.icon-btn.send { background: var(--accent); color: var(--accent-text); }
.icon-btn.send:hover { background: var(--accent-hover); }
.icon-btn.send .ic { width: 19px; height: 19px; margin-left: -2px; }

/* ---------- смайлики ---------- */
.emoji-panel { border-top: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; height: 290px; }
.emoji-tabs { display: flex; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; flex: none; }
.emoji-tabs::-webkit-scrollbar { display: none; }
.emoji-tabs button { border: 0; background: none; font-size: 20px; line-height: 1; padding: 7px 8px; border-radius: 9px; flex: none; opacity: .55; }
.emoji-tabs button[aria-selected="true"] { background: var(--panel); opacity: 1; }
.emoji-tabs button:hover { opacity: 1; }
.emoji-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); align-content: start; padding: 6px; overscroll-behavior: contain; }
.emoji-grid button { border: 0; background: none; font-size: 26px; line-height: 1; height: 44px; border-radius: 10px; padding: 0;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", var(--font); }
.emoji-grid button:hover, .emoji-grid button:focus-visible { background: var(--panel); }
.emoji-empty { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 30px 16px; margin: 0; font-size: 14px; }
.emoji-big { line-height: 1.15; }
.emoji-big.e1 { font-size: 48px; } .emoji-big.e2 { font-size: 40px; } .emoji-big.e3 { font-size: 34px; }
.msg.emoji-msg .bubble { background: transparent; color: var(--text); padding: 0 2px; }
.msg.emoji-msg .meta { opacity: .55; }

/* ---------- групи ---------- */
.avatar.group { border-radius: 30%; }
.avatar.group img { border-radius: 30%; }
.grp-ic { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; background: var(--bg); color: var(--text);
  display: grid; place-items: center; border: 1px solid var(--line); }
.grp-ic .ic { width: 11px; height: 11px; }
.profile-avatar .grp-ic { width: 34px; height: 34px; } .profile-avatar .grp-ic .ic { width: 20px; height: 20px; }
.bubble .who { display: block; border: 0; background: none; padding: 0; margin: 0 0 2px; font-size: 13px; font-weight: 700; color: var(--hue); text-align: left; }
.who[data-hue="0"] { --hue: #52525b; } .who[data-hue="1"] { --hue: #1d4ed8; } .who[data-hue="2"] { --hue: #047857; } .who[data-hue="3"] { --hue: #b45309; }
.who[data-hue="4"] { --hue: #7c3aed; } .who[data-hue="5"] { --hue: #be123c; } .who[data-hue="6"] { --hue: #0e7490; } .who[data-hue="7"] { --hue: #4d7c0f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bubble .who { filter: brightness(1.6); } }
:root[data-theme="dark"] .bubble .who { filter: brightness(1.6); }
.msg.media .bubble .who { padding: 4px 8px 0; }
.composer.gone { justify-content: space-between; align-items: center; padding: 14px 16px; }
.pick-members, .members { display: flex; flex-direction: column; max-height: 300px; overflow-y: auto; margin: 0 -4px; }
.check.member { gap: 10px; padding: 6px 4px; border-bottom: 0; }
.check.member .avatar { width: 36px; height: 36px; font-size: 14px; }
.row-inline { display: flex; gap: 8px; align-items: center; }
.row-inline input { flex: 1; min-width: 0; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.member-row .avatar { width: 36px; height: 36px; font-size: 14px; }
.link-row { border: 0; background: none; padding: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row:disabled { opacity: 1; cursor: default; }
.badge-admin { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 8px; background: var(--panel); color: var(--muted); }
.info h3.sub { margin: 8px 0 0; font-size: 15px; }

/* ---------- голосові ---------- */
.composer { position: relative; }
.composer.recording > :not(.rec-bar) { visibility: hidden; }
.rec-bar { position: absolute; inset: 0; display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg);
  padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; flex: none; }
@keyframes blink { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; min-width: 42px; }
.rec-bars { flex: 1; height: 28px; display: flex; align-items: center; justify-content: flex-end; gap: 2px; overflow: hidden; }
.rec-bars i { width: 3px; border-radius: 2px; background: var(--danger); flex: none; }
.file.voice { display: flex; align-items: center; gap: 10px; min-width: 230px; padding: 2px 0; }
.voice-play { width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--accent-text); }
.msg.out .voice-play { background: var(--out-text); color: var(--out); }
.voice-play .ic { width: 18px; height: 18px; }
.voice-body { flex: 1; min-width: 0; }
.wave { height: 30px; display: flex; align-items: center; gap: 2px; cursor: pointer; }
.wave i { flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px; background: currentColor; opacity: .35; }
.wave i.on { opacity: 1; }
.voice-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .8; margin-top: 2px; }
.voice-time { font-variant-numeric: tabular-nums; }
.voice-dot { width: 7px; height: 7px; border-radius: 50%; background: #3b82f6; }
.voice-rate { border: 0; border-radius: 8px; padding: 0 6px; font-size: 11px; font-weight: 700; background: rgb(127 127 127 / .25); color: inherit; }
.voice-state .state { font-size: 12px; }

/* ---------- пам'ять ---------- */
.dialog.wide { max-width: 560px; }
.storage { display: flex; flex-direction: column; gap: 10px; }
.storage h3 { margin: 14px 0 0; font-size: 15px; }
.st-total { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.st-total strong { font-size: 30px; letter-spacing: -.02em; }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--panel); gap: 2px; }
.stack i { display: block; height: 100%; min-width: 3px; }
.seg-photo { background: #2563eb; } .seg-video { background: #db2777; } .seg-audio { background: #d97706; }
.seg-file { background: #059669; } .seg-partial { background: #a1a1aa; } .seg-text { background: #7c3aed; } .seg-other { background: #52525b; }
.legend { display: flex; flex-direction: column; gap: 6px; }
.storage .row, .check { display: flex; align-items: center; gap: 10px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.grow { flex: 1; min-width: 0; }
.small { font-size: 13px; margin: 0; }
.st-chats { padding: 0; margin: 0 -10px; max-height: 260px; }
.row.clean { padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.row.clean .select { padding: 5px 8px; font-size: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv > span:nth-child(even) { overflow-wrap: anywhere; }
.info label.check { flex-direction: row; }
.check { padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; font-weight: 400; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- діалоги ---------- */
.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .4); display: grid; place-items: center; padding: 16px; z-index: 50; }
.dialog { background: var(--bg); border-radius: 18px; padding: 20px; width: 100%; max-width: 420px; max-height: calc(100dvh - 32px); overflow-y: auto; box-shadow: 0 20px 50px rgb(0 0 0 / .25); }
.dialog h2 { margin: 0 0 12px; font-size: 19px; }
.dialog p { margin: 0 0 10px; }
.info { display: flex; flex-direction: column; gap: 10px; }
.info p { margin: 0; }
.info code { font-size: 13px; background: var(--panel); padding: 2px 6px; border-radius: 6px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.safety { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 12px; background: var(--panel); padding: 14px; border-radius: 12px; font: 600 17px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-align: center; }
.ok-text { color: var(--ok); display: flex; align-items: center; gap: 6px; }
.pick-list { display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow-y: auto; }
.pick { display: flex; gap: 10px; align-items: center; }
.pick img, .pick-ic { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; background: var(--panel); display: grid; place-items: center; }
.pick .name { font-weight: 600; overflow-wrap: anywhere; }

.popup {
  position: fixed; z-index: 60; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .15); min-width: 220px; display: flex; flex-direction: column;
}
.popup button { border: 0; background: none; text-align: left; padding: 10px 12px; border-radius: 8px; }
.popup button:hover, .popup button:focus-visible { background: var(--panel); outline: none; }
.popup button.danger { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 70; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 20px rgb(0 0 0 / .2);
}

.viewer { position: fixed; inset: 0; z-index: 80; background: rgb(0 0 0 / .94); display: grid; place-items: center; }
.viewer img { max-width: 100vw; max-height: calc(100dvh - 60px); object-fit: contain; margin-top: 30px; }
.viewer-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 8px 10px; color: #fff; padding-top: max(8px, env(safe-area-inset-top)); }
.viewer-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.viewer-bar .icon-btn { color: #fff; }
.viewer-bar .icon-btn:hover { background: rgb(255 255 255 / .15); }

/* ---------- телефон ---------- */
@media (max-width: 759px) {
  #app.shell { grid-template-columns: 1fr; }
  .side { border-right: 0; }
  #app.shell .main { display: none; }
  #app.shell.chat-open .side { display: none; }
  #app.shell.chat-open .main { display: flex; }
  .back { display: inline-grid; }
  .bar .avatar { width: 38px; height: 38px; }
  .messages { padding: 10px 8px 6px; }
  .bubble { max-width: 85%; }
  .emoji-panel { height: min(300px, 42dvh); }
  .emoji-grid button { font-size: 28px; height: 46px; }
}

/* ---------- дзвінки ---------- */
.call-screen {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: max(20px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
  background: #111113; color: #f4f4f5; text-align: center;
}
.call-top { min-height: 24px; }
.call-e2e { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #a1a1aa; }
.call-e2e .ic { width: 14px; height: 14px; }
.call-who { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.call-who h2 { margin: 18px 0 0; font-size: 26px; letter-spacing: -.02em; }
.call-who .muted { color: #a1a1aa; margin: 0; }
.call-ava { position: relative; border-radius: 50%; }
.call-screen.ringing .call-ava::before, .call-screen.ringing .call-ava::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid rgb(255 255 255 / .35);
  animation: call-ring 2s ease-out infinite;
}
.call-screen.ringing .call-ava::after { animation-delay: 1s; }
@keyframes call-ring { from { transform: scale(1); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }
.avatar.big { width: 112px; height: 112px; font-size: 44px; }
.call-status { margin: 8px 0 0; color: #a1a1aa; font-variant-numeric: tabular-nums; min-height: 1.4em; }
.call-status.live { color: #f4f4f5; }
.call-actions { display: flex; gap: clamp(8px, 4vw, 28px); justify-content: center; align-items: flex-start; }
.call-btn-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 78px; font-size: 13px; color: #d4d4d8; }
.call-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: rgb(255 255 255 / .14); color: #fff;
}
.call-btn .ic { width: 26px; height: 26px; }
.call-btn:hover { background: rgb(255 255 255 / .22); }
.call-btn[aria-pressed="true"] { background: #f4f4f5; color: #111113; }
.call-btn.end { background: #dc2626; }
.call-btn.end:hover { background: #b91c1c; }
.call-btn.end .ic { transform: rotate(0deg); }
.call-btn.accept { background: #16a34a; animation: call-pulse 1.4s ease-in-out infinite; }
.call-btn.accept:hover { background: #15803d; }
@keyframes call-pulse { 50% { transform: scale(1.08); } }
.call-btn:focus-visible { outline: 3px solid #7cc4ff; outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
  .call-screen.ringing .call-ava::before, .call-screen.ringing .call-ava::after, .call-btn.accept { animation: none; }
}

.call-pill {
  position: fixed; z-index: 55; top: calc(env(safe-area-inset-top) + 64px); left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px; max-width: calc(100vw - 32px);
  border: 0; border-radius: 999px; padding: 8px 16px; background: #16a34a; color: #fff;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; box-shadow: 0 6px 20px rgb(0 0 0 / .25);
}
.call-pill .ic { width: 16px; height: 16px; flex: none; }
.call-pill > span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-pill .pill-st { font-weight: 400; font-variant-numeric: tabular-nums; opacity: .9; }

.msg.call .bubble { padding: 0; }
.call-msg {
  display: flex; align-items: center; gap: 10px; border: 0; background: none; color: inherit; font: inherit;
  padding: 9px 14px 9px 10px; text-align: left; cursor: pointer; border-radius: inherit;
}
.call-msg:disabled { cursor: default; }
.call-ic { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; background: rgb(127 127 127 / .16); }
.call-ic .ic { width: 17px; height: 17px; }
.call-msg.bad .call-ic { color: var(--danger); }
.call-txt { display: flex; flex-direction: column; line-height: 1.25; }
.call-txt small { opacity: .7; font-size: 12px; }
