:root {
    --ppo-color: #E8743B; 
    --hdhp-color: #50A750;
    --ppo-color-faded: rgba(232, 116, 59, 0.2);
    --hdhp-color-faded: rgba(80, 167, 80, 0.2);
    --bg-color: #f7f9fc;
    --card-bg: #ffffff;
    --text-color: #1a1a1a;
    --text-light: #555;
    --border-color: #e8e8e8;
    --input-bg: #f0f2f5; 
    --error-color: #d93025;
    --radius: 10px; 
}
*, *::before, *::after { box-sizing: border-box; }
html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth; /* For click-to-edit */
}
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    font-size: 14px;
}

#app-container {
    display: grid;
    grid-template-columns: 450px 1fr; 
    gap: 2rem;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
}
#controls-pane {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
#analysis-pane {
    position: sticky;
    top: 2rem;
    height: calc(100vh - 4rem); 
    overflow-y: auto;
    padding-right: 1rem; 
}

.results-hook { display: none; }

h1 { 
    margin: 0; 
    font-size: 1.75rem;
    color: #1a1a1a;
    font-weight: 700;
}
h2 { 
    font-size: 1.2rem; 
    color: var(--text-color); 
    margin: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
h3 {
    font-size: 1.1rem;
    color: var(--text-color); 
    margin-top: 1.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    font-weight: 600;
}
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-color); 
    padding: 1.5rem 1.75rem;
}

details {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-color); 
}
summary {
    list-style: none; 
    padding: 1.25rem 1.75rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
summary::after {
    content: '\F282'; 
    font-family: "bootstrap-icons";
    font-weight: 600;
    color: var(--text-light);
    transition: transform 0.2s ease;
}
details[open] summary::after {
    transform: rotate(180deg);
}
details .collapsible-content {
    padding: 0 1.75rem 1.5rem 1.75rem;
    border-top: 1px solid var(--border-color);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem; 
    margin-bottom: 0.65rem;
    position: relative;
}
.plan-grid-input .input-group {
    margin-bottom: 0; 
    gap: 0.5rem;
}

label, .label {
    font-weight: 500;
    font-size: 12px; 
    color: var(--text-light); 
    display: flex;
    align-items: center;
    gap: 5px;
}
.plan-grid-input > label {
    font-size: 13px;
    color: var(--text-color);
    font-weight: 500;
    padding-top: 0.5rem; /* Align with inputs */
}

.info-tip {
    color: #888;
    cursor: help;
    position: relative;
}
/* ACCESSIBILITY: Added :focus rule */
.info-tip .tooltip-text {
    visibility: hidden; width: 280px; background-color: #333; color: #fff; text-align: left;
    border-radius: 6px; padding: 8px 12px; position: absolute; z-index: 10;
    bottom: 135%; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity 0.3s;
    font-size: 12px; font-weight: 400; line-height: 1.4;
}
.info-tip:hover .tooltip-text,
.info-tip:focus .tooltip-text { 
    visibility: visible; 
    opacity: 1; 
}

/* MODIFIED: Added 'output' selector */
input[type="number"], 
select,
output {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    padding: 0.55rem 0.7rem;
    border-radius: 6px; 
    box-sizing: border-box;
    width: 100%;
    -moz-appearance: textfield;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid var(--input-bg); 
    background: var(--input-bg);
    color: var(--text-color);
}

/* Style output elements to look like readonly inputs */
output {
    display: inline-block; /* Needed for padding */
    color: var(--text-color);
    font-weight: 500;
    min-height: 38px; /* Match input height */
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* MODIFIED: Added 'output:focus-within' */
input:focus, 
select:focus,
output:focus-within {
    outline: none;
    background: var(--card-bg); 
    border-color: #6a99c5; 
    box-shadow: 0 0 0 2px rgba(58, 80, 107, 0.2); 
}
.input-error,
.input-error:focus {
    border-color: var(--error-color) !important;
    box-shadow: 0 0 0 2px rgba(217, 48, 37, 0.2) !important;
}
.error-message {
    font-size: 12px;
    color: var(--error-color);
    font-weight: 500;
    margin-top: -0.25rem;
    margin-bottom: 0.5rem;
}
.checkbox-group { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-group label { font-weight: 400; font-size: 13px; color: var(--text-color); } 

button {
    font-family: 'Inter', sans-serif;
    background-color: #2c3e50; 
    color: white; border: none; padding: 0.5rem 0.85rem;
    border-radius: 5px; cursor: pointer; font-size: 13px; font-weight: 600;
    transition: background-color 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
button:hover { background-color: #1a2530; }
.secondary-button { background-color: #6c757d; }
.secondary-button:hover { background-color: #5a6268; }

.hidden { display: none !important; }

.input-with-adornment { position: relative; }
.input-with-adornment::before {
    content: attr(data-symbol);
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    z-index: 2;
}
.input-with-adornment input { padding-left: 26px; }
.input-with-adornment output { padding-left: 26px; } /* Added for output */
.input-with-adornment.suffix::before { left: auto; right: 10px; }
.input-with-adornment.suffix input { padding-left: 0.75rem; padding-right: 28px; }
.input-with-adornment.suffix output { padding-left: 0.75rem; padding-right: 28px; } /* Added for output */

/* MODIFIED: Alignment (Item 1) & Input Size (Item 2) */
.plan-grid-input {
    display: grid;
    /* Changed to minmax(100px, 1fr) for better responsiveness */
    grid-template-columns: auto minmax(100px, 1fr) minmax(100px, 1fr);
    gap: 0.65rem 1rem;
    align-items: center;
}
/* NEW: Header styles (Item 1) */
.plan-grid-input > strong {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.plan-grid-input > .ppo-header {
    grid-column: 2; /* Align to column 2 */
    color: var(--ppo-color);
}
.plan-grid-input > .hdhp-header {
    grid-column: 3; /* Align to column 3 */
    color: var(--hdhp-color);
}
/* REMOVED: .plan-grid-header styles are no longer needed */

.hsa-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: flex-end;
    gap: 0.65rem 1rem;
}
.hsa-grid .input-group { margin-bottom: 0; }
.hsa-grid .btn-hsa-max { padding: 0.55rem 0.8rem; font-size: 13px; }

#verdict-wrapper {
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}
#verdict-box {
    padding: 1.25rem;
    text-align: center;
}
#verdict-title {
    font-size: 1.15rem; 
    font-weight: 600;
    margin: 0 0 0.25rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
#verdict-title .bi-trophy-fill {
    font-size: 1.25rem;
}
#verdict-savings-amount {
    font-size: 1.75rem; 
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}
#verdict-savings-label {
    font-size: 12px;
    color: var(--text-light);
    margin: 0 0 0.75rem 0;
}

#verdict-net-costs {
    display: flex;
    justify-content: space-around;
    border-top: 1px solid var(--border-color);
    background: var(--bg-color);
    padding: 0.75rem;
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}
#verdict-net-costs > div {
    text-align: center;
}
#verdict-net-costs p {
    margin: 0;
    font-size: 12px;
    color: var(--text-light);
    font-weight: 500;
}
#verdict-net-costs strong {
    font-size: 1.25rem; 
    font-weight: 600;
    line-height: 1.3;
}
#verdict-net-costs .ppo-value { color: var(--ppo-color); }
#verdict-net-costs .hdhp-value { color: var(--hdhp-color); }

