/* ============================================
   CSS VARIABLES - Purple Theme
   ============================================ */
:root {
  /* Colors - Purple Theme */
  --primary-purple: #CF9FFF;
  --light-purple: #E5CCFF;
  --dark-purple: #B380E6;
  --bg-cream: #FFF9F0;
  --card-bg: #FFFBF5;
  --text-dark: #333333;
  --text-medium: #666666;
  --text-light: #999999;
  --text-on-purple: #FFFFFF;
  --success-green: #6BCF7F;
  --error-red: #FF6B6B;
  --warning-yellow: #FFD93D;
  
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-page-title: 24px;
  --font-section-header: 18px;
  --font-body: 16px;
  --font-button: 16px;
  --font-amount-mobile: 25px;
  --font-amount: 48px;
  --font-small: 14px;
  --font-tiny: 12px;
  
  /* Spacing */
  --page-padding: 20px;
  --card-padding: 16px;
  --button-padding: 12px 24px;
  --icon-size: 32px;
  --icon-large: 48px;
  
  /* Border Radius */
  --radius-small: 8px;
  --radius-medium: 12px;
  --radius-large: 24px;
  --radius-circle: 50%;
  
  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
  --shadow-purple: 0 4px 12px rgba(207, 159, 255, 0.4);
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
  
  /* Z-index */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
}

/* ============================================
   RESET & BASE STYLES
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-body);
  line-height: 1.6;
  color: var(--text-dark);
  background-color: var(--bg-cream);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-dark);
  margin-bottom: 0.5em;
}

h1 { font-size: var(--font-page-title); font-weight: 700; }
h2 { font-size: var(--font-section-header); font-weight: 600; }
h3 { font-size: var(--font-body); font-weight: 600; }

p {
  margin-bottom: 1em;
}

a {
  color: var(--primary-purple);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--dark-purple);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: var(--button-padding);
  font-size: var(--font-button);
  font-weight: 600;
  border: none;
  border-radius: var(--radius-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px; /* Touch-friendly */
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button Variants */
.btn-primary {
  background-color: var(--primary-purple);
  color: var(--text-on-purple);
}

.btn-primary:hover {
  background-color: var(--dark-purple);
}

.btn-primary:active {
  background-color: var(--dark-purple);
}

.btn-secondary {
  background-color: var(--card-bg);
  color: var(--text-dark);
  border: 2px solid var(--light-purple);
}

.btn-secondary:hover {
  background-color: var(--light-purple);
}

.btn-success {
  background-color: var(--success-green);
  color: var(--text-on-purple);
}

.btn-success:hover {
  background-color: #5ABF6F;
}

.btn-danger {
  background-color: var(--error-red);
  color: var(--text-on-purple);
}

.btn-danger:hover {
  background-color: #FF5555;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-circle);
}

.btn-large {
  width: 80px;
  height: 80px;
  font-size: 36px;
  border-radius: var(--radius-circle);
  border: 4px solid currentColor;
  background-color: var(--card-bg);
}

.btn-block {
  width: 100%;
  display: flex;
}

/* ============================================
   INPUTS & FORMS
   ============================================ */
input, select, textarea {
  width: 100%;
  padding: 12px 16px;
  font-size: var(--font-body);
  font-family: var(--font-family);
  color: var(--text-dark);
  background-color: var(--card-bg);
  border: 1px solid var(--light-purple);
  border-radius: var(--radius-small);
  transition: all var(--transition-fast);
  min-height: 44px; /* Touch-friendly */
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-purple);
  border-width: 2px;
  padding: 11px 15px; /* Adjust for border width change */
}

input::placeholder, textarea::placeholder {
  color: var(--text-light);
}

input:disabled, select:disabled, textarea:disabled {
  background-color: #F5F5F5;
  cursor: not-allowed;
  opacity: 0.6;
}

input.error, select.error, textarea.error {
  border-color: var(--error-red);
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  font-size: var(--font-body);
  font-family: var(--font-family);
  color: var(--text-dark);
  background-color: var(--card-bg);
  border: 1px solid var(--light-purple);
  border-radius: var(--radius-small);
  transition: all var(--transition-fast);
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-purple);
  border-width: 2px;
  padding: 11px 15px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: var(--font-small);
  font-weight: 600;
  color: var(--text-medium);
}

