:root {
    --primary-color: #005a9c;
    --primary-color-light: #006acb;
    --text-color: #333;
    --text-color-light: #555;
    --bg-color: #f4f7f9;
    --bg-color-light: #fff;
    --border-color: #e0e0e0;
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
    --success-color: #27ae60;
    --danger-color: #c0392b;
    --neutral-bg: #f8f9fa;
}

/* --- General & Layout --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    line-height: 1.6;
}

.container {
    background-color: var(--bg-color-light);
    padding: 20px 40px;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 8px 24px rgba(0, 30, 80, 0.08);
    width: 100%;
    max-width: 1200px;
}

header {
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
    margin-bottom: 30px;
}

header h1 {
    color: var(--primary-color);
    margin-bottom: 4px;
}

header p {
    color: var(--text-color-light);
    font-size: 1.1em;
}

.main-content {
    display: flex;
    gap: 40px;
    flex-wrap: wrap;
}

.input-column {
    flex: 1;
    min-width: 300px;
}

.output-column {
    flex: 2;
    min-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* --- Input Controls --- */
.input-group {
    margin-bottom: 20px;
}

label {
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
    color: var(--text-color);
}

input[type="number"], input[type="text"], .slider, select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: var(--border-radius-md);
    box-sizing: border-box;
    font-size: 1em;
    background-color: var(--bg-color-light);
}

input[type="number"]:focus, input[type="text"]:focus, select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 90, 156, 0.2);
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

#calculate-btn, .secondary-btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-size: 1.1em;
    font-weight: 700;
    transition: all 0.2s ease-in-out;
}

#calculate-btn {
    background: linear-gradient(145deg, var(--primary-color-light), var(--primary-color));
    color: var(--bg-color-light);
}

#calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 90, 156, 0.3);
}

.secondary-btn {
    background-color: #e9ecef;
    color: #495057;
    border: 1px solid #ced4da;
}

.secondary-btn:hover {
    background-color: #dee2e6;
}


.input-with-buttons {
    display: flex;
}

.input-with-buttons input {
    text-align: center;
    border-left: none;
    border-right: none;
    border-radius: 0;
}

.adjust-btn {
    width: 40px;
    padding: 10px;
    border: 1px solid #ccc;
    background-color: #f8f9fa;
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
}

.adjust-btn:hover {
    background-color: #e9ecef;
}

#income-decrement {
    border-top-left-radius: var(--border-radius-md);
    border-bottom-left-radius: var(--border-radius-md);
}

#income-increment {
    border-top-right-radius: var(--border-radius-md);
    border-bottom-right-radius: var(--border-radius-md);
}

#salary-decrement, #balance-decrement {
    border-top-left-radius: var(--border-radius-md);
    border-bottom-left-radius: var(--border-radius-md);
}

#salary-increment, #balance-increment, #btl-property-value-increment {
    border-top-right-radius: var(--border-radius-md);
    border-bottom-right-radius: var(--border-radius-md);
}

#btl-property-value-decrement {
    border-top-left-radius: var(--border-radius-md);
    border-bottom-left-radius: var(--border-radius-md);
}

/* --- Sliders & Toggles --- */
.slider {
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: #ddd;
    outline: none;
    border-radius: var(--border-radius-sm);
    padding: 0;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
}
.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
}

.toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
}
.toggle {
    margin-right: 10px;
    width: 18px;
    height: 18px;
}

/* --- Output & Summary Cards --- */
.summary-card {
    background-color: var(--neutral-bg);
    padding: 25px;
    border-radius: var(--border-radius-md);
    border: 1px solid #e9ecef;
}

