/* Корпоративный чат. Единая дизайн-система в духе Apple.
   Только системные шрифты, никаких CDN: работает в сети без интернета.
   Структура: 1) токены  2) база  3) элементы управления  4) общие компоненты
   5) вход  6) чат  7) админка  8) адаптив и движение */

/* ============ 1. Токены ============ */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, "Cascadia Mono", Consolas, monospace;

  /* Шкала текста: 12 / 13 / 15 / 17 / 21 / 28 / 40 */
  --fs-xs: 12px; --fs-s: 13px; --fs-m: 15px; --fs-l: 17px; --fs-xl: 21px; --fs-2xl: 28px; --fs-3xl: 40px;

  /* Поверхности */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --sidebar: #f5f5f7;
  --fill: rgba(118, 118, 128, .12);
  --fill-2: rgba(118, 118, 128, .07);
  --fill-hover: rgba(0, 0, 0, .04);
  --chrome: rgba(255, 255, 255, .72);

  /* Текст */
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --on-accent: #ffffff;

  /* Линии */
  --sep: rgba(0, 0, 0, .08);
  --sep-strong: rgba(0, 0, 0, .14);

  /* Акцент и статусы */
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-press: #006edb;
  --accent-soft: rgba(0, 113, 227, .10);
  --accent-ring: rgba(0, 113, 227, .20);
  --accent-text: #0066cc;
  --green: #34c759;  --green-text: #1d8a3a;  --green-soft: rgba(52, 199, 89, .14);
  --orange: #ff9f0a; --orange-text: #b25000; --orange-soft: rgba(255, 159, 10, .16);
  --red: #ff3b30;    --red-text: #d70015;    --red-soft: rgba(255, 59, 48, .10);
  --gray-soft: rgba(118, 118, 128, .12);

  /* Палитра аватаров (мягкие системные цвета) */
  /* приглушённые, белые инициалы читаются с контрастом не ниже 4.5:1 */
  --av-0: #5856d6; --av-1: #0071e3; --av-2: #127f94; --av-3: #248a3d;
  --av-4: #b25f00; --av-5: #d6336c; --av-6: #9a3fd1; --av-7: #8a6a45;

  /* Форма */
  --r-xs: 6px; --r-s: 8px; --r-field: 10px; --r-m: 12px; --r-l: 16px; --r-xl: 18px; --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(0, 0, 0, .04);
  --sh-2: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  --sh-pop: 0 2px 6px rgba(0, 0, 0, .06), 0 16px 40px rgba(0, 0, 0, .12);

  /* Движение */
  --ease: cubic-bezier(.25, .1, .25, 1);
  --t-fast: 150ms;
  --t: 200ms;
  --t-slow: 250ms;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --sidebar: #161618;
    --fill: rgba(118, 118, 128, .24);
    --fill-2: rgba(118, 118, 128, .14);
    --fill-hover: rgba(255, 255, 255, .05);
    --chrome: rgba(28, 28, 30, .72);
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #8e8e93;
    --sep: rgba(255, 255, 255, .10);
    --sep-strong: rgba(255, 255, 255, .16);
    --accent: #0a84ff;
    --accent-hover: #2491ff;
    --accent-press: #0077ed;
    --accent-soft: rgba(10, 132, 255, .18);
    --accent-ring: rgba(10, 132, 255, .32);
    --accent-text: #4aa3ff;
    --green: #30d158;  --green-text: #30d158;  --green-soft: rgba(48, 209, 88, .16);
    --orange: #ff9f0a; --orange-text: #ffb340; --orange-soft: rgba(255, 159, 10, .18);
    --red: #ff453a;    --red-text: #ff6961;    --red-soft: rgba(255, 69, 58, .16);
    --gray-soft: rgba(118, 118, 128, .24);
    --sh-1: 0 1px 2px rgba(0, 0, 0, .3);
    --sh-2: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --sh-pop: 0 2px 6px rgba(0, 0, 0, .4), 0 16px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ============ 2. База ============ */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 400 var(--fs-m)/1.47 var(--font);
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; font-weight: 600; color: var(--text); }
h1 { font-size: var(--fs-2xl); line-height: 1.14; letter-spacing: -.022em; }
h2 { font-size: var(--fs-xl); line-height: 1.24; letter-spacing: -.018em; }
h3 { font-size: var(--fs-l); line-height: 1.3; letter-spacing: -.014em; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code { font-family: var(--mono); font-size: .92em; letter-spacing: 0; }
.muted { color: var(--text-2); }
small, .hint { color: var(--text-2); font-size: var(--fs-s); font-weight: 400; }
.i { flex-shrink: 0; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring); }
::selection { background: var(--accent-ring); }

