:root {
  --color-primary: #0078d4;
  --color-primary-dark: #005a9e;
  --color-primary-light: rgba(0, 120, 212, 0.1);
  --color-success: #28a745;
  --color-error: #dc3545;
  --color-warning: #ffc107;
  --color-text: #1f1f1f;
  --color-text-secondary: #64748b;
  --color-text-muted: #94a3b8;
  --color-bg: #f6f8fb;
  --color-bg-card: #ffffff;
  --color-border: rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  
  color-scheme: light dark;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

/* ============================================
   APP LAYOUT
   ============================================ */

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

.app-header {
  flex-shrink: 0;
  padding: 16px 24px;
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.app-title {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
}

/* ============================================
   SEARCH FORM
   ============================================ */

.search-form {
  margin: 0;
}

.search-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.search-input-wrapper input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #ccc;
  border-radius: var(--radius-md);
  font-size: 15px;
  background: #ffffff;
  color: #1f1f1f;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input-wrapper input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.search-input-wrapper input::placeholder {
  color: var(--color-text-muted);
}

.submit-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.submit-button:hover {
  background: var(--color-primary-dark);
}

.submit-button:active {
  transform: scale(0.98);
}

.search-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.search-controls__radius {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-controls__label {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.search-controls__select {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--color-bg-card);
  color: var(--color-text);
  min-width: 64px;
}

.search-controls__filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  border: none;
  margin: 0;
  padding: 0;
}

.search-controls__checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
}

.search-controls__checkbox input {
  margin: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
}

/* Под картой: радиус (ползунок) и галочки */
.map-controls {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 10px 16px;
  background: var(--color-bg-card);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-card);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.04);
}

/* Класс map-controls--visible оставлен для совместимости (добавляется в showMap) */
.map-controls.map-controls--visible {
  display: flex;
}

.map-controls__radius {
  display: flex;
  align-items: center;
  gap: 10px;
}

.map-controls__label {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.map-controls__slider {
  width: 120px;
  min-width: 120px;
  height: 8px;
  accent-color: var(--color-primary);
}

.map-controls__value {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  min-width: 36px;
}

.map-controls__filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  border: none;
  margin: 0;
  padding: 0;
}

.map-controls__filters .map-controls__label {
  margin-right: 4px;
}

.map-controls__checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
}

.map-controls__checkbox input {
  margin: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
}

.submit-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.submit-button svg {
  flex-shrink: 0;
}

/* ============================================
   CONTENT WRAPPER (MAP + LIST)
   ============================================ */

.content-wrapper {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ============================================
   MAP SECTION
   ============================================ */

.map-section {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Область карты (карта + плейсхолдер); под ней всегда виден блок с ползунком и чекбоксами */
.map-area {
  flex: 1;
  min-height: 0;
  position: relative;
}

.map-container {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  z-index: 1;
}

.map-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8f4fc 0%, #f0f7fb 100%);
  z-index: 2;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.map-placeholder.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.map-placeholder__icon {
  color: var(--color-primary);
  opacity: 0.5;
  margin-bottom: 16px;
}

.map-placeholder__text {
  margin: 0;
  font-size: 15px;
  color: var(--color-text-secondary);
  text-align: center;
  padding: 0 20px;
}

/* Leaflet custom styles */
.leaflet-container {
  font-family: inherit;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.leaflet-popup-content {
  margin: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
}

/* Custom marker styles */
.pvz-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  color: white;
  font-size: 12px;
  font-weight: 700;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  cursor: pointer;
}

/* Hover state - легкое увеличение */
.pvz-marker.highlighted {
  transform: scale(1.15);
  box-shadow: var(--shadow-lg);
  filter: brightness(1.1);
}

/* Active state - выбран для просмотра (popup открыт) */
.pvz-marker.active {
  transform: scale(1.3);
  box-shadow: 0 0 0 4px rgba(0, 120, 212, 0.3), var(--shadow-lg);
  z-index: 1000 !important;
}

/* Selected state - окончательно выбран */
.pvz-marker.selected {
  transform: scale(1.3);
  background: var(--color-success) !important;
  box-shadow: 0 0 0 4px rgba(40, 167, 69, 0.3), var(--shadow-lg);
  z-index: 1001 !important;
}

.pvz-marker--post {
  background: #f03b24;
}

.pvz-marker--cdek {
  background: #008c3a;
}

.pvz-marker--yandex {
  background: #fc0;
  color: #1a1a1a;
}

/* Отделение Почты России соответствует адресу клиента */
.pvz-marker.pvz-marker--matches-address {
  box-shadow: 0 0 0 3px var(--color-success);
}

/* Client marker */
.client-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: #ff6b6b;
  border: 4px solid white;
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
}

.client-marker::after {
  content: '';
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
}

/* Popup content */
.pvz-popup {
  min-width: 220px;
  max-width: 280px;
}

.pvz-popup__title {
  font-weight: 600;
  font-size: 15px;
  margin: 0 0 6px;
  color: var(--color-text);
}

.pvz-popup__badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.pvz-popup__badge--matches {
  background: rgba(40, 167, 69, 0.2);
  color: #1e7e34;
}

.pvz-popup__code {
  display: inline-block;
  padding: 3px 10px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  font-family: 'Consolas', monospace;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 10px;
}

.pvz-popup__address {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin: 0 0 6px;
  line-height: 1.4;
}

.pvz-popup__worktime {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: 0 0 8px;
  line-height: 1.3;
}

.pvz-popup__distance {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 12px;
}

.pvz-popup__select {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-success);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.pvz-popup__select:hover {
  background: #218838;
  transform: translateY(-1px);
}

.pvz-popup__select:active {
  transform: translateY(0);
}

/* ============================================
   LIST SECTION
   ============================================ */

.list-section {
  width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-card);
  border-left: 1px solid var(--color-border);
  overflow: hidden;
}

