:root {
    --primary: #2c3e50;
    --secondary: #ff6b6b;
    --accent: #3d5a80;
    --light-bg: #f8f9fa;
    --teal: #4ecdc4;
    --border-color: #e0e0e0;
    --text-color: #000000;
    --text-light: #666;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Times New Roman', Times, serif;
    font-size: 1rem;
    line-height: 1.6;
    color: #000;
    background-color: var(--light-bg);
}

/* Main container - centered */
.main-container {
    max-width: 1400px;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 0 10px;
}

/* Desktop layout (≥1025px) */
@media (min-width: 1025px) {
    .main-container {
        display: grid;
        grid-template-columns: 300px 1fr 300px;
        gap: 20px;
    }
    
    .sidebar-left,
    .sidebar-right {
        position: sticky;
        top: 20px;
        align-self: start;
    }
    
    /* ADDED: Desktop left ad bottom margin 0px */
    #ad-left.desktop {
        margin-bottom: 0px;
    }
}

/* Tablet layout (768px–1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .main-container {
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        gap: 5px !important; /* ADDED: Reduced from 30px to 5px */
    }
    
    .calculator-container {
        order: 1;
        margin-bottom: 0px;
    }
    
    .sidebar-left,
    .sidebar-right {
        display: none;
    }
    
    /* Move mobile-tablet-tools-container below calculator in tablet */
    .mobile-tablet-tools-container {
        order: 2;
        margin-top: 5px !important; /* CHANGED: Reduced from 20px to 5px */
    }
}

/* Mobile layout (≤767px) */
@media (max-width: 767px) {
    .main-container {
        gap: 5px !important; /* ADDED: Reduced from 30px to 5px */
    }
    
    .sidebar-left,
    .sidebar-right {
        display: none;
    }
    
    .calculator-container {
        margin-bottom: 0px;
    }
    
    .mobile-tablet-tools-container {
        margin-top: 5px !important; /* CHANGED: Reduced from 20px to 5px */
    }
}

/* Calculator container */
.calculator-container {
    background-color: white;
    border-radius: var(--radius);
    padding: 25px;
    box-shadow: var(--shadow);
    overflow: hidden; /* Prevent expansion when amortization table is shown */
}

/* Sidebar common styles - REDUCED GAP FROM 25px TO 10px */
.sidebar-left,
.sidebar-right {
    display: flex;
    flex-direction: column;
    gap: 10px; /* CHANGED: Reduced from 25px to 10px */
}

/* Hide desktop related tools on mobile/tablet */
@media (max-width: 1024px) {
    #related-tools {
        display: none;
    }
}

/* Show mobile/tablet related tools only on mobile/tablet */
@media (min-width: 1025px) {
    .mobile-tablet-tools-container {
        display: none;
    }
    
    /* Hide mobile/tablet related tools on desktop */
    #related-tools-mobile-tablet {
        display: none;
    }
}

/* Mobile/Tablet container for ads and tools - REDUCED GAP FROM 25px TO 10px */
.mobile-tablet-tools-container {
    display: flex;
    flex-direction: column;
    gap: 10px; /* CHANGED: Reduced from 25px to 10px */
    align-items: center; /* Center content in mobile/tablet */
}

/* Tablet layout adjustments - CENTERED TABLET AD */
@media (min-width: 768px) and (max-width: 1024px) {
    .mobile-tablet-tools-container {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px; /* CHANGED: Reduced from 20px to 10px */
        align-items: center;
        justify-items: center;
    }
    
    .mobile-tablet-tools-container .ad-container {
        width: 100%;
        max-width: 300px;
        justify-self: center;
        margin: 0 auto; /* Ensure centering */
    }
    
    .mobile-tablet-tools-container #related-tools-mobile-tablet {
        grid-column: span 1;
        width: 100%; /* Make related tools 100% width in tablet */
    }
}