#breakeven-point {
    font-weight: 500; margin-top: 0.5rem; font-size: 14px; text-align: center;
    margin-bottom: 1.5rem;
}

.analysis-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-top: 1.5rem;
}
#card-breakdown {
    border: 1px solid var(--border-color); 
    padding: 1rem 1.25rem;
}
#card-breakdown .collapsible-header h3 {
    margin: 0; border: none; font-size: 1.1rem;
}
#card-breakdown .collapsible-content {
    padding-top: 0;
    border-top: none;
    margin-top: 1rem;
}

/* MODIFIED: Sized for Chart.js (Item 4) */
#graph-container { 
    width: 100%; 
    height: 350px; /* Increased height for stacked chart */
    position: relative; 
    margin-top: 1rem; 
}
canvas { 
    border: 1px solid var(--border-color); 
    border-radius: 6px; 
    background: white;
}
/* REMOVED: .legend styles (Chart.js provides its own) */

#analysis-table { width: 100%; border-collapse: collapse; }
#analysis-table th, #analysis-table td { padding: 0.6rem 0.75rem; text-align: right; border-bottom: 1px solid var(--border-color); font-size: 14px; }
#analysis-table th:first-child, #analysis-table td:first-child { text-align: left; font-weight: 500;}
#analysis-table th { background-color: var(--bg-color); font-size: 12px; text-align: center; font-weight: 600; text-transform: uppercase; color: var(--text-light); }
#analysis-table th:first-child { text-align: left; }
#analysis-table td { font-family: 'Inter', sans-serif; }
#analysis-table td:nth-child(2) { color: var(--ppo-color); font-weight: 600; }
#analysis-table td:nth-child(3) { color: var(--hdhp-color); font-weight: 600; }
#analysis-table tr:last-child td { border-bottom: none; }
#analysis-table .total-row td { font-weight: 600; border-top: 2px solid #333; }
#analysis-table .net-row td { font-weight: 700; font-size: 15px; background-color: #eef2f7; }
#analysis-table .sub-row td { font-size: 13px; color: var(--text-light); padding-top: 0.25rem; padding-bottom: 0.25rem; border: none; }
#analysis-table .sub-row td:first-child { padding-left: 2rem; }
#analysis-table .sub-row td:nth-child(2) { font-weight: 500; }
#analysis-table .sub-row td:nth-child(3) { font-weight: 500; }
#analysis-table .ppo-oop-label { font-weight: 500; }
#analysis-table .hdhp-oop-label { font-weight: 500; }

