/* =========================================================================
   PixelPulse135 – Aurora Console design system
   ========================================================================= */

:root {
  /* Palette — PixelPulse135 Neon Night */
  --bg-1: #07040f;
  --bg-2: #0b0718;
  --bg-3: #110a24;
  --ink-1: #f2eeff;
  --ink-2: #c9c0e8;
  --ink-3: #9a8fc4;
  --ink-muted: #6f6596;
  --line: rgba(139, 92, 246, 0.20);
  --line-strong: rgba(139, 92, 246, 0.40);
  --surface: rgba(23, 15, 45, 0.72);
  --surface-strong: rgba(32, 22, 60, 0.92);
  --surface-soft: rgba(23, 15, 45, 0.55);

  --accent-indigo: #8b5cf6;
  --accent-cyan: #22d3ee;
  --accent-emerald: #34d399;
  --accent-mint: #6ee7b7;
  --accent-violet: #8b5cf6;
  --accent-amber: #fbbf24;
  --accent-coral: #fb7185;
  --accent-danger: #f87171;

  --gradient-primary: linear-gradient(135deg, #7c3aed 0%, #9333ea 52%, #c026d3 100%);
  --gradient-soft: linear-gradient(140deg, rgba(139, 92, 246, 0.16), rgba(236, 72, 153, 0.10), rgba(34, 211, 238, 0.12));
  --gradient-warm: linear-gradient(135deg, #fb7185, #fbbf24);

  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 8px 24px rgba(139, 92, 246, 0.45);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --header-h: 64px;

  font-family: "Inter", "Segoe UI", Tahoma, sans-serif;
  color: var(--ink-1);
  background: var(--bg-1);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink-1);
  background:
    radial-gradient(1000px 600px at 12% -8%, rgba(139, 92, 246, 0.22), transparent 55%),
    radial-gradient(900px 550px at 105% 8%, rgba(236, 72, 153, 0.14), transparent 55%),
    radial-gradient(800px 600px at 50% 115%, rgba(34, 211, 238, 0.12), transparent 55%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
  background-attachment: fixed;
}

::selection {
  background: rgba(236, 72, 153, 0.4);
  color: #fff;
}

.hidden {
  display: none !important;
}

/* =========================================================================
   Brand header
   ========================================================================= */

.brand-header {
  position: sticky;
  top: 0;
  z-index: 25;
  padding: 12px 18px;
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  background: rgba(11, 7, 24, 0.72);
  border-bottom: 1px solid var(--line);
}

.brand-wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-symbol {
  width: 42px;
  height: 42px;
  display: block;
  border-radius: 12px;
  box-shadow: 0 7px 20px rgba(124, 58, 237, 0.3);
}

.brand-name {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
}

.brand-main {
  font-family: "Orbitron", "Inter", sans-serif;
  font-size: clamp(22px, 3vw, 30px);
  letter-spacing: 0.5px;
  color: var(--ink-1);
  background: linear-gradient(120deg, #f2eeff, #c4b5fd 60%, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-family: "Orbitron", "Inter", sans-serif;
  font-size: clamp(15px, 2vw, 20px);
  letter-spacing: 0.8px;
  color: var(--accent-violet);
  text-shadow: 0 0 10px rgba(236, 72, 153, 0.45);
}

.brand-number {
  margin-left: 3px;
  color: #a78bfa;
  font-family: "Orbitron", "Inter", sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.8px;
  align-self: flex-start;
  padding-top: 2px;
}

@keyframes pulseGlow {
  from { text-shadow: 0 0 6px rgba(236, 72, 153, 0.35); color: #8b5cf6; }
  to   { text-shadow: 0 0 18px rgba(236, 72, 153, 0.85); color: #ec4899; }
}

/* =========================================================================
   Landing
   ========================================================================= */

.landing {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 28px 20px 40px;
}

.hero-title {
  font-family: "Orbitron", "Inter", sans-serif;
  letter-spacing: 0.6px;
  font-size: clamp(28px, 5vw, 46px);
  line-height: 1.1;
  margin: 0;
  background: linear-gradient(125deg, #f2eeff 0%, #c4b5fd 55%, #22d3ee 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.landing p {
  max-width: 560px;
  color: var(--ink-3);
  font-size: clamp(14px, 1.6vw, 17px);
  margin: 0;
  line-height: 1.55;
}

/* =========================================================================
   Cards & shells
   ========================================================================= */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 18px;
}

.workspace-shell {
  height: calc(100vh - var(--header-h) - 20px);
}

/* =========================================================================
   Buttons & inputs
   ========================================================================= */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-strong);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.035);
  transition: transform 0.15s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
  line-height: 1.1;
  user-select: none;
  white-space: nowrap;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.button:active {
  transform: translateY(0);
}

.button:focus-visible {
  outline: 2px solid var(--accent-indigo);
  outline-offset: 2px;
}

.button.primary {
  background: var(--gradient-primary);
  border-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 7px 18px rgba(124, 58, 237, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.10);
}

.button.primary:hover {
  box-shadow: 0 10px 22px rgba(124, 58, 237, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  filter: brightness(1.06);
}

.button.warn {
  background: rgba(248, 113, 113, 0.12);
  color: #fda4af;
  border-color: rgba(248, 113, 113, 0.4);
}

.button.warn:hover {
  background: rgba(248, 113, 113, 0.22);
}

.button.ghost {
  background: rgba(139, 92, 246, 0.08);
  color: var(--ink-2);
}

.button.ghost:hover {
  background: rgba(139, 92, 246, 0.18);
  color: var(--ink-1);
}

.button.big {
  padding: 16px 22px;
  font-size: 16px;
  border-radius: var(--radius-md);
}

.button.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 16px;
  border-radius: var(--radius-sm);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--ink-1);
  background: rgba(7, 4, 15, 0.6);
  font-family: inherit;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-muted);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.28);
  background: rgba(7, 4, 15, 0.85);
}

textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.45;
}

.muted {
  color: var(--ink-3);
  font-size: 12px;
}

.hint {
  font-size: 12px;
  color: var(--ink-3);
  white-space: pre-line;
}

.error {
  color: var(--accent-danger);
  font-size: 13px;
  margin-top: 6px;
}

/* =========================================================================
   Page shells
   ========================================================================= */

.client-page,
.admin-page {
  padding: 12px;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 10px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.chat-header > div {
  flex: 1 1 0;
  min-width: 0;
}

.chat-header h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header #client-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#active-chat-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

#active-chat-title {
  font-weight: 700;
  color: var(--ink-1);
  font-size: 15px;
  letter-spacing: 0.2px;
}

.chat-header.muted #active-chat-title {
  color: var(--ink-muted);
  font-weight: 600;
}

/* =========================================================================
   Messages
   ========================================================================= */

.messages {
  background: linear-gradient(180deg, rgba(7, 4, 15, 0.35), rgba(11, 7, 24, 0.55));
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  height: 100%;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 4px;
}

.msg {
  max-width: min(78%, 760px);
  padding: 11px 14px;
  border-radius: 14px;
  white-space: pre-line;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.5;
  width: fit-content;
  display: inline-block;
  box-shadow: var(--shadow-sm);
  animation: msgPop 0.18s ease-out both;
}

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

.msg.client {
  margin-left: auto;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #ffffff;
  border: 1px solid transparent;
  border-bottom-right-radius: 6px;
}

.msg.client .meta {
  color: rgba(255, 255, 255, 0.85);
}

.msg.client a {
  color: #ffffff;
  text-decoration: underline;
}

.msg.admin {
  background: var(--surface-strong);
  color: var(--ink-1);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.msg.system {
  max-width: min(86%, 860px);
  background: rgba(251, 191, 36, 0.10);
  border: 1px dashed rgba(251, 191, 36, 0.55);
  color: #fcd34d;
}

/* --- Клиентская страница: поддержка справа, клиент слева ----------------
   Единая схема по всему сайту: сообщения тех-поддержки — справа, цветные;
   сообщения клиента — слева, нейтральным тёмным пузырём. */

.client-page .msg.client {
  margin-left: 0;
  margin-right: auto;
  background: var(--surface-strong);
  color: var(--ink-1);
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 6px;
}

.client-page .msg.client .meta {
  color: var(--ink-muted);
}

.client-page .msg.client a {
  color: var(--accent-cyan);
}

.client-page .msg.admin {
  margin-left: auto;
  margin-right: 0;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #ffffff;
  border: 1px solid transparent;
  border-radius: 14px;
  border-bottom-right-radius: 6px;
}

.client-page .msg.admin .meta {
  color: rgba(255, 255, 255, 0.85);
}

.client-page .msg.admin a {
  color: #ffffff;
  text-decoration: underline;
}

/* --- Админ-панель: стороны зеркалятся -----------------------------------
   На клиентской странице «свои» сообщения (client) справа. В админке
   «свои» — это admin: их отправляем мы, поэтому они справа и цветные,
   а сообщения клиента — слева, нейтральным тёмным пузырём. */

.admin-page .msg.client {
  margin-left: 0;
  margin-right: auto;
  background: var(--surface-strong);
  color: var(--ink-1);
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 6px;
}

.admin-page .msg.client .meta {
  color: var(--ink-muted);
}

.admin-page .msg.client a {
  color: var(--accent-cyan);
}

.admin-page .msg.admin {
  margin-left: auto;
  margin-right: 0;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #ffffff;
  border: 1px solid transparent;
  border-radius: 14px;
  border-bottom-right-radius: 6px;
}

.admin-page .msg.admin .meta {
  color: rgba(255, 255, 255, 0.85);
}

.admin-page .msg.admin a {
  color: #ffffff;
  text-decoration: underline;
}

/* Кнопка «Удалить сообщение» внутри цветного пузыря оператора */
.admin-page .msg.admin .button.ghost {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}

.admin-page .msg.admin .button.ghost:hover {
  background: rgba(255, 255, 255, 0.28);
}

.msg.priority {
  border: 1px solid #fb923c;
  box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.20);
}