/* Mobile layout adjustments */
@media (max-width: 767px) {
    .mobile-tablet-tools-container #related-tools-mobile-tablet {
        width: 100%; /* Make related tools 100% width in mobile */
    }
    
    .mobile-tablet-tools-container .ad-container {
        margin: 0 auto; /* Center mobile ads */
    }
}

/* Ad container styles - WHITE BACKGROUND WITH DIMENSIONS - REMOVED DASHED BORDER */
.ad-container {
    background-color: white !important;
    border: none; /* CHANGED: Removed dashed border */
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow); /* Added subtle shadow to replace border */
}

.ad-label {
    display: none; /* Hide advertisement label */
}

.ad-content {
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    width: 100%;
}

/* Ad dimension indicators */
.ad-dimension {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 0.7rem;
    color: #000;
    background: rgba(255, 255, 255, 0.8);
    padding: 2px 5px;
    border-radius: 3px;
}

/* Related tools - UPDATED STYLES - REDUCED MARGIN FROM 20px TO 10px */
#related-tools,
#related-tools-mobile-tablet {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
    width: 100%; /* Default to 100% width */
    margin-top: 10px; /* CHANGED: Reduced from 20px to 10px */
}

.tools-list {
    list-style: none;
}

.tools-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.tools-list li:last-child {
    border-bottom: none;
}

.tools-list a {
    color: #000;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tools-list a:hover {
    color: var(--teal);
}

/* Typography */
h1 {
    font-size: 1.5rem;
    color: #000;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--teal);
    text-align: center;
}

h2 {
    font-size: 1.375rem;
    color: #ff6b6b;
    margin: 25px 0 15px 0;
}

h3 {
    font-size: 1.25rem;
    color: #000;
    margin: 20px 0 12px 0;
}

h4 {
    font-size: 1.125rem;
    color: #000;
}

@media (min-width: 768px) and (max-width: 1024px) {
    h2 {
        font-size: 1.25rem;
    }
    
    h3 {
        font-size: 1.125rem;
    }
    
    h4 {
        font-size: 1rem;
    }
}

@media (max-width: 767px) {
    h1 {
        font-size: 1.25rem;
    }
    
    h2 {
        font-size: 1.125rem;
    }
    
    h3 {
        font-size: 1rem;
    }
    
    h4 {
        font-size: 0.9375rem;
    }
}

/* Form elements */
.form-section {
    background-color: white;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 25px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.form-group {
    margin-bottom: 18px;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.form-row .form-group {
    flex: 1;
    min-width: 200px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: bold;
    color: #000;
}

.input-with-icon {
    position: relative;
}

.input-with-icon i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #000;
    font-size: 1.125rem;
}

input, select, button {
    font-family: 'Times New Roman', Times, serif;
    font-size: 1rem;
}

input, select {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: white;
    color: #000;
}

.input-with-icon input {
    padding-left: 40px;
}

input:thefocus, select:thefocus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.2);
}

.input-hint {
    font-size: 0.875rem;
    color: #000;
    margin-top: 5px;
}

.required::after {
    content: " *";
    color: var(--secondary);
}

/* Toggle section */
.toggle-section {
    margin: 15px 0;
}

.toggle-header {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px 0;
    color: #000;
    font-size: 1.25rem;
}

.toggle-header i {
    margin-right: 10px;
    transition: transform 0.3s;
    font-size: 1.375rem;
}

.toggle-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.toggle-content.expanded {
    max-height: 2000px;
}

/* Payment flexibility */
.payment-flexibility {
    background-color: rgba(78, 205, 196, 0.1);
    border-left: 4px solid var(--teal);
    padding: 15px;
    margin: 15px 0;
    border-radius: 0 5px 5px 0;
}

/* Buttons - HORIZONTAL LAYOUT */
.btn-group {
    display: flex;
    flex-direction: row;
    gap: 15px;
    margin: 30px 0;
}

@media (max-width: 767px) {
    .btn-group {
        flex-direction: column;
    }
}

.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    min-height: 48px;
    flex: 1;
    font-size: 1rem;
    color: #000;
}

.btn-primary {
    background-color: var(--teal);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #3db8af;
}

