/* Reset & Base – mobile fixed, no zoom, no scroll */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --khalti-red: #e4002b;
  --khalti-red-dark: #c40026;
  --text-dark: #2d2d2d;
  --text-muted: #6b6b6b;
  --border-color: #d1d1d1;
  --tab-active: #2563eb;
  --white: #ffffff;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

html {
  overflow: hidden;
  overflow-x: hidden;
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--white);
  color: var(--text-dark);
  overflow: hidden;
  overflow-x: hidden;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
}

/* Screens */
.screen {
  display: none;
  min-height: 100%;
  height: 100%;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
  overflow-x: hidden;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========== Splash Screen ========== */
#splash-screen {
  background: var(--white);
}

.splash-content {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
  padding: 2rem;
}

.splash-logo {
  max-width: 180px;
  width: 100%;
  height: auto;
  object-fit: contain;
}

/* ========== Loader Screen (full screen, logo centered) ========== */
.loader-screen {
  background: var(--white);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
}

.loader-screen.active {
  display: flex;
}

/* ========== OTP Screen ========== */
#otp-screen {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 1rem 1rem 2rem;
  min-height: 100vh;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

#otp-screen.active {
  display: flex;
}

.otp-container {
  margin-top: 0;
  margin-bottom: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  padding-top: 1rem;
}

.otp-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 340px;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  padding: 0 0.5rem;
}

.otp-header .otp-logo {
  margin: 0;
  max-width: 180px;
  width: 180px;
}

.otp-logo {
  width: 180px;
  max-width: 55%;
  height: auto;
  object-fit: contain;
  margin-top: 0;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
  transition: width 0.2s ease, margin 0.2s ease;
}

/* When OTP input focused (keyboard open): compact layout so logo + box stay visible */
.otp-container.keyboard-open .otp-logo {
  width: 72px;
  max-width: 28%;
  margin-bottom: 0.5rem;
}

.otp-container.keyboard-open .otp-header .otp-logo {
  max-width: 100px;
  width: 100px;
}

.otp-container.keyboard-open .otp-message {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.otp-container.keyboard-open .otp-center {
  gap: 0;
}

.otp-container.keyboard-open .otp-error {
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
}

.otp-container.keyboard-open .btn-continue {
  margin-top: 0.5rem;
}

.otp-container.keyboard-open .btn-resend {
  margin-top: 0.5rem;
}

.otp-center {
  width: 100%;
  max-width: 340px;
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.otp-message {
  font-size: 1rem;
  color: var(--text-dark);
  line-height: 1.5;
  margin-bottom: 1.25rem;
  width: 100%;
}

.otp-error {
  padding: 0.75rem 1rem;
  background: rgba(228, 0, 43, 0.08);
  border: 1px solid var(--khalti-red);
  border-radius: 10px;
  margin-bottom: 1rem;
  width: 100%;
}

.otp-error .otp-error-text,
.otp-error #otp-error-text {
  color: var(--khalti-red);
  font-size: 0.95rem;
  font-weight: 500;
}

.otp-center .input-field {
  margin-bottom: 0;
  width: 100%;
  text-align: center;
}

#otp-input {
  text-align: center;
}

.otp-center .btn-continue {
  margin-top: 0.75rem;
  width: 100%;
}

.btn-resend {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  color: var(--khalti-red);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s;
}

.btn-resend:hover:not(:disabled) {
  text-decoration: underline;
}

.btn-resend:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  color: var(--text-muted);
}

.otp-no-receive-msg {
  margin-top: 1rem;
  padding: 0.75rem 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  width: 100%;
  text-align: center;
}

.otp-no-receive-msg:not(.hidden) {
  display: block !important;
}

.back-btn-below-msg {
  position: relative;
  top: auto;
  left: auto;
  width: 100%;
  margin-top: 1rem;
  padding: 0.75rem 1.25rem;
  min-height: 48px;
  font-weight: 600;
  border: 2px solid var(--khalti-red);
  color: var(--khalti-red);
  background: rgba(228, 0, 43, 0.06);
}

.back-btn-below-msg:hover {
  background: rgba(228, 0, 43, 0.12);
}

.back-btn-below-msg:not(.hidden) {
  display: block !important;
}

.back-btn {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--white);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dark);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.back-btn:hover {
  border-color: var(--text-muted);
  box-shadow: var(--shadow);
}

