:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --ink: #0a0a0a;
  --ink-2: #404040;
  --muted: #737373;
  --line: #e5e5e5;
  --line-strong: #d4d4d4;
  --accent: #0a0a0a;
  --bubble-mine-bg: #0a0a0a;
  --bubble-mine-fg: #ffffff;
  --bubble-other-bg: #ffffff;
  --bubble-other-fg: #0a0a0a;
  --radius: 8px;
}

/* === ТЕМЫ === */
body[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-soft: #0f0f0f;
  --ink: #f5f5f5;
  --ink-2: #d4d4d4;
  --muted: #a3a3a3;
  --line: #2a2a2a;
  --line-strong: #404040;
  --accent: #f5f5f5;
  --bubble-mine-bg: #2563eb;
  --bubble-mine-fg: #ffffff;
  --bubble-other-bg: #2a2a2a;
  --bubble-other-fg: #f5f5f5;
}
body[data-theme="ocean"] {
  --bg: #f0f7ff;
  --bg-soft: #e0eef9;
  --ink: #0c1e2e;
  --ink-2: #1f3a52;
  --muted: #5a7a92;
  --line: #c8dcec;
  --line-strong: #94b8d4;
  --accent: #0c1e2e;
  --bubble-mine-bg: #1e6fb5;
  --bubble-mine-fg: #ffffff;
  --bubble-other-bg: #ffffff;
  --bubble-other-fg: #0c1e2e;
}
body[data-theme="forest"] {
  --bg: #f0faf0;
  --bg-soft: #e0f0e0;
  --ink: #0f2410;
  --ink-2: #1f3a1f;
  --muted: #5a7a5a;
  --line: #c8e0c8;
  --line-strong: #94b894;
  --accent: #0f2410;
  --bubble-mine-bg: #2f8f3f;
  --bubble-mine-fg: #ffffff;
  --bubble-other-bg: #ffffff;
  --bubble-other-fg: #0f2410;
}
body[data-theme="warm"] {
  --bg: #fdf6ec;
  --bg-soft: #f7eddb;
  --ink: #2b1f10;
  --ink-2: #4a3a2a;
  --muted: #8a7560;
  --line: #ead9c0;
  --line-strong: #c4b193;
  --accent: #2b1f10;
  --bubble-mine-bg: #c2410c;
  --bubble-mine-fg: #ffffff;
  --bubble-other-bg: #ffffff;
  --bubble-other-fg: #2b1f10;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100svh;
  overflow: hidden; /* по умолчанию body фиксирован на viewport, скролл уходит внутрь */
  display: flex;
  flex-direction: column;
}
/* для landing/share — разрешаем body скроллить (контент может быть длинным) */
body.scroll-page { overflow-y: auto; height: auto; min-height: 100svh; }
#app {
  flex: 1;
  min-height: 0; /* критично для flex column на iOS — без этого children могут вылезти */
  display: flex;
  flex-direction: column;
}

/* === LANDING === */
.landing {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 60px 24px;
  text-align: center;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
.landing h1 {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -1.5px;
  color: var(--ink);
  margin-bottom: 16px;
}
.landing .tagline {
  font-size: 17px;
  color: var(--muted);
  max-width: 520px;
  margin-bottom: 36px;
  line-height: 1.5;
}

.btn-primary {
  background: var(--ink);
  color: white;
  border: 1px solid var(--ink);
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.btn-primary:hover { background: var(--ink-2); }
.btn-primary:active { background: #000; }

.btn-secondary {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: var(--bg-soft); border-color: var(--ink-2); }

.btn-primary:disabled {
  background: var(--bg-soft);
  color: var(--muted);
  border-color: var(--line);
  cursor: not-allowed;
}
.btn-primary:disabled:hover { background: var(--bg-soft); }

.agree-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  text-align: left;
  max-width: 460px;
  line-height: 1.4;
}
.agree-row input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  width: 16px;
  height: 16px;
}
.agree-row a { color: var(--ink-2); }
.agree-row a:hover { color: var(--ink); }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-top: 56px;
  width: 100%;
  overflow: hidden;
}
.feature {
  background: var(--bg);
  padding: 24px;
  text-align: left;
}
.feature h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}
.feature p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

