/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-input: #252830;
    --border: #2e3140;
    --text: #e4e6ed;
    --text-muted: #8b8fa3;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --gravity: #f97316;
    --rolling: #22c55e;
    --aero: #3b82f6;
    --drive: #a855f7;
    --error: #ef4444;
    --radius: 8px;
}

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

/* ===== Navigation ===== */
nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--accent-hover);
}

/* ===== Layout ===== */
main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.page-header p {
    color: var(--text-muted);
}

/* ===== Calculator Grid ===== */
.calculator-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

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

/* ===== Forms ===== */
.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.form-section h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

details.form-section summary {
    cursor: pointer;
    list-style: none;
}

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

details.form-section summary h2::before {
    content: '+ ';
    color: var(--accent);
}

details.form-section[open] summary h2::before {
    content: '- ';
}

.form-row {
    display: flex;
    gap: 1rem;
}

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

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

input:focus {
    outline: none;
    border-color: var(--accent);
}

.inline-input {
    width: 80px !important;
    display: inline-block;
    margin-left: 0.5rem;
}

/* Radio buttons */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.2s;
}

.radio-label:has(input:checked) {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

.radio-label input[type="radio"] {
    accent-color: var(--accent);
}

/* Submit button */
.btn-primary {
    display: inline-block;
    padding: 0.7rem 2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* Button group */
.btn-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.btn-secondary {
    display: inline-block;
    padding: 0.7rem 2rem;
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.btn-secondary:hover {
    background: var(--accent);
    color: white;
}

/* HTMX loading indicator */
.htmx-indicator {
    display: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-left: 1rem;
}

.htmx-request .htmx-indicator {
    display: inline;
}

/* ===== Results ===== */
.result-area {
    position: sticky;
    top: 2rem;
}

.result-placeholder {
    background: var(--bg-card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-muted);
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.power-headline {
    text-align: center;
    margin-bottom: 0.25rem;
}

.power-value {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--accent-hover);
    line-height: 1;
}

.power-unit {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-left: 0.3rem;
}

.power-wpkg {
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.result-summary {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.7;
}

/* Power breakdown bar */
.power-breakdown {
    margin-bottom: 1.5rem;
}

.power-breakdown h3,
.result-details h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.breakdown-bar {
    display: flex;
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.bar-gravity { background: var(--gravity); }
.bar-rolling { background: var(--rolling); }
.bar-aero { background: var(--aero); }
.bar-drive { background: var(--drive); }

.breakdown-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot-gravity { background: var(--gravity); }
.dot-rolling { background: var(--rolling); }
.dot-aero { background: var(--aero); }
.dot-drive { background: var(--drive); }

/* Details table */
.details-table {
    width: 100%;
    font-size: 0.9rem;
}

.details-table tr {
    border-bottom: 1px solid var(--border);
}

.details-table td {
    padding: 0.5rem 0;
}

.details-table td:last-child {
    text-align: right;
    font-weight: 600;
}

/* Error message */
.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 1rem;
    color: var(--error);
}

/* Coming soon placeholder */
.coming-soon {
    background: var(--bg-card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-muted);
}

.coming-soon a {
    color: var(--accent-hover);
}

/* ===== GPX-specific ===== */
.gpx-grid {
    grid-template-columns: 1fr 1.5fr;
}

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

.file-input {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
}

.file-input::file-selector-button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.4rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 0.75rem;
}

.track-name {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* Chart */
.chart-container {
    margin-bottom: 1.5rem;
}

.chart-container h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.chart-container canvas {
    width: 100% !important;
    max-height: 300px;
}

/* Segment table */
.segment-details {
    margin-top: 1rem;
}

.segment-details summary {
    cursor: pointer;
    list-style: none;
    color: var(--text-muted);
}

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

.segment-details summary h3::before {
    content: '+ ';
    color: var(--accent);
}

.segment-details[open] summary h3::before {
    content: '- ';
}

.segment-table-wrapper {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 0.75rem;
}

.segment-table {
    width: 100%;
    font-size: 0.8rem;
    border-collapse: collapse;
}

.segment-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    text-align: left;
    padding: 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.segment-table td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* Gradient color coding in segment table */
.grade-easy { color: #22c55e; }
.grade-moderate { color: #eab308; }
.grade-hard { color: #f97316; }
.grade-very-hard { color: #ef4444; }
.grade-extreme { color: #991b1b; }

/* ===== Mode Toggle ===== */
.mode-toggle {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.mode-option {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.mode-option:has(input:checked) {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

.mode-option input[type="radio"] {
    display: none;
}

.mode-label {
    font-weight: 600;
    font-size: 0.95rem;
}

.mode-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.calc-input {
    margin-top: 0.5rem;
}

/* ===== Wind Forecast ===== */
.wind-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    cursor: pointer;
}

.wind-checkbox input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

.wind-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

.wind-options {
    margin-top: 0.5rem;
}

.wind-datetime-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    color-scheme: dark;
}

.wind-datetime-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Wind comparison cards */
.wind-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

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

.wind-card {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}

.wind-card-highlight {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.05);
}

.wind-card-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.wind-card-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--accent-hover);
    line-height: 1.1;
}

.wind-card-unit {
    font-size: 1rem;
    color: var(--text-muted);
    margin-left: 0.2rem;
}

.wind-card-detail {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.wind-card-wind {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.wind-card-delta {
    font-size: 0.9rem;
    font-weight: 600;
    margin-top: 0.4rem;
}

.wind-hurts {
    color: var(--error);
}

.wind-helps {
    color: var(--rolling);
}

/* YR attribution */
.yr-attribution {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.yr-attribution a {
    color: var(--accent-hover);
    text-decoration: none;
}

.yr-attribution a:hover {
    text-decoration: underline;
}

/* ===== Optimal Time Table ===== */
.optimal-table-wrapper {
    max-height: 600px;
    overflow-y: auto;
    margin-top: 1rem;
}

.optimal-table {
    width: 100%;
    font-size: 0.85rem;
    border-collapse: collapse;
}

.optimal-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    padding: 0.5rem;
    text-align: left;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.optimal-table td {
    padding: 0.45rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.optimal-table .rank-col {
    width: 2rem;
    text-align: center;
    color: var(--text-muted);
}

.optimal-best {
    background: rgba(99, 102, 241, 0.08);
}

.optimal-best td {
    font-weight: 600;
}

.mono {
    font-variant-numeric: tabular-nums;
}
