/* This file is part of MaxRepTracker - Prevent direct access */
/* Performance Chart - Mobile Optimized CSS */

/* Global MRT Tap Highlight Reset */
[class^="mrt-"],
[class*=" mrt-"],
.stat-box {
    -webkit-tap-highlight-color: transparent;
}

.performance-chart-container {
    border-radius: 18px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 20px auto;
    box-sizing: border-box;
    position: relative;
    min-height: 500px;
    overflow: hidden;
    contain: layout style;
    background: transparent;
}

.performance-chart-wrapper,
.performance-stats {
    position: relative;
    z-index: 2;
}

.performance-chart-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    flex: 1;
    min-height: 400px;
    border-radius: 18px;
}

.performance-chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
    /* Fix: Allow vertical scroll (pan-y) so user doesn't get stuck on chart */
    touch-action: pan-y;
}

#typing-text-element {
    min-height: 0;
    border-radius: 12px;
    text-align: center;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    width: 100%;
}

.stat-box {
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-box:hover {
    transform: translateY(-8px);
}

.stat-value {
    display: block;
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 5px;
    line-height: 1;
    letter-spacing: -0.03em;
    /* CLS Fix: Reserve width for counter animation */
    min-width: 2.5ch;
    text-align: center;
}

.stat-label {
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
}

.stat-value-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mrt-arrow {
    font-size: 1.2rem;
    font-weight: bold;
    transition: all 0.3s ease;
    display: inline-block;
}

.mrt-arrow.up {
    color: #10b981;
    animation: pulseUp 0.6s ease;
}

.mrt-arrow.down {
    color: #ef4444;
    animation: pulseDown 0.6s ease;
}

.mrt-arrow.same {
    color: #6b7280;
}

/* Animation for arrows */

.mrt-arrow.up {
    animation: pulseUp 0.6s ease;
}

.mrt-arrow.down {
    animation: pulseDown 0.6s ease;
}

/* Performance Chart Skeleton Shimmer */
.performance-chart-wrapper .mrt-skeleton-placeholder--chart {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #e2e8f0;
    background: linear-gradient(
        90deg,
        #e2e8f0 25%,
        #edf2f7 50%,
        #e2e8f0 75%
    );
    background-size: 200% 100%;
    animation: perf-skeleton-shimmer 1.5s infinite;
    border-radius: 18px;
    z-index: 5;
    transition: opacity 300ms ease-out;
    pointer-events: none;
}

.performance-chart-wrapper
    .mrt-skeleton-placeholder--chart.is-hiding {
    opacity: 0;
}

html.maxreptracker-dark-mode-enabled .performance-chart-wrapper .mrt-skeleton-placeholder--chart {
    background: #2a2a2a;
    background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
}

@media (prefers-reduced-motion: reduce) {
    .performance-chart-wrapper
        .mrt-skeleton-placeholder--chart {
        transition: none;
    }
}

@keyframes perf-skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

@keyframes pulseUp {
    0% {
        transform: scale(1) translateY(0);
    }
    50% {
        transform: scale(1.3) translateY(-2px);
    }
    100% {
        transform: scale(1) translateY(0);
    }
}

@keyframes pulseDown {
    0% {
        transform: scale(1) translateY(0);
    }
    50% {
        transform: scale(1.3) translateY(2px);
    }
    100% {
        transform: scale(1) translateY(0);
    }
}

/* Tablet Styles */
@media (max-width: 1024px) and (min-width: 769px) {
    .performance-chart-container {
        min-height: 450px;
        gap: 20px;
    }

    .performance-chart-wrapper {
        height: 320px;
    }

    .stats-grid {
        gap: 12px;
    }

    .stat-value {
        font-size: 1.8rem;
    }

    .stat-label {
        font-size: 0.85rem;
    }

    #typing-text-element {
        margin: 0 0 6px 0;
    }
}

/* Mobile Styles - STAT BOXES ALWAYS IN ONE ROW */
@media (max-width: 768px) {
    .performance-chart-container {
        flex-direction: column;
        margin: 30px 0;
        border-radius: 15px;
        min-height: 550px;
        gap: 15px;
    }

    .performance-chart-wrapper {
        height: 300px;
        min-height: 250px;
    }

    #typing-text-element {
        font-size: 1rem;
        font-weight: 600;
        letter-spacing: 0.02em;
        margin-bottom: 8px;
    }

    .stat-value-container {
        gap: 6px;
    }

    /* KEEP 3 STAT BOXES IN ONE ROW */
    .stats-grid {
        gap: 10px;
    }

    .stat-box {
        padding: 12px 8px;
        min-height: 65px;
    }

    .stat-value {
        font-size: 1.6rem;
        margin-bottom: 3px;
    }

    .stat-label {
        font-size: 0.8rem;
    }

    .mrt-arrow {
        font-size: 1rem;
    }

    /* Adjust hover effects for touch devices */
    .stat-box:hover {
        transform: none;
    }

    .stat-box:active {
        transform: scale(0.98);
        background: rgba(255, 255, 255, 0.2) !important;
    }
}

