/* HERMES — оформление в стиле Telegram для Android. Светлая и тёмная темы по системе. */

:root {
  --header-bg: #527DA3;
  --header-fg: #FFFFFF;
  --header-sub: rgba(255, 255, 255, 0.78);
  --accent: #3390EC;
  --accent-fg: #FFFFFF;
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F1F3F5;
  --text: #000000;
  --text-2: #707579;
  --divider: rgba(0, 0, 0, 0.09);
  --wall-a: #D1DFC4;
  --wall-b: #9EC5B3;
  --wall-dot: rgba(255, 255, 255, 0.22);
  --wall-dot-2: rgba(80, 120, 90, 0.10);
  --me-bg: #EFFDDE;
  --me-meta: #4FAE4E;
  --bot-bg: #FFFFFF;
  --bot-meta: #A0A7AD;
  --link: #2481CC;
  --code-bg: rgba(0, 0, 0, 0.055);
  --code-fg: #C0392B;
  --pre-bg: #F4F6F8;
  --quote: #3390EC;
  --pill-bg: rgba(0, 0, 0, 0.22);
  --pill-fg: #FFFFFF;
  --danger: #E53935;
  --ok: #43A047;
  --shadow: 0 1px 1.5px rgba(0, 0, 0, 0.13);
  --menu-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  --composer-bg: #FFFFFF;
  --icon: #8A9299;
  --input-bg: #FFFFFF;
  --sheet-bg: #FFFFFF;
  --backdrop: rgba(0, 0, 0, 0.4);
  --table-border: rgba(0, 0, 0, 0.12);
  --table-head: rgba(0, 0, 0, 0.04);
  --radius: 15px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --header-bg: #212D3B;
    --header-fg: #FFFFFF;
    --header-sub: #7E8D9F;
    --accent: #5FA8E8;
    --bg: #17212B;
    --surface: #17212B;
    --surface-2: #242F3D;
    --text: #F5F5F5;
    --text-2: #7E8D9F;
    --divider: rgba(255, 255, 255, 0.07);
    --wall-a: #0E1621;
    --wall-b: #0E1621;
    --wall-dot: rgba(255, 255, 255, 0.025);
    --wall-dot-2: rgba(95, 168, 232, 0.035);
    --me-bg: #2B5278;
    --me-meta: #7DA8D3;
    --bot-bg: #182533;
    --bot-meta: #6D7F8F;
    --link: #71BAFA;
    --code-bg: rgba(255, 255, 255, 0.08);
    --code-fg: #F2A07B;
    --pre-bg: rgba(0, 0, 0, 0.25);
    --quote: #5FA8E8;
    --pill-bg: rgba(0, 0, 0, 0.35);
    --shadow: 0 1px 1.5px rgba(0, 0, 0, 0.3);
    --menu-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
    --composer-bg: #17212B;
    --icon: #6D7F8F;
    --input-bg: #17212B;
    --sheet-bg: #1E2C3A;
    --backdrop: rgba(0, 0, 0, 0.55);
    --table-border: rgba(255, 255, 255, 0.12);
    --table-head: rgba(255, 255, 255, 0.05);
    color-scheme: dark;
  }
}

/* ---------- база ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--header-bg);
  color: var(--text);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 100%; /* следует системному масштабу шрифта */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }

