/* ============================================================
   Beacon — стили SPA
   Тёмная тема по умолчанию, двухколоночный layout с адаптивом.
   ============================================================ */

/* ---------- Переменные темы ---------- */
:root {
  --bg: #121212;
  --bg-sidebar: #191919;
  --bg-elevated: #1e1e1e;
  --bg-hover: #262626;
  --bg-input: #232323;
  --border: #2c2c2c;
  --text: #ececec;
  --text-muted: #9b9b9b;
  --accent: #ffb84d;
  --accent-strong: #ffa726;
  --accent-contrast: #22180a;
  --danger: #ff6b6b;
  --success: #7bc47f;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---------- Сброс и база ---------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden; /* SPA занимает весь экран, скроллятся только списки */
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
}

input,
textarea {
  font: inherit;
  color: inherit;
}

img {
  display: block;
}

.hidden {
  display: none !important;
}

/* Скроллбары */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #383838;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #484848;
}

/* ---------- Общие компоненты ---------- */
.screen {
  height: 100vh;
  height: 100dvh;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}
.btn:active:not(:disabled) {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.55;
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-contrast);
}
.btn.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}
.btn.ghost {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text);
}
.btn.ghost:hover:not(:disabled) {
  background: var(--bg-hover);
}
.btn.full {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.input,
.textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  caret-color: var(--accent);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.input:hover:not(:focus),
.textarea:hover:not(:focus) {
  border-color: #3a3a3a;
}
.input::placeholder,
.textarea::placeholder {
  color: #6d6d6d;
}
.input:focus,
.textarea:focus {
  border-color: rgba(255, 184, 77, 0.55);
  background: #262626;
  box-shadow: 0 0 0 3px rgba(255, 184, 77, 0.12);
}
.textarea {
  resize: none;
  min-height: 74px;
  line-height: 1.5;
}

/* Кастомные поля: убираем нативные артефакты браузера (крестики, «глаз», стрелки) */
input::-webkit-search-cancel-button,
input::-webkit-search-decoration,
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
}
input::-ms-reveal,
input::-ms-clear {
  display: none;
}
/* Автозаполнение Chrome/Edge не должно красить поля светлым */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px #232323 inset;
  -webkit-text-fill-color: var(--text);
  caret-color: var(--accent);
  transition: background-color 99999s ease-out;
}
::selection {
  background: rgba(255, 184, 77, 0.3);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  line-height: 1.45;
}

/* ---------- Экран авторизации ---------- */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(255, 184, 77, 0.1), transparent 65%),
    var(--bg);
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 380px;
  padding: 30px 26px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  align-self: center;
}

.auth-title {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.auth-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -8px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 12px;
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.link-btn {
  align-self: center;
  padding: 4px;
  color: var(--text-muted);
  font-size: 13px;
  transition: color 0.15s ease;
}
.link-btn:hover {
  color: var(--accent);
}

/* ---------- Layout мессенджера ---------- */
.messenger {
  display: flex;
}

/* Боковая панель */
#sidebar {
  position: relative; /* якорь для плавающей кнопки «создать» */
  display: flex;
  flex-direction: column;
  width: 340px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
}

.brand {
  flex: 1;
  min-width: 0;
}
.brand h1 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
}
.current-user {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-actions {
  padding: 12px 16px 10px;
}

/* Кнопка «создать чат» — аккуратный плюс в правом нижнем углу докбара */
.fab {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.fab:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
}
.fab:active {
  transform: scale(0.94);
}

.chat-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px 84px; /* нижний отступ — чтобы список не прятался под кнопкой «+» */
}

.chat-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.13s ease;
}
.chat-item:hover {
  background: var(--bg-hover);
}
.chat-item.active {
  background: var(--bg-hover);
  box-shadow: inset 3px 0 0 var(--accent);
}

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  font-size: 18px;
  font-weight: 700;
  color: #1a1408; /* тёмная буква на светлой заливке */
  user-select: none;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-item-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.chat-item-title {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-item-preview {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-type-icon {
  display: inline-flex;
  color: #5c5c5c;
  flex-shrink: 0;
}
.chat-type-icon svg {
  width: 14px;
  height: 14px;
}

.sidebar-empty {
  padding: 28px 16px;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}

/* ---------- Панель чата ---------- */
.chat-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.panel-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
}
.panel-empty img {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  opacity: 0.3;
}

.chat-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.chat-header .avatar {
  width: 42px;
  height: 42px;
  font-size: 16px;
}
.chat-header-info {
  min-width: 0;
}
.chat-header-info h2 {
  font-size: 15.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-info p {
  font-size: 12.5px;
  color: var(--text-muted);
}
#back-btn {
  display: none; /* появляется только на мобильных */
}

/* Лента сообщений */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.messages-empty {
  margin: auto;
  font-size: 13.5px;
  text-align: center;
  color: var(--text-muted);
}

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}
.message.own {
  align-items: flex-end;
}