.msg .meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.2px;
}

.msg-image {
  width: 100%;
  max-width: 100%;
  max-height: 560px;
  border-radius: 10px;
  margin-top: 6px;
  object-fit: contain;
  display: block;
  cursor: zoom-in;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.msg.has-media {
  width: min(400px, 82%);
  max-width: min(82%, 400px);
}

.msg.has-media > div:first-child:not(:last-child) {
  margin-bottom: 6px;
}

/* =========================================================================
   Composer
   ========================================================================= */

.send-form {
  display: grid;
  gap: 8px;
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: linear-gradient(180deg, rgba(11, 7, 24, 0), rgba(11, 7, 24, 0.96) 40%);
}

.send-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.composer-actions {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  box-shadow: var(--shadow-sm);
}

.file-input-hidden {
  display: none;
}

.photo-button {
  font-weight: 600;
  min-width: 84px;
  text-align: center;
}

.send-button {
  min-width: 120px;
  font-weight: 700;
  margin-left: auto;
}

/* Состояние "идёт отправка": кнопка задизейблена + крутится спиннер,
   пока сервер принимает фото. Защищает от дублей при повторных кликах. */
.send-button.is-sending {
  opacity: 0.85;
  cursor: progress;
  position: relative;
  padding-right: 36px;
}
.send-button.is-sending::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: dxb-spin 0.7s linear infinite;
}
@keyframes dxb-spin {
  to { transform: rotate(360deg); }
}

.photo-button.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.selected-file-name.is-uploading {
  color: var(--accent-cyan);
  font-weight: 600;
}

.selected-file-name {
  font-size: 11px;
  color: var(--ink-3);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================================
   Mobile nav (in workspaces)
   ========================================================================= */

.mobile-nav {
  display: none;
}

.mobile-only {
  display: none;
}

/* =========================================================================
   Admin & client layouts
   ========================================================================= */

.admin-layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 320px;
  gap: 12px;
  align-items: stretch;
  height: 100%;
}

.client-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 270px;
  gap: 12px;
  align-items: stretch;
  height: 100%;
}

.client-main-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  grid-template-columns: 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  gap: 0;
}

.client-pane-chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.rules-pane-root {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.dialog-tile {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface-strong);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.dialog-tile:hover {
  border-color: var(--accent-indigo);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.dialog-tile.active {
  border-color: var(--accent-violet);
  background: rgba(139, 92, 246, 0.14);
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.3);
}

.dialog-tile:focus-visible {
  outline: 2px solid var(--accent-violet);
  outline-offset: 2px;
}

.dialog-tile.locked {
  border-color: rgba(251, 191, 36, 0.45);
  background:
    repeating-linear-gradient(
      135deg,
      rgba(251, 191, 36, 0.05) 0,
      rgba(251, 191, 36, 0.05) 6px,
      rgba(251, 191, 36, 0.12) 6px,
      rgba(251, 191, 36, 0.12) 12px
    ),
    var(--surface-strong);
}

.dialog-tile.locked::after {
  content: "📷 Сначала пришлите 2 фото и примите правила";
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: #fcd34d;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.rules-iframe {
  width: 100%;
  min-height: 200px;
  height: 100%;
  border: 0;
  border-radius: var(--radius-sm);
}

/* Контейнер с инлайнным текстом правил (заменил iframe — на iOS Safari
   внутренний скролл iframe не работает). Скроллится сама панель правил;
   actions-bar ниже — sticky к низу, так что кнопки «Согласен/Не согласен»
   видны всегда, не нужно прокручивать длинный текст до конца. */
.rules-content {
  width: 100%;
  height: 100%;
  min-height: 200px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(7, 4, 15, 0.5);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 14px 16px 18px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-1);
}

.rules-content article {
  max-width: 760px;
  margin: 0 auto;
}

.rules-content h1 {
  font-size: 17px;
  margin: 0 0 14px;
  color: var(--ink-1);
}

.rules-content h2 {
  font-size: 14px;
  margin: 18px 0 8px;
  color: #c4b5fd;
}