.form-group {
  margin-bottom: 20px;
}

/* ============================================
   CARDS
   ============================================ */
.card {
  background-color: var(--card-bg);
  border-radius: var(--radius-medium);
  padding: var(--card-padding);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-selected {
  border: 2px solid var(--primary-purple);
  background-color: var(--light-purple);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--page-padding);
}

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--primary-purple); }
.text-success { color: var(--success-green); }
.text-danger { color: var(--error-red); }
.text-muted { color: var(--text-medium); }

.bg-primary { background-color: var(--primary-purple); }
.bg-light { background-color: var(--light-purple); }
.bg-cream { background-color: var(--bg-cream); }
.bg-card { background-color: var(--card-bg); }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }

.p-1 { padding: 8px; }
.p-2 { padding: 16px; }
.p-3 { padding: 24px; }
.p-4 { padding: 32px; }

.hidden { display: none !important; }
.invisible { visibility: hidden; }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-column { flex-direction: column; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }

.rounded { border-radius: var(--radius-medium); }
.rounded-full { border-radius: var(--radius-circle); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* ============================================
   LOADING SPINNER
   ============================================ */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--light-purple);
  border-top-color: var(--primary-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

/* ============================================
   MODAL/POPUP BASE - FIXED
   ============================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal-backdrop);
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-backdrop.modal-open {
  display: flex; /* Show when modal-open class added */
}

/* Modal container */
.modal {
  background-color: var(--card-bg);
  border-radius: var(--radius-large);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: var(--z-modal);
}

/* Modal header */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background-color: var(--primary-purple);
  color: var(--text-on-purple);
  border-bottom: 1px solid var(--light-purple);
}

.modal-title {
  font-size: var(--font-section-header);
  font-weight: 600;
  color: var(--text-on-purple);
  margin: 0;
}

.modal-close-btn {
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--text-on-purple);
  font-size: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-small);
  transition: all var(--transition-fast);
  line-height: 1;
  padding: 0;
}

.modal-close-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Modal body */
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* Modal variations */
.modal-bottom {
  width: 100%;
  max-width: 100%;
  border-radius: var(--radius-large) var(--radius-large) 0 0;
  max-height: 80vh;
  position: absolute;
  bottom: 0;
  transform: translateY(100%);
  transition: transform var(--transition-normal);
}

.modal-backdrop.modal-open .modal-bottom {
  transform: translateY(0);
}

.modal-center {
  opacity: 0;
  transform: scale(0.9);
  transition: all var(--transition-normal);
}

.modal-backdrop.modal-open .modal-center {
  opacity: 1;
  transform: scale(1);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ============================================
   TOAST/NOTIFICATION
   ============================================ */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: var(--card-bg);
  color: var(--text-dark);
  padding: 16px 20px;
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-tooltip);
  animation: slideInRight 0.3s ease;
  min-width: 280px;
  max-width: 400px;
}

.toast.success { border-left: 4px solid var(--success-green); }
.toast.error { border-left: 4px solid var(--error-red); }
.toast.warning { border-left: 4px solid var(--warning-yellow); }

@keyframes slideInRight {
  from { transform: translateX(400px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================
   NAVBAR ICON BUTTON (for modal headers)
   ============================================ */
.navbar-icon {
  background: transparent;
  border: none;
  color: var(--text-on-purple);
  font-size: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-small);
  transition: all var(--transition-fast);
}

.navbar-icon:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

/* ============================================
   RESPONSIVE - DESKTOP
   ============================================ */
@media (min-width: 768px) {
  :root {
    --page-padding: 40px;
  }
  
  .modal {
    max-width: 600px;
    border-radius: var(--radius-medium);
    animation: scaleIn 0.3s ease;
  }
  
  .modal-bottom {
    max-width: 800px;
    left: 50%;
    transform: translate(-50%, 100%);
    border-radius: var(--radius-medium);
  }
  
  .modal-backdrop.modal-open .modal-bottom {
    transform: translate(-50%, 0);
  }
  
  @keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
  }
  
  .btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
  
  .btn:active {
    transform: translateY(0);
  }
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background-color: var(--bg-cream);
}

::-webkit-scrollbar-thumb {
  background-color: var(--light-purple);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--primary-purple);
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--primary-purple);
  outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}