/* Layout: modals, dropdown, safe area (CSP-safe) */

html {
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 10050;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

.modal.show {
  display: block;
}

.modal.fade .modal-dialog {
  transform: translateY(12px) scale(0.98);
  opacity: 0;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
}

.modal.fade.show .modal-dialog {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10040;
}

.modal-backdrop.show {
  display: block;
}

.modal-dialog {
  margin: 1.75rem auto;
  max-width: 500px;
  min-height: calc(100vh - 3.5rem);
  min-height: calc(100dvh - 3.5rem);
  display: flex;
  align-items: center;
  width: calc(100% - 1.5rem);
}

.modal-dialog.modal-lg {
  max-width: 800px;
}

.modal-content {
  margin: auto;
  width: 100%;
  max-width: 100%;
  max-height: calc(100vh - 3.5rem);
  max-height: calc(100dvh - 3.5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 1.125rem;
  border: 1px solid rgba(51, 65, 85, 0.65);
  background: linear-gradient(165deg, rgba(15, 23, 42, 0.98), rgba(11, 18, 32, 0.99));
  color: #e2e8f0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 24px 64px -20px rgba(0, 0, 0, 0.7);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid rgba(51, 65, 85, 0.55);
  flex-shrink: 0;
}

.modal-title {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #f8fafc;
}

.modal-body {
  padding: 1rem 1.125rem;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  min-height: 0;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.125rem;
  border-top: 1px solid rgba(51, 65, 85, 0.55);
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Backup step-up: fixed viewport layer (lives inside #backupModal for focus trap) */
.backup-stepup-panel {
  position: fixed;
  inset: 0;
  z-index: 10070;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.75rem, env(safe-area-inset-top, 0))
    max(0.75rem, env(safe-area-inset-right, 0))
    max(0.75rem, env(safe-area-inset-bottom, 0))
    max(0.75rem, env(safe-area-inset-left, 0));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: rgba(2, 6, 23, 0.8);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: auto;
}

.backup-stepup-panel.hidden {
  display: none !important;
}

.backup-stepup-panel__card {
  pointer-events: auto;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 24rem;
  margin: auto;
  border-radius: 0.875rem;
  border: 1px solid rgba(51, 65, 85, 0.9);
  background: #020617;
  box-shadow: 0 24px 64px -20px rgba(0, 0, 0, 0.7);
}

@media (max-width: 639px) {
  .modal-dialog {
    margin: 0.75rem auto;
    min-height: calc(100vh - 1.5rem);
    min-height: calc(100dvh - 1.5rem);
    width: calc(100% - 1rem);
    align-items: flex-end;
  }

  .modal-content {
    max-height: calc(100vh - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
    border-radius: 1rem 1rem 0.85rem 0.85rem;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .modal-footer {
    padding-bottom: calc(0.875rem + env(safe-area-inset-bottom, 0));
  }

  .modal-footer > * {
    flex: 1 1 auto;
    min-width: 0;
  }

  .backup-stepup-panel {
    align-items: flex-end;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0));
  }

  .backup-stepup-panel__card {
    max-height: min(90dvh, 100%);
    overflow-y: auto;
  }
}

/* Bootstrap close without Bootstrap CSS */
.btn-close {
  box-sizing: content-box;
  width: 0.75rem;
  height: 0.75rem;
  padding: 0.4rem;
  color: transparent;
  background: transparent
    url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%94a3b8'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e")
    center/0.75em auto no-repeat;
  border: 0;
  border-radius: 0.5rem;
  opacity: 0.85;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.btn-close:hover {
  opacity: 1;
  background-color: rgba(51, 65, 85, 0.55);
}

.btn-close-white {
  filter: none;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 1060;
  min-width: 10rem;
  padding: 0.4rem;
  margin-top: 0.5rem;
  border-radius: 0.75rem;
  border: 1px solid #334155;
  background-color: #020617;
  color: #f1f5f9;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65);
  isolation: isolate;
}

.dropdown-menu.show {
  display: block;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  clear: both;
  font-size: 0.75rem;
  color: #f1f5f9 !important;
  text-align: inherit;
  text-decoration: none;
  background-color: transparent;
  border: 0;
  border-radius: 0.5rem;
}

.dropdown-item:hover {
  background-color: #1e293b;
  color: #ffffff !important;
}

.dropdown-divider {
  height: 0;
  margin: 0.35rem 0;
  overflow: hidden;
  border-top: 1px solid rgba(51, 65, 85, 0.55);
}

.safe-area-pb {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav {
  position: fixed;
  bottom: 0 !important;
  left: 0;
  right: 0;
  margin: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  min-height: 4rem;
}

.bottom-nav > div {
  min-height: 4rem;
}

#add-to-home-banner {
  bottom: 5.5rem;
}

@media (prefers-reduced-motion: reduce) {
  .modal.fade .modal-dialog,
  .modal.fade.show .modal-dialog {
    transition: none;
    transform: none;
    opacity: 1;
  }
}