.rules-content p {
  margin: 0 0 10px;
}

.rules-content ul {
  margin: 0 0 10px;
  padding-left: 1.2em;
}

.rules-content li {
  margin-bottom: 4px;
}

.rules-content .warn {
  border-left: 3px solid var(--accent-amber);
  padding-left: 10px;
  margin: 10px 0;
  background: rgba(251, 191, 36, 0.08);
}

.rules-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  position: sticky;
  bottom: 0;
  background: rgba(11, 7, 24, 0.97);
  padding: 10px 4px;
  border-top: 1px solid var(--line);
  z-index: 2;
}

.rules-status-hint {
  flex: 1 1 180px;
  font-size: 12px;
}

.banner-mini {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.10);
  color: #fcd34d;
  font-size: 12px;
}

.tag.ok {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.45);
  color: #6ee7b7;
}

.tag.rules-alert {
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.4);
  color: #fda4af;
}

.tag.rules-wait {
  background: rgba(251, 191, 36, 0.10);
  border-color: rgba(251, 191, 36, 0.35);
  color: #fcd34d;
}

.admin-layout .chat-header.flex-chat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
}

.active-chat-titlebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.tag.rules-tag-header {
  font-size: 12px;
  padding: 4px 10px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.admin-layout .flex-chat-bar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.admin-sidebar,
.admin-main,
.admin-tools,
.admin-clients,
.client-sidebar,
.client-main-stack,
.client-tools {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.admin-clients {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  position: relative;
  min-height: 0;
}

.admin-clients .clients-content {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  align-content: start;
  overflow-y: auto;
  padding-right: 4px;
}

.admin-clients.collapsed {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.admin-clients.collapsed .clients-content {
  display: none;
}

.clients-collapse-toggle {
  display: none;
  width: 100%;
  height: 100%;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  color: var(--accent-indigo);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.admin-clients.collapsed .clients-collapse-toggle {
  display: flex;
}

.clients-collapse-toggle:hover {
  border-color: var(--accent-indigo);
  background: rgba(139, 92, 246, 0.12);
}

.clients-collapse-toggle:active {
  transform: scale(0.99);
}

.clients-collapse-arrow {
  font-size: 28px;
  line-height: 1;
}

.clients-collapse-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
}

.admin-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  gap: 8px;
}

.admin-sidebar,
.admin-tools,
.client-sidebar,
.client-tools {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* =========================================================================
   Sidebar (chat list)
   ========================================================================= */

.toolbar {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.toolbar input {
  margin-bottom: 0;
}

.status-box {
  background: linear-gradient(140deg, rgba(139, 92, 246, 0.10), rgba(34, 211, 238, 0.08));
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 13px;
  margin: 12px 0;
  white-space: pre-line;
  color: var(--ink-2);
  line-height: 1.45;
}

.chat-list {
  height: 100%;
  overflow: auto;
  margin-top: 8px;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.chat-list::-webkit-scrollbar {
  width: 6px;
}

.chat-list::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 4px;
}

.chat-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface-strong);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.chat-item:hover {
  border-color: var(--accent-indigo);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.chat-item strong {
  font-family: "Orbitron", "Inter", sans-serif;
  letter-spacing: 0.4px;
  color: var(--ink-1);
  font-size: 13px;
}

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

/* Цветной кружок-индикатор статуса правил у каждого клиента в списке.
   Никаких подписей рядом — только цвет:
   - зелёный = правила приняты
   - красный = правила ещё не подтверждены
   - оранжевый = клиент явно отказался (отдельная важная ситуация). */
.rules-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
}

.rules-dot-agreed {
  background: #22c55e;
  box-shadow: 0 0 0 1px rgba(22, 163, 74, 0.45),
    0 0 6px rgba(34, 197, 94, 0.55);
}

.rules-dot-pending {
  background: #ef4444;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.45),
    0 0 6px rgba(239, 68, 68, 0.55);
}

.rules-dot-disagreed {
  background: #f97316;
  box-shadow: 0 0 0 1px rgba(234, 88, 12, 0.45),
    0 0 6px rgba(249, 115, 22, 0.55);
}

.chat-item .chat-time {
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.chat-preview {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  line-height: 1.4;
  min-height: 2.7em;
  margin-top: 4px;
}

.draft-preview {
  margin-top: 6px;
  margin-bottom: 4px;
  font-size: 11px;
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.10);
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 6px;
  padding: 4px 8px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.chat-item.active {
  border-color: var(--accent-indigo);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.16), rgba(236, 72, 153, 0.10));
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.30), var(--shadow-sm);
}

.chat-item.pending-urgent {
  border-color: #fb923c;
  box-shadow: inset 0 0 0 1px rgba(251, 146, 60, 0.40);
}

.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-radius: var(--radius-pill);
  padding: 3px 8px;
  margin-left: 6px;
  vertical-align: middle;
}