.app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  height: var(--app-h, 100%);
  overflow: hidden;
  background: var(--bg);
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- заставка ---------- */
.boot { align-items: center; justify-content: center; background: #1F2A44; }
.boot-logo, .login-logo {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: #1F2A44;
  color: #FFF;
  font-weight: 800;
  font-size: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.boot-logo { animation: pulse 1.4s ease-in-out infinite; box-shadow: 0 0 0 2px rgba(255,255,255,0.15); }
.login-logo { box-shadow: 0 0 0 2px rgba(127,127,127,0.25), 0 6px 18px rgba(0,0,0,0.18); }
@keyframes pulse { 50% { transform: scale(0.94); opacity: 0.8; } }

/* ---------- вход ---------- */
.login {
  background: var(--surface);
  align-items: center;
  justify-content: flex-start;
  padding: calc(24px + var(--safe-top)) calc(24px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(24px + var(--safe-left));
  overflow-y: auto;
}
.login-box { width: 100%; max-width: 360px; text-align: center; margin: auto 0; flex: 0 0 auto; }
.login-logo { margin: 0 auto 20px; }
.login-title { font-size: 1.35rem; font-weight: 600; margin: 0 0 10px; line-height: 1.3; }
.login-hint { color: var(--text-2); margin: 0 0 24px; line-height: 1.45; font-size: 0.95rem; }
.login-error { color: var(--danger); margin: 16px 0 0; font-size: 0.95rem; line-height: 1.4; }
.code-form { display: flex; flex-direction: column; align-items: stretch; }
.code-label { color: var(--text-2); font-size: 0.85rem; margin-bottom: 8px; }
.code-input {
  width: 100%;
  max-width: 280px;
  margin: 0 auto 18px;
  text-align: center;
  font-size: 2rem;
  letter-spacing: 0.45em;
  padding: 10px 0 10px 0.45em;
  border: 0;
  border-bottom: 2px solid var(--accent);
  background: transparent;
  outline: none;
  font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
}
.code-input::placeholder { color: var(--text-2); opacity: 0.4; }

.btn {
  border: 0;
  border-radius: 10px;
  min-height: 48px;
  padding: 0 20px;
  font-weight: 600;
  font-size: 1rem;
}
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:disabled { opacity: 0.55; }
.btn-wide { width: 100%; }
.btn-link { background: transparent; color: var(--accent); font-weight: 500; margin-top: 8px; }
.btn-link:disabled { color: var(--text-2); }
.btn-flat { background: transparent; color: var(--accent); min-height: 40px; padding: 0 14px; text-transform: none; }
.btn-flat-accent { font-weight: 700; }

/* ---------- шапка ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  background: var(--header-bg);
  color: var(--header-fg);
  padding: var(--safe-top) calc(4px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  min-height: calc(56px + var(--safe-top));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  position: relative;
  z-index: 3;
}
.avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #1F2A44;
  color: #FFF;
  font-weight: 800;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.25);
}
.topbar-text { flex: 1 1 auto; min-width: 0; }
.topbar-title { font-weight: 600; font-size: 1.1rem; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-status { font-size: 0.85rem; color: var(--header-sub); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-status.typing { color: #FFFFFF; }
.topbar-status.phrase { font-size: 0.78rem; font-style: italic; }
.topbar-status.offline { color: #FFD6A5; }
.overlay-screen .topbar { padding-left: calc(4px + var(--safe-left)); }
.overlay-screen .topbar-text { margin-left: 8px; }

.icon-btn {
  border: 0;
  background: transparent;
  color: inherit;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-decoration: none;
}
.icon-btn svg { fill: currentColor; }
.icon-btn:active { background: rgba(127, 127, 127, 0.18); }

.offline-banner {
  flex: 0 0 auto;
  background: #F4B400;
  color: #222;
  text-align: center;
  font-size: 0.85rem;
  padding: 6px 12px;
  z-index: 2;
}

/* ---------- лента ---------- */
.feed {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.scroller {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  position: relative;
  padding: 6px calc(8px + var(--safe-right)) 10px calc(8px + var(--safe-left));
  background-color: var(--wall-a);
  background-image:
    radial-gradient(circle at 25% 30%, var(--wall-dot) 0 2px, transparent 2.5px),
    radial-gradient(circle at 75% 70%, var(--wall-dot-2) 0 3px, transparent 3.5px),
    radial-gradient(circle at 60% 15%, var(--wall-dot) 0 1.5px, transparent 2px),
    linear-gradient(160deg, var(--wall-a), var(--wall-b));
  background-size: 46px 46px, 64px 64px, 38px 38px, 100% 100%;
  background-attachment: local, local, local, fixed;
}
.msg-list { display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }

.loading-note, .empty-note { text-align: center; margin: 12px 0; }
.loading-note { color: var(--pill-fg); font-size: 0.85rem; }
.empty-note { display: flex; justify-content: center; margin-top: 30vh; }
.empty-card {
  background: var(--pill-bg);
  color: var(--pill-fg);
  border-radius: 16px;
  padding: 14px 18px;
  max-width: 280px;
}
.empty-title { font-weight: 600; margin-bottom: 4px; }
.empty-text { font-size: 0.9rem; line-height: 1.4; opacity: 0.95; }

.mrow { display: flex; flex-direction: column; margin-top: 2px; }
.mrow.me { align-items: flex-end; }
.mrow.bot { align-items: flex-start; }
.mrow.system { align-items: center; }
.mrow.group-start { margin-top: 8px; }

.date-sep {
  align-self: center;
  background: var(--pill-bg);
  color: var(--pill-fg);
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 14px;
  padding: 3px 10px;
  margin: 10px 0 6px;
  user-select: none;
}

.bubble {
  position: relative;
  max-width: min(85%, 640px);
  min-width: 64px;
  padding: 6px 9px 7px 10px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 1rem;
  line-height: 1.38;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  -webkit-user-select: text;
  user-select: text;
}
.mrow.me .bubble { background: var(--me-bg); color: var(--text); }
.mrow.bot .bubble { background: var(--bot-bg); color: var(--text); }
.mrow.bot .bubble.wide { width: min(85%, 640px); }

/* хвостики как в Telegram: у последнего сообщения группы */
.mrow.tail.me .bubble { border-bottom-right-radius: 4px; }
.mrow.tail.bot .bubble { border-bottom-left-radius: 4px; }
.mrow.tail .bubble::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 10px;
  height: 14px;
}
.mrow.tail.me .bubble::after {
  right: -7px;
  background: radial-gradient(circle at 100% 0, transparent 9.5px, var(--me-bg) 10px);
}
.mrow.tail.bot .bubble::after {
  left: -7px;
  background: radial-gradient(circle at 0 0, transparent 9.5px, var(--bot-bg) 10px);
}
.mrow.tail.me { margin-right: 7px; }
.mrow.tail.bot { margin-left: 7px; }
.mrow.me:not(.tail) { margin-right: 7px; }
.mrow.bot:not(.tail) { margin-left: 7px; }

.mrow.system .bubble {
  background: var(--pill-bg);
  color: var(--pill-fg);
  box-shadow: none;
  font-size: 0.875rem;
  text-align: center;
  padding: 4px 12px;
  max-width: 90%;
}
.mrow.system .meta { display: none; }

.text:empty { display: none; }
.text > :first-child { margin-top: 0; }
.text > :last-child { margin-bottom: 0; }

/* время и галочки в углу пузыря */
.meta {
  float: right;
  position: relative;
  bottom: -5px;
  margin: 2px -2px 0 10px;
  font-size: 0.72rem;
  line-height: 1;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  user-select: none;
  color: var(--bot-meta);
}
.mrow.me .meta { color: var(--me-meta); }
.meta .ticks { margin-left: 3px; display: inline-flex; }
.meta svg { width: 16px; height: 11px; fill: currentColor; }
.meta .err { color: var(--danger); font-weight: 700; margin-left: 4px; }
.bubble::before { content: ""; display: table; } /* для float */
.bubble-end { clear: both; }

/* ---------- markdown ---------- */
.md p { margin: 0 0 0.5em; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 0.6em 0 0.35em; line-height: 1.3; }
.md h1 { font-size: 1.3em; }
.md h2 { font-size: 1.2em; }
.md h3 { font-size: 1.08em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { margin: 0.2em 0 0.55em; padding-left: 1.4em; }
.md li { margin: 0.12em 0; }
.md li > ul, .md li > ol { margin: 0.1em 0 0.15em; }
.md blockquote {
  margin: 0.3em 0 0.55em;
  padding: 2px 0 2px 10px;
  border-left: 3px solid var(--quote);
  border-radius: 2px;
}
.md hr { border: 0; border-top: 1px solid var(--divider); margin: 0.7em 0; }
.md code {
  font-family: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 4px;
  padding: 0.05em 0.3em;
}
.md a { word-break: break-all; }
.md-code {
  margin: 0.3em 0 0.6em;
  background: var(--pre-bg);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--divider);
}
.md-code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 0 10px;
  font-size: 0.78rem;
  color: var(--text-2);
  border-bottom: 1px solid var(--divider);
}
.md-copy {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  min-height: 34px;
  padding: 0 8px;
}
.md-code pre { margin: 0; padding: 8px 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.md-code code {
  background: transparent;
  color: var(--text);
  padding: 0;
  font-size: 0.84em;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}
.md-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.3em 0 0.6em;
  max-width: 100%;
  border: 1px solid var(--table-border);
  border-radius: 8px;
}
.md table { border-collapse: collapse; font-size: 0.9em; min-width: 100%; }
.md th, .md td {
  padding: 5px 9px;
  border-bottom: 1px solid var(--table-border);
  border-right: 1px solid var(--table-border);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  overflow-wrap: normal;
}
.md td { white-space: normal; min-width: 70px; max-width: 280px; }
.md th:last-child, .md td:last-child { border-right: 0; }
.md tbody tr:last-child td { border-bottom: 0; }
.md th { background: var(--table-head); font-weight: 600; }
.md .al-c { text-align: center; }
.md .al-r { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- вложения в сообщениях ---------- */
.files { margin: -2px -5px 4px -6px; }
.files:last-child { margin-bottom: 0; }
.img-grid { display: flex; flex-wrap: wrap; gap: 3px; }
.img-thumb {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(127, 127, 127, 0.18);
  border-radius: 11px;
  overflow: hidden;
  flex: 1 1 140px;
  max-width: 100%;
  min-height: 120px;
  max-height: 320px;
  display: block;
}
.img-thumb.single { flex-basis: 240px; min-width: 200px; }
.img-thumb img { display: block; width: 100%; height: 100%; max-height: 320px; object-fit: cover; }
.doc-chip {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  padding: 4px 6px;
  min-height: 52px;
  border-radius: 10px;
  max-width: 320px;
}
.doc-chip + .doc-chip { margin-top: 2px; }
.doc-ico {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFF;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin-right: 10px;
  background: #5B8FD0;
}
.doc-ico.pdf { background: #E5534B; }
.doc-ico.xls { background: #2E9E5B; }
.doc-ico.doc { background: #2F6FD6; }
.doc-ico.img { background: #8E6BD1; }
.doc-ico.aud { background: #E08A2E; }
.doc-ico.zip { background: #7C8691; }
.doc-text { min-width: 0; flex: 1 1 auto; }
.doc-name { font-weight: 500; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-size { color: var(--text-2); font-size: 0.8rem; margin-top: 2px; }
.mrow.me .doc-size { color: var(--me-meta); }
.upload-bar {
  height: 3px;
  background: rgba(127, 127, 127, 0.25);
  border-radius: 2px;
  margin: 4px 2px 2px;
  overflow: hidden;
}
.upload-bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.upload-note { font-size: 0.8rem; color: var(--text-2); margin: 2px 2px 0; }

/* ---------- карточки подтверждения и вопроса ---------- */
.card-title { font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; }
.card-title .card-ico { margin-right: 6px; }
.card-desc { margin-bottom: 6px; }
.card-cmd {
  font-family: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--pre-bg);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 4px 0 8px;
  overflow-wrap: anywhere;
  /* строго слева направо в порядке символов: переставить видимую команду нельзя */
  direction: ltr;
  unicode-bidi: bidi-override;
  text-align: left;
}
.card-warn {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 4px 0 2px;
  line-height: 1.35;
}
.card-actions { display: flex; flex-wrap: wrap; margin: 2px -3px 2px; }
.card-btn {
  flex: 1 1 auto;
  min-height: 42px;
  margin: 3px;
  border-radius: 10px;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  padding: 0 12px;
}
.card-btn.primary { background: var(--accent); color: var(--accent-fg); }
.card-btn.deny { border-color: var(--danger); color: var(--danger); }
.card-btn:disabled { opacity: 0.45; }
/* «Разрешить один раз» взводится ~0,6 с после появления карточки */
.card-btn.primary.arming { opacity: 0.6; animation: arm 0.6s linear; }
@keyframes arm { from { opacity: 0.25; } to { opacity: 0.6; } }
.card-state { font-weight: 600; margin-top: 4px; font-size: 0.92rem; }
.card-state.approved, .card-state.answered { color: var(--ok); }
.card-state.denied { color: var(--danger); }
.card-state.expired { color: var(--text-2); }
.clarify-form { display: flex; margin-top: 4px; }
.clarify-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 0 10px;
  background: var(--input-bg);
  outline: none;
}
.clarify-input:focus { border-color: var(--accent); }
.clarify-send { margin-left: 6px; min-width: 44px; color: var(--accent); }

/* ---------- печатает… ---------- */
.typing-row { max-width: 860px; margin: 4px auto 0; width: 100%; padding-left: 7px; }
.typing-bubble {
  min-width: 0;
  padding: 12px 14px;
  display: inline-flex;
  align-items: center;
  border-bottom-left-radius: 4px;
}
.typing-bubble span {
  width: 7px;
  height: 7px;
  margin: 0 2px;
  border-radius: 50%;
  background: var(--bot-meta);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.18s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- кнопка «вниз» ---------- */
.jump-btn {
  position: absolute;
  right: calc(12px + var(--safe-right));
  bottom: 12px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--surface);
  color: var(--icon);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
}
.jump-btn svg { fill: currentColor; }
.jump-badge {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #FFF;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* ---------- лоток вложений ---------- */
.tray {
  flex: 0 0 auto;
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--composer-bg);
  border-top: 1px solid var(--divider);
  padding: 8px calc(8px + var(--safe-right)) 4px calc(8px + var(--safe-left));
}
.tray-item {
  position: relative;
  flex: 0 0 auto;
  margin-right: 8px;
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}
.tray-img { width: 72px; height: 72px; }
.tray-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tray-doc { height: 72px; width: 170px; display: flex; align-items: center; padding: 0 28px 0 8px; }
.tray-doc .doc-ico { width: 38px; height: 38px; margin-right: 8px; }
.tray-doc .doc-name { font-size: 0.85rem; }
.tray-doc .doc-size { font-size: 0.75rem; }
.tray-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 2px;
}
.tray-x span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #FFF;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tray-busy { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.45); color: #fff; font-size: 0.68rem; text-align: center; padding: 2px 0; }

/* ---------- поле ввода ---------- */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  background: var(--composer-bg);
  padding: 2px calc(2px + var(--safe-right)) calc(2px + var(--safe-bottom)) calc(2px + var(--safe-left));
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.06);
  z-index: 3;
}
.composer-btn { color: var(--icon); flex: 0 0 auto; }
.send-btn { color: var(--accent); }
.input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 1.05rem;
  line-height: 1.35;
  padding: 13px 6px 13px 2px;
  min-height: 48px;
  max-height: 40vh;
  overflow-y: auto;
  color: var(--text);
}
.input::placeholder { color: var(--text-2); }

/* ---------- меню ⋮ ---------- */
.menu-backdrop { position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 20; }
.menu {
  position: absolute;
  top: calc(6px + var(--safe-top));
  right: calc(6px + var(--safe-right));
  z-index: 21;
  background: var(--sheet-bg);
  color: var(--text);
  border-radius: 10px;
  box-shadow: var(--menu-shadow);
  padding: 6px 0;
  min-width: 250px;
  max-width: calc(100vw - 24px);
  transform-origin: top right;
  animation: menuIn 0.14s ease-out;
}
@keyframes menuIn { from { opacity: 0; transform: scale(0.92); } }
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0 20px;
  min-height: 48px;
  font-size: 1rem;
}
.menu-item:active, .sheet-item:active, .hist-item:active { background: rgba(127, 127, 127, 0.14); }
.menu-item:disabled, .menu-item.is-disabled { color: var(--text-2); opacity: 0.55; }
.composer-btn.is-disabled { opacity: 0.4; }
.composer-hint {
  flex: 0 0 auto;
  background: var(--composer-bg);
  color: var(--danger);
  font-size: 0.85rem;
  line-height: 1.35;
  padding: 4px calc(12px + var(--safe-right)) 2px calc(12px + var(--safe-left));
}
.menu-item.danger { color: var(--danger); }
.btn-flat.danger-text { color: var(--danger); }
.offscreen { position: fixed; top: -1000px; left: -1000px; width: 1px; height: 1px; opacity: 0; }
@media (pointer: coarse) { .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }

/* ---------- нижние листы ---------- */
.sheet-backdrop, .dialog-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--backdrop);
  z-index: 30;
  animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  background: var(--sheet-bg);
  color: var(--text);
  border-radius: 14px 14px 0 0;
  padding: 6px var(--safe-right) calc(8px + var(--safe-bottom)) var(--safe-left);
  max-width: 560px;
  margin: 0 auto;
  animation: sheetIn 0.2s ease-out;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
}
@keyframes sheetIn { from { transform: translateY(100%); } }
.sheet-tall { max-height: 85%; display: flex; flex-direction: column; }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--divider); margin: 2px auto 8px; }
.sheet-title { font-weight: 600; padding: 6px 20px 10px; color: var(--text-2); font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-head { display: flex; align-items: center; }
.sheet-head .sheet-title { flex: 1 1 auto; color: var(--text); font-size: 1.1rem; padding-bottom: 6px; }
.sheet-x { color: var(--text-2); font-size: 1.1rem; }
.sheet-item {
  display: flex;
  align-items: center;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0 20px;
  min-height: 52px;
  font-size: 1rem;
}
.sheet-ico { width: 32px; font-size: 1.25rem; margin-right: 12px; text-align: center; }
.sheet-cancel { justify-content: center; color: var(--accent); font-weight: 600; border-top: 1px solid var(--divider); margin-top: 4px; }
.sheet-body { overflow-y: auto; padding: 0 20px 12px; line-height: 1.45; -webkit-overflow-scrolling: touch; }
.mem-h { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); font-weight: 700; margin: 14px 0 6px; }
.mem-empty { color: var(--text-2); font-style: italic; }

