/* =====================================================
   CALENDAR TAB - Month/Week/Year Calendar Views
   Mobile-first responsive with centralized colors
   ===================================================== */

/* ─── Calendar Root ────────────────────────────── */
.cal-root {
    padding: var(--spacing-md);
}

@media (min-width: 768px) {
    .cal-root {
        padding: var(--spacing-lg);
    }
}

.cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.cal-controls-left {
    display: flex;
    gap: var(--spacing-md);
    align-items: center;
    flex-wrap: wrap;
}

.cal-view-btns {
    display: flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--color-bg-card);
}

.cal-view-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    border: none;
    border-right: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text-dark);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-weight: var(--font-weight-medium);
}

.cal-view-btn:last-child {
    border-right: none;
}

.cal-view-btn:hover {
    background: var(--color-bg-hover);
}

.cal-view-btn.active {
    background: var(--color-primary);
    color: white;
    font-weight: var(--font-weight-bold);
}

.cal-type-filter {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-card);
    color: var(--color-text-dark);
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.cal-type-filter:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(252, 76, 2, 0.1);
}

.cal-nav {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.cal-nav-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-base);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-card);
    color: var(--color-text-dark);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.cal-nav-btn:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-primary);
}

.cal-today-btn {
    font-size: var(--font-size-xs);
}

.cal-title {
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-lg);
    min-width: 200px;
    text-align: center;
}

/* ─── Streaks ──────────────────────────────── */
.cal-streak-cards {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    margin-bottom: var(--spacing-lg);
}

.cal-streak-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    text-align: center;
    min-width: 90px;
    flex: 1 1 100px;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-fast);
}

.cal-streak-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}

.cal-streak-num {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    line-height: 1.1;
    color: var(--color-primary);
}

.cal-streak-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: var(--spacing-sm);
    font-weight: var(--font-weight-semibold);
}

