: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);
    --transition: all 0.3s ease;
    --border-radius: 8px;
}

/* Base Styles */
* {
    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);
    transition: var(--transition);
    
}

h1 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: #000;
    text-align: center;
}

h2 {
    font-size: 1.375rem;
    margin-bottom: 1.25rem;
    color: #ff6b6b;
}

h3 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: #000;
}

h4 {
    font-size: 1.125rem;
    color: #000;
}

.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

/* Main Content Layout - FIXED: Added missing semicolon */
.content {
    display: grid;
    gap: 1rem;
    padding: 0 0.5rem;
}

/* Sidebars */
.sidebar {
    display: none;
}

.ad-box {
    background: linear-gradient(135deg, #f5f7fa, #e4e7eb);
    border: 1px dashed var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
    font-weight: 500;
    text-align: center;
    padding: 1rem;
    margin-bottom: 1.5rem;
    position: relative;
}

.ad-label {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    color: #000;
}

/* Related Tools */
.related-tools {
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    max-width: 100%;
}

.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: var(--accent);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tools-list a:hover {
    color: var(--teal);
}

/* Calculator Styles */
.calculator {
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    width: 100%;
    overflow: hidden;
}

.calculator-grid {
    display: grid;
    gap: 1.5rem;
    width: 100%;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.input-row .input-group {
    flex: 1;
    min-width: 200px;
}

label {
    font-weight: 500;
    color: #000;
}

input, select {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: 'Times New Roman', Times, serif;
    font-size: 1rem;
    transition: var(--transition);
    width: 100%;
    color: #000;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(61, 90, 128, 0.2);
}

.switch-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--teal);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* Results Container */
.results-container {
    display: none;
    margin-top: 2rem;
    width: 100%;
}

.results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.result-card {
    background: linear-gradient(135deg, #f0f9ff, #e6f7ff);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow);
}

.result-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #000;
    margin: 0.5rem 0;
}

.result-label {
    color: #000;
    font-size: 0.9rem;
}

.chart-container {
    grid-column: 1 / -1;
    height: 300px;
    background: white;
    border-radius: var(--border-radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    margin-top: 1rem;
    width: 100%;
    overflow: hidden;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-family: 'Times New Roman', Times, serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:hover {
    background-color: var(--primary);
    transform: translateY(-2px);
}

.btn-secondary {
    background-color: var(--teal);
}

.btn-reset {
    background-color: var(--secondary);
}

.btn-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

/* Amortization Table */
.amortization-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.amortization-table th {
    background-color: var(--primary);
    color: white;
    padding: 0.75rem;
    text-align: left;
    font-size: 1rem;
}

.amortization-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    color: #000;
}

.amortization-table tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.03);
}

.amortization-table tr:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Advanced Sections */
.advanced-section {
    display: none;
    margin-top: 1.5rem;
    padding: 1.5rem;
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 100%;
    overflow: hidden;
}

/* Export Buttons */
.export-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.export-btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    font-family: 'Times New Roman', Times, serif;
    font-size: 0.9rem;
    font-weight: 500;
    flex: 1;
    min-width: 120px;
    justify-content: center;
    text-align: center;
}

.export-btn:hover {
    background-color: var(--primary);
    transform: translateY(-2px);
}

/* Amortization Toggle */
.amortization-toggle {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.amortization-toggle button {
    padding: 0.5rem 1rem;
    background-color: #e0e0e0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Times New Roman', Times, serif;
    font-size: 1rem;
    color: #000;
}

.amortization-toggle button.active {
    background-color: var(--accent);
    color: white;
}

/* Monthly Schedule */
.monthly-schedule {
    display: none;
    max-height: 400px;
    overflow-y: auto;
    margin-top: 1rem;
}

.monthly-schedule table {
    width: 100%;
}

/* Below calculator ad */
.below-calculator-ad {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    width: 100%;
}

/* Extra Payments Section */
.extra-payments-section {
    display: none;
    background: #f9f9f9;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-top: 1rem;
    border-left: 4px solid var(--teal);
}

.extra-payments-section h4 {
    margin-bottom: 0.75rem;
    color: #000;
    font-size: 1.125rem;
}

/* Summary Section */
.summary-section {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-top: 1.5rem;
    width: 100%;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.summary-card {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.summary-card h4 {
    margin-bottom: 0.5rem;
    color: #000;
    font-size: 1.125rem;
}

.summary-card ul {
    list-style: none;
    padding-left: 0;
}

.summary-card li {
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
}

.summary-card .label {
    font-weight: 500;
    color: #000;
}

.summary-card .value {
    font-weight: 600;
    color: #000;
}

/* Loading indicator for PDF generation - FIXED: Removed duplicate display property */
.pdf-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
    font-size: 1.5rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 5px solid #fff;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Breadcrumb styles */
.breadcrumb {
    padding: 0px 10px;
    color: #000;
    margin-bottom: 5px;
    font-size: 1rem;
    max-width: 100%;
    overflow: hidden;
}

.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;
    }

.calculating-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

/* Responsive table container for amortization */
.amortization-container {
    overflow-x: auto;
    max-width: 100%;
    margin-top: 1rem;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--border-radius);
}

/* Ensure tables fit within their containers */
.amortization-table {
    min-width: 600px;
    width: 100%;
}

/* Related tools for mobile and tablet */
#related-tools-mobile,
#related-tools-tablet {
    display: none;
}

/* Responsive Design */
@media (min-width: 768px) {
    h1 {
        font-size: 1.5rem;
    }
    
    h2 {
        font-size: 1.25rem;
    }
    
    h3 {
        font-size: 1.125rem;
    }

    h4 {
        font-size: 1rem;
    }

    .amortization-toggle button {
        font-size: 1rem;
    }

    #ad-tablet {
        display: flex;
        margin-top: 10px;
    }
    
    .below-calculator-ad,
    #ad-mobile {
        display: none;
    }
    
    #related-tools-tablet {
        display: block;
        max-width: 100%;
    }
}