/* === SHARE === */
.share-screen {
  flex: 1;
  padding: 48px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.share-card {
  max-width: 560px;
  width: 100%;
}
.share-card h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}
.share-card p.lead {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 14px;
}
.link-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg);
}
.link-block .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.link-block .label.warn { color: #c2410c; }
.link-block .url {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
  color: var(--ink-2);
  background: var(--bg-soft);
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  margin-bottom: 8px;
  line-height: 1.4;
}
.link-block .desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* === CHAT === */
.chat-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0; /* iOS flex bugfix: без этого chat-body не сжимается, под чатом белая полоса */
  background: var(--bg);
  overflow: hidden;
}
.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-header .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
}
.chat-header .info { flex: 1; min-width: 0; }
.chat-header .info .name {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}
.chat-header .info .status {
  font-size: 12px;
  color: var(--muted);
}
.chat-header .info .status.online { color: #16a34a; }
.chat-header .info .status.online::before { content: '● '; }

.chat-body {
  flex: 1;
  min-height: 0; /* iOS flex bugfix */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px;
  background: var(--bg-soft);
}
.msg {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}
.msg-mine {
  background: var(--bubble-mine-bg);
  color: var(--bubble-mine-fg);
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.msg-other {
  background: var(--bubble-other-bg);
  color: var(--bubble-other-fg);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}
.msg-mine .msg-time {
  color: rgba(255,255,255,0.55);
  text-align: right;
}
.system-msg {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 14px auto;
  padding: 6px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-block;
  width: fit-content;
}

.chat-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-footer input,
.chat-footer textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  color: var(--ink);
  transition: border-color .15s;
  resize: none;
  line-height: 1.4;
  max-height: 120px;
  min-height: 40px;
}
.chat-footer input:focus,
.chat-footer textarea:focus { border-color: var(--ink); }
.chat-footer button {
  background: var(--ink);
  color: white;
  border: 1px solid var(--ink);
  padding: 0 18px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
  font-size: 14px;
}
.chat-footer button:disabled {
  background: var(--bg-soft);
  color: var(--muted);
  border-color: var(--line);
  cursor: not-allowed;
}
.chat-footer #attach-btn,
.chat-footer #templates-btn,
.chat-footer #emoji-btn,
.chat-footer #voice-btn {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 0 12px;
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  height: 40px;
  flex-shrink: 0;
}
.chat-footer #attach-btn:hover,
.chat-footer #templates-btn:hover,
.chat-footer #emoji-btn:hover,
.chat-footer #voice-btn:hover { background: var(--bg-soft); }
.chat-footer #voice-btn.recording {
  background: #dc2626;
  border-color: #dc2626;
  color: white;
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7); }
  50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

/* === PREVIEW MODAL === */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.85);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.preview-modal {
  background: var(--bg);
  color: var(--ink);
  border-radius: 12px;
  max-width: 1100px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.preview-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}
