/*
(c) Tax Policy Associates Ltd, 2025, licensed under the MIT licence.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software,
to use it however they wish provided they attribute it to Tax Policy Associates Ltd.
*/
:root {
    --desktop-content-max-width: 960px;
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f8f9fa;
    color: #212529;
}

#app {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: min(1200px, 100%);
    margin: 0 auto;
    width: 100%;
}

.skip-link {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 8px 14px;
    background-color: #1133AF;
    color: #fff;
    border-radius: 6px;
    text-decoration: none;
    transform: translateY(-200%);
    transition: transform 0.2s ease;
    z-index: 1000;
}

.skip-link:focus {
    transform: translateY(0);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    color: #1133AF;
}

.page-header h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 600;
}

.hide-branding .page-header {
    display: none;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    flex-wrap: wrap;
}

.controls-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.controls-card {
    background-color: #fff;
    border-radius: 12px;
    padding: 20px 24px;
    border: 1px solid #e6e9f2;
    box-shadow: 0 10px 24px rgba(17, 51, 175, 0.05);
    width: 100%;
}

.control-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-end;
}

.control-row--middle {
    align-items: flex-end;
}

.control {
    display: flex;
    flex-direction: column;
}

.control label {
    font-weight: bold;
    font-size: 0.9em;
    margin-bottom: 5px;
}

.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;
}

.control select, .control input {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ced4da;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

.income-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

.employment-type-select {
    display: flex;
}

.employment-type-select select {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ced4da;
    height: 38px;
}

.control--marginal-income {
    margin-left: auto;
    min-width: 200px;
}

.control--marginal-income select {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ced4da;
    height: 38px;
    width: 100%;
}

.control--income input {
    min-width: 220px;
}

.input-with-clear {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-clear input {
    width: 100%;
    padding-right: 36px;
}

.clear-input {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background-color: transparent;
    border: none;
    color: #8a92a6;
    padding: 0;
    width: 28px;
    height: 28px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.clear-input:hover,
.clear-input:focus-visible {
    color: #0d2784;
    background-color: rgba(17, 51, 175, 0.08);
}

.clear-input:focus-visible {
    outline: 2px solid rgba(17, 51, 175, 0.35);
    outline-offset: 2px;
}

.control--flip {
    display: flex;
    align-items: flex-end;
}

.control--compare {
    margin-left: 20px;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px; /* Align with select boxes */
}

.checkbox-group label {
    margin-bottom: 0;
    font-weight: normal;
}

.option-fieldset {
    border: 0;
    padding: 0;
    margin: 0;
    min-width: 0;
}

#chart-container {
    flex-grow: 1;
    width: 100%;
    min-width: 0; /* Important for flexbox shrinking */
    margin: 0 auto;
    position: relative;
}

#plotly-chart {
    width: 100%;
    min-height: 320px;
}

.chart-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    display: flex;
    gap: 8px;
}

.icon-button.download-button {
    position: relative;
    background-color: rgba(255, 255, 255, 0.9);
    border-color: rgba(17, 51, 175, 0.35);
    color: #1133AF;
    height: 26px;
    min-width: 36px;
    padding: 0 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.8rem;
    box-shadow: 0 6px 18px rgba(17, 51, 175, 0.18);
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.icon-button.download-button:hover {
    background-color: #fff;
    border-color: rgba(17, 51, 175, 0.5);
    box-shadow: 0 8px 22px rgba(17, 51, 175, 0.22);
    transform: translateY(-1px);
}

.icon-button.download-button:active {
    transform: translateY(0);
    box-shadow: 0 3px 10px rgba(17, 51, 175, 0.15);
}

.icon-button.download-button::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translate(-50%, 4px);
    background-color: rgba(17, 51, 175, 0.9);
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.icon-button.download-button:focus-visible::after,
.icon-button.download-button:hover::after {
    opacity: 1;
    transform: translate(-50%, 0);
}

.income-panel {
    background-color: #fff;
    border-radius: 12px;
    padding: 16px 20px;
    border: 1px solid #e6e9f2;
    box-shadow: 0 10px 24px rgba(17, 51, 175, 0.05);
}

.results-card {
    background-color: #fff;
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: 0 10px 30px rgba(17, 51, 175, 0.08);
    border: 1px solid #e6e9f2;
}

.results-card-title {
    margin: 0 0 16px;
    font-size: 1.2rem;
    font-weight: 600;
    color: #1133AF;
}

.results-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 24px;
    border-bottom: 1px solid #f0f1f5;
    padding-bottom: 16px;
    margin-bottom: 12px;
}

