/* IMPORT GLOBAL LAYOUT STYLES (Header/Footer) */
@import url('../layout.css');

/* --- GLOBAL RESET & BOX SIZING (CRITICAL FOR MOBILE) --- */
* {
    box-sizing: border-box; /* This prevents padding from expanding width beyond 100% */
}

/* --- Existing Calculator Styles --- */
:root {
    --bg-color: #f3f3f3;
    --panel-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #757575;
    --accent-color: #5a8acc;
    --border-color: #e0e0e0;
    --slider-track: #d9e2f3;
    --highlight-positive: #2e7d32;
    --highlight-negative: #c62828;
    --principal-color: #4CAF50;
    --interest-color: #F44336;
}

/* Ensure body uses flex to support sticky footer from layout */
body {
    font-family: 'Arial', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden; /* Prevent horizontal scroll on the entire page */
    width: 100%;
}

/* Add padding back to the main container wrapper */
.main-wrapper {
    padding: 2rem;
    flex: 1;
    width: 100%;
}

.main-container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Layout Grid: 
   Default is 1 column (Mobile). 
*/
.calculator-container {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    background-color: var(--panel-bg);
    box-shadow: 0 5px 25px rgba(0,0,0,0.1);
    border-radius: 8px;
    overflow: hidden; 
}

/* Desktop: Switch to 2 columns */
@media (min-width: 992px) {
    .calculator-container {
        grid-template-columns: 450px 1fr;
    }
}

/* --- Input Panel (Left) --- */
.input-panel {
    padding: 2.5rem 2rem;
    border-right: 1px solid var(--border-color);
    min-width: 0; /* Flexbox safety */
}

.panel-header h1 {
    font-family: 'Georgia', serif;
    font-size: 2rem;
    margin: 0 0 0.5rem 0;
    line-height: 1.2;
}

.panel-header p {
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 0 2.5rem 0;
}

.input-section {
    margin-bottom: 1.5rem;
    width: 100%;
}

.input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    gap: 10px;
    width: 100%;
}

.input-row label {
    font-weight: bold;
    font-size: 0.9rem;
    margin-right: 1rem;
    color: var(--text-secondary);
    white-space: nowrap; /* Default for desktop */
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: #f9f9f9;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0 0.5rem;
    /* Fixed width removed, rely on flex sizing */
    flex-shrink: 0;
}

.input-wrapper span {
    color: var(--text-secondary);
    font-size: 1rem;
    padding: 0 0.25rem;
}

.value-display {
    font-size: 1.1rem;
    font-weight: bold;
    border: none;
    background: transparent;
    text-align: right;
    width: 90px;
    padding: 0.5rem 0;
    /* -webkit-appearance: none;  */
    margin: 0;
}
.value-display:focus { outline: none; }

/* Custom Sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--slider-track);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    display: block;
    margin: 10px 0;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 20px; height: 20px;
    background: var(--accent-color);
    border-radius: 50%;
    border: 3px solid var(--panel-bg);
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}
input[type="range"]::-moz-range-thumb {
    width: 20px; height: 20px; background: var(--accent-color);
    border-radius: 50%; border: 3px solid var(--panel-bg);
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

/* Advanced Options */
.advanced-options summary {
    cursor: pointer; font-weight: bold; color: var(--accent-color);
    list-style: none; margin-top: 2rem;
}
.advanced-options summary::-webkit-details-marker { display: none; }
.advanced-options[open] summary { margin-bottom: 1.5rem; }
.advanced-grid {
    display: grid; 
    grid-template-columns: 1fr; 
    gap: 0;
    width: 100%;
}
.advanced-grid .input-section { margin-bottom: 1.5rem; }

/* --- Output Panel (Right) --- */
.output-panel {
    background-color: #eef2f9;
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    min-width: 0; 
}

.result-display { text-align: center; }
.result-display .result-label { font-size: 1.25rem; color: var(--text-secondary); }
.result-display .result-value {
    font-family: 'Georgia', serif; font-size: 4.5rem; font-weight: 700;
    margin: 0.5rem 0; color: var(--accent-color);
    line-height: 1.1;
    word-break: break-word; /* Ensure huge numbers don't break layout */
}
.result-display .result-value span{
    font-size: 1.5rem; font-family: 'Arial', sans-serif;
    font-weight: normal; color: var(--text-secondary); vertical-align: middle;
}
.result-display .result-comparison {
    font-size: 1.1rem; line-height: 1.6; max-width: 350px;
    margin: 0 auto 1.5rem auto;
}
.highlight-positive { color: var(--highlight-positive); font-weight: bold; }
.highlight-negative { color: var(--highlight-negative); font-weight: bold; }