.summary-card h2 {
    margin-top: 0;
    color: var(--primary-color);
    font-size: 1.2em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.summary-card ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.summary-card li {
    margin-bottom: 12px;
    font-size: 1.05em;
    display: flex;
    justify-content: space-between;
}

.disclaimer {
    font-size: 0.8em;
    color: #666;
    margin-top: 20px;
    text-align: center;
}

#optimizer-summary ul {
    list-style-type: '💡';
    padding-left: 20px;
}
#optimizer-summary li {
    padding-left: 10px;
    display: list-item;
    justify-content: flex-start;
    margin-bottom: 15px;
}

#paycheck-impact ul {
    list-style-type: '✓';
    padding-left: 20px;
}
#paycheck-impact li {
    padding-left: 10px;
    display: list-item;
    justify-content: flex-start;
}

#btl-costs-summary li span {
    color: var(--text-color-light);
}

#btl-purchase-details {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

#btl-purchase-details h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: var(--text-color);
}

#btl-purchase-details p {
    margin: 5px 0;
}

/* --- Assumptions & Explanation Panels --- */
.assumptions-panel, .explanation-panel {
    margin-top: 30px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
}
.assumptions-header, .explanation-header {
    padding: 10px 15px;
    background-color: var(--neutral-bg);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.assumptions-header h3, .explanation-header h4 {
    margin: 0;
    font-size: 1.1em;
    color: var(--primary-color);
}
.toggle-icon {
    font-size: 1.2em;
    transition: transform 0.3s ease;
}
.assumptions-content, .explanation-content {
    padding: 15px;
    border-top: 1px solid var(--border-color);
}
.assumptions-content.hidden, .explanation-content.hidden {
    display: none;
}
.assumptions-content h4 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--text-color);
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}
.assumptions-content ul, .explanation-content ul {
    padding-left: 0;
    list-style: none;
    margin-bottom: 15px;
}
.assumptions-content li, .explanation-content li {
    font-size: 0.95em;
    margin-bottom: 8px;
}
.assumptions-content li span, .explanation-content li span {
    color: var(--text-color-light);
}
.explanation-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}
.explanation-content th, .explanation-content td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    text-align: left;
}
.explanation-content td:nth-child(2), .explanation-content td:nth-child(3) {
    text-align: right;
    font-feature-settings: "tnum"; /* Tabular nums for alignment */
}
.explanation-content th {
    font-weight: 600;
    color: var(--text-color);
}
.explanation-content tr.total td {
    font-weight: bold;
    border-top: 2px solid #ddd;
    border-bottom: none;
}


/* --- Chart --- */
#summary-chart-container {
    position: relative;
    height: 300px; /* Give the container a defined height */
}
.chart-container {
    position: relative;
    height: 40vh;
    min-height: 350px;
}

/* --- Utility --- */
.hidden {
    display: none;
}

#results-title, #results-hr {
    display: none;
}

.btl-accordion-item.hidden {
    display: none;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .main-content {
        flex-direction: column;
    }
    .container {
        padding: 20px;
    }
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
        gap: 20px;
    }

    #results-title, #results-hr {
        display: block;
    }

    #results-title {
        margin-bottom: 0;
        color: var(--primary-color);
    }

    #results-hr {
        margin: 15px 0;
        border: none;
        border-top: 1px solid var(--border-color);
    }

    .input-column {
        min-width: 100%;
    }
    
    .output-column {
        min-width: 100%;
        padding-top: 20px;
        border-top: 2px solid var(--border-color);
    }

    .power-grid {
        grid-template-columns: 1fr;
    }

    .tabs {
        border-bottom: none;
        flex-wrap: wrap;
        gap: 8px;
        scroll-margin-top: 20px;
    }

    .tab-link {
        flex-grow: 1;
        text-align: center;
        border-radius: 20px;
        border: 1px solid var(--border-color);
        background-color: var(--neutral-bg);
        margin-bottom: 0;
        border-bottom: 1px solid var(--border-color);
    }

    .tabs .tab-link.active {
        background-color: var(--primary-color);
        color: var(--bg-color-light) !important;
        border-color: var(--primary-color);
        border-bottom-color: var(--primary-color);
    }
}

