* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f1f4f9;
  --panel: #ffffff;
  --border: #e4e9f2;
  --text: #17203a;
  --muted: #6b7a99;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-dark: #4338ca;
  --grad: linear-gradient(135deg, #4f46e5, #7c3aed);
  --danger: #e11d48;
  --success: #10b981;
  --warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 32, 58, .04), 0 4px 16px rgba(23, 32, 58, .06);
  --shadow-hover: 0 4px 8px rgba(79, 70, 229, .08), 0 8px 28px rgba(79, 70, 229, .14);
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ============ Экран входа ============ */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, #6d5cff 0%, transparent 60%),
              radial-gradient(1000px 700px at 110% 110%, #9333ea 0%, transparent 55%),
              #171a36;
  padding: 20px;
}
.auth-card {
  background: rgba(255, 255, 255, .97);
  border-radius: 22px;
  padding: 38px 34px;
  width: 400px;
  box-shadow: 0 24px 80px rgba(10, 8, 45, .45);
  backdrop-filter: blur(10px);
}
.auth-card h1 {
  text-align: center; margin-bottom: 24px; font-size: 26px;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tabs { display: flex; gap: 6px; margin-bottom: 22px; background: #eef1f8; border-radius: 12px; padding: 4px; }
.tab {
  flex: 1; padding: 9px; border: none; background: transparent;
  border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted);
  font-family: inherit; transition: all .18s;
}
.tab.active { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(23,32,58,.1); }

/* ============ Формы ============ */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 15px; font-family: inherit; background: #fbfcfe;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.error {
  background: #fff1f2; color: var(--danger); padding: 10px 14px;
  border-radius: 10px; font-size: 14px; margin-bottom: 14px; border: 1px solid #fecdd3;
}
.error.info { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.checkbox-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  border: 1.5px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #fbfcfe;
}
.checkbox-item {
  display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer;
}
.checkbox-item input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ============ Кнопки ============ */
.btn {
  padding: 9px 18px; border: 1.5px solid var(--border); background: #fff;
  border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; font-family: inherit;
  color: var(--text); transition: all .16s;
}
.btn:hover { border-color: #c9d2e5; box-shadow: var(--shadow); transform: translateY(-1px); }
.btn.primary { background: var(--grad); color: #fff; border: none; }
.btn.primary:hover { box-shadow: var(--shadow-hover); filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: #fbcfe0; }
.btn.danger:hover { background: #fff1f2; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.full { width: 100%; padding: 12px; font-size: 15px; }
a.btn { display: inline-block; text-decoration: none; }

/* ============ Каркас ============ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: linear-gradient(180deg, #171a36 0%, #1e1b4b 100%);
  color: #c7cdea; padding: 24px 14px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.logo {
  font-size: 24px; font-weight: 800; color: #fff; padding: 0 12px 24px; line-height: 1.1;
  letter-spacing: -.5px;
}
.logo span {
  background: linear-gradient(90deg, #818cf8, #c084fc);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  font-size: 16px; font-weight: 700;
}
.sidebar nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-btn {
  text-align: left; padding: 11px 14px; background: none; border: none;
  color: #aab3d9; font-size: 14.5px; font-weight: 600; border-radius: 11px; cursor: pointer;
  font-family: inherit; transition: all .16s;
}
.nav-btn:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-btn.active {
  background: var(--grad); color: #fff;
  box-shadow: 0 6px 18px rgba(99, 82, 255, .35);
}
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.09); padding-top: 16px; }
.user-name { font-size: 13px; margin-bottom: 10px; padding: 0 6px; color: #8f9ac4; }
.sidebar-footer .btn { background: rgba(255,255,255,.08); border: none; color: #c7cdea; }
.sidebar-footer .btn:hover { background: rgba(255,255,255,.16); color: #fff; transform: none; }

.content { flex: 1; padding: 32px 36px; max-width: 1340px; }
.view h2 { margin-bottom: 20px; font-size: 24px; letter-spacing: -.4px; }
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.view-header h2 { margin: 0; }

/* ============ Сводка ============ */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border-radius: var(--radius); padding: 20px 22px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  transition: all .18s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.card .card-value { font-size: 32px; font-weight: 800; margin-bottom: 4px; letter-spacing: -1px; }
.card .card-label { color: var(--muted); font-size: 13.5px; font-weight: 500; }
.card.alert .card-value { color: var(--danger); }
.card.good .card-value { color: var(--success); }

/* ============ Списки и фильтры ============ */
.filters { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 220px; padding: 11px 16px; border: 1.5px solid var(--border);
  border-radius: 11px; font-size: 15px; font-family: inherit; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.filter-select {
  padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 11px;
  font-size: 14px; font-family: inherit; background: #fff; min-width: 180px; font-weight: 500;
}
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 20px; display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow); flex-wrap: wrap; transition: all .16s;
}
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { border-color: #b9b3f5; transform: translateY(-1px); box-shadow: var(--shadow-hover); }
.list-item .grow { flex: 1; min-width: 200px; }
.item-title { font-weight: 700; font-size: 15px; }
.item-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; font-size: 15px; }

/* ============ Бейджи ============ */
.badge {
  display: inline-block; padding: 4px 11px; border-radius: 20px; font-size: 12px;
  font-weight: 700; white-space: nowrap; letter-spacing: .1px;
}
.badge.st-new     { background: #eef2ff; color: #4f46e5; }
.badge.st-gray    { background: #f1f4f9; color: var(--muted); }
.badge.st-warn    { background: #fff7e6; color: #b45309; }
.badge.st-good    { background: #ecfdf5; color: #047857; }
.badge.st-blue    { background: #eff6ff; color: #1d4ed8; }
.badge.st-bad     { background: #fff1f2; color: var(--danger); }
.badge.st-reserve { background: #f5f3ff; color: #7c3aed; }

/* ============ Задачи ============ */
.task-check { width: 20px; height: 20px; cursor: pointer; accent-color: var(--success); }
.task-done .item-title { text-decoration: line-through; color: var(--muted); }

/* ============ Канбан ============ */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kanban.kanban-5 { grid-template-columns: repeat(5, 1fr); }
.kanban-col {
  background: #e9edf5; border-radius: var(--radius); padding: 14px; min-height: 240px;
}
.kanban-col h4 { font-size: 13px; color: #55628a; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
.kanban-col .col-total { font-size: 12px; color: var(--muted); margin-bottom: 12px; min-height: 15px; font-weight: 600; }
.deal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 11px;
  padding: 12px 14px; margin-bottom: 9px; cursor: pointer; box-shadow: var(--shadow);
  transition: all .16s;
}
.deal-card:hover { border-color: #b9b3f5; transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.deal-card .deal-title { font-weight: 700; font-size: 14px; }
.deal-card .deal-client { color: var(--muted); font-size: 12px; margin-top: 3px; }
.deal-card .deal-amount { color: var(--primary); font-size: 13.5px; font-weight: 700; margin-top: 6px; }

/* ============ Карточка клиента ============ */
.detail-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 26px; margin-top: 16px; box-shadow: var(--shadow);
}
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.detail-header h2 { margin: 0 0 4px; font-size: 24px; }
.detail-contacts { color: var(--muted); font-size: 14px; line-height: 2; margin-top: 12px; }
.detail-contacts b { color: var(--text); }
.detail-section { margin-top: 26px; }
.detail-section h3 { font-size: 16.5px; margin-bottom: 12px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-header h3 { margin: 0; }
.activity-item { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.activity-item .activity-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.activity-form { display: flex; gap: 8px; margin-bottom: 14px; }
.activity-form input {
  flex: 1; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 14px; background: #fbfcfe;
}
.activity-form input:focus { outline: none; border-color: var(--primary); background: #fff; }

/* --- Телефон и ссылка на карточку --- */
.phone-link { color: var(--primary); text-decoration: none; font-weight: 700; }
.phone-link:hover { text-decoration: underline; }
.card-link {
  display: inline-block; color: var(--primary); text-decoration: none;
  font-weight: 700; padding: 2px 0;
}
.card-link:hover { text-decoration: underline; }
.mine-filter {
  border: 1.5px solid var(--border); border-radius: 11px; padding: 0 16px;
  background: #fff; white-space: nowrap; font-weight: 500;
}

/* ============ Статистика ============ */
.period-tabs { display: flex; gap: 6px; }
.period-btn.active-period { background: var(--grad); color: #fff; border: none; }
.stats {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.stats th, .stats td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.stats th { background: #f7f9fd; font-size: 12.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.stats tbody tr { transition: background .12s; }
.stats tbody tr:hover { background: #fafbff; }
.stats .num-good { color: var(--success); font-weight: 700; }
.stats .num-bad { color: var(--danger); }
.stats .totals-row td { font-weight: 800; background: #f7f9fd; }
.hint { color: var(--muted); font-size: 13.5px; margin: 12px 0; line-height: 1.6; }

/* ============ Скрипты продаж ============ */
.script-card { margin-bottom: 16px; margin-top: 0; }
.script-card h3 { margin-bottom: 12px; font-size: 16px; }
.script-edit {
  width: 100%; min-height: 140px; padding: 14px; border: 1.5px solid var(--border);
  border-radius: 11px; font-family: inherit; font-size: 14px; line-height: 1.7; resize: vertical;
  background: #fbfcfe;
}
.script-edit:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.script-content { white-space: pre-wrap; font-size: 14px; line-height: 1.75; }
.script-details {
  border: 1px solid #f0e9d2; border-radius: 11px; margin-bottom: 9px;
  background: linear-gradient(180deg, #fffdf4, #fffaeb);
}
.script-details summary { padding: 12px 16px; cursor: pointer; font-weight: 700; font-size: 14px; }
.script-details .script-content { padding: 0 16px 14px; }

/* ============ Модальное окно ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 18, 45, .55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
  backdrop-filter: blur(3px);
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--panel); border-radius: 20px; width: 480px; max-width: 100%;
  max-height: 90vh; overflow-y: auto; padding: 26px;
  box-shadow: 0 24px 80px rgba(10, 8, 45, .35);
  animation: slideUp .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 19px; }
.modal-close {
  background: #f1f4f9; border: none; font-size: 20px; cursor: pointer; color: var(--muted);
  line-height: 1; width: 34px; height: 34px; border-radius: 10px; transition: all .15s;
}
.modal-close:hover { background: #e4e9f2; color: var(--text); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ============ Адаптив ============ */
@media (max-width: 1100px) {
  .kanban.kanban-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static; flex-direction: row; align-items: center;
    padding: 10px 12px; gap: 6px; overflow-x: auto;
  }
  .logo { padding: 0 8px; font-size: 16px; white-space: nowrap; }
  .sidebar nav { flex-direction: row; }
  .nav-btn { white-space: nowrap; padding: 9px 12px; }
  .sidebar-footer { border: none; padding: 0; display: flex; align-items: center; gap: 8px; }
  .user-name { margin: 0; white-space: nowrap; }
  .kanban, .kanban.kanban-5 { grid-template-columns: 1fr 1fr; }
  .content { padding: 18px; }
  .filters { flex-direction: column; }
  .mine-filter { padding: 10px 16px; }
}
