/* CRITICAL FIX: Balance meter circle - Allow JavaScript control */
.balance-meter .meter-container .meter-indicator,
.meter-container .meter-indicator,
#balance-indicator {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  min-height: 26px !important;
  max-width: 26px !important;
  max-height: 26px !important;
  border-radius: 50% !important;
  position: absolute !important;
  top: -6px !important;
  /* JavaScript can override this initial position */
  left: 50%;
  /* Allow JavaScript to control transform - no !important */
  transform: translateX(-50%);
  background: white !important;
  border: 3px solid #333 !important;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
  z-index: 2 !important;
  box-sizing: border-box !important;
  display: block !important;
  transition: left 0.5s ease !important;
}

.balance-meter .meter-container {
  overflow: visible !important;
  position: relative !important;
  height: 14px !important;
  width: 100% !important;
  background: linear-gradient(to right, #ef4444, #f59e0b, #10b981) !important;
  border-radius: 7px !important;
  margin: 20px 0 !important;
}

/* Large screens */
@media (min-width: 1400px) {
  .container {
    max-width: 2000px;
    grid-template-columns: 200px 1.2fr 0.8fr 200px;
  }
  
  .header h1 {
    font-size: 2.5rem;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .ad-container.vertical {
    min-height: 700px;
    width: 180px;
  }
}

/* Medium to Large screens */
@media (max-width: 1200px) {
  .container { 
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    width: 100vw;
  }
  
  .ad-sidebar {
    display: none; /* Hide side ads on medium screens */
  }
  
  .right-panel {
    position: static;
    min-height: auto; /* Remove fixed height on smaller screens */
    border-left: none;
    border-top: 1px solid #dee2e6;
  }
  
  .left-panel {
    min-height: auto;
  }
  
  .form-row { 
    grid-template-columns: 1fr; 
  }
  
  .header h1 {
    font-size: 2rem;
  }
}

/* Tablet styles */
@media (max-width: 768px) {
  body {
    padding: 0; /* Keep zero padding for full width */
  }

  .header svg {
    margin: 0 !important;
    flex: 1;
    min-width: 0;
  }
  
  .header-content {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    flex-wrap: nowrap;
  }
  
  .support-button {
    margin-top: 10px;
    padding: 6px 8px;
    min-width: 60px;
    flex-shrink: 0;
  }
  
  .support-button i {
    font-size: 0.9rem;
  }
  
  .support-button span {
    font-size: 0.7rem;
  }
  
  /* Fix goal slider thumb clipping on tablets */
  .goal-item input[type="range"].slider,
  .goal-item .slider {
    margin: 18px 0 !important;
    padding: 0 !important;
    height: 6px !important;
    border: none !important;
    background: #dee2e6 !important;
    border-radius: 3px !important;
    overflow: visible !important;
    box-sizing: content-box !important;
    -webkit-appearance: none !important;
  }

  /* CRITICAL FIX: Progress bars must not be forced to 100% width on tablets */
  .progress-fill,
  #financial-health-bar,
  #expense-progress,
  .progress-container .progress-fill,
  .progress-bar .progress-fill {
    width: auto !important;
    max-width: none !important;
  }

  /* ULTRA-SPECIFIC FIX: Force financial health bar to respect JavaScript width */
  #financial-health-bar {
    transition: width 0.5s ease !important;
  }
  
  /* Override any background that might make it appear full */
  .progress-bar {
    background: #e9ecef !important;
  }
  
  /* Ensure goal items don't clip slider thumbs on tablets */
  .goal-item {
    overflow: visible !important;
  }
  
  
  .container {
    width: 100vw;
    grid-template-columns: 1fr;
  }
  
  .ad-sidebar {
    display: none; /* Hide side ads on tablets */
  }
  
  .left-panel {
    padding: 20px;
  }
  
  .right-panel {
    padding: 20px;
  }
  
  .header {
    padding: 10px 20px 20px 20px;
    margin-bottom: 20px;
  }
  
  .header h1 {
    font-size: 1.8rem;
  }
  
  .header p {
    font-size: 0.9rem;
  }
  
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    -ms-overflow-style: auto;
    padding-bottom: 5px;
    margin-bottom: 20px;
  }
  
  .tabs::-webkit-scrollbar {
    display: block;
    height: 3px;
  }
  
  .tabs::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
  }
  
  .tabs::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
  }
  
  .tabs::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
  }
  
  .tab {
    white-space: nowrap;
    padding: 10px 4px;
    min-width: 50px;
    max-width: 80px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    font-size: 12px;
    margin-right: 2px;
  }
  
  .tab:active {
    background-color: rgba(102, 126, 234, 0.1);
    transform: scale(0.98);
    transition: all 0.1s ease;
  }
  
  .section-title {
    font-size: 1.2rem !important;
    flex-direction: row !important;
    gap: 10px !important;
    text-align: left !important;
    align-items: center !important;
    justify-content: space-between !important;
    display: flex !important;
  }
  
  .section-title span {
    flex: 1 !important;
    display: flex !important;
    align-items: center !important;
  }
  
  .section-title .info-icon {
    flex-shrink: 0 !important;
    margin-left: 8px !important;
    margin-right: 0 !important;
    font-size: 1rem !important;
    padding: 4px !important;
    border-radius: 50% !important;
    transition: all 0.2s ease !important;
  }
  
  .section-title .info-icon:hover {
    background-color: rgba(102, 126, 234, 0.1) !important;
    transform: scale(1.1) !important;
  }
  
  .section-title .info-icon:active {
    transform: scale(0.95) !important;
  }
  
  /* Ensure section titles are properly inline on mobile */
  .section .section-title {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
  }
  
  .section .section-title span {
    order: 1 !important;
  }
  
  .section .section-title .info-icon {
    order: 2 !important;
  }
  
  .card {
    padding: 20px;
  }
  
  .goal-controls {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .amount-display {
    text-align: left;
    margin-bottom: 20px;
  }
  
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  
  .kpi-card {
    padding: 12px;
  }
  
  .kpi-value {
    font-size: 1.1rem;
  }
  
  .export-buttons {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .scenario-metrics {
    grid-template-columns: 1fr;
  }
  
  .plan-metrics {
    grid-template-columns: 1fr;
  }
  
  .go-to-top {
    bottom: 90px; /* Position above mobile navigation */
    right: 20px;
    width: 45px;
    height: 45px;
    font-size: 16px;
    z-index: 1040; /* Below mobile nav but above other content */
  }

  /* REMOVED: Duplicate rule - already exists at top of file */

  .meter-container {
    overflow: visible !important;
    position: relative !important;
    height: 14px !important;
    background: linear-gradient(to right, #ef4444, #f59e0b, #10b981) !important;
    border-radius: 7px !important;
    margin: 20px 0 !important;
  }
}

/* Mobile styles */
@media (max-width: 480px) {
  body {
    padding: 5px;
  }

  .header svg {
    margin: 0 auto !important;
    max-width: 500px !important; /* Increased from 400px for mobile */
  }
  
  /* Fix mobile goal slider thumb clipping */
  .goal-item input[type="range"].slider,
  .goal-item .slider {
    margin: 20px 0 !important;
    padding: 0 !important;
    height: 6px !important;
    border: none !important;
    background: #dee2e6 !important;
    border-radius: 3px !important;
    overflow: visible !important;
    box-sizing: content-box !important;
    position: relative !important;
    -webkit-appearance: none !important;
  }

  /* CRITICAL FIX: Progress bars must not be forced to 100% width */
  .progress-fill,
  #financial-health-bar,
  #expense-progress,
  .progress-container .progress-fill,
  .progress-bar .progress-fill {
    width: auto !important;
    max-width: none !important;
  }

  /* ULTRA-SPECIFIC FIX: Force financial health bar to respect JavaScript width */
  #financial-health-bar {
    transition: width 0.5s ease !important;
  }
  
  /* Override any background that might make it appear full */
  .progress-bar {
    background: #e9ecef !important;
  }
  
  /* REMOVED: Another duplicate rule - consolidating at top of file */
  
  /* Mobile goal slider track - keep it visible */
  .goal-item input[type="range"].slider::-webkit-slider-track,
  .goal-item .slider::-webkit-slider-track {
    height: 6px !important;
    background: #dee2e6 !important;
    border-radius: 3px !important;
    border: none !important;
    -webkit-appearance: none !important;
  }
  
  /* Mobile goal slider thumb - with proper spacing */
  .goal-item input[type="range"].slider::-webkit-slider-thumb,
  .goal-item .slider::-webkit-slider-thumb {
    margin-top: -6px !important;
    height: 18px !important;
    width: 18px !important;
    border-radius: 50% !important;
    background: var(--primary) !important;
    cursor: pointer !important;
    -webkit-appearance: none !important;
    border: none !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
    position: relative !important;
    z-index: 100 !important;
  }
  
  /* Ensure goal items don't clip slider thumbs but keep normal size */
  .goal-item {
    overflow: visible !important;
    padding: 15px !important;
  }
  
  .balance-meter {
    width: 100% !important;
    overflow: visible !important;
  }
  
  .meter-container {
    overflow: visible !important;
    position: relative !important;
    height: 14px !important;
    width: 100% !important;
    display: block !important;
    background: linear-gradient(to right, #ef4444, #f59e0b, #10b981) !important;
    border-radius: 7px !important;
    margin: 20px 0 !important;
  }

  /* Additional fix for very small screens */
  @media screen and (max-width: 480px) {
    .meter-indicator, #balance-indicator {
      width: 24px !important;
      height: 24px !important;
      border-radius: 12px !important;
      transform: translateX(-50%) scale(1) !important;
    }
  }
  
  .left-panel {
    padding: 15px;
  }
  
  .right-panel {
    padding: 15px;
  }
  
  .header {
    padding: 20px 15px 25px 15px !important;
  }
  
  .header h1 {
    font-size: 1.6rem;
    margin-bottom: 8px;
  }
  
  .header p {
    font-size: 0.85rem;
    margin-top: 15px;
  }
  
  .support-button {
    margin-top: 10px;
    padding: 3px 5px;
    min-width: 45px;
  }
  
  .support-button i {
    font-size: 0.75rem;
  }
  
  .support-button span {
    font-size: 0.6rem;
  }
  
  .form-group label {
    font-size: 0.85rem;
  }
  
  .form-control {
    padding: 10px 12px;
    font-size: 14px;
  }
  
  .goal-item {
    padding: 15px;
  }
  
  .goal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .goal-title {
    font-size: 0.9rem;
  }
  
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  
  .kpi-card {
    padding: 15px;
  }
  
  .results-title {
    font-size: 1.1rem;
  }
  
  .btn {
    padding: 10px 16px;
    font-size: 13px;
  }
  
  .btn-sm {
    padding: 8px 12px;
    font-size: 12px;
  }
  
  .modal-content {
    padding: 20px;
    width: 95%;
  }
  
  .modal-title {
    font-size: 1.2rem;
  }
  
  .plan-option {
    padding: 15px;
  }
  
  .insight {
    font-size: 0.85rem;
    padding: 10px;
  }
  
  .scenario {
    padding: 12px;
  }
  
  .toast {
    top: 20px;
    right: 10px;
    left: 10px;
    bottom: auto;
    padding: 12px 15px;
    transform: translateY(-100px);
  }
  
  .toast.show {
    transform: translateY(0);
  }
  
  .go-to-top {
    bottom: 85px; /* Position above mobile navigation */
    right: 15px;
    width: 40px;
    height: 40px;
    font-size: 14px;
    z-index: 1040; /* Below mobile nav but above other content */
  }
}

/* Small mobile styles */
@media (max-width: 320px) {
  .header h1 {
    font-size: 1.4rem;
  }

  .header svg {
    margin: 0 auto !important;
    max-width: 480px !important; /* Increased from 400px for small mobile */
  }
  
  .section-title {
    font-size: 1.1rem;
  }
  
  .form-control {
    font-size: 13px;
  }
  
  .goal-input {
    font-size: 13px;
    min-width: 200px; /* Ensure enough width for placeholder text */
  }
  
  .kpi-value {
    font-size: 1rem;
  }
  
  .kpi-label {
    font-size: 0.75rem;
  }
}

/* Print styles */
@media print {
  .container {
    box-shadow: none;
    border-radius: 0;
    grid-template-columns: 1fr;
  }
  
  .ad-sidebar {
    display: none !important;
  }
  
  .no-print {
    display: none !important;
  }
  
  .right-panel {
    break-inside: avoid;
    border-left: none;
    border-top: 1px solid #000;
    background: white !important;
  }
  
  .left-panel {
    background: white !important;
  }
  
  .header {
    background: white !important;
    color: black !important;
    border: 1px solid #000;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #ccc;
  }
  
  .btn {
    display: none;
  }
  
  .tabs {
    display: none;
  }
  
  .modal {
    display: none !important;
  }
  
  .toast {
    display: none !important;
  }
  
  .go-to-top {
    display: none !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .card {
    border: 2px solid #000;
  }
  
  .btn {
    border: 2px solid #000;
  }
  
  .form-control {
    border: 2px solid #000;
  }
  
  .progress-bar {
    border: 1px solid #000;
  }
  
  .slider {
    border: 1px solid #000;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .card:hover {
    transform: none;
  }
  
  .btn:hover {
    transform: none;
  }
  
  .goal-item.active {
    transform: none;
  }
  
  .go-to-top {
    transition: opacity 0.3s ease;
  }
}

/* Mobile Navigation Styles */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #dee2e6;
  z-index: 1050;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
  justify-content: center;
  padding: 8px 0;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 8px;
  margin: 0 10px;
  min-width: 60px;
}

.mobile-nav-item i {
  font-size: 20px;
  margin-bottom: 4px;
  color: #6c757d;
}

.mobile-nav-item span {
  font-size: 12px;
  color: #6c757d;
  font-weight: 500;
}

.mobile-nav-item.active i,
.mobile-nav-item.active span {
  color: var(--primary);
}

.mobile-nav-item.active {
  background: rgba(102, 126, 234, 0.1);
}

.mobile-nav-item:hover {
  background: rgba(102, 126, 234, 0.05);
}

/* Mobile Ad Container */
.mobile-ad-container {
  display: none;
  padding: 10px;
  background: #f8f9fa;
}

.ad-container.mobile-banner {
  min-height: 60px;
  margin: 0;
  border-radius: 6px;
  font-size: 0.75rem;
}

/* Show mobile nav and ads only on small screens */
@media (max-width: 768px) {
  .mobile-nav {
    display: flex !important;
  }
  
  /* Prevent unwanted scroll behaviors on mobile */
  html {
    scroll-behavior: auto !important; /* Disable smooth scrolling on mobile */
  }
  
  body {
    scroll-behavior: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: auto; /* Enable pull-to-refresh */
  }
  
  .mobile-ad-container {
    display: block;
  }
  
  body {
    padding-bottom: 200px; /* Space for fixed bottom nav + banner ads */
    padding-top: 0;
  }
  
  /* Hide desktop sidebars */
  .ad-sidebar {
    display: none !important;
  }
  
  .container {
    grid-template-columns: 1fr !important;
    position: relative;
    min-height: auto;
  }
  
  .container::before {
    left: 0;
    right: 0;
    height: 150px;
  }
  
  /* Mobile section switching */
  .mobile-hidden {
    display: none !important;
  }
  
  #home-section,
  #results-section {
    width: 100%;
    height: auto;
    position: relative;
    overflow-y: visible;
  }
  
  /* Adjust layout for mobile single column */
  .right-panel {
    border-left: none;
    border-top: 1px solid #dee2e6;
    margin-top: 0;
    padding-top: 30px;
    height: auto;
    position: relative;
  }
  
  .left-panel {
    height: auto;
    position: relative;
    padding-bottom: 20px;
  }
  
  /* Mobile ads optimization */
  .ad-container.banner,
  .ad-container.native,
  .ad-container.sidebar {
    margin: 15px 0;
    min-height: 100px;
  }
  
  /* Ensure bottom banner ads don't overlap with mobile navigation */
  .left-panel .ad-container.banner:last-child,
  .right-panel .ad-container.banner:last-child,
  .ad-container.banner:has(p:contains("Bottom Banner")) {
    margin-bottom: 120px !important; /* Extra space above mobile nav */
  }
  
  /* Additional safety for any ads at the end of content */
  .left-panel > .ad-container:last-of-type,
  .right-panel > .ad-container:last-of-type {
    margin-bottom: 120px !important;
  }
  
  /* Add mobile ad between sections */
  #results-section::before {
    content: '';
    display: block;
    width: 100%;
    height: 80px;
    background: #f8f9fa;
    border: 1px dashed #dee2e6;
    border-radius: 6px;
    margin-bottom: 20px;
    position: relative;
  }
  
  #results-section::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 80'%3E%3Ctext x='50%25' y='50%25' text-anchor='middle' dy='.35em' fill='%236c757d' font-size='12' font-family='sans-serif'%3EMobile Banner Ad Space%3C/text%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 250px 30px;
  }
  
  /* Improve touch targets for mobile */
  .btn {
    min-height: 44px;
    padding: 12px 20px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    user-select: none;
  }

  /* Specific fix for Work ↔ Life Balance button */
  #balance-button {
    position: relative !important;
    z-index: 10 !important;
    min-height: 48px !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: rgba(255, 193, 7, 0.3) !important;
    cursor: pointer !important;
  }

  #balance-button:active {
    background-color: #e0a800 !important;
    transform: scale(0.98) !important;
    transition: all 0.1s ease !important;
  }

  .mobile-nav-item {
    min-height: 60px;
    min-width: 80px;
  }
  
  /* Optimize form inputs for mobile */
  .form-control {
    min-height: 48px;
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  /* Mobile KPI grid optimization */
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  
  .kpi-card {
    padding: 16px 12px;
    min-height: 80px;
  }
}

