/* MaxHub — интерфейс. Главная идея: у каждого аккаунта свой цвет,
   и он виден везде, где важно не перепутать, с какого аккаунта вы пишете. */

:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --ink: #1a2230;
  --muted: #6b7684;
  --line: #dde2e8;
  --danger: #c62f3b;
  --in-bubble: #ffffff;
  --acc-1: #2f6fed;
  --acc-2: #0e9f7e;
  --acc-3: #b4307a;
  --acc: var(--acc-1);
  --acc-soft: color-mix(in srgb, var(--acc) 14%, var(--surface));
  --out-bubble: color-mix(in srgb, var(--acc) 16%, #ffffff);
  --radius: 14px;
  --font: "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #18202a;
    --surface-2: #1f2934;
    --ink: #e6ebf1;
    --muted: #8d98a6;
    --line: #2a3542;
    --in-bubble: #1f2934;
    --acc-1: #5b8ff5;
    --acc-2: #2bbf9b;
    --acc-3: #d9579f;
    --out-bubble: color-mix(in srgb, var(--acc) 30%, #18202a);
  }
}

.acc-1 { --acc: var(--acc-1); }
.acc-2 { --acc: var(--acc-2); }
.acc-3 { --acc: var(--acc-3); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
a { color: var(--acc); }

#app { height: 100dvh; display: flex; overflow: hidden; }

/* ---------- общая раскладка ---------- */

.pane-list, .pane-chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}
.pane-list { flex: 1; background: var(--surface); }
.pane-chat { flex: 1; display: none; }
.view-chat .pane-list { display: none; }
.view-chat .pane-chat { display: flex; }

@media (min-width: 900px) {
  .pane-list { flex: 0 0 380px; border-right: 1px solid var(--line); display: flex !important; }
  .pane-chat { display: flex; }
  .back-btn { display: none !important; }
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-height: 56px;
  flex-shrink: 0;
}
.topbar h1 { font-size: 22px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -0.01em; }
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--ink);
  flex-shrink: 0;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- выдвижная панель аккаунтов ---------- */

.topbar h1 { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar h1 .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--acc); flex-shrink: 0; }
.topbar h1 .dot.off { background: transparent; border: 2px solid var(--acc); }
#drawer-btn { position: relative; margin-left: -6px; }
#drawer-btn.has-unread::after {
  content: ""; position: absolute; top: 6px; right: 5px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--danger); border: 2px solid var(--surface);
}
.drawer-backdrop { position: fixed; inset: 0; z-index: 44; background: rgba(0,0,0,.4); opacity: 0; transition: opacity .2s; }
.drawer-backdrop.open { opacity: 1; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 45;
  width: min(310px, 84vw);
  padding: calc(var(--safe-top) + 8px) 0 calc(var(--safe-bottom) + 8px);
  background: var(--surface);
  box-shadow: 6px 0 30px rgba(0,0,0,.25);
  transform: translateX(-105%); transition: transform .2s ease-out;
  display: flex; flex-direction: column; overflow-y: auto;
}
.drawer.open { transform: none; }
.drawer-head { padding: 10px 18px 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.drawer-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px 18px; text-align: left; min-height: 58px;
}
.drawer-item:active { background: var(--surface-2); }
.drawer-item[aria-current="true"] { background: var(--acc-soft); }
.drawer-item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.drawer-item .name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-item .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-item .badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--acc); color: #fff; font-size: 13px; font-weight: 600;
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.drawer-item .acc-av { background: var(--acc); color: #fff; }
.drawer-item .all-av { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.drawer-item.plain .name { font-weight: 500; }
.drawer-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--muted); }
.drawer-icon svg { width: 22px; height: 22px; }
.drawer-sep { height: 1px; background: var(--line); margin: 8px 0; }

/* ---------- фильтр аккаунтов ---------- */

.accbar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  flex-shrink: 0;
}
.accbar::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: 17px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  white-space: nowrap;
  font-size: 15px;
  font-weight: 500;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--acc); }
