/* Apple-Style Design System for Strava Analytics */
:root {
    /* Color Palette - Neutral & Premium */
    --bg-app: #F5F5F7;
    --bg-card: #FFFFFF;
    --bg-secondary: #F9F9F9;
    --bg-tertiary: #F2F2F7;
    --bg-sidebar: rgba(245, 245, 247, 0.8);
    /* Translucent */

    /* Text */
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --text-tertiary: #B0B0B5;

    /* Separators */
    --border-light: rgba(0, 0, 0, 0.05);
    --border-medium: rgba(60, 60, 67, 0.12);
    /* Apple standard separator */

    /* Accents */
    --accent-blue: #007AFF;
    /* Apple Blue */
    --accent-orange: #FF5F2E;
    /* Strava-ish but softer */
    --accent-green: #34C759;
    /* Success */
    --accent-red: #ea4545;
    /* Error */
    --accent-yellow: #FF9500;
    /* Warning */

    /* Semantic Aliases (for template compatibility) */
    --primary: #007AFF;
    --danger: #FF3B30;
    --warning: #FF9500;
    --success: #34C759;

    /* Status Colors */
    --status-connected: #34C759;
    --status-warning: #FF9500;
    --status-error: #FF3B30;
    --status-neutral: #E5E5EA;

    /* Dimensions */
    --sidebar-width: 260px;
    --header-height: 50px;
    --radius-s: 8px;
    --radius-m: 12px;
    --radius-l: 16px;
    /* Standard card radius */
    --radius-xl: 20px;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    /* Standard padding */
    --space-4: 24px;
    --space-5: 32px;

    /* Shadows - Ultra subtle */
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-float: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* --- Reset & Typography --- */
* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    /* Standard text size */
    line-height: 1.4;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

a {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

h1,
h2,
h3,
h4,
h5 {
    margin: 0;
    font-weight: 600;
    color: var(--text-primary);
}

/* Typography Scale */
.text-large-title {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.text-title-1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.text-title-2 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* Card Headers */
.text-title-3 {
    font-size: 20px;
    font-weight: 600;
}

.text-headline {
    font-size: 17px;
    font-weight: 600;
}

.text-body {
    font-size: 17px;
    font-weight: 400;
}

.text-callout {
    font-size: 16px;
    font-weight: 400;
}

.text-subhead {
    font-size: 15px;
    font-weight: 500;
}

.text-footnote {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
}

.text-caption {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
}

.text-caption-2 {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Layout Shell --- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Sidebar (Desktop) */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-app);
    /* Use app bg for seamless look, or white */
    border-right: 1px solid var(--border-medium);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    padding: var(--space-4) var(--space-3);
    overflow-y: auto;
    z-index: 100;
}

.logo-area {
    margin-bottom: var(--space-5);
    padding-left: var(--space-2);
}

.logo-text {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 12px;
    margin-top: 12px;
}

.nav-section-title:first-child {
    margin-top: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-m);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    transition: background 0.15s ease;
}

.nav-item:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

.nav-item.active {
    background-color: rgba(0, 0, 0, 0.05);
    /* Soft gray active state instead of blue */
    color: var(--text-primary);
    font-weight: 600;
}

.nav-icon {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-item.active .nav-icon {
    color: var(--accent-blue);
}

.user-snippet {
    display: flex;
    align-items: center;
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-medium);
    margin-top: auto;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e1e1e1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

/* Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: var(--space-4) var(--space-5);
    max-width: 1400px;
    width: 100%;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
    height: 40px;
}

/* Mobile Bottom Nav (Hidden on Desktop) */
.mobile-tab-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 83px;
    /* iOS standard is roughly 83px including safe area */
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--border-medium);
    padding-bottom: 20px;
    /* Safe area padding */
    z-index: 1000;
    justify-content: space-around;
    align-items: center;
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    color: #999999;
    gap: 4px;
    width: 60px;
}

.tab-item.active {
    color: var(--accent-blue);
}

.tab-icon {
    font-size: 22px;
    margin-bottom: 1px;
}

/* --- Components --- */

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-l);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-card);
    margin-bottom: var(--space-4);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-light);
}

.card-title {
    font-size: 17px;
    font-weight: 600;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 20px;
    /* Pill shape */
    font-size: 14px;
    font-weight: 500;
    border: none;
    transition: all 0.2s;
    cursor: pointer;
}

.btn-primary {
    background-color: var(--text-primary);
    /* Apple often uses black for primary actions or brand color */
    color: white;
}

.btn-primary:hover {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-secondary {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.btn-text {
    background: transparent;
    color: var(--accent-blue);
    padding: 0;
}

.btn-text:hover {
    opacity: 0.7;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    color: var(--accent-blue);
    font-size: 17px;
    font-weight: 400;
    gap: 4px;
    margin-bottom: var(--space-2);
}

.back-btn:hover {
    opacity: 0.8;
}

/* Grid System */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-3);
}

.grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--space-3);
}

/* Responsive Grid - 4 columns on medium+ screens */
@media (min-width: 768px) {
    .grid-md-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}


