/* ===================================================================
   MODAL SYSTEM - COMPLETE FIXED VERSION
   =================================================================== */

/* Base Modal Overlay - Works for ALL modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-slow) ease, visibility var(--duration-slow) ease;

  /* Key fix: Use simple flexbox centering */
  display: flex;
  align-items: center;
  justify-content: center;
  
  /* Add safe padding and enable scrolling */
  padding: 1rem;
  overflow-y: auto;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Base Modal - Applies to ALL modals */
.modal {
  background: var(--bg-secondary);
  border-radius: 24px;
  width: 100%;
  max-width: 450px;

  /* Key fix: Use flexible height with constraints */
  min-height: auto;
  max-height: 90vh; /* Never exceed 90% of viewport */

  padding: 2rem;
  transform: translateY(20px);
  transition: transform var(--duration-slow) ease;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);

  /* Enable internal scrolling when content is too tall */
  overflow-y: auto;

  /* Ensure modal can shrink if needed */
  flex-shrink: 1;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #3b82f6;
}

.modal h2 {
  text-align: center;
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Login Options Tabs */
.login-options {
  display: flex;
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 0.25rem;
  margin-bottom: 1.5rem;
  overflow: hidden;
  transition: background-color 0.3s ease;
}

.login-tab {
  flex: 1;
  padding: 0.75rem 0.5rem;
  background: transparent;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: background var(--duration-slow) ease, color var(--duration-slow) ease, box-shadow var(--duration-slow) ease;
  border-radius: 8px;
  text-align: center;
}

.login-tab.active {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.login-tab.register-tab.active {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

/* Device Confirmation Modal - Special handling for larger content */
#deviceConfirmationModal {
  z-index: 10000;
}

#deviceConfirmationModal.active {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
}

#deviceConfirmationModal .modal {
  max-width: 600px;
  
  /* Allow this modal to use more space but still constrain */
  max-height: 85vh; /* Slightly less to ensure it fits */
  overflow-y: auto;
}

/* Device Warning Styles */
#deviceConfirmationModal .device-warning {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 2px solid #f59e0b;
  border-radius: 12px;
  padding: 1.5rem;
  margin: 1.5rem 0;
}

#deviceConfirmationModal .device-warning p {
  margin: 0 0 1rem 0;
  font-weight: 600;
  color: #92400e;
}

#deviceConfirmationModal .device-warning ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

#deviceConfirmationModal .device-warning li {
  padding: 0.5rem 0;
  color: #78350f;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#deviceConfirmationModal .warning-box {
  background: #fecaca;
  border: 2px solid #ef4444;
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
  text-align: center;
}

#deviceConfirmationModal .warning-box strong {
  color: #dc2626;
  font-size: 1.1rem;
}

/* Button styling for device confirmation */
#deviceConfirmationModal .confirmation-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  justify-content: center;
}

#deviceConfirmationModal .btn-primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--duration-slow) ease, box-shadow var(--duration-slow) ease;
  font-size: 1rem;
}

#deviceConfirmationModal .btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
}

#deviceConfirmationModal .btn-secondary {
  background: #6b7280;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--duration-slow) ease, transform var(--duration-slow) ease;
  font-size: 1rem;
}

#deviceConfirmationModal .btn-secondary:hover {
  background: #4b5563;
  transform: translateY(-2px);
}

/* OTP Modal */
.otp-modal {
  background: var(--bg-secondary);
  border-radius: 24px;
  width: 100%;
  max-width: 400px;
  padding: 2rem;
  transform: translateY(20px);
  transition: transform var(--duration-slow) ease;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;

  /* Constrain height */
  max-height: 80vh;
  overflow-y: auto;
}

.otp-input {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.resend-otp {
  text-align: center;
  margin-top: 1rem;
}

.resend-link {
  color: #10b981;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

.resend-link:hover {
  text-decoration: underline;
}

.resend-link:disabled {
  color: #94a3b8;
  cursor: not-allowed;
}

/* Success Modal with Confetti */
.success-modal {
  background: var(--bg-secondary);
  border-radius: 24px;
  width: 100%;
  max-width: 500px;
  padding: 3rem;
  transform: translateY(20px);
  transition: transform var(--duration-slow) ease;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;

  /* Constrain height */
  max-height: 85vh;
  overflow-y: auto;
}

.confetti-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  border-radius: 24px;
}

.success-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  font-size: 2rem;
  color: white;
  animation: bounce 0.6s ease-out;
}