.tag.warn {
  background: rgba(251, 146, 60, 0.16);
  color: #fdba74;
}

.banner {
  background: rgba(251, 191, 36, 0.10);
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #fcd34d;
}

.draft {
  margin-top: 6px;
  min-height: 64px;
  background: rgba(251, 191, 36, 0.06);
  border-color: rgba(251, 191, 36, 0.35);
}

.draft:focus {
  border-color: var(--accent-amber);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.18);
}

/* =========================================================================
   Tools panel header
   ========================================================================= */

.tools-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}

.tools-header h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-1);
}

.tools-header h3::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 18px;
  border-radius: 3px;
  background: var(--gradient-primary);
}

.tools-content {
  display: grid;
  gap: 14px;
  overflow: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.tools-content::-webkit-scrollbar {
  width: 6px;
}

.tools-content::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 4px;
}

.admin-layout.tools-collapsed {
  grid-template-columns: 290px minmax(0, 1fr) 64px;
}

.admin-layout.tools-collapsed .admin-tools,
.client-layout.tools-collapsed .client-tools {
  padding: 12px 8px;
}

.admin-layout.tools-collapsed .tools-header,
.client-layout.tools-collapsed .tools-header {
  justify-content: center;
}

.admin-layout.tools-collapsed .tools-header h3,
.client-layout.tools-collapsed .tools-header h3 {
  display: none;
}

.admin-layout.tools-collapsed .tools-header .button,
.client-layout.tools-collapsed .tools-header .button {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.client-layout.tools-collapsed {
  grid-template-columns: 250px minmax(0, 1fr) 64px;
}

/* =========================================================================
   QUICK ANSWERS — modern card design
   ========================================================================= */

.qa-section {
  display: grid;
  gap: 12px;
}

.qa-search {
  position: relative;
}

.qa-search input {
  margin-bottom: 0;
  padding-left: 36px;
}

.qa-search::before {
  content: "🔎";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
  opacity: 0.7;
}

.qa-create-toggle {
  display: flex;
  width: 100%;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-style: dashed;
  background: rgba(139, 92, 246, 0.08);
  color: #c4b5fd;
  border-color: rgba(139, 92, 246, 0.4);
}

.qa-create-toggle:hover {
  background: rgba(139, 92, 246, 0.16);
}

.script-create-form {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: linear-gradient(140deg, rgba(139, 92, 246, 0.08), rgba(34, 211, 238, 0.05));
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: var(--radius-md);
}

.icon-field {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: start;
  gap: 8px;
}

.icon-field input,
.icon-field textarea {
  margin-bottom: 0;
}

.field-icon {
  width: 32px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  font-size: 16px;
  color: var(--accent-indigo);
}

.script-create-form textarea {
  min-height: 78px;
}

.script-create-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.scripts-list {
  display: grid;
  gap: 10px;
  max-height: none;
  overflow: visible;
  margin-bottom: 0;
}

.script-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 12px 10px;
  background: var(--surface-strong);
  transition: border-color 0.15s ease, box-shadow 0.18s ease, transform 0.15s ease;
  display: grid;
  gap: 8px;
}

.script-row:hover {
  border-color: var(--accent-indigo);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.script-row.editing {
  border-color: var(--accent-amber);
  background: rgba(251, 191, 36, 0.08);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.18);
}

.script-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.script-topic {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-1);
  background: var(--gradient-soft);
  border: 1px solid rgba(139, 92, 246, 0.30);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.script-topic::before {
  content: "📌";
  font-size: 12px;
}

.script-order {
  display: inline-flex;
  gap: 4px;
}

.script-order .button {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  border-radius: 8px;
}

.script-body-wrap {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
  white-space: pre-line;
  background: rgba(7, 4, 15, 0.45);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
}

.script-body-wrap.collapsed {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.script-body-wrap:hover {
  border-color: var(--accent-indigo);
}

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

.script-actions .send-btn {
  flex: 1;
  min-width: 130px;
  padding: 9px 12px;
  font-size: 13px;
}

.script-actions .icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 15px;
  border-radius: var(--radius-sm);
}

.script-actions .icon-btn.danger {
  color: #fda4af;
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.10);
}

.script-actions .icon-btn.danger:hover {
  background: rgba(248, 113, 113, 0.2);
}

.script-actions .button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.script-edit-form {
  display: grid;
  gap: 8px;
}

.script-edit-form input,
.script-edit-form textarea {
  margin-bottom: 0;
}

.script-edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.scripts-empty {
  text-align: center;
  color: var(--ink-muted);
  padding: 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  font-size: 13px;
}

