/* CoupleBill 移动端友好弹窗系统与安全区自适应样式 (Modal Responsive & Touch System) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  z-index: 200;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

.modal-overlay.active {
  display: flex;
  flex-direction: column;
  animation: modalFadeIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-card {
  background: #ffffff;
  width: 100%;
  max-width: 400px;
  border-radius: 20px;
  padding: 16px 18px;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.28);
  margin: auto;
  max-height: calc(85dvh);
  max-height: calc(85vh);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  position: relative;
}

/* 固定吸顶头部，永远置顶、绝不随内容滚动出可视区 */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
  background: #ffffff;
  flex-shrink: 0;
  z-index: 5;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 6px;
}

.modal-close {
  border: none;
  background: #f1f5f9;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.modal-close:hover,
.modal-close:active {
  background: #e2e8f0;
  color: #0f172a;
  transform: scale(1.05);
}

/* 表单与内容独立滚动区 */
.modal-card > form,
.modal-card > .modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-right: 2px;
  flex: 1;
}

.modal-card > form::-webkit-scrollbar,
.modal-card > .modal-body::-webkit-scrollbar {
  width: 4px;
}

.modal-card > form::-webkit-scrollbar-thumb,
.modal-card > .modal-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.modal-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  font-size: 14px;
  color: #1e293b;
  outline: none;
  background: #f8fafc;
  box-sizing: border-box;
  transition: border-color 0.15s ease;
}

.modal-input:focus {
  border-color: #ff4b72;
  background: #ffffff;
}

.pair-code-box {
  background: #fff1f2;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.pair-code-label {
  font-size: 12px;
  color: #ff4b72;
  font-weight: 600;
}

.pair-code-val {
  font-size: 15px;
  font-weight: 800;
  color: #ff4b72;
  letter-spacing: 1.5px;
}

.modal-actions-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-shrink: 0;
}

.modal-actions-row .primary-btn {
  flex: 2;
}

/* 针对矮屏手机或软键盘弹起时的极佳视口适配 */
@media (max-height: 700px) {
  .modal-overlay {
    padding: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .modal-card {
    max-height: calc(88dvh);
    max-height: calc(88vh);
    padding: 12px 14px;
    border-radius: 16px;
  }
  .modal-header {
    margin-bottom: 8px;
    padding-bottom: 6px;
  }
  .form-group {
    margin-bottom: 10px;
  }
}