.chip .dot.off { background: transparent; border: 2px solid var(--acc); width: 10px; height: 10px; }
.chip .count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip[aria-pressed="true"] .count { color: inherit; opacity: 0.75; }
.chip.acc-1[aria-pressed="true"], .chip.acc-2[aria-pressed="true"], .chip.acc-3[aria-pressed="true"] {
  background: var(--acc); border-color: var(--acc); color: #fff;
}
.chip.acc-1[aria-pressed="true"] .dot, .chip.acc-2[aria-pressed="true"] .dot, .chip.acc-3[aria-pressed="true"] .dot { background: #fff; border-color: #fff; }

.search {
  margin: 0 14px 8px;
  height: 38px;
  border-radius: 10px;
  border: 0;
  background: var(--surface-2);
  padding: 0 12px;
  font-size: 16px;
  flex-shrink: 0;
}

.notice {
  margin: 0 14px 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--acc-soft);
  font-size: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.notice b { font-weight: 600; }
.notice .grow { flex: 1; }
.notice button { color: var(--acc); font-weight: 600; }
.notice.warn { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.notice.warn button { color: var(--danger); }

/* ---------- список чатов ---------- */

.chatlist { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--safe-bottom); }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px 9px 14px;
  position: relative;
  width: 100%;
  text-align: left;
}
.row::before {
  content: "";
  position: absolute;
  left: 0; top: 10px; bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--acc);
  opacity: var(--stripe, 0);
}
.show-stripes .row { --stripe: 1; }
.row:active, .row.active { background: var(--surface-2); }
.row .body { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 9px; margin-bottom: -9px; }
.row:last-child .body { border-bottom: 0; }
.row .top { display: flex; gap: 8px; align-items: baseline; }
.row .title { flex: 1; font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.row .bottom { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.row .preview {
  flex: 1;
  color: var(--muted);
  font-size: 15px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
  word-break: break-word;
}
.row .acc-tag { font-size: 12px; color: var(--acc); font-weight: 600; flex-shrink: 0; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  min-width: 22px; height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--acc);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.row.unread .preview { color: var(--ink); }

.avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 18px;
  color: #fff;
  background: var(--av, #8a96a6);
  overflow: hidden;
  position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }

.empty {
  padding: 48px 28px;
  text-align: center;
  color: var(--muted);
}
.empty h2 { color: var(--ink); font-size: 19px; margin: 0 0 8px; }
.empty p { margin: 0 0 18px; }

/* ---------- окно чата ---------- */

.chat-head .titles { flex: 1; min-width: 0; }
.chat-head .name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .sub { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.acc-pill {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--acc); font-weight: 600;
}
.acc-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--acc); }

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg);
}
.messages-wrap { flex: 1; position: relative; display: flex; min-height: 0; }
.messages-wrap .messages { flex: 1; }
.jump {
  position: absolute; right: 12px; bottom: 12px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  display: grid; place-items: center;
}
.jump svg { width: 22px; height: 22px; transform: rotate(-90deg); }
.jump .jump-count {
  position: absolute; top: -6px; right: -4px;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--acc); color: #fff; font-size: 12px; font-weight: 600;
  display: grid; place-items: center;
}
.jump .jump-count[hidden], .jump[hidden] { display: none; }
.messages .loader { text-align: center; color: var(--muted); font-size: 13px; padding: 8px; }
.day {
  align-self: center;
  margin: 10px 0 6px;
  padding: 3px 11px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.service {
  align-self: center;
  max-width: 85%;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0;
}

.msg {
  max-width: min(78%, 560px);
  align-self: flex-start;
  background: var(--in-bubble);
  border-radius: var(--radius);
  border-bottom-left-radius: 5px;
  padding: 6px 10px 6px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--ink) 7%, transparent);
  user-select: text;
  -webkit-user-select: text;
}
.msg.out {
  align-self: flex-end;
  background: var(--out-bubble);
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: 5px;
}
.msg.cont { margin-top: -1px; }
.msg.media-only { padding: 3px; }
.msg.highlight { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--acc); } to { box-shadow: 0 0 0 3px transparent; } }
.msg .from { font-size: 14px; font-weight: 600; color: var(--sender, var(--acc)); margin-bottom: 1px; }
.msg .text { white-space: pre-wrap; font-size: 16px; }
.msg .meta {
  float: right;
  margin: 6px 0 -4px 10px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.msg .meta .ticks { margin-left: 4px; letter-spacing: -3px; padding-right: 3px; }
.msg .meta .ticks.read { color: var(--acc); }
.msg.media-only .meta .ticks.read { color: #7fd0ff; }
.msg.media-only .meta {
  position: absolute; right: 8px; bottom: 7px; margin: 0;
  background: rgba(0, 0, 0, 0.45); color: #fff; padding: 1px 7px; border-radius: 9px;
}
.msg .removed { font-style: italic; color: var(--muted); }
.msg .text .b { font-weight: 700; }
.msg .text .i { font-style: italic; }
.msg .text .u { text-decoration: underline; }
.msg .text .s { text-decoration: line-through; }
.msg .text code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }

.quote {
  display: block;
  border-left: 3px solid var(--acc);
  background: color-mix(in srgb, var(--acc) 9%, transparent);
  border-radius: 4px 8px 8px 4px;
  padding: 4px 8px;
  margin: 2px 0 5px;
  font-size: 14px;
  width: 100%;
  text-align: left;
}
.quote .q-name { font-weight: 600; color: var(--acc); }
.quote .q-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fwd-label { font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.fwd-label b { color: var(--acc); font-weight: 600; }

.photo {
  display: block;
  border-radius: 11px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  margin: 2px 0;
  max-width: 100%;
}
.photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.sticker img { width: 160px; height: auto; display: block; }

.file {
  display: flex; align-items: center; gap: 11px;
  padding: 4px 2px; margin: 2px 0;
  text-decoration: none; color: inherit;
  min-width: 220px;
}
.file .ext {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--acc); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.file .fname { font-weight: 500; font-size: 15px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.file .fsize { font-size: 13px; color: var(--muted); }

.voice { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 3px 0; }
.voice .play {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--acc); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
}
.voice .play svg { width: 18px; height: 18px; }
.voice .track { flex: 1; }
.voice .bars { display: flex; align-items: center; gap: 2px; height: 26px; }
.voice .bars i { flex: 1; background: color-mix(in srgb, var(--acc) 35%, transparent); border-radius: 2px; min-height: 3px; }
.voice .bars i.on { background: var(--acc); }
.voice .vtime { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.transcript { font-size: 14px; color: var(--muted); margin-top: 3px; font-style: italic; }

.video { position: relative; display: block; border-radius: 11px; overflow: hidden; background: #000; margin: 2px 0; }
.video img, .video video { display: block; width: 100%; max-height: 420px; object-fit: contain; }
.video .playbig {
  position: absolute; inset: 0; margin: auto;
  width: 54px; height: 54px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); color: #fff; display: grid; place-items: center;
}
.video .playbig svg { width: 24px; height: 24px; }
.video .dur { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 1px 7px; border-radius: 9px; }

.share {
  display: block; text-decoration: none; color: inherit;
  border-left: 3px solid var(--acc); padding: 3px 8px; margin: 4px 0; font-size: 14px;
}
.share b { display: block; color: var(--acc); }
.share img { display: block; max-width: 100%; border-radius: 8px; margin-top: 4px; }

.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.reactions span { font-size: 13px; background: color-mix(in srgb, var(--ink) 7%, transparent); border-radius: 10px; padding: 1px 7px; }

.pending { opacity: 0.75; }
.pending .meta .progress { color: var(--acc); }
.failed { outline: 1px solid var(--danger); }
.failed .retry { color: var(--danger); font-size: 13px; font-weight: 600; display: block; margin-top: 4px; }

/* ---------- поле ввода ---------- */

.composer {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  flex-shrink: 0;
}
.composer .from-line {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted); padding: 0 6px 6px;
}
.composer .from-line b { color: var(--acc); font-weight: 600; }
.composer .reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px 8px 6px;
}
.composer .reply-bar .quote { margin: 0; flex: 1; min-width: 0; }
.composer .files { display: flex; gap: 8px; overflow-x: auto; padding: 0 4px 8px; }
.composer .ffile {
  position: relative; flex-shrink: 0;
  width: 64px; height: 64px; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 11px; text-align: center; padding: 4px;
  word-break: break-all;
}
.composer .ffile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.composer .ffile .x {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 20px; z-index: 1;
}
.composer .inputrow { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 9px 14px;
  min-height: 40px;
  max-height: 160px;
  background: var(--surface-2);
  font-size: 16px;
  line-height: 1.35;
  outline: none;
}
.composer textarea:focus { border-color: var(--acc); }
.send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--acc); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.4; }
.send-btn svg { width: 20px; height: 20px; }
.attach-btn { color: var(--muted); }

