/* ═══════════════════════════════════════════════════════════
   components.css — Стили всех UI-компонентов
   table, card, modal, toast, filters, pagination
   ═══════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════
   TABLE
   ═══════════════════════════════════════════════════════════ */

.table-wrapper {
  overflow-x: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
}

.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-md);
}

.crm-table th {
  text-align: left;
  padding: 10px var(--space-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  user-select: none;
}

.crm-table__th--sortable {
  cursor: pointer;
  transition: color var(--transition-fast);
}

.crm-table__th--sortable:hover {
  color: var(--text-primary);
}

/* Индикатор сортировки */
.crm-table__th--sorted::after {
  content: ' ▲';
  font-size: 10px;
  opacity: 0.6;
}

.crm-table__th--sorted[data-sort-dir="desc"]::after {
  content: ' ▼';
}

.crm-table td {
  padding: 10px var(--space-lg);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.crm-table tbody tr:last-child td {
  border-bottom: none;
}

.crm-table tbody tr:hover td {
  background: var(--bg-hover);
}

.crm-table__row--clickable {
  cursor: pointer;
}

/* Пустое состояние таблицы */
.table-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-3xl) var(--space-xl);
  gap: var(--space-md);
}

.table-empty__icon {
  width: 40px;
  height: 40px;
  color: var(--text-disabled);
}

.table-empty__text {
  font-size: var(--text-md);
  color: var(--text-tertiary);
}

/* Скелетон */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

.skeleton--text {
  height: 14px;
  width: 70%;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.crm-table--loading th .skeleton { width: 60%; }
.crm-table--loading td .skeleton { width: 80%; }
.crm-table--loading td:nth-child(odd) .skeleton { width: 60%; }

/* ═══════════════════════════════════════════════════════════
   CARD
   ═══════════════════════════════════════════════════════════ */

.card {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card--interactive {
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.card--interactive:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
}

.card__header {
  padding: var(--space-xl) var(--space-xl) var(--space-lg);
}

.card__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.card__subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-top: var(--space-xs);
}

/* Вкладки */
.card__tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-light);
  padding: 0 var(--space-xl);
}

.card__tab {
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--text-md);
  font-weight: 400;
  color: var(--text-tertiary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-bottom: -1px;
}

.card__tab:hover {
  color: var(--text-primary);
}

.card__tab--active {
  color: var(--accent);
  font-weight: 500;
  border-bottom-color: var(--accent);
}

/* Поля */
.card__fields {
  padding: var(--space-lg) var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.card__field {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
}

.card__field-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 120px;
  flex-shrink: 0;
}

.card__field-value {
  font-size: var(--text-md);
  color: var(--text-primary);
}

.card__content {
  padding: var(--space-lg) var(--space-xl) var(--space-xl);
}

/* Раскрывающийся блок */
.collapsible {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.collapsible__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.collapsible__trigger:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.collapsible__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.collapsible--open .collapsible__icon {
  transform: rotate(90deg);
}

.collapsible__body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease;
}

.collapsible--open .collapsible__body {
  max-height: 2000px;
}

.collapsible__content {
  padding: var(--space-lg);
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  font-family: var(--font-mono);
}

/* ═══════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-xl);
}

.modal-overlay--closing {
  animation: fadeOut 0.15s ease-out forwards;
}

@keyframes fadeOut {
  to { opacity: 0; }
}

.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideIn 0.15s ease-out;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal--small { max-width: 400px; }
.modal--medium { max-width: 560px; }
.modal--large { max-width: 800px; }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xl) var(--space-xl) var(--space-lg);
  border-bottom: 1px solid var(--border-light);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.modal__close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal__close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal__close svg {
  width: 18px;
  height: 18px;
}

.modal__body {
  padding: var(--space-xl);
  font-size: var(--text-md);
  color: var(--text-primary);
  line-height: 1.6;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-lg) var(--space-xl) var(--space-xl);
  border-top: 1px solid var(--border-light);
}

/* ═══════════════════════════════════════════════════════════
   BUTTONS (global)
   ═══════════════════════════════════════════════════════════ */