.back-btn:focus {
  outline: none;
  border-color: var(--tab-active);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* Back button below message: must override .back-btn and stay visible when .hidden removed */
.back-btn.back-btn-below-msg {
  position: relative !important;
  top: auto !important;
  left: auto !important;
}

.back-btn.back-btn-below-msg:not(.hidden) {
  display: block !important;
}

.hidden {
  display: none !important;
}

/* ========== Login Screen (mobile-optimized) ========== */
#login-screen {
  align-items: flex-start;
  padding: 1rem 1rem 2rem;
  min-height: 100vh;
}

.login-container {
  width: 100%;
  max-width: 420px;
  min-width: 0;
  margin: 0 auto;
  position: relative;
  padding: 0 0.25rem;
  overflow: hidden;
}

/* Language Toggle */
.lang-toggle {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--white);
  font-size: 1rem;
  color: var(--text-dark);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.lang-toggle:hover {
  border-color: var(--text-muted);
  box-shadow: var(--shadow);
}

.lang-toggle:focus {
  outline: none;
  border-color: var(--tab-active);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* Welcome Section */
.welcome-section {
  margin-top: 3rem;
  margin-bottom: 1.5rem;
}

.welcome-title {
  font-size: 2.5rem;
  font-weight: 600;
  color: var(--text-dark);
  line-height: 1.3;
  margin-bottom: 0.5rem;
}

.welcome-title .brand-name {
  color: var(--khalti-red);
  font-weight: 700;
}

.welcome-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Login Tabs */
.login-tabs {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.tab {
  padding: 0.5rem 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
  color: var(--text-dark);
}

.tab.active {
  color: var(--tab-active);
  border-bottom-color: var(--tab-active);
}

/* Input Groups */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-group.hidden {
  display: none;
}

.input-group:not(.hidden) {
  margin-bottom: 0.5rem;
}

/* Mobile: country code + number in one line */
.mobile-row {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  align-items: stretch;
}

.input-group.mobile-inputs .input-wrapper.country-code {
  flex: 0 0 auto;
  min-width: 5rem;
  width: 5.5rem;
}

.input-group.mobile-inputs .mobile-row .input-field {
  flex: 1;
  min-width: 0;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--white);
  min-height: 48px;
}

.input-wrapper .input-icon {
  font-size: 1rem;
}

.input-wrapper select {
  flex: 1;
  border: none;
  background: none;
  font-size: 1rem;
  color: var(--text-dark);
  cursor: pointer;
  appearance: none;
  padding: 0.25rem 0;
}

.input-wrapper select:focus {
  outline: none;
}

.input-arrow {
  font-size: 0.65rem;
  color: var(--text-muted);
  pointer-events: none;
}

.input-field {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 1rem;
  color: var(--text-dark);
  transition: border-color 0.2s;
}

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

.input-field:focus {
  outline: none;
  border-color: var(--tab-active);
}

.input-field.full-width {
  min-height: 48px;
}

/* Continue Button (mobile & email) */
.btn-continue {
  width: 100%;
  padding: 0.9rem 1.5rem;
  min-height: 48px;
  background: var(--khalti-red);
  color: var(--white);
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-continue:hover {
  background: var(--khalti-red-dark);
}

.btn-continue:active {
  transform: scale(0.99);
}

.btn-continue:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(228, 0, 43, 0.3);
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
}

.divider-line {
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.divider-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* IME Pay Button */
.ime-pay-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--khalti-red);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.ime-pay-btn:hover {
  background: rgba(228, 0, 43, 0.06);
  border-color: var(--khalti-red);
}

.ime-pay-icon {
  width: 24px;
  height: 24px;
  background: var(--khalti-red);
  border-radius: 4px;
  flex-shrink: 0;
}

.ime-pay-text {
  color: var(--khalti-red);
}

/* Mobile: keep country code + number in one line, touch-friendly */
@media (max-width: 480px) {
  .login-container {
    max-width: 100%;
  }

  .welcome-title {
    font-size: 2rem;
  }

  .input-group.mobile-inputs .input-wrapper.country-code {
    min-width: 4.5rem;
    width: 4.75rem;
    padding: 0 0.5rem;
  }

  .input-wrapper select {
    font-size: 0.95rem;
  }
}

@media (min-width: 481px) {
  #login-screen {
    padding: 2rem 1.5rem 3rem;
  }

  .input-group.mobile-inputs .input-wrapper.country-code {
    width: 6rem;
  }
}