.preview-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
  min-width: 0;
}
.preview-size {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}
.preview-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.preview-btn {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.preview-btn:hover { background: var(--bg-soft); }
.preview-body {
  flex: 1;
  overflow: auto;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}
.preview-body img {
  max-width: 100%;
  max-height: 80vh;
  display: block;
}
.preview-body iframe {
  width: 100%;
  height: 80vh;
  border: 0;
}
.preview-text {
  width: 100%;
  height: 70vh;
  overflow: auto;
  padding: 16px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
}
.preview-fallback {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.preview-fallback-icon {
  font-size: 64px;
  margin-bottom: 12px;
}
.preview-fallback-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
  word-break: break-all;
}
.preview-fallback-desc {
  font-size: 14px;
}
.preview-loading {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.docx-content {
  padding: 24px 32px;
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}
.docx-content h1 { font-size: 22px; margin: 16px 0 10px; }
.docx-content h2 { font-size: 18px; margin: 14px 0 8px; }
.docx-content h3 { font-size: 16px; margin: 12px 0 6px; }
.docx-content p { margin: 8px 0; }
.docx-content table { border-collapse: collapse; margin: 10px 0; }
.docx-content table td, .docx-content table th {
  border: 1px solid var(--line); padding: 6px 10px;
}
.docx-content img { max-width: 100%; height: auto; }

.preview-xlsx {
  width: 100%;
  height: 80vh;
  display: flex;
  flex-direction: column;
}
.xlsx-tabs {
  display: flex;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  overflow-x: auto;
  flex-shrink: 0;
}
.xlsx-tab {
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.xlsx-tab.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.xlsx-content {
  flex: 1;
  overflow: auto;
  padding: 12px;
  background: var(--bg);
}
.xlsx-content table {
  border-collapse: collapse;
  font-size: 12px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
.xlsx-content table td, .xlsx-content table th {
  border: 1px solid var(--line);
  padding: 4px 8px;
  white-space: nowrap;
  color: var(--ink);
}
.xlsx-content table th { background: var(--bg-soft); font-weight: 600; }

.msg-clickable { cursor: pointer; }
.msg-clickable:hover { opacity: 0.92; }

/* === DRAG-AND-DROP OVERLAY === */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 10, 0.55);
  z-index: 50;
  pointer-events: none;
}
.chat-screen { position: relative; }
.drop-overlay.active { display: flex; }
.drop-overlay-text {
  background: var(--bg);
  color: var(--ink);
  padding: 28px 36px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  border: 2px dashed var(--accent);
}

.msg-voice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
}
.msg-voice audio {
  width: 100%;
  height: 36px;
}
.msg-voice-meta {
  font-size: 11px;
  opacity: 0.7;
}
.chat-footer #send-btn {
  height: 40px;
  flex-shrink: 0;
}

/* === THEME PICKER === */
.theme-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-2);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: inherit;
}
.theme-btn:hover { background: var(--bg-soft); border-color: var(--line-strong); }

.theme-popup {
  position: fixed;
  bottom: 80px;
  right: 16px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.15);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 100;
  min-width: 160px;
}
.theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
}
.theme-option:hover { background: var(--bg-soft); }
.theme-option.active { background: var(--bg-soft); font-weight: 600; }
.theme-swatch {
  width: 20px; height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid var(--line);
}

/* === HEADER ACTION BUTTONS === */
.header-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-2);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .12s, border-color .12s, color .12s;
  font-family: inherit;
}
.header-btn:hover { background: var(--bg-soft); border-color: var(--line-strong); }
.header-btn-danger:hover { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }

/* === EMOJI POPUP === */
.emoji-popup {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 16px));
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.15);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  z-index: 100;
}
.emoji-btn-item {
  background: transparent;
  border: none;
  font-size: 24px;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  font-family: inherit;
  line-height: 1;
}
.emoji-btn-item:hover { background: var(--bg-soft); }

/* === QR CODE === */
.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 0 6px;
  margin-bottom: 6px;
}
.qr-wrap canvas {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: var(--bg);
}
.qr-hint {
  font-size: 12px;
  color: var(--muted);
}

