/* Общий фон и типографика */
html {
  background: #020617;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background: radial-gradient(circle at top left, #064e3b 0, #020817 45%, #020617 100%);
  background-color: #020617;
  background-attachment: fixed;
  color: #ffffff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

.app-shell {
  min-height: calc(100vh - 64px);
}

main.container {
  max-width: 1080px;
}

/* Навбар */
.navbar-brand {
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.9rem;
}

.navbar-dark.bg-dark {
  background: linear-gradient(90deg, #022c22, #064e3b, #052e16);
  border-bottom: 1px solid rgba(34, 197, 94, 0.45);
}

/* Карточки и панели */
.card {
  border: 1px solid rgba(34, 197, 94, 0.35);
  background: radial-gradient(circle at top, #020617 0, #020617 40%, #020617 100%);
  background-color: #020617;
  color: #ffffff;
}

.card-header {
  border-bottom-color: rgba(148, 163, 184, 0.25);
}

.card.shadow-sm {
  box-shadow: 0 18px 45px rgba(6, 95, 70, 0.85);
}

.card h1,
.card h2,
.card h3,
.card h4,
.card h5 {
  color: #f9fafb;
}

.list-group-item {
  background-color: rgba(15, 23, 42, 0.9);
  color: #ffffff;
  border-color: rgba(22, 163, 74, 0.7);
}

/* Кнопки */
.btn-primary {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-color: transparent;
  box-shadow: 0 10px 25px rgba(22, 163, 74, 0.65);
}

.btn-primary:hover,
.btn-primary:focus {
  background: linear-gradient(135deg, #16a34a, #15803d);
  box-shadow: 0 16px 35px rgba(21, 128, 61, 0.9);
}

.btn-outline-primary {
  color: #6ee7b7;
  border-color: rgba(34, 197, 94, 0.65);
}

.btn-outline-primary:hover {
  background: rgba(34, 197, 94, 0.16);
  border-color: #22c55e;
  color: #ecfdf5;
}

/* Формы */
label.form-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ca3af;
}

.form-control,
.form-select,
input.form-control,
textarea.form-control,
select.form-select {
  background-color: rgba(15, 23, 42, 0.95) !important;
  border-color: rgba(55, 65, 81, 0.9);
  color: #e5e7eb !important;
  border-radius: 0.5rem;
}

.form-control::placeholder {
  color: rgba(148, 163, 184, 0.8);
}

.form-control:focus,
.form-select:focus,
input.form-control:focus,
textarea.form-control:focus {
  background-color: rgba(15, 23, 42, 1) !important;
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.75);
  color: #e5f4ec !important;
}

.form-text {
  color: #e5e7eb;
}

/* Форма отчёта по лидам — все поля в стиле сайта (тёмный фон) */
.leads-report-form .form-control,
.leads-report-form .form-select {
  background-color: rgba(15, 23, 42, 0.95) !important;
  border: 1px solid rgba(55, 65, 81, 0.9);
  color: #e5e7eb !important;
}
.leads-report-form .form-control:focus,
.leads-report-form .form-select:focus {
  background-color: rgba(15, 23, 42, 1) !important;
  border-color: #22c55e;
  color: #e5f4ec !important;
}
.leads-report-form .form-control::placeholder {
  color: rgba(148, 163, 184, 0.8);
}

input[type="radio"] {
  accent-color: #22c55e;
}

/* Сообщения (django messages) */
.alert {
  border-radius: 0.75rem;
  border-width: 1px;
}

.alert-info {
  background-color: rgba(59, 130, 246, 0.06);
  border-color: rgba(59, 130, 246, 0.45);
  color: #bfdbfe;
}

.alert-success {
  background-color: rgba(16, 185, 129, 0.09);
  border-color: rgba(16, 185, 129, 0.55);
  color: #bbf7d0;
}

.alert-warning {
  background-color: rgba(234, 179, 8, 0.12);
  border-color: rgba(234, 179, 8, 0.6);
  color: #fef3c7;
}

.alert-danger {
  background-color: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.6);
  color: #fee2e2;
}

/* Хиро-блок */
.hero-title {
  font-size: clamp(2.1rem, 3vw, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.hero-subtitle {
  color: #e5e7eb;
  max-width: 42rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  background: rgba(55, 65, 81, 0.6);
  color: #ffffff;
}

/* Перекрашиваем "приглушённый" текст Bootstrap */
.text-muted {
  color: #e5e7eb !important;
}

/* Вкладки (все пользователи и др.) */
.nav-tabs {
  border-bottom-color: rgba(34, 197, 94, 0.4);
}
.nav-tabs .nav-link {
  color: rgba(255, 255, 255, 0.8);
  border-color: transparent;
  background: transparent;
}
.nav-tabs .nav-link:hover {
  color: #bbf7d0;
  border-color: transparent;
}
.nav-tabs .nav-link.active {
  color: #ecfdf5;
  background: rgba(6, 78, 59, 0.5);
  border-color: rgba(34, 197, 94, 0.4) rgba(34, 197, 94, 0.4) transparent;
}

/* Дашборд */
.dashboard-grid .card {
  transition: transform 0.12s ease-out, box-shadow 0.12s ease-out, border-color 0.12s ease-out;
}

.dashboard-grid .card:hover {
  transform: translateY(-3px);
  box-shadow: 0 20px 45px rgba(6, 95, 70, 0.95);
  border-color: rgba(34, 197, 94, 0.95);
}

.dashboard-grid .card-icon {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.35rem;
  font-size: 1.25rem;
}

.dashboard-grid .card-icon.contacts {
  background: rgba(74, 222, 128, 0.18);
  color: #bbf7d0;
}

.dashboard-grid .card-icon.report {
  background: rgba(251, 191, 36, 0.18);
  color: #fde68a;
}

.dashboard-grid .card-icon.stats {
  background: rgba(52, 211, 153, 0.18);
  color: #6ee7b7;
}

.dashboard-grid .card-icon.support {
  background: rgba(45, 212, 191, 0.18);
  color: #99f6e4;
}

/* Поддержка — пузыри сообщений */
.support-thread-user,
.support-thread-support {
  max-width: 100%;
  overflow: hidden;
}
.support-thread-user {
  background: linear-gradient(135deg, #22c55e, #16a34a);
}
.support-thread-support {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.6);
}

/* Виджет поддержки */
.support-widget {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 1050;
  font-size: 0.9rem;
}

.support-chat-toggle.nav-link {
  color: rgba(255, 255, 255, 0.85);
}
.support-chat-toggle.nav-link:hover {
  color: #bbf7d0;
}

.support-panel {
  position: absolute;
  bottom: 3.5rem;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 2rem);
  max-height: 420px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(34, 197, 94, 0.45);
  background: linear-gradient(180deg, #022c22 0, #020617 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.support-panel-inner {
  display: flex;
  flex-direction: column;
  height: 420px;
}

.support-panel-header {
  padding: 0.6rem 1rem;
  background: rgba(6, 78, 59, 0.6);
  border-bottom: 1px solid rgba(34, 197, 94, 0.35);
  font-weight: 600;
  color: #ecfdf5;
}

.support-panel-close {
  font-size: 1.25rem;
  line-height: 1;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.6) !important;
}
.support-panel-close:hover {
  color: #ecfdf5 !important;
}

.support-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  min-height: 120px;
}

.support-panel-form {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid rgba(34, 197, 94, 0.35);
  background: rgba(2, 6, 23, 0.95);
}

.support-panel-form .form-control {
  font-size: 0.875rem;
}

.support-messages .support-msg:last-child {
  margin-bottom: 0;
}

/* Область чата с поддержкой: прокрутка */
.support-chat-body {
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 197, 94, 0.5) rgba(15, 23, 42, 0.8);
}
.support-chat-body::-webkit-scrollbar {
  width: 8px;
}
.support-chat-body::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.8);
  border-radius: 4px;
}
.support-chat-body::-webkit-scrollbar-thumb {
  background: rgba(34, 197, 94, 0.5);
  border-radius: 4px;
}
.support-chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(34, 197, 94, 0.7);
}

