/**
 * TOS Hub Pages - Mobile UX Enhancements
 * SEO Audit: Mobile UX, Internal Linking, Performance
 * Version: 1.0.0
 */

/* ==========================================================================
   CSS Custom Properties for Mobile
   ========================================================================== */
:root {
    --touch-target-min: 44px;
    --mobile-padding: 16px;
    --mobile-header-height: 60px;
}

/* ==========================================================================
   1. Mobile Touch Targets (P0 - High Impact, Low Effort)
   WCAG 2.5.5 recommends 44x44px minimum touch targets
   ========================================================================== */

/* Navigation links - ensure 48px minimum height */
@media (max-width: 1024px) {
    .tos-nav-link,
    .tos-sidebar-link,
    .ind-toc-link {
        min-height: 48px;
        padding: 14px 16px;
        display: flex;
        align-items: center;
    }

    .tos-mega-cat-list a,
    .tos-mobile-nav a {
        min-height: var(--touch-target-min);
        padding: 12px 16px;
    }

    /* Buttons */
    .tos-btn,
    .ind-btn,
    .tos-cta-button {
        min-height: 48px;
        padding: 14px 24px;
    }

    /* Filter dropdowns */
    .tos-select-field,
    .tos-access-select {
        min-height: 48px;
        padding: 12px 16px;
    }

    /* Card action buttons */
    .tos-indicator-action,
    .ind-featured-link {
        min-height: var(--touch-target-min);
        padding: 12px 20px;
    }

    /* FAQ questions */
    .ind-faq-question {
        min-height: 56px;
        padding: 16px 20px;
    }

    /* Pagination */
    .tos-page-btn {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
    }

    /* Modal close button */
    .tos-access-modal-close,
    .ind-modal-close {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
    }
}

/* ==========================================================================
   2. Mobile Grid Breakpoint Fixes (P0 - High Impact, Low Effort)
   Fix cramped cards between 768-1024px
   ========================================================================== */

