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

/* ===== THEME VARIABLES ===== */
:root {
    --bg-sidebar: #12122a;
    --bg-panel: #1a1a2e;
    --bg-card: #16213e;
    --bg-input: #0f3460;
    --border: #2a2a4a;
    --border-light: rgba(255,255,255,0.05);
    --text-primary: #eee;
    --text-secondary: #aaa;
    --text-muted: #888;
    --text-dim: #666;
    --text-faint: #555;
    --text-darker: #444;
    --accent: #e94560;
    --accent-hover: #c73650;
    --accent-glow: rgba(233, 69, 96, 0.1);
    --blue: #3b82f6;
    --blue-hover: #1a4a8a;
    --blue-glow: rgba(59, 130, 246, 0.1);
    --green: #16c784;
    --dropzone-border: #444;
    --dropzone-text: #aaa;
    --dropzone-or: #555;
    --resizer-bg: #2a2a4a;
    --resizer-handle: #555;
    --elevation-bg: rgba(26, 26, 46, 0.92);
    --table-alt: rgba(255,255,255,0.03);
    --btn-hover: rgba(255, 255, 255, 0.06);
    --btn-hover-color: #bbb;
    --clear-border: #444;
    --clear-color: #888;
    --remove-color: #666;
}

body.light {
    --bg-sidebar: #e8e8ec;
    --bg-panel: #f5f5f7;
    --bg-card: #ffffff;
    --bg-input: #e0e7f0;
    --border: #d0d0d8;
    --border-light: rgba(0,0,0,0.06);
    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #777;
    --text-dim: #888;
    --text-faint: #999;
    --text-darker: #bbb;
    --accent-glow: rgba(233, 69, 96, 0.08);
    --blue-glow: rgba(59, 130, 246, 0.08);
    --dropzone-border: #bbb;
    --dropzone-text: #666;
    --dropzone-or: #aaa;
    --resizer-bg: #d0d0d8;
    --resizer-handle: #aaa;
    --elevation-bg: rgba(245, 245, 247, 0.95);
    --table-alt: rgba(0,0,0,0.03);
    --btn-hover: rgba(0, 0, 0, 0.06);
    --btn-hover-color: #444;
    --clear-border: #ccc;
    --clear-color: #777;
    --remove-color: #999;
}

body {
    display: flex;
    height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

/* ===== APP SIDEBAR ===== */
#app-sidebar {
    width: 52px;
    height: 100vh;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
}

.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 0 8px 0;
}

#sidebar-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
}

.sidebar-bottom {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0;
}

.sidebar-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.sidebar-btn:hover {
    background: var(--btn-hover);
    color: var(--btn-hover-color);
}

/* Theme toggle icons */
.theme-icon-light {
    display: none;
}

body.light .theme-icon-dark {
    display: none;
}

body.light .theme-icon-light {
    display: block;
}

/* ===== LEFT PANEL ===== */
#left-panel {
    width: 50%;
    height: 100vh;
    background: var(--bg-panel);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    position: relative;
    border-right: none;
}

/* ===== TAB BAR ===== */
#tab-bar {
    flex-shrink: 0;
    padding: 16px 24px 0 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#tab-bar-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
}

.tab {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 600;
    padding: 8px 16px 10px 16px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.2s, border-color 0.2s;
    white-space: nowrap;
}

.tab:hover:not(.disabled) {
    color: var(--text-secondary);
}

.tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}

.tab.disabled {
    color: var(--text-darker);
    cursor: default;
    position: relative;
}

/* ===== TAB CONTENT ===== */
.tab-content {
    display: none;
    flex-direction: column;
    gap: 16px;
}

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

.tab-placeholder {
    color: var(--text-faint);
    text-align: center;
    padding: 40px 0;
    font-size: 0.95rem;
}

#left-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ===== RESIZER HANDLE ===== */
#resizer {
    width: 6px;
    background: var(--resizer-bg);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background 0.15s;
    position: relative;
}

#resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 32px;
    border-radius: 2px;
    background: var(--resizer-handle);
    transition: background 0.15s, height 0.15s;
}

#resizer:hover {
    background: var(--accent);
}