.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
}

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

.btn-secondary {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
  background: var(--danger);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.btn-danger:hover { background: var(--danger-text); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-md);
  font-weight: 400;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════════ */

.toast-container {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-sm);
  z-index: 2000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 280px;
  max-width: 420px;
  pointer-events: auto;
  animation: toastIn 0.2s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast--hiding {
  animation: toastOut 0.2s ease-in forwards;
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); }
}

.toast--success { border-left: 3px solid var(--success); }
.toast--error { border-left: 3px solid var(--danger); }
.toast--info { border-left: 3px solid var(--info); }

.toast__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toast--success .toast__icon { color: var(--success-text); }
.toast--error .toast__icon { color: var(--danger-text); }
.toast--info .toast__icon { color: var(--info-text); }

.toast__text {
  flex: 1;
  font-size: var(--text-md);
  color: var(--text-primary);
  line-height: 1.4;
}

.toast__close {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-disabled);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.toast__close:hover { color: var(--text-primary); }
.toast__close svg { width: 16px; height: 16px; }

/* ═══════════════════════════════════════════════════════════
   FILTERS
   ═══════════════════════════════════════════════════════════ */

.filters-panel {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  flex-wrap: wrap;
}

.filters__group {
  flex-shrink: 0;
}

.filters__search {
  position: relative;
}

.filters__search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.filters__input {
  padding: var(--space-sm) var(--space-md);
  padding-left: 34px;
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  outline: none;
  width: 200px;
  transition: all var(--transition-fast);
}

.filters__input:focus {
  border-color: var(--border-focus);
  background: var(--bg-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.filters__select {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  outline: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-primary);
}

.filters__select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.filters__range {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.filters__range-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.filters__range-input {
  width: 100px;
  accent-color: var(--accent);
}

.filters__range-value {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  min-width: 28px;
  text-align: center;
  font-family: var(--font-mono);
}

.filters__reset {
  margin-left: auto;
}

/* ═══════════════════════════════════════════════════════════
   PAGINATION
   ═══════════════════════════════════════════════════════════ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-lg) 0;
}

.pagination__btn {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: 400;
  color: var(--text-secondary);
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pagination__btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.pagination__btn--active {
  background: var(--accent-light) !important;
  color: var(--accent) !important;
  font-weight: 500;
  border-color: var(--accent-subtle);
}

.pagination__btn--disabled,
.pagination__btn:disabled {
  color: var(--text-disabled);
  cursor: default;
}

.pagination__dots {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  color: var(--text-disabled);
  font-size: var(--text-md);
}

.pagination__info {
  text-align: center;
  padding-bottom: var(--space-sm);
}

/* ═══════════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}

.badge--new { background: var(--info-light); color: var(--info-text); }
.badge--contact { background: var(--accent-light); color: var(--accent); }
.badge--showing { background: var(--warning-light); color: var(--warning-text); }
.badge--negotiation { background: #FFF4E6; color: #D9480F; }
.badge--deal { background: var(--success-light); color: var(--success-text); }
.badge--closed { background: var(--bg-tertiary); color: var(--text-tertiary); }
.badge--lost { background: var(--danger-light); color: var(--danger-text); }

/* ═══════════════════════════════════════════════════════════
   PAGE HEADER
   ═══════════════════════════════════════════════════════════ */

.page-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.page-header h2 {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--text-primary);
}

.companies-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE для компонентов
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .filters-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .filters__input {
    width: 100%;
  }

  .filters__reset {
    margin-left: 0;
  }

  .toast-container {
    bottom: var(--space-lg);
    right: var(--space-lg);
    left: var(--space-lg);
  }

  .toast {
    min-width: auto;
    max-width: none;
  }

  .modal-overlay {
    padding: var(--space-lg);
  }

  .modal--large {
    max-width: none;
  }

  .card__field {
    flex-direction: column;
    gap: var(--space-xs);
  }

  .card__field-label {
    min-width: auto;
  }
}

@media (max-width: 480px) {
  .pagination__btn {
    min-width: 32px;
    height: 32px;
    font-size: var(--text-base);
  }
}
