/* ===== Переменные темы ===== */
:root {
  --primary: #1C82AD;
  --primary-dark: #045273;
  --bg: #eef4f8;
  --card: #ffffff;
  --text: #1f2d3d;
  --text-soft: #6b7c8f;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(4, 82, 115, 0.12);
}

/* ===== Сброс ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 0; /* mobile: без отступов — виджет на весь экран */
}

/* ===== Контейнер виджета (mobile-first: на весь экран) ===== */
.widget {
  position: relative;
  width: 100%;
  height: 100vh;        /* mobile: во весь экран (запасной вариант) */
  height: 100dvh;       /* динамическая высота — учитывает адресную строку iOS */
  background: var(--card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== Кнопка закрытия (красный крестик справа вверху) ===== */
.widget__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #e02424;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
}
.widget__close:hover { background: #fff; }
.widget__close:active { transform: scale(0.92); }

/* Область контента растягивается и прокручивается — высота виджета не меняется */
.widget__body {
  flex: 1;
  overflow-y: auto;
}

/* ===== Шапка с градиентом ===== */
.widget__header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 24px 20px;
  text-align: center;
}
.widget__title { font-size: 22px; letter-spacing: 1px; }
.widget__subtitle { font-size: 14px; opacity: 0.9; margin-top: 4px; }

/* ===== Индикатор шагов ===== */
.steps {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 16px 0 4px;
}
.steps__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #cdd9e3;
  transition: all 0.3s;
}
.steps__dot.is-active {
  background: var(--primary);
  width: 22px;
  border-radius: 4px;
}

/* ===== Тело ===== */
.widget__body { padding: 20px; }

.screen__title {
  font-size: 18px;
  margin-bottom: 16px;
  text-align: center;
}

