:root {
    --bg-paper: #f2f2ee;
    --ink: #111111;
    --line: rgba(17, 17, 17, 0.15);
    --accent: #c42900;
    --success: #166b2e;
    --pending: #555555;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-paper);
    color: var(--ink);
    font-family: 'Space Mono', monospace;
    width: 100%;
}

/* --- LAYOUT --- */
.page-wrapper {
    max-width: 1000px;
    margin: 0 auto;
    padding: 4rem 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- HEADER --- */
header {
    margin-bottom: 4rem;
    border-bottom: 2px solid var(--ink);
    padding-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

h1 {
    font-family: 'Inter', sans-serif;
    font-size: 3rem;
    letter-spacing: -0.03em;
    margin: 0;
    line-height: 1;
}

.meta {
    text-align: right;
    font-size: 0.8rem;
    opacity: 0.7;
}

/* --- DATA SECTIONS --- */
.data-section { 
    margin-bottom: 2rem; 
}

/* --- STATS TOGGLE BUTTONS --- */
.stats-toggle {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.period-toggle {
    padding-bottom: 25px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 25px;
}

.stats-btn {
    padding: 10px 16px;
    font-family: 'Space Mono', monospace;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1px;
    background: transparent;
    border: 1px solid transparent;
    color: rgba(17, 17, 17, 0.6);
    cursor: pointer;
    transition: all 0.2s;
}

.stats-btn:hover {
    color: rgba(17, 17, 17, 0.8);
    border-color: rgba(17, 17, 17, 0.3);
}

.stats-btn.active {
    background: var(--ink);
    color: var(--bg-paper);
    border-color: var(--ink);
}

/* --- SINGLE SPORT STATS DISPLAY --- */
.stats-display-single {
    margin-bottom: 20px;
}

.stats-grid-single {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.stat-item-large {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-value-large {
    font-size: 2rem;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    letter-spacing: -0.02em;
    line-height: 1;
}

.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.7;
}

.strava-link {
    display: inline-block;
    color: #c43c02;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 700;
    transition: opacity 0.2s;
}

.strava-link:hover {
    opacity: 0.7;
}

/* --- SPORT INFO (inside accordions) --- */
.sport-info {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 15px 0 20px 0;
    margin-bottom: 15px;
    border-bottom: 1px dashed var(--line);
}

.sport-info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sport-info-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.7;
}

.sport-info-value {
    font-size: 0.85rem;
    font-weight: 700;
}

.status-active {
    color: var(--success);
}

.status-inactive {
    color: var(--pending);
}

.status-failed {
    color: var(--accent);
}

h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
    padding-bottom: 12px;
    margin-bottom: 20px;
    letter-spacing: 2px;
    font-weight: 700;
}

/* --- ACCORDION --- */
.accordion {
    margin-bottom: 1px;
    background: var(--bg-paper);
}

.accordion-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0;
    border: none;
    border-bottom: 1px solid var(--ink);
    background: transparent;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
    color: var(--ink);
    transition: all 0.3s ease;
}

.accordion-header:hover {
    background: rgba(0,0,0,0.02);
    padding-left: 10px;
}

.accordion-title {
    flex: 1;
    text-align: left;
}

.accordion-meta {
    font-weight: 400;
    opacity: 0.7;
    font-size: 0.75rem;
    margin-right: 20px;
    text-transform: lowercase;
    letter-spacing: 0;
}

.accordion-icon {
    width: 20px;
    height: 20px;
    position: relative;
    flex-shrink: 0;
}

.accordion-icon::before,
.accordion-icon::after {
    content: '';
    position: absolute;
    background: var(--ink);
    transition: transform 0.3s ease;
}

.accordion-icon::before {
    width: 100%;
    height: 2px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.accordion-icon::after {
    width: 2px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* Rotate icon when expanded */
.accordion-header[aria-expanded="true"] .accordion-icon::after {
    transform: translateX(-50%) rotate(90deg);
}

.accordion-header[aria-expanded="true"] .accordion-icon::before {
    transform: translateY(-50%) rotate(180deg);
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
    padding: 0;
}

.accordion-header[aria-expanded="true"] + .accordion-content {
    padding: 20px 0 30px 0;
}

/* --- METRICS GRID --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
}

.metric-card {
    background: var(--bg-paper);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.metric-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.7;
}

.metric-card strong {
    font-size: 0.9rem;
}

/* --- TABLE ROWS (CSS Grid for precise columns) --- */
.log-row {
    display: grid;
    grid-template-columns: 2.5fr 1fr 1fr 1fr 1fr;
    gap: 15px;
    align-items: baseline;
    padding: 15px 0;
    border-bottom: 1px solid var(--line);
    font-size: 0.85rem;
    transition: background 0.2s;
}

.log-row:hover:not(.log-header-row) { 
    background: rgba(0,0,0,0.03); 
}

/* Header row */
.log-header-row {
    font-weight: 700;
    opacity: 0.7;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--ink);
}

/* Column classes for semantic styling */
.col-event {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.row-meta {
    font-size: 0.75rem;
    opacity: 0.7;
}

.col-link a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.8rem;
}

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

/* Status indicators */
.status-dq {
    color: var(--accent);
    font-weight: 700;
}

.status-pending {
    opacity: 0.7;
    font-style: italic;
}

.status-active {
    color: var(--success);
    font-size: 0.75rem;
}

/* --- TRAINING GRID --- */
.training-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
}

.training-day {
    background: var(--bg-paper);
    padding: 20px 15px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.day-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.day-type {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* --- GEAR SECTION --- */
.gear-subsection {
    margin-top: 30px;
    padding-top: 25px;
    border-top: 1px dashed var(--line);
}

.gear-subsection h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0 0 20px 0;
    opacity: 0.7;
    font-weight: 700;
}

/* --- GEAR LIST --- */
.gear-list {
    display: flex;
    flex-direction: column;
}

.gear-list-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 0.85rem;
}

.gear-list-item:last-child {
    border-bottom: none;
}

.gear-name {
    font-weight: 700;
}

.gear-type {
    opacity: 0.7;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.gear-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.gear-mileage {
    font-size: 0.75rem;
    font-weight: 700;
    opacity: 0.9;
}

/* --- GOALS LIST --- */
.goals-list {
    display: flex;
    flex-direction: column;
}

.goal-item {
    display: grid;
    grid-template-columns: 120px 1fr 150px;
    gap: 20px;
    padding: 15px 0;
    border-bottom: 1px solid var(--line);
    align-items: center;
}

.goal-target {
    font-weight: 700;
    font-size: 1.1rem;
}

.goal-event {
    opacity: 0.7;
}

.goal-status {
    text-align: right;
    font-size: 0.8rem;
}

/* --- BACK LINK --- */
.back-link {
    position: fixed;
    top: 2rem; 
    left: 2rem;
    text-decoration: none;
    color: var(--ink);
    font-weight: 700;
    border: 1px solid var(--ink);
    padding: 10px 20px;
    background: var(--bg-paper);
    z-index: 100;
    transition: all 0.3s;
    font-size: 0.85rem;
}

.back-link:hover { 
    background: var(--ink); 
    color: var(--bg-paper); 
}

/* --- MOBILE --- */
@media (max-width: 900px) {
    .metrics-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .gear-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .training-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .training-day:nth-child(n+5) {
        border-top: none;
    }
}

@media (max-width: 700px) {
    h1 { font-size: 2rem; }
    
    .page-wrapper {
        padding: 4rem 1.5rem;
        padding-top: 5rem;
    }
    
    .back-link {
        top: 1rem;
        left: 1rem;
        padding: 8px 15px;
        font-size: 0.75rem;
    }
    
    .accordion-header {
        padding: 15px 0;
        font-size: 0.75rem;
    }
    
    .accordion-meta {
        display: none;
    }
    
    /* Stats toggle mobile */
    .stats-toggle {
        gap: 6px;
    }
    
    .stats-btn {
        padding: 8px 12px;
        font-size: 0.6rem;
    }
    
    .stats-grid-single {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
    
    .stat-value-large {
        font-size: 1.5rem;
    }
    
    /* Stack table rows on mobile */
    .log-row {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 20px 0;
    }
    
    .log-header-row { 
        display: none; 
    }
    
    .col-event {
        margin-bottom: 5px;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .gear-list-item {
        flex-direction: column;
        gap: 4px;
        align-items: flex-start;
    }
    
    .training-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .goal-item {
        grid-template-columns: 1fr;
        gap: 5px;
    }
    
    .goal-status {
        text-align: left;
    }
}