/* =========================================================================
   Inline forms & exports
   ========================================================================= */

.inline-form {
  display: flex;
  gap: 8px;
}

.inline-form input {
  margin-bottom: 0;
}

.tools-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

.tools-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-3);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tools-section h3::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 14px;
  border-radius: 2px;
  background: var(--gradient-primary);
}

.xls-result {
  max-height: 28vh;
  overflow: auto;
  font-size: 12px;
  white-space: pre-line;
  padding: 8px;
  background: rgba(7, 4, 15, 0.5);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-2);
}

/* =========================================================================
   Login & register cards
   ========================================================================= */

.login-card,
#register-card {
  max-width: 460px;
  margin: 40px auto;
  padding: 28px;
}

.login-card h2,
#register-card h3 {
  margin: 0 0 18px;
  background: linear-gradient(120deg, #f2eeff, #c4b5fd 50%, #ec4899);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-card form,
#register-card form {
  display: grid;
  gap: 8px;
}

/* =========================================================================
   Lightbox
   ========================================================================= */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
}
.lightbox.hidden { display: none; }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 12, 24, 0.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 0;
}

/* Сцена с картинкой. Скроллится, если изображение увеличили
   за пределы вьюпорта — пользователь сможет проматывать драгом. */
.lightbox-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 56px 60px;
  -webkit-overflow-scrolling: touch;
}