/* Center tablet elements */
@media (min-width: 768px) and (max-width: 1024px) {
    h2 {
        font-size: 1.25rem;
    }
    
    h3 {
        font-size: 1.125rem;
    }
    
    h4 {
        font-size: 1rem;
    }
    
    #ad-tablet,
    #related-tools-tablet {
        margin-left: auto;
        margin-right: auto;
        display: flex;
        flex-direction: column;
        align-items: left;
        max-width: 100%;
    }
    
    #related-tools-tablet {
        width: 100%;
        max-width: 700px;
    }
    
    #ad-tablet {
        width: 300px;
    }
    
    /* Fix calculator expansion */
    .calculator {
        max-width: 100%;
        overflow-x: hidden;
    }
}

/* DESKTOP STICKY POSITIONING */
@media (min-width: 1025px) {
    h1 {
        font-size: 1.5rem;
    }
    
    h2 {
        font-size: 1.375rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
    
    h4 {
        font-size: 1.125rem;
    }
    
    .content {
        grid-template-columns: 300px 1fr 300px;
    }
    
    .sidebar {
        display: block;
        position: sticky;
        top: 20px;
        height: fit-content;
        overflow-y: auto;
        z-index: 5;
    }
    
    #ad-tablet {
        display: none;
    }
    
    /* Hide tablet related tools on desktop */
    #related-tools-tablet {
        display: none;
    }

    /* Custom scrollbar for sticky sidebar */
    .sidebar::-webkit-scrollbar {
        width: 6px;
    }
    .sidebar::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }
    .sidebar::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 3px;
    }
    .sidebar::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
}

/* MOBILE STYLES */
@media (max-width: 767px) {
    h1 {
        font-size: 1.25rem;
    }
    
    h2 {
        font-size: 1.125rem;
    }
    
    h3 {
        font-size: 1rem;
    }
    
    h4 {
        font-size: 0.9375rem;
    }
    
    body {
        overflow-x: hidden;
    }
    
    .below-calculator-ad {
        display: flex;
    }
    
    #ad-tablet {
        display: none;
    }
    
    #related-tools-mobile {
        display: block;
        max-width: 100%;
    }
    
    .input-row {
        flex-direction: column;
        gap: 1rem;
    }
    
    .input-row .input-group {
        min-width: 100%;
    }
    
    .export-buttons {
        flex-direction: column;
    }
    
    /* FIXED: Mobile results layout - removed !important */
    .results {
        grid-template-columns: 1fr;
    }
    
    .result-card {
        margin-bottom: 1rem;
        width: 100%;
    }
    
    .summary-grid {
        grid-template-columns: 1fr;
    }
    
    .chart-container {
        height: 250px;
        padding: 0.5rem;
    }
    
    /* Fix amortization toggle buttons to fit better */
    .amortization-toggle {
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .amortization-toggle button {
        padding: 0.4rem 0.8rem;
        font-size: 0.875rem;
        flex: 1;
        min-width: 0;
        white-space: nowrap;
    }
    
    /* FIXED: Better mobile table approach without !important */
    .amortization-table {
        min-width: auto;
        width: 100%;
        display: table;
        font-size: 0.8rem;
        table-layout: fixed;
    }
    
    .amortization-table th,
    .amortization-table td {
        padding: 6px 4px;
        font-size: 0.75rem;
        word-wrap: break-word;
        min-width: 0;
    }
    
    /* Make specific columns more responsive */
    .amortization-table th:nth-child(1),
    .amortization-table td:nth-child(1) {
        width: 15%;
    }
    
    .amortization-table th:nth-child(2),
    .amortization-table td:nth-child(2) {
        width: 25%;
    }
    
    .amortization-table th:nth-child(3),
    .amortization-table td:nth-child(3) {
        width: 20%;
    }
    
    .amortization-table th:nth-child(4),
    .amortization-table td:nth-child(4) {
        width: 20%;
    }
    
    .amortization-table th:nth-child(5),
    .amortization-table td:nth-child(5) {
        width: 20%;
    }
    
    /* Fix the container to prevent overflow */
    .amortization-container {
        overflow-x: visible;
        margin: 0;
        padding: 0;
        width: 100%;
        position: static;
        left: auto;
        transform: none;
        max-width: 100%;
    }
    
    /* Ensure the schedule section fits properly */
    .monthly-schedule {
        max-height: 300px;
        overflow-y: auto;
        overflow-x: visible;
        margin-top: 1rem;
        width: 100%;
    }
    
    /* Fix advanced section mobile display */
    .advanced-section {
        padding: 1rem 0.5rem;
        margin-top: 1rem;
        overflow: hidden;
        max-width: 100%;
    }
    
    /* Ensure amortization section title fits */
    .advanced-section h3 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }
    
    /* Fix calculator expansion */
    .calculator {
        padding: 1rem;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    .results-container {
        padding: 0.5rem;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Fix chart overflow */
    .chart-container canvas {
        max-width: 100%;
    }
    
    /* Fix summary card text overflow */
    .summary-card {
        min-width: 0;
        overflow: hidden;
    }
    
    .summary-card .label,
    .summary-card .value {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Fix related tools */
    .related-tools {
        max-width: 100%;
    }
    
    /* Fix export buttons */
    .export-btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    /* Mobile optimization */
    .calculator {
        overflow: hidden;
        padding: 1rem;
        max-width: 100vw;
    }

    .amortization-schedule {
        padding: 1rem 0.5rem;
    }

    .results-container {
        padding: 0.5rem;
        max-width: 100vw;
    }
}