/* Превью изображений в чате — жёстко ограничены, по клику открывается в полном размере */
.support-attachment {
  margin-top: 0.35rem;
  max-width: 280px;
  overflow: hidden;
}
.support-attachment-link {
  display: block;
  max-width: 280px;
  line-height: 0;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
}
.support-attachment-link:focus {
  outline: 2px solid rgba(34, 197, 94, 0.6);
  outline-offset: 2px;
}
.support-inline-image {
  max-width: 280px !important;
  max-height: 180px !important;
  width: auto !important;
  height: auto !important;
  border-radius: 6px;
  display: block;
  object-fit: contain;
  vertical-align: middle;
}
.support-attachment-link:hover .support-inline-image {
  opacity: 0.92;
}
.support-attachment-link::after {
  content: "Открыть в полном размере";
  display: block;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 4px;
  line-height: 1.2;
}
.support-attachment-link:hover::after {
  color: rgba(255, 255, 255, 0.95);
}

/* Таблица диалогов поддержки в админке — под стиль сайта */
.card .support-threads-table.table,
.support-threads-table.table {
  --bs-table-bg: rgba(2, 6, 23, 0.95);
  --bs-table-color: #e5e7eb;
  --bs-table-border-color: rgba(34, 197, 94, 0.25);
  background: rgba(2, 6, 23, 0.95);
  color: #e5e7eb;
}
.support-threads-table thead th {
  background: rgba(6, 78, 59, 0.6) !important;
  border-bottom: 1px solid rgba(34, 197, 94, 0.45);
  color: #ecfdf5 !important;
  font-weight: 600;
  padding: 0.75rem 1rem;
}
.support-threads-table tbody tr {
  background: transparent !important;
}
.support-threads-table tbody td {
  background: transparent !important;
  border-bottom: 1px solid rgba(34, 197, 94, 0.2);
  color: #e5e7eb !important;
  padding: 0.75rem 1rem;
  vertical-align: middle;
}
.support-threads-table tbody tr:hover td {
  background: rgba(6, 78, 59, 0.2) !important;
}
.support-thread-unread td:first-child {
  font-weight: 600;
}
.support-threads-table .badge.bg-success {
  background: rgba(34, 197, 94, 0.9) !important;
  font-size: 0.7rem;
}
.support-threads-table .table-responsive {
  background: transparent;
}
.support-threads-table + .card-body,
.card-body .support-threads-table {
  background: transparent;
}

