/* ============== DOCTOR MODAL — выведена за пределы @layer для приоритета ============ */

.doctor-card-button {
  appearance: none;
  background: white;
  border: 1px solid #e9ecef;
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
  font: inherit;
  color: inherit;
  display: block;
}
.doctor-card-button:hover,
.doctor-card-button:focus-visible {
  border-color: var(--color-brand);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(22, 142, 149, 0.12);
}
.doctor-card-button .doctor-card-link {
  color: var(--color-brand);
  font-weight: 600;
  font-size: 12px;
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* dialog: сброс встроенных стилей + полноэкранный контейнер */
dialog.doctor-modal {
  /* НЕ ставим display — браузер сам скроет через display:none когда закрыт */
  border: none;
  padding: 0;
  background: transparent;
  color: inherit;
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  margin: 0;
  inset: 0;
  overflow: visible;
  /* pointer-events не отключаем — иначе клик по пустому полю не закроет диалог */
}
dialog.doctor-modal[open] {
  display: flex;
  align-items: flex-end;       /* mobile-first: bottom sheet */
  justify-content: center;
}

dialog.doctor-modal::backdrop {
  background: rgba(15, 25, 35, 0);
  transition: background 0.25s ease, -webkit-backdrop-filter 0.25s ease, backdrop-filter 0.25s ease;
  -webkit-backdrop-filter: blur(0px);
  backdrop-filter: blur(0px);
}
dialog.doctor-modal.open::backdrop {
  background: rgba(15, 25, 35, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

/* Sheet — видимый белый контейнер. Mobile-first: full-width внизу, slide-up. */
.doctor-modal-sheet {
  position: relative;
  width: 100%;
  max-height: 92vh;
  background: white;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
dialog.doctor-modal.open .doctor-modal-sheet {
  transform: translateY(0);
}

.doctor-modal-handle {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  z-index: 3;
  pointer-events: none;
}

.doctor-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  border: none;
  color: var(--color-ink-deep);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 4;
  transition: background 0.15s, transform 0.15s;
}
.doctor-modal-close:hover { background: white; transform: scale(1.05); }

.doctor-modal-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(22, 142, 149, 0.45) transparent;
}
.doctor-modal-scroll::-webkit-scrollbar {
  width: 8px;
}
.doctor-modal-scroll::-webkit-scrollbar-track {
  background: transparent;
  margin: 12px 0;
}
.doctor-modal-scroll::-webkit-scrollbar-thumb {
  background-color: rgba(22, 142, 149, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.doctor-modal-scroll::-webkit-scrollbar-thumb:hover {
  background-color: rgba(22, 142, 149, 0.65);
}

/* Контент */
.doctor-modal-content article {
  display: block;
}

/* Боковая колонка mobile: фото + документы стоят сверху, текст снизу */
.doctor-modal-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0;
}

.doctor-modal-photo {
  aspect-ratio: 4 / 5;
  background: var(--color-brand-pale);
  overflow: hidden;
  max-height: 56vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.doctor-modal-photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.doctor-modal-body {
  padding: 20px;
}
.doctor-modal-body h2 {
  font-size: clamp(22px, 4vw, 28px);
  line-height: 1.2;
  margin-bottom: 8px;
}

dl.doctor-modal-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: var(--color-brand-pale);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 0 0 22px 0;
}
dl.doctor-modal-facts dt {
  font-size: 12px;
  color: var(--color-ink-soft);
  margin: 0 0 2px 0;
}
dl.doctor-modal-facts dd {
  margin: 0;
  font-weight: 700;
  color: var(--color-brand-dark);
  font-size: 16px;
}

.doctor-modal-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-ink-deep);
  margin: 18px 0 8px 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.doctor-modal-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.doctor-modal-list li {
  position: relative;
  padding-left: 18px;
  margin-bottom: 6px;
  color: var(--color-ink-soft);
  line-height: 1.55;
}
.doctor-modal-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 9px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--color-brand);
}
.doctor-modal-text {
  color: var(--color-ink-soft);
  line-height: 1.6;
}