.message-sender {
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.bubble {
  max-width: min(72%, 560px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px 16px 16px 16px;
}
.message.own .bubble {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
  border-radius: 16px 6px 16px 16px;
}

.bubble-text {
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble-time {
  align-self: flex-end;
  font-size: 10.5px;
  opacity: 0.62;
}

.message-day {
  align-self: center;
  margin: 8px 0;
  padding: 3px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Плашка канала: доступ только администраторам */
.channel-locked {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(255, 184, 77, 0.07);
  border-top: 1px solid var(--border);
  color: #ffcf8a;
  font-size: 13px;
}

/* Поле ввода */
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}
.composer input {
  flex: 1;
  min-width: 0;
  padding: 11px 18px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  caret-color: var(--accent);
  transition: border-color 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}
.composer input:focus {
  border-color: rgba(255, 184, 77, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 184, 77, 0.12);
}
.composer input:disabled {
  opacity: 0.45;
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  transition: background 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-strong);
}
.send-btn:active:not(:disabled) {
  transform: scale(0.94);
}
.send-btn:disabled {
  opacity: 0.4;
}

/* ---------- Модальное окно создания чата ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
}

.modal {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: modal-in 0.18s ease;
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 17px;
}

.tabs {
  display: flex;
  gap: 5px;
  padding: 4px;
  background: var(--bg-input);
  border-radius: 12px;
}
.tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  background: var(--bg-hover);
  color: var(--accent);
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tab-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- Поиск в сайдбаре ---------- */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 40px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}
.search-box:focus-within {
  border-color: rgba(255, 184, 77, 0.55);
  background: #262626;
  color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 184, 77, 0.12);
}
.search-box input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  font-size: 13.5px;
  color: var(--text);
  caret-color: var(--accent);
}
.search-box input::placeholder {
  color: #6d6d6d;
}
.search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.search-clear:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.search-section {
  padding: 12px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.search-badge {
  flex-shrink: 0;
  padding: 1px 7px;
  border: 1px solid rgba(255, 184, 77, 0.35);
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
}
.search-empty {
  padding: 28px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Профиль и онбординг ---------- */
.onboarding-email {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: -6px;
}
.field-hint {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-muted);
}
.avatar-btn {
  display: inline-flex;
  border-radius: 50%;
  flex-shrink: 0;
}
.avatar-btn:hover {
  box-shadow: 0 0 0 3px var(--bg-hover);
}
.avatar-sm {
  width: 34px;
  height: 34px;
  font-size: 13px;
}
.avatar-lg {
  width: 76px;
  height: 76px;
  font-size: 30px;
}

/* ---------- Предпросмотр канала ---------- */
.preview-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.preview-meta {
  font-size: 13px;
}
.preview-description {
  max-width: 420px;
  font-size: 13.5px;
  line-height: 1.55;
}
.panel-empty .btn {
  margin-top: 4px;
}

/* ---------- Отписка от канала ---------- */
.unsubscribe-btn {
  margin-left: auto;
  flex-shrink: 0;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.unsubscribe-btn:hover {
  background: var(--bg-hover);
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.4);
}

/* ---------- Тост-уведомления ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 100;
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  padding: 11px 18px;
  background: #2a2a2a;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: toast-in 0.2s ease;
}
.toast.error {
  border-color: rgba(255, 107, 107, 0.55);
  color: #ffb4b4;
}
.toast.success {
  border-color: rgba(123, 196, 127, 0.5);
  color: #bfe6c1;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------- Адаптив: мобильная навигация ---------- */
@media (max-width: 768px) {
  /* Сайдбар и чат поочерёдно занимают весь экран */
  #sidebar {
    width: 100%;
    border-right: none;
  }
  .chat-panel {
    display: none;
  }

  body.chat-open #sidebar {
    display: none;
  }
  body.chat-open .chat-panel {
    display: flex;
  }

  #back-btn {
    display: inline-flex;
  }

  .messages {
    padding: 12px;
  }
  .chat-header {
    padding: 10px 12px;
  }
  .bubble {
    max-width: 84%;
  }
}