.lightbox-stage img {
  display: block;
  max-width: calc(100vw - 120px);
  max-height: calc(100vh - 120px);
  width: auto;
  height: auto;
  transform: scale(var(--lb-scale, 1));
  transform-origin: center center;
  transition: transform 0.15s ease, opacity 0.15s ease;
  user-select: none;
  -webkit-user-drag: none;
  cursor: zoom-in;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.lightbox-stage.is-zoomed img { cursor: grab; }
.lightbox-stage.is-panning img { cursor: grabbing; }
.lightbox-stage img.is-loading { opacity: 0.35; }

/* Тулбар: всегда видим поверх картинки даже при максимальном зуме. */
.lightbox-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(20, 28, 44, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.lightbox-counter {
  color: #d8dde7;
  font-size: 13px;
  font-weight: 600;
  padding: 0 10px;
  user-select: none;
  white-space: nowrap;
}

.lightbox-tool {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.05s;
}
.lightbox-tool:hover { background: rgba(255, 255, 255, 0.18); }
.lightbox-tool:active { transform: scale(0.95); }
.lightbox-tool[disabled],
.lightbox-tool.is-disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.lightbox-close-btn { background: rgba(220, 56, 56, 0.85); }
.lightbox-close-btn:hover { background: rgba(220, 56, 56, 1); }

/* Стрелки перелистывания: фиксированы по бокам, всегда видны. */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 4;
  appearance: none;
  background: rgba(20, 28, 44, 0.72);
  color: #fff;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0 0 4px 0;
}
.lightbox-nav:hover { background: rgba(20, 28, 44, 0.95); }
.lightbox-nav:active { transform: translateY(-50%) scale(0.95); }
.lightbox-nav-prev { left: 16px; }
.lightbox-nav-next { right: 16px; }
.lightbox-nav.is-disabled,
.lightbox-nav[disabled] {
  opacity: 0;
  cursor: default;
  pointer-events: none;
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 1100px) {
  .admin-layout,
  .client-layout,
  .admin-layout.tools-collapsed,
  .client-layout.tools-collapsed {
    grid-template-columns: 1fr;
    height: auto;
  }

  .workspace-shell {
    height: auto;
  }
}

@media (max-width: 1100px) {
  :root {
    --header-h: 56px;
  }

  html,
  body {
    overscroll-behavior: contain;
  }

  body {
    overflow: hidden;
    position: fixed;
    inset: 0;
    width: 100%;
    height: var(--admin-app-height, 100dvh);
    touch-action: manipulation;
  }

  .brand-header {
    display: none !important;
  }

  .client-page,
  .admin-page {
    padding: 0;
    height: var(--admin-app-height, 100dvh);
    min-height: 0;
    overflow: hidden;
  }

  .workspace-shell {
    height: 100%;
    border-radius: 0;
  }

  .admin-layout,
  .client-layout,
  .admin-layout.tools-collapsed,
  .client-layout.tools-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 0;
    height: 100%;
    min-height: 0;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: max(6px, env(safe-area-inset-top)) 8px 6px;
    background: rgba(11, 7, 24, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 6;
  }

  .mobile-nav .button {
    padding: 8px 6px;
    font-size: 13px;
    border-radius: var(--radius-sm);
    min-height: 40px;
  }

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

  /* Удаление клиента — опасное действие, на мобильном легко промахнуться
     по соседним кнопкам шапки чата. Прячем на телефоне: удалять можно
     только из ПК-версии. JS-обработчик остаётся в силе, но кнопка
     невидима и не кликабельна. */
  #admin-delete-client-btn {
    display: none !important;
  }

  /* Шапка чата в админ-панели на мобильном.
     Раньше: grid auto/1fr/auto — длинная кнопка «Принять правила за клиента»
     внутри третьей колонки переносилась через flex-wrap, расширяла колонку
     и выдавливала заголовок + тег «ПОДТВЕРЖДЕНЫ» друг на друга.
     Сейчас: одна колонка, заголовок сверху, кнопки отдельной строкой,
     каждая занимает 1fr и переносит длинный текст вместо «выпрыгивания».
     Дубль кнопки «К чатам» убираем — её работу делает верхний mobile-nav
     (💬 Чаты), как уже сделано для клиентского чата. */
  #active-chat-header {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto;
    align-items: stretch;
    gap: 8px;
    padding: 6px 4px 8px;
  }

  .admin-main .chat-header #admin-back-to-chats {
    display: none !important;
  }

  .admin-layout .active-chat-titlebar {
    flex-wrap: wrap;
    row-gap: 4px;
    column-gap: 8px;
  }

  .admin-layout #active-chat-title {
    font-size: 14px;
    line-height: 1.25;
  }

  .admin-layout .tag.rules-tag-header {
    font-size: 10px;
    padding: 3px 8px;
    letter-spacing: 0;
  }

  /* Контейнер кнопок на гриде с auto-fit: одна видимая кнопка занимает
     всю ширину, две — поровну, три — переносятся в две строки.
     Скрытые через .hidden { display: none } из грида автоматически
     выпадают, поэтому одинокая кнопка «Свернуть чат» (типичная ситуация
     после согласия с правилами) растягивается на всю ширину. */
  .admin-layout .flex-chat-bar-controls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 6px;
    align-items: stretch;
  }

  .admin-layout .flex-chat-bar-controls > .button {
    min-width: 0;
    padding: 8px 10px;
    font-size: 12px;
    min-height: 38px;
    line-height: 1.2;
    white-space: normal;
    text-align: center;
    word-break: break-word;
  }

  .admin-sidebar,
  .admin-main,
  .admin-tools,
  .client-sidebar,
  .client-main-stack,
  .client-tools {
    border-radius: 0;
    box-shadow: none;
    border: 0;
    padding: 8px;
    min-height: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .admin-layout .admin-sidebar,
  .admin-layout .admin-main,
  .admin-layout .admin-tools,
  .client-layout .client-sidebar,
  .client-layout .client-main-stack,
  .client-layout .client-tools {
    display: none;
  }

  .admin-layout[data-mobile-view="chats"] .admin-sidebar,
  .admin-layout[data-mobile-view="chat"] .admin-main,
  .admin-layout[data-mobile-view="tools"] .admin-tools,
  .client-layout[data-mobile-view="dialogs"] .client-sidebar,
  .client-layout[data-mobile-view="chat"] .client-main-stack,
  .client-layout[data-mobile-view="tools"] .client-tools {
    display: grid;
    align-content: stretch;
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  .admin-layout[data-mobile-view="dialogs"] .admin-sidebar,
  .admin-layout[data-mobile-view="tools"] .admin-tools,
  .client-layout[data-mobile-view="dialogs"] .client-sidebar,
  .client-layout[data-mobile-view="tools"] .client-tools {
    overflow-y: auto;
  }

  .admin-main,
  .client-main-stack > .client-pane-chat {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .chat-header {
    padding: 4px 4px 6px;
    gap: 6px;
  }

  .chat-header h2 {
    font-size: 14px;
    margin: 0;
    line-height: 1.2;
  }

  .chat-header #client-meta,
  .chat-header .muted {
    font-size: 11px;
    margin-top: 2px;
  }

  /* На мобильных кнопка «К диалогам/К чатам» в шапке дублирует верхнюю
     mobile-nav (💬 Чаты / 📝 Диалог) — прячем, чтобы шапка была
     компактнее и над сообщениями оставалось больше места. */
  .client-pane-chat .chat-header .mobile-only,
  .rules-pane-header .mobile-only {
    display: none !important;
  }

  /* Жёлтая мини-плашка с напоминанием про правила и фото на мобильных
     дублирует приветственное системное сообщение прямо в чате. Убираем —
     вернём ~80–120px высоты под видимые сообщения. */
  .banner-mini {
    display: none !important;
  }

  /* Кнопку «Выйти» делаем меньше, чтобы заголовок чата получил больше
     места и не переносился. */
  .client-pane-chat .chat-header > .button.ghost,
  .rules-pane-header > .button.ghost {
    padding: 8px 10px;
    font-size: 12px;
    min-height: auto;
  }

  /* Заголовок и логин — в одной строке, чтобы не съедать вторую строку. */
  .client-pane-chat .chat-header > div {
    line-height: 1.2;
  }

  .messages {
    min-height: 0;
    height: 100%;
    border-radius: var(--radius-md);
    padding: 8px;
    gap: 6px;
  }

  /* Боковые отступы у панели чата на мобиле тоже ужмём — каждый пиксель
     по ширине отдаём под сообщения и пузыри. */
  .client-main,
  .client-main-stack,
  .client-pane-chat,
  .rules-pane-root {
    padding: 0;
  }

  /* Содержимое правил на мобилке: контейнер становится «нативно» скроллимым,
     при этом полоса кнопок под ним остаётся sticky-снизу — Apple-Safari больше
     не «поедает» кнопки. */
  .rules-content {
    padding: 12px 12px 16px;
    font-size: 13.5px;
    line-height: 1.55;
  }

  .msg {
    max-width: 84%;
    font-size: 14px;
    padding: 8px 10px;
    line-height: 1.4;
  }

  .admin-page .msg.admin .button.ghost[data-delete-id] {
    width: 28px;
    min-width: 28px;
    height: 28px;
    min-height: 28px;
    padding: 0;
    border-radius: 50%;
    font-size: 0;
    box-shadow: none;
    float: right;
  }

  .admin-page .msg.admin .button.ghost[data-delete-id]::before {
    content: "×";
    font-size: 20px;
    line-height: 1;
  }

  .msg-image {
    max-width: 100%;
    max-height: min(52vh, 520px);
  }

  .send-form textarea,
  #admin-message-input,
  #message-input {
    min-height: 56px;
    max-height: 120px;
    font-size: 16px;
    padding: 10px 12px;
  }

  /* Когда клавиатура открыта (фокус в textarea), скрываем верхнюю
     панель навигации и кнопку «К диалогам/К чатам»: они в этот момент
     отъедают ~120px и от чата остаётся 1-2 сообщения. */
  body.keyboard-open .mobile-nav,
  body.keyboard-open .chat-header .mobile-only,
  body.keyboard-open #client-tools,
  body.keyboard-open #admin-tools {
    display: none !important;
  }

  body.keyboard-open .send-form textarea,
  body.keyboard-open #admin-message-input,
  body.keyboard-open #message-input {
    min-height: 44px;
  }

  input,
  textarea,
  select {
    font-size: 16px !important;
  }

  .admin-page .draft {
    min-height: 42px;
    max-height: 70px;
    margin-top: 4px;
    padding: 9px 10px;
  }

  body.keyboard-open .chat-header {
    padding: 4px 4px 4px;
  }

  body.keyboard-open .chat-header h2 {
    font-size: 13px;
  }

  body.keyboard-open .chat-header #client-meta,
  body.keyboard-open .chat-header .muted {
    display: none;
  }

  .send-actions {
    position: sticky;
    bottom: 0;
    background: rgba(11, 7, 24, 0.98);
    padding-top: 6px;
  }

  .send-actions .button {
    min-width: 100px;
    font-size: 14px;
    padding: 12px 14px;
    min-height: 44px;
  }

  .selected-file-name {
    max-width: 110px;
  }

  .chat-list {
    max-height: calc(100dvh - 240px);
  }

  .scripts-list {
    max-height: none;
  }

  .tools-content {
    gap: 12px;
    overflow: visible;
  }

  .inline-form {
    flex-direction: column;
    gap: 8px;
  }

  .lightbox-stage {
    padding: 64px 12px;
  }
  .lightbox-stage img {
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 130px);
  }
  .lightbox-nav {
    width: 44px;
    height: 44px;
    font-size: 26px;
  }
  .lightbox-nav-prev { left: 6px; }
  .lightbox-nav-next { right: 6px; }
  .lightbox-toolbar { gap: 2px; padding: 4px 6px; }
  .lightbox-tool { min-width: 32px; height: 32px; font-size: 14px; padding: 0 8px; }
  .lightbox-counter { font-size: 12px; padding: 0 6px; }

  .login-card,
  #register-card {
    margin: 16px auto;
    padding: 20px;
  }

  .script-actions .send-btn {
    flex: 1 0 100%;
  }

  .script-actions .icon-btn {
    flex: 0 0 auto;
  }
}

@media (max-width: 420px) {
  .msg {
    max-width: 92%;
  }

  .send-actions .button {
    min-width: 0;
    flex: 1;
  }

  .send-actions .photo-button {
    flex: 0 0 auto;
    min-width: 70px;
  }
}