#resizer:hover::after,
#resizer.dragging::after {
    background: var(--text-primary);
    height: 48px;
}

#resizer.dragging {
    background: var(--accent);
}

/* ===== RIGHT PANEL ===== */
#right-panel {
    flex: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

#map {
    flex: 1;
}

#map.segment-mode {
    cursor: crosshair !important;
}

#elevation-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 150px;
    min-height: 80px;
    max-height: 50vh;
    padding: 8px 12px;
    background: var(--elevation-bg);
    border-top: 2px solid var(--accent);
    z-index: 999;
    resize: vertical;
    overflow: hidden;
}

/* ===== UPLOAD SECTION ===== */
#upload-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#drop-zone {
    border: 2px dashed var(--dropzone-border);
    border-radius: 8px;
    padding: 20px 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color 0.2s, background 0.2s;
    color: var(--dropzone-text);
    font-size: 0.85rem;
}

#drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

#drop-zone.uploading {
    border-color: var(--blue);
    background: var(--blue-glow);
    color: var(--blue);
}

.drop-or {
    color: var(--dropzone-or);
    font-size: 0.75rem;
}

#file-label {
    display: inline-block;
    padding: 8px 16px;
    background: var(--accent);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.2s;
}

#file-label:hover {
    background: var(--accent-hover);
}

#upload-section input[type="file"] {
    display: none;
}

/* ===== DIVIDERS ===== */
hr.panel-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* ===== WORKOUTS ===== */
#workouts-section h2,
#segment-section h3 {
    margin-bottom: 10px;
}

#workouts-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.workout-card {
    background: var(--bg-card);
    border-radius: 6px;
    overflow: hidden;
}

.workout-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
}

.workout-card-header:hover {
    background: var(--accent-glow);
}

.workout-card-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.workout-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.workout-card-toggle {
    color: var(--text-secondary);
    font-size: 0.8rem;
    transition: transform 0.2s;
}

.workout-card-toggle.expanded {
    transform: rotate(180deg);
}

.workout-card-stats {
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-light);
}

.workout-card-stats.open {
    display: flex;
}

.workout-card-remove {
    background: none;
    border: none;
    color: var(--remove-color);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 4px;
    line-height: 1;
}

.workout-card-remove:hover {
    color: var(--accent);
}

.workout-card-eye {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    color: var(--text-faint);
    transition: color 0.2s;
}

.workout-card-eye:hover {
    color: var(--text-muted);
}

.workout-card-eye.active {
    color: var(--text-primary);
}

.workout-card-eye.active:hover {
    color: var(--text-primary);
}

.workout-card-eye.loading {
    animation: pulse 0.8s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.workout-card.disabled .workout-card-name {
    opacity: 0.4;
}

.workout-card.disabled .workout-card-stats {
    opacity: 0.4;
}

.stat {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.stat-value {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.85rem;
}

/* ===== SEGMENT ===== */
.segment-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

#segment-section {
    background: var(--bg-card);
    border-radius: 6px;
    padding: 12px;
}

#segment-section h3 {
    font-size: 0.95rem;
    color: var(--blue);
}

#segment-btn {
    padding: 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--blue);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

#segment-btn:hover {
    background: var(--blue-hover);
}

#segment-btn.active {
    background: var(--blue);
    border-color: var(--blue);
}

#clear-segment-btn {
    padding: 6px;
    background: transparent;
    color: var(--clear-color);
    border: 1px solid var(--clear-border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
}

#clear-segment-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

#segment-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

#segment-table th {
    color: var(--text-muted);
    font-weight: 500;
    text-align: right;
    padding: 4px 6px;
    border-bottom: 1px solid var(--border-light);
}

#segment-table th:first-child {
    text-align: left;
}

#segment-table td {
    text-align: right;
    padding: 5px 6px;
    color: var(--text-primary);
}

#segment-table td:first-child {
    text-align: left;
}

#segment-table tr:nth-child(even) td {
    background: var(--table-alt);
}

#segment-table .best {
    color: #16c784;
    font-weight: 700;
}

.segment-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.hidden {
    display: none !important;
}
