/* ================================================================
   eldauto.ru — Модальные окна, тосты и выезжающие панели (modals.css)
   Версия: v=16 (Иконка активного региона в светлой теме в тёмном цвете)
   ----------------------------------------------------------------
   Что здесь:
     - .modal-overlay, .modal, .modal-header, .close-btn, .tabs, .form-group
     - .toast, .toast.show, .toast.with-action, .toast-action-*
     - .fav-panel-overlay, .fav-panel* (боковая панель избранного)
     - .modal-region, .region-search-wrap, .region-list, .region-item*
     - .info-sheet-overlay, .info-sheet* (мобильная инфо-шторка)
     - @media (max-width: 768px) адаптация .modal (slideUp)
   ================================================================ */

/* ==========================================
   МОДАЛЬНЫЕ ОКНА (Вход, Регион)
   ========================================== */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay-bg); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 99999 !important; padding: 1rem; }
.modal-overlay.active { display: flex; }
.modal { background: var(--card-bg); border: 1px solid var(--border); padding: 1.5rem; border-radius: var(--radius); width: 100%; max-width: 460px; max-height: min(90dvh, 640px); overflow-y: auto; box-shadow: var(--shadow-hover); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-header h3 { font-size: 1.2rem; margin: 0; }
.close-btn { background: none; border: none; font-size: 1.75rem; width: 40px; height: 40px; color: var(--text-muted); display: flex; align-items: center; justify-content: center; }
.close-btn:hover { color: var(--text); }
.close-btn svg { width: 24px; height: 24px; }
.tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.tab { flex: 1; text-align: center; padding: 0.6rem 1rem; cursor: pointer; color: var(--text-muted); border-radius: 8px; font-weight: 500; background: none; border: none; font-family: inherit; font-size: 1rem; }
.tab.active { color: var(--text); background: var(--input-bg); }
.tab:hover { color: #ff4d4d; background: var(--input-bg); }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.45rem; color: var(--text); font-weight: 500; font-size: 0.95rem; }
.form-group input { width: 100%; min-height: 46px; background: var(--input-bg); color: var(--text); padding: 0.75rem 0.9rem; border: 1px solid var(--border); border-radius: 10px; font-size: 1rem; }
.form-group input:focus { outline: none; border-color: var(--primary); background: var(--filter-focus-bg); }
.form-group input:-webkit-autofill, .form-group input:-webkit-autofill:hover, .form-group input:-webkit-autofill:focus, .form-group input:-webkit-autofill:active { -webkit-box-shadow: 0 0 0 30px var(--input-bg) inset !important; -webkit-text-fill-color: var(--text) !important; transition: background-color 5000s ease-in-out 0s; }

/* ==========================================
   TOAST (Всплывающие уведомления)
   ========================================== */
.toast { 
  position: fixed; 
  left: 50%; 
  bottom: 24px; 
  transform: translateX(-50%) translateY(20px); 
  background: #1e293b !important; 
  color: #ffffff !important;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 12px 24px; 
  border-radius: 10px; 
  font-size: 0.95rem; 
  box-shadow: 0 8px 20px rgba(0,0,0,0.3); 
  opacity: 0; 
  pointer-events: none; 
  transition: opacity 0.25s ease, transform 0.25s ease; 
  z-index: 99999; 
  max-width: calc(100vw - 2rem); 
  text-align: center; 
  font-weight: 500;
}
.toast.show { 
  opacity: 1; 
  transform: translateX(-50%) translateY(0); 
}
/* ==========================================
   ПАНЕЛЬ ИЗБРАННОГО (Выезжающая справа)
   ========================================== */
.fav-panel-overlay { position: fixed; inset: 0; background: var(--overlay-bg); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 900; }
.fav-panel-overlay.active { opacity: 1; pointer-events: auto; }
.fav-panel { position: fixed; top: 0; right: 0; height: 100dvh; width: min(420px, 100%); background: var(--card-bg); border-left: 1px solid var(--border); box-shadow: var(--shadow-hover); display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1); z-index: 950; pointer-events: none; }
.fav-panel.open { transform: translateX(0); pointer-events: auto; }
.fav-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.fav-panel-header h3 { font-size: 1.15rem; margin: 0; }
.fav-panel-body { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.fav-empty { text-align: center; color: var(--text-muted); padding: 2.5rem 1rem; font-size: 0.95rem; line-height: 1.5; }
.fav-empty .fav-empty-icon { font-size: 2.5rem; color: var(--fav-inactive); display: block; margin-bottom: 0.75rem; }
.fav-item { display: flex; gap: 0.75rem; padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--input-bg); align-items: flex-start; }
.fav-item-img { width: 64px; height: 48px; border-radius: 6px; background: var(--car-img-bg); flex-shrink: 0; }
.fav-item-info { flex: 1; min-width: 0; }
.fav-item-title { font-weight: 600; font-size: 0.95rem; color: var(--text); margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-item-specs { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-item-price { font-weight: 700; color: var(--text); font-size: 0.95rem; }
.fav-item-remove { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; padding: 4px; line-height: 1; border-radius: 6px; }
.fav-item-remove:hover { color: #ff4d4d; background: var(--card-bg); }
.fav-panel-footer { display: flex; align-items: center; gap: 0.5rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.fav-panel-footer .filter-link { font-size: 13px; }
.fav-panel-footer .btn-primary-large { flex: 1; padding: 0.7rem 1rem; min-height: 44px; font-size: 0.95rem; min-width: 140px; }

/* ==========================================
   МОДАЛКА ВЫБОРА РЕГИОНА И ШТОРКА ИНФО
   ========================================== */
.modal-region { max-width: 500px; max-height: min(80dvh, 600px); display: flex; flex-direction: column; padding: 0; }
.modal-region .modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); margin-bottom: 0; flex-shrink: 0; display: flex; justify-content: space-between; align-items: center; }
.modal-region .modal-header h3 { font-size: 1.15rem; font-weight: 700; }
.region-search-wrap { padding: 1rem 1.5rem 0.5rem 1.5rem; flex-shrink: 0; }
.region-search-wrap input { width: 100%; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 1rem; outline: none; transition: all 0.2s; }
.region-search-wrap input:focus { border-color: var(--primary); background: var(--card-bg); }
.region-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0.5rem 1.5rem 1.5rem 1.5rem; }
.region-item { text-align: left; background: transparent; border: none; padding: 12px 14px; border-radius: 10px; font-size: 1rem; color: var(--text); cursor: pointer; transition: background 0.15s ease, color 0.15s ease; width: 100%; display: flex; align-items: center; justify-content: space-between; position: relative; }
.region-item:hover { background: var(--input-bg); color: #ff4d4d; }
.region-item.active { background: var(--input-bg); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }
.region-item.active::after { content: ''; display: inline-block; width: 18px; height: 18px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230f172a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'%3E%3C/path%3E%3Ccircle cx='12' cy='10' r='3'%3E%3C/circle%3E%3C/svg%3E"); background-size: contain; background-repeat: no-repeat; background-position: center; }
.region-list::-webkit-scrollbar { width: 6px; }
.region-list::-webkit-scrollbar-track { background: transparent; }
.region-list::-webkit-scrollbar-thumb { background-color: var(--border); border-radius: 10px; }
.region-list::-webkit-scrollbar-thumb:hover { background-color: var(--text-muted); }

/* ==========================================
   ШТОРКА ИНФО (Mobile)
   ========================================== */
.info-sheet-overlay { position: fixed; inset: 0; background: var(--overlay-bg); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 1100; }
.info-sheet-overlay.active { opacity: 1; pointer-events: auto; }
.info-sheet { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card-bg); border-top: 1px solid var(--border); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-hover); padding: 1rem 1.25rem calc(1rem + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform 0.32s cubic-bezier(0.34, 1.2, 0.64, 1); z-index: 1150; }
.info-sheet.open { transform: translateY(0); }
.info-sheet-top { display: flex; justify-content: space-between; align-items: center; padding-bottom: 1rem; border-bottom: 1px solid var(--border); margin-bottom: 0.5rem; }
.info-sheet-top h3 { font-size: 1.1rem; margin: 0; }
.info-item { display: flex; align-items: center; gap: 12px; width: 100%; background: transparent; border: none; padding: 14px 8px; border-bottom: 1px solid var(--border); font-size: 1rem; color: var(--text); text-align: left; transition: background 0.15s ease, color 0.15s ease; }
.info-item:last-child { border-bottom: none; }
.info-item:hover { background: var(--input-bg); color: var(--primary); }
.info-item-icon { font-size: 1.3rem; width: 24px; text-align: center; flex-shrink: 0; }

/* ==========================================
   МОБИЛЬНАЯ АДАПТАЦИЯ МОДАЛОК (до 768px)
   ========================================== */
@media (max-width: 768px) {
  .modal {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 95dvh !important;
    border-radius: 20px 20px 0 0 !important;
    position: absolute;
    bottom: 0;
    padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom)) !important;
    animation: slideUp 0.3s ease-out;
  }
  
  @keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}

/* ================================================================
   Дополнение к .toast (Шаг 3, #79)
   ----------------------------------------------------------------
   Базовый .toast уже есть выше в этом файле (фон #1e293b, белый текст).
   Здесь — то, чего не хватало для канона showToast:
     - pointer-events: auto, чтобы можно было кликнуть кнопку действия;
     - .with-action / .toast-action-content / .toast-action-btn для
       тоста с кнопкой (listing.html: «Перейти к списку»).
   Эти же правила раньше были inline в listing.html — теперь канон.
   ================================================================ */

.toast.show {
  pointer-events: auto;
}

.toast.with-action {
  padding: 10px 16px;
  border-radius: 12px;
  width: auto;
  min-width: 300px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.toast-action-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.toast-action-btn {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: background 0.2s;
  cursor: pointer;
}

.toast-action-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ================================================================
   Мобильная адаптация всплывающих уведомлений (.toast) (v=150)
   Поднимаем тост над нижней панелью навигации #globalBottomNav
   ================================================================ */
@media (max-width: 768px) {
  .toast {
    bottom: calc(82px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
    padding: 10px 16px;
    font-size: 0.88rem;
    line-height: 1.35;
    border-radius: 12px;
    z-index: 100050;
  }

  .toast.with-action {
    min-width: 0;
    width: calc(100vw - 24px);
    max-width: 420px;
    padding: 10px 14px;
  }

  .toast-action-content {
    gap: 10px;
    text-align: left;
  }

  .toast-action-btn {
    padding: 6px 10px;
    font-size: 0.82rem;
    flex-shrink: 0;
  }

  /* В открытом чате нижняя панель скрыта, а снизу поле ввода и клавиатура — показываем тост аккуратно сверху */
  body.chat-open .toast {
    top: calc(68px + env(safe-area-inset-top));
    bottom: auto;
    transform: translateX(-50%) translateY(-16px);
  }

  body.chat-open .toast.show {
    transform: translateX(-50%) translateY(0);
  }
}


/* === Адаптация модалок под iOS Safari (запрет авто-зума < 16px) и Android (100dvh + safe-area) (v=166) === */
@media (max-width: 768px) {
  .modal input,
  .modal select,
  .modal textarea,
  .form-group input,
  .region-search-wrap input {
    font-size: 16px !important;
  }
  .modal {
    max-height: calc(100dvh - env(safe-area-inset-top) - 16px) !important;
  }
}
