/* ============================================================
   MaxRepTracker YouTube — self-contained styles
   Toggle style copied from core mrt-exercise-type-toggle
   with local fallback variables (no core dependency).
   ============================================================ */

:root {
    --mrt-bg-tertiary: #edf2f7;
    --mrt-border-light: #e2e8f0;
    --mrt-primary: #4f33ff;
    --mrt-primary-hover: #3b1fe0;
    --mrt-shadow-primary: 0 4px 12px rgba(79, 51, 255, 0.3);
    --mrt-transition-smooth: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --mrt-transition-bounce: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --mrt-radius: 18px;
    --mrt-radius-sm: 8px;
    --mrt-app-nav-inset-bottom: 0px;
}

.mrt-yt-container {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-sizing: border-box;
    background: #ffffff;
    border-radius: var(--mrt-radius);
    box-shadow: none;
    font-family: inherit;
    color: #1e293b;
}

/* ---------- Header + hamburger ---------- */
.mrt-yt-header {
    position: sticky;
    top: 0;
    /* Below the FAB menu button (z-index 9998) so it never crosses the FAB,
       and below the off-canvas sidebar (9999) which should paint over it. */
    z-index: 9990;
    background: inherit;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    /* Reserve the FAB Menu footprint on the right (vars injected on :root by
       the FAB plugin) so the title never sits under the floating button. */
    padding-right: calc(var(--mrt-fab-menu-size, 48px) + var(--mrt-fab-menu-right, 16px) + 12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.mrt-yt-toggle {
    position: relative;
    z-index: 10003;
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    padding: 6px;
    border-radius: var(--mrt-radius-sm);
    display: flex;
    align-items: center;
}

.mrt-yt-toggle:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #64748b;
}

.mrt-yt-title {
    font-weight: 700;
    font-size: 1.05em;
    color: #1e293b;
}

/* ---------- Body layout ---------- */
.mrt-yt-body {
    display: flex;
    position: relative;
    min-height: 60vh;
}

/* ---------- Side panel (off-canvas drawer, closed by default) ---------- */
.mrt-yt-sidebar {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 9999;
    width: 300px;
    max-width: 85vw;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    background: #fafbfc;
    border-right: 1px solid rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.mrt-yt-sidebar.open {
    transform: translateX(0);
    bottom: var(--mrt-app-nav-inset-bottom, 0px);
}

.mrt-yt-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 14px 56px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    font-weight: 700;
    font-size: 0.9em;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.mrt-yt-sidebar-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5em;
    line-height: 1;
    color: #94a3b8;
    padding: 0 4px;
    border-radius: var(--mrt-radius-sm);
    transition: color 0.2s ease, background 0.2s ease;
}

.mrt-yt-sidebar-close:hover {
    color: #1e293b;
    background: rgba(0, 0, 0, 0.05);
}

.mrt-yt-nav {
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 6px;
}

.mrt-yt-nav-item {
    text-align: left;
    background: none;
    border: none;
    padding: 10px 12px;
    border-radius: var(--mrt-radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    color: #475569;
}

.mrt-yt-nav-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.mrt-yt-nav-item.active {
    background: var(--mrt-primary);
    color: #ffffff;
}

.mrt-yt-panel {
    padding: 0 12px 16px;
    overflow-y: auto;
    flex: 1;
}

.mrt-yt-panel-empty {
    color: #94a3b8;
    font-size: 0.9em;
    padding: 8px 4px;
}

.mrt-yt-panel-more {
    color: #94a3b8;
    font-size: 12px;
    opacity: 0.7;
    padding: 10px 4px 2px;
}

.mrt-yt-history-item,
.mrt-yt-watch-item {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px 4px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.mrt-yt-history-item img,
.mrt-yt-watch-item img {
    width: 88px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.mrt-yt-history-item span,
.mrt-yt-watch-item span {
    font-size: 0.82em;
    line-height: 1.3;
    color: #334155;
}

.mrt-yt-sessions-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 9998;
}

.mrt-yt-sessions-backdrop.open {
    display: block;
}

@media (min-width: 1024px) {
    .mrt-yt-sessions-backdrop {
        display: none !important;
    }
}

/* ---------- Main content ---------- */
.mrt-yt-main {
    flex: 1;
    padding: 20px;
    min-width: 0;
}

.mrt-yt-empty-notice,
.mrt-yt-grid-empty,
.mrt-yt-publisher-error {
    color: #94a3b8;
}

.mrt-yt-publisher-error {
    color: #dc2626;
    font-size: 0.9em;
}

/* ---------- Exercise type toggle (copied) ---------- */
.mrt-exercise-type-toggle {
    position: relative;
    display: inline-flex;
    background: var(--mrt-bg-tertiary);
    border-radius: 18px;
    padding: 3px;
    border: 1px solid var(--mrt-border-light);
    margin-bottom: 20px;
    width: 100%;
    max-width: 100%;
    height: 48px;
    align-items: center;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

.mrt-exercise-type-toggle input[type="radio"] {
    display: none;
}

.mrt-toggle-option {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    transition: var(--mrt-transition-smooth);
    font-weight: 700;
    font-size: 12px;
    color: #64748b;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    text-align: center;
}

.mrt-exercise-type-toggle input[type="radio"]:checked + label {
    color: #ffffff !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.mrt-toggle-slider {
    position: absolute;
    height: calc(100% - 6px);
    width: calc(50% - 3px);
    border-radius: 15px;
    transition: var(--mrt-transition-bounce);
    background: linear-gradient(135deg, var(--mrt-primary) 0%, var(--mrt-primary-hover) 100%);
    box-shadow: none;
    z-index: 1;
    left: 3px;
}

#mrt_yt_tab_local:checked ~ .mrt-toggle-slider {
    transform: translateX(0);
}

#mrt_yt_tab_world:checked ~ .mrt-toggle-slider {
    transform: translateX(100%);
}

/* ---------- Type filter (Shorts / Regular) — filter-button row ---------- */
.mrt-yt-type-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 0;
    margin-bottom: 12px;
}

.mrt-yt-type-filter-btn {
    padding: 8px 15px;
    border: 1px solid #cbd5e0;
    background: #edf2f7;
    border-radius: 18px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    color: #4a5568;
    flex: 0 0 auto;
    white-space: nowrap;
}

.mrt-yt-type-filter-btn:hover,
.mrt-yt-type-filter-btn.active {
    background: var(--mrt-primary, #4f33ff);
    color: #fff;
    border-color: var(--mrt-primary, #4f33ff);
}

.mrt-yt-type-empty {
    padding: 24px 4px;
    color: #94a3b8;
    font-size: 0.9em;
    text-align: center;
}

.mrt-toggle-option:active {
    transform: scale(0.97);
}

/* ---------- Video grid ---------- */
/* Two type-pure shelves: Shorts denser (6 across, like YouTube),
   Regulars stay 4 across. The type toggle shows one at a time. */
.mrt-yt-grid {
    display: grid;
    gap: 16px;
}

.mrt-yt-grid-short {
    grid-template-columns: repeat(6, 1fr);
}

.mrt-yt-grid-regular {
    grid-template-columns: repeat(4, 1fr);
}

.mrt-yt-video {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mrt-yt-thumb {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    margin: 0;
    padding: 0;
    border: 0;
    background: #000;
    cursor: pointer;
}

/* Shorts use a portrait 9:16 thumbnail like YouTube; Regular stays 16:9 */
.mrt-yt-video[data-type="short"] .mrt-yt-thumb {
    aspect-ratio: 9 / 16;
}

.mrt-yt-thumb-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.mrt-yt-thumb-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.mrt-yt-thumb-play::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    margin-left: 4px;
    border-style: solid;
    border-width: 11px 0 11px 18px;
    border-color: transparent transparent transparent #ffffff;
}

.mrt-yt-thumb:hover .mrt-yt-thumb-play {
    background: rgba(255, 0, 0, 0.85);
    transform: translate(-50%, -50%) scale(1.06);
}

.mrt-yt-duration {
    position: absolute;
    right: 8px;
    bottom: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    font-size: 0.72em;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 4px;
    letter-spacing: 0.3px;
}

.mrt-yt-video-frame {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    background: #000;
}

.mrt-yt-video-frame iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Shorts play in a 9:16 player so the tile doesn't snap back to 16:9 on click */
.mrt-yt-video[data-type="short"] .mrt-yt-video-frame {
    padding-bottom: 177.78%;
}

.mrt-yt-video-meta {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
}

.mrt-yt-video-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mrt-yt-video-title {
    font-size: 0.9em;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mrt-yt-video-channel {
    font-size: 0.78em;
    color: #64748b;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mrt-yt-video-date {
    font-size: 0.74em;
    color: #94a3b8;
    line-height: 1.2;
}

.mrt-yt-watch-later {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.3em;
    line-height: 1;
    color: #cbd5e1;
    padding: 2px 4px;
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.mrt-yt-watch-later.active {
    color: var(--mrt-primary);
}

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
    .mrt-yt-sidebar {
        width: 300px;
    }

    .mrt-yt-main {
        padding: 16px 18px;
    }

    body.mrt-yt-sidebar-open {
        overflow: hidden;
    }
}

@media (max-width: 1100px) {
    .mrt-yt-grid-short {
        grid-template-columns: repeat(4, 1fr);
    }
    .mrt-yt-grid-regular {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 760px) {
    .mrt-yt-grid-regular {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .mrt-yt-main {
        padding: 12px 14px;
    }

    .mrt-yt-grid-short {
        grid-template-columns: repeat(1, 1fr);
    }
    .mrt-yt-grid-regular {
        grid-template-columns: 1fr;
    }
}

/* ---------- Dark mode compatibility ---------- */
html.maxreptracker-dark-mode-enabled .mrt-exercise-type-toggle {
    background: rgba(255, 255, 255, 0.05) !important;
    border-color: var(--maxreptracker-dark-border) !important;
}

html.maxreptracker-dark-mode-enabled .mrt-toggle-option {
    color: rgba(255, 255, 255, 0.7) !important;
}

html.maxreptracker-dark-mode-enabled .mrt-yt-type-filter-btn {
    background: rgba(255, 255, 255, 0.05) !important;
    border-color: var(--maxreptracker-dark-border) !important;
    color: var(--maxreptracker-dark-text) !important;
}

html.maxreptracker-dark-mode-enabled .mrt-yt-type-filter-btn:hover,
html.maxreptracker-dark-mode-enabled .mrt-yt-type-filter-btn.active {
    background: #4f33ff !important;
    border-color: #4f33ff !important;
    color: #fff !important;
}

html.maxreptracker-dark-mode-enabled .mrt-yt-container {
    background: #14161a;
    color: var(--maxreptracker-dark-text);
}

html.maxreptracker-dark-mode-enabled .mrt-yt-sidebar,
html.maxreptracker-dark-mode-enabled .mrt-yt-title,
html.maxreptracker-dark-mode-enabled .mrt-yt-video-title {
    color: var(--maxreptracker-dark-text);
}

html.maxreptracker-dark-mode-enabled .mrt-yt-video-channel {
    color: rgba(255, 255, 255, 0.65);
}

html.maxreptracker-dark-mode-enabled .mrt-yt-video-date {
    color: rgba(255, 255, 255, 0.45);
}

html.maxreptracker-dark-mode-enabled .mrt-yt-thumb-play {
    background: rgba(255, 255, 255, 0.18);
}

html.maxreptracker-dark-mode-enabled .mrt-yt-thumb-play::before {
    border-color: transparent transparent transparent #ffffff;
}

html.maxreptracker-dark-mode-enabled .mrt-yt-sidebar {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--maxreptracker-dark-border);
}

html.maxreptracker-dark-mode-enabled .mrt-yt-video {
    background: #1c1f26;
    border-color: var(--maxreptracker-dark-border);
}

html.maxreptracker-dark-mode-enabled .mrt-yt-nav-item {
    color: rgba(255, 255, 255, 0.75);
}

html.maxreptracker-dark-mode-enabled .mrt-yt-nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ---------- Infinite scroll sentinel ---------- */
.mrt-yt-scroll-sentinel {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mrt-yt-scroll-sentinel.mrt-yt-loading::after {
    content: '';
    width: 22px;
    height: 22px;
    border: 2px solid #ccc;
    border-top-color: var(--mrt-yt-accent, #e31b23);
    border-radius: 50%;
    animation: mrt-yt-spin 0.6s linear infinite;
}

@keyframes mrt-yt-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Faux fullscreen (no Fullscreen API — avoids YouTube mobile crop bug) ---------- */
.mrt-yt-fs-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.55);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
}
@media (hover: hover) {
    .mrt-yt-fs-btn { opacity: 0; }
    .mrt-yt-video-frame:hover .mrt-yt-fs-btn,
    .mrt-yt-fs-btn:focus-visible { opacity: 1; }
}
@media (hover: none) {
    .mrt-yt-fs-btn { opacity: 1; }
}

.mrt-yt-fs-exit {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.55);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    align-items: center;
    justify-content: center;
}

body.mrt-yt-fs-active,
html.mrt-yt-fs-active {
    overflow: hidden;
}
.mrt-yt-fs-active .mrt-yt-video {
    overflow: visible !important;
}
.mrt-yt-fs-active .mrt-yt-video-frame.mrt-yt-fs-target {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: auto !important;
    height: auto !important;
    padding-bottom: 0 !important;
    background: #000 !important;
    z-index: 99999 !important;
}
.mrt-yt-fs-active .mrt-yt-video-frame.mrt-yt-fs-target iframe {
    width: 100% !important;
    height: 100% !important;
}
.mrt-yt-fs-active .mrt-yt-video-frame.mrt-yt-fs-target .mrt-yt-fs-exit {
    display: flex;
}
.mrt-yt-fs-active .mrt-yt-video-frame.mrt-yt-fs-target .mrt-yt-fs-btn {
    display: none;
}
