:root {
    --bg: #ffffff;
    --surface: #f5f5f7;
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --border: #d2d2d7;
    --primary: #007aff;
    --primary-hover: #0056b3;
    --danger: #ff3b30;
    --success: #34c759;
    --warning: #ff9500;
    --selected: #007aff;
    --selected-text: #ffffff;
    --green-bg: #d4edda;
    --yellow-bg: #fff3cd;
    --red-bg: #f8d7da;
    --green-text: #155724;
    --yellow-text: #856404;
    --red-text: #721c24;
    --tab-bg: #e5e5ea;
    --modal-overlay: rgba(0,0,0,0.4);
}

[data-theme="dark"] {
    --bg: #1c1c1e;
    --surface: #2c2c2e;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --border: #48484a;
    --tab-bg: #2c2c2e;
    --green-bg: #1b3a26;
    --yellow-bg: #3a3019;
    --red-bg: #3a1b1b;
    --green-text: #34c759;
    --yellow-text: #ff9500;
    --red-text: #ff453a;
    --modal-overlay: rgba(0,0,0,0.6);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Onboarding */
.onboarding-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    gap: 16px;
}

.onboarding-container h1 {
    font-size: 2rem;
    font-weight: 700;
}

.onboarding-container p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.onboarding-container h2 {
    margin-top: 32px;
    font-size: 1.3rem;
}

.sport-buttons {
    display: flex;
    gap: 16px;
    margin-top: 12px;
}

.sport-btn {
    padding: 16px 40px;
    font-size: 1.1rem;
    border: 2px solid var(--primary);
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.sport-btn:hover {
    background: var(--primary);
    color: var(--selected-text);
}

/* Tab Bar */
.tab-bar {
    display: flex;
    background: var(--tab-bg);
    border-radius: 10px;
    padding: 3px;
    margin: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.tab.active {
    background: var(--bg);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.tab-content {
    display: none;
    padding-bottom: 24px;
}

.tab-content.active {
    display: block;
}

/* Swipe navigation — hidden on desktop */
.swipe-dots {
    display: none;
}

.swipe-label {
    display: none;
}

.swipe-viewport {
    position: relative;
}

.swipe-track {
    position: relative;
}

@media (max-width: 600px) {
    .tab-bar { display: none; }

    .swipe-viewport {
        overflow: hidden;
        width: 100%;
    }

    .swipe-track {
        display: -webkit-flex;
        display: flex;
        width: 300%;
        -webkit-transition: -webkit-transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }

    .swipe-track.swiping {
        -webkit-transition: none;
        transition: none;
    }

    .swipe-track > .tab-content {
        display: block;
        width: calc(100vw - 16px);
        flex-shrink: 0;
        padding-bottom: 24px;
        min-height: 50vh;
        overflow-y: auto;
    }

    .swipe-dots {
        display: flex;
        justify-content: center;
        gap: 8px;
        padding: 8px 0 4px;
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--bg);
    }

    .swipe-dots .dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--border);
        transition: all 0.3s;
        cursor: pointer;
    }

    .swipe-dots .dot.active {
        background: var(--primary);
        transform: scale(1.3);
    }

    .swipe-label {
        display: block;
        text-align: center;
        font-size: 0.7rem;
        font-weight: 600;
        color: var(--primary);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        padding-bottom: 6px;
    }

    #app { padding: 0 8px; }
    .selection-grid { gap: 5px; }
    .sel-btn { padding: 8px 10px; font-size: 0.82rem; min-width: 56px; }
    .section h3 { font-size: 0.8rem; }
    .submit-btn { padding: 12px; font-size: 0.9rem; }
    .settings-section { padding: 12px; }
    .action-btn { font-size: 0.8rem; padding: 7px 12px; }
    .modal-content { min-width: unset; width: 92vw; padding: 16px; }
}

/* Selection Grid */
.section {
    margin-bottom: 16px;
}

.section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.hint {
    font-weight: 400;
    text-transform: none;
    font-size: 0.8rem;
}

.selection-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.sel-btn {
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
    min-width: 70px;
    text-align: center;
}

.sel-btn:hover {
    border-color: var(--primary);
}

.sel-btn.selected {
    background: var(--selected);
    color: var(--selected-text);
    border-color: var(--selected);
}

