/*
 * Базовые стили CRM. Адаптивно: таблицы и карточки читаемы с телефона.
 *
 * Палитра и параметры компонентов (радиусы, тени, отступы) взяты из
 * дизайн-системы Sneat (ThemeSelection, MIT-лицензия, themeselection.com) —
 * реализованы заново в чистом CSS, без Bootstrap и без сборки.
 */

:root {
  --bg: #f5f5f9;
  --surface: #ffffff;
  --text: #646e78;
  --heading: #384551;
  --muted: #7a838b;
  --border: #e4e6e8;
  --hover-bg: #f2f3f3;
  --accent: #696cff;
  --accent-hover: #5f62e6;
  --accent-tint: #ebebff;
  --success: #71dd37;
  --success-tint: #e7f9dc;
  --info: #03c3ec;
  --info-tint: #dcf7fc;
  --warning: #ffab00;
  --warning-tint: #fff2d9;
  --danger: #ff3e1d;
  --danger-tint: #ffe2dd;
  --radius: 6px;
  --shadow: 0 3px 8px 0 rgba(56, 69, 81, 0.1);
  --shadow-sm: 0 2px 6px 0 rgba(56, 69, 81, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1f2228;
    --text: #b6bcc4;
    --heading: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2e3239;
    --hover-bg: #262a31;
    --accent: #8083ff;
    --accent-hover: #9295ff;
    --accent-tint: #2a2a45;
    --success-tint: #1f3320;
    --info-tint: #12333b;
    --warning-tint: #3a2e12;
    --danger-tint: #3a1f1a;
    --shadow: 0 3px 8px 0 rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 6px 0 rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Public Sans", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3 {
  color: var(--heading);
}

h1 {
  font-size: 24px;
  margin: 0 0 8px;
}

.lead {
  color: var(--muted);
  margin: 0 0 24px;
}

code {
  background: var(--hover-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}

/* Общая раскладка: сайдбар слева + контент справа */

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  flex: 0 0 260px;
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 20px;
  color: var(--heading);
  padding: 4px 10px 20px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a,
.sidebar-nav .nav-disabled {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--heading);
  font-size: 14px;
  font-weight: 500;
}

.sidebar-nav a:hover {
  background: var(--hover-bg);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--accent-tint);
  color: var(--accent);
}