/* ===== Шапка «Приём ведёт …» (шаг даты при записи к врачу) ===== */
.doctor-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  margin-bottom: 18px;
  background: #f2f8fb;
  border: 1px solid #e3edf4;
  border-radius: 14px;
}
.doctor-banner__photo {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.doctor-banner__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.doctor-banner__label {
  font-size: 12px;
  color: var(--text-soft);
}
.doctor-banner__name {
  font-size: 16px;
  font-weight: 600;
  color: #026D9A;
  line-height: 1.25;
}
.doctor-banner__spec {
  font-size: 13px;
  color: var(--text-soft);
}
.doctor-banner__date {
  margin-left: auto;
  flex-shrink: 0;
  padding-left: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #026D9A;
  white-space: nowrap;
}

/* ===== Строка поиска (шаг 1) ===== */
.search {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.search__icon {
  position: absolute;
  left: 14px;
  font-size: 15px;
  opacity: 0.6;
  pointer-events: none;
}
.search__input {
  width: 100%;
  padding: 13px 40px 13px 40px;
  border: 2px solid #e3edf4;
  border-radius: 12px;
  font-size: 15px;
  outline: none;
  transition: border 0.2s;
}
.search__input:focus { border-color: var(--primary); }
.search__clear {
  position: absolute;
  right: 8px;
  width: 28px; height: 28px;
  border: none;
  border-radius: 50%;
  background: #eef4f8;
  color: var(--text-soft);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.search__clear:hover { background: #e0eaf1; }
.search__label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-soft);
  margin: 6px 2px 10px;
}

/* ===== Сетка карточек (mobile-first: одна колонка) ===== */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

/* ===== Карточки выбора ===== */
.card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: var(--card);
  border: 2px solid #e3edf4;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}
/* В сетке отступ задаёт gap, поэтому margin у карточек убираем */
.card-grid .card { margin-bottom: 0; height: 100%; }
/* hover только на устройствах с мышью — на тач-экранах он "залипает" после тапа */
@media (hover: hover) {
  .card:hover { border-color: var(--primary); transform: translateY(-2px); }
}
.card__icon {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
/* Иконка-фото врача: убираем градиент, показываем картинку целиком */
.card__icon--photo {
  width: 52px; height: 52px;
  background: #e3edf4;
  padding: 0;
  overflow: hidden;
}
.card__icon--photo img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
/* Иконка-картинка направления: без подложки, картинка целиком */
.card__icon--contain {
  background: transparent;
}
.card__icon--contain img {
  object-fit: contain;
}
.card__title { font-weight: 600; font-size: 17px; color: #026D9A; display: inline-block; margin-bottom: 4px; }
.card__desc { font-size: 14px; color: var(--text-soft); }

/* ===== Сетка времени / дат ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.chip {
  padding: 12px 0;
  border: 2px solid #e3edf4;
  border-radius: 12px;
  background: #fff;
  color: #026D9A;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
@media (hover: hover) {
  .chip:hover { border-color: var(--primary); transform: translateY(-2px); }
}
.chip.is-selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.chip:disabled { opacity: 0.4; cursor: not-allowed; }
.chip__weekday { display: inline-block; margin-bottom: 6px; }
.chip__month { font-size: 12px; color: #026D9A; text-transform: uppercase; }
.chip.is-selected .chip__month { color: #fff; }

/* ===== Форма ===== */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text-soft); }
.field input {
  width: 100%;
  padding: 14px;
  border: 2px solid #e3edf4;
  border-radius: 12px;
  font-size: 15px;
  outline: none;
  transition: border 0.2s;
}
.field input:focus { border-color: var(--primary); }

/* Телефон: серый "хвост" маски поверх поля ввода */
.phone-field { position: relative; }
.phone-field__input,
.phone-field__mask {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  letter-spacing: 1px;
  line-height: 1.4;
}
.phone-field__mask {
  position: absolute;
  left: 0;
  top: 0;
  padding: 14px;
  border: 2px solid transparent;
  color: #9bb3c2;            /* серый цвет маски */
  white-space: pre;          /* сохраняем пробелы выравнивания */
  pointer-events: none;
}

.field .error { color: #d64545; font-size: 12px; margin-top: 4px; display: none; }
.field.is-invalid input { border-color: #d64545; }
.field.is-invalid .error { display: block; }

/* ===== Согласие на обработку персональных данных ===== */
.consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 20px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-soft);
  cursor: pointer;
}
.consent input {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  accent-color: var(--primary);
  cursor: pointer;
}
.consent.is-invalid { color: #d64545; }
.consent.is-invalid input { outline: 1px solid #d64545; outline-offset: 1px; }
.consent__link { color: var(--primary); text-decoration: underline; }

/* ===== Большие кнопки ===== */
.btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn--primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
}
.btn--primary:disabled { opacity: 0.5; cursor: not-allowed; }
/* mobile: кнопка "Назад" — закреплённый нижний бар во всю ширину */
.btn--ghost {
  background: #fff;
  color: var(--primary);
  margin: 0;
  width: 100%;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom)); /* не прячется за панелью iOS */
  border-top: 1px solid #e3edf4;
  flex-shrink: 0;
}
.btn--outline {
  background: #fff;
  color: var(--primary);
  border: 2px solid var(--primary);
  padding: 13px;
  font-size: 15px;
  margin-bottom: 16px;
}
@media (hover: hover) {
  .btn--outline:hover {
    background: var(--primary);
    color: #fff;
  }
}

/* ===== Сводка / подтверждение ===== */
.summary {
  background: #f4f9fc;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.summary__row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #e3edf4;
  font-size: 14px;
}
.summary__row:last-child { border-bottom: none; }
.summary__row span:first-child { color: var(--text-soft); }
.summary__row span:last-child { font-weight: 600; }

/* ===== Экран успеха ===== */
.success { text-align: center; padding: 20px 0; }
.success__icon {
  width: 70px; height: 70px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
}

/* ===== Планшет/десктоп: чуть шире сетки времени ===== */
@media (min-width: 600px) {
  body { padding: 16px; }
  .widget {
    max-width: 700px;
    height: calc(100vh - 32px); /* десктоп: карточка во всю высоту минус отступы */
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  /* Встроен в iframe на сайте: заполняем всю панель без полей и скруглений */
  html.embedded body { padding: 0; }
  html.embedded .widget {
    max-width: none;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
  .grid { grid-template-columns: repeat(4, 1fr); }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  /* десктоп: заголовок карточки на 1 меньше, чем на мобильной */
  .card__title { font-size: 16px; }
  /* десктоп: кнопка "Назад" снова обычная, внутри карточки */
  .btn--ghost {
    background: transparent;
    margin: 0 20px 20px;
    width: calc(100% - 40px);
    padding: 12px;
    border-top: none;
  }
}