/* ===== CSS Variables ===== */
:root {
    --bg-primary: #f8f8f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --border: #e0e0e0;
    --grid: #f0f0f0;
    --error: #cc3333;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #242424;
        --bg-tertiary: #2a2a2a;
        --text-primary: #e0e0e0;
        --text-secondary: #a0a0a0;
        --text-tertiary: #707070;
        --accent: #a78bfa;
        --accent-hover: #c4b5fd;
        --border: #3a3a3a;
        --grid: #2a2a2a;
        --error: #ff6666;
    }
}

body.light-theme {
    --bg-primary: #f8f8f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --border: #e0e0e0;
    --grid: #f0f0f0;
    --error: #cc3333;
}

body.dark-theme {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-tertiary: #2a2a2a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-tertiary: #707070;
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --border: #3a3a3a;
    --grid: #2a2a2a;
    --error: #ff6666;
}

/* ===== Base Styles ===== */
body {
    margin: 0;
    padding: 0;
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    font-size: 13px;
}

@media (max-width: 768px) {
    body {
        overflow-x: hidden;
        overflow-y: auto;
    }
}

/* ===== Layout ===== */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 8px;
    box-sizing: border-box;
    overflow: hidden;
}

@media (max-width: 768px) {
    .container {
        overflow-x: hidden;
        overflow-y: visible;
    }
}

.header {
    background: var(--bg-secondary);
    padding: 6px 10px;
    border: 1px solid var(--border);
    margin-bottom: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 15px;
    align-items: stretch;
    position: relative;
}

h1 {
    margin: 0 0 6px 0;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center;
}

/* ===== Controls ===== */
.controls {
    display: flex;
    gap: 15px;
    align-items: stretch;
    height: 64px;
}

.selectors-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    height: 100%;
}

.toggles-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 0 0 auto;
    height: 100%;
    justify-content: space-between;
}