/* ============ 3. Элементы управления ============ */
.btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 16px;
  border: 0; border-radius: var(--r-pill);
  background: var(--fill); color: var(--text);
  font: 500 var(--fs-m)/1 var(--font); letter-spacing: -.01em; white-space: nowrap;
  cursor: pointer; text-decoration: none;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}
.btn:hover { background: var(--fill); filter: brightness(.97); text-decoration: none; }
.btn:active { filter: brightness(.93); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); filter: none; }
.btn-primary:active { background: var(--accent-press); filter: none; }
.btn-danger { background: var(--red-soft); color: var(--red-text); }
.btn-danger:hover { background: var(--red-soft); }
.btn-ghost { background: transparent; color: var(--accent-text); }
.btn-ghost:hover { background: var(--accent-soft); filter: none; }
.btn-small { min-height: 30px; padding: 0 12px; font-size: var(--fs-s); }
.btn-large { min-height: 44px; padding: 0 22px; font-size: var(--fs-l); }
.btn-block { width: 100%; }
.btn-link { background: none; min-height: 0; padding: 0; color: var(--accent-text); font-weight: 400; }
.btn-link:hover { background: none; filter: none; text-decoration: underline; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: default; filter: none; }

.icon-btn {
  -webkit-appearance: none; appearance: none;
  display: inline-grid; place-items: center; position: relative;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: var(--r-s);
  background: transparent; color: var(--text-2); cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--fill-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red-text); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: var(--fs-s); font-weight: 500; color: var(--text); }
