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

/* CSS Variables - Light Theme (default) */
:root {
    --bg-body: #f4f6f9;
    --bg-panel: #ffffff;
    --bg-input: #fafafa;
    --bg-input-focus: #ffffff;
    --text-primary: #0D1321;
    --text-label: #444444;
    --text-result-label: #555555;
    --text-muted: #6c757d;
    --text-dimmed: #888888;
    --border: #d1d5db;
    --border-light: #f0f0f0;
    --border-subtle: #f8f8f8;
    --shadow: rgba(0, 0, 0, 0.08);
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-body: #121212;
    --bg-panel: #1e1e1e;
    --bg-input: #2a2a2a;
    --bg-input-focus: #333333;
    --text-primary: #e0e0e0;
    --text-label: #b0b0b0;
    --text-result-label: #999999;
    --text-muted: #888888;
    --text-dimmed: #666666;
    --border: #404040;
    --border-light: #2a2a2a;
    --border-subtle: #252525;
    --shadow: rgba(0, 0, 0, 0.4);
}

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

header {
    background: #0D1321;
    color: #fff;
    padding: 1.5rem 2rem;
    border-bottom: 3px solid #D4A434;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

header .subtitle {
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: #a8b2c1;
}

.lang-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    align-self: flex-end;
    width: fit-content;
}

.lang-selector label {
    font-size: 0.8rem;
    color: #a8b2c1;
    font-weight: 500;
    margin-bottom: 0;
    white-space: nowrap;
}

.lang-selector select {
    width: auto;
    min-width: 110px;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    background: #2c2c3e;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
}

.lang-selector select:focus {
    outline: none;
    border-color: #D4A434;
    background: #0D1321;
}

.container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    max-width: 550px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}

.container:has(#results.is-visible) {
    grid-template-columns: 1fr 1fr;
    max-width: 1100px;
}

.input-panel, .results-panel, .error-panel {
    background: var(--bg-panel);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 4px var(--shadow);
}

h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #D4A434;
}

.results-panel h3 {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 1.5rem 0 0.75rem 0;
}

.results-panel h3:first-of-type {
    margin-top: 0;
}

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

label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-label);
    margin-bottom: 0.35rem;
}

input[type="number"], select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-input);
    transition: border-color 0.15s, background-color 0.15s;
}

input[type="number"]:focus, select:focus {
    outline: none;
    border-color: #D4A434;
    background: var(--bg-input-focus);
}

.calc-btn {
    width: 100%;
    padding: 0.75rem;
    background: #D4A434;
    color: #0D1321;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: background 0.15s;
}

.calc-btn:hover {
    background: #BF9320;
}

.calc-btn:active {
    background: #A67E10;
}

/* Results panel hidden until calculation */
#results {
    display: none;
}

#results.is-visible {
    display: block;
}

/* Metrics grid */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
}

.metric-card {
    background: var(--bg-input);
    border-radius: 6px;
    padding: 1rem 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.metric-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Colour coding for metrics */
.metric-good {
    color: #84b84c;
}

.metric-warning {
    color: #d97706;
}

.metric-danger {
    color: #C43C32;
}

[data-theme="dark"] .metric-good {
    color: #84b84c;
}

[data-theme="dark"] .metric-warning {
    color: #fbbf24;
}

[data-theme="dark"] .metric-danger {
    color: #C43C32;
}

/* Breakdown rows */
.results-detail {
    border-top: 1px solid var(--border-light);
    padding-top: 0.75rem;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border-subtle);
}

.result-row .result-label {
    font-size: 0.85rem;
    color: var(--text-result-label);
}

.result-row .result-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
}

.result-row--total {
    font-weight: 700;
    font-size: 1rem;
    border-top: 2px solid var(--border);
    margin-top: 0.25rem;
    padding-top: 0.5rem;
    border-bottom: none;
}

.result-row--total .result-label {
    color: var(--text-primary);
}

/* Warning panel */
.warning-panel {
    grid-column: 1 / -1;
    background: #fef3cd;
    border-left: 4px solid #d97706;
    border-radius: 8px;
    padding: 1rem 1.5rem;
    font-size: 0.9rem;
    color: #92400e;
}

[data-theme="dark"] .warning-panel {
    background: #422006;
    color: #fbbf24;
}

/* Error panel */
.error-panel {
    border-left: 4px solid #dc3545;
    grid-column: 1 / -1;
}

.error-panel h2 {
    color: #dc3545;
    border-color: #dc3545;
}

#error-message {
    color: #dc3545;
    font-size: 0.9rem;
}

.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Notes panel */
.notes-panel {
    grid-column: 2 / 3;
    background: var(--bg-panel);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 4px var(--shadow);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.notes-panel h3 {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 0.75rem 0;
}

.notes-content {
    line-height: 1.6;
}

.notes-content h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 1rem 0 0.25rem 0;
}

.notes-content h4:first-child {
    margin-top: 0;
}

.notes-content p {
    margin: 0 0 0.15rem 0;
}

.notes-content .note-formula {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-primary);
    background: var(--bg-input);
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    display: inline-block;
    margin: 0.2rem 0;
}

.notes-content .note-tip {
    font-style: italic;
    margin-top: 0.15rem;
}

/* Responsive overrides */
@media (max-width: 700px) {
    .container {
        grid-template-columns: 1fr;
    }
    .notes-panel {
        grid-column: 1;
    }
    #results:not(.is-visible) {
        display: none;
    }
    .metrics-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    header {
        flex-direction: column;
        align-items: flex-start;
    }
    .lang-selector {
        align-self: flex-end;
    }
}