#hsa-investment-section {
    margin-top: 1.5rem;
}
#hsa-investment-section h3 { color: var(--hdhp-color); margin-top: 0; font-size: 1.1rem; }
#hsa-investment-section p { font-size: 13px; line-height: 1.5; margin: 0.5rem 0; }
#hsa-investment-section p:last-child { margin-top: 0.75rem; }

.assumptions-container { margin-top: 2rem; }
.assumptions-container .card {
    padding: 1.25rem 1.75rem;
    max-width: 900px;
    margin: 0 auto;
}
.assumptions-container ul {
    font-size: 13px; 
    color: var(--text-light); 
    padding-left: 1.25rem; 
    margin: 0; 
    line-height: 1.6;
}
.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
.collapsible-header::after {
    content: '\25B2'; font-size: 1rem; transition: transform 0.2s ease;
    color: var(--text-light);
}
.collapsed .collapsible-header::after { transform: rotate(180deg); }
.collapsible-content {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
}
.collapsed .collapsible-content { display: none; }

/* --- Slider Styles --- */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.slider-group .slider-labels {
     display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-light);
    padding: 0 5px;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    background: #ddd;
    border-radius: 5px;
    outline: none;
    opacity: 0.7;
    transition: opacity .2s;
    padding: 0; 
}
input[type="range"]:hover { opacity: 1; }
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #2c3e50; 
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #2c3e50; 
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
/* For tax slider datalist */
.tax-slider-group {
    position: relative;
}
.tax-slider-group datalist {
    position: absolute;
    top: 8px; /* Position under the track */
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-light);
}
.tax-slider-group datalist option {
    padding: 0;
}


/* --- Responsive Styles --- */
@media (max-width: 900px) {
    #app-container {
        grid-template-columns: 1fr; 
        padding: 1rem;
        gap: 1.5rem;
    }
    #analysis-pane {
        position: static; 
        height: auto;
        overflow-y: visible;
        padding-right: 0;
    }
    h1 { font-size: 1.5rem; }
    .card, summary, details .collapsible-content {
        padding: 1.25rem;
    }
    
    #verdict-wrapper {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--bg-color);
        padding-top: 1rem;
        margin: -1rem -1rem 1rem -1rem; 
        padding-left: 1rem;
        padding-right: 1rem;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid var(--border-color);
    }
    #verdict-box {
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        background: var(--card-bg);
    }
    
    /* MODIFIED: Item 2 (Input Size) - more gap for mobile */
    .plan-grid-input {
        gap: 0.5rem 0.75rem;
    }
    .plan-grid-input > label {
        font-size: 12px; 
    }
    .plan-grid-input > strong {
        font-size: 13px;
    }

    .hsa-grid { grid-template-columns: 1fr; }
    .hsa-grid .btn-hsa-max { grid-row: 3; }

    /* Mobile Table */
    #analysis-table { border: 0; }
    #analysis-table thead {
        border: none; clip: rect(0 0 0 0); height: 1px;
        margin: -1px; overflow: hidden; padding: 0;
        position: absolute; width: 1px;
    }
    #analysis-table tr {
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        display: block;
        margin-bottom: 1rem;
        background: var(--card-bg);
    }
    #analysis-table td {
        border-bottom: 1px solid #eee;
        display: block;
        font-size: 14px;
        text-align: right;
        padding: 0.6rem 1rem;
    }
    #analysis-table td::before {
        content: attr(data-label);
        float: left;
        font-weight: 500;
        color: var(--text-color);
    }
    #analysis-table td:first-child {
        font-weight: 600;
        font-size: 1rem;
        background-color: var(--bg-color);
        border-bottom: 1px solid var(--border-color);
        padding: 0.8rem 1rem;
    }
    #analysis-table td:first-child::before { content: ""; }
    #analysis-table tr:last-child td:last-child { border-bottom: 0; }
    #analysis-table td[data-label="PPO Plan"] { color: var(--ppo-color); font-weight: 600; }
    #analysis-table td[data-label="HDHP Plan"] { color: var(--hdhp-color); font-weight: 600; }
    
    #analysis-table .total-row td,
    #analysis-table .net-row td { font-weight: 600; font-size: 14px; }
    #analysis-table .total-row td:first-child,
    #analysis-table .net-row td:first-child { font-weight: 700; font-size: 1rem; }
    
    #analysis-table .sub-row td { padding-left: 1rem; }
    #analysis-table .sub-row td::before { padding-left: 1rem; font-size: 13px; }
}