:root {
    --bg-primary: #0d0d0d;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --text-muted: #666666;
    --accent: #e63946;
    --accent-dark: #b32d38;
    --border: #333333;
    --success: #2ecc71;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }
}

/* Header */
header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

@media (max-width: 600px) {
    header h1 {
        font-size: 2rem;
    }
}

header .subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
}

@media (max-width: 600px) {
    header .subtitle {
        font-size: 1rem;
    }
}

header .subtitle em {
    color: var(--text-primary);
    font-style: italic;
}

/* Calculator Layout */
.calculator {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
}

@media (max-width: 900px) {
    .calculator {
        grid-template-columns: 1fr;
    }
}

/* Inputs Section */
.inputs {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-group {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border);
}

@media (max-width: 600px) {
    .input-group {
        padding: 1rem;
    }
}

.input-group h2 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.input-group label {
    display: block;
    margin-bottom: 1rem;
}

.input-group label:last-child {
    margin-bottom: 0;
}

.label-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.label-text {
    flex-shrink: 0;
}

.help {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--border);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.help:hover {
    background: var(--accent);
    color: var(--text-primary);
}

.help.active {
    background: var(--accent);
    color: var(--text-primary);
}

/* Tooltip popup */
.tooltip {
    position: fixed;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    color: var(--text-primary);
    width: min(250px, calc(100vw - 32px));
    max-width: 250px;
    line-height: 1.5;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

.tooltip::after {
    content: '';
    position: absolute;
    border: 6px solid transparent;
    border-top-color: var(--border);
}

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

.input-wrapper .prefix {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

input[type="number"],
select {
    width: 100%;
    padding: 0.75rem 1rem;
    padding-left: 2rem;
    font-size: 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="number"]:not(.input-wrapper input) {
    padding-left: 1rem;
}

select {
    padding-left: 1rem;
    cursor: pointer;
}

input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.2);
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
}

.hidden {
    display: none !important;
}

/* Checkbox styling */
.input-group .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: background 0.2s, border-color 0.2s;
}

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

.checkbox-label input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
}

.checkbox-label input[type="checkbox"]:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.2);
}

.checkbox-label .label-row {
    margin-bottom: 0;
}


/* Results Section */
.results {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .summary {
        gap: 0.75rem;
    }
}

.stat {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid var(--border);
    text-align: center;
}

.stat.primary {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    border: none;
}

.stat .label {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.stat.primary .label {
    color: rgba(255, 255, 255, 0.8);
}

.stat .value {
    font-size: 1.75rem;
    font-weight: 700;
}

.stat.primary .value {
    font-size: 2.5rem;
}

@media (max-width: 600px) {
    .stat.primary .value {
        font-size: 2rem;
    }

    .stat .value {
        font-size: 1.5rem;
    }
}

/* Breakdown Table */
.breakdown {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border);
}

@media (max-width: 600px) {
    .breakdown {
        padding: 1rem;
    }
}

.breakdown h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* Expandable breakdown groups */
.breakdown-groups {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tax-group {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s;
}

.group-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    cursor: pointer;
    background: var(--bg-tertiary);
    transition: background 0.2s;
    user-select: none;
}

.group-header:hover {
    background: var(--border);
}

.group-header:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(230, 57, 70, 0.3);
}

.group-chevron {
    font-size: 0.7rem;
    transition: transform 0.3s ease;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.tax-group:not(.collapsed) .group-chevron {
    transform: rotate(90deg);
}

.group-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.group-total {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    transition: opacity 0.3s;
}

.tax-group:not(.collapsed) .group-total {
    opacity: 0;
}

.group-items {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.tax-group.collapsed .group-items {
    opacity: 0;
}

.tax-item {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.95rem;
}

@media (max-width: 600px) {
    .tax-item {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
}

.tax-item:first-child {
    border-top: none;
}

.tax-item > span:first-child {
    color: var(--text-secondary);
}

.tax-item > span:last-child {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.tax-item.excluded {
    opacity: 0.4;
}

.tax-item.excluded > span:first-child::after {
    content: ' (excluded)';
    font-size: 0.75rem;
    color: var(--text-muted);
}

.breakdown-total {
    display: flex;
    justify-content: space-between;
    padding: 1rem 0.75rem;
    margin-top: 0.5rem;
    border-top: 2px solid var(--accent);
    font-weight: 700;
}

.breakdown-total > span:first-child {
    color: var(--text-primary);
}

.breakdown-total > span:last-child {
    color: var(--accent);
    font-size: 1.1rem;
    font-variant-numeric: tabular-nums;
}

/* Footer */
footer {
    margin-top: 3rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}


/* Animations */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.stat.primary {
    animation: pulse 2s ease-in-out infinite;
}

.stat.primary:hover {
    animation: none;
}

/* ============================================
   Tax Freedom Section - Unified
   ============================================ */

.tax-freedom-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    margin-bottom: 2rem;
}

/* Decorative gradient accent */
.tax-freedom-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 12px 12px 0 0;
}

.tax-freedom-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.tax-freedom-header h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-weight: 600;
}

.freedom-date-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.5rem;
    background: linear-gradient(135deg, rgba(230, 57, 70, 0.1), rgba(230, 57, 70, 0.05));
    border-radius: 12px;
    border: 1px solid rgba(230, 57, 70, 0.3);
}

.date-label,
.date-sublabel {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.freedom-date {
    font-size: 3rem;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
}

.calendar-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 1rem;
    line-height: 1.4;
}

.tax-calendar {
    display: grid;
    grid-template-columns: repeat(37, 1fr);
    gap: 3px;
    max-width: 800px;
    margin: 0 auto 1rem;
}

@media (max-width: 768px) {
    .tax-calendar {
        grid-template-columns: repeat(30, 1fr);
    }
}

@media (max-width: 500px) {
    .tax-calendar {
        grid-template-columns: repeat(20, 1fr);
        gap: 2px;
    }
}

.calendar-day {
    aspect-ratio: 1;
    border-radius: 2px;
    transition: transform 0.15s ease;
    cursor: pointer;
}

.calendar-day:hover {
    transform: scale(1.3);
    z-index: 10;
}

.calendar-day.tax-day {
    background: var(--accent);
}

.calendar-day.freedom-day {
    background: var(--success);
}

.tax-freedom-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.calendar-stats {
    display: flex;
    gap: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.stat-item:first-child .stat-value {
    color: var(--accent);
}

.stat-item:last-child .stat-value {
    color: var(--success);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.freedom-btn {
    padding: 0.875rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid;
    white-space: nowrap;
}

.freedom-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-primary);
}

.freedom-btn.primary:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(230, 57, 70, 0.3);
}

.freedom-btn.secondary {
    background: transparent;
    border-color: var(--success);
    color: var(--success);
}

.freedom-btn.secondary:hover {
    background: var(--success);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3);
}

.freedom-btn:active {
    transform: scale(0.98);
}

.freedom-btn.loading {
    opacity: 0.7;
    cursor: wait;
}

.freedom-btn.loading::after {
    content: '';
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-left: 0.5em;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .tax-freedom-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .calendar-stats {
        justify-content: center;
        width: 100%;
    }

    .action-buttons {
        width: 100%;
        flex-direction: column;
    }

    .freedom-btn {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .freedom-date {
        font-size: 2.25rem;
    }

    .tax-freedom-section {
        padding: 1.5rem;
    }
}