/* DESKTOP — центрированное окно, фото слева, текст справа */
@media (min-width: 641px) {
  dialog.doctor-modal[open] {
    align-items: center;
  }
  .doctor-modal-handle { display: none; }
  .doctor-modal-sheet {
    width: calc(100% - 32px);
    max-width: min(1080px, calc(100vw - 64px));
    max-height: 88vh;
    border-radius: 24px;
    transform: scale(0.96) translateY(8px);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    padding-bottom: 0;
  }
  dialog.doctor-modal.open .doctor-modal-sheet {
    transform: scale(1) translateY(0);
    opacity: 1;
  }

  /* Сетка: side-колонка слева 320px, текст справа */
  .doctor-modal-content article {
    display: grid;
    grid-template-columns: 320px 1fr;
    align-items: start;
  }
  .doctor-modal-side {
    padding: 24px 0 24px 24px;
  }
  .doctor-modal-photo {
    aspect-ratio: 4 / 5;
    width: 100%;
    max-height: none;
    border-radius: 14px;
  }
  .doctor-modal-body {
    padding: 28px 32px 32px;
  }
}

/* Документы и сертификаты */
.doctor-modal-docs {
  padding: 0 20px;
}
.doctor-modal-docs .doctor-modal-heading {
  margin: 0 0 8px 0;
}
.doctor-modal-docs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* 2 в ряд везде */
  gap: 8px;
}
.doctor-modal-docs-grid button {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  color: inherit;
  margin: 0;
  padding: 0;
  display: block;
  aspect-ratio: 3 / 4;
  border: 1px solid #e9ecef;
  border-radius: 10px;
  overflow: hidden;
  background: var(--color-bg-soft);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  cursor: pointer;
  width: 100%;
}
.doctor-modal-docs-grid button:hover,
.doctor-modal-docs-grid button:focus-visible {
  border-color: var(--color-brand);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(22, 142, 149, 0.15);
}
.doctor-modal-docs-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}
.doctor-modal-docs-grid button::after {
  content: '';
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23168e95' stroke-width='2.5' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='M21 21l-5-5'/></svg>") center/14px no-repeat;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.doctor-modal-docs-grid button:hover::after,
.doctor-modal-docs-grid button:focus-visible::after { opacity: 1; }

/* На мобиле в side-колонке документы через padding к фото */
@media (min-width: 641px) {
  .doctor-modal-docs {
    padding: 0;
  }
}

/* ============== CERTIFICATE THUMBNAILS на главной =================
   Все 4 превью одной высоты, картинка по центру, подпись сверху одной линией. */
.cert-thumb {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid #eef0f2;
  border-radius: 8px;
  padding: 4px;
  overflow: hidden;
}
.cert-thumb img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}
.cert-caption {
  margin: 12px 0 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--color-ink-soft);
  text-align: center;
  min-height: 2.7em;
  width: 100%;
}
@media (min-width: 768px) {
  .cert-thumb { height: 130px; }
}

/* ============== LIGHTBOX (просмотр документов) ============== */
dialog.lightbox {
  /* НЕ ставим display здесь — иначе native dialog не скрывается когда закрыт */
  border: none;
  padding: 0;
  background: transparent;
  color: inherit;
  max-width: none;
  max-height: none;
  width: 100vw;
  height: 100vh;
  margin: 0;
  inset: 0;
  overflow: hidden;
}
/* Видим только когда явно открыт через showModal() */
dialog.lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}

dialog.lightbox::backdrop {
  background: rgba(0, 0, 0, 0);
  transition: background 0.2s ease;
}
dialog.lightbox.open::backdrop {
  background: rgba(0, 0, 0, 0.9);
}

