/* ============================================================
   CHATLY — дизайн-система платформы (стиль Twitch)
   ============================================================ */

:root {
  /* Цвета */
  --bg: #0e0e10;
  --bg-alt: #18181b;
  --surface: #1f1f23;
  --surface-hover: #26262c;
  --surface-active: #2d2d33;
  --border: #2f2f35;
  --border-strong: #3d3d44;
  --text: #efeff1;
  --text-alt: #dedee3;
  --muted: #adadb8;
  --muted-dim: #848494;

  --brand: #9147ff;
  --brand-hover: #772ce8;
  --brand-active: #5c16c5;
  --brand-soft: rgba(145, 71, 255, 0.16);
  --brand-glow: rgba(145, 71, 255, 0.35);

  --live: #eb0400;
  --success: #00b884;
  --warning: #ffb224;
  --danger: #e5484d;
  --info: #1f9cf0;

  /* Форма */
  --r-xs: 3px;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 16px;
  --r-full: 999px;

  /* Тени */
  --sh-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --sh-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --sh-lg: 0 12px 40px rgba(0, 0, 0, 0.55);

  --topbar-h: 56px;
  --font: 'Unbounded', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    Roboto, 'Helvetica Neue', Arial, sans-serif;

  /* Безопасные зоны (вырез камеры / жестовая зона iPhone) */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --mnav-h: 0px;
}

/* ---------- База ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
ul, ol { list-style: none; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

::selection { background: var(--brand); color: #fff; }

/* Скроллбары в стиле Twitch */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #56565e; background-clip: padding-box; }

/* ---------- Типографика ---------- */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.page-title { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.section-title { font-size: 18px; font-weight: 700; }
.eyebrow {
  font-size: 11px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--muted);
}
.muted { color: var(--muted); }
.dim { color: var(--muted-dim); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.mono {
  font-family: ui-monospace, 'SFMono-Regular', 'Cascadia Code', Consolas, monospace;
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Каркас ---------- */
.container { width: 100%; max-width: 1400px; margin: 0 auto; padding: 0 24px; }
.page { padding: 28px 0 56px; }

/* ---------- Верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px;
  background: rgba(14, 14, 16, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 19px; font-weight: 900; letter-spacing: 0.02em;
  color: var(--text);
  padding: 6px 10px; border-radius: var(--r-sm);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.brand:hover { background: var(--surface-hover); color: var(--brand); }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--brand), #5c16c5);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 900; color: #fff;
  box-shadow: 0 2px 10px var(--brand-glow);
}
.brand-name { font-weight: 900; letter-spacing: 0.04em; }

.topnav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 600; color: var(--text-alt);
  white-space: nowrap; transition: background 0.15s, color 0.15s;
}
.topnav a:hover { background: var(--surface-hover); color: var(--text); }
.topnav a.active { color: var(--brand); background: var(--brand-soft); }
.topnav .ic { font-size: 16px; line-height: 1; }

.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: var(--r-full);
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.user-chip:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.user-chip img, .user-chip .avatar-fallback {
  width: 28px; height: 28px; border-radius: 50%; background: var(--surface-active);
  object-fit: cover;
}
.user-chip .avatar-fallback { display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.user-chip .uname { font-weight: 700; font-size: 13px; max-width: 140px; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  background: var(--surface-hover);
  color: var(--text);
  border: none; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 700; letter-spacing: 0.01em;
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--surface-active); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-hover); box-shadow: 0 4px 16px var(--brand-glow); }

.btn--live { background: var(--live); color: #fff; }
.btn--live:hover { background: #c40400; box-shadow: 0 4px 16px rgba(235, 4, 0, 0.35); }

.btn--success { background: var(--success); color: #04231a; }
.btn--success:hover { background: #00a074; }

.btn--danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }

.btn--ghost { background: transparent; color: var(--text-alt); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn--sm { padding: 6px 11px; font-size: 12px; }
.btn--lg { padding: 12px 22px; font-size: 15px; }
.btn--block { width: 100%; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: transparent; border: none; border-radius: var(--r-sm);
  color: var(--muted); cursor: pointer; font-size: 16px;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ---------- Формы ---------- */
.field { display: block; margin-bottom: 14px; }
.field > label,
.label {
  display: block; margin-bottom: 7px;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.input, .select, .textarea,
input[type='text'], input[type='password'], input[type='email'],
input[type='number'], input[type='search'], select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input::placeholder, input::placeholder, textarea::placeholder { color: var(--muted-dim); }
.input:focus, .select:focus, .textarea:focus,
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  background: #100d16;
}
input[type='color'] {
  width: 72px; height: 38px; padding: 3px;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--r-sm); cursor: pointer;
}
input[type='file'] {
  width: 100%; padding: 9px 12px;
  background: var(--bg-alt); border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm); color: var(--muted); font-size: 13px; cursor: pointer;
}
input[type='file']::file-selector-button {
  margin-right: 12px; padding: 6px 12px;
  background: var(--surface-hover); color: var(--text);
  border: none; border-radius: var(--r-sm);
  font-weight: 700; font-size: 12px; cursor: pointer;
}
input[type='file']::file-selector-button:hover { background: var(--surface-active); }
.textarea { resize: vertical; min-height: 84px; font-family: inherit; }

