/* Loan-request modal — overlay form for collecting passport/registration/selfie
   photos plus identity + loan-terms fields. Three steps managed by JS:
   form → confirm → success. */

.loan-modal {
  position: fixed;
  /* `inset` поддерживается всеми современными браузерами, но для подстраховки
     перед старыми мобильными webview оставляем явные top/right/bottom/left. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 1000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(40, 45, 60, 0.55);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-family: Rubik, Roboto, Helvetica, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.loan-modal[hidden] { display: none; }

.loan-modal__panel {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  max-width: 720px;
  width: 100%;
  /* iOS Safari: 100vh учитывает URL-bar и панель внизу — модалка обрезается.
     `dvh` использует динамическую высоту вьюпорта; для браузеров без dvh
     остаётся прежний vh-фолбэк. */
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.loan-modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: #f4f6fb;
  color: #778095;
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  z-index: 2;
  -webkit-appearance: none;
          appearance: none;
  -webkit-tap-highlight-color: transparent;
}
.loan-modal__close:hover { background: #d9dce3; }
.loan-modal__close:focus-visible {
  outline: 2px solid #1fadff;
  outline-offset: 2px;
}

.loan-modal__body {
  padding: 32px 28px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* учёт нижней home-indicator на iPhone */
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}

/* Планшет: убираем огромные поля, выходим на 2 колонки в файловых тайлах */
@media (max-width: 900px) {
  .loan-modal { padding: 16px; }
  .loan-modal__body { padding: 28px 20px; }
}

@media (max-width: 600px) {
  .loan-modal { padding: 0; }
  .loan-modal__panel {
    border-radius: 0;
    max-width: 100%;
    /* На телефоне модалка занимает весь экран — снова dvh + vh-фолбэк */
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
  }
  .loan-modal__body {
    /* верхний отступ — чтобы крестик не залезал под notch / status bar */
    padding: max(56px, calc(env(safe-area-inset-top) + 48px)) 16px
             max(24px, env(safe-area-inset-bottom));
  }
  .loan-modal__close {
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
  }
}

.loan-modal__step[hidden] { display: none; }

.loan-modal__title {
  font-size: 22px;
  font-weight: 500;
  color: #282d3c;
  margin-bottom: 8px;
}

.loan-modal__subtitle {
  font-size: 14px;
  color: #778095;
  margin-bottom: 24px;
}

/* ---- file uploads --------------------------------------------------------- */

.loan-modal__uploads {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

/* Планшет: 2 в ряд + один на новой строке. Лучше, чем три узких или один длинный. */
@media (max-width: 900px) {
  .loan-modal__uploads { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .loan-modal__uploads { grid-template-columns: 1fr; }
}

.loan-modal__upload {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 2px dashed #a3abbd;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  min-height: 120px;
  background: #f4f6fb;
  -webkit-tap-highlight-color: transparent;
  /* Длинные имена файлов на мобильном ломали грид — обрезаем. */
  overflow: hidden;
  word-break: break-word;
}
.loan-modal__upload:hover { border-color: #1fadff; background: #eef7ff; }
.loan-modal__upload.has-files { border-color: #65c466; border-style: solid; background: #eafbe7; }

.loan-modal__upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.loan-modal__upload-title {
  font-size: 14px;
  font-weight: 500;
  color: #282d3c;
}

.loan-modal__upload-hint {
  font-size: 12px;
  color: #778095;
}

.loan-modal__upload-preview {
  margin-top: auto;
  font-size: 12px;
  color: #1fadff;
  word-break: break-all;
}

/* ---- form fields ---------------------------------------------------------- */

.loan-modal__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .loan-modal__grid { grid-template-columns: 1fr; gap: 10px; }
}

.loan-modal__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.loan-modal__field--full { grid-column: 1 / -1; }

.loan-modal__field label {
  font-size: 12px;
  font-weight: 500;
  color: #778095;
  padding-left: 4px;
}

.loan-modal__field input,
.loan-modal__field select {
  background: #f4f6fb;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #282d3c;
  font-family: inherit;
  /* iOS Safari масштабирует страницу при фокусе на input < 16px. Держим 16px. */
  font-size: 16px;
  padding: 14px 16px;
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
  /* Сбрасываем нативную стилизацию iOS, чтобы тени и скругления выглядели одинаково. */
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  /* iOS не показывает рамку без явного box-sizing — фиксируем. */
  box-sizing: border-box;
  max-width: 100%;
}

/* Дата на iOS подхватывает тёмные шрифты системного календаря — выравниваем. */
.loan-modal__field input[type="date"] {
  min-height: 50px; /* высота как у обычных полей */
  line-height: 1.2;
}

.loan-modal__field input:focus,
.loan-modal__field select:focus { border-color: #1fadff; }

/* Only flag an invalid input after the user has actually interacted with it
   (data-touched is set on blur by landing.js). Avoids painting every empty
   required field red on initial open. */
.loan-modal__field input[data-touched]:invalid {
  border-color: #ea4e3d;
}

/* ---- actions -------------------------------------------------------------- */

.loan-modal__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
}

.loan-modal__primary,
.loan-modal__secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Минимум 44px — Apple HIG / Material 48dp. 52px — комфортно для пальца. */
  min-height: 52px;
  padding: 0 16px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
  -webkit-appearance: none;
          appearance: none;
  -webkit-tap-highlight-color: transparent;
  /* Без этого Safari иногда рисует серый фон у <a>-кнопок. */
  -webkit-user-select: none;
          user-select: none;
}
.loan-modal__primary:focus-visible,
.loan-modal__secondary:focus-visible {
  outline: 2px solid #1fadff;
  outline-offset: 2px;
}

.loan-modal__primary {
  background: #1fadff;
  color: #fff;
}
.loan-modal__primary:hover { background: #009bf5; }
.loan-modal__primary:disabled { background: #d9dce3; cursor: not-allowed; }

.loan-modal__secondary {
  background: #f4f6fb;
  color: #282d3c;
}
.loan-modal__secondary:hover { background: #d9dce3; }

.loan-modal__legal {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: #778095;
}
.loan-modal__legal a { color: #1fadff; }

/* ---- confirm step --------------------------------------------------------- */

.loan-modal__review {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 0 0 24px;
  padding: 16px;
  background: #f4f6fb;
  border-radius: 8px;
  font-size: 14px;
}
.loan-modal__review dt { color: #778095; font-weight: 400; }
.loan-modal__review dd { color: #282d3c; font-weight: 500; word-break: break-word; }

/* На узких телефонах max-content делает первую колонку шире доступного места —
   падаем в одно-колоночный список с «лейбл сверху, значение снизу». */
@media (max-width: 480px) {
  .loan-modal__review {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px;
  }
  .loan-modal__review dt { margin-bottom: -6px; font-size: 12px; }
}

/* ---- success step --------------------------------------------------------- */

.loan-modal__success {
  text-align: center;
  padding: 24px 0;
}

.loan-modal__success-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: #eafbe7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: #65c466;
}

.loan-modal__uuid-label {
  font-size: 14px;
  color: #ea4e3d;
  font-weight: 500;
  margin: 12px 0 4px;
}

.loan-modal__uuid {
  display: inline-block;
  background: #f4f6fb;
  border-radius: 8px;
  padding: 12px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  color: #282d3c;
  user-select: all;
  word-break: break-all;
  margin-bottom: 24px;
}

.loan-modal__error {
  margin-top: 12px;
  padding: 12px 16px;
  background: #fbdcd8;
  color: #ea4e3d;
  border-radius: 8px;
  font-size: 14px;
}
.loan-modal__error[hidden] { display: none; }

/* ---- status page ---------------------------------------------------------- */

.status-page {
  /* Фолбэк для старых браузеров + dvh для iOS Safari (избегаем «дыры» под URL-bar). */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(40px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(40px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  font-family: Rubik, Roboto, Helvetica, sans-serif;
  text-align: center;
  color: #282d3c;
  background: #f4f6fb;
}

.status-page__card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  padding: 40px 32px;
  max-width: 520px;
  width: 100%;
  box-sizing: border-box;
}

@media (max-width: 480px) {
  .status-page__card { padding: 28px 20px; border-radius: 12px; }
  .status-page__title { font-size: 20px; }
  .status-page__body { font-size: 14px; }
}

.status-page__icon {
  width: 96px;
  height: 96px;
  margin: 0 auto 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
}
.status-page__icon--approved { background: #eafbe7; color: #65c466; }
.status-page__icon--rejected { background: #fbdcd8; color: #ea4e3d; }
.status-page__icon--pending {
  background: #d6f0ff;
  border: 4px solid #d6f0ff;
  border-top-color: #1fadff;
  animation: status-spin 1s linear infinite;
}

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

.status-page__title {
  font-size: 24px;
  font-weight: 500;
  margin-bottom: 12px;
}
.status-page__body {
  font-size: 15px;
  color: #778095;
  line-height: 1.5;
  margin-bottom: 24px;
}
.status-page__contact { color: #1fadff; font-weight: 500; }

.status-page__back {
  display: inline-block;
  color: #1fadff;
  font-size: 14px;
}