.offline-bar {
  background: var(--danger); color: #fff; text-align: center;
  font-size: 13px; padding: 4px; flex-shrink: 0;
}

/* ---------- аккаунты и формы ---------- */

.sheet { flex: 1; overflow-y: auto; padding: 14px 14px calc(30px + var(--safe-bottom)); background: var(--bg); }
.card {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}
.card h2 { font-size: 17px; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.card h2 .acc-swatch { width: 12px; height: 12px; border-radius: 50%; background: var(--acc); }
.card .status { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.card .status.ok { color: var(--acc-2); }
.card .status.bad { color: var(--danger); }
.card p { font-size: 14px; color: var(--muted); margin: 6px 0 10px; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.card .actions .btn { height: 36px; padding: 0 12px; font-size: 14px; font-weight: 500; }
.card .actions .btn:not(.ghost):not(.danger) { font-weight: 600; }
.qrbox { background: #fff; border-radius: 12px; padding: 8px; width: 232px; height: 232px; margin: 6px 0; }
.qrbox img { width: 100%; height: 100%; display: block; }

.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; height: 44px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2);
  padding: 0 12px; font-size: 16px;
}
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; height: 36px; border-radius: 8px; font-size: 15px; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.btn {
  height: 42px; padding: 0 16px; border-radius: 10px;
  background: var(--acc); color: #fff; font-weight: 600; font-size: 15px;
}
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }
.btn:disabled { opacity: 0.5; }
.btn.wide { width: 100%; }

/* ---------- вход ---------- */

.login {
  margin: auto;
  width: min(360px, 100% - 40px);
  padding-bottom: 10vh;
}
.login .mark { display: flex; gap: 6px; margin-bottom: 18px; }
.login .mark i { width: 14px; height: 40px; border-radius: 7px; }
.login .mark i:nth-child(1) { background: var(--acc-1); }
.login .mark i:nth-child(2) { background: var(--acc-2); height: 52px; }
.login .mark i:nth-child(3) { background: var(--acc-3); height: 30px; }
.login h1 { font-size: 30px; margin: 0 0 4px; letter-spacing: -0.02em; }
.login p { color: var(--muted); margin: 0 0 22px; }
.login .error { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* ---------- просмотр фото, меню, тосты ---------- */

.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.92);
  display: grid; place-items: center;
  padding: var(--safe-top) 0 var(--safe-bottom);
}
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox .close { position: absolute; top: calc(var(--safe-top) + 10px); right: 12px; color: #fff; }
.lightbox .save { position: absolute; bottom: calc(var(--safe-bottom) + 14px); right: 14px; color: #fff; font-size: 15px; }

.menu-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.25); }
.menu {
  position: fixed; z-index: 41;
  background: var(--surface); border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
  min-width: 200px; overflow: hidden;
}
.menu button { display: block; width: 100%; text-align: left; padding: 13px 16px; font-size: 16px; }
.menu button + button { border-top: 1px solid var(--line); }
.menu button:active { background: var(--surface-2); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 90px);
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100% - 40px); z-index: 60;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- просмотр файлов ---------- */

