/* ============================================================
   ЕНЦ ПК 112 — стиль (v3, дизайн-апдейт + фиксы)
   ============================================================ */

:root {
  --bg: #0a0f1a;
  --bg-2: #101827;
  --panel: #182136;
  --panel-2: #1f2a44;
  --border: #2a3654;
  --border-2: #38466b;
  --red: #b91c1c;
  --red-2: #dc2626;
  --gold: #f0b429;
  --gold-2: #fbbf24;
  --text: #e8edf7;
  --muted: #8fa0be;
  --muted-2: #64748b;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.35);
  --shadow: 0 4px 16px rgba(0,0,0,.30);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.50);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-height: 56px;
  --tabbar-height: 62px;

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[data-theme="light"] {
  --bg: #eef1f6;
  --bg-2: #e3e7ee;
  --panel: #f7f8fb;
  --panel-2: #eceff4;
  --border: #d4dae3;
  --border-2: #b8c0cc;
  --text: #1f2937;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --shadow-sm: 0 1px 2px rgba(31,41,55,.05);
  --shadow: 0 4px 14px rgba(31,41,55,.08);
  --shadow-lg: 0 12px 32px rgba(31,41,55,.12);
  --gold: #4b5563;
  --gold-2: #374151;
  --red: #4b5563;
  --red-2: #6b7280;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
}

html {
  background: var(--bg);
}

body {
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-attachment: fixed;
  background-size: cover;
}

[data-theme="light"] body {
  background: var(--bg);
  color: var(--text);
}