.summary-details {
    margin-top: 2rem; padding-top: 2rem;
    border-top: 1px solid var(--border-color);
    display: grid; 
    grid-template-columns: 1fr 1fr;
    gap: 2rem; text-align: left;
}
.summary-section h3 {
    margin-top: 0; margin-bottom: 1rem; font-size: 0.9rem;
    text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-secondary); font-weight: 700;
}
.detail-row {
    display: flex; justify-content: space-between;
    margin-bottom: 0.75rem; font-size: 0.95rem;
}
.detail-row span:last-child { font-weight: bold; text-align: right; margin-left: 10px; }
.detail-row.total { font-weight: bold; font-size: 1.05rem; margin-top: 0.5rem; }
.detail-row.recommendation { font-size: 0.9rem; background-color: #e3e8f2; padding: 0.5rem; border-radius: 4px;}
.detail-row.secondary { color: var(--text-secondary); }

hr { border: none; height: 1px; background-color: var(--border-color); margin: 1rem 0; }

/* Tabs */
.ownership-tabs { margin-top: 2rem; width: 100%; }
.tab-headers { 
    border-bottom: 1px solid var(--border-color); 
    margin-bottom: 1rem; 
    display: flex; 
    overflow-x: auto; /* Allows tabs to scroll horizontally on mobile */
    white-space: nowrap;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    padding-bottom: 5px;
}
.tab-link {
    background: none; border: none; font-size: 1rem;
    padding: 0.5rem 1rem; cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    flex-shrink: 0; /* Prevents tabs from crushing */
}
.tab-link.active {
    border-bottom-color: var(--accent-color);
    font-weight: bold;
}
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.5s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.tab-content h4 { margin-top: 0; }

/* Amortization Section */
.amortization-container {
    background: var(--panel-bg);
    border-radius: 8px;
    margin-top: 2rem;
    border: 1px solid var(--border-color);
    padding: 1rem 2rem;
    overflow: hidden;
}
.amortization-container summary {
    cursor: pointer; list-style: none;
    display: flex; justify-content: space-between; align-items: center;
}
.amortization-container summary::-webkit-details-marker { display: none; }
.amortization-container h2 { margin: 0; font-family: 'Georgia', serif; font-size: 1.5rem; }
.arrow-down {
    width: 12px; height: 12px;
    border-left: 2px solid var(--text-secondary);
    border-bottom: 2px solid var(--text-secondary);
    transform: rotate(-45deg);
    transition: transform 0.3s;
}
.amortization-container[open] .arrow-down { transform: rotate(135deg); }

#amortization-chart {
    width: 100%;
    height: 300px;
    margin-top: 1rem;
}

#table-container {
    max-height: 500px;
    overflow-y: auto;
    overflow-x: auto; 
    display: block;
    margin-top: 1rem;
    border-top: 1px solid var(--border-color);
    width: 100%;
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 500px; }
th, td { padding: 0.75rem; text-align: left; border-bottom: 1px solid var(--border-color); }
thead th {
    background-color: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 10;
    font-weight: bold;
}
tr:last-child td { border-bottom: none; }
.principal { color: var(--principal-color); font-weight: bold; }
.service-cost { color: var(--interest-color); font-weight: bold; }


/* --- MOBILE RESPONSIVENESS (Max-width 768px) --- */
@media (max-width: 768px) {
    /* 1. Page & Layout Padding */
    .main-wrapper {
        padding: 10px; /* Reduced padding */
    }
    
    .input-panel, .output-panel {
        padding: 1.5rem 1rem;
    }
    
    .panel-header h1 {
        font-size: 1.6rem; /* Smaller title */
    }

    /* 2. Input Rows - Vertical Stacking */
    .input-row {
        flex-direction: column; /* Stack label on top of input */
        align-items: flex-start;
        gap: 5px;
    }
    
    .input-row label {
        width: 100%;
        margin-right: 0;
        margin-bottom: 2px;
        white-space: normal;
    }

    .input-wrapper {
        width: 100%; /* Full width input */
        justify-content: space-between;
    }

    .value-display {
        flex-grow: 1;
        width: auto;
    }

    /* 3. Output Panel Adjustments */
    .summary-details {
        grid-template-columns: 1fr; /* Stack detailed columns */
        gap: 1.5rem;
    }

    .result-display .result-value {
        font-size: 2.8rem; /* Smaller big number to fit screen */
    }
    
    .result-display .result-value span {
        display: block; /* Stack the units text below if needed */
        font-size: 1.2rem;
        margin-top: 5px;
    }
    
    .detail-row {
        flex-wrap: wrap; /* Prevent row text collision */
    }
    
    /* 4. Amortization adjustments */
    .amortization-container {
        padding: 1rem;
    }
    .amortization-container h2 {
        font-size: 1.2rem;
    }
}