/* Таблицы в стиле сайта (админская статистика и др.) */
.table-dark-site {
  --bs-table-bg: rgba(2, 6, 23, 0.95);
  --bs-table-color: #e5e7eb;
  --bs-table-border-color: rgba(34, 197, 94, 0.25);
  background: rgba(2, 6, 23, 0.95);
  color: #e5e7eb;
}
.table-dark-site thead th {
  background: rgba(6, 78, 59, 0.6) !important;
  border-bottom: 1px solid rgba(34, 197, 94, 0.45);
  color: #ecfdf5 !important;
  font-weight: 600;
  padding: 0.75rem 1rem;
}
.table-dark-site tbody tr {
  background: transparent !important;
}
.table-dark-site tbody td {
  background: transparent !important;
  border-bottom: 1px solid rgba(34, 197, 94, 0.2);
  color: #e5e7eb !important;
  padding: 0.75rem 1rem;
  vertical-align: middle;
}
.table-dark-site tbody tr:hover td {
  background: rgba(6, 78, 59, 0.2) !important;
}
.card-body .table-dark-site {
  background: transparent;
}

/* Админская таблица «Новые отчёты (лиды)» — длинные контакты не ломают вёрстку */
.table-dark-site td.contact-cell {
  max-width: 260px;
  word-break: break-all;
  white-space: normal;
}
.table-dark-site td.comment-cell {
  max-width: 220px;
  word-break: break-word;
  white-space: normal;
}
@media (max-width: 991.98px) {
  .table-dark-site td.contact-cell,
  .table-dark-site td.comment-cell {
    max-width: 200px;
    font-size: 0.8rem;
  }
  .table-dark-site thead th,
  .table-dark-site tbody td {
    padding: 0.5rem 0.5rem;
  }
}

