/* =============== ОБЩИЕ СТИЛИ CRM =============== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  margin: 0;
  padding: 0;
  line-height: 1.5;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* =============== БОКОВОЕ МЕНЮ =============== */
.sidebar {
  width: 240px;
  background: var(--gray-900);
  color: white;
  padding: 20px 0;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--gray-700);
  margin-bottom: 20px;
}

.sidebar-logo h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
}

.sidebar-logo span {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: var(--gray-300);
  text-decoration: none;
  transition: all 0.2s;
  font-size: 0.95rem;
}

.sidebar nav a:hover {
  background: var(--gray-700);
  color: white;
}

.sidebar nav a.active {
  background: var(--primary);
  color: white;
}

.sidebar nav a .icon {
  font-size: 1.2rem;
}

.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  border-top: 1px solid var(--gray-700);
}

.sidebar-footer .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--gray-300);
  font-size: 0.9rem;
}

.sidebar-footer .user-avatar {
  width: 36px;
  height: 36px;
  background: var(--gray-700);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.sidebar-footer .logout-btn {
  width: 100%;
  padding: 10px;
  background: var(--gray-700);
  color: var(--gray-300);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.sidebar-footer .logout-btn:hover {
  background: var(--danger);
  color: white;
}

/* Автодополнение */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 250px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background: var(--gray-50);
}

.autocomplete-item strong {
  color: var(--gray-900);
}

/* =============== ОСНОВНОЙ КОНТЕНТ =============== */
.main {
  flex: 1;
  margin-left: 240px;
  padding: 30px;
}

.page-header {
  margin-bottom: 30px;
}

.page-header h1 {
  margin: 0 0 5px;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-900);
}

.page-header p {
  margin: 0;
  color: var(--gray-500);
}

/* =============== КАРТОЧКИ =============== */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--gray-200);
}

.card-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

/* =============== ТАБЛИЦЫ =============== */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

th {
  background: var(--gray-50);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
}

tr:hover {
  background: var(--gray-50);
}

/* =============== КНОПКИ =============== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #059669;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-outline {
  background: white;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}

.btn-outline:hover {
  background: var(--gray-50);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* =============== ФОРМЫ =============== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--gray-700);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-control {
  cursor: pointer;
}

/* =============== БЕЙДЖИ / СТАТУСЫ =============== */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge-info {
  background: #dbeafe;
  color: #1e40af;
}

.badge-gray {
  background: var(--gray-200);
  color: var(--gray-700);
}

/* =============== СООБЩЕНИЯ =============== */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* =============== GRID =============== */
.grid {
  display: grid;
  gap: 24px;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* =============== СТАТИСТИКА =============== */
.stat-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stat-card .label {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-900);
}

/* =============== МОДАЛЬНЫЕ ОКНА =============== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(-20px);
  transition: transform 0.3s;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-500);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* =============== ПУСТОЕ СОСТОЯНИЕ =============== */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--gray-500);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

/* =============== АДАПТИВНОСТЬ =============== */