a { color: var(--gold-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.edge-top, .edge-bottom { display: none !important; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  height: var(--topbar-height);
  background: rgba(16, 24, 39, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
[data-theme="light"] .topbar {
  background: rgba(247, 248, 251, 0.92);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.topbar .brand .logo-wrap {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: #050810;
  border: 1.5px solid var(--gold);
  padding: 3px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(240,180,41,.15), inset 0 0 8px rgba(240,180,41,.1);
}
[data-theme="light"] .topbar .brand .logo-wrap {
  background: #e8ebf0;
  border-color: var(--border-2);
  box-shadow: none;
}
.topbar .brand .logo-wrap .logo-img {
  width: 100%; height: 100%;
  object-fit: contain; display: block;
}
.topbar .brand .logo-wrap .logo {
  width: 100%; height: 100%; border-radius: 6px;
  display: grid; place-items: center;
  background: radial-gradient(circle at 30% 30%, #f0b429, #b91c1c);
  color: #fff; font-weight: 900; font-size: 11px;
}
[data-theme="light"] .topbar .brand .logo-wrap .logo {
  background: linear-gradient(135deg, #9ca3af, #4b5563);
}

.topbar .brand .title {
  color: var(--text);
  font-size: 14px; font-weight: 700;
  letter-spacing: .2px;
  min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.15;
}
.topbar .brand .title small {
  display: block;
  color: var(--muted);
  font-weight: 400;
  font-size: 10.5px;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

.topbar .group-title {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar .group-title .gname {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .group-title .gmembers {
  color: var(--muted);
  font-size: 10.5px;
}

.topbar .icon-actions {
  display: flex; gap: 6px; align-items: center;
  flex: 0 0 auto;
}

.topbar .icon-btn,
.topbar .search-trigger {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  font-family: inherit;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.topbar .icon-btn:hover,
.topbar .search-trigger:hover {
  border-color: var(--gold);
  color: var(--gold-2);
  background: var(--panel);
}
.topbar .icon-btn:active,
.topbar .search-trigger:active { transform: scale(.95); }

.topbar .icon-btn svg,
.topbar .search-trigger svg {
  width: 18px; height: 18px;
  stroke: currentColor; stroke-width: 1.7;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}

[data-theme="light"] .topbar .icon-btn,
[data-theme="light"] .topbar .search-trigger {
  background: var(--panel);
  border-color: var(--border);
  color: var(--text);
}

.net-status {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74,222,128,.6);
  flex: 0 0 auto;
  transition: background .2s, box-shadow .2s;
}
.net-status.offline {
  background: #f87171;
  box-shadow: 0 0 8px rgba(248,113,113,.6);
}
.net-status.reconnecting {
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251,191,36,.6);
  animation: pulseDot 1.2s infinite;
}
@keyframes pulseDot {
  0%,100% { opacity: 1; }
  50%     { opacity: .35; }
}

/* ---------- main ---------- */
main {
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px;
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 60px);
}

/* ---------- Таббар ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(10, 15, 26, 0.96);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  z-index: 100;
}
[data-theme="light"] .tabbar {
  background: rgba(247, 248, 251, 0.96);
  border-top: 1px solid var(--border);
}
.tabbar a {
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10.5px; font-weight: 500;
  letter-spacing: .2px;
  transition: color .15s;
}
.tabbar a svg {
  width: 22px; height: 22px;
  stroke: currentColor; stroke-width: 1.6;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.tabbar a.active { color: var(--gold-2); }
.tabbar a.active svg { stroke: var(--gold-2); }
[data-theme="light"] .tabbar a.active { color: #374151; }
[data-theme="light"] .tabbar a.active svg { stroke: #374151; }
.tabbar a:hover { color: var(--text); }
.tabbar a .badge-dot {
  position: absolute;
  top: 6px; right: calc(50% - 14px);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--red-2);
  box-shadow: 0 0 0 2px var(--bg);
}
[data-theme="light"] .tabbar a .badge-dot {
  background: #4b5563;
  box-shadow: 0 0 0 2px var(--panel);
}

/* ---------- Логин ---------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 20px;
  background: radial-gradient(ellipse at top, var(--panel) 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 26px 26px;
}
.crest-img {
  width: 100px; height: 100px;
  display: block;
  margin: 0 auto 14px;
  object-fit: contain;
  filter: drop-shadow(0 6px 20px rgba(240,180,41,.25));
}
.crest {
  width: 88px; height: 88px;
  margin: 0 auto 14px;
  border-radius: 22px;
  background: radial-gradient(circle at 30% 30%, #f0b429, #b91c1c);
  display: grid; place-items: center;
  color: #fff; font-weight: 900; font-size: 26px;
  box-shadow: 0 8px 24px rgba(185,28,28,.4);
}
.login-card h1 {
  text-align: center;
  font-size: 17px;
  margin: 0 0 4px;
  color: var(--text);
  letter-spacing: .6px;
  font-weight: 700;
}
.login-card p.sub {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 24px;
  letter-spacing: .3px;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  outline: none;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, background .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--gold);
  background: var(--panel);
}
[data-theme="light"] .field input,
[data-theme="light"] .field select,
[data-theme="light"] .field textarea {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--border);
}

.btn {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  font-weight: 700;
  letter-spacing: .3px;
  font-size: 14px;
  font-family: inherit;
  transition: transform .1s, filter .15s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(180deg, var(--red-2), var(--red));
  color: #fff;
  box-shadow: 0 2px 8px rgba(185,28,28,.25);
}
.btn-primary:hover { filter: brightness(1.08); }
[data-theme="light"] .btn-primary {
  background: linear-gradient(180deg, #6b7280, #4b5563);
  color: #fff;
  box-shadow: 0 2px 8px rgba(75,85,99,.2);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  border-color: var(--gold);
  color: var(--gold-2);
}
.btn-block { width: 100%; display: block; }
.error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(185,28,28,.12);
  border: 1px solid rgba(220,38,38,.5);
  color: #ffb4b4;
  font-size: 13px;
  display: none;
}

/* ---------- Контейнер и секции ---------- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 4px 16px 0;
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 60px);
  /* Явно указываем width: 100% для корректного grid */
  width: 100%;
}
.section-title {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 22px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  width: 100%;
}
.section-title:first-child { margin-top: 4px; }
.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--border), transparent);
}
.section-title.collapsible { cursor: pointer; user-select: none; }
.section-title.collapsible:hover { color: var(--gold); }
.section-toggle {
  display: inline-block;
  width: 14px;
  transition: transform .2s ease;
  font-size: 12px;
}
.section-title.collapsed .section-toggle { transform: rotate(-90deg); }
.tiles.hidden { display: none; }

/* ---------- Плитки ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  width: 100%;
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 150px;
  padding: 18px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--tile-color, var(--panel-2)), #0e1526);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
  overflow: hidden;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 0%, rgba(240,180,41,.08), transparent 60%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.tile:hover::before { opacity: 1; }
.tile:hover {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
[data-theme="light"] .tile {
  background: var(--panel) !important;
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
[data-theme="light"] .tile:hover {
  border-color: var(--border-2);
  box-shadow: var(--shadow);
}
.tile .icon {
  width: 44px; height: 44px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: rgba(240,180,41,.12);
  border: 1px solid rgba(240,180,41,.35);
  color: var(--gold-2);
  font-size: 22px;
  position: relative;
  z-index: 1;
}
[data-theme="light"] .tile .icon {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--muted);
}
.tile .name {
  font-size: 15px;
  font-weight: 700;
  margin-top: 14px;
  color: var(--text);
  position: relative;
  z-index: 1;
}
.tile .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  position: relative;
  z-index: 1;
}
.tile .badge {
  position: absolute;
  top: 12px; right: 12px;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--red-2);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 0 0 2px var(--panel);
  z-index: 2;
}
[data-theme="light"] .tile .badge {
  background: #4b5563;
  box-shadow: 0 0 0 2px var(--panel);
}
.tile .badge.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--panel), 0 0 0 0 rgba(220,38,38,.7); }
  50%      { box-shadow: 0 0 0 2px var(--panel), 0 0 0 10px rgba(220,38,38,0); }
}
[data-theme="light"] .tile .badge.pulse { animation: none; }

.tile.tile-news {
  background: linear-gradient(160deg, #3a1212, #1a0b0b) !important;
  border-color: #7a1d1d;
}
.tile.tile-news .icon {
  background: rgba(240,180,41,.18);
  border-color: rgba(240,180,41,.5);
}
[data-theme="light"] .tile.tile-news {
  background: var(--panel) !important;
  border-color: var(--border);
}
[data-theme="light"] .tile.tile-news .icon {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--muted);
}

/* ---------- ЧАТ ---------- */
.chat-layout {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-height) + var(--safe-bottom));
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: 1fr auto auto;
  overflow: hidden;
  background: var(--bg);
  z-index: 50;
}
.chat-messages {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  min-height: 0;
}
.msg {
  max-width: 78%;
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  align-self: flex-start;
  position: relative;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
}
[data-theme="light"] .msg {
  background: var(--panel);
  border-color: var(--border);
  color: var(--text);
}
.msg.mine {
  background: linear-gradient(180deg, #2a1a3a, #1f1430);
  border-color: #4b2c73;
  align-self: flex-end;
}
[data-theme="light"] .msg.mine {
  background: var(--panel-2);
  border-color: var(--border-2);
  color: var(--text);
}
.msg .meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
}
.msg .meta .author {
  color: var(--gold-2);
  font-weight: 700;
  cursor: pointer;
}
[data-theme="light"] .msg .meta .author { color: #374151; }
.msg .meta .author:hover { text-decoration: underline; }
.msg .meta .author-org {
  color: var(--muted-2);
  font-size: 10.5px;
  margin-left: 4px;
  font-weight: 400;
}
.msg .body {
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg .attach { margin-top: 8px; }
.msg .attach img, .msg .attach video {
  max-width: 100%;
  border-radius: 10px;
  display: block;
}
.msg .attach audio { width: 100%; }
.msg .attach a.file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 10px;
  background: rgba(240,180,41,.1);
  border: 1px solid rgba(240,180,41,.35);
  color: var(--gold-2);
  font-size: 13px;
  word-break: break-all;
}
[data-theme="light"] .msg .attach a.file-link {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--muted);
}

.chat-input {
  position: relative;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  flex: 0 0 auto;
}
[data-theme="light"] .chat-input {
  background: var(--panel);
  border-top-color: var(--border);
}
.chat-input textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 13px;
  border-radius: 12px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  outline: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.35;
  transition: border-color .15s;
}
.chat-input textarea:focus { border-color: var(--gold); }
[data-theme="light"] .chat-input textarea {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--border);
}
.chat-input .icon-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex: 0 0 auto;
  transition: border-color .15s, color .15s;
}
.chat-input .icon-btn:hover {
  border-color: var(--gold);
  color: var(--gold-2);
}
[data-theme="light"] .chat-input .icon-btn {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--border);
}
.chat-input .send-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(180deg, var(--red-2), var(--red));
  color: #fff;
  border: none;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex: 0 0 auto;
  transition: filter .15s, transform .1s;
}
.chat-input .send-btn:hover { filter: brightness(1.08); }
.chat-input .send-btn:active { transform: scale(.96); }
[data-theme="light"] .chat-input .send-btn {
  background: linear-gradient(180deg, #6b7280, #4b5563);
}

#uploadBar {
  position: absolute;
  top: -4px;
  left: 10px; right: 10px;
  height: 3px;
  background: var(--bg-2);
  border-radius: 2px;
  overflow: hidden;
  display: none;
}
#uploadBarFill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), var(--red-2));
  transition: width .15s;
}