/* ─── Month Grid ───────────────────────────── */
.cal-month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    background: var(--color-border);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.cal-dow-header {
    background: var(--color-bg-hover);
    text-align: center;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-medium);
    padding: var(--spacing-md) 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cal-day {
    background: var(--color-bg-card);
    min-height: 90px;
    padding: var(--spacing-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.cal-day:hover {
    background: var(--color-bg-hover);
}

.cal-day-empty {
    background: #fafafa !important;
    cursor: default;
}

.cal-today {
    background: linear-gradient(135deg, #fff4ec 0%, #ffffff 65%) !important;
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.cal-future {
    opacity: 0.4;
    pointer-events: none;
}

.cal-day-num {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-medium);
    margin-bottom: var(--spacing-sm);
}

.cal-today .cal-day-num {
    color: var(--color-primary);
    font-weight: var(--font-weight-bold);
}

.cal-day-pills {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cal-pill {
    font-size: .65rem;
    padding: 1px 4px;
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.cal-pill-more {
    background: #ebebeb;
    color: #777;
    font-style: italic;
}

/* ─── Week Grid ────────────────────────────── */
.cal-week-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.cal-week-col {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    min-height: 220px;
}

.cal-week-col.cal-today {
    outline: 2px solid var(--strava-orange);
    outline-offset: -2px;
    background: #fff7f4;
}

.cal-week-col.cal-future {
    opacity: .4;
    pointer-events: none;
}

.cal-week-day-header {
    background: #f8f9fa;
    padding: .38rem .55rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: .1rem;
}

.cal-week-dow {
    font-weight: 700;
    font-size: .74rem;
    text-transform: uppercase;
    color: var(--text-medium);
}

.cal-week-date {
    font-size: .7rem;
    color: var(--text-light);
}

.cal-week-day-total {
    font-size: .68rem;
    color: var(--strava-orange);
    font-weight: 600;
    margin-top: .1rem;
}

.cal-week-acts {
    padding: .45rem .38rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.cal-week-activity {
    display: block;
    padding: .38rem .45rem;
    border-radius: 5px;
    text-decoration: none;
    color: inherit;
    font-size: .73rem;
    line-height: 1.4;
    transition: filter .1s;
}

.cal-week-activity:hover {
    filter: brightness(.9);
}

.cal-week-act-sport {
    font-weight: 600;
    font-size: .67rem;
    opacity: .7;
}

.cal-week-act-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.cal-week-act-stats {
    opacity: .6;
    font-size: .65rem;
}

.cal-week-rest {
    font-size: .72rem;
    color: var(--text-light);
    font-style: italic;
    padding: .3rem .15rem;
}

/* ─── Year Heatmap ────────────────────────── */
.cal-year-outer {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.cal-year-dow-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-top: 22px;
    flex-shrink: 0;
    align-items: flex-end;
}

.cal-year-dow {
    height: 13px;
    font-size: .59rem;
    color: var(--text-light);
    white-space: nowrap;
    padding-right: 3px;
    display: flex;
    align-items: center;
}

.cal-year-heatmap {
    overflow-x: auto;
    overflow-y: hidden;
}

.cal-year-weeks {
    display: flex;
    gap: 2px;
}

.cal-year-week {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cal-year-cell {
    width: 13px;
    height: 13px;
    border-radius: 2px;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform .1s;
}

.cal-year-cell:hover {
    transform: scale(1.45);
    z-index: 1;
    position: relative;
}

.cal-year-empty {
    background: #e8e8e8;
    cursor: default;
}

.cal-year-empty:hover {
    transform: none;
}

.cal-year-summary {
    display: flex;
    gap: 1.25rem;
    margin-top: .9rem;
    font-size: .84rem;
    color: var(--text-medium);
    flex-wrap: wrap;
}

.cal-year-summary span {
    font-weight: 600;
}

/* ─── Day Detail Panel ────────────────────── */
.cal-day-detail {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    margin-top: .7rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.cal-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .55rem 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid var(--border-color);
    font-size: .88rem;
}

.cal-detail-close {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: .45;
    padding: 0 .25rem;
}

.cal-detail-close:hover {
    opacity: 1;
}

.cal-detail-row {
    display: flex;
    align-items: baseline;
    gap: .7rem;
    padding: .5rem 1rem;
    border-bottom: 1px solid #f4f4f4;
    text-decoration: none;
    color: inherit;
    transition: background .1s;
}

.cal-detail-row:hover {
    background: #f9f9f9;
}

.cal-detail-row:last-child {
    border-bottom: none;
}

.cal-detail-sport {
    font-size: .73rem;
    opacity: .68;
    min-width: 85px;
}

.cal-detail-name {
    font-weight: 500;
    font-size: .84rem;
    flex: 1;
}

.cal-detail-stats {
    font-size: .76rem;
    color: var(--text-light);
    white-space: nowrap;
}

/* ─── Legend ───────────────────────────────── */
.cal-legend {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem .85rem;
    margin-top: .7rem;
    padding: .45rem;
    font-size: .73rem;
    color: var(--text-medium);
}

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

.cal-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ─── Heatmap Container ────────────────────── */
#cal-heatmap {
    margin-top: 1rem;
}

/* ─── Responsive ───────────────────────────── */
@media (max-width: 768px) {
    .cal-root {
        padding: 0.75rem;
    }

    .cal-header {
        gap: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .cal-view-btn {
        padding: 0.25rem 0.6rem;
        font-size: 0.75rem;
    }

    .cal-nav-btn {
        padding: 0.25rem 0.6rem;
        font-size: 0.9rem;
    }

    .cal-title {
        font-size: 0.95rem;
        min-width: 150px;
    }

    .cal-day {
        min-height: 70px;
    }

    .cal-pill {
        font-size: 0.6rem;
        padding: 0px 3px;
    }

    .cal-week-col {
        min-height: 180px;
    }

    .cal-legend {
        gap: 0.3rem 0.65rem;
        font-size: 0.68rem;
    }
}

@media (max-width: 480px) {
    .cal-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.35rem;
    }

    .cal-controls-left {
        width: 100%;
        justify-content: flex-start;
    }

    .cal-view-btns {
        width: 100%;
    }

    .cal-view-btn {
        flex: 1;
        text-align: center;
    }

    .cal-type-filter {
        width: 100%;
    }

    .cal-nav {
        width: 100%;
    }

    .cal-nav-btn {
        flex: 1;
    }

    .cal-title {
        min-width: 0;
    }

    .cal-day {
        min-height: 60px;
        padding: 0.25rem;
    }

    .cal-pill {
        font-size: 0.55rem;
        padding: 0px 2px;
    }

    .cal-week-col {
        min-height: 150px;
    }

    .cal-legend {
        justify-content: center;
    }
}