@media (max-width: 480px) {
    body {
        padding: 5px;
    }
    .container {
        padding: 10px;
    }
    header h1 {
        font-size: 1.4em;
    }
    header p {
        font-size: 0.9em;
    }
    #calculate-btn, .secondary-btn {
        padding: 12px;
        font-size: 1em;
    }
    .tabs {
        flex-wrap: wrap;
    }
    .tab-link {
        font-size: 1em;
        padding: 8px 12px;
    }
    .summary-card {
        padding: 15px;
    }
}

/* --- Paycheck Impact --- */
.paycheck-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 16px;
    align-items: center;
    margin-bottom: 15px;
}
.paycheck-value {
    font-weight: 600;
    font-size: 1.1em;
    text-align: right;
    font-feature-settings: "tnum";
}
.paycheck-cost {
    color: var(--danger-color); /* Red */
}
.paycheck-final {
    color: var(--success-color); /* Green */
    font-size: 1.2em;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}
.paycheck-grid div:nth-last-child(-n+2) { /* Selects the last row */
    margin-top: 8px;
}
.paycheck-explainer {
    font-size: 0.95em;
    color: var(--text-color-light);
    text-align: center;
    line-height: 1.5;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

/* --- Power of £1 / 1% --- */
.power-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 25px;
}
.power-section {
    text-align: center;
}
.power-section h2 {
    font-size: 1.1em;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}
.power-section p {
    font-size: 0.9em;
    color: var(--text-color-light);
    margin: 0 0 15px 0;
}
.power-section ul {
    text-align: left;
    font-size: 1em;
}
.power-section li span {
    color: var(--text-color);
}
.power-one-percent-value {
    font-size: 2.2em;
    font-weight: 700;
    color: var(--success-color);
    margin: 10px 0;
}
.power-one-percent-explainer {
    font-size: 0.9em;
    color: var(--text-color-light);
    margin-top: 5px;
}
.power-one-percent-income {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--text-color);
    margin-top: -5px;
}

/* --- Freedom Summary --- */
.freedom-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 16px;
    align-items: center;
}
.freedom-value {
    font-weight: 600;
    font-size: 1.1em;
    text-align: right;
    font-feature-settings: "tnum";
}
.freedom-number {
    font-size: 1.4em;
    color: var(--primary-color);
}
.freedom-age {
    font-size: 1.4em;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
}
.freedom-age.achieved {
    color: var(--success-color); /* Green */
}
.freedom-age.unachieved {
    color: var(--danger-color); /* Red */
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

.confetti {
    position: fixed;
    z-index: 9999;
    width: 8px;
    height: 8px;
    background-color: #f00;
    opacity: 1;
    animation: pop 1s ease-out forwards;
    pointer-events: none;
}

@keyframes pop {
    to {
        transform: translate(var(--x), var(--y)) rotate(720deg) scale(0);
        opacity: 0;
    }
}

.freedom-subheader {
    margin-top: 20px;
    font-size: 1.1em;
    color: var(--text-color);
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
}

/* --- Cost of Delay --- */
#cost-of-delay-summary ul {
    padding-left: 0;
    list-style: none;
}
#cost-of-delay-summary li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 1.05em;
}
.delay-diff {
    font-size: 0.9em;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--border-radius-sm);
    margin-left: 8px;
}
.delay-diff.increase {
    color: var(--danger-color);
    background-color: rgba(192, 57, 43, 0.1);
}
.delay-diff.decrease {
    color: var(--success-color);
    background-color: rgba(39, 174, 96, 0.1);
}

/* --- Tax Saved --- */
#tax-saved-summary {
    text-align: center;
}
.tax-saved-value {
    font-size: 2.2em;
    font-weight: 700;
    color: var(--primary-color);
    margin: 10px 0;
}