.file-chip {
  position: absolute;
  top: -34px;
  left: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 8px;
  background: rgba(240,180,41,.15);
  border: 1px solid rgba(240,180,41,.5);
  color: var(--gold-2);
  font-size: 12px;
  max-width: calc(100% - 20px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-chip .x {
  cursor: pointer;
  font-weight: 700;
  padding-left: 4px;
}

.day-divider {
  align-self: center;
  margin: 8px 0;
  padding: 3px 12px;
  background: rgba(143,160,190,.12);
  border: 1px solid rgba(143,160,190,.2);
  color: var(--muted);
  font-size: 11px;
  border-radius: 10px;
  letter-spacing: .3px;
}
[data-theme="light"] .day-divider {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--muted);
}

.reply-quote {
  display: flex;
  gap: 6px;
  margin: -2px -4px 8px;
  padding: 6px 10px;
  background: rgba(240,180,41,.08);
  border-left: 3px solid var(--gold);
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.reply-quote .r-author {
  color: var(--gold-2);
  font-weight: 700;
}
.reply-quote .r-text {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.msg.highlight { animation: msgHighlight 1.6s ease; }
@keyframes msgHighlight {
  0% { background: rgba(240,180,41,.35); }
  100% { background: var(--panel); }
}
.msg.mine.highlight { animation: msgHighlightMine 1.6s ease; }
@keyframes msgHighlightMine {
  0% { background: rgba(240,180,41,.35); }
  100% { background: linear-gradient(180deg, #2a1a3a, #1f1430); }
}

.msg.deleted .body,
.msg.deleted .attach { display: none; }
.msg.deleted .meta { opacity: .5; }
.msg.deleted .deleted-note {
  font-style: italic;
  color: var(--muted);
  font-size: 13px;
}

.msg-actions-bar {
  display: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(143,160,190,.25);
  gap: 6px;
  flex-wrap: wrap;
}
.msg.show-actions .msg-actions-bar { display: flex; }
.msg-actions-bar button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.msg-actions-bar button:hover {
  border-color: var(--gold);
  color: var(--gold-2);
  background: rgba(240,180,41,.08);
}
.msg-actions-bar button.danger:hover {
  border-color: var(--red-2);
  color: #ff9f9f;
  background: rgba(220,38,38,.10);
}
.msg-actions-bar button svg {
  width: 14px; height: 14px;
  stroke: currentColor; stroke-width: 1.8;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}

.reactions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 12px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background .12s, border-color .12s;
}
.reaction-chip:hover {
  background: rgba(240,180,41,.10);
  border-color: var(--gold);
}
.reaction-chip .count {
  font-size: 11.5px;
  color: var(--muted);
}
.reaction-chip.me {
  background: rgba(240,180,41,.15);
  border-color: rgba(240,180,41,.55);
}
.reaction-chip.me .count { color: var(--gold-2); }
.reaction-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  border-radius: 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  transition: border-color .12s, color .12s;
}
.reaction-add:hover {
  border-color: var(--gold);
  color: var(--gold-2);
}

.emoji-picker {
  position: fixed;
  z-index: 3001;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 300px;
  max-width: calc(100vw - 24px);
}
.emoji-picker button {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s;
}
.emoji-picker button:hover { background: rgba(240,180,41,.15); }

.typing-indicator {
  padding: 2px 16px 8px;
  color: var(--muted);
  font-size: 12px;
  min-height: 18px;
  font-style: italic;
}
.typing-indicator .dots::after {
  content: '...';
  display: inline-block;
  width: 0;
  overflow: hidden;
  animation: typingDots 1.4s steps(4,end) infinite;
}
@keyframes typingDots { to { width: 1.4em; } }

/* ---------- Документы ---------- */
.docs-wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 8px 16px 0;
}
.crumbs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.crumbs a { color: var(--gold-2); }
.docs-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.docs-actions .btn {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.docs-actions .btn:disabled { opacity: .6; cursor: not-allowed; }
.docs-actions .btn.spin .spin-icon {
  display: inline-block;
  animation: docsSpin .8s linear infinite;
}
@keyframes docsSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.docs-stats {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  margin-left: auto;
  white-space: nowrap;
}
.docs-stats .pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
  font-weight: 600;
}
.docs-stats .pill .num {
  color: var(--gold-2);
  font-weight: 800;
}
.docs-list { display: grid; gap: 8px; }
.docs-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.docs-item:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow-sm);
}
.docs-item .ic {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(240,180,41,.12);
  border: 1px solid rgba(240,180,41,.35);
  color: var(--gold-2);
  font-size: 18px;
  flex: 0 0 auto;
}
.docs-item .ic.folder {
  background: rgba(59,130,246,.14);
  border-color: rgba(59,130,246,.4);
  color: #93c5fd;
}
[data-theme="light"] .docs-item .ic,
[data-theme="light"] .docs-item .ic.folder {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--muted);
}
.docs-item .info { flex: 1; min-width: 0; }
.docs-item .info .name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}
.docs-item .info .meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.docs-item .dl,
.docs-item .btn-danger {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
  font-size: 12px;
  flex: 0 0 auto;
  transition: border-color .15s, color .15s;
}
.docs-item .dl:hover { border-color: var(--gold); color: var(--gold-2); }
.docs-item .btn-danger:hover { border-color: var(--red-2); color: #ff9f9f; }

.docs-item.has-new {
  border-color: rgba(220,38,38,.5);
  box-shadow: 0 0 0 1px rgba(220,38,38,.2) inset;
}
.docs-item .ic .new-dot {
  position: absolute;
  top: -3px; right: -3px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--red-2);
  box-shadow: 0 0 0 2px var(--panel);
}
.docs-item .ic.folder { position: relative; }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 30px;
  font-size: 14px;
}

