/* ============================================
   AARAA Modal System – Production v2.0
   Fixed: overflow, viewport, z-index, responsive
   ============================================ */

/* Overlay */
.ai-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

.ai-modal-overlay.active {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}

/* Modal Box */
.ai-modal-box {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border-radius: 16px;
  padding: 40px 32px 32px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
  transform: scale(0.92) translateY(20px);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  word-wrap: break-word;
  overflow-wrap: break-word;
  -ms-overflow-style: -ms-autohiding-scrollbar;
}

.ai-modal-overlay.active .ai-modal-box {
  transform: scale(1) translateY(0);
}

/* Close Button */
.ai-modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #f0f0f0;
  color: #333;
  font-size: 20px;
  font-family: 'Montserrat', sans-serif;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 2;
  padding: 0;
}

.ai-modal-close:hover {
  background: #ed2f39;
  color: #fff;
  transform: rotate(90deg);
}

/* Title */
.ai-modal-title {
  font-family: 'Roboto Condensed', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #111;
  margin: 0 0 24px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Form Groups */
.ai-form-group {
  margin-bottom: 16px;
}

.ai-form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #444;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-family: 'Montserrat', sans-serif;
}

.ai-form-control {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #e0e0e0;
  border-radius: 8px;
  font-size: 15px;
  font-family: 'Montserrat', sans-serif;
  color: #333;
  background: #fafafa;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
  box-sizing: border-box;
  display: block;
}

.ai-form-control:focus {
  border-color: #ed2f39;
  box-shadow: 0 0 0 3px rgba(237, 47, 57, 0.12);
  background: #fff;
}

.ai-form-control.error {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}

textarea.ai-form-control {
  resize: vertical;
  min-height: 80px;
}

/* Field Error */
.ai-field-error {
  color: #dc2626;
  font-size: 12px;
  margin-top: 4px;
  display: block;
  font-family: 'Montserrat', sans-serif;
}

/* Form Row (2 columns) */
.ai-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Submit Button */
.ai-btn-submit {
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: 8px;
  background: #ed2f39;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  font-family: 'Montserrat', sans-serif;
  cursor: pointer;
  transition: all 0.25s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: relative;
  margin-top: 8px;
}

.ai-btn-submit:hover:not(:disabled) {
  background: #d01f29;
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(237, 47, 57, 0.3);
}

.ai-btn-submit:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.ai-btn-submit.loading {
  pointer-events: none;
}

.ai-spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: aiSpin 0.7s linear infinite;
  position: absolute;
  left: calc(50% - 10px);
  top: calc(50% - 10px);
}

.ai-btn-submit.loading .ai-spinner {
  display: block;
}

.ai-btn-submit.loading .ai-btn-text {
  visibility: hidden;
}

@keyframes aiSpin {
  to { transform: rotate(360deg); }
}

/* Toast Notifications */
.ai-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100000;
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
  pointer-events: none;
}

.ai-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 300px;
  max-width: 420px;
  padding: 16px 20px;
  border-radius: 12px;
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  font-family: 'Montserrat', sans-serif;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.4s ease;
}

.ai-toast.show {
  transform: translateX(0);
  opacity: 1;
}

.ai-toast.success { background: #065f46; border-left: 4px solid #059669; }
.ai-toast.error { background: #991b1b; border-left: 4px solid #dc2626; }
.ai-toast.info { background: #1e3a5f; border-left: 4px solid #2563eb; }

/* Body Scroll Lock */
body.ai-modal-open,
html.ai-modal-open {
  overflow: hidden !important;
}

body.ai-modal-open {
  padding-right: var(--ai-scrollbar-width, 0px);
}

/* Guarantee modal overlay stacks above all page content */
.ai-modal-overlay.active {
  z-index: 99999;
}

/* Guarantee modal box is centered */
.ai-modal-overlay.active .ai-modal-box {
  margin: auto;
}

/* Custom Scrollbar for Modal */
.ai-modal-box::-webkit-scrollbar { width: 6px; }
.ai-modal-box::-webkit-scrollbar-track { background: transparent; }
.ai-modal-box::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* Responsive: Tablet */
@media (max-width: 768px) {
  .ai-modal-overlay { padding: 16px; }
  .ai-modal-box { padding: 32px 24px 24px; max-width: 100%; max-height: 85vh; }
  .ai-form-row { grid-template-columns: 1fr; }
  .ai-modal-title { font-size: 20px; }
}

/* Responsive: Mobile */
@media (max-width: 480px) {
  .ai-modal-overlay {
    padding: 0;
    align-items: flex-end;
    overflow: hidden;
  }
  .ai-modal-box {
    padding: 28px 20px 20px;
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
    max-width: 100%;
    width: 100%;
  }
  .ai-toast { min-width: auto; max-width: calc(100vw - 24px); }
}

/* Extra small devices */
@media (max-width: 360px) {
  .ai-modal-box { padding: 20px 14px 14px; max-height: 88vh; }
  .ai-form-control { padding: 10px 12px; font-size: 14px; }
  .ai-modal-title { font-size: 18px; }
}