/* --- Tax Breakdown --- */
#tax-breakdown-summary h4 {
    font-size: 1.1em;
    color: var(--text-color);
    margin-top: 0;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border-color);
}
.tax-breakdown-item {
    margin-top: 20px;
}
.tax-grid {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 4px 16px;
    font-size: 0.95em;
}
.tax-grid-header {
    font-weight: 700;
    color: var(--text-color-light);
    text-align: right;
}
.tax-value {
    font-weight: 600;
    text-align: right;
    font-feature-settings: "tnum";
}
.tax-cost {
    color: var(--danger-color);
}
.tax-final {
    font-weight: 700;
    color: var(--primary-color);
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
    padding-top: 4px;
}

/* --- Input Sections --- */
.accordion-item {
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    overflow: hidden;
}
.accordion-header {
    width: 100%;
    background-color: var(--neutral-bg);
    border: none;
    padding: 15px 20px;
    text-align: left;
    font-size: 1.2em;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    transition: background-color 0.3s ease;
    position: relative;
}
.accordion-header::after {
    content: '▼';
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.3s ease;
}
.accordion-header.active::after {
    transform: translateY(-50%) rotate(180deg);
}
.accordion-header:hover {
    background-color: #e9ecef;
}
.accordion-content {
    padding: 0 20px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}
.accordion-content .input-group:first-child {
    padding-top: 20px;
}

/* --- Standout Card --- */
.standout-card {
    background-color: #e7f5ff;
    border-color: #bde0fe;
}

/* --- Snapshot --- */
.snapshot {
    text-align: center;
}
.snapshot h3 {
    margin-top: 0;
    font-size: 1.2em;
    color: var(--primary-color);
}
.snapshot p {
    margin: 10px 0;
}
.snapshot-value {
    font-size: 2.5em;
    font-weight: 700;
    color: var(--primary-color);
}



/* --- Dashboard --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 16px;
    align-items: center;
}
.dashboard-value {
    font-weight: 600;
    font-size: 1.2em;
    text-align: right;
    font-feature-settings: "tnum";
}
.dashboard-value.highlight {
    font-size: 2em;
    color: var(--primary-color);
    font-weight: 700;
}

.summary-card-tab {
    padding: 20px;
    background-color: var(--bg-color-light);
}
.summary-card-tab h2 {
    margin-top: 0;
    font-size: 1.2em;
    color: var(--primary-color);
}

/* --- Tabs --- */
.tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #dee2e6;
}
.tab-link {
    padding: 10px 20px;
    cursor: pointer;
    border: none;
    background-color: transparent;
    font-size: 1.1em;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s ease-in-out;
}
.tab-link:hover {
    color: var(--primary-color);
}
.tab-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}
.tab-content {
    display: none;
    flex-direction: column;
    gap: 30px;
}
.tab-content.active {
    display: flex;
}

#optimizer-summary ul {
    list-style-type: '💡';
    padding-left: 20px;
}
#optimizer-summary li {
    padding-left: 10px;
    display: list-item;
    justify-content: flex-start;
    margin-bottom: 15px;
}

/* --- Tooltips --- */
.tooltip {
    position: relative;
    display: inline-block;
    cursor: pointer;
    background-color: var(--primary-color);
    color: var(--bg-color-light);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 12px;
    line-height: 16px;
    text-align: center;
    font-weight: bold;
    margin-left: 5px;
}

.tooltip::before, .tooltip::after {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
    z-index: 10;
}

.tooltip::before {
    content: attr(data-tooltip);
    background-color: var(--text-color);
    color: var(--bg-color-light);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9em;
    width: 220px;
    text-align: left;
    line-height: 1.4;
    bottom: 150%;
    font-weight: normal;
}

.tooltip::after {
    content: '';
    border-style: solid;
    border-width: 6px;
    border-color: var(--text-color) transparent transparent transparent;
    bottom: 150%;
    margin-bottom: -12px;
}

.tooltip:hover::before, .tooltip:hover::after {
    opacity: 1;
}