.toggles-row {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.play-button-group {
    justify-content: center;
    gap: 8px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.selectors-group .control-group {
    gap: 4px;
}

.selectors-group .control-group select {
    width: 160px;
}

.control-group > label:first-child {
    font-size: 12px;
    font-weight: normal;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 4px;
}

.control-group label {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.control-group label span {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-left: 8px;
}

/* ===== Stats Section ===== */
.stats-wrapper {
    display: flex;
    flex-direction: column;
}

.stats {
    background: var(--bg-tertiary);
    padding: 6px 10px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stats-row {
    display: flex;
    gap: 15px;
}

.stat {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-label {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

.stat-value {
    font-size: 13px;
    font-weight: normal;
    color: var(--text-primary);
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
    line-height: 1.2;
}

.stat-change {
    font-size: 11px;
    color: var(--text-tertiary);
    display: block;
    line-height: 1.2;
}

.stat-change.positive {
    color: #10b981;
}

.stat-change.negative {
    color: #ef4444;
}

/* ===== Tax Reform Note ===== */
.tax-reform-note {
    margin: 2px 0 0 0;
    padding: 4px 8px;
    background: var(--bg-primary);
    border-left: 3px solid var(--accent);
    font-size: 10px;
    line-height: 1.3;
    transition: all 0.3s;
}

.tax-reform-note.empty {
    border-left-color: var(--text-tertiary);
    opacity: 0.5;
}

.note-label {
    color: var(--accent);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tax-reform-note.empty .note-label {
    color: var(--text-tertiary);
}

.note-text {
    color: var(--text-secondary);
    margin-left: 4px;
}

.tax-reform-note.empty .note-text {
    color: var(--text-tertiary);
}

/* ===== Tax Brackets Visualization ===== */
.tax-brackets {
    background: var(--bg-tertiary);
    padding: 6px 10px;
    border: 1px solid var(--border);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.tax-brackets-header {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.tax-brackets-viz {
    position: relative;
    flex: 1;
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.tax-bracket-bar {
    display: flex;
    height: 24px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

.tax-bracket {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg-secondary);
    font-size: 10px;
    font-weight: bold;
    transition: all 0.3s;
    border-right: 1px solid var(--border);
}

.tax-bracket:last-child {
    border-right: none;
}

.tax-bracket-labels {
    display: flex;
    position: relative;
    height: 15px;
    font-size: 9px;
    color: var(--text-tertiary);
}

.tax-bracket-label {
    position: absolute;
    top: 4px;
    transform: translateX(-50%);
    white-space: nowrap;
}

.tax-bracket-label:last-child {
    transform: translateX(-100%);
}

/* ===== Chart Container ===== */
#chart-container {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    position: relative;
    min-height: 0;
    padding-bottom: 14px;
    overflow: hidden;
}

#chart {
    width: 100%;
    height: calc(100% - 14px);
}

@media (max-width: 768px) {
    #chart {
        height: 100%;
    }
}

/* ===== Form Elements ===== */
select, button {
    padding: 4px 8px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 0;
}

select:focus, button:focus {
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

button {
    background: var(--bg-tertiary);
    color: var(--accent);
    border: 1px solid var(--border);
    transition: all 0.2s;
    font-weight: 500;
    letter-spacing: 0.5px;
}

button:hover {
    background: var(--accent);
    color: var(--bg-secondary);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.25);
}

button.playing {
    background: var(--accent);
    color: var(--bg-secondary);
    border-color: var(--accent);
}

button.playing:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* ===== Navigation Buttons ===== */
.nav-button {
    padding: 4px 12px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--accent);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 0;
    transition: all 0.2s;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.nav-button:hover, .nav-button:active {
    background: var(--accent);
    color: var(--bg-secondary);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.25);
}

.nav-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-button:disabled:hover {
    background: var(--bg-tertiary);
    color: var(--accent);
    border-color: var(--border);
    box-shadow: none;
}

/* ===== Toggle Switches ===== */
input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-icon {
    font-size: 18px !important;
    display: inline-block;
    width: 24px;
    text-align: center;
    margin-left: 6px !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    top: 2px;
    background-color: var(--text-tertiary);
    border-radius: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

input[type="checkbox"]:checked + .toggle-switch {
    background-color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.25);
}

input[type="checkbox"]:checked + .toggle-switch::after {
    transform: translateX(14px);
    background-color: var(--bg-secondary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.control-group label:hover .toggle-switch {
    background-color: var(--bg-tertiary);
    border-color: var(--accent);
}

input[type="checkbox"]:checked + .toggle-switch:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

input[type="checkbox"]:focus-visible + .toggle-switch {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Toggle tooltips */
.control-group label[data-tooltip] {
    position: relative;
}

.control-group label[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 4px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.control-group label[data-tooltip]:hover::after {
    opacity: 1;
}

/* ===== Theme Toggle ===== */
.theme-toggle {
    position: absolute;
    top: -1px;
    right: -1px;
    font-size: 11px;
    text-transform: uppercase;
    padding: 3px 6px;
    background: var(--accent);
    border: 1px solid var(--accent);
    color: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
}

.theme-toggle:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.theme-toggle::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.theme-toggle:hover::after {
    opacity: 1;
}

/* ===== Help Button ===== */
.help-button {
    position: fixed;
    bottom: 8px;
    right: 8px;
    font-size: 11px;
    text-transform: uppercase;
    padding: 3px 6px;
    background: var(--accent);
    border: 1px solid var(--accent);
    color: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.2s;
    z-index: 100;
    border-radius: 0;
}

.help-button:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 50px auto;
    padding: 30px;
    border: 1px solid var(--border);
    width: 90%;
    max-width: 700px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
}

.modal-close {
    color: var(--text-secondary);
    float: right;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
    margin: -10px -10px 0 0;
}

.modal-close:hover,
.modal-close:focus {
    color: var(--text-primary);
}

.modal h2 {
    color: var(--text-primary);
    font-size: 18px;
    margin: 0 0 20px 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modal h3 {
    color: var(--text-primary);
    font-size: 14px;
    margin: 20px 0 10px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal p, .modal li {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.6;
    margin: 10px 0;
}

.modal ul {
    margin: 10px 0;
    padding-left: 20px;
}

.modal a {
    color: var(--accent);
    text-decoration: none;
}

.modal a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.modal code {
    background: var(--bg-tertiary);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 11px;
    color: var(--text-primary);
}

/* ===== Helper Text ===== */
.data-source, .current-year {
    margin-top: auto;
    padding-top: 6px;
    font-size: 9px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
}

.data-source-bottom {
    position: fixed;
    bottom: 8px;
    left: 8px;
    font-size: 8px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--bg-secondary);
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.help-text {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.current-year {
    margin-top: 6px;
    padding-top: 0;
}

/* ===== Links ===== */
.data-source a, .data-source-bottom a {
    color: var(--accent);
    text-decoration: none;
}

.data-source a:hover, .data-source-bottom a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ===== Dark Theme Specific ===== */
body.dark-theme input[type="checkbox"]:checked + .toggle-switch {
    box-shadow: 0 0 8px rgba(167, 139, 250, 0.3);
}

body.dark-theme button:hover {
    box-shadow: 0 0 8px rgba(167, 139, 250, 0.3);
}

@media (prefers-color-scheme: dark) {
    button {
        color: var(--accent);
    }
    
    input[type="checkbox"]:checked + .toggle-switch {
        box-shadow: 0 0 8px rgba(167, 139, 250, 0.3);
    }
    
    button:hover {
        box-shadow: 0 0 8px rgba(167, 139, 250, 0.3);
    }
}

/* ===== Mobile Styles ===== */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .container {
        padding: 4px;
        display: flex;
        flex-direction: column;
        position: relative;
    }
    
    .header {
        grid-template-columns: 1fr;
        gap: 10px;
        order: 2;
        margin-bottom: 4px;
        flex: 0 0 auto;
    }
    
    .header h1 {
        display: none;
    }
    
    #chart-container {
        order: 1;
        flex: 1 1 auto;
        min-height: 350px;
        margin-bottom: 8px;
        padding-bottom: 0;
    }
    
    .controls {
        flex-direction: column;
        gap: 10px;
        height: auto;
    }
    
    .selectors-group {
        height: auto;
    }
    
    .toggles-group {
        height: auto;
        justify-content: flex-start;
    }
    
    .selectors-group .control-group select {
        width: 100%;
        min-width: 140px;
    }
    
    .data-source-bottom {
        display: none;
    }
    
    .help-text {
        display: none;
    }
    
    .nav-button {
        padding: 6px 16px;
        font-size: 16px;
    }
    
    .mobile-only {
        display: flex;
    }
    
    .tax-brackets-header {
        display: none;
    }
    
    .help-button:not(.mobile-only) {
        display: none;
    }
    
    .help-button.mobile-only {
        display: block;
        position: absolute;
        bottom: 8px;
        right: 8px;
        z-index: 100;
    }
    
    .header {
        position: relative;
    }
    
    .modal-content {
        margin: 10px;
        padding: 15px;
        width: calc(100% - 20px);
        max-width: none;
        max-height: calc(100vh - 20px);
        border-radius: 4px;
        box-sizing: border-box;
    }
}