.field-label small { margin-left: 4px; }
.input, .select, .textarea {
  -webkit-appearance: none; appearance: none;
  width: 100%; min-height: 40px; padding: 9px 12px;
  border: 1px solid transparent; border-radius: var(--r-field);
  background: var(--fill-2); color: var(--text);
  font: 400 var(--fs-m)/1.35 var(--font); letter-spacing: -.01em;
  transition: background-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.input-mono { font-family: var(--mono); letter-spacing: .06em; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover { background: var(--fill); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; background: var(--surface); border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}
.input[type="number"] { -moz-appearance: textfield; }
.input[type="number"]::-webkit-inner-spin-button, .input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.select {
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
.select-small { min-height: 30px; padding: 4px 30px 4px 10px; font-size: var(--fs-s); background-position: right 8px center; background-size: 14px; }

.search { position: relative; }
.search .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 36px; }
.search-wide .input { width: 300px; }

/* Сегментированный переключатель на радиокнопках */
.segmented {
  display: inline-flex; padding: 2px; gap: 2px; border-radius: 9px;
  background: var(--fill); min-height: 40px; align-items: stretch;
}
.segmented label { position: relative; display: flex; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 14px; border-radius: 7px; font-size: var(--fs-s); font-weight: 500; color: var(--text);
  cursor: pointer; white-space: nowrap; transition: background-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.segmented input:checked + span { background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 2px 6px rgba(0, 0, 0, .06); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-ring); }
@media (prefers-color-scheme: dark) { .segmented input:checked + span { background: #636366; } }

/* ============ 4. Общие компоненты ============ */
.card {
  background: var(--surface); border-radius: var(--r-l);
  box-shadow: var(--sh-1), 0 0 0 1px var(--sep);
}
.card-pad { padding: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.card-head p { margin-top: 2px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 500; line-height: 1; white-space: nowrap;
  background: var(--gray-soft); color: var(--text-2);
}
.pill .i { width: 12px; height: 12px; }
.pill-green { background: var(--green-soft); color: var(--green-text); }
.pill-orange { background: var(--orange-soft); color: var(--orange-text); }
.pill-red { background: var(--red-soft); color: var(--red-text); }
.pill-blue { background: var(--accent-soft); color: var(--accent-text); }
.pill-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--r-m); font-size: var(--fs-m); line-height: 1.4;
}
.alert .i { margin-top: 1px; }
.alert-err { background: var(--red-soft); color: var(--red-text); }
.alert-warn { background: var(--orange-soft); color: var(--orange-text); }
.alert-ok { background: var(--green-soft); color: var(--green-text); }
.alert-info { background: var(--fill-2); color: var(--text-2); }

.avatar {
  --size: 36px;
  position: relative; flex-shrink: 0; display: inline-grid; place-items: center;
  width: var(--size); height: var(--size); border-radius: 50%;
  color: #fff; font-size: calc(var(--size) * .38); font-weight: 600; letter-spacing: 0; line-height: 1;
  background: linear-gradient(180deg, rgba(255, 255, 255, .18), rgba(255, 255, 255, 0)) var(--av-7);
  user-select: none;
}
.avatar.tone-0 { background-color: var(--av-0); } .avatar.tone-1 { background-color: var(--av-1); }
.avatar.tone-2 { background-color: var(--av-2); } .avatar.tone-3 { background-color: var(--av-3); }
.avatar.tone-4 { background-color: var(--av-4); } .avatar.tone-5 { background-color: var(--av-5); }
.avatar.tone-6 { background-color: var(--av-6); } .avatar.tone-7 { background-color: var(--av-7); }
.avatar-s { --size: 24px; }
.avatar-m { --size: 32px; }
.avatar-l { --size: 40px; }
.avatar.is-online::after {
  content: ""; position: absolute; right: -1px; bottom: -1px;
  width: calc(var(--size) * .3); height: calc(var(--size) * .3); min-width: 8px; min-height: 8px;
  border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px var(--ring-bg, var(--surface));
}
.avatar-console { background: var(--fill); color: var(--text-2); }

.tile {
  --size: 32px;
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: var(--size); height: var(--size); border-radius: 9px;
  background: var(--fill-2); color: var(--text-2);
}
.tile .i { width: 18px; height: 18px; }
.tile-xl { --size: 64px; border-radius: 16px; background: var(--surface); box-shadow: var(--sh-2), 0 0 0 1px var(--sep); color: var(--accent); }
.tile-xl .i { width: 30px; height: 30px; }
.tile-warn { color: var(--orange); }

.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--r-pill); background: var(--accent); color: #fff;
  font-size: var(--fs-xs); font-weight: 600; line-height: 1;
}

.empty { display: grid; justify-items: center; gap: 8px; padding: 48px 24px; text-align: center; color: var(--text-2); }
.empty .tile { --size: 48px; border-radius: 14px; margin-bottom: 4px; }
.empty .tile .i { width: 24px; height: 24px; }
.empty h3 { font-size: var(--fs-l); }
.empty p { max-width: 340px; font-size: var(--fs-m); }

.logo {
  --size: 28px;
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: var(--size); height: var(--size); border-radius: calc(var(--size) * .26);
  background: linear-gradient(180deg, #3b9bff 0%, #0071e3 100%); color: #fff;
  box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .1), 0 1px 2px rgba(0, 113, 227, .25);
}
.logo svg { width: 62%; height: 62%; }
.logo-xl { --size: 64px; box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .1), 0 8px 24px rgba(0, 113, 227, .28); }