/* ---------- Поверхности ---------- */
.panel {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}
.panel--flush { padding: 0; overflow: hidden; }
.panel__head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.panel__title { font-size: 15px; font-weight: 700; }
.panel__body { padding: 20px; }

/* ---------- Теги / бейджи ---------- */
.live-tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 7px;
  background: var(--live); color: #fff;
  border-radius: var(--r-xs);
  font-size: 11px; font-weight: 900;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.live-tag::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: #fff; animation: live-pulse 1.6s ease-in-out infinite;
}
.live-tag--off { background: var(--surface-active); color: var(--muted); }
.live-tag--off::before { animation: none; background: var(--muted-dim); }
@keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12px; font-weight: 700;
  color: var(--text-alt);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
a.chip:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--text); }
.chip--brand { background: var(--brand-soft); border-color: rgba(145, 71, 255, 0.4); color: #d4b8ff; }
.chip--ok { background: rgba(0, 184, 132, 0.14); border-color: rgba(0, 184, 132, 0.4); color: #6ee7c4; }
.chip--warn { background: rgba(255, 178, 36, 0.14); border-color: rgba(255, 178, 36, 0.4); color: #ffd591; }
.chip--danger { background: rgba(229, 72, 77, 0.14); border-color: rgba(229, 72, 77, 0.45); color: #ff9ea1; }

.avatar {
  border-radius: 50%; object-fit: cover;
  background: var(--surface-active);
  border: 2px solid transparent;
  flex-shrink: 0;
}

/* ---------- Табы ---------- */
.tabs {
  display: flex; gap: 4px;
  padding: 4px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.tabs button {
  flex: 1; padding: 9px 14px;
  background: transparent; border: none;
  border-radius: var(--r-sm);
  color: var(--muted); font-weight: 700; font-size: 13px;
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tabs button:hover { background: var(--surface-hover); color: var(--text); }
.tabs button.active { background: var(--brand); color: #fff; }

.seg {
  display: flex; gap: 2px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px;
}
.seg button {
  padding: 7px 14px; background: transparent; border: none;
  border-radius: var(--r-sm); color: var(--muted);
  font-weight: 700; font-size: 13px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button.active { background: var(--surface-hover); color: var(--text); }

/* ---------- Пустое состояние ---------- */
.empty-state {
  grid-column: 1 / -1;
  display: grid; place-items: center; gap: 10px;
  padding: 64px 24px; text-align: center;
}
.empty-state .ic { font-size: 52px; opacity: 0.5; }
.empty-state h3 { font-size: 20px; }
.empty-state p { color: var(--muted); max-width: 420px; }

/* ---------- Скелетон загрузки ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-alt) 25%, var(--surface) 37%, var(--bg-alt) 63%);
  background-size: 400% 100%;
  animation: skeleton-wave 1.4s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes skeleton-wave { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Уведомления ---------- */
.toasts {
  position: fixed; top: 16px; right: 16px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--brand);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  font-size: 13px; font-weight: 600;
  max-width: 340px;
  animation: toast-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.toast--error { border-left-color: var(--danger); }
.toast--success { border-left-color: var(--success); }
.toast--warn { border-left-color: var(--warning); }
.toast.is-out { opacity: 0; transform: translateX(20px); transition: all 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } }

/* ---------- Чат ---------- */
.chat {
  display: flex; flex-direction: column;
  min-height: 0; height: 100%;
  background: var(--bg-alt);
}
.chat__head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat__title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.chat__status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; color: var(--muted);
}
.chat__status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-dim); }
.chat__status.online .dot { background: var(--success); box-shadow: 0 0 8px rgba(0, 184, 132, 0.8); }
.chat__status.connecting .dot { background: var(--warning); animation: live-pulse 1s infinite; }
.chat__status.offline .dot { background: var(--danger); }

.chat__log {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex; flex-direction: column; gap: 2px;
  scroll-behavior: smooth;
}

.msg {
  position: relative;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-size: 14px; line-height: 1.45;
  word-wrap: break-word; overflow-wrap: anywhere;
  transition: background 0.12s;
}
.msg:hover { background: var(--surface-hover); }
.msg--own { background: rgba(145, 71, 255, 0.09); }
.msg--own:hover { background: rgba(145, 71, 255, 0.14); }
.msg--mention { background: rgba(255, 178, 36, 0.14); box-shadow: inset 3px 0 0 var(--warning); }
.msg--system {
  text-align: center; font-size: 12.5px; color: var(--muted);
  padding: 6px 10px; font-weight: 600;
}
.msg--system:hover { background: transparent; }

.msg__author {
  font-weight: 800; font-size: 13.5px;
  letter-spacing: 0.01em;
}
.msg__colon { font-weight: 800; color: var(--muted); margin-right: 3px; }
.msg__text { color: var(--text-alt); }
.msg__text a { color: var(--info); }
.msg__text a:hover { text-decoration: underline; }

.msg__badge {
  display: inline-flex; align-items: center;
  height: 15px; padding: 0 5px; margin-right: 5px;
  border-radius: var(--r-xs);
  font-size: 10px; font-weight: 900;
  letter-spacing: 0.05em; text-transform: uppercase;
  vertical-align: 2px; color: #fff;
}
.msg__badge--web { background: var(--brand); }
.msg__badge--discord { background: #5865f2; }
.msg__badge--telegram { background: #229ed9; }
.msg__badge--mod { background: var(--success); color: #04231a; }
.msg__badge--owner { background: var(--live); }
.msg__badge--system { background: var(--surface-active); color: var(--muted); }
.msg__img-badge { width: 17px; height: 17px; vertical-align: -3px; margin: 0 2px 0 4px; border-radius: 2px; }

.msg__quote {
  display: block;
  padding: 4px 8px; margin-bottom: 4px;
  background: rgba(145, 71, 255, 0.1);
  border-left: 2px solid var(--brand);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg__quote b { color: #d4b8ff; }

.msg__tools {
  position: absolute; top: 2px; right: 4px;
  display: none; gap: 2px;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 2px;
  box-shadow: var(--sh-md);
}
.msg:hover .msg__tools { display: flex; }
.msg__tools button {
  width: 24px; height: 22px; display: grid; place-items: center;
  background: transparent; border: none; border-radius: var(--r-xs);
  color: var(--muted); cursor: pointer; font-size: 12px;
}
.msg__tools button:hover { background: var(--surface-hover); color: var(--text); }
.msg__tools button.danger:hover { background: var(--danger); color: #fff; }

.msg__reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: 12px; cursor: pointer; user-select: none;
  transition: background 0.15s, border-color 0.15s;
}
.reaction:hover { background: var(--surface-hover); }
.reaction.own { background: var(--brand-soft); border-color: var(--brand); }

/* Ответ на сообщение */
.reply-bar {
  display: none; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12.5px; color: #d4b8ff;
  flex-shrink: 0;
}
.reply-bar.open { display: flex; }
.reply-bar .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar button {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: var(--r-xs);
}
.reply-bar button:hover { color: var(--text); background: var(--surface-hover); }

/* Поле ввода */
.chat__composer {
  position: relative;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
  flex-shrink: 0;
}
.chat__form {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 6px 6px 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat__form:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.chat__form textarea {
  flex: 1; min-width: 0;
  padding: 6px 2px;
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 14px; line-height: 1.4;
  resize: none; max-height: 120px; overflow-y: auto;
  font-family: inherit;
}
.chat__form textarea::placeholder { color: var(--muted-dim); }
.chat__form .send {
  width: 32px; height: 32px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--brand); color: #fff;
  border: none; border-radius: var(--r-sm); cursor: pointer;
  font-size: 15px; font-weight: 800;
  transition: background 0.15s;
}
.chat__form .send:hover { background: var(--brand-hover); }
.chat__emoji {
  width: 32px; height: 32px; flex-shrink: 0;
  display: grid; place-items: center;
  background: transparent; border: none; border-radius: var(--r-sm);
  color: var(--muted); cursor: pointer; font-size: 16px;
}
.chat__emoji:hover { background: var(--surface-hover); color: var(--text); }

.chat__hint { margin-top: 7px; font-size: 11.5px; color: var(--muted-dim); text-align: center; }

/* Гейт авторизации */
.chat__gate {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  text-align: center;
}
.chat__gate .ic {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
  font-size: 17px;
}
.chat__gate .t { font-weight: 700; font-size: 13.5px; }
.chat__gate .s { font-size: 12px; color: var(--muted); }
.chat__gate .actions { display: flex; gap: 8px; }

/* Автодополнение @упоминаний */
.autocomplete {
  position: absolute; left: 10px; right: 10px; bottom: calc(100% - 4px);
  max-height: 210px; overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  display: none; z-index: 20;
}
.autocomplete.open { display: block; }
.autocomplete button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 12px; background: transparent; border: none;
  color: var(--text); font-size: 13.5px; text-align: left; cursor: pointer;
}
.autocomplete button:hover, .autocomplete button.sel { background: var(--surface-hover); }

/* Эмодзи */
.emoji-picker {
  position: absolute; right: 10px; bottom: calc(100% - 4px);
  width: 320px; height: 300px;
  display: none; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  z-index: 25; overflow: hidden;
}
.emoji-picker.open { display: flex; }
.emoji-picker__cats {
  display: flex; gap: 2px; padding: 6px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.emoji-picker__cats button {
  width: 32px; height: 30px;
  background: transparent; border: none; border-radius: var(--r-sm);
  font-size: 16px; cursor: pointer;
}
.emoji-picker__cats button:hover { background: var(--surface-hover); }
.emoji-picker__cats button.active { background: var(--brand-soft); }
.emoji-picker__grid {
  flex: 1; overflow-y: auto; padding: 6px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.emoji-picker__grid button {
  height: 32px;
  background: transparent; border: none; border-radius: var(--r-sm);
  font-size: 19px; cursor: pointer;
}
.emoji-picker__grid button:hover { background: var(--surface-hover); }

/* Кнопка «вниз» */
.chat__down {
  position: absolute; right: 16px; bottom: 84px;
  width: 32px; height: 32px;
  display: none; place-items: center;
  background: var(--brand); color: #fff;
  border: none; border-radius: 50%;
  box-shadow: var(--sh-md); cursor: pointer; font-size: 14px; z-index: 5;
}
.chat__down.visible { display: grid; }

/* ---------- Сетка карточек ---------- */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px 16px;
}
.media-card {
  background: var(--bg-alt);
  border-radius: var(--r-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.media-card:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45); }
.media-card__thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  display: grid; place-items: center;
  overflow: hidden;
}
.media-card__thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-card__thumb .ph { font-size: 40px; color: var(--surface-active); }
.media-card__thumb > .live-tag { position: absolute; top: 8px; left: 8px; }
.media-card__thumb > .views {
  position: absolute; bottom: 8px; left: 8px;
  padding: 2px 7px; background: rgba(0, 0, 0, 0.72);
  border-radius: var(--r-sm);
  font-size: 11.5px; font-weight: 700;
}
.media-card__thumb > .dur {
  position: absolute; bottom: 8px; right: 8px;
  padding: 2px 6px; background: rgba(0, 0, 0, 0.72);
  border-radius: var(--r-sm);
  font-size: 11.5px; font-weight: 700;
}
.media-card__body { padding: 10px 12px 12px; display: flex; gap: 10px; }
.media-card__body img { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-active); }
.media-card__info { min-width: 0; flex: 1; }
.media-card__title {
  font-weight: 700; font-size: 14px; margin-bottom: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.35;
}
.media-card__meta {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 13px; color: var(--muted);
}
.media-card__meta .who { font-weight: 700; color: var(--text-alt); }
.media-card__meta .who:hover { color: var(--brand); }
.media-card__tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- Таблицы ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 10px 12px;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

/* ---------- Строка настройки ---------- */
.row-item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.row-item:last-child { border-bottom: none; }
.row-item .lbl { font-size: 13px; color: var(--muted); font-weight: 600; }
.row-item .val { font-size: 13.5px; display: flex; align-items: center; gap: 8px; min-width: 0; }

/* ---------- Код ---------- */
code.code {
  display: inline-block;
  padding: 5px 9px;
  background: #0b0b0d;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  font-size: 12.5px;
  color: #6ee7c4;
  word-break: break-all;
}

/* ============================================================
   Адаптив
   ============================================================ */

/* ---------- Мобильная нижняя навигация ---------- */
.mnav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 6px calc(6px + var(--safe-r)) calc(6px + var(--safe-b)) calc(6px + var(--safe-l));
  background: rgba(14, 14, 16, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.mnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 44px; padding: 4px 2px;
  border-radius: var(--r-sm);
  color: var(--muted); font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.01em;
}
.mnav a .ic { font-size: 19px; line-height: 1; }
.mnav a.active { color: var(--brand); }
.mnav a:active { background: var(--surface-hover); }

/* ---------- Тач-устройства: убираем hover-эффекты ---------- */
@media (hover: none) {
  .media-card:hover { transform: none; box-shadow: none; }
  .top-card:hover { transform: none; border-color: var(--border); }
  .user-chip:hover { background: var(--surface); border-color: var(--border); }
  /* Инструменты сообщения на тач-устройствах по наведению недоступны */
  .msg:hover .msg__tools { display: flex; }
}

/* ---------- Планшеты и крупные телефоны ---------- */
@media (max-width: 900px) {
  :root { --topbar-h: 52px; --mnav-h: 57px; }

  .container { padding: 0 16px; }
  .page { padding: 20px 0 32px; }
  .page-title { font-size: 22px; }
  .section-title { font-size: 16px; }
  .grid-cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 12px; }
  .user-chip .uname { display: none; }
  .topnav a span.lbl { display: none; }

  /* iOS зумит страницу, если у поля меньше 16px */
  .input, .select, .textarea,
  input[type='text'], input[type='password'], input[type='email'],
  input[type='number'], input[type='search'], select, textarea,
  .chat__form textarea {
    font-size: 16px;
  }

  /* Тач-таргеты не меньше 44px */
  .btn, .btn--sm, .btn--lg { min-height: 44px; padding-left: 14px; padding-right: 14px; }
  .btn--sm { font-size: 13px; }
  .icon-btn { width: 44px; height: 44px; font-size: 18px; }
  .chat__form .send, .chat__emoji { width: 40px; height: 40px; }
  .msg__tools button { width: 34px; height: 34px; font-size: 15px; }

  /* Верхняя панель */
  .topbar {
    padding: 0 calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
    gap: 4px;
  }
  .brand { padding: 6px 6px; font-size: 17px; }
  .brand-mark { width: 24px; height: 24px; }
  .topnav { gap: 0; }
  .topnav a { padding: 9px 11px; }

  /* Нижняя навигация + отступ под неё */
  .mnav { display: grid; }
  body.has-mnav { padding-bottom: calc(var(--mnav-h) + var(--safe-b)); }

  /* Уведомления на всю ширину */
  .toasts {
    top: calc(var(--topbar-h) + var(--safe-t) + 8px);
    left: 10px; right: 10px;
    align-items: stretch;
  }
  .toast { max-width: none; }

  /* Панели и пустые состояния */
  .panel { padding: 16px; }
  .panel--flush { padding: 0; }
  .panel__head { padding: 12px 16px; }
  .panel__body { padding: 16px; }
  .empty-state { padding: 40px 16px; }
  .empty-state .ic { font-size: 40px; }

  /* Строка настройки — в столбик */
  .row-item { flex-direction: column; align-items: flex-start; gap: 6px; }
  .row-item .val { width: 100%; }

  /* Широкая таблица скроллится по горизонтали */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll .table { min-width: 480px; }
  .table th, .table td { padding: 10px; }

  /* Эмодзи-пикер не шире экрана */
  .emoji-picker { width: min(320px, calc(100vw - 24px)); height: 260px; }
  .autocomplete { left: 6px; right: 6px; }
  .chat__down { right: 12px; bottom: 78px; }
}

/* ---------- Телефоны ---------- */
@media (max-width: 560px) {
  .hide-sm { display: none !important; }
  .container { padding: 0 12px; }
  .panel { padding: 14px; }
  .panel__body { padding: 14px; }

  .topbar .brand-name { display: none; }
  .topbar-right .btn { padding: 9px 11px; font-size: 12.5px; }

  .grid-cards { grid-template-columns: 1fr; gap: 12px; }
  .tabs button { padding: 10px 8px; font-size: 12.5px; }
  .seg { flex-wrap: wrap; }
  .seg button { flex: 1; padding: 9px 8px; }

  /* Скроллбары-полосы на тач-устройствах мешают, прячем у горизонтальных лент */
  .tabs, .seg, .chips, .side nav, .top-strip { scrollbar-width: none; }
  .tabs::-webkit-scrollbar, .seg::-webkit-scrollbar,
  .chips::-webkit-scrollbar { display: none; }

  .media-card__title { font-size: 14px; }
  .msg { padding: 7px 10px; }
  .msg__tools { position: static; display: flex; margin-top: 4px; background: transparent; border: none; padding: 0; box-shadow: none; }
}

/* ---------- Очень узкие экраны ---------- */
@media (max-width: 380px) {
  .container { padding: 0 10px; }
  .topnav a { padding: 9px 8px; }
  .grid-cards { gap: 10px; }
}

/* ---------- Ландшафтная ориентация телефона ---------- */
@media (max-height: 480px) and (orientation: landscape) and (max-width: 1000px) {
  .stage { aspect-ratio: auto; height: 56vh; }
  .chat-col { height: 70vh; }
}

/* ---------- Крупные экраны ---------- */
@media (min-width: 1600px) {
  :root { --topbar-h: 60px; }
  .container { max-width: 1560px; }
}