/* ---------- диалоги ---------- */
.dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 31;
  width: calc(100% - 48px);
  max-width: 420px;
  background: var(--sheet-bg);
  color: var(--text);
  border-radius: 14px;
  padding: 20px 20px 10px;
  box-shadow: var(--menu-shadow);
  animation: fadeIn 0.15s ease-out;
}
.dialog-title { font-weight: 600; font-size: 1.1rem; margin-bottom: 10px; }
.dialog-text { color: var(--text-2); line-height: 1.45; margin-bottom: 12px; white-space: pre-line; }
.dialog-text:empty { display: none; }
.dialog-input {
  width: 100%;
  border: 0;
  border-bottom: 2px solid var(--accent);
  background: transparent;
  outline: none;
  padding: 8px 2px;
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--text);
}
.dialog-textarea { resize: vertical; min-height: 96px; max-height: 40vh; border: 1px solid var(--divider); border-radius: 8px; padding: 8px 10px; }
.dialog-textarea:focus { border-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 6px; }

/* ---------- история ---------- */
.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.18s ease-out;
}
@keyframes slideIn { from { transform: translateX(30%); opacity: 0; } }
.history-list { flex: 1 1 auto; overflow-y: auto; padding-bottom: var(--safe-bottom); -webkit-overflow-scrolling: touch; }
.hist-item {
  display: flex;
  align-items: center;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px calc(4px + var(--safe-right)) 8px calc(12px + var(--safe-left));
  min-height: 72px;
  color: var(--text);
}
.hist-item.current { background: rgba(51, 144, 236, 0.09); }
.hist-ava {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #1F2A44;
  color: #FFF;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  font-size: 1.1rem;
}
.hist-main { flex: 1 1 auto; min-width: 0; border-bottom: 1px solid var(--divider); padding: 6px 0 10px; }
.hist-top { display: flex; align-items: baseline; }
.hist-title { flex: 1 1 auto; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-date { flex: 0 0 auto; color: var(--text-2); font-size: 0.8rem; margin-left: 8px; }
.hist-preview { color: var(--text-2); font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.hist-more { color: var(--text-2); flex: 0 0 auto; }
.hist-empty { color: var(--text-2); text-align: center; padding: 40px 20px; }

/* ---------- просмотр фото ---------- */
.viewer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease-out;
}
.viewer-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: flex-end;
  padding: calc(4px + var(--safe-top)) calc(4px + var(--safe-right)) 4px 4px;
  background: linear-gradient(rgba(0, 0, 0, 0.5), transparent);
  z-index: 1;
}
.viewer-btn { color: #FFF; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; touch-action: pinch-zoom; }

/* ---------- всплывашка ---------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  bottom: calc(12px + max(var(--composer-h, 0px), var(--safe-bottom)));
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(30, 30, 30, 0.92);
  color: #FFF;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.92rem;
  max-width: calc(100% - 32px);
  text-align: center;
  line-height: 1.35;
  animation: fadeIn 0.15s ease-out;
}

@media (min-width: 900px) {
  .bubble { max-width: 640px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
@media (pointer: coarse) { .bubble input, .bubble textarea { -webkit-user-select: text; user-select: text; } }