/* Small Mobile Styles - STILL KEEP 3 IN ROW */
@media (max-width: 480px) {
    .performance-chart-container {
        margin: 20px 0;
        min-height: auto;
        gap: 6px;
    }

    .performance-chart-wrapper {
        height: 250px;
        min-height: 200px;
    }

    #typing-text-element {
        font-size: 0.8rem;
        padding: 6px;
        margin-bottom: 4px;
    }

    .stat-value-container {
        gap: 4px;
    }

    /* STILL 3 STAT BOXES IN ONE ROW */
    .stats-grid {
        gap: 8px;
    }

    .stat-box {
        padding: 10px 6px;
        min-height: 55px;
        border-radius: 6px;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .mrt-arrow {
        font-size: 0.9rem;
    }
}

/* Very Small Mobile Styles - STILL KEEP 3 IN ROW */
@media (max-width: 360px) {
    .performance-chart-container {
        border-radius: 10px;
        gap: 4px;
    }

    .performance-chart-wrapper {
        height: 220px;
    }

    /* STILL 3 STAT BOXES IN ONE ROW */
    .stats-grid {
        gap: 6px;
    }

    .stat-box {
        padding: 8px 4px;
        min-height: 50px;
        display: flex;
        flex-direction: column;
        text-align: center;
    }

    .stat-value {
        font-size: 1.2rem;
        margin-bottom: 2px;
        justify-self: center;
    }

    .stat-label {
        font-size: 0.7rem;
        justify-self: center;
    }

    #typing-text-element {
        margin-bottom: 4px;
    }
}

/* Landscape Mobile Styles */
@media (max-width: 768px) and (orientation: landscape) {
    .performance-chart-container {
        flex-direction: row;
        align-items: center;
        min-height: 300px;
        gap: 8px;
    }

    .performance-chart-wrapper {
        flex: 1;
        height: 250px;
        max-width: 60%;
    }

    .performance-stats {
        position: relative;
        z-index: 1;
    }

    /* STILL 3 STAT BOXES IN ONE ROW */
    .stats-grid {
        gap: 8px;
    }

    .stat-box {
        padding: 8px;
        min-height: 50px;
    }

    .stat-value {
        font-size: 1.3rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    #typing-text-element {
        margin-bottom: 6px;
    }
}

/* Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
    .stat-box {
        transition: none;
    }

    .stat-box:hover {
        transform: none;
    }

    #typing-text-element {
        transition: none;
    }

    .mrt-arrow.up,
    .mrt-arrow.down {
        animation: none;
    }

    #typing-text-element::after {
        animation: none;
    }
}

/* Print Styles */
@media print {
    .performance-chart-container {
        background: white !important;
        color: black !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        border: 1px solid #ccc;
    }

    .stat-value,
    .stat-label,
    #typing-text-element {
        color: black !important;
    }
}

/* Typing animation styles */
#typing-text-element {
    height: auto;
    overflow: hidden;
}

#typing-text-element::after {
    content: "|";
    animation: blink 1s infinite;
    margin-left: 2px;
    color: currentColor;
}

@keyframes blink {
    0%,
    50% {
        opacity: 1;
    }
    51%,
    100% {
        opacity: 0;
    }
}

/* --flat modifier */
.performance-chart-container--flat .stat-box,
.performance-chart-container--flat #typing-text-element {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    min-height: 0;
    border-radius: 0;
}

.performance-chart-container--flat .stat-box:hover,
.performance-chart-container--flat #typing-text-element:hover {
    background: transparent !important;
    transform: none !important;
    border-color: transparent !important;
}

.performance-chart-container--flat .stats-grid {
    gap: 0;
}

/* Defer rendering for below-the-fold sections */
.mrt-timeline-container,
#mrt-charts-preview,
#mrt-calendar-app,
#mrt-workout-form-preview {
    content-visibility: auto;
    contain-intrinsic-size: auto 400px;
}
