:root {
  --bg: #0e1116;
  --bg-soft: #151a22;
  --bg-elev: #1b212b;
  --line: #262e3a;
  --text: #e8edf5;
  --text-dim: #8b96a8;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.16);
  --danger: #ff6b6b;
  --ok: #2fbf8f;
  --radius: 14px;
  --radius-sm: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, "Inter", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(900px 500px at 15% -10%, rgba(79, 140, 255, 0.13), transparent 60%),
    radial-gradient(700px 420px at 110% 10%, rgba(168, 121, 255, 0.10), transparent 55%);
  background-attachment: fixed;
}

[hidden] { display: none !important; }

button { font: inherit; cursor: pointer; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.2px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), 0 0 18px rgba(79, 140, 255, 0.6);
  flex: none;
}

/* ---------------- Вход ---------------- */

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

.auth-sub {
  color: var(--text-dim);
  margin: 8px 0 22px;
  font-size: 0.92rem;
}

.app-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 0.85rem;
  text-decoration: none;
}

.app-download:hover,
.app-download:focus-visible {
  color: var(--accent);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 10px;
  border-radius: 8px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.tab.is-active {
  background: var(--accent-soft);
  color: var(--text);
}

.auth-form { display: grid; gap: 14px; }

.auth-form label { display: grid; gap: 6px; }

.auth-form label span {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.auth-form input {
  width: 100%;
  padding: 12px 13px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-error {
  margin: 0;
  min-height: 1.2em;
  color: var(--danger);
  font-size: 0.86rem;
}

.btn-primary {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  background: linear-gradient(180deg, #5a95ff, #3f7ae6);
  color: #fff;
  font-weight: 650;
  transition: filter 0.15s, transform 0.05s;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }

/* ---------------- Чат ---------------- */

.chat {
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  position: relative;
  overflow: hidden;
}

.chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-width: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(14, 17, 22, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.chat-title { display: flex; align-items: center; gap: 10px; }
.chat-title strong { display: block; font-size: 1rem; }

.chat-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.header-actions { display: flex; align-items: center; gap: 6px; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 0.82rem;
  transition: color 0.15s, border-color 0.15s;
}

.btn-ghost:hover { color: var(--text); border-color: #37404f; }

.dot-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

/* ---------------- Боковая панель ---------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100dvh;
  min-height: 0;
  padding: 14px 12px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 6px;
}

.brand-text { display: grid; gap: 1px; }
.brand-text strong { font-size: 0.98rem; }
.brand-text .chat-sub { font-size: 0.72rem; }

.sidebar-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 0;
  font-size: 0.69rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.contacts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
  align-content: start;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #2b3441 transparent;
}

.conv {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
  transition: background 0.14s, border-color 0.14s;
}

.conv:hover { background: rgba(255, 255, 255, 0.04); }
.conv.is-active { background: var(--accent-soft); border-color: #2a4373; }

.conv-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #0b0f14;
  flex: none;
}

.conv-avatar-general {
  background: linear-gradient(180deg, #5a95ff, #3f7ae6);
  color: #fff;
  font-size: 1rem;
}

.conv-body { display: grid; gap: 2px; flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: baseline; gap: 8px; }

.conv-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-time { font-size: 0.68rem; color: var(--text-dim); flex: none; }

.conv-last {
  font-size: 0.76rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.presence {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--bg-soft);
}

.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex: none;
}

.sidebar-foot {
  display: flex;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.sidebar-foot .btn-ghost { flex: 1; justify-content: center; }

.empty {
  margin: 4px 8px;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-dim);
}

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 15; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.chat-avatar { width: 34px; height: 34px; font-size: 0.78rem; }

.burger,
.only-mobile { display: none; }

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #0b0f14;
  flex: none;
}

.messages {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px clamp(10px, 4vw, 22px) 8px;
  scrollbar-color: #2b3441 transparent;
  scrollbar-width: thin;
}

.messages-list { display: flex; flex-direction: column; gap: 12px; max-width: 900px; margin: 0 auto; }

.load-older {
  display: block;
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.day-sep {
  align-self: center;
  font-size: 0.74rem;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 3px 11px;
  border-radius: 999px;
  margin: 6px 0;
}

.msg { display: flex; gap: 9px; max-width: 100%; animation: pop 0.16s ease-out; }
.msg.mine { flex-direction: row-reverse; }

@keyframes pop {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.msg-body {
  min-width: 0;
  max-width: min(76ch, 82%);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
  display: flex;
  gap: 7px;
  align-items: baseline;
  padding: 0 4px;
}

.msg.mine .msg-meta { justify-content: flex-end; }

.msg-author { font-weight: 650; }

.bubble {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-top-left-radius: 5px;
  padding: 9px 12px;
  font-size: 0.93rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.mine .bubble {
  background: linear-gradient(180deg, #2b5dbd, #234c9c);
  border-color: #2f63c9;
  border-top-left-radius: var(--radius);
  border-top-right-radius: 5px;
}

.bubble-text + .bubble-file { margin-top: 6px; }

.bubble-img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  color: inherit;
  text-decoration: none;
  font-size: 0.85rem;
  max-width: 100%;
}

.file-chip:hover { border-color: rgba(255, 255, 255, 0.28); }
.file-chip .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .file-size { color: var(--text-dim); font-size: 0.76rem; flex: none; }

.jump-new {
  position: absolute;
  bottom: 104px;
  left: 50%;
  transform: translateX(-50%);
  border: 1px solid var(--accent);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 3;
}

/* ---------------- Ввод ---------------- */

.composer-wrap {
  border-top: 1px solid var(--line);
  background: rgba(14, 17, 22, 0.9);
  backdrop-filter: blur(12px);
  padding: 8px clamp(10px, 4vw, 22px) calc(10px + env(safe-area-inset-bottom));
}

.typing-hint {
  max-width: 900px;
  margin: 0 auto;
  min-height: 16px;
  font-size: 0.76rem;
  color: var(--text-dim);
  padding: 0 4px 4px;
}

.attach-preview {
  max-width: 900px;
  margin: 0 auto 7px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid #33518c;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.82rem;
}

.attach-preview span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.attach-preview button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.1rem;
  line-height: 1;
}

.attach-preview button:hover { color: var(--danger); }

.composer {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 6px 8px;
}

.composer:focus-within { border-color: #33518c; }

.btn-icon {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.05rem;
  padding: 7px;
  border-radius: 10px;
  flex: none;
}

.btn-icon:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

#input {
  flex: 1;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  padding: 8px 4px;
  max-height: 160px;
  outline: none;
}

#input::placeholder { color: #66707f; }

.btn-send {
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  display: grid;
  place-items: center;
  transition: filter 0.15s, opacity 0.15s;
}

.btn-send:hover { filter: brightness(1.1); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

.composer-error {
  max-width: 900px;
  margin: 6px auto 0;
  min-height: 1em;
  font-size: 0.78rem;
  color: var(--danger);
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #24303f;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 999px;
  font-size: 0.84rem;
  z-index: 10;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

@media (max-width: 860px) {
  .chat { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 320px);
    z-index: 20;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: 30px 0 60px rgba(0, 0, 0, 0.5);
  }

  .sidebar.is-open { transform: none; }

  .burger,
  .only-mobile { display: inline-flex; }

  .burger { margin-left: -4px; }

  .jump-new { bottom: 96px; }
  .msg-body { max-width: 88%; }
  .chat-title .brand-dot { display: none; }
  .chat-header { padding: 10px 12px; }
  .chat-avatar { width: 30px; height: 30px; font-size: 0.72rem; }
}

@media (max-width: 560px) {
  .msg-body { max-width: 90%; }
  .chat-title strong { font-size: 0.94rem; }
  .header-actions .pill { display: none; }
}

/* ------------------------------ админ ------------------------------ */

.lock { font-size: 0.72rem; flex: none; }

.sidebar-foot { flex-wrap: wrap; }

.msg-del {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text-dim);
  font-size: 0.68rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.bubble:hover .msg-del,
.msg-del:focus-visible { opacity: 1; }

.msg-del:hover { color: var(--danger, #ff6b8b); border-color: var(--danger, #ff6b8b); }

@media (hover: none) {
  .msg-del { opacity: 0.55; }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.62);
}

.modal-card {
  width: 100%;
  max-width: 470px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.modal-note {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--text-dim);
}

.admin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev);
}

.admin-name {
  min-width: 0;
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-name small { color: var(--text-dim); font-size: 0.7rem; margin-left: 6px; }

.admin-row .btn-ghost {
  padding: 4px 8px;
  font-size: 0.72rem;
  border-radius: 8px;
  white-space: nowrap;
}

.admin-row .btn-ghost.is-on { color: var(--ok); border-color: var(--ok); }

.admin-row .is-danger:hover { color: var(--danger, #ff6b8b); border-color: var(--danger, #ff6b8b); }

.admin-empty { font-size: 0.8rem; color: var(--text-dim); }

/* ------------------------------ заявки ------------------------------ */

.auth-error.is-ok { color: var(--ok); }

#admin-requests-wrap { display: flex; flex-direction: column; gap: 6px; }

#admin-requests { max-height: 32vh; }

.request-row { grid-template-columns: auto minmax(0, 1fr) auto auto; }

.admin-note-title { margin: 2px 0 0; }
