/* Эфир — messenger. Layout: chat list rail (stories strip on top) + conversation; on phones one pane at a time. */
:root {
  --bg: #f4f5f7; --surface: #ffffff; --side: #eceef2; --ink: #16181d; --ink-2: #5b6170; --ink-3: #8b91a0; --line: #e1e4ea;
  --accent: #f2541b; --accent-ink: #ffffff; --mine: #ffe7dc; --mine-ink: #2a1309; --other: #ffffff;
  --hover: rgba(22, 24, 29, 0.05); --danger: #c8322b; --ok: #1e9e5a; --read: #1f8fd6; --shadow: 0 10px 30px rgba(20, 22, 30, 0.12);
  --wall: #ebe7e1;
  --f-brand: "Dela Gothic One", "Arial Black", system-ui, sans-serif;
  --f-body: "Golos Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --surface: #181b21; --side: #0d0f12; --ink: #eceef2; --ink-2: #a4aab8; --ink-3: #6f7686; --line: #262a33;
    --accent: #ff7440; --accent-ink: #1a0c05; --mine: #3a2014; --mine-ink: #ffe5d8; --other: #1f232b;
    --hover: rgba(236, 238, 242, 0.06); --danger: #ff6b62; --ok: #4fd18b; --read: #5db8ff; --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    --wall: #0f1114; color-scheme: dark;
  }
}
html { height: 100%; box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }
body { height: 100%; margin: 0; padding-top: env(safe-area-inset-top, 0px); background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- shared bits ---------- */
.onair { display: inline-flex; align-items: center; gap: 6px; font-family: var(--f-mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 3px 6px 2px; }
.onair::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 2s ease-in-out infinite; }
.onair.off { color: var(--ink-3); border-color: var(--line); }
.onair.off::before { background: var(--ink-3); animation: none; }
@keyframes blink { 50% { opacity: .25; } }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 0; background: transparent; display: grid; place-items: center; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.light { color: #fff; }
.btn { padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: transparent; font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.wide { width: 100%; padding: 12px; font-size: 15px; }
.btn.tiny { padding: 4px 10px; font-size: 12.5px; margin-left: 8px; }
.btn.light { color: #fff; border-color: rgba(255, 255, 255, .4); background: rgba(0, 0, 0, .25); }
.btn.danger-text { border: 0; color: var(--danger); padding-left: 0; text-align: left; }
.btn.more { align-self: center; margin: 4px 0 12px; font-size: 13px; }
.linklike { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.muted { color: var(--ink-3); font-size: 13.5px; line-height: 1.5; margin: 0; }
.muted.pad { padding: 16px; }
.sec-label { font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin-top: 4px; }
.av { position: relative; width: 44px; height: 44px; border-radius: 50%; flex: none; }
.av img { width: 100%; height: 100%; border-radius: 50%; display: block; object-fit: cover; background: var(--line); }
.av.ini { display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 15px; letter-spacing: .02em; }
.av.live::after { content: ""; position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid var(--side); }
.av.big { width: 88px; height: 88px; font-size: 30px; }
.tag { font-family: var(--f-mono); font-size: 10.5px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 1px 5px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); }
.field input { padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); outline: none; font-size: 16px; }
.field input:focus { border-color: var(--ink-3); }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }

/* ---------- auth ---------- */
.auth { height: 100%; display: grid; place-items: center; overflow-y: auto; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(60% 50% at 80% 10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%), var(--bg); }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 28px 24px 24px; box-shadow: var(--shadow); display: grid; gap: 18px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand b { font-family: var(--f-brand); font-weight: 400; font-size: 40px; line-height: 1; }
.auth-step { display: grid; gap: 14px; }
.auth-lead { margin: 0; color: var(--ink-2); line-height: 1.5; }
.auth-lead b { color: var(--ink); white-space: nowrap; }
#inCode { font-family: var(--f-mono); font-size: 26px; letter-spacing: .4em; text-align: center; }
.auth-error { margin: 0; color: var(--danger); font-size: 14px; }

/* ---------- app shell ---------- */
.app { height: 100%; display: grid; grid-template-columns: 360px minmax(0, 1fr); }
.rail { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding-left: env(safe-area-inset-left, 0px); }
.brand { display: flex; align-items: center; gap: 10px; padding: 12px 10px 8px 14px; }
.me-btn { border: 0; background: none; padding: 0; border-radius: 50%; }
.me-btn .av { width: 36px; height: 36px; font-size: 13px; }
.logo { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.logo b { font-family: var(--f-brand); font-weight: 400; font-size: 22px; line-height: 1; }
.brand-actions { display: flex; }

.stories { display: flex; gap: 12px; overflow-x: auto; padding: 6px 14px 10px; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.stories::-webkit-scrollbar { display: none; }
.story-chip { border: 0; background: none; padding: 0; display: grid; justify-items: center; gap: 4px; width: 64px; flex: none; }
.ring { position: relative; padding: 2.5px; border-radius: 50%; background: conic-gradient(from 200deg, var(--accent), #ffb347, var(--accent)); }
.ring .av { width: 54px; height: 54px; border: 2.5px solid var(--surface); font-size: 17px; }
.ring.seen { background: var(--line); }
.ring.empty { background: none; padding: 2.5px; }
.story-plus { position: absolute; right: -2px; bottom: -2px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); border: 2px solid var(--surface); display: grid; place-items: center; }
.story-plus svg, .plus-av svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 3; }
.plus-av { background: var(--side); color: var(--ink-2); }
.plus-av svg { width: 22px; height: 22px; stroke-width: 2.4; }
.story-name { font-size: 11.5px; color: var(--ink-2); max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search { padding: 8px 12px; }
.search input { width: 100%; padding: 9px 14px; border-radius: 10px; border: 0; background: var(--side); outline: none; }
.chats { flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 10px; }
.ch { width: 100%; display: grid; grid-template-columns: 50px minmax(0, 1fr); gap: 12px; align-items: center; padding: 8px 8px; border: 0; border-radius: 12px; background: transparent; text-align: left; }
.ch .av { width: 50px; height: 50px; }
.ch .av.live::after { border-color: var(--surface); }
.ch:hover { background: var(--hover); }
.ch.cur { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.ch-t { min-width: 0; display: grid; gap: 3px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.ch:last-child .ch-t { border-bottom: 0; }
.ch-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ch-row b { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-row time { font-family: var(--f-mono); font-size: 11px; color: var(--ink-3); flex: none; }
.ch.unread .ch-row time { color: var(--accent); }
.ch-prev { flex: 1; min-width: 0; font-size: 13.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 3px; }
.ch-prev.typing-text { color: var(--accent); }
.tick { display: inline-grid; flex: none; color: var(--ink-3); }
.tick svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tick.read { color: var(--read); }
.badge-n { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-family: var(--f-mono); font-size: 11.5px; font-weight: 500; display: grid; place-items: center; flex: none; }
.badge-n.muted-b { background: var(--ink-3); color: var(--surface); }

/* ---------- conversation ---------- */
.chat { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: var(--wall); }
.head { display: flex; align-items: center; gap: 6px; padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface); min-height: 62px; }
.back { display: none; }
.head-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 4px 6px; border-radius: 10px; text-align: left; }
.head-main:not(:disabled):hover { background: var(--hover); }
.head-main:disabled { cursor: default; }
.head-av .av { width: 40px; height: 40px; font-size: 14px; }
.head-t { min-width: 0; display: grid; }
.head-t b { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-t span { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.feed { overflow-y: auto; padding: 14px max(14px, env(safe-area-inset-right, 0px)) 10px 14px; overscroll-behavior: contain; }
.feed-inner { max-width: 840px; margin: 0 auto; display: flex; flex-direction: column; }
.day, .sys { align-self: center; margin: 12px 0 8px; font-size: 12px; color: var(--ink-2); background: var(--surface); border-radius: 8px; padding: 4px 10px; box-shadow: 0 1px 0 rgba(0,0,0,.05); text-align: center; max-width: 90%; }
.day { font-family: var(--f-mono); letter-spacing: .04em; }
.row { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 8px; align-items: end; margin-top: 2px; }
.row.noav { grid-template-columns: minmax(0, 1fr); }
.row.noav .av-slot { display: none; }
.row.first { margin-top: 10px; }
.row.mine { grid-template-columns: minmax(0, 1fr); justify-items: end; }
.row.mine .av-slot { display: none; }
.av-slot .av { width: 34px; height: 34px; font-size: 12px; }
.col { min-width: 0; max-width: min(560px, 82%); display: flex; flex-direction: column; align-items: flex-start; position: relative; }
.row.mine .col { align-items: flex-end; }
.who { font-size: 12.5px; font-weight: 600; margin: 0 0 2px 10px; }
.bubble { position: relative; background: var(--other); color: var(--ink); border-radius: 16px; padding: 7px 10px 6px; line-height: 1.42; overflow-wrap: anywhere; white-space: pre-wrap; max-width: 100%; box-shadow: 0 1px 0 rgba(0,0,0,.06); }
.row.last:not(.mine) .bubble { border-bottom-left-radius: 5px; }
.row.mine .bubble { background: var(--mine); color: var(--mine-ink); }
.row.mine.last .bubble { border-bottom-right-radius: 5px; }
.bubble.has-media { padding: 4px 4px 6px; }
.bubble.has-media .text, .bubble.has-media .quote { margin: 4px 6px 0; }
.bubble .media { display: block; max-width: 100%; width: 320px; max-height: 420px; object-fit: cover; border-radius: 12px; background: var(--line); cursor: zoom-in; }
.bubble video.media { cursor: default; }
.bubble.deleted { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.del-text { font-style: italic; color: var(--ink-3); }
.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.meta { float: right; margin: 6px 0 -3px 10px; font-family: var(--f-mono); font-size: 10.5px; color: var(--ink-3); white-space: nowrap; user-select: none; display: inline-flex; align-items: center; gap: 3px; }
.bubble.has-media .meta { margin-right: 6px; }
.row.mine .meta { color: color-mix(in srgb, var(--mine-ink) 55%, transparent); }
.row.mine .meta .tick.read { color: var(--read); }
.quote { display: block; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 4px; padding: 3px 8px; margin: 2px 0 5px; font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; cursor: pointer; }
.quote b { display: block; color: var(--accent); font-weight: 600; font-size: 12.5px; }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: -4px; padding: 0 6px; position: relative; z-index: 1; }
.react { padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; }
.react.me { border-color: var(--accent); }
.acts { position: absolute; top: -18px; right: 6px; display: none; gap: 1px; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 3; }
.row:not(.mine) .acts { right: auto; left: 6px; }
.row:hover .acts, .row:focus-within .acts, .row.tap .acts { display: flex; }
.acts button { border: 0; background: transparent; border-radius: 8px; padding: 4px 5px; font-size: 15px; line-height: 1; color: var(--ink-2); }
.acts button:hover { background: var(--hover); }
.acts button.warn { color: var(--danger); font-size: 12px; font-weight: 600; }
.acts .sep { width: 1px; background: var(--line); margin: 2px; }
.row.flash .bubble { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }
.empty { margin: 18vh auto 0; text-align: center; color: var(--ink-2); max-width: 32ch; line-height: 1.55; background: var(--surface); padding: 20px 22px; border-radius: 16px; }
.empty b { display: block; font-family: var(--f-brand); font-weight: 400; font-size: 22px; color: var(--ink); margin-bottom: 6px; overflow-wrap: anywhere; }

/* ---------- composer ---------- */
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 8px max(12px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) 8px; }
.composer:empty { display: none; }
.composer-inner { max-width: 840px; margin: 0 auto; display: grid; gap: 6px; }
.ctx { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 6px; font-size: 13px; }
.ctx div { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.ctx b { color: var(--accent); font-weight: 600; margin-right: 6px; }
.ctx button { border: 0; background: none; color: var(--ink-3); font-size: 20px; line-height: 1; padding: 0 4px; }
.inputbar { display: flex; align-items: flex-end; gap: 6px; }
.inputbar textarea { flex: 1; min-width: 0; resize: none; max-height: 160px; min-height: 44px; padding: 11px 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--bg); line-height: 1.4; outline: none; font-size: 16px; }
.inputbar textarea:focus { border-color: var(--ink-3); }
.attach { width: 44px; height: 44px; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .4; cursor: default; }
.send svg { width: 20px; height: 20px; fill: currentColor; }

/* ---------- dialogs ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 16, .5); display: grid; place-items: center; padding: 16px; z-index: 20; }
.dialog { width: min(440px, 100%); max-height: calc(100% - 32px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.dialog h2 { margin: 0; font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.dialog p { margin: 0; }
.btns { display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: -20px; background: var(--surface); padding: 8px 0 0; }
.person { display: flex; align-items: center; gap: 10px; font-size: 14.5px; }
.person .av { width: 36px; height: 36px; font-size: 13px; }
.person > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person small { color: var(--ink-3); font-size: 12px; }
.pick-list { display: grid; gap: 4px; max-height: 260px; overflow-y: auto; }
.pick { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 10px; cursor: pointer; }
.pick:hover { background: var(--hover); }
.pick input { accent-color: var(--accent); width: 18px; height: 18px; }
.pick .av { width: 34px; height: 34px; font-size: 12px; }
.pick span { flex: 1; min-width: 0; }
.pick small { color: var(--ink-3); font-size: 12px; font-family: var(--f-mono); }
.profile-top { display: flex; align-items: center; gap: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 40; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

/* ---------- story viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 30; background: #000; color: #fff; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); }
.viewer-bars { display: flex; gap: 4px; padding: 10px 12px 6px; max-width: 520px; width: 100%; margin: 0 auto; }
.bar { flex: 1; height: 3px; border-radius: 2px; background: rgba(255,255,255,.3); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: #fff; }
.bar i.done { width: 100%; }
.bar i.run { animation: fill linear forwards; animation-duration: 6000ms; }
@keyframes fill { to { width: 100%; } }
.viewer-top { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 6px 14px; max-width: 520px; width: 100%; margin: 0 auto; }
.viewer-who { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.viewer-who .av { width: 34px; height: 34px; font-size: 12px; }
.viewer-who span { color: rgba(255,255,255,.7); font-family: var(--f-mono); font-size: 12px; }
.viewer-stage { display: grid; place-items: center; min-height: 0; }
.viewer-stage img, .viewer-stage video { max-width: min(520px, 100%); max-height: 100%; object-fit: contain; }
.viewer-nav { position: absolute; top: 15%; bottom: 20%; width: 35%; border: 0; background: transparent; z-index: 1; }
.viewer-nav.prev { left: 0; } .viewer-nav.next { right: 0; }
.viewer-bottom { padding: 10px 16px 18px; display: grid; gap: 10px; justify-items: center; position: relative; z-index: 2; }
.viewer-cap { margin: 0; text-align: center; font-size: 15px; max-width: 46ch; }
.viewer-actions { display: flex; gap: 8px; }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app[data-view="chat"] .rail { display: none; }
  .app[data-view="list"] .chat { display: none; }
  .rail { border-right: 0; padding-right: env(safe-area-inset-right, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
  .back { display: grid; }
  .col { max-width: 86%; }
  .acts { top: -40px; }
}
@media (prefers-reduced-motion: reduce) { .onair::before, .row.flash .bubble { animation: none; } }