/* Планшеты */
@media (max-width: 1024px) {
  .main {
    margin-left: 200px;
    padding: 16px;
  }
  
  .sidebar {
    width: 200px;
  }
  
  .sidebar-logo h1 {
    font-size: 1.2rem;
  }
  
  .grid-3, .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Мобильные */
@media (max-width: 768px) {
  .app {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 12px;
  }
  
  .sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
  }
  
  .sidebar-logo span {
    display: none;
  }
  
  .sidebar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .sidebar nav a {
    padding: 8px 12px;
    font-size: 0.85rem;
    border-radius: var(--radius);
  }
  
  .sidebar nav a .icon {
    margin-right: 4px;
  }
  
  .sidebar-footer {
    position: relative;
    border-top: none;
    padding: 12px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  .sidebar-footer .user-info {
    margin-bottom: 0;
  }
  
  .sidebar-footer .logout-btn {
    width: auto;
    padding: 8px 16px;
  }
  
  .main {
    margin-left: 0;
    padding: 12px;
  }
  
  .page-header h1 {
    font-size: 1.3rem;
  }
  
  .page-header p {
    font-size: 0.85rem;
  }
  
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  
  .stat-card {
    padding: 12px;
  }
  
  .stat-card .value {
    font-size: 1.5rem;
  }
  
  .card {
    padding: 12px;
  }
  
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .card-header h2 {
    font-size: 1rem;
  }
  
  /* Таблицы на мобильных */
  table {
    font-size: 0.8rem;
  }
  
  th, td {
    padding: 8px 6px;
  }
  
  /* Скрываем некоторые колонки на мобильных */
  .hide-mobile {
    display: none;
  }
  
  /* Формы */
  .form-control {
    padding: 10px 12px;
    font-size: 16px; /* Предотвращает зум на iOS */
  }
  
  .btn {
    padding: 10px 16px;
    font-size: 0.9rem;
  }
  
  .btn-sm {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
  
  /* Модальные окна */
  .modal {
    width: 95%;
    max-width: none;
    margin: 10px;
    max-height: 90vh;
  }
  
  .modal-body {
    max-height: 60vh;
    overflow-y: auto;
  }
  
  /* Бейджи */
  .badge {
    font-size: 0.7rem;
    padding: 3px 6px;
  }
  
  /* Автодополнение */
  .autocomplete-list {
    max-height: 200px;
  }
  
  /* Чекбоксы зон */
  .zones-checkboxes {
    gap: 8px;
  }
  
  .checkbox-label {
    font-size: 0.8rem;
  }
}

/* Маленькие мобильные */
@media (max-width: 480px) {
  .sidebar nav a {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
  
  .page-header h1 {
    font-size: 1.1rem;
  }
  
  table {
    font-size: 0.75rem;
  }
  
  th, td {
    padding: 6px 4px;
  }
  
  .stat-card .value {
    font-size: 1.2rem;
  }
  
  .stat-card .label {
    font-size: 0.7rem;
  }
}

/* Горизонтальный скролл для таблиц */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* =============== КАЛЕНДАРЬ =============== */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 16px;
}
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.calendar-header h3 {
  margin: 0;
  font-size: 1.2rem;
}
.day-header {
  text-align: center;
  font-weight: 600;
  padding: 8px;
  color: var(--gray-500);
  font-size: 0.85rem;
}
.day-cell {
  min-height: 100px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.day-cell:hover {
  border-color: var(--primary);
  background: white;
}
.day-cell.other-month {
  opacity: 0.4;
}
.day-cell.today {
  border-color: var(--primary);
  background: rgba(79, 70, 229, 0.05);
}
.day-cell.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}
.day-number {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}
.day-cell.today .day-number {
  color: var(--primary);
}
.day-tasks {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.day-task {
  font-size: 0.7rem;
  padding: 2px 4px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.day-task.planned {
  background: var(--warning);
  color: white;
}
.day-task.running {
  background: var(--info);
  color: white;
}
.day-task.completed {
  background: var(--success);
  color: white;
}
.day-more {
  font-size: 0.7rem;
  color: var(--gray-500);
  text-align: center;
}
.plan-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
  margin-bottom: 8px;
  border-left: 4px solid var(--warning);
}
.plan-item.running {
  border-left-color: var(--info);
}
.plan-item.completed {
  border-left-color: var(--success);
}
.plan-item-info h4 {
  margin: 0 0 4px 0;
  font-size: 0.95rem;
}
.plan-item-info p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--gray-500);
}
.plan-item-actions {
  display: flex;
  gap: 4px;
}

@media (max-width: 768px) {
  .calendar {
    gap: 2px;
  }
  .day-cell {
    min-height: 60px;
    padding: 4px;
  }
  .day-number {
    font-size: 0.8rem;
  }
  .day-task {
    font-size: 0.6rem;
  }
}