.lightbox-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(92vw, 100% - 120px);  /* оставляем место под боковые стрелки на десктопе */
  max-width: 1100px;
  height: min(86vh, 100% - 80px);  /* отступ под счётчик и кнопку закрытия */
  cursor: zoom-out;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  background: white;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
  cursor: default;
  pointer-events: auto;
}
dialog.lightbox.open .lightbox-img {
  opacity: 1;
  transform: scale(1);
}

.lightbox-close,
.lightbox-nav {
  position: fixed;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  border: none;
  color: #1a2230;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  transition: background 0.15s ease, transform 0.15s ease;
}
.lightbox-close:hover,
.lightbox-nav:hover { background: white; transform: scale(1.05); }

.lightbox-close {
  top: max(12px, env(safe-area-inset-top, 0));
  right: max(12px, env(safe-area-inset-right, 0));
}

.lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
}
.lightbox-nav:hover { transform: translateY(-50%) scale(1.05); }
.lightbox-prev { left: max(12px, env(safe-area-inset-left, 0)); }
.lightbox-next { right: max(12px, env(safe-area-inset-right, 0)); }

.lightbox-counter {
  position: fixed;
  bottom: max(20px, calc(env(safe-area-inset-bottom, 0) + 12px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: white;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  z-index: 10;
}

@media (max-width: 640px) {
  .lightbox-stage {
    width: 96vw;
    height: 78vh;
  }
  .lightbox-nav {
    bottom: max(16px, calc(env(safe-area-inset-bottom, 0) + 8px));
    top: auto;
    transform: none;
  }
  .lightbox-nav:hover { transform: scale(1.05); }
  .lightbox-prev { left: 16px; }
  .lightbox-next { right: 16px; }
  .lightbox-counter {
    bottom: max(28px, calc(env(safe-area-inset-bottom, 0) + 18px));
  }
}

/* Блокировка прокрутки реализована в JS (position:fixed на body).
   .modal-locked нужен только для запрета overscroll touch-action. */
html.modal-locked {
  overscroll-behavior: none;
  touch-action: none;
}

/* ============== COOKIE BANNER ============== */
.cookie-banner {
  position: fixed;
  z-index: 60;
  left: 12px;
  right: 12px;
  bottom: max(12px, calc(env(safe-area-inset-bottom, 0) + 12px));
  background: white;
  border: 1px solid #e9ecef;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.cookie-banner.cookie-banner-visible {
  opacity: 1;
  transform: translateY(0);
}
.cookie-banner-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-ink-soft);
}
.cookie-banner .cookie-link {
  color: var(--color-brand-dark);
  font-weight: 600;
}
.cookie-accept {
  align-self: flex-end;
  min-height: 40px !important;
  padding: 8px 22px !important;
  font-size: 14px !important;
}
@media (min-width: 641px) {
  .cookie-banner {
    flex-direction: row;
    align-items: center;
    padding: 14px 18px;
  }
  .cookie-banner-text { flex: 1; }
}
/* На мобиле над sticky CTA-плашкой не лезем */
@media (max-width: 768px) {
  .cookie-banner {
    bottom: max(76px, calc(env(safe-area-inset-bottom, 0) + 76px));
  }
}

/* ============== BOOKING MODAL — наследует базу .doctor-modal ============== */
.booking-modal-body {
  padding: 28px 20px 20px;
}
.booking-modal-body h2 {
  font-size: clamp(22px, 4vw, 30px);
  line-height: 1.2;
}

@media (min-width: 641px) {
  /* На десктопе модалка записи компактнее основной — форма не любит широкое */
  dialog.booking-modal .booking-modal-sheet {
    max-width: 640px;
  }
  .booking-modal-body {
    padding: 44px 56px 36px;
  }
  .booking-modal-body h2 {
    font-size: 30px;
  }
  .booking-modal-body input[type="text"],
  .booking-modal-body input[type="tel"],
  .booking-modal-body textarea {
    font-size: 17px;
    padding: 14px 16px;
  }
  .booking-modal-body button[type="submit"] {
    font-size: 17px;
    padding: 16px 28px;
    min-height: 56px;
  }
}
