/* ============ Disable zoom on touch devices ============ */
html {
  touch-action: pan-x pan-y;
  -ms-touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
* {
  -webkit-touch-callout: none;
}
input, textarea, select {
  font-size: 16px !important;
}

/* ============================================
   ForexBro — Auth Overlays (Modals)
   Single-file approach like Wajhati
   ============================================ */

/* ============ Overlay Base ============ */
.fb-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
  animation: fbOverlayIn 0.25s ease-out;
}

.fb-overlay.open { display: flex; }

@keyframes fbOverlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============ Modal Base ============ */
.fb-modal {
  background: linear-gradient(145deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  position: relative;
  box-shadow: 0 25px 80px -20px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 184, 0, 0.08);
  animation: fbModalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  margin: auto;
}

.fb-modal::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-gold), transparent);
  opacity: 0.6;
}

.fb-modal.fb-modal-lg { max-width: 780px; }

@keyframes fbModalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.fb-modal-close {
  position: absolute;
  top: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 5;
}

html[dir="rtl"] .fb-modal-close { left: 16px; }
html[dir="ltr"] .fb-modal-close { right: 16px; }

.fb-modal-close:hover {
  background: var(--accent-red-dim);
  color: var(--accent-red);
  border-color: rgba(255, 59, 92, 0.3);
}

.fb-modal-close svg { width: 18px; height: 18px; }

.fb-modal-body { padding: 40px 32px 32px; }
.fb-modal-lg .fb-modal-body { padding: 40px 40px 32px; max-height: 85vh; overflow-y: auto; }

/* ============ Modal Header ============ */
.fb-modal-logo { display: flex; align-items: center; justify-content: center; margin-bottom: 20px; }
.fb-modal-logo-mark { width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; }
.fb-modal-logo-mark svg { width: 100%; height: 100%; display: block; }

.fb-modal-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

html[lang="ar"] .fb-modal-title { letter-spacing: 0; font-family: var(--font-arabic); }

.fb-modal-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
}

/* ============ Form ============ */
.fb-form { display: flex; flex-direction: column; gap: 16px; }
.fb-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fb-field { display: flex; flex-direction: column; gap: 6px; }
.fb-label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }

.fb-input, .fb-select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s;
  outline: none;
}

html[lang="ar"] .fb-input, html[lang="ar"] .fb-select { font-family: var(--font-arabic); }

.fb-input:focus, .fb-select:focus {
  border-color: var(--accent-gold);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(255, 184, 0, 0.1);
}

.fb-input::placeholder { color: var(--text-muted); }

.fb-select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3e%3cpath d='M1 1.5l5 5 5-5' stroke='%23A0A8C0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
}

html[dir="rtl"] .fb-select { background-position: left 14px center; padding-left: 36px; }
html[dir="ltr"] .fb-select { background-position: right 14px center; padding-right: 36px; }

.fb-select option { background: var(--bg-card); color: var(--text-primary); }

/* Password */
.fb-pw-wrap { position: relative; }

.fb-pw-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

html[dir="rtl"] .fb-pw-toggle { left: 8px; }
html[dir="ltr"] .fb-pw-toggle { right: 8px; }
.fb-pw-toggle:hover { color: var(--accent-gold); }
.fb-pw-toggle svg { width: 18px; height: 18px; }

html[dir="rtl"] .fb-pw-wrap .fb-input { padding-left: 40px; }
html[dir="ltr"] .fb-pw-wrap .fb-input { padding-right: 40px; }

.fb-pw-strength {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.fb-pw-strength-bar {
  height: 100%;
  width: 0;
  background: var(--accent-red);
  transition: all 0.3s;
  border-radius: 2px;
}

.fb-pw-strength-bar.medium { background: #FFB800; }
.fb-pw-strength-bar.strong { background: var(--accent-green); }
.fb-pw-strength-bar.very-strong { background: linear-gradient(90deg, var(--accent-green), #00D97E); }

.fb-pw-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  min-height: 14px;
}

.fb-pw-label.weak { color: var(--accent-red); }
.fb-pw-label.medium { color: #FFB800; }
.fb-pw-label.strong, .fb-pw-label.very-strong { color: var(--accent-green); }

/* Checkbox */
.fb-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  cursor: pointer;
  user-select: none;
}

.fb-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-medium);
  border-radius: 4px;
  background: var(--bg-tertiary);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  margin-top: 1px;
  transition: all 0.2s;
}

.fb-checkbox input[type="checkbox"]:checked {
  background: var(--accent-gold);
  border-color: var(--accent-gold);
}

.fb-checkbox input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 5px;
  width: 5px;
  height: 10px;
  border: solid var(--bg-primary);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.fb-checkbox .fb-link {
  color: var(--accent-gold);
  text-decoration: none;
  font-weight: 600;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
}

html[lang="ar"] .fb-checkbox .fb-link { font-family: var(--font-arabic); }
.fb-checkbox .fb-link:hover { text-decoration: underline; }

/* Submit */
.fb-submit {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent-gold) 0%, #FF8A00 100%);
  color: var(--bg-primary);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
  box-shadow: 0 10px 30px -10px rgba(255, 184, 0, 0.5);
}