/* ============ 5. Вход, регистрация, смена пароля, ошибки ============ */
.auth-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 48px 16px; }
.auth { width: 100%; max-width: 400px; }
.auth-brand { display: grid; justify-items: center; gap: 16px; text-align: center; margin-bottom: 32px; }
.auth-brand h1 { font-size: var(--fs-2xl); }
.auth-brand p { color: var(--text-2); font-size: var(--fs-l); margin-top: -8px; }
.auth-card { padding: 32px; border-radius: var(--r-xl); background: var(--surface); box-shadow: var(--sh-2), 0 0 0 1px var(--sep); }
.auth-card .form { gap: 16px; }
.auth-card .btn-primary { margin-top: 8px; }
.auth-foot { margin-top: 24px; text-align: center; color: var(--text-2); font-size: var(--fs-m); }
.auth-foot form { display: inline; }
.secret-box {
  display: flex; align-items: center; justify-content: center; padding: 20px;
  border-radius: var(--r-m); background: var(--fill-2);
  font: 600 var(--fs-xl)/1 var(--mono); letter-spacing: .04em; user-select: all;
}
.form { display: flex; flex-direction: column; gap: 16px; }
.auth-inline { margin: 24px auto 0; }

/* ============ 6. Чат ============ */
.chat-page { height: 100vh; height: 100dvh; overflow: hidden; }
.chat { display: flex; height: 100vh; height: 100dvh; }

/* --- боковая панель --- */
.sidebar {
  --ring-bg: var(--sidebar);
  width: 288px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--sidebar); border-right: 1px solid var(--sep);
}
.sidebar-head { display: flex; align-items: center; gap: 10px; height: 64px; padding: 0 12px 0 20px; flex-shrink: 0; }
.workspace { flex: 1; min-width: 0; }
.workspace-name { font-size: var(--fs-l); font-weight: 600; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-sub { font-size: var(--fs-xs); color: var(--text-2); }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 4px 12px 16px; }
.side-section + .side-section { margin-top: 20px; }
.side-title {
  display: flex; align-items: center; justify-content: space-between;
  height: 28px; padding: 0 4px 0 8px; margin: 0 0 2px;
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0; color: var(--text-2);
}
.side-title .icon-btn { width: 24px; height: 24px; border-radius: var(--r-xs); }
.side-title .icon-btn .i { width: 16px; height: 16px; }
.side-title .count { font-weight: 500; color: var(--text-2); padding-right: 4px; }
.room-list, .online-list, .messages, .plain-list, .people-results { list-style: none; margin: 0; padding: 0; }
.room-btn {
  -webkit-appearance: none; appearance: none;
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 4px 8px;
  border: 0; border-radius: var(--r-s); background: none; color: var(--text);
  font: 400 var(--fs-m)/1.25 var(--font); letter-spacing: -.01em; text-align: left; cursor: pointer;
  transition: background-color var(--t-fast) var(--ease);
}
.room-btn:hover { background: var(--fill-hover); }
.room-btn .room-ico { width: 24px; height: 24px; display: grid; place-items: center; color: var(--text-3); flex-shrink: 0; }
.room-btn .room-ico .i { width: 17px; height: 17px; }
.room-btn .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-btn.unread .name { font-weight: 600; }
.room-btn.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.room-btn.active .room-ico { color: var(--accent-text); }
.room-btn.archived { opacity: .5; }
.online-list .room-btn { cursor: pointer; }
.online-list .you { color: var(--text-2); font-weight: 400; }

.side-form { display: flex; gap: 6px; padding: 6px 0 8px; }
.side-form .input { min-height: 34px; padding: 6px 10px; font-size: var(--fs-s); background: var(--surface); box-shadow: 0 0 0 1px var(--sep); }
.side-form .input:focus { box-shadow: 0 0 0 4px var(--accent-ring); }
.side-form .btn { min-height: 34px; }
.side-form-hint { padding: 0 2px 6px; font-size: var(--fs-xs); color: var(--text-2); }
.people-results { margin-bottom: 6px; }
.people-results .empty-note { padding: 6px 8px; font-size: var(--fs-s); color: var(--text-2); }