.results-summary--comparison {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.result-metric {
    flex: 1 1 auto;
}

.metric-label {
    text-transform: uppercase;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6c757d;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.metric-value {
    font-size: 2rem;
    font-weight: 600;
    margin: 0;
    color: #111;
}

.metric-value--accent {
    color: #1133AF;
}

.metric-note {
    margin: 4px 0 0;
    color: #6c757d;
    font-size: 0.9rem;
}

.comparison-summary-wrapper {
    margin-top: 16px;
    padding: 16px 20px;
    border-radius: 10px;
    border: 1px solid #dbe3ff;
    background-color: #f5f7ff;
    box-shadow: 0 8px 20px rgba(17, 51, 175, 0.08);
}

.comparison-summary-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.comparison-summary-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #1133AF;
}

.results-details summary {
    cursor: pointer;
    list-style: none;
    font-weight: 600;
    color: #1133AF;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

.results-details summary::-webkit-details-marker {
    display: none;
}

.results-details[open] .chevron {
    transform: rotate(180deg);
}

.chevron {
    border: solid #1133AF;
    border-width: 0 2px 2px 0;
    display: inline-block;
    padding: 4px;
    transform: rotate(-135deg);
    transition: transform 0.2s ease;
}

.breakdown-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-top: 12px;
}

.breakdown-section h4 {
    margin: 0 0 8px;
    font-size: 1rem;
    color: #212529;
}

.breakdown-section {
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.personal-allowance-line {
    font-weight: 600;
    margin: 10px 0 20px;
    font-size: 0.9rem;
}

.breakdown-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
}

.breakdown-section li {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    padding: 6px 0;
    border-bottom: 1px solid #f0f1f5;
}

.breakdown-section li:last-child {
    border-bottom: none;
}

.breakdown-section li span:last-child,
.breakdown-total span:last-child {
    min-width: 110px;
    text-align: right;
}

.breakdown-total {
    margin-top: auto;
    padding-top: 8px;
    border-top: 2px solid #dce1eb;
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.9rem;
}

.logo-link {
    margin-left: auto;
}

.logo {
    height: 60px;
    object-fit: contain;
}

.article-link-banner {
    font-size: 1rem;
    color: #212529;
    margin: 10px 0 12px;
    line-height: 1.5;
}

.article-link-banner a {
    color: #1133AF;
    font-weight: 600;
    text-decoration: underline;
}

.hide-branding .article-link-banner {
    display: none;
}

.disclaimer {
    font-size: 0.85rem;
    color: #6c757d;
    margin: 0 0 30px;
    line-height: 1.4;
}

.apply-button,
.flip-button,
.icon-button {
    padding: 8px 16px;
    border: 1px solid #1133AF;
    border-radius: 4px;
    background-color: #1133AF;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.apply-button:hover,
.flip-button:hover,
.icon-button:hover {
    background-color: #0d2784;
    border-color: #0d2784;
}

.income-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.delta-negative {
    color: #D7263D;
}

@media (min-width: 769px) {
    .page-header,
    .top-bar,
    #chart-container,
    .income-panel,
    .results-card,
    .article-link-banner,
    .disclaimer {
        max-width: var(--desktop-content-max-width);
        width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    .controls-card {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .page-header {
        flex-direction: row;
        align-items: center;
        text-align: left;
        justify-content: flex-start;
    }

    .page-header h1 {
        font-size: 1.5rem;
        flex: 1 1 auto;
    }

    .logo-link {
        order: -1;
        margin-left: 0;
    }

    .control-row {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }
    
    .top-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .control-row--top {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .control--chart-type {
        grid-column: 1;
        grid-row: 1;
    }

    .control--flip {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
        align-self: end;
    }

    .control--dataset {
        grid-column: 1;
        grid-row: 2;
    }

    .control--compare {
        grid-column: 2;
        grid-row: 2;
        margin-left: 0;
    }

    .control-row--middle {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
        padding: 16px;
        border: 1px solid #d9def0;
        border-radius: 12px;
        background-color: #f3f5ff;
    }

    .control--children,
    .control--childcare {
        grid-column: span 1;
        max-width: 180px;
        justify-self: start;
    }

    .control--checkboxes {
        grid-column: 1 / span 2;
        padding-top: 10px;
        margin-top: 4px;
        border-top: 1px dashed #c0c8ea;
    }

    .income-form {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .control--income input {
        min-width: 0;
        width: min(50vw, 100%);
    }
    
    .control--marginal-income {
        width: 100%;
        margin-left: 0;
    }

    .control select {
        color: #000;
    }

    .apply-button {
        width: 100%;
    }

    .chart-download {
        top: 46px;
    }

    .results-summary {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .result-metric {
        margin: 0;
        padding: 8px;
        border: 1px solid #e3e7f3;
        border-radius: 8px;
        background-color: #fafbff;
    }

    .metric-value {
        font-size: 1.4rem;
    }

    .metric-label {
        font-size: 0.65rem;
        letter-spacing: 0.03em;
    }

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

    .logo {
        height: 48px;
    }

    .results-card {
        padding: 16px;
    }

    .comparison-summary-wrapper {
        padding: 12px;
    }

    .controls-card {
        padding: 16px;
    }
}