/* Scrollbar styling for better UX */
.modal::-webkit-scrollbar,
.otp-modal::-webkit-scrollbar,
.success-modal::-webkit-scrollbar {
  width: 6px;
}

.modal::-webkit-scrollbar-track,
.otp-modal::-webkit-scrollbar-track,
.success-modal::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

html.dark .modal::-webkit-scrollbar-track,
html.dark .otp-modal::-webkit-scrollbar-track,
html.dark .success-modal::-webkit-scrollbar-track,
body.dark .modal::-webkit-scrollbar-track,
body.dark .otp-modal::-webkit-scrollbar-track,
body.dark .success-modal::-webkit-scrollbar-track {
  background: #334155;
}

.modal::-webkit-scrollbar-thumb,
.otp-modal::-webkit-scrollbar-thumb,
.success-modal::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

html.dark .modal::-webkit-scrollbar-thumb,
html.dark .otp-modal::-webkit-scrollbar-thumb,
html.dark .success-modal::-webkit-scrollbar-thumb,
body.dark .modal::-webkit-scrollbar-thumb,
body.dark .otp-modal::-webkit-scrollbar-thumb,
body.dark .success-modal::-webkit-scrollbar-thumb {
  background: #64748b;
}

.modal::-webkit-scrollbar-thumb:hover,
.otp-modal::-webkit-scrollbar-thumb:hover,
.success-modal::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

html.dark .modal::-webkit-scrollbar-thumb:hover,
html.dark .otp-modal::-webkit-scrollbar-thumb:hover,
html.dark .success-modal::-webkit-scrollbar-thumb:hover,
body.dark .modal::-webkit-scrollbar-thumb:hover,
body.dark .otp-modal::-webkit-scrollbar-thumb:hover,
body.dark .success-modal::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* ===================================================================
   FORMS AND INPUT ELEMENTS
   =================================================================== */

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-input {
  width: 100%;
  padding: 0.875rem;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 1rem;
  transition: border-color var(--duration-slow) ease, box-shadow var(--duration-slow) ease;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.form-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input.error {
  border-color: #e53e3e;
  background-color: #fff5f5;
  animation: shake 0.5s ease-in-out;
}

.password-field {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s;
}

.password-toggle:hover {
  color: #3b82f6;
}

.forgot-pin {
  text-align: right;
  margin-top: 0.5rem;
}

.forgot-pin a {
  color: white;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border: 2px solid transparent;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  transition: transform var(--duration-slow) ease, box-shadow var(--duration-slow) ease;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.forgot-pin a:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  text-decoration: none;
}

.submit-btn {
  width: 100%;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  padding: 0.875rem;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--duration-slow) ease, box-shadow var(--duration-slow) ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.submit-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(59, 130, 246, 0.3);
}

.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.submit-btn.register-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.submit-btn.register-btn:hover:not(:disabled) {
  box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
}

/* PIN Display Styles */
.pin-display {
  background: #f0fdf4;
  border: 2px solid #10b981;
  border-radius: 12px;
  padding: 1rem;
  margin: 1rem 0;
  text-align: center;
  font-size: 1.5rem;
  font-weight: bold;
  letter-spacing: 0.2rem;
  color: #15803d;
}

/* ===================================================================
   MESSAGE AND NOTIFICATION STYLES
   =================================================================== */

.error-message {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  animation: slideIn 0.3s ease-out;
}

html.dark .error-message,
body.dark .error-message {
  background: #7f1d1d;
  border-color: #991b1b;
  color: #fca5a5;
}

.success-message {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #16a34a;
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  display: none;
  font-size: 0.875rem;
}

html.dark .success-message,
body.dark .success-message {
  background: #14532d;
  border-color: #166534;
  color: #86efac;
}

/* Trial Info */
.trial-info {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #16a34a;
  padding: 1rem;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  text-align: center;
}

.trial-info h4 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: #15803d;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.trial-info ul {
  list-style: none;
  margin: 0.5rem 0 0 0;
  padding: 0;
}

.trial-info li {
  padding: 0.25rem 0;
  color: #15803d;
}

.trial-info li:before {
  content: "✓ ";
  color: #10b981;
  font-weight: bold;
}

/* Enhanced device security notice */
.device-security-notice {
  background: linear-gradient(135deg, #e0f2fe 0%, #b3e5fc 100%);
  border: 2px solid #0288d1;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.device-security-notice h4 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: #01579b;
}

.device-security-notice p {
  margin: 0;
  color: #0277bd;
  font-size: 0.9rem;
  line-height: 1.4;
}