/* Featured Grid - improved breakpoints */
@media (max-width: 1200px) and (min-width: 769px) {
    .ind-featured-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .ind-featured-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* Category Grid - improved breakpoints */
@media (max-width: 1200px) and (min-width: 1025px) {
    .ind-category-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
}

@media (max-width: 1024px) and (min-width: 769px) {
    .ind-category-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
}

@media (max-width: 768px) {
    .ind-category-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* Video Grid - improved breakpoints */
@media (max-width: 1200px) and (min-width: 1025px) {
    .ind-video-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
}

@media (max-width: 1024px) and (min-width: 769px) {
    .ind-video-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
}

@media (max-width: 768px) {
    .ind-video-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* TOS Indicators Grid - improved breakpoints */
@media (max-width: 1024px) and (min-width: 769px) {
    .tos-indicators-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .tos-indicators-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* Featured Tools Grid */
@media (max-width: 1024px) and (min-width: 769px) {
    .tos-featured-tools {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .tos-featured-tools {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* ==========================================================================
   3. Mobile Table of Contents Dropdown (P2 - Medium Impact)
   Collapsible quick-jump for mobile
   ========================================================================== */

/* Mobile ToC - show as collapsible dropdown */
@media (max-width: 600px) {
    .ind-toc {
        display: block !important;
        padding: 0;
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--gray-50, #f9fafb);
        border-bottom: 1px solid var(--gray-200, #e5e7eb);
    }

    .ind-toc-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    .ind-toc-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 16px var(--mobile-padding);
        background: transparent;
        border: none;
        font-size: 14px;
        font-weight: 600;
        color: var(--gray-700, #374151);
        cursor: pointer;
    }

    .ind-toc-toggle-icon {
        width: 20px;
        height: 20px;
        transition: transform 0.2s ease;
    }

    .ind-toc.expanded .ind-toc-toggle-icon {
        transform: rotate(180deg);
    }

    .ind-toc-label {
        display: none;
    }

    .ind-toc-links {
        display: none;
        flex-direction: column;
        padding: 0 var(--mobile-padding) 16px;
        gap: 4px;
    }

    .ind-toc.expanded .ind-toc-links {
        display: flex;
    }

    .ind-toc-link {
        padding: 12px 16px;
        border-radius: 8px;
        background: var(--gray-100, #f3f4f6);
    }

    .ind-toc-link:hover,
    .ind-toc-link:active {
        background: var(--green, #4caf50);
        color: white;
    }
}

/* Desktop ToC toggle - hidden */
@media (min-width: 601px) {
    .ind-toc-toggle {
        display: none;
    }
}

/* ==========================================================================
   4. Mobile Navigation CTA (P1 - Medium Impact, Low Effort)
   Sticky CTA at bottom of mobile nav overlay
   ========================================================================== */

@media (max-width: 1024px) {
    .tos-mobile-cta {
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        padding: var(--mobile-padding);
        background: var(--white, #ffffff);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        border-top: 1px solid var(--gray-200, #e5e7eb);
        z-index: 10;
    }

    .tos-mobile-cta .tos-btn,
    .tos-mobile-cta .ind-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ==========================================================================
   5. Mobile Hero CTA Stacking
   ========================================================================== */

@media (max-width: 640px) {
    .ind-hero-ctas,
    .tos-cta-buttons,
    .tos-hero-ctas {
        flex-direction: column;
        gap: 12px;
    }

    .ind-hero-ctas .ind-btn,
    .tos-cta-buttons .tos-btn,
    .tos-hero-ctas .tos-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ==========================================================================
   6. Skeleton Loading States (P2 - Medium Impact)
   Show loading placeholders while content loads
   ========================================================================== */

.tos-skeleton {
    background: linear-gradient(90deg,
        var(--gray-100, #f3f4f6) 25%,
        var(--gray-200, #e5e7eb) 50%,
        var(--gray-100, #f3f4f6) 75%
    );
    background-size: 200% 100%;
    animation: tos-skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm, 8px);
}

@keyframes tos-skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Skeleton card */
.tos-skeleton-card {
    background: var(--white, #ffffff);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: var(--radius-md, 12px);
    overflow: hidden;
}

.tos-skeleton-card__image {
    aspect-ratio: 16/10;
}

.tos-skeleton-card__content {
    padding: 20px;
}

.tos-skeleton-card__title {
    height: 20px;
    width: 70%;
    margin-bottom: 12px;
}

.tos-skeleton-card__text {
    height: 14px;
    margin-bottom: 8px;
}

.tos-skeleton-card__text:last-child {
    width: 50%;
}

.tos-skeleton-card__button {
    height: 40px;
    width: 120px;
    margin-top: 16px;
}

/* Skeleton grid */
.tos-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

/* Loading state for grid */
.tos-indicators-grid[aria-busy="true"],
.ind-featured-grid[aria-busy="true"] {
    position: relative;
}

.tos-indicators-grid[aria-busy="true"]::after,
.ind-featured-grid[aria-busy="true"]::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    z-index: 10;
}

/* ==========================================================================
   7. Video Thumbnail Facade (P2 - Medium Impact)
   Show static thumbnail until user clicks to play
   ========================================================================== */

.tos-video-facade {
    position: relative;
    aspect-ratio: 16/9;
    background: var(--gray-900, #111827);
    border-radius: var(--radius-md, 12px);
    overflow: hidden;
    cursor: pointer;
}

.tos-video-facade__thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.tos-video-facade:hover .tos-video-facade__thumb {
    transform: scale(1.03);
}

.tos-video-facade__play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.tos-video-facade:hover .tos-video-facade__play {
    background: var(--green, #4caf50);
    transform: translate(-50%, -50%) scale(1.1);
}

.tos-video-facade__play svg {
    width: 28px;
    height: 28px;
    color: white;
    margin-left: 4px; /* Optical centering for play icon */
}

.tos-video-facade__label {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: white;
    white-space: nowrap;
}

/* When video is loaded, hide facade */
.tos-video-facade.loaded {
    display: none;
}

/* ==========================================================================
   8. Breadcrumbs (P1 - Medium Impact, Low Effort)
   Enable and style breadcrumbs for SEO + navigation
   ========================================================================== */

.tos-breadcrumbs {
    padding: 16px 0;
    font-size: 13px;
    color: var(--gray-500, #6b7280);
}

.tos-breadcrumbs__list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.tos-breadcrumbs__item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tos-breadcrumbs__separator {
    color: var(--gray-400, #9ca3af);
}

.tos-breadcrumbs__link {
    color: var(--gray-500, #6b7280);
    text-decoration: none;
    transition: color 0.15s ease;
}

.tos-breadcrumbs__link:hover {
    color: var(--green, #4caf50);
    text-decoration: underline;
}

.tos-breadcrumbs__current {
    color: var(--gray-700, #374151);
    font-weight: 500;
}

/* Mobile breadcrumbs */
@media (max-width: 640px) {
    .tos-breadcrumbs {
        padding: 12px 0;
        font-size: 12px;
    }

    /* Truncate long breadcrumbs on mobile */
    .tos-breadcrumbs__link,
    .tos-breadcrumbs__current {
        max-width: 120px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* ==========================================================================
   9. Related Indicators Component (P1 - High Impact, Medium Effort)
   Displays related indicators after main content
   ========================================================================== */

.tos-related {
    margin: 48px 0;
    padding: 32px;
    background: var(--gray-50, #f9fafb);
    border-radius: var(--radius-lg, 16px);
}

.tos-related__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.tos-related__title {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900, #111827);
    margin: 0;
}

.tos-related__link {
    font-size: 14px;
    font-weight: 600;
    color: var(--green, #4caf50);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tos-related__link:hover {
    text-decoration: underline;
}

.tos-related__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.tos-related__card {
    background: var(--white, #ffffff);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: var(--radius-md, 12px);
    overflow: hidden;
    text-decoration: none;
    transition: all 0.2s ease;
}

.tos-related__card:hover {
    border-color: var(--green, #4caf50);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.15);
    transform: translateY(-2px);
}

.tos-related__thumb {
    aspect-ratio: 16/9;
    background: var(--gray-100, #f3f4f6);
    overflow: hidden;
}

.tos-related__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tos-related__content {
    padding: 16px;
}

.tos-related__name {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-900, #111827);
    margin: 0 0 8px;
    line-height: 1.3;
}

.tos-related__desc {
    font-size: 13px;
    color: var(--gray-600, #4b5563);
    margin: 0 0 12px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tos-related__action {
    font-size: 13px;
    font-weight: 600;
    color: var(--green, #4caf50);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Mobile: horizontal scroll carousel */
@media (max-width: 768px) {
    .tos-related {
        padding: 24px var(--mobile-padding);
        margin: 32px calc(var(--mobile-padding) * -1);
        border-radius: 0;
    }

    .tos-related__grid {
        grid-template-columns: none;
        display: flex;
        gap: 16px;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 16px;
        margin: 0 calc(var(--mobile-padding) * -1);
        padding-left: var(--mobile-padding);
        padding-right: var(--mobile-padding);
    }

    .tos-related__grid::-webkit-scrollbar {
        display: none;
    }

    .tos-related__card {
        flex: 0 0 280px;
        scroll-snap-align: start;
    }

    /* Carousel dots indicator */
    .tos-related__dots {
        display: flex;
        justify-content: center;
        gap: 8px;
        margin-top: 16px;
    }

    .tos-related__dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--gray-300, #d1d5db);
        border: none;
        padding: 0;
        cursor: pointer;
        transition: background 0.2s ease;
    }

    .tos-related__dot.active,
    .tos-related__dot:hover {
        background: var(--green, #4caf50);
    }
}

/* Tablet: 2 columns */
@media (max-width: 1024px) and (min-width: 769px) {
    .tos-related__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Hide dots on desktop */
@media (min-width: 769px) {
    .tos-related__dots {
        display: none;
    }
}

/* ==========================================================================
   10. Category Navigation Pills (P3 - Low Impact, Low Effort)
   Below hero, above content on pillar pages
   ========================================================================== */

.tos-category-pills {
    display: flex;
    gap: 8px;
    padding: 16px 0;
    flex-wrap: wrap;
}

.tos-category-pill {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700, #374151);
    background: var(--gray-100, #f3f4f6);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.tos-category-pill:hover {
    background: rgba(76, 175, 80, 0.15);
    color: var(--green, #4caf50);
}

.tos-category-pill.active {
    background: var(--green, #4caf50);
    color: white;
}

/* Mobile: horizontal scroll */
@media (max-width: 640px) {
    .tos-category-pills {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 12px 0;
        margin: 0 calc(var(--mobile-padding) * -1);
        padding-left: var(--mobile-padding);
        padding-right: var(--mobile-padding);
    }

    .tos-category-pills::-webkit-scrollbar {
        display: none;
    }

    .tos-category-pill {
        flex-shrink: 0;
    }

    /* Fade edges */
    .tos-category-pills-wrapper {
        position: relative;
    }

    .tos-category-pills-wrapper::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 40px;
        background: linear-gradient(to right, transparent, var(--white, #ffffff));
        pointer-events: none;
    }
}

/* ==========================================================================
   11. Accessibility Enhancements
   ========================================================================== */

/* Focus visible styles for keyboard navigation */
.ind-btn:focus-visible,
.tos-btn:focus-visible,
.ind-toc-link:focus-visible,
.tos-sidebar-link:focus-visible,
.ind-faq-question:focus-visible,
.tos-related__card:focus-visible {
    outline: 2px solid var(--green, #4caf50);
    outline-offset: 2px;
}

/* Skip link styles */
.tos-skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--gray-900, #111827);
    color: white;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    z-index: 10000;
    text-decoration: none;
    transition: top 0.2s ease;
}

.tos-skip-link:focus {
    top: 0;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .tos-skeleton,
    .tos-video-facade__thumb,
    .tos-video-facade__play,
    .tos-related__card,
    .ind-featured-card {
        animation: none;
        transition: none;
    }
}
