/* QPay Theme Colors */
:root {
  --qpay-primary: #2a52be;
  --qpay-secondary: #1e3a8a;
  --qpay-accent: #3b82f6;
  --qpay-success: #10b981;
  --qpay-error: #ef4444;
  --qpay-warning: #f59e0b;
  --qpay-light: #f8fafc;
  --qpay-dark: #1e293b;
  --qpay-gray: #64748b;
  --qpay-light-gray: #e2e8f0;
}

/* Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body {
  background-color: #f1f5f9;
  color: var(--qpay-dark);
  line-height: 1.6;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes paymentProcessing {
  0% {
    transform: translateY(0) rotate(0);
    opacity: 1;
  }
  50% {
    transform: translateY(-20px) rotate(180deg);
    opacity: 0.5;
  }
  100% {
    transform: translateY(0) rotate(360deg);
    opacity: 1;
  }
}

/* Container Styles */
.qpay-container {
  max-width: 600px;
  margin: 2rem auto;
  background: white;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  animation: fadeIn 0.5s ease-out;
}

.qpay-header {
  background: linear-gradient(
    135deg,
    var(--qpay-primary),
    var(--qpay-secondary)
  );
  color: white;
  padding: 1.5rem;
  text-align: center;
  position: relative;
}

.qpay-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  font-size: 1.5rem;
  font-weight: bold;
}

.qpay-logo i {
  margin-right: 0.5rem;
  font-size: 2rem;
  animation: float 3s ease-in-out infinite;
}

.qpay-flow-container {
  padding: 1.5rem;
}

/* Progress Steps */
.progress-steps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2rem;
  position: relative;
}

.progress-steps::before {
  content: "";
  position: absolute;
  top: 15px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--qpay-light-gray);
  z-index: 1;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
}

.step-number {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--qpay-light-gray);
  color: var(--qpay-gray);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  margin-bottom: 0.5rem;
  transition: all 0.3s ease;
}

.step-label {
  font-size: 0.8rem;
  color: var(--qpay-gray);
  text-align: center;
  transition: all 0.3s ease;
}

.step.active .step-number {
  background: var(--qpay-primary);
  color: white;
  box-shadow: 0 0 0 4px rgba(42, 82, 190, 0.2);
}

.step.active .step-label {
  color: var(--qpay-dark);
  font-weight: 600;
}

/* Form Styles */
.qpay-step {
  animation: fadeIn 0.5s ease-out;
}

/* Fix step description - now h4 and not centered */
.step-description {
  margin: 0.5rem 0 1.5rem;
  text-indent: 0;
  margin-left: 0;
  padding-left: 0;
  font-size: 1rem;
  color: var(--qpay-gray);
  font-weight: 400;
}