.btn-secondary {
    background-color: var(--secondary);
    color: white;
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #e95c5c;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Spinner styles */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Results section */
.results-container {
    background-color: white;
    border-radius: var(--radius);
    padding: 25px;
    margin-top: 30px;
    box-shadow: var(--shadow);
    display: none;
    overflow: hidden; /* Prevent expansion when amortization table is shown */
}

/* Responsive results */
.results-highlight {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

@media (max-width: 480px) {
    .results-highlight {
        grid-template-columns: 1fr;
    }
}

.result-card {
    background-color: var(--light-bg);
    border-radius: var(--radius);
    padding: 15px;
    text-align: center;
    border-top: 4px solid var(--teal);
}

.result-value {
    font-size: 1.25rem;
    font-weight: bold;
    color: #000;
    margin: 10px 0;
}

.result-label {
    font-size: 0.85rem;
    color: #000;
}

/* Chart containers - responsive - MADE SMALLER */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

@media (max-width: 767px) {
    .charts-container {
        grid-template-columns: 1fr;
    }
}

.chart-wrapper {
    background-color: white;
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    height: 220px; /* Smaller height for pie charts */
    display: flex;
    flex-direction: column;
}

.chart-title {
    color: #000;
    margin-bottom: 8px;
    text-align: center;
    font-size: 1.25rem;
}

.chart-canvas {
    flex-grow: 1;
    width: 100%;
}

/* Amortization table - responsive with horizontal scrolling FOR DESKTOP AND TABLET TOO */
.amortization-container {
    overflow-x: auto;
    margin-top: 20px;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

/* Ensure horizontal scrolling works on all devices - DESKTOP AND TABLET TOO */
.amortization-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Force table to be wider than container to trigger scroll on desktop/tablet */
.amortization-container table {
    min-width: 1200px; /* Increased from 800px to ensure horizontal scrolling */
    width: 100%;
}

/* Mobile-specific */
@media (max-width: 767px) {
    .amortization-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .amortization-container table {
        min-width: 1200px; /* Increased from 800px */
    }
}

.amortization-container::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.amortization-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.amortization-container::-webkit-scrollbar-thumb {
    background: var(--teal);
    border-radius: 4px;
}

.amortization-container::-webkit-scrollbar-thumb:hover {
    background: #3db8af;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1200px; /* Increased from 800px */
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    color: #000;
}

th {
    background-color: var(--light-bg);
    color: #000;
    font-weight: bold;
    position: sticky;
    top: 0;
    font-size: 1rem;
}

td {
    font-size: 0.85rem;
}

tr:hover {
    background-color: rgba(78, 205, 196, 0.05);
}

/* Credit score selector */
.credit-score-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.credit-option {
    flex: 1;
    min-width: 120px;
}

.credit-option input[type="radio"] {
    display: none;
}

.credit-option label {
    display: block;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.9rem;
    color: #000;
}

.credit-option input[type="radio"]:checked + label {
    border-color: var(--teal);
    background-color: rgba(78, 205, 196, 0.1);
    font-weight: bold;
}

/* Validation messages */
.error-message {
    color: var(--secondary);
    font-size: 0.875rem;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.input-error {
    border-color: var(--secondary);
    background-color: rgba(255, 107, 107, 0.05);
}

.warning-message {
    background-color: rgba(255, 193, 7, 0.1);
    border-left: 4px solid #ffc107;
    padding: 15px;
    margin: 15px 0;
    border-radius: 0 5px 5px 0;
    display: none;
    font-size: 0.9rem;
    color: #000;
}

.info-message {
    background-color: rgba(78, 205, 196, 0.1);
    border-left: 4px solid var(--teal);
    padding: 15px;
    margin: 15px 0;
    border-radius: 0 5px 5px 0;
    font-size: 0.9rem;
    color: #000;
}

/* Export buttons - responsive */
.export-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 25px;
}

.export-btn {
    padding: 8px 16px;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s;
    font-size: 0.9rem;
    flex: 1;
    min-width: 140px;
    justify-content: center;
    color: #000;
}

@media (max-width: 767px) {
    .export-btn {
        min-width: 120px;
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}

.export-btn:hover {
    background-color: var(--light-bg);
    border-color: var(--teal);
}

/* Tabs for different views - responsive */
.results-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.results-tabs::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-weight: bold;
    color: #000;
    transition: all 0.3s;
    white-space: nowrap;
    font-size: 1rem;
}

@media (max-width: 767px) {
    .tab {
        padding: 8px 15px;
        font-size: 0.875rem;
    }
}

.tab.active {
    color: #000;
    border-bottom-color: var(--teal);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Responsive visibility rules */
#ad-left.desktop,
#ad-right.desktop {
    display: none;
}

#ad-tablet.tablet {
    display: none;
}

#ad-mobile.mobile {
    display: none;
}

@media (min-width: 1025px) {
    #ad-left.desktop,
    #ad-right.desktop {
        display: block;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    #ad-tablet.tablet {
        display: block;
    }
}

