/* Mobile Performance Optimizations */
* {
  box-sizing: border-box;
}

/* Reduce motion for users who prefer it (performance boost) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body { 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif; 
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #333;
  min-height: 100vh;
  /* Optimize font rendering and prevent font-swap layout shifts */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeSpeed;
  font-display: swap;
}

/* Navbar Styles */
.navbar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 70px;
}

.nav-brand a {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: #2c3e50;
  font-weight: 700;
  font-size: 1.5rem;
}

.brand-icon {
  font-size: 2rem;
  margin-right: 10px;
}

.brand-text {
  background: linear-gradient(135deg, #ff0050, #ff6b9d);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 30px;
}

.nav-link {
  text-decoration: none;
  color: #2c3e50;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 25px;
  transition: all 0.3s ease;
  position: relative;
}

.nav-link:hover,
.nav-link.active {
  background: linear-gradient(135deg, #ff0050, #ff6b9d);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 0, 80, 0.3);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  cursor: pointer;
  padding: 5px;
}

.bar {
  width: 25px;
  height: 3px;
  background: #2c3e50;
  margin: 3px 0;
  transition: 0.3s;
  border-radius: 2px;
}

.nav-toggle.active .bar:nth-child(2) {
  opacity: 0;
}

.nav-toggle.active .bar:nth-child(1) {
  transform: translateY(9px) rotate(45deg);
}

.nav-toggle.active .bar:nth-child(3) {
  transform: translateY(-9px) rotate(-45deg);
}

/* Main Content */
.main-content {
  min-height: calc(100vh - 140px);
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 20px;
  background: white;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.1);
}

h1 {
  background: linear-gradient(135deg, #ff0050, #ff6b9d);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  margin-bottom: 15px;
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

h2 {
  color: #2c3e50;
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, #ff0050, #ff6b9d) 1;
  padding-bottom: 15px;
  font-size: 1.8rem;
  font-weight: 600;
  margin-top: 40px;
}

h3 {
  color: #34495e;
  margin-top: 25px;
  font-weight: 600;
  font-size: 1.1rem;
}

.container > p {
  text-align: center;
  color: #7f8c8d;
  font-size: 1.1rem;
  margin-bottom: 40px;
  line-height: 1.6;
}

.calculator-form {
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  padding: 40px;
  border-radius: 20px;
  margin-bottom: 40px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.form-group {
  margin-bottom: 25px;
  /* Prevent layout shift by reserving minimum height */
  min-height: 85px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #2c3e50;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 16px 20px;
  border: 2px solid #e1e8ed;
  border-radius: 12px;
  font-size: 16px;
  background: white;
  transition: all 0.3s ease;
  font-family: inherit;
  /* Fixed height to prevent layout shift */
  min-height: 54px;
  line-height: 1.5;
  box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus {
  border-color: #ff0050;
  outline: none;
  box-shadow: 0 0 0 4px rgba(255, 0, 80, 0.1);
  transform: translateY(-2px);
}

.form-group input:hover,
.form-group select:hover {
  border-color: #ff6b9d;
}

.calculate-btn {
  background: linear-gradient(135deg, #ff0050, #ff6b9d);
  color: white;
  border: none;
  padding: 18px 40px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 50px;
  cursor: pointer;
  width: 100%;
  margin-top: 20px;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 10px 30px rgba(255, 0, 80, 0.3);
}

.calculate-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 40px rgba(255, 0, 80, 0.4);
}

.calculate-btn:active {
  transform: translateY(-1px);
}

.form-actions {
  display: flex;
  gap: 20px;
  align-items: stretch;
  margin-top: 20px;
}

.form-actions .calculate-btn {
  flex: 2;
  margin-top: 0;
}

.form-actions .clear-btn {
  flex: 1;
}

.clear-btn {
  background: transparent;
  color: #666;
  border: 2px solid #ddd;
  padding: 18px 30px;
  border-radius: 50px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  height: 58px;
  box-sizing: border-box;
}

.clear-btn:hover {
  background: #f5f5f5;
  border-color: #999;
  color: #333;
  text-decoration: none;
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.clear-btn:active {
  transform: translateY(-1px);
}

@media (max-width: 768px) {
  .form-actions {
    flex-direction: column;
    gap: 15px;
  }
  
  .form-actions .calculate-btn,
  .form-actions .clear-btn {
    flex: none;
    width: 100%;
  }
}

.results {
  margin-top: 50px;
  animation: fadeInUp 0.8s ease;
}

/* Results placeholder to prevent layout shift */
.results-placeholder {
  margin-top: 50px;
  min-height: 400px;
  display: none;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 25px;
  margin: 30px 0;
}

.result-card {
  background: white;
  border: 1px solid #e1e8ed;
  border-radius: 16px;
  padding: 25px;
  transition: all 0.3s ease;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
}

.result-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
}

.result-card.highlight {
  background: linear-gradient(135deg, #ff0050, #ff6b9d);
  color: white;
  border: none;
  box-shadow: 0 10px 30px rgba(255, 0, 80, 0.3);
}

.result-card.highlight:hover {
  box-shadow: 0 20px 40px rgba(255, 0, 80, 0.4);
}

.result-card h3 {
  margin-top: 0;
  color: inherit;
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 15px;
}

.result-card p {
  margin: 8px 0;
  line-height: 1.5;
}

.result-card strong {
  font-weight: 600;
}

.big-number {
  font-size: 2rem;
  font-weight: 700;
  margin: 15px 0;
  line-height: 1.2;
}

.result-card.highlight small {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.85rem;
}

.disclaimer {
  background: linear-gradient(135deg, #fff3e0, #ffe8cc);
  border: 2px solid #ffcc80;
  border-radius: 12px;
  padding: 20px;
  margin-top: 30px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #bf6900;
}

/* Error Message Styles - prevent layout shift */
.error-message {
  background: linear-gradient(135deg, #ffebee, #ffcdd2);
  border: 2px solid #f44336;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 30px;
  font-size: 1rem;
  line-height: 1.6;
  color: #c62828;
  animation: shake 0.5s ease-in-out;
  /* Fixed minimum height to prevent layout shift */
  min-height: 60px;
  box-sizing: border-box;
}

.error-message p {
  margin: 0;
}

.error-message strong {
  color: #d32f2f;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* About Page Styles */
.about-page {
  max-width: 800px;
  margin: 0 auto;
}

.about-intro {
  text-align: center;
  margin-bottom: 50px;
}

.lead {
  font-size: 1.3rem;
  color: #7f8c8d;
  line-height: 1.6;
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 30px;
  margin: 50px 0;
}

.about-card {
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  padding: 30px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.about-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.about-icon {
  font-size: 3rem;
  margin-bottom: 20px;
}

.methodology {
  margin: 50px 0;
}

.method-section {
  background: white;
  border: 1px solid #e1e8ed;
  border-radius: 16px;
  padding: 25px;
  margin: 20px 0;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.method-section h3 {
  margin-top: 0;
  color: #2c3e50;
}

.method-section ul {
  padding-left: 20px;
}

.method-section li {
  margin: 8px 0;
  line-height: 1.5;
}

.data-sources {
  margin: 50px 0;
}

.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin: 30px 0;
}

.source-card {
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  padding: 25px;
  border-radius: 16px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.source-card h4 {
  margin-top: 0;
  color: #2c3e50;
  font-weight: 600;
}

.disclaimer-section {
  margin: 50px 0;
}

.disclaimer-box {
  background: linear-gradient(135deg, #fff3e0, #ffe8cc);
  border: 2px solid #ffcc80;
  border-radius: 16px;
  padding: 30px;
  color: #bf6900;
}

.disclaimer-box ul {
  padding-left: 20px;
}

.disclaimer-box li {
  margin: 8px 0;
}

.cta-section {
  text-align: center;
  margin: 50px 0;
  padding: 40px;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border-radius: 20px;
}

.cta-button {
  display: inline-block;
  background: linear-gradient(135deg, #ff0050, #ff6b9d);
  color: white;
  text-decoration: none;
  padding: 15px 40px;
  border-radius: 50px;
  font-weight: 600;
  margin-top: 20px;
  transition: all 0.3s ease;
  box-shadow: 0 10px 30px rgba(255, 0, 80, 0.3);
}

.cta-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 40px rgba(255, 0, 80, 0.4);
}

/* Footer */
.footer {
  background: rgba(44, 62, 80, 0.9);
  color: white;
  text-align: center;
  padding: 20px;
  margin-top: 50px;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
}

/* Mobile Navigation */
@media (max-width: 768px) {
  .nav-menu {
    position: fixed;
    left: -100%;
    top: 60px;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    width: 100%;
    text-align: center;
    transition: 0.3s;
    box-shadow: 0 10px 27px rgba(0, 0, 0, 0.05);
    padding: 20px 0;
    gap: 10px;
    z-index: 999;
  }

  .nav-menu.active {
    left: 0;
  }

  .nav-toggle {
    display: flex;
  }

  .container {
    padding: 20px 15px;
  }
  
  h1 {
    font-size: 2rem;
  }
  
  .calculator-form {
    padding: 25px;
    border-radius: 15px;
  }
  
  .results-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .result-card {
    padding: 20px;
  }
  
  .big-number {
    font-size: 1.6rem;
  }

  .about-grid {
    grid-template-columns: 1fr;
  }

  .sources-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .nav-container {
    padding: 0 15px;
  }

  .container {
    padding: 15px 10px;
  }
  
  h1 {
    font-size: 1.8rem;
  }
  
  .calculator-form {
    padding: 20px;
  }
  
  .form-group input,
  .form-group select {
    padding: 14px 16px;
  }
  
  .calculate-btn {
    padding: 16px 30px;
    font-size: 16px;
  }

  .about-card {
    padding: 20px;
  }

  .method-section {
    padding: 20px;
  }

  .disclaimer-box {
    padding: 20px;
  }
}

/* Info Icon Styles */
.info-icon {
  display: inline-block;
  margin-left: 8px;
  color: #667eea;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: normal;
  transition: all 0.3s ease;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  text-align: center;
  line-height: 20px;
}

.info-icon:hover {
  color: #ff0050;
  background: rgba(255, 0, 80, 0.1);
  transform: scale(1.1);
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  animation: fadeIn 0.3s ease;
}

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

.modal-content {
  background: white;
  margin: 5% auto;
  padding: 0;
  border-radius: 20px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { 
    opacity: 0;
    transform: translateY(-50px);
  }
  to { 
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px 30px;
  border-radius: 20px 20px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.3rem;
  color: white;
  border: none;
}

.close {
  color: white;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.modal-body {
  padding: 30px;
}

.requirement-section {
  margin-bottom: 25px;
  padding: 20px;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border-radius: 15px;
  border-left: 4px solid transparent;
  border-image: linear-gradient(135deg, #ff0050, #ff6b9d) 1;
}

.requirement-section h4 {
  margin-top: 0;
  margin-bottom: 15px;
  color: #2c3e50;
  font-size: 1.1rem;
  font-weight: 600;
}

.requirement-section ul {
  margin: 0;
  padding-left: 20px;
}

.requirement-section li {
  margin: 8px 0;
  line-height: 1.5;
}

.requirement-section p {
  margin: 8px 0;
  line-height: 1.6;
}

.requirement-section strong {
  color: #2c3e50;
  font-weight: 600;
}

.requirement-section em {
  color: #7f8c8d;
  font-style: italic;
}

/* Mobile Modal Styles */
@media (max-width: 768px) {
  .modal-content {
    margin: 10% auto;
    width: 95%;
    max-height: 85vh;
  }
  
  .modal-header {
    padding: 15px 20px;
  }
  
  .modal-header h3 {
    font-size: 1.1rem;
  }
  
  .modal-body {
    padding: 20px;
  }
  
  .requirement-section {
    padding: 15px;
    margin-bottom: 20px;
  }
}

@media (max-width: 480px) {
  .modal-content {
    margin: 5% auto;
    width: 98%;
    max-height: 90vh;
  }
  
  .modal-header {
    padding: 12px 15px;
  }
  
  .modal-body {
    padding: 15px;
  }
}

/* Mobile Performance Optimizations & CLS Prevention */
@media (max-width: 768px) {
  /* Reduce backdrop filter intensity for better mobile performance */
  .navbar {
    backdrop-filter: blur(5px) !important;
    -webkit-backdrop-filter: blur(5px) !important;
    /* Fixed height prevents navbar layout shift */
    height: 60px !important;
  }
  
  .nav-container {
    height: 60px !important;
  }
  
  .nav-menu {
    top: 60px !important;
  }
  
  /* Mobile-specific form sizing to prevent shifts */
  .form-group {
    min-height: 75px !important;
  }
  
  .form-group input,
  .form-group select {
    min-height: 48px !important;
    padding: 12px 16px !important;
  }
  
  /* Simplify shadows for mobile */
  .result-card {
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
  }
  
  /* Remove hover effects on mobile for performance */
  .result-card:hover, 
  .calculate-btn:hover,
  .clear-btn:hover {
    transform: none !important;
  }
  
  /* Optimize animations for mobile - disable expensive ones */
  .calculator-section,
  .results {
    animation: none !important;
  }
  
  /* Reduce gradient complexity on mobile */
  body {
    background: linear-gradient(135deg, #667eea, #764ba2) !important;
  }
  
  /* Optimize will-change property usage */
  .form-control:focus {
    will-change: auto;
  }
  
  /* GPU acceleration only for critical elements */
  .modal {
    will-change: transform, opacity;
  }
  
  .modal.show {
    will-change: auto;
  }
  
  /* Reserve space for calculator section on mobile */
  .calculator-section {
    min-height: 500px !important;
  }
}

/* Additional CLS Prevention Rules */
/* Ensure all images and icons have dimensions */
img, svg {
  max-width: 100%;
  height: auto;
}

/* Prevent shifts from dynamic content loading */
.result-card {
  min-height: 200px;
  contain: layout style;
}

/* Container queries for better responsive behavior */
.calculator-form {
  contain: layout style paint;
}

/* Stabilize button layout */
.form-actions {
  min-height: 70px;
  align-items: stretch;
}

/* Prevent font-loading induced layout shifts */
@font-face {
  font-family: 'System';
  src: local('system-ui'), local('-apple-system'), local('BlinkMacSystemFont');
  font-display: swap;
}