.qpay-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group input {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid var(--qpay-light-gray);
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.input-group input:focus {
  outline: none;
  border-color: var(--qpay-accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.input-prefix {
  padding: 12px;
  background: var(--qpay-light-gray);
  border: 1px solid var(--qpay-light-gray);
  border-radius: 8px 0 0 8px;
  font-weight: 500;
  color: var(--qpay-dark);
}

.input-prefix + input {
  border-radius: 0 8px 8px 0;
  border-left: none;
}

.input-suffix {
  position: absolute;
  right: 15px;
  color: var(--qpay-gray);
}

/* Button Styles */
.qpay-btn {
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
}

.qpay-btn i {
  font-size: 1rem;
}

.qpay-btn.primary {
  background: var(--qpay-primary);
  color: white;
}

.qpay-btn.primary:hover {
  background: var(--qpay-secondary);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(42, 82, 190, 0.3);
}

.qpay-btn.secondary {
  background: white;
  color: var(--qpay-primary);
  border: 1px solid var(--qpay-primary);
}

.qpay-btn.secondary:hover {
  background: var(--qpay-light);
}

/* OTP Message */
.otp-message {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(16, 185, 129, 0.1);
  color: var(--qpay-success);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  animation: pulse 2s infinite;
}

.otp-message i {
  font-size: 1.2rem;
}

/* Card Selection */
.card-selection {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card-option {
  display: block;
  cursor: pointer;
}

.card-option input {
  display: none;
}

.card-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--qpay-light-gray);
  border-radius: 8px;
  transition: all 0.3s ease;
}

.card-option input:checked + .card-content {
  border-color: var(--qpay-primary);
  background: rgba(42, 82, 190, 0.05);
  box-shadow: 0 0 0 1px var(--qpay-primary);
  transform: scale(1.05);
}

.card-icon {
  font-size: 1.8rem;
  color: var(--qpay-primary);
}

.card-details {
  flex: 1;
}

.card-number {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.card-name {
  color: var(--qpay-gray);
  font-size: 0.9rem;
}

/* Amount Display */
.amount-display {
  display: flex;
  justify-content: space-between;
  padding: 1rem;
  background: var(--qpay-light);
  border-radius: 8px;
  font-weight: 600;
}

.amount {
  color: var(--qpay-primary);
  font-size: 1.1rem;
}

/* Loading Animation */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  text-align: center;
}

.payment-processing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.payment-loader {
  display: flex;
  gap: 0.5rem;
}

.payment-circle {
  width: 15px;
  height: 15px;
  background: var(--qpay-primary);
  border-radius: 50%;
  animation: paymentProcessing 1.5s ease-in-out infinite;
}

.payment-circle:nth-child(2) {
  animation-delay: 0.2s;
}

.payment-circle:nth-child(3) {
  animation-delay: 0.4s;
}

/* Result Container */
.result-container {
  text-align: center;
}

.result-icon {
  font-size: 4rem;
  margin-bottom: 1.5rem;
}

.result-icon.success {
  color: var(--qpay-success);
}

.result-icon.error {
  color: var(--qpay-error);
}

/* Error Message Styles */
.error-message {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  color: var(--qpay-error);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.error-message i {
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* Step Header Layout */
.step-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.step-title-section {
  flex: 1;
}

.step-title-section h2 {
  margin-bottom: 0.5rem;
}

/* Compact Order Summary for Step Header */
.order-summary-compact {
  flex-shrink: 0;
}

.order-amount-display-compact {
  background: linear-gradient(135deg, #f8fafc, #ffffff);
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: relative;
  min-width: 140px;
}

.order-amount-display-compact::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--qpay-primary), var(--qpay-accent));
  border-radius: 8px 8px 0 0;
}

.order-label-compact {
  font-size: 0.7rem;
  color: var(--qpay-gray);
  margin-bottom: 0.25rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.order-amount-compact {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--qpay-primary);
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Legacy Amount Display Styles (for other screens) */
.amount-display-section {
  margin-bottom: 1.5rem;
}

.amount-display {
  background: linear-gradient(135deg, var(--qpay-light), #ffffff);
  border: 2px solid var(--qpay-accent);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}

.amount-label {
  display: block;
  font-size: 0.9rem;
  color: var(--qpay-gray);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.amount-value {
  display: block;
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--qpay-primary);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.result-details {
  background: var(--qpay-light);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  text-align: left;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.detail-row:last-child {
  margin-bottom: 0;
}

.detail-row span:first-child {
  color: var(--qpay-gray);
}

.detail-row span:last-child {
  font-weight: 600;
}

.result-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.return-form {
  flex: 1;
}

/* Responsive Adjustments */
@media (max-width: 600px) {
  .qpay-container {
    margin: 0;
    border-radius: 0;
    min-height: 100vh;
  }

  .result-actions {
    flex-direction: column;
  }

  /* Stack step header on mobile */
  .step-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .order-summary-compact {
    align-self: center;
  }

  .order-amount-display-compact {
    min-width: auto;
    max-width: 200px;
  }
}

/* Loading Animation Enhancements */
.loading-progress {
  width: 100%;
  height: 4px;
  background: var(--qpay-light-gray);
  border-radius: 2px;
  margin-top: 2rem;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--qpay-primary);
  border-radius: 2px;
  animation: progressAnimation 1s linear infinite;
}

@keyframes progressAnimation {
  0% {
    width: 0;
    margin-left: 0;
  }
  50% {
    width: 50%;
    margin-left: 25%;
  }
  100% {
    width: 0;
    margin-left: 100%;
  }
}

/* Enhanced payment loader */
.payment-loader {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 1.5rem;
}

.payment-circle {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--qpay-primary);
  border-radius: 50%;
  animation: paymentProcessing 1.5s ease-in-out infinite;
  opacity: 0.7;
}

.payment-circle:nth-child(1) {
  top: 0;
  left: 30px;
  animation-delay: 0s;
}

.payment-circle:nth-child(2) {
  top: 30px;
  right: 0;
  animation-delay: 0.2s;
}

.payment-circle:nth-child(3) {
  bottom: 0;
  left: 30px;
  animation-delay: 0.4s;
}

.payment-circle:nth-child(4) {
  top: 30px;
  left: 0;
  animation-delay: 0.6s;
}

@keyframes paymentProcessing {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.5);
    opacity: 1;
  }
}

/* Plan Selection Grid */
.plan-selection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

/* Plan Card Styling */
.plan-card-wrapper {
  display: block;
  cursor: pointer;
}

.plan-card-wrapper input[type="radio"] {
  position: absolute;
  opacity: 0;
}

.plan-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 2px solid #e2e8f0;
  transition: all 0.3s ease;
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.plan-card-wrapper input[type="radio"]:checked + .plan-card {
  border-color: #2a52be;
  box-shadow: 0 4px 25px rgba(42, 82, 190, 0.15);
  transform: translateY(-5px);
}

.plan-card-header {
  background: linear-gradient(135deg, #2a52be, #3b82f6);
  color: white;
  padding: 1.5rem;
  position: relative;
}

.plan-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.2);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.plan-name {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.plan-duration {
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  opacity: 0.9;
}

.plan-duration i {
  margin-right: 0.5rem;
  font-size: 0.9rem;
}

.plan-card-body {
  padding: 1.5rem;
  flex-grow: 1;
}

/* Timeline Styling */
.installment-timeline {
  margin: 1rem 0;
}

.timeline-item {
  display: flex;
  margin-bottom: 1rem;
}

.timeline-marker {
  position: relative;
  width: 24px;
  margin-right: 1rem;
}

.timeline-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #2a52be;
  border: 3px solid #e2e8f0;
  z-index: 2;
  position: relative;
}

.timeline-line {
  position: absolute;
  left: 7px;
  top: 16px;
  bottom: -1rem;
  width: 2px;
  background: #e2e8f0;
}

.timeline-content {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.installment-period {
  grid-column: span 2;
  font-weight: 600;
  color: #2a52be;
  font-size: 0.9rem;
}

.installment-date {
  font-size: 0.85rem;
  color: #64748b;
  display: flex;
  align-items: center;
}

.installment-date i {
  margin-right: 0.25rem;
  font-size: 0.8rem;
}

.installment-amount {
  text-align: right;
  font-weight: 600;
  color: #10b981;
}

/* Plan Summary */
.plan-summary {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px dashed #e2e8f0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.summary-item {
  display: flex;
  flex-direction: column;
}

.summary-item span:first-child {
  font-size: 0.8rem;
  color: #64748b;
}

.summary-value {
  font-weight: 600;
  color: #1e293b;
  font-size: 1.1rem;
}

/* Footer */
.plan-card-footer {
  padding: 1rem 1.5rem;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

.penalty-notice {
  font-size: 0.8rem;
  color: #ef4444;
  display: flex;
  align-items: center;
}

.penalty-notice i {
  margin-right: 0.5rem;
}

/* Select Button */
.btn-select-plan {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.btn-select-plan i {
  margin-left: 0.5rem;
  transition: transform 0.3s ease;
}

.btn-select-plan:hover i {
  transform: translateX(3px);
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .plan-selection-grid {
    grid-template-columns: 1fr;
  }

  .timeline-content {
    grid-template-columns: 1fr;
  }

  .installment-amount {
    text-align: left;
  }

  .plan-summary {
    grid-template-columns: 1fr;
  }
}

/* First Installment Styles */
.first-installment {
  position: relative;
}

.first-installment::before {
  content: "";
  position: absolute;
  top: 0;
  left: -10px;
  right: -10px;
  bottom: 0;
  background: rgba(239, 68, 68, 0.05);
  border-radius: 8px;
  z-index: -1;
}

.today-badge {
  background: #ef4444;
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  margin-left: 0.5rem;
  animation: pulse 2s infinite;
}

.today-badge i {
  margin-right: 0.25rem;
  font-size: 0.7rem;
}

.first-dot {
  background: #ef4444 !important;
  border-color: white !important;
  box-shadow: 0 0 0 2px #ef4444;
}

.first-amount {
  color: #ef4444;
  font-weight: 700;
}

.installment-header {
  display: flex;
  align-items: center;
  margin-bottom: 0.25rem;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* Full-page processing overlay with 60% transparency */
#processingOverlay {
  position: fixed;
  inset: 0;
  display: none; /* default hidden */
  align-items: center; /* center spinner */
  justify-content: center; /* center spinner */
  background: rgba(247, 250, 255, 0.6); /* 60% transparency */
  backdrop-filter: saturate(180%) blur(6px);
  z-index: 9999;
}

/* When body has the flag, show overlay and freeze UI */
body.is-processing #processingOverlay {
  display: flex;
}

body.is-processing .qpay-container {
  filter: blur(1px);
  pointer-events: none;
  user-select: none;
}

/* Collapse unselected plans */
.plan-card.collapsed .plan-card-body,
.plan-card.collapsed .plan-card-footer {
  display: none;
}

/* Make sure plan headers look clickable when collapsed */
.plan-card.collapsed .plan-card-header {
  cursor: pointer;
}

/* Collapse look for unselected plans */
.plan-card.collapsed {
  max-height: 100px; /* show just the header band */
  overflow: hidden;
  filter: grayscale(35%);
  opacity: 0.85;
  cursor: pointer;
  transition: max-height 0.25s ease, opacity 0.25s ease, filter 0.25s ease;
}

/* Ensure internal "loading step" (server-driven) aligns center if used */
.loading-container {
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}