.sidebar-foot {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding: 12px 12px 12px 16px; border-top: 1px solid var(--sep);
}
.me-card { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.me-text { min-width: 0; }
.me-name { font-size: var(--fs-s); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.conn.ok::before { background: var(--green); }
.conn.bad::before { background: var(--orange); }
.foot-actions { display: flex; gap: 2px; }
.foot-actions form { display: contents; }

/* --- комната --- */
.room { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface); position: relative; }
.room-head {
  position: relative; z-index: 2; flex-shrink: 0;
  display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 24px;
  background: var(--chrome); border-bottom: 1px solid var(--sep);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
}
.room-head .tile, .room-head .avatar { --size: 36px; }
.room-head-text { min-width: 0; flex: 1; }
.room-head h1 { font-size: var(--fs-l); line-height: 1.25; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-kind { display: block; font-size: var(--fs-xs); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-btn { margin-left: -8px; width: auto; min-width: 36px; height: 36px; padding: 0 4px; gap: 2px; color: var(--accent-text); display: none; }
.back-btn:hover { background: var(--accent-soft); color: var(--accent-text); }
.back-btn .i { width: 24px; height: 24px; }

.feed { flex: 1; display: flex; flex-direction: column; overflow-y: auto; padding: 16px 0 8px; overscroll-behavior: contain; }
.feed > .messages { margin-top: auto; } /* короткая переписка прижата к полю ввода, как в «Сообщениях» */
.load-more { display: flex; flex-shrink: 0; margin: 0 auto 16px; }
.messages { padding: 0 0 4px; }

.day-sep {
  display: flex; align-items: center; gap: 12px; padding: 16px 24px 8px;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-2);
}
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--sep); }