/* === TYPING INDICATOR === */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  margin: 4px 0 6px;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-pulse 1.2s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.typing-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-pulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* === TEMPLATES POPUP === */
.templates-popup {
  position: fixed;
  bottom: 70px;
  left: 340px;
  width: 360px;
  max-height: 60vh;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.templates-header {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.templates-list {
  flex: 1;
  overflow-y: auto;
  max-height: 40vh;
}
.templates-empty { padding: 16px; color: var(--muted); font-size: 13px; text-align: center; }
.template-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
}
.template-text {
  flex: 1;
  font-size: 13px;
  cursor: pointer;
  line-height: 1.4;
}
.template-text:hover { color: var(--ink); }
.template-del {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.template-del:hover { color: #dc2626; }
.templates-add {
  display: flex;
  padding: 10px;
  gap: 6px;
  border-top: 1px solid var(--line);
}
.templates-add input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.templates-add input:focus { border-color: var(--ink); }
.templates-add button {
  background: var(--ink);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.msg-image {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
}
.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  margin-bottom: 4px;
  min-width: 200px;
}
.msg-other .msg-file { background: var(--bg-soft); border: 1px solid var(--line); }
.msg-file-icon { font-size: 22px; }
.msg-file-info { display: flex; flex-direction: column; min-width: 0; }
.msg-file-name { font-weight: 500; font-size: 14px; word-break: break-all; }
.msg-file-size { font-size: 12px; opacity: 0.7; }
.msg-stripped {
  display: inline-block;
  font-size: 13px;
  opacity: 0.6;
  font-style: italic;
}

.connecting {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
}
.connecting .spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer-links {
  margin-top: 36px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--ink); text-decoration: underline; }

/* === ADMIN LAYOUT === */
.admin-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  background: var(--bg);
}
.admin-sidebar {
  width: 320px;
  border-right: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.brand-mini { font-weight: 700; font-size: 16px; }
.sidebar-status {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.sidebar-list {
  flex: 1;
  overflow-y: auto;
}
.sidebar-empty {
  padding: 24px 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.sidebar-item {
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  transition: background .12s;
}
.sidebar-item:hover { background: var(--bg-soft); }
.sidebar-item.active { background: var(--bg-soft); }
.sidebar-item-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  position: relative;
}
.sidebar-item-avatar.online::after {
  content: '';
  position: absolute;
  bottom: 0; right: 0;
  width: 10px; height: 10px;
  background: #16a34a;
  border-radius: 50%;
  border: 2px solid white;
}
.sidebar-item-info {
  flex: 1;
  min-width: 0;
}
.sidebar-item-top {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: baseline;
}
.sidebar-item-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-item-time {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}
.sidebar-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.sidebar-item-preview {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.sidebar-badge {
  background: var(--ink);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  flex-shrink: 0;
}
.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.admin-main .chat-screen { height: 100%; }

.empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  color: var(--muted);
}
.empty-chat-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.empty-chat-desc { font-size: 14px; }

/* === NAME FORM === */
.name-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.name-card {
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.name-card h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}
.name-card p {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
}
.name-card input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  margin-bottom: 12px;
}
.name-card input:focus { border-color: var(--ink); }
.name-card .btn-primary { width: 100%; }

.back-btn {
  display: none;
  background: transparent;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  padding: 0 4px;
  margin-right: 4px;
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

@media (max-width: 700px) {
  .landing h1 { font-size: 36px; }
  .landing .tagline { font-size: 15px; }
  .features { grid-template-columns: 1fr; }

  /* админ-панель: показывать или sidebar или chat, не оба */
  .admin-layout { flex-direction: column; }
  .admin-sidebar {
    width: 100%;
    max-height: none;
    flex: 1;
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .admin-main { display: none; }
  body.admin-show-chat .admin-sidebar { display: none; }
  body.admin-show-chat .admin-main { display: flex; flex: 1; min-height: 0; }
  .back-btn { display: block; }

  /* шапка чата компактнее */
  .chat-header { padding: 10px 12px; }
  .chat-header .avatar { width: 32px; height: 32px; font-size: 12px; }

  /* ввод сообщения с большими touch-target */
  .chat-footer { padding: 8px 8px; gap: 4px; }
  .chat-footer input,
  .chat-footer textarea {
    font-size: 16px; /* предотвращает zoom на iOS при focus */
    padding: 8px 10px;
    min-width: 0;
    flex: 1 1 0;
  }
  .chat-footer #attach-btn,
  .chat-footer #templates-btn,
  .chat-footer #emoji-btn,
  .chat-footer #voice-btn {
    padding: 0 8px;
    min-width: 32px;
    font-size: 16px;
  }
  .chat-footer #send-btn { padding: 0 12px; min-width: 48px; }
  .header-btn { width: 28px; height: 28px; font-size: 13px; }

  /* templates popup на мобильном — снизу на весь экран */
  .templates-popup {
    left: 0 !important;
    right: 0 !important;
    bottom: 64px !important;
    width: auto !important;
    border-radius: 10px 10px 0 0;
  }
}