/* Track Layout */
.track-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

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

.submit-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.submit-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.submit-btn:not(:disabled):hover {
    background: var(--primary-hover);
}

.undo-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 0.85rem;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.2s;
}

.undo-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* Live Results */
.live-results {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

.live-results h3 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.live-result-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 4px;
    font-size: 0.88rem;
}

.live-result-row .label {
    font-weight: 600;
}

.live-result-row .stat {
    text-align: center;
    min-width: 50px;
}

.live-result-row .stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.live-result-row .stat-value {
    font-weight: 700;
    font-size: 0.95rem;
}

.perf-green {
    background: var(--green-bg);
    color: var(--green-text);
}

.perf-yellow {
    background: var(--yellow-bg);
    color: var(--yellow-text);
}

.perf-red {
    background: var(--red-bg);
    color: var(--red-text);
}

/* Results Tab */
.results-filters {
    background: var(--surface);
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
}

.filter-row {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.filter-row:last-child {
    margin-bottom: 0;
}

.filter-row label {
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-row select, .filter-row input[type="date"] {
    padding: 6px 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
}

.date-toggle {
    cursor: pointer;
}

.results-table {
    overflow-x: auto;
}

.results-table-el {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 4px;
    font-size: 0.85rem;
}

.results-table-el thead th {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    padding: 8px 10px;
    text-align: left;
    white-space: nowrap;
}

.results-table-el thead th.stat-cell {
    text-align: center;
}

.results-table-el tbody td {
    padding: 10px 10px;
}

.results-table-el tbody td.stat-cell {
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
}

.results-table-el tbody tr {
    border-radius: 10px;
}

.results-table-el tbody tr td:first-child {
    border-radius: 10px 0 0 10px;
}

.results-table-el tbody tr td:last-child {
    border-radius: 0 10px 10px 0;
}

@media (max-width: 768px) {
    .results-table-el {
        font-size: 0.72rem;
    }
    .results-table-el thead th {
        font-size: 0.68rem;
        padding: 6px 4px;
    }
    .results-table-el tbody td {
        padding: 8px 4px;
    }
    .results-table-el .hide-mobile {
        display: none;
    }
}

/* Settings */
.settings-sections {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
}

.settings-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.logo-upload {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 10px 0;
}

.section-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 8px;
}

.logo-preview {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    border: 2px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.logo-preview.has-logo {
    border-style: solid;
}

.logo-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 8px;
}

.settings-item span {
    font-weight: 500;
}

.settings-item-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s;
}

.icon-btn:hover {
    color: var(--primary);
    background: var(--surface);
}

.icon-btn.danger:hover {
    color: var(--danger);
}

.add-row {
    display: flex;
    gap: 8px;
}

.add-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
}

.action-btn {
    padding: 8px 16px;
    border: 1.5px solid var(--primary);
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.action-btn:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.action-btn.danger {
    background: var(--danger);
    border-color: var(--danger);
}

.action-btn.danger:hover {
    opacity: 0.85;
}

.data-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    font-weight: 500;
}

.toggle-label input[type="checkbox"] {
    width: 44px;
    height: 24px;
    appearance: none;
    -webkit-appearance: none;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-label input[type="checkbox"]::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}

.toggle-label input[type="checkbox"]:checked {
    background: var(--primary);
}

.toggle-label input[type="checkbox"]:checked::after {
    transform: translateX(20px);
}

.help-content {
    margin-top: 12px;
}

.help-block {
    background: var(--bg);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 10px;
}

.help-block h4 {
    margin: 0 0 6px;
    font-size: 0.95rem;
    color: var(--text);
}

.help-block p {
    margin: 0 0 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.help-block ul {
    margin: 0;
    padding-left: 18px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.help-block li { margin-bottom: 2px; }

.version-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: var(--bg);
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 1000;
    transition: transform 0.3s ease;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    background: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-content {
    background: var(--bg);
    padding: 24px;
    border-radius: 14px;
    min-width: 300px;
    max-width: 90vw;
}

.modal-content h3 {
    margin-bottom: 12px;
}

.modal-content input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.95rem;
    margin-bottom: 16px;
}

.modal-content p {
    margin-bottom: 16px;
    line-height: 1.4;
}

.modal-grid {
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 1rem;
    margin-top: 8px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
