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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f4f5f7;
    color: #1a1a2e;
    line-height: 1.6;
    padding: 2rem 1rem;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
}

.main-layout {
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1a1a2e;
}

.tax-year {
    font-size: 0.95rem;
    color: #5a5a7a;
    margin-top: 0.25rem;
}

.card {
    background: #fff;
    border: 1px solid #e0e0e8;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: #1a1a2e;
}

/* Input section */

.form-group {
    margin-bottom: 1rem;
}

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

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: #3a3a5a;
}

.input-wrapper {
    display: flex;
    align-items: center;
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: hidden;
}

.input-wrapper:focus-within {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.currency-symbol {
    padding: 0.5rem 0.65rem;
    background: #f4f5f7;
    color: #5a5a7a;
    font-weight: 500;
    border-right: 1px solid #ccc;
}

.input-wrapper input {
    flex: 1;
    border: none;
    outline: none;
    padding: 0.5rem 0.65rem;
    font-size: 1rem;
}

.form-group > input[type="number"] {
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0.5rem 0.65rem;
    font-size: 1rem;
}

.form-group > input[type="number"]:focus {
    border-color: #2563eb;
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* Help icon / tooltip */

.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #5a5a7a;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: help;
    position: relative;
    vertical-align: middle;
    margin-left: 0.35rem;
}

.tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    background: #1a1a2e;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.45;
    padding: 0.75rem;
    border-radius: 6px;
    z-index: 10;
    pointer-events: none;
}

.tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1a1a2e;
}

.help-icon:hover .tooltip,
.help-icon:focus .tooltip {
    display: block;
}

/* Output section */

.key-figures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.figure {
    background: #f4f5f7;
    border-radius: 6px;
    padding: 0.75rem;
}

.figure.highlight {
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
}

.figure-label {
    display: block;
    font-size: 0.8rem;
    color: #5a5a7a;
    margin-bottom: 0.2rem;
}

.figure.highlight .figure-label {
    color: #2e7d32;
}

.figure-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
}

.figure.highlight .figure-value {
    color: #2e7d32;
}

/* Bottleneck */

.bottleneck {
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.bottleneck.bottleneck-gift-aid {
    background: #fff8e1;
    border: 1px solid #ffe082;
}

.bottleneck.bottleneck-matched {
    background: #f3e5f5;
    border: 1px solid #ce93d8;
}

.bottleneck.bottleneck-untapped {
    background: #e3f2fd;
    border: 1px solid #90caf9;
}

.bottleneck.bottleneck-maxed {
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
}

.bottleneck-status {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
}

.bottleneck-gift-aid .bottleneck-status {
    color: #e65100;
}

.bottleneck-matched .bottleneck-status {
    color: #7b1fa2;
}

.bottleneck-untapped .bottleneck-status {
    color: #1565c0;
}

.bottleneck-maxed .bottleneck-status {
    color: #2e7d32;
}

.bottleneck-advice {
    font-size: 0.875rem;
    color: #3a3a5a;
}

/* Bar chart */

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.bar-row {
    display: grid;
    grid-template-columns: 180px 1fr 80px;
    align-items: center;
    gap: 0.75rem;
}

.bar-label {
    font-size: 0.8rem;
    color: #5a5a7a;
    text-align: right;
}

.bar-track {
    height: 24px;
    background: #e8e8ee;
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
    min-width: 0;
}

.bar-gift-aid {
    background: #2563eb;
}

.bar-small-donations {
    background: #7c3aed;
}

.bar-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1a1a2e;
}

/* Final tally */

.tally {
    margin-top: 1.5rem;
    border-top: 1px solid #e0e0e8;
    padding-top: 1.25rem;
}

.tally h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #1a1a2e;
}

.tally-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.tally-table td {
    padding: 0.4rem 0;
    color: #3a3a5a;
}

.tally-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.tally-table tfoot td {
    border-top: 1px solid #e0e0e8;
    padding-top: 0.6rem;
    font-weight: 700;
    color: #1a1a2e;
    font-size: 1.05rem;
}

/* Desktop: side-by-side layout */

@media (min-width: 768px) {
    .main-layout {
        flex-direction: row;
        gap: 1.5rem;
        align-items: flex-start;
    }

    .input-section {
        flex: 0 0 340px;
        position: sticky;
        top: 2rem;
    }

    .output-section {
        flex: 1;
        margin-bottom: 0;
    }
}

/* Small screens */

@media (max-width: 500px) {
    .key-figures {
        grid-template-columns: 1fr;
    }

    .bar-row {
        grid-template-columns: 1fr 80px;
    }

    .bar-label {
        grid-column: 1 / -1;
        text-align: left;
    }
}