/* ---------- Участники ---------- */
.members-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px 0;
}
.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.member-item:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow-sm);
}
.member-item .avatar {
  position: relative;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 30% 30%, #f0b429, #b91c1c);
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  flex: 0 0 auto;
}
[data-theme="light"] .member-item .avatar {
  background: linear-gradient(135deg, #9ca3af, #4b5563);
}
.member-item .avatar .online-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px var(--panel);
}
.member-item .info { flex: 1; min-width: 0; }
.member-item .info .name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.member-item .info .org {
  font-size: 12px;
  color: var(--gold-2);
  margin-top: 2px;
}
.member-item .info .meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.member-item .role {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(240,180,41,.15);
  color: var(--gold-2);
  border: 1px solid rgba(240,180,41,.35);
  flex: 0 0 auto;
}
.seen-online { color: #4ade80; }
.seen-day { color: #fbbf24; }
.seen-old { color: var(--muted); }

/* ---------- Модалки ---------- */
.profile-backdrop,
.perm-backdrop,
.org-backdrop,
.tg-backdrop,
.readers-backdrop,
.main-tile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  place-items: center;
  padding: 16px;
}
.org-backdrop,
.tg-backdrop,
.main-tile-backdrop {
  place-items: flex-start center;
  padding: 20px 16px;
  overflow-y: auto;
}
.profile-backdrop.open,
.perm-backdrop.open,
.org-backdrop.open,
.tg-backdrop.open,
.readers-backdrop.open,
.main-tile-backdrop.open { display: grid; }

.profile-card,
.readers-card,
.modal-box {
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px 20px;
}
.modal-box { max-width: 720px; padding: 22px 20px 18px; }
.modal-box.perm { max-width: 500px; }
.modal-box.access { max-width: 520px; }

.profile-card .avatar-big,
.readers-card .avatar-big {
  width: 72px; height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 30% 30%, #f0b429, #b91c1c);
  color: #fff;
  font-weight: 900;
  font-size: 28px;
  margin: 0 auto 12px;
}
.profile-card h2,
.readers-card h3 {
  text-align: center;
  margin: 0 0 4px;
  font-size: 18px;
  color: var(--text);
}
.profile-card .role-line {
  text-align: center;
  color: var(--gold-2);
  font-size: 13px;
  margin-bottom: 18px;
}
.profile-card .role-line .badge,
.modal-box .badge-self {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(240,180,41,.15);
  border: 1px solid rgba(240,180,41,.35);
  font-size: 11px;
  margin-left: 6px;
}
.profile-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  gap: 12px;
}
.profile-row:last-child { border-bottom: none; }
.profile-row .lbl {
  color: var(--muted);
  flex: 0 0 auto;
}
.profile-row .val {
  color: var(--text);
  text-align: right;
  word-break: break-word;
  flex: 1;
}
.profile-row .val a {
  color: var(--gold-2);
  text-decoration: none;
}
.profile-actions,
.readers-actions {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}
.profile-actions .btn,
.readers-actions .btn {
  width: auto;
  padding: 10px 22px;
}