.msg {
  position: relative; display: grid; grid-template-columns: 36px 1fr; column-gap: 12px;
  padding: 6px 24px; transition: background-color var(--t-fast) var(--ease);
}
@media (hover: hover) { .msg:hover { background: var(--fill-hover); } }
.msg:focus-within { background: var(--fill-hover); }
.msg.cont { padding-top: 1px; padding-bottom: 1px; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg.cont .msg-head { display: none; }
.msg-gutter { grid-row: 1 / span 2; padding-top: 2px; }
.msg-gutter .stamp {
  display: block; width: 36px; text-align: right; padding-top: 3px;
  font-size: 11px; color: var(--text-3); opacity: 0; transition: opacity var(--t-fast) var(--ease);
}
@media (hover: hover) { .msg.cont:hover .stamp { opacity: 1; } }
.msg.cont:focus-within .stamp, .msg.cont.show-actions .stamp { opacity: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.msg-author { font-size: var(--fs-m); font-weight: 600; letter-spacing: -.012em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-author.remote { color: var(--av-6); }
.msg-time { font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; }
.msg-body { font-size: var(--fs-m); line-height: 1.47; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; color: var(--text); }
.msg-edited { font-size: var(--fs-xs); color: var(--text-2); margin-left: 4px; }
.msg-deleted .msg-body { color: var(--text-3); font-style: italic; }
.msg-actions {
  position: absolute; top: -14px; right: 20px; display: flex; gap: 2px; padding: 2px;
  background: var(--surface); border-radius: 10px; box-shadow: var(--sh-2), 0 0 0 1px var(--sep);
  opacity: 0; pointer-events: none; transform: translateY(2px);
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
@media (hover: hover) { .msg:hover .msg-actions { opacity: 1; pointer-events: auto; transform: none; } }
.msg:focus-within .msg-actions { opacity: 1; pointer-events: auto; transform: none; }
.msg-actions .icon-btn { width: 30px; height: 28px; }
.msg-actions .icon-btn .i { width: 16px; height: 16px; }
.msg-edit { display: grid; gap: 8px; margin-top: 4px; }
.msg-edit .textarea { min-height: 64px; resize: vertical; }
.msg-edit-actions { display: flex; gap: 8px; align-items: center; }
.msg-edit-actions .hint { margin-left: auto; font-size: var(--fs-xs); }

.feed-empty { flex: 1; display: grid; place-items: center; }

.typing { display: flex; align-items: center; gap: 6px; min-height: 22px; padding: 0 24px; font-size: var(--fs-xs); color: var(--text-2); }
.typing.error { color: var(--red-text); }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .4; animation: blink 1.2s infinite var(--ease); }
.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.summary {
  position: relative; margin: 0 24px 8px; padding: 14px 44px 14px 16px;
  border-radius: var(--r-m); background: var(--accent-soft);
}
.summary-head { display: flex; align-items: center; gap: 6px; font-size: var(--fs-s); font-weight: 600; color: var(--accent-text); margin-bottom: 4px; }
.summary-head .i { width: 16px; height: 16px; }
.summary-head span { font-weight: 400; color: var(--text-2); }
.summary-text { font-size: var(--fs-m); white-space: pre-wrap; }
.summary .icon-btn { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; }

.composer { padding: 4px 24px 20px; flex-shrink: 0; }
.composer-box {
  display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 16px;
  border-radius: 22px; background: var(--surface-2); box-shadow: 0 0 0 1px var(--sep-strong);
  transition: box-shadow var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.composer-box:focus-within { background: var(--surface); box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-ring); }
.composer textarea {
  flex: 1; min-height: 32px; max-height: 160px; padding: 6px 0; resize: none;
  border: 0; background: transparent; color: var(--text); outline: none; box-shadow: none;
  font: 400 var(--fs-m)/1.35 var(--font); letter-spacing: -.01em;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer textarea:focus-visible { box-shadow: none; }
.send-btn {
  -webkit-appearance: none; appearance: none;
  display: grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0;
  border: 0; border-radius: 50%; background: var(--accent); color: #fff; cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.send-btn .i { width: 18px; height: 18px; stroke-width: 2.2; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { background: var(--fill); color: var(--text-3); cursor: default; transform: none; }
.composer-hint { display: flex; gap: 16px; padding: 8px 16px 0; font-size: var(--fs-xs); color: var(--text-2); }
.composer-hint kbd { font: inherit; font-weight: 600; color: var(--text); }

/* Диалог подтверждения */
.dialog {
  width: min(360px, calc(100vw - 32px)); padding: 24px; border: 0; border-radius: var(--r-xl);
  background: var(--surface); color: var(--text); box-shadow: var(--sh-pop); text-align: center;
}
.dialog::backdrop { background: rgba(0, 0, 0, .28); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.dialog h2 { font-size: var(--fs-l); margin-bottom: 6px; }
.dialog p { color: var(--text-2); font-size: var(--fs-s); }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 20px; }
.dialog[open] { animation: pop var(--t) var(--ease); }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

/* ============ 7. Админка ============ */
.admin-page { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--chrome); border-bottom: 1px solid var(--sep);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
}
.topbar-inner { max-width: 1120px; margin: 0 auto; height: 56px; padding: 0 24px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: var(--fs-l); font-weight: 600; letter-spacing: -.02em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .muted { font-weight: 400; }
.tabs { display: flex; gap: 2px; flex: 1; min-width: 0; }
.tabs a {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--r-pill);
  color: var(--text-2); font-size: var(--fs-s); font-weight: 500; white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.tabs a .i { width: 16px; height: 16px; }
.tabs a:hover { color: var(--text); background: var(--fill-2); text-decoration: none; }
.tabs a.active { color: var(--text); background: var(--fill); }
.topbar .btn { flex-shrink: 0; }
.ai-pill { flex-shrink: 0; cursor: help; }

.admin-main { max-width: 1120px; margin: 0 auto; padding: 40px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-head p { margin-top: 6px; color: var(--text-2); font-size: var(--fs-l); }
.page-head-side { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.eyebrow { display: inline-flex; margin-bottom: 8px; }
.stack > * + * { margin-top: 24px; }
.admin-main > .alert { margin-bottom: 24px; }
.section-title { font-size: var(--fs-xl); margin: 40px 0 16px; }

/* Форма в карточке: поля тянутся, переключатели и кнопка по содержимому, перенос на узких экранах */
.form-grid { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.form-grid > .field { flex: 1 1 200px; }
.form-grid > .field-fit { flex: 0 0 auto; }
.form-grid .form-submit { display: flex; flex: 0 0 auto; }
.form-grid .form-submit .btn { min-height: 40px; }
.form-hint { margin-top: 12px; }
.form-row { display: flex; gap: 8px; align-items: center; }

.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-m); }
.table th {
  text-align: left; padding: 12px 16px; white-space: nowrap;
  font-size: var(--fs-xs); font-weight: 500; color: var(--text-2); border-bottom: 1px solid var(--sep);
}
.table td { padding: 12px 16px; vertical-align: middle; border-bottom: 1px solid var(--sep); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--t-fast) var(--ease); }
.table tbody tr:hover { background: var(--fill-hover); }
.table th:first-child, .table td:first-child { padding-left: 24px; }
.table th:last-child, .table td:last-child { padding-right: 24px; }
.table .num { color: var(--text-3); width: 1%; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }
.table .right { text-align: right; }
.table .empty-row td { padding: 0; }
.table .muted-cell { color: var(--text-2); }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; }
.actions form { display: contents; }
.actions-start { justify-content: flex-start; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who-text { min-width: 0; line-height: 1.3; }
.who-name { font-weight: 500; white-space: nowrap; }
.who-sub { font-size: var(--fs-s); color: var(--text-2); white-space: nowrap; }
.code-chip {
  display: inline-flex; align-items: center; height: 28px; padding: 0 10px; border-radius: var(--r-s);
  background: var(--fill-2); font: 500 var(--fs-s)/1 var(--mono); letter-spacing: .06em; user-select: all; white-space: nowrap;
}
.code-cell { display: flex; align-items: center; gap: 4px; }
.copy-btn.copied { color: var(--green-text); }
.err-cell { color: var(--red-text); font-size: var(--fs-s); max-width: 280px; }
.role-form { display: flex; align-items: center; gap: 6px; }
.role-form .select { width: auto; }
.js .js-hide { display: none; }
.meter { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.meter-bar { width: 48px; height: 4px; border-radius: 2px; background: var(--fill); overflow: hidden; }
.meter-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.dot-tone { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--text-3); }
.dot-tone.blue { background: var(--accent); } .dot-tone.green { background: var(--green); }
.dot-tone.orange { background: var(--orange); } .dot-tone.red { background: var(--red); }
.action-cell { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-weight: 500; }
.note { display: flex; gap: 12px; align-items: flex-start; padding: 16px 20px; border-radius: var(--r-m); background: var(--fill-2); color: var(--text-2); font-size: var(--fs-s); }
.note .i { color: var(--text-3); margin-top: 1px; }
.note code { color: var(--text); }
.members-head { padding-bottom: 16px; border-bottom: 1px solid var(--sep); }
.members-head .card-head { margin-bottom: 12px; }
.grow { flex: 1; min-width: 0; }
.member-list li { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--sep); }
.member-list li:last-child { border-bottom: 0; }
.member-list .who { flex: 1; }
.back-link { display: inline-flex; align-items: center; gap: 2px; margin-bottom: 16px; font-size: var(--fs-m); }
.back-link .i { width: 18px; height: 18px; margin-left: -4px; }
.kv { display: flex; gap: 24px; flex-wrap: wrap; margin: 0; }
.kv div { min-width: 140px; }
.kv dt { font-size: var(--fs-xs); color: var(--text-2); }
.kv dd { margin: 2px 0 0; font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.02em; }

/* ============ 8. Адаптив и движение ============ */
.only-mobile { display: none !important; }

@media (max-width: 760px) {
  .only-mobile { display: inline-grid !important; }
  .back-btn.only-mobile { display: inline-flex !important; }
  .sidebar {
    position: fixed; inset: 0; z-index: 20; width: 100%; border-right: 0;
    transform: translateX(-100%); visibility: hidden;
    transition: transform var(--t-slow) var(--ease), visibility 0s linear var(--t-slow);
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: none; visibility: visible; transition: transform var(--t-slow) var(--ease); }
  .sidebar-head { height: 56px; padding-left: 16px; }
  .room-btn { min-height: 44px; font-size: var(--fs-l); }
  .room-btn .room-ico { width: 28px; height: 28px; }
  .sidebar .avatar-s { --size: 28px; }
  .side-title { height: 32px; font-size: var(--fs-s); }
  .side-title .icon-btn { width: 36px; height: 36px; }
  .side-form .input, .side-form .btn { min-height: 40px; font-size: var(--fs-m); }
  .sidebar-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .foot-actions .icon-btn { width: 40px; height: 40px; }
  .room-head { height: 56px; padding: 0 12px 0 8px; gap: 8px; }
  .room-head .tile, .room-head .avatar { --size: 32px; }
  .msg { padding: 6px 16px; column-gap: 10px; grid-template-columns: 32px 1fr; }
  .msg .avatar { --size: 32px; }
  .msg-gutter .stamp { width: 32px; }
  .msg-actions { opacity: 1; pointer-events: auto; transform: none; position: static; grid-column: 2; justify-self: start; margin-top: 4px; box-shadow: none; background: none; padding: 0; display: none; }
  .msg.show-actions .msg-actions { display: flex; }
  .msg-actions .icon-btn { width: 40px; height: 36px; background: var(--fill-2); }
  .day-sep { padding: 12px 16px 6px; }
  .typing { padding: 0 16px; }
  .summary { margin: 0 12px 8px; }
  .composer { padding: 4px 12px calc(12px + env(safe-area-inset-bottom)); }
  .composer-box { padding-left: 14px; }
  .composer textarea { font-size: 16px; } /* без зума в iOS */
  .send-btn { width: 34px; height: 34px; }
  .composer-hint { display: none; }

  .topbar-inner { height: auto; flex-wrap: wrap; gap: 0 12px; padding: 10px 16px 0; }
  .brand { flex: 1; min-width: 0; height: 36px; }
  .brand > span { overflow: hidden; text-overflow: ellipsis; }
  .brand .muted { display: none; }
  .to-chat span { display: none; }
  .to-chat { width: 36px; padding: 0; }
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; padding: 8px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { height: 36px; }
  .admin-main { padding: 24px 16px 64px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 16px; }
  .page-head h1 { font-size: var(--fs-2xl); }
  .page-head p { font-size: var(--fs-m); }
  .page-head-side { flex-wrap: wrap; }
  .page-head-side > * { flex: 1; }
  .search-wide .input { width: 100%; }
  .card-pad { padding: 20px; }
  .table th:first-child, .table td:first-child { padding-left: 16px; }
  .table th:last-child, .table td:last-child { padding-right: 16px; }
  .input, .select { min-height: 44px; font-size: 16px; }
  .btn { min-height: 40px; }
  .btn-small { min-height: 36px; }
  .segmented { min-height: 44px; }
  .auth-card { padding: 24px 20px; }
  .auth-brand { margin-bottom: 24px; }
  .member-list li { padding: 12px 16px; }

  /* Таблицы на телефоне превращаются в список карточек-строк */
  .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 16px; border-bottom: 1px solid var(--sep); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack td, .table-stack td:first-child, .table-stack td:last-child { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 32px; padding: 4px 0; border: 0; text-align: right; }
  .table-stack td[data-label]::before { content: attr(data-label); color: var(--text-2); font-size: var(--fs-s); text-align: left; flex-shrink: 0; }
  .table-stack td.cell-main { padding-bottom: 8px; text-align: left; }
  .table-stack td.cell-actions { padding-top: 8px; justify-content: flex-start; }
  .table-stack td.cell-actions.is-empty { display: none; }
  .form-grid > .field, .form-grid > .field-fit, .form-grid .form-submit { flex: 1 1 100%; }
  .form-grid .form-submit .btn { width: 100%; min-height: 44px; }
  .form-grid .segmented { display: flex; }
  .form-grid .segmented label { flex: 1; }
  .form-grid .segmented span { flex: 1; }
  .table-stack td.cell-actions .actions { justify-content: flex-start; flex-wrap: wrap; }
  .table-stack .empty-row td { display: block; padding: 0; }
  .table-stack tbody tr:hover { background: none; }
  .table-stack .actions-start { justify-content: flex-end; flex-wrap: wrap; }
  .table-stack .who-name, .table-stack .who-sub { white-space: normal; }
}

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