/* Tables (Apple Settings Style) */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-medium);
    padding: 10px 0;
}

.data-table td {
    padding: 14px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 15px;
    color: var(--text-primary);
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* Forms */
input[type="text"],
input[type="number"],
input[type="date"],
select {
    background: var(--bg-tertiary);
    border: none;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 16px;
    /* Avoid scale zoom on iOS */
    width: 100%;
    color: var(--text-primary);
}

input:focus {
    outline: 2px solid var(--accent-blue);
}

/* Mobile Adaptations */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    /* Hide sidebar on mobile */
    .mobile-tab-bar {
        display: flex;
    }

    /* Show bottom bar */
    .main-content {
        margin-left: 0;
        padding: var(--space-3);
        padding-bottom: 100px;
    }

    /* Reset margin and add bottom padding for tab bar */

    h1,
    h2,
    h3,
    h4,
    h5 {
        margin: 0;
        font-weight: 600;
        color: var(--text-primary);
    }

    .text-large-title {
        font-size: 28px;
    }

    .grid-2,
    .grid-3,
    .grid-4,
    .grid-5 {
        grid-template-columns: 1fr;
        /* Stack grids on mobile */
    }

    .hide-on-mobile {
        display: none !important;
    }
}

/* Utilities */
.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.w-full {
    width: 100%;
}

.mb-1 {
    margin-bottom: var(--space-1);
}

.mb-2 {
    margin-bottom: var(--space-2);
}

.mb-3 {
    margin-bottom: var(--space-3);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

.mb-5 {
    margin-bottom: var(--space-5);
}

.mt-1 {
    margin-top: var(--space-1);
}

.mt-2 {
    margin-top: var(--space-2);
}

.mt-3 {
    margin-top: var(--space-3);
}

.mt-4 {
    margin-top: var(--space-4);
}

.mt-5 {
    margin-top: var(--space-5);
}

/* Padding Utilities */
.p-2 {
    padding: var(--space-2);
}

.p-3 {
    padding: var(--space-3);
}

.p-4 {
    padding: var(--space-4);
}

.p-5 {
    padding: var(--space-5);
}

/* Gap Utilities */
.gap-1 {
    gap: var(--space-1);
}

.gap-2 {
    gap: var(--space-2);
}

.gap-3 {
    gap: var(--space-3);
}

.gap-4 {
    gap: var(--space-4);
}

.gap-5 {
    gap: var(--space-5);
}

/* ============================================
   COMPONENT CLASSES
   ============================================ */

/* Status Indicator Dot */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--status-neutral);
    flex-shrink: 0;
}

.status-dot--connected {
    background: var(--status-connected);
}

.status-dot--warning {
    background: var(--status-warning);
}

.status-dot--error {
    background: var(--status-error);
}

/* Status Row (dot + text combo) */
.status-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Form Input Styling */
.form-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-s);
    border: 1px solid var(--border-medium);
    background: #f9f9f9;
    font-size: 16px;
    font-family: inherit;
    color: var(--text-primary);
    transition: border-color 0.2s, outline 0.2s;
}

.form-input:focus {
    outline: 2px solid var(--accent-blue);
    border-color: var(--accent-blue);
}

.form-input--with-action {
    flex: 1;
}

/* Form Group */
.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    margin-bottom: var(--space-1);
}

/* Input with inline button */
.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Badge / Pill */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.badge--primary {
    background: rgba(0, 122, 255, 0.1);
    color: var(--accent-blue);
}

.badge--success {
    background: rgba(52, 199, 89, 0.1);
    color: var(--success);
}

.badge--warning {
    background: rgba(255, 149, 0, 0.1);
    color: var(--warning);
}

.badge--danger {
    background: rgba(255, 59, 48, 0.1);
    color: var(--danger);
}

.badge--neutral {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-secondary);
}

/* Card Variants */
.card--flush {
    padding: 0;
}

.card-padding-sm {
    padding: var(--space-3);
}

.card-padding-md {
    padding: 20px;
}

.card-padding-lg {
    padding: var(--space-4);
}

.card-padding-xl {
    padding: 30px;
}

/* Sidebar Layout */
.sidebar-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Divider */
.divider {
    height: 1px;
    background: var(--border-medium);
    margin: var(--space-4) 0;
}