/* ============================================================
   MOBILE (< 768px)
   ============================================================ */
@media (max-width: 767.98px) {
  /* Меньше горизонтальных отступов у контейнера */
  main.container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  /* Навбар: компактнее */
  .navbar { padding-top: 0.35rem; padding-bottom: 0.35rem; }
  .navbar .container { padding-left: 0.75rem; padding-right: 0.75rem; }

  /* Юзернейм в навбаре — не слишком длинный */
  .navbar-nav .nav-item.me-2 {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.85rem;
  }

  /* Карточки: меньше внутренних отступов */
  .card-body { padding: 0.75rem; }
  .card-header { padding: 0.5rem 0.75rem; }
  .card-footer { padding: 0.5rem 0.75rem; }

  /* Заголовки поменьше */
  h1.h4, .h4 { font-size: 1.15rem; }
  h2.h6, .h6 { font-size: 0.9rem; }

  /* Вкладки (tabs) — горизонтальный скролл вместо переноса */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs .nav-item { flex-shrink: 0; }
  .nav-tabs .nav-link {
    font-size: 0.8rem;
    padding: 0.4rem 0.65rem;
    white-space: nowrap;
  }

  /* Таблицы — компактнее */
  .table-dark-site thead th,
  .table-dark-site tbody td,
  .support-threads-table thead th,
  .support-threads-table tbody td {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
  }
  .table-dark-site thead th:first-child,
  .table-dark-site tbody td:first-child {
    padding-left: 0.65rem;
  }

  /* Кнопки действий в таблицах — минимальная высота для тач */
  .table-dark-site .btn-sm,
  .table .btn-sm {
    min-height: 32px;
    min-width: 32px;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  /* Поисковая строка — на всю ширину */
  form.d-flex input[name="q"] {
    max-width: 100% !important;
    flex: 1;
  }

  /* Общие d-flex обёртки — на мобильном стакаем */
  .d-flex.justify-content-between.align-items-center.mb-3 {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.5rem;
  }

  /* Статистика-карточки с числами — компактнее */
  .fs-4 { font-size: 1.25rem !important; }

  /* Пагинация — компактнее */
  .pagination-sm .page-link {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    min-width: 36px;
    text-align: center;
  }

  /* Виджет поддержки — на всю ширину */
  .support-panel {
    width: calc(100vw - 1rem);
    max-width: calc(100vw - 1rem);
    right: 0.5rem;
  }

  /* Бейджи — чуть меньше */
  .badge {
    font-size: 0.68rem;
    padding: 0.2em 0.5em;
  }

  /* row g-3 — уменьшить гаттер */
  .row.g-3 { --bs-gutter-x: 0.75rem; --bs-gutter-y: 0.75rem; }

  /* Алерты — компактнее */
  .alert { padding: 0.5rem 0.75rem; font-size: 0.85rem; }

  /* Футер */
  footer .d-flex { gap: 0.75rem !important; }
  footer .small { font-size: 0.72rem; }
}

/* ============================================================
   SMALL MOBILE (< 576px)
   ============================================================ */
@media (max-width: 575.98px) {
  /* Ещё компактнее */
  main.container {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .card-body { padding: 0.6rem; }

  /* Таблицы совсем компактные */
  .table-dark-site thead th,
  .table-dark-site tbody td {
    padding: 0.3rem 0.35rem;
    font-size: 0.75rem;
  }

  /* Убираем лишние колонки, если помечены как скрываемые */
  .hide-xs { display: none !important; }

  /* Формы поиска — стакаем */
  form.mb-3.d-flex.gap-2 {
    flex-wrap: wrap;
  }
  form.mb-3.d-flex.gap-2 input[name="q"] {
    width: 100% !important;
    max-width: 100% !important;
    flex-basis: 100%;
  }
}