/* Ad Placement Areas */
.ad-container {
  background: #f8f9fa;
  border: 1px dashed #dee2e6;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  margin: 20px 0;
  color: #6c757d;
  font-size: 0.85rem;
  min-height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.ad-container:hover {
  background: #e9ecef;
  border-color: #adb5bd;
}

.ad-container.banner {
  min-height: 120px;
  margin: 15px 0;
}

.ad-container.sidebar {
  min-height: 300px;
  margin: 25px 0;
}

.ad-container.native {
  background: white;
  border: 1px solid #e9ecef;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  min-height: 200px;
}

/* Ad responsive behavior */
@media (max-width: 768px) {
  .ad-container.sidebar {
    min-height: 200px;
    margin: 15px 0;
  }
  
  .ad-container.banner {
    min-height: 100px;
    margin: 10px 0;
  }
  
  /* Override for last banner ads to prevent mobile nav overlap */
  .left-panel > .ad-container.banner:last-of-type,
  .right-panel > .ad-container.banner:last-of-type,
  .ad-container.banner:last-child {
    margin-bottom: 120px !important;
  }
}

/* Large screens */
@media (min-width: 1400px) {
  .container {
    max-width: 2000px;
  }
  
  .header h1 {
    font-size: 2.5rem;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Medium to Large screens */
@media (max-width: 1200px) {
  .container { 
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  
  .right-panel {
    position: static;
    max-height: none;
    border-left: none;
    border-top: 1px solid #dee2e6;
  }
  
  .form-row { 
    grid-template-columns: 1fr; 
  }
  
  .header h1 {
    font-size: 2rem;
  }
}

/* Tablet styles */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  
  /* Loan summary responsive improvements for tablets */
  .loan-summary-item {
    flex-direction: column;
    align-items: flex-start !important;
    padding: 8px 0;
    border-bottom: 1px solid rgba(190, 229, 235, 0.3);
  }
  
  .loan-summary-item:last-child {
    border-bottom: none;
  }
  
  .loan-summary-item span:first-child {
    font-size: 0.85rem;
    color: #6c757d;
    margin-bottom: 4px;
    padding-right: 0;
  }
  
  .loan-summary-item span:last-child {
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    text-align: left;
  }
  
  /* Goal Allocation pie chart responsive improvements for tablets */
  .pie-chart-wrapper {
    flex-direction: column !important;
    align-items: center !important;
    gap: 20px !important;
    padding: 15px !important;
  }
  
  .pie-chart-metrics {
    width: 100% !important;
    max-width: 500px !important;
    max-height: none !important;
    overflow: visible !important;
  }
  
  /* Tablet layout - horizontal but still well-spaced */
  .pie-chart-metric-row.mobile {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 12px 14px !important;
    margin-bottom: 8px !important;
    background: #f8f9fa !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.06) !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-left {
    display: flex !important;
    align-items: center !important;
    flex: 1 !important;
    margin-bottom: 0 !important;
    min-width: 0 !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-icon {
    font-size: 1.3rem !important;
    width: 30px !important;
    height: 30px !important;
    margin-right: 12px !important;
    background: rgba(255,255,255,0.8) !important;
    border-radius: 8px !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-title {
    font-size: 1rem !important;
    font-weight: 600 !important;
    color: #333 !important;
    flex: 1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-right {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-end !important;
    padding: 0 !important;
    width: auto !important;
    flex-shrink: 0 !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-percentage {
    font-size: 1.1rem !important;
    font-weight: bold !important;
    color: var(--primary) !important;
    margin-bottom: 2px !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-amount {
    font-size: 0.9rem !important;
    font-weight: 500 !important;
    color: #666 !important;
  }
  
  .container {
    border-radius: 10px;
    min-height: 95vh;
  }
  
  .left-panel {
    padding: 20px;
  }
  
  .right-panel {
    padding: 20px;
  }
  
  .header {
    padding: 20px;
    margin-bottom: 20px;
  }
  
  .header h1 {
    font-size: 1.8rem;
  }
  
  .header p {
    font-size: 0.9rem;
  }
  
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    -ms-overflow-style: auto;
    padding-bottom: 5px;
    margin-bottom: 20px;
  }
  
  .tabs::-webkit-scrollbar {
    display: block;
    height: 3px;
  }
  
  .tabs::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
  }
  
  .tabs::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
  }
  
  .tabs::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
  }
  
  .tab {
    white-space: nowrap;
    padding: 10px 4px;
    min-width: 50px;
    max-width: 80px;
    font-size: 12px;
    margin-right: 2px;
  }
  
  .section-title {
    font-size: 1.2rem;
    flex-direction: row !important;
    gap: 10px;
    text-align: left !important;
    align-items: center !important;
    justify-content: space-between !important;
  }
  
  .card {
    padding: 20px;
  }
  
  .goal-controls {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .amount-display {
    text-align: left;
    margin-bottom: 20px;
  }
  
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  
  .kpi-card {
    padding: 12px;
  }
  
  .kpi-value {
    font-size: 1.1rem;
  }
  
  .export-buttons {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .scenario-metrics {
    grid-template-columns: 1fr;
  }
  
  .plan-metrics {
    grid-template-columns: 1fr;
  }
}

/* Mobile styles */
@media (max-width: 480px) {
  body {
    padding: 5px;
    padding-bottom: 85px; /* Extra space for nav */
  }
  
  /* Ensure loan details are properly contained on mobile */
  .loan-details-container {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }
  
  .loan-item {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: 15px !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }
  
  /* Mobile loan summary specific improvements */
  .loan-summary {
    margin: 15px 0 !important;
    padding: 12px !important;
    border-radius: 8px;
  }
  
  .loan-summary-item {
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 6px 0 !important;
    margin-bottom: 10px !important;
    border-bottom: 1px solid rgba(190, 229, 235, 0.4) !important;
  }
  
  .loan-summary-item:last-child {
    border-bottom: none !important;
    margin-bottom: 0 !important;
    font-weight: bold !important;
    padding-top: 8px !important;
    border-top: 2px solid #bee5eb !important;
  }
  
  .loan-summary-item span:first-child {
    font-size: 0.8rem !important;
    color: #6c757d !important;
    margin-bottom: 3px !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
  }
  
  .loan-summary-item span:last-child {
    font-size: 1.1rem !important;
    font-weight: 600 !important;
    color: #333 !important;
    text-align: left !important;
  }
  
  /* EMI scenario improvements for mobile */
  .emi-scenario {
    margin-top: 15px !important;
    padding: 12px !important;
    background: rgba(40, 167, 69, 0.05) !important;
    border-radius: 6px !important;
    border: 1px solid rgba(40, 167, 69, 0.2) !important;
    border-top: 3px solid #28a745 !important;
  }
  
  .scenario-header {
    font-size: 0.9rem !important;
    margin-bottom: 10px !important;
    color: #28a745 !important;
  }
  
  /* Enhanced Goal Allocation mobile responsiveness */
  .goal-chart-container {
    padding: 8px !important;
    margin: 10px 0 !important;
  }
  
  .pie-chart-wrapper {
    flex-direction: column !important;
    align-items: center !important;
    gap: 15px !important;
    padding: 8px 5px !important;
  }
  
  .pie-chart-metrics {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }
  
  /* NEW MOBILE LAYOUT: Icon/Name top, %/Amount bottom - COMPLETE OVERRIDE */
  @media (max-width: 768px) {
    
    /* Container overrides - NO SCROLL */
    .goal-chart-container,
    .pie-chart-wrapper,
    .pie-chart-metrics,
    .pie-chart-metrics > div {
      max-height: none !important;
      overflow: visible !important;
      height: auto !important;
    }
    
    .goal-chart-container {
      padding: 5px !important;
      margin: 8px 0 !important;
    }
    
    .pie-chart-wrapper {
      flex-direction: column !important;
      align-items: center !important;
      gap: 10px !important;
      padding: 5px !important;
    }
    
    .pie-chart-metrics {
      width: 100% !important;
      max-width: 100% !important;
      padding: 0 !important;
    }
    
    /* MOBILE METRIC ROW - New 2-row structure */
    .pie-chart-metric-row.mobile {
      display: block !important;
      padding: 10px !important;
      margin-bottom: 8px !important;
      background: #f8f9fa !important;
      border-radius: 8px !important;
      border-left: 3px solid var(--primary) !important;
      box-shadow: 0 2px 4px rgba(0,0,0,0.06) !important;
      min-height: auto !important;
      width: 100% !important;
      box-sizing: border-box !important;
    }
    
    /* TOP ROW: Icon and Name left-aligned */
    .pie-chart-metric-row.mobile .pie-chart-metric-left {
      display: flex !important;
      align-items: center !important;
      justify-content: flex-start !important;
      width: 100% !important;
      margin-bottom: 8px !important;
      text-align: left !important;
    }
    
    .pie-chart-metric-row.mobile .pie-chart-metric-icon {
      font-size: 1.2rem !important;
      margin-right: 8px !important;
      margin-bottom: 0 !important;
      width: auto !important;
      height: auto !important;
      display: inline !important;
      background: none !important;
      border: none !important;
      padding: 0 !important;
      flex-shrink: 0 !important;
      font-family: "Font Awesome 6 Free" !important;
      font-weight: 900 !important;
      line-height: 1 !important;
      text-rendering: auto !important;
      -webkit-font-smoothing: antialiased !important;
    }
    
    .pie-chart-metric-row.mobile .pie-chart-metric-title {
      font-size: 0.9rem !important;
      font-weight: 600 !important;
      color: #2c3e50 !important;
      margin: 0 !important;
      padding: 0 !important;
      background: none !important;
      border: none !important;
      text-align: left !important;
      line-height: 1.2 !important;
      display: inline !important;
      white-space: nowrap !important;
      overflow: visible !important;
    }
    
    /* BOTTOM ROW: Percentage and Amount side by side */
    .pie-chart-metric-row.mobile .pie-chart-metric-right {
      display: flex !important;
      justify-content: space-between !important;
      align-items: center !important;
      width: 100% !important;
      margin: 0 !important;
      padding: 0 !important;
      background: none !important;
      border: none !important;
    }
    
    .pie-chart-metric-row.mobile .pie-chart-metric-percentage {
      font-size: 1rem !important;
      font-weight: bold !important;
      color: var(--primary) !important;
      margin: 0 !important;
      padding: 0 !important;
      background: none !important;
      border: none !important;
      display: block !important;
      text-align: left !important;
    }
    
    .pie-chart-metric-row.mobile .pie-chart-metric-amount {
      font-size: 0.85rem !important;
      font-weight: 500 !important;
      color: #666 !important;
      margin: 0 !important;
      padding: 0 !important;
      background: none !important;
      border: none !important;
      display: block !important;
      text-align: right !important;
    }
  }
  
  /* Single column KPI layout for very small screens */
  .kpi-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }
  
  /* Smaller mobile navigation */
  .mobile-nav {
    padding: 6px 0;
  }
  
  .mobile-nav-item {
    padding: 20px;
    min-width: 70px;
    min-height: 55px;
  }
  
  .mobile-nav-item i {
    font-size: 18px;
  }
  
  .mobile-nav-item span {
    font-size: 11px;
  }
  
  /* Compact mobile ads */
  .mobile-ad-container {
    padding: 8px;
  }
  
  .ad-container.mobile-banner {
    min-height: 50px;
    padding: 10px;
  }
  
  /* Extra small screen fixes for checkboxes - left side */
  .modal .plan-option {
    padding: 12px 12px 12px 45px !important; /* Left padding for checkbox */
  }
  
  .modal .plan-checkbox {
    top: 12px !important;
    left: 12px !important; /* Left side positioning */
    transform: scale(1.2) !important;
    width: 16px !important;
    height: 16px !important;
  }
  
  .modal .plan-title {
    padding-left: 8px !important; /* Space from left checkbox */
    padding-right: 15px !important;
    font-size: 0.9rem !important;
  }
  
  #results-section::before {
    height: 60px;
    background-size: 200px 24px;
  }
  
  .left-panel {
    padding: 15px;
  }
  
  .right-panel {
    padding: 15px;
  }
  
  .header {
    padding: 20px 15px 25px 15px !important;
  }
  
  .header h1 {
    font-size: 1.6rem;
    margin-bottom: 8px;
  }
  
  .header p {
    font-size: 0.85rem;
    margin-top: 15px;
  }
  
  .support-button {
    margin-top: 10px;
    padding: 3px 5px;
    min-width: 45px;
  }
  
  .support-button i {
    font-size: 0.75rem;
  }
  
  .support-button span {
    font-size: 0.6rem;
  }
  
  .form-group label {
    font-size: 0.85rem;
  }
  
  .form-control {
    padding: 10px 12px;
    font-size: 14px;
  }
  
  .goal-item {
    padding: 15px;
  }
  
  .goal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .goal-title {
    font-size: 0.9rem;
  }
  
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  
  .kpi-card {
    padding: 15px;
  }
  
  .results-title {
    font-size: 1.1rem;
  }
  
  .btn {
    padding: 10px 16px;
    font-size: 13px;
  }
  
  .btn-sm {
    padding: 8px 12px;
    font-size: 12px;
  }
  
  .modal-content {
    padding: 20px;
    width: 95%;
  }
  
  .modal-title {
    font-size: 1.2rem;
  }
  
  .plan-option {
    padding: 15px;
  }
  
  .insight {
    font-size: 0.85rem;
    padding: 10px;
  }
  
  .scenario {
    padding: 12px;
  }
  
  .toast {
    top: 20px;
    right: 10px;
    left: 10px;
    bottom: auto;
    padding: 12px 15px;
    transform: translateY(-100px);
  }
  
  .toast.show {
    transform: translateY(0);
  }
}

/* Small mobile styles */
@media (max-width: 320px) {
  .header h1 {
    font-size: 1.4rem;
  }

  .header svg {
    margin: 0 auto !important;
    max-width: 480px !important; /* Increased from 400px for small mobile */
  }
  
  .section-title {
    font-size: 1.1rem;
  }
  
  .form-control {
    font-size: 13px;
  }
  
  .goal-input {
    font-size: 13px;
    min-width: 200px; /* Ensure enough width for placeholder text */
  }
  
  .kpi-value {
    font-size: 1rem;
  }
  
  .kpi-label {
    font-size: 0.75rem;
  }
}

/* Print styles */
@media print {
  .container {
    box-shadow: none;
    border-radius: 0;
    grid-template-columns: 1fr;
  }
  
  .no-print {
    display: none !important;
  }
  
  .right-panel {
    break-inside: avoid;
    border-left: none;
    border-top: 1px solid #000;
    background: white !important;
  }
  
  .left-panel {
    background: white !important;
  }
  
  .header {
    background: white !important;
    color: black !important;
    border: 1px solid #000;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #ccc;
  }
  
  .btn {
    display: none;
  }
  
  .tabs {
    display: none;
  }
  
  .modal {
    display: none !important;
  }
  
  .toast {
    display: none !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .card {
    border: 2px solid #000;
  }
  
  .btn {
    border: 2px solid #000;
  }
  
  .form-control {
    border: 2px solid #000;
  }
  
  .progress-bar {
    border: 1px solid #000;
  }
  
  .slider {
    border: 1px solid #000;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .card:hover {
    transform: none;
  }
  
  .btn:hover {
    transform: none;
  }
  
  .goal-item.active {
    transform: none;
  }
}

/* FINAL OVERRIDE: Force new mobile Goal Allocation layout */
@media screen and (max-width: 768px) {
  /* Kill all components.css overrides - EXCEPT icon font properties */
  .pie-chart-metric-row.mobile,
  .pie-chart-metric-row.mobile .pie-chart-metric-left,
  .pie-chart-metric-row.mobile .pie-chart-metric-right,
  .pie-chart-metric-row.mobile .pie-chart-metric-title,
  .pie-chart-metric-row.mobile .pie-chart-metric-percentage,
  .pie-chart-metric-row.mobile .pie-chart-metric-amount {
    all: unset !important;
  }
  
  /* DON'T reset icon font properties */
  .pie-chart-metric-row.mobile .pie-chart-metric-icon {
    /* Reset most properties but keep font essentials */
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    /* BUT preserve font properties for icons */
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important;
    font-style: normal !important;
    font-variant: normal !important;
    text-rendering: auto !important;
    line-height: 1 !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
  }
  
  /* Apply new structure */
  .pie-chart-metric-row.mobile {
    display: block !important;
    padding: 10px !important;
    margin-bottom: 8px !important;
    background: #f8f9fa !important;
    border-radius: 8px !important;
    border-left: 3px solid currentColor !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.06) !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-left {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    margin-bottom: 8px !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-icon {
    font-size: 1.2rem !important;
    margin-right: 8px !important;
    display: inline-block !important;
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important;
    line-height: 1 !important;
    width: auto !important;
    height: auto !important;
    text-rendering: auto !important;
    -webkit-font-smoothing: antialiased !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-title {
    font-size: 0.9rem !important;
    font-weight: 600 !important;
    color: #2c3e50 !important;
    display: inline-block !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-right {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    width: 100% !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-percentage {
    font-size: 1rem !important;
    font-weight: bold !important;
    color: var(--primary) !important;
  }
  
  .pie-chart-metric-row.mobile .pie-chart-metric-amount {
    font-size: 0.85rem !important;
    font-weight: 500 !important;
    color: #666 !important;
  }
  
  /* Force no scroll containers */
  .goal-chart-container,
  .pie-chart-wrapper,
  .pie-chart-metrics {
    max-height: none !important;
    overflow: visible !important;
    height: auto !important;
  }
}

/* Mobile-specific fixes for Work ↔ Life Balance button and modal */
@media (max-width: 768px) {
  /* Enhanced modal button interactions on mobile */
  .modal .plan-option {
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2) !important;
    min-height: 48px !important;
    cursor: pointer !important;
  }
  
  .modal .plan-option:active {
    background-color: rgba(102, 126, 234, 0.1) !important;
    transform: scale(0.98) !important;
    transition: all 0.1s ease !important;
  }
  
  #balance-modal {
    z-index: 1055 !important; /* Above mobile nav */
  }
  
  /* Force balance modal to display when shown */
  #balance-modal[style*="display: flex"] {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .modal-content {
    max-height: 85vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  /* Fix checkbox visibility in mobile modal - move to left side */
  .modal .plan-option {
    position: relative !important;
    padding: 15px 15px 15px 50px !important; /* Extra left padding for checkbox */
    margin-bottom: 10px !important;
    overflow: visible !important;
  }
  
  .modal .plan-checkbox {
    position: absolute !important;
    top: 15px !important;
    left: 15px !important; /* Move to left side */
    transform: scale(1.3) !important;
    z-index: 10 !important;
    width: 18px !important;
    height: 18px !important;
    cursor: pointer !important;
    background: white !important;
    border: 2px solid #ccc !important;
    border-radius: 3px !important;
  }
  
  .modal .plan-checkbox:checked {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
  }
  
  .modal .plan-title {
    padding-left: 10px !important; /* Space from left checkbox */
    padding-right: 15px !important;
    margin-left: 0 !important;
  }
  
  /* Hide investment badge on very small screens to make room */
  .modal .plan-option div[style*="INVESTMENT"] {
    display: none !important;
  }
}