.viewer {
  position: fixed; inset: 0; z-index: 55;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.viewer-bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: var(--surface); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.viewer-title { flex: 1; min-width: 0; font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-action { color: var(--acc); font-size: 16px; font-weight: 500; padding: 8px 6px; }
.viewer-action:disabled { opacity: .4; }
.viewer-body {
  flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 8px 8px calc(var(--safe-bottom) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  touch-action: pan-x pan-y pinch-zoom;
}
.viewer-page { background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.2); max-width: none; height: auto; flex-shrink: 0; }
.viewer-note { margin: auto; text-align: center; color: var(--muted); padding: 24px; font-size: 16px; }
.viewer-note.small { margin: 4px auto; padding: 4px; font-size: 13px; }
.viewer-big { margin-top: 12px; padding: 12px 20px; border-radius: 12px; background: var(--acc); color: #fff; font-size: 16px; font-weight: 600; }

/* ---------- редактор фото ---------- */

.composer .ffile.editable { cursor: pointer; }
.composer .ffile .edit-badge {
  position: absolute; left: 3px; bottom: 3px; z-index: 1;
  padding: 0 6px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff;
  font-size: 12px; font-weight: 700; line-height: 18px;
}
.editor {
  position: fixed; inset: 0; z-index: 55;
  background: #0d0f12; color: #fff;
  display: flex; flex-direction: column;
}
.editor-bar { display: flex; align-items: center; padding: calc(var(--safe-top) + 6px) 10px 6px; flex-shrink: 0; }
.editor-bar .grow { flex: 1; }
.editor-cancel, .editor-done { font-size: 17px; padding: 10px 10px; color: #fff; }
.editor-done { font-weight: 700; color: #6fb1ff; }
.editor-done:disabled { opacity: .6; }
.editor-stage { flex: 1; min-height: 120px; display: grid; place-items: center; overflow: hidden; padding: 4px; }
.editor-canvas { touch-action: none; display: block; }
.editor-panel {
  flex-shrink: 0; padding: 10px 14px calc(var(--safe-bottom) + 12px);
  background: #171b21; display: flex; flex-direction: column; gap: 10px;
  max-height: 55dvh; overflow-y: auto;
}
.editor-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.editor-btn { padding: 9px 14px; border-radius: 18px; background: #2a313b; color: #fff; font-size: 15px; font-weight: 600; }
.editor-btn:active { background: #3a434f; }
.editor-btn.danger { color: #ff8a8a; }
.editor-text {
  flex: 1; min-width: 120px; height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid #3a434f; background: #0d0f12; color: #fff; font-size: 16px;
}
.editor-slider { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #b9c2cd; }
.editor-slider span { width: 104px; flex-shrink: 0; }
.editor-slider input { flex: 1; min-width: 0; height: 28px; accent-color: #6fb1ff; }
.editor-color { width: 32px; height: 32px; border-radius: 50%; border: 2px solid #55606d; }
.editor-color[aria-pressed="true"] { outline: 3px solid #6fb1ff; outline-offset: 2px; }
.editor-hint { font-size: 14px; color: #b9c2cd; }
.editor-check { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.editor-check input { width: 20px; height: 20px; accent-color: #6fb1ff; }

/* ---------- закреплённые чаты ---------- */

.row { -webkit-touch-callout: none; }
.row .pin { color: var(--muted); flex-shrink: 0; display: inline-grid; place-items: center; }
.row .pin svg { width: 15px; height: 15px; }

.row, .row *, .menu, .menu *, .sheet, .sheet * { -webkit-user-select: none; user-select: none; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 46; background: rgba(0,0,0,.4); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 47;
  max-width: 520px; margin: 0 auto;
  padding: 14px 14px calc(var(--safe-bottom) + 14px);
  background: var(--surface); border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,.25);
  display: flex; flex-direction: column; gap: 10px;
  -webkit-touch-callout: none;
}
.sheet-title { font-size: 15px; font-weight: 600; color: var(--muted); text-align: center; padding: 2px 8px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 52px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 17px; font-weight: 600; color: var(--ink);
}
.sheet-btn.primary { background: var(--acc); border-color: var(--acc); color: #fff; }
.sheet-btn:active { opacity: .8; }
.sheet-btn svg { width: 20px; height: 20px; }

/* ---------- пересылка ---------- */

.picker { background: var(--surface); }
.picker .search { margin: 10px 14px 8px; }
.picker-quote {
  margin: 10px 14px 0; padding: 8px 12px; border-left: 3px solid var(--acc); border-radius: 6px;
  background: var(--acc-soft); font-size: 14px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0;
}
.picker-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(var(--safe-bottom) + 8px); display: flex; flex-direction: column; }
.picker-list.busy { opacity: .5; pointer-events: none; }
.picker-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 14px; text-align: left; min-height: 54px; flex-shrink: 0; }
.picker-item:active { background: var(--surface-2); }
.picker-item .name { flex: 1; min-width: 0; font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-item .pin { color: var(--muted); }
.picker-item .pin svg { width: 15px; height: 15px; }
.picker, .picker * { -webkit-user-select: none; user-select: none; }
.picker input { -webkit-user-select: text; user-select: text; }