.sidebar-nav .nav-disabled {
  color: var(--muted);
  cursor: default;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 64px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Мобильный/узкий экран: сайдбар возвращается в горизонтальную панель сверху */
@media (max-width: 992px) {
  .layout {
    flex-direction: column;
    min-height: 0;
  }

  .sidebar {
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar .brand {
    padding: 0;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .sidebar-nav a,
  .sidebar-nav .nav-disabled {
    padding: 6px 10px;
  }
}

/* Контент */

.content {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

/* Карточки разделов (главная страница) */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-pending {
  opacity: 0.7;
}

.card-title {
  font-weight: 600;
  color: var(--heading);
  margin-bottom: 4px;
}

.card-status {
  color: var(--muted);
  font-size: 13px;
}

/* Пользователь в шапке */

.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.user-name {
  color: var(--muted);
}

/* Метки состояния и ролей — «мягкий» бейдж: светлая заливка + текст того же цвета */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: var(--hover-bg);
  color: var(--heading);
  white-space: nowrap;
}

.badge-admin {
  background: var(--accent-tint);
  color: var(--accent);
}

.badge-manager {
  background: var(--success-tint);
  color: #3d8a17;
}

.badge-viewer {
  background: var(--info-tint);
  color: #04788f;
}

.badge-ok {
  background: var(--success-tint);
  color: #3d8a17;
}

.badge-wait {
  background: var(--warning-tint);
  color: #8a5c00;
}

.badge-off {
  background: var(--hover-bg);
  color: var(--muted);
}

/* Бейдж-кнопка: например, состояние организации в списке — кликом меняется на месте */
.badge-btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.badge-btn:hover {
  filter: brightness(0.95);
}

/* Формы */

.auth-box,
.form-narrow {
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-box {
  margin: 40px auto;
}

label {
  display: block;
  margin: 14px 0 4px;
  font-size: 13px;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="date"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-block;
  margin-top: 18px;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s ease-in-out, filter 0.15s ease-in-out;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
}

.btn-link:hover {
  text-decoration: underline;
}

.inline-form {
  display: inline;
}

.radio-group {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.hint-inline {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.hint {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

.form-error {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--danger-tint);
  color: #a3271a;
  font-size: 14px;
}

/* Всплывающие сообщения */

.flash {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
}

.flash-success {
  background: var(--success-tint);
  color: #3d8a17;
}

.flash-error {
  background: var(--danger-tint);
  color: #a3271a;
}

.flash-link {
  margin-top: 10px;
}

.copy-field {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--heading);
  font-family: ui-monospace, "Consolas", monospace;
  font-size: 13px;
}

/* Заголовок раздела */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.page-head h1,
.page-head h2 {
  margin: 0;
}

.row-inactive {
  opacity: 0.55;
}

/* Фильтры над списком (поиск, менеджер) */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.filter-bar input[type="text"] {
  width: auto;
  min-width: 200px;
  flex: 1;
}

.filter-bar select {
  width: auto;
}

/* Карточка сведений (организация, привлечение, ...) */

.detail-card {
  display: grid;
  gap: 10px;
  margin-bottom: 24px;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.actions {
  display: flex;
  gap: 12px;
  white-space: nowrap;
}

/* Таблицы: обёрнуты в карточку с тенью, на узком экране прокручиваются по горизонтали */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Выпадающий список прямо в ячейке таблицы (например, смена менеджера) — не на всю ширину колонки */
.list-inline-select {
  width: auto;
  max-width: 220px;
}

/*
 * Быстрая постановка задачи прямо в строке таблицы (тип + срок + кнопка).
 * Столбец в ширину растёт вместе с таблицей (table без table-layout:fixed),
 * поэтому поля стоят друг под другом — иначе на узком окне часть формы
 * уезжает за край и становится не видна и не нажимаема.
 */
.quick-task-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 170px;
}

.quick-task-form select,
.quick-task-form input {
  width: 100%;
  padding: 4px 6px;
  font-size: 13px;
}

.quick-task-submit {
  margin-top: 0;
  padding: 5px 10px;
  font-size: 13px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tbody tr:hover {
  background: var(--hover-bg);
}

/* Канбан воронки продаж */

.kanban-board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 18px;
}

.kanban-column {
  flex: 0 0 240px;
  background: var(--hover-bg);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kanban-column-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--heading);
  display: flex;
  justify-content: space-between;
}

.kanban-count {
  background: var(--border);
  border-radius: 10px;
  padding: 0 7px;
  font-weight: 400;
}

.kanban-column-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 40px;
}

.kanban-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 10px 12px;
  cursor: grab;
}

.kanban-card-dragging {
  opacity: 0.5;
}

.kanban-card-title {
  display: block;
  font-weight: 600;
  color: var(--heading);
  margin-bottom: 2px;
}

.kanban-card-amount {
  margin-top: 4px;
  font-weight: 600;
  color: var(--heading);
}

.kanban-stage-form {
  display: flex;
  flex-direction: column;
}

.kanban-card select,
.kanban-card input[type="text"] {
  width: 100%;
  margin-top: 6px;
  font-size: 12px;
  padding: 4px 6px;
}

.kanban-stage-form button {
  align-self: flex-start;
  margin-top: 6px;
}

/* Дашборд */

.dash-stack {
  display: grid;
  gap: 16px;
}

.dash-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .dash-cols {
    grid-template-columns: 1fr;
  }
}

.card h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

.kpi-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 2px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--heading);
}

.kpi-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.bar-list {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 92px 1fr 90px;
  align-items: center;
  gap: 10px;
}

.bar-label {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.stage-label {
  color: var(--heading);
}

.bar-track {
  height: 12px;
  background: var(--hover-bg);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
}

.bar-value {
  font-size: 13px;
  text-align: right;
  color: var(--heading);
  white-space: nowrap;
}