/* Flex utilities */
.flex-start {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.flex-end {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* Auth Page Layout */
.auth-body {
    background: var(--bg-app);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    text-align: center;
}

/* Alert / Error Messages */
.alert {
    padding: 10px 12px;
    border-radius: var(--radius-s);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 20px;
}

.alert--error {
    background: rgba(255, 59, 48, 0.1);
    color: var(--danger);
}

.alert--success {
    background: rgba(52, 199, 89, 0.1);
    color: var(--success);
}

.alert--warning {
    background: rgba(255, 149, 0, 0.1);
    color: var(--warning);
}

/* Form Input Auth Variant */
.form-input--auth {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 10px;
    font-size: 16px;
}

/* Icon Container */
.icon-box {
    width: 50px;
    height: 50px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-box--lg {
    width: 80px;
    height: 80px;
    font-size: 32px;
}

/* Empty State */
.empty-state {
    padding: 60px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.empty-state__icon {
    font-size: 40px;
    color: var(--text-tertiary);
    margin-bottom: 20px;
}

/* Zone Color Classes */
.zone-recovery {
    color: #34C759;
}

.zone-aerobic {
    color: #007AFF;
}

.zone-tempo {
    color: #FF9500;
}

.zone-threshold {
    color: #FF3B30;
}

.zone-interval {
    color: #AF52DE;
}

/* Text utilities */
.text-left {
    text-align: left;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

/* Link styling */
.link {
    color: var(--accent-blue);
    font-weight: 600;
    text-decoration: none;
}

.link:hover {
    text-decoration: underline;
}

.link--danger {
    color: var(--danger);
}

/* Button inside input row */
.btn--icon {
    padding: 10px 12px;
}

/* Checkbox styling */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 30px;
}

.checkbox {
    width: 18px;
    height: 18px;
}

/* Modal Overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-overlay--active {
    display: flex;
}

.modal-card {
    width: 100%;
    max-width: 500px;
    margin: 20px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-card--sm {
    max-width: 400px;
}

.modal-card--lg {
    max-width: 600px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

/* Hero Gradient Cards */
.hero-gradient {
    background: linear-gradient(135deg, var(--accent-blue) 0%, #0055D4 100%);
    color: white;
    padding: 30px;
    position: relative;
    overflow: hidden;
}

.hero-gradient--orange {
    background: linear-gradient(135deg, #FF5F2E 0%, #FF3B30 100%);
}

.hero-gradient--green {
    background: linear-gradient(135deg, #34C759 0%, #30B050 100%);
}

.hero-gradient--purple {
    background: linear-gradient(135deg, #AF52DE 0%, #8E44AD 100%);
}

/* Hero decorative circles */
.hero-circle {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
}

.hero-circle--1 {
    top: -20px;
    right: -20px;
    width: 150px;
    height: 150px;
}

.hero-circle--2 {
    bottom: -40px;
    left: -20px;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.05);
}

.hero-content {
    position: relative;
    z-index: 1;
}

/* Pill / Tag Styles */
.pill {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    display: inline-block;
}

.pill--dark {
    background: rgba(0, 0, 0, 0.2);
    color: white;
}

.pill--light {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.pill--rest {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.pill--workout {
    background: rgba(0, 122, 255, 0.1);
    color: var(--accent-blue);
}

/* Legend Items */
.legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 20px;
}

.legend-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.legend-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.legend-dot--z1 {
    background: #34C759;
}

.legend-dot--z2 {
    background: #007AFF;
}

.legend-dot--z3 {
    background: #FF9500;
}

.legend-dot--z4 {
    background: #FF5F2E;
}

.legend-dot--z5 {
    background: #FF3B30;
}

/* Chart Container */
.chart-container {
    height: 300px;
    position: relative;
}

.chart-container--sm {
    height: 200px;
}

.chart-container--md {
    height: 250px;
}

.chart-container--lg {
    height: 400px;
}

/* Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #E5E5EA;
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Log Box (for progress modals) */
.log-box {
    height: 150px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow-y: auto;
    text-align: left;
    padding: 15px;
    font-family: monospace;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Stat Details (metrics below stat) */
.stat-meta {
    margin-top: 4px;
}

/* Flex Row with Gap */
.flex-row {
    display: flex;
    align-items: center;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

/* Padding Y-axis Utilities */
.py-2 {
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
}

.py-3 {
    padding-top: var(--space-3);
    padding-bottom: var(--space-3);
}

/* Display utilities */
.d-none {
    display: none;
}

.d-flex {
    display: flex;
}

.d-block {
    display: block;
}

.d-inline-block {
    display: inline-block;
}

/* Position utilities */
.pos-relative {
    position: relative;
}

.pos-absolute {
    position: absolute;
}

/* Width Utilities */
.max-w-sm {
    max-width: 450px;
}

.max-w-md {
    max-width: 600px;
}

.max-w-lg {
    max-width: 800px;
}

/* Margin auto utilities */
.mx-auto {
    margin-left: auto;
    margin-right: auto;
}

/* Form Textarea */
.form-textarea {
    width: 100%;
    border: none;
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 10px;
    font-family: inherit;
    resize: vertical;
}

/* Workout Card Border States */
.workout-completed {
    border: 1px solid var(--success);
}

/* Icon with color */
.icon-secondary {
    color: var(--text-secondary);
}

/* Tooltips */
.tooltip-container {
    position: relative;
    cursor: help;
}

.card-tooltip {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-m);
    padding: 12px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    box-shadow: var(--shadow-float);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 8px;
    pointer-events: none;
    text-transform: none;
    letter-spacing: normal;
}

.tooltip-container:hover .card-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.tooltip-container .ph-info {
    opacity: 0.4;
    font-size: 14px;
    transition: opacity 0.2s;
}

.tooltip-container:hover .ph-info {
    opacity: 1;
    color: var(--accent-blue);
}