@media (max-width: 767px) {
    #ad-mobile.mobile {
        display: block;
    }
}

/* 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;
}

a:thefocus,
button:thefocus,
input:thefocus,
select:thefocus {
    outline: 3px solid var(--teal);
    outline-offset: 2px;
}

/* Percentage/Amount toggle */
.toggle-switch {
    display: flex;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    overflow: hidden;
    width: fit-content;
}

.toggle-option {
    padding: 8px 16px;
    cursor: pointer;
    background-color: var(--light-bg);
    transition: all 0.3s;
    font-size: 0.9rem;
    color: #000;
}

.toggle-option.active {
    background-color: var(--teal);
    color: white;
    font-weight: bold;
}

/* Fee groups */
.fee-group {
    background-color: rgba(248, 249, 250, 0.5);
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 15px;
}

/* Reverse calc results */
.reverse-calc-results {
    background-color: rgba(78, 205, 196, 0.1);
    border-radius: var(--radius);
    padding: 15px;
    margin-top: 20px;
}

/* Ratio display */
.ratio-display {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.ratio-bar {
    flex-grow: 1;
    height: 20px;
    background-color: var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    min-width: 150px;
}

.ratio-fill {
    height: 100%;
    background-color: var(--teal);
    border-radius: 10px;
}

.ratio-text {
    min-width: 100px;
    font-weight: bold;
    color: #000;
    font-size: 0.9rem;
}

/* Loan term toggle */
.loan-term-toggle {
    display: flex;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    overflow: hidden;
    width: fit-content;
}

.loan-term-option {
    padding: 8px 16px;
    cursor: pointer;
    background-color: var(--light-bg);
    transition: all 0.3s;
    font-size: 0.9rem;
    color: #000;
}

.loan-term-option.active {
    background-color: var(--teal);
    color: white;
    font-weight: bold;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    color: white;
    font-size: 1.5rem;
    flex-direction: column;
    gap: 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--teal);
    animation: spin 1s linear infinite;
}

/* Success message */
.success-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: #2ecc71;
    color: white;
    padding: 15px 25px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 9998;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Add breadcrumb styles */
.breadcrumb {
    padding: 0px 10px;
    color: #000;
    margin-bottom: 5px;
    font-size: 1rem;
}

.breadcrumb a {
    color: #000;
    text-decoration: none;
    transition: color 0.3s;
}

.breadcrumb a:hover {
    color: var(--secondary);
    text-decoration: underline;
}
    .mobile-table {
        overflow-x: auto;
        margin: 20px 0;
        border: 1px solid #eee;
        border-radius: 8px;
    }
    .mobile-table table {
        width: 100%;
        min-width: 600px;
        border-collapse: collapse;
    }
    .mobile-table th, .mobile-table td {
        padding: 12px 15px;
        text-align: left;
        border-bottom: 1px solid #eee;
    }
    .mobile-table th {
        background-color: #4ecdc4;
        font-weight: bold;
    }
    .mobile-table tr:nth-child(even) {
        background-color: #fafafa;
    }