/* ---------- Поиск ---------- */
.search-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2500;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  display: none;
  place-items: flex-start center;
  padding: 20px 16px;
  overflow-y: auto;
}
.search-backdrop.open { display: grid; }
.search-modal {
  width: 100%;
  max-width: 720px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow: hidden;
}
.search-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
}
.search-head input {
  flex: 1;
  padding: 11px 14px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.search-head .close-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
}
.search-filters {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--panel-2);
}
.search-filters select,
.search-filters input[type="date"] {
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
}
.search-results {
  overflow-y: auto;
  padding: 12px 16px 20px;
  flex: 1;
  min-height: 0;
}
.search-result {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  margin-bottom: 10px;
  cursor: pointer;
}
.search-result:hover { border-color: var(--gold); }
.search-result .sr-head {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.search-result .sr-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(240,180,41,.10);
  border: 1px solid rgba(240,180,41,.35);
  color: var(--gold-2);
  font-size: 11px;
}
.search-result .sr-author { color: var(--gold-2); font-weight: 600; }
.search-result .sr-date { margin-left: auto; }
.search-result .sr-text { font-size: 14px; line-height: 1.4; color: var(--text); }
.search-result .sr-text mark {
  background: rgba(240,180,41,.35);
  color: #fff;
  padding: 1px 3px;
  border-radius: 3px;
}
.search-empty { text-align: center; padding: 40px 20px; color: var(--muted); font-size: 14px; }
.search-totals {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Тосты ---------- */
.cmp-toast-stack {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(90px + var(--safe-bottom));
  z-index: 4000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: calc(100vw - 24px);
  max-width: 420px;
}
.cmp-toast {
  pointer-events: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  box-shadow: var(--shadow-lg);
  width: 100%;
  transform: translateY(20px);
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease;
  overflow: hidden;
  position: relative;
}
.cmp-toast.show { transform: translateY(0); opacity: 1; }
.cmp-toast-icon {
  width: 22px; height: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}
.cmp-toast-icon.success { background: #16a34a; }
.cmp-toast-icon.error   { background: #dc2626; }
.cmp-toast-icon.warn    { background: #f59e0b; }
.cmp-toast-icon.info    { background: #2563eb; }
.cmp-toast-body { flex: 1; word-break: break-word; line-height: 1.35; }
.cmp-toast-close {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px;
  flex: 0 0 auto;
}
.cmp-toast-close:hover { color: var(--text); }
.cmp-toast-progress {
  position: absolute;
  bottom: 0; left: 0;
  height: 2px;
  background: currentColor;
  opacity: .35;
  animation: cmp-toast-progress linear forwards;
}
@keyframes cmp-toast-progress {
  from { width: 100%; }
  to   { width: 0%; }
}

.cmp-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  display: none;
  place-items: center;
  padding: 20px;
}
.cmp-modal-backdrop.open { display: grid; }
.cmp-modal {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px 18px;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-family: inherit;
  animation: cmp-modal-in .2s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes cmp-modal-in {
  from { transform: scale(.95); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.cmp-modal h3 { margin: 0 0 10px; font-size: 17px; color: var(--gold-2); }
.cmp-modal .cmp-modal-text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 18px;
  white-space: pre-wrap;
  word-break: break-word;
}
.cmp-modal .cmp-modal-input {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  margin-bottom: 18px;
}
.cmp-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.cmp-modal-actions .cmp-btn {
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  border: none;
}
.cmp-modal-actions .cmp-btn-primary {
  background: linear-gradient(180deg, var(--red-2), var(--red));
  color: #fff;
}
.cmp-modal-actions .cmp-btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.cmp-modal-actions .cmp-btn-danger {
  background: linear-gradient(180deg, var(--red-2), var(--red));
  color: #fff;
}

/* ---------- Скелетоны ---------- */
.cmp-skel {
  background: linear-gradient(90deg, var(--panel-2) 0%, var(--panel) 40%, var(--panel-2) 80%);
  background-size: 200% 100%;
  animation: cmp-skel-shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}
@keyframes cmp-skel-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.cmp-skel-tile { height: 150px; border-radius: 14px; }
.cmp-skel-line { height: 12px; border-radius: 6px; }
.cmp-skel-line.short { width: 40%; }
.cmp-skel-line.medium { width: 70%; }
.cmp-skel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.cmp-skel-circle { width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto; }
.cmp-skel-msg {
  align-self: flex-start;
  width: 60%;
  padding: 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.cmp-skel-msg.right { align-self: flex-end; width: 45%; }

.section-title .section-badge {
  display: none;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--red-2);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  letter-spacing: 0;
  text-transform: none;
  margin-left: 6px;
}
.section-title .section-badge.show { display: inline-block; }
.section-title .section-badge.pulse { animation: sectionBadgePulse 1.6s infinite; }
@keyframes sectionBadgePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.55); }
  50%      { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
}

/* ---------- Таблицы: адаптивность ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.panel-card {
  overflow: hidden;
}

@media (max-width: 520px) {
  :root {
    --topbar-height: 54px;
    --tabbar-height: 60px;
  }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .tile { min-height: 130px; padding: 14px; }
  .tile .name { font-size: 14px; }
  .tile .icon { width: 40px; height: 40px; font-size: 20px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar .brand .title { font-size: 13px; }
  .topbar .brand .title small { font-size: 10px; }
  .topbar .brand .logo-wrap { width: 34px; height: 34px; padding: 2px; }
  .msg { max-width: 88%; }
  .container { padding: 4px 12px 0; }
  .login-card { padding: 26px 20px 20px; }
  .crest-img { width: 80px; height: 80px; }
  table { font-size: 12px; }
  th, td { padding: 8px 6px; }
  .panel-card { padding: 14px; }
}

/* ---------- Скроллбары ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--muted-2);
  background-clip: content-box;
  border: 2px solid transparent;
}

/* Универсальный запас для всех "wrap"-контейнеров */
.admin-wrap,
.docs-wrap,
.members-wrap {
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 60px) !important;
}
/* Убираем задержку 300мс на тач-устройствах */
button,
a,
.tile,
.docs-item,
.member-item,
.tab,
.tabbar a,
.icon-btn,
.mini-btn,
.send-btn,
.btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* Активное нажатие — мгновенно */
button:active,
a:active,
.tile:active,
.docs-item:active,
.member-item:active,
.icon-btn:active,
.mini-btn:active {
  transform: scale(0.97);
  transition: transform 0.05s;
}

/* Никаких анимаций при prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   УНИВЕРСАЛЬНЫЙ ВИЗУАЛЬНЫЙ ОТКЛИК
   ============================================================ */
button,
a,
.tile,
.docs-item,
.member-item,
.tab,
.tabbar a,
.icon-btn,
.mini-btn,
.send-btn,
.btn,
.search-trigger,
.reaction-chip,
.reaction-add,
.readers-line {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:active,
a:active,
.tile:active,
.docs-item:active,
.member-item:active,
.icon-btn:active,
.mini-btn:active,
.btn:active,
.send-btn:active {
  transform: scale(0.97) !important;
  transition: transform 0.05s !important;
  filter: brightness(1.15);
}

button.loading,
.btn.loading,
.mini-btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
button.loading::after,
.btn.loading::after,
.mini-btn.loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btnSpin .6s linear infinite;
}
@keyframes btnSpin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   ОПТИМИЗАЦИЯ ОТКЛИКА
   ============================================================ */
button,
a,
.tile,
.docs-item,
.member-item,
.tab,
.tabbar a,
.icon-btn,
.mini-btn,
.send-btn,
.btn,
.search-trigger {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button:active,
a:active,
.tile:active,
.docs-item:active,
.member-item:active,
.icon-btn:active,
.mini-btn:active,
.btn:active {
  transform: scale(0.97) !important;
  transition: transform 0.05s !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Protected pages remain invisible until /api/auth/me confirms the session. */
html.auth-pending body { visibility: hidden; }
html.auth-error body { visibility: visible; }
.auth-bootstrap-error {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #f3f4f6;
  background: #111827;
  text-align: center;
  font: 500 16px/1.5 system-ui, sans-serif;
}