html[lang="ar"] .fb-submit { font-family: var(--font-arabic); }

.fb-submit:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 15px 35px -10px rgba(255, 184, 0, 0.7);
}

.fb-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.fb-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(10, 14, 26, 0.3);
  border-top-color: var(--bg-primary);
  border-radius: 50%;
  animation: fbSpin 0.6s linear infinite;
  margin-inline-end: 8px;
  vertical-align: middle;
}

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

/* Switch between modals */
.fb-modal-switch {
  text-align: center;
  margin-top: 24px;
  font-size: 14px;
  color: var(--text-secondary);
}

.fb-modal-switch button {
  color: var(--accent-gold);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  margin-inline-start: 4px;
}

html[lang="ar"] .fb-modal-switch button { font-family: var(--font-arabic); }
.fb-modal-switch button:hover { text-decoration: underline; }

/* Alert */
.fb-alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  display: none;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.fb-alert.show { display: flex; }

.fb-alert.error {
  background: var(--accent-red-dim);
  border: 1px solid rgba(255, 59, 92, 0.3);
  color: var(--accent-red);
}

.fb-alert.success {
  background: var(--accent-green-dim);
  border: 1px solid rgba(0, 255, 135, 0.3);
  color: var(--accent-green);
}

.fb-alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* Between row */
.fb-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.fb-forgot {
  color: var(--accent-gold);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
}

html[lang="ar"] .fb-forgot { font-family: var(--font-arabic); }
.fb-forgot:hover { text-decoration: underline; }

/* MFA */
.fb-mfa-input {
  text-align: center;
  letter-spacing: 8px;
  font-size: 20px;
  font-family: 'JetBrains Mono', monospace;
}

/* Success state */
.fb-success { text-align: center; padding: 16px 0; }

.fb-success-icon {
  width: 72px;
  height: 72px;
  background: var(--accent-green-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: var(--accent-green);
}

.fb-success-icon svg { width: 36px; height: 36px; }

.fb-success-msg {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 20px;
}

.fb-success-email {
  color: var(--accent-gold);
  font-weight: 600;
  display: block;
  margin-top: 12px;
  direction: ltr;
}

/* Legal modal content */
.fb-legal-meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 32px;
  text-align: center;
}

.fb-legal-section { margin-bottom: 28px; }

.fb-legal-section h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--accent-gold);
}

html[lang="ar"] .fb-legal-section h3 { font-family: var(--font-arabic); }

.fb-legal-section p, .fb-legal-section li {
  color: var(--text-secondary);
  line-height: 1.8;
  font-size: 14.5px;
  margin-bottom: 8px;
}

.fb-legal-section ul { padding-inline-start: 20px; margin-top: 8px; }
.fb-legal-section li { margin-bottom: 6px; }
.fb-legal-section strong { color: var(--text-primary); }

.fb-legal-warning {
  background: var(--accent-red-dim);
  border: 1px solid rgba(255, 59, 92, 0.25);
  border-radius: var(--radius-md);
  padding: 18px;
  margin: 20px 0;
}

.fb-legal-warning h3 { color: var(--accent-red); margin-top: 0; }
.fb-legal-warning p { color: var(--text-primary); }

/* Responsive */
@media (max-width: 520px) {
  .fb-overlay { padding: 20px 12px; }
  .fb-modal-body { padding: 32px 24px 24px; }
  .fb-modal-lg .fb-modal-body { padding: 32px 24px 24px; }
  .fb-form-row { grid-template-columns: 1fr; }
  .fb-modal-title { font-size: 22px; }
}

body.fb-modal-open { overflow: hidden; }