.list-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.list-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

.results-count {
  font-size: 13px;
  color: var(--color-text-muted);
}

.results-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.list-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  text-align: center;
}

.list-empty-state p {
  margin: 0;
  font-size: 14px;
  color: var(--color-text-muted);
}

/* Loading state */
.list-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.list-loading::after {
  content: '';
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   PVZ CARD (COMPACT)
   ============================================ */

.pvz-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pvz-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--color-bg);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
}

.pvz-card:hover {
  background: white;
  border-color: var(--color-border);
  box-shadow: var(--shadow-sm);
}

/* Highlighted - при наведении */
.pvz-card.highlighted {
  background: white;
  border-color: #ccc;
  box-shadow: var(--shadow-sm);
}

/* Active - кликнули, смотрим на карте */
.pvz-card.active {
  background: white;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light), var(--shadow-md);
}

/* Selected - окончательно выбран */
.pvz-card.selected {
  background: rgba(40, 167, 69, 0.08);
  border-color: var(--color-success);
  box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.15);
}

.pvz-card.selected .pvz-card__index {
  background: var(--color-success) !important;
}

/* Карточка ОПС, соответствующего адресу клиента */
.pvz-card.pvz-card--matches-address {
  border-left: 4px solid var(--color-success);
}

.pvz-card__badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.pvz-card__badge--matches {
  background: rgba(40, 167, 69, 0.15);
  color: #1e7e34;
}

.pvz-card__header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pvz-card__index {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.pvz-card__index--post {
  background: #f03b24;
}

.pvz-card__index--cdek {
  background: #008c3a;
}

.pvz-card__index--yandex {
  background: #fc0;
  color: #1a1a1a;
}

.pvz-card__service {
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text);
}

.pvz-card__code {
  margin-left: auto;
  padding: 2px 8px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-sm);
  font-family: 'Consolas', monospace;
  font-size: 11px;
  color: var(--color-text-secondary);
}

.pvz-card__body {
  padding-left: 32px;
}

.pvz-card__address {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pvz-card__meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}

.pvz-card__distance {
  font-weight: 600;
  color: var(--color-primary);
}

.pvz-card__time {
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

/* ============================================
   NOTIFICATIONS
   ============================================ */

.pvz-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  color: white;
  background: var(--color-success);
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  opacity: 0;
  transform: translateY(-20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: 320px;
}

.pvz-notification--show {
  opacity: 1;
  transform: translateY(0);
}

.pvz-notification--error {
  background: var(--color-error);
}

.pvz-notification--success {
  background: var(--color-success);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 900px) {
  .content-wrapper {
    flex-direction: column;
  }
  
  .map-section {
    height: 50vh;
    min-height: 300px;
  }
  
  .list-section {
    width: 100%;
    height: 50vh;
    border-left: none;
    border-top: 1px solid var(--color-border);
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 12px 16px;
  }
  
  .app-title {
    font-size: 18px;
  }
  
  .search-input-wrapper {
    flex-direction: column;
  }
  
  .submit-button {
    justify-content: center;
  }
  
  .list-section {
    width: 100%;
  }
  
  .pvz-card__body {
    padding-left: 0;
  }
  
  .pvz-card__time {
    display: none;
  }
}

/* ============================================
   LEGACY SUPPORT (for old card styles if needed)
   ============================================ */

.pvz-card__footer {
  display: none;
}

.pvz-card__select-button {
  display: none;
}

.pvz-empty {
  margin: 0;
  padding: 24px;
  border-radius: var(--radius-lg);
  background: var(--color-bg);
  font-size: 14px;
  text-align: center;
  color: var(--color-text-secondary);
}

.pvz-empty--error {
  background: #fff5f5;
  border: 1px solid #fecaca;
  color: #991b1b;
  text-align: left;
}

.pvz-empty__title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}

.pvz-empty__hint {
  margin: 0;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  color: #7f1d1d;
}

.pvz-card__select {
  margin-top: 10px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.pvz-card__select:hover {
  background: var(--color-primary-dark);
}
