/* Responsive Mobile-First Optimization for MyToolsSocial */

/* ========== BREAKPOINTS ========== */
/* Mobile: < 600px (default) */
/* Tablet: 600px - 904px */
/* Desktop: > 905px */

/* ========== DESKTOP - HIDE MOBILE-ONLY ELEMENTS ========== */

@media (min-width: 769px) {
    .hide-on-desktop {
        display: none !important;
    }

    .md-nav-menu-header {
        display: none !important;
    }

    .md-nav-close {
        display: none !important;
    }

    /* Align nav items to the left on desktop */
    .md-nav-list {
        justify-content: flex-start !important;
    }
}

/* ========== GENERAL MOBILE OPTIMIZATIONS ========== */

/* Prevent horizontal scroll */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Ensure all images are responsive */
img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* iOS Safari fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix for iOS viewport height with address bar */
    body {
        min-height: -webkit-fill-available;
    }

    /* Smooth scrolling on iOS */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Fix for iOS input zoom */
    input[type="text"],
    input[type="url"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Reduce padding on mobile */
@media (max-width: 600px) {
    body {
        font-size: 14px;
    }

    .container {
        padding: 0 16px !important;
    }

    /* Hero section - reduce padding */
    main .container > div:first-child {
        padding: 40px 16px 24px 16px !important;
    }

    /* Card padding adjustments */
    .md-card {
        padding: 24px 16px !important;
        border-radius: 16px !important;
    }

    .md-card-filled {
        padding: 24px 16px !important;
    }

    /* Uniform spacing for info cards */
    .md-info-cards-container {
        margin-top: 24px !important;
        padding: 0 8px !important;
    }

    .md-info-cards-container .md-card {
        margin-top: 0 !important;
        padding: 24px 16px !important;
    }

    .md-info-cards-container .md-card + .md-card,
    .md-info-cards-container .md-card + div {
        margin-top: 24px !important;
    }

    /* Typography - make titles smaller on mobile */
    .md-headline-large {
        font-size: 28px !important;
        line-height: 1.2 !important;
    }

    .md-headline-medium {
        font-size: 24px !important;
        line-height: 1.3 !important;
    }

    .md-title-medium {
        font-size: 16px !important;
    }

    .md-body-large {
        font-size: 15px !important;
    }

    .md-body-medium {
        font-size: 14px !important;
    }

    /* FAQ section spacing on mobile */
    .faq-section {
        margin-top: 80px !important;
    }

    .faq-title {
        margin-bottom: 24px !important;
    }
}

/* ========== NAVIGATION ========== */

@media (max-width: 768px) {
    .md-top-app-bar {
        padding: 8px 16px !important;
    }

    .md-nav-container {
        flex-wrap: wrap;
        position: relative;
    }

    .md-nav-brand {
        gap: 8px !important;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    /* Show site name on mobile */
    .md-nav-title {
        display: inline !important;
    }

    .md-nav-brand .theme-logo {
        width: 32px !important;
        height: 32px !important;
    }

    .md-nav-title {
        font-size: 16px !important;
    }

    .md-nav-toggle {
        z-index: 10;
    }

    .md-nav-menu {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        background: var(--md-sys-color-surface);
        padding: 16px;
        box-shadow: 2px 0 8px rgba(0,0,0,0.2);
        z-index: 999;
        transition: left 0.3s ease-in-out;
        overflow-y: auto;
    }

    /* RTL (Arabic) support */
    [dir="rtl"] .md-nav-menu {
        left: auto;
        right: -280px;
        box-shadow: -2px 0 8px rgba(0,0,0,0.2);
        transition: right 0.3s ease-in-out;
    }

    [dir="rtl"] .md-nav-menu.md-nav-menu-open {
        right: 0;
    }

    [dir="rtl"] .md-nav-menu::before {
        left: auto;
        right: 280px;
    }

    .md-nav-close {
        position: absolute;
        top: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
        border: none;
        background: transparent;
        color: var(--md-sys-color-on-surface);
        cursor: pointer;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background-color 0.2s ease;
        z-index: 1000;
    }

    [dir="rtl"] .md-nav-close {
        right: auto;
        left: 16px;
    }

    .md-nav-close:hover {
        background-color: var(--md-sys-color-surface-variant);
    }

    .md-nav-close svg {
        stroke: var(--md-sys-color-on-surface);
    }

    .md-nav-menu.md-nav-menu-open {
        left: 0;
    }

    /* Overlay backdrop */
    .md-nav-menu::before {
        content: '';
        position: fixed;
        top: 0;
        left: 280px;
        width: 0;
        height: 100vh;
        background: rgba(0, 0, 0, 0);
        transition: opacity 0.3s ease-in-out;
        pointer-events: none;
        z-index: -1;
    }

    .md-nav-menu.md-nav-menu-open::before {
        width: 100vw;
        background: rgba(0, 0, 0, 0.5);
        pointer-events: all;
    }

    .md-nav-menu-header {
        display: flex !important;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        margin-top: 40px;
        border-bottom: 1px solid var(--md-sys-color-outline-variant);
    }

    .md-nav-menu-header .theme-logo {
        width: 32px !important;
        height: 32px !important;
    }

    .md-nav-menu-title {
        font-size: 16px;
        font-weight: 600;
        color: var(--md-sys-color-on-surface);
        margin: 0;
    }

    /* Hide icons in nav links on desktop */
    .md-nav-link svg {
        display: inline-block !important;
    }

    .md-nav-list {
        flex-direction: column;
        gap: 8px;
        margin-top: 16px;
    }

    .md-nav-actions {
        flex-direction: column;
        width: 100%;
        gap: 8px;
        margin-top: 16px;
        padding: 0;
        list-style: none;
    }

    .md-nav-actions > div {
        width: 100%;
    }

    /* Mobile: Make icon buttons behave like nav links */
    .md-nav-language .md-icon-button,
    .md-nav-color .md-icon-button,
    .md-nav-theme .md-icon-button {
        width: 100% !important;
        min-height: 48px !important;
        height: auto !important;
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 12px 16px !important;
        background: transparent !important;
        border: none !important;
        color: var(--md-sys-color-on-surface) !important;
        cursor: pointer !important;
        border-radius: 8px !important;
        transition: background-color 0.2s ease !important;
        text-align: left !important;
        font-size: 15px !important;
        flex-direction: row !important;
        justify-content: flex-start !important;
        flex-wrap: nowrap !important;
    }

    .md-nav-language .md-icon-button:hover,
    .md-nav-color .md-icon-button:hover,
    .md-nav-theme .md-icon-button:hover {
        background-color: var(--md-sys-color-surface-variant) !important;
    }

    .md-nav-language .md-icon-button svg,
    .md-nav-color .md-icon-button svg,
    .md-nav-theme .md-icon-button svg {
        flex-shrink: 0;
        stroke: var(--md-sys-color-on-surface);
    }

    /* Show only light icon by default, dark icon in dark mode */
    .md-nav-theme .md-icon-button .theme-icon-light {
        display: block;
    }

    .md-nav-theme .md-icon-button .theme-icon-dark {
        display: none;
    }

    [data-bs-theme="dark"] .md-nav-theme .md-icon-button .theme-icon-light {
        display: none;
    }

    [data-bs-theme="dark"] .md-nav-theme .md-icon-button .theme-icon-dark {
        display: block;
    }

    /* Make text labels visible on mobile */
    .md-nav-action-text {
        display: inline !important;
        flex: 1;
        white-space: nowrap;
    }

    /* Language code styling on mobile - override desktop absolute positioning */
    .md-nav-language .md-icon-button .md-nav-lang-text {
        position: static !important;
        font-size: 12px;
        font-weight: 500;
        white-space: nowrap;
        align-self: center;
        background-color: var(--md-sys-color-primary) !important;
        color: var(--md-sys-color-on-primary) !important;
        padding: 2px 6px !important;
        border-radius: 4px !important;
        line-height: 1;
    }

    .md-outlined-button {
        width: 100%;
        justify-content: center;
    }
}

/* ========== SEARCH FORM ========== */

@media (max-width: 600px) {
    /* Hero section container */
    main.container[style*="max-width: 1200px"] {
        padding: 0 8px !important;
    }

    /* Hero section padding */
    main > div[style*="padding: 60px"] {
        padding: 32px 8px 24px 8px !important;
    }

    /* Search card */
    .md-card.md-card-filled[style*="max-width: 900px"] {
        max-width: 100% !important;
        padding: 20px 12px !important;
        border-radius: 16px !important;
        margin: 0 !important;
    }

    /* Form elements */
    .form-group {
        margin-bottom: 16px;
    }

    /* URL input */
    input[type="url"],
    input[type="text"] {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 12px 16px !important;
    }

    /* Submit button */
    button[type="submit"] {
        width: 100%;
        padding: 14px 24px !important;
        font-size: 16px !important;
    }

    /* Platform chips container */
    #chips-container {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
    }

    #chips-container::-webkit-scrollbar {
        display: none; /* Chrome/Safari/Opera */
    }

    #platform-chips {
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
    }

    md-assist-chip {
        font-size: 12px !important;
        height: 28px !important;
        flex-shrink: 0 !important;
    }

    md-assist-chip svg {
        width: 14px !important;
        height: 14px !important;
    }
}

/* ========== VIDEO CARDS / GRID ========== */

@media (max-width: 600px) {
    /* Video cards grid - stack on mobile */
    .video-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    /* Video card adjustments */
    .video-card {
        margin-bottom: 16px;
    }

    .video-card img,
    .video-card video {
        max-height: 250px;
        object-fit: cover;
    }

    /* Download buttons */
    .download-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .download-buttons button,
    .download-buttons a {
        width: 100% !important;
        justify-content: center;
    }
}

/* ========== VIDEO DETAILS PAGE ========== */

@media (max-width: 768px) {
    /* Details layout - stack vertically */
    .details-container {
        flex-direction: column !important;
    }

    .details-sidebar {
        width: 100% !important;
        margin-top: 16px;
    }

    /* Video player */
    .video-player {
        max-height: 300px;
    }

    /* Format selection */
    .format-selector {
        flex-direction: column;
    }

    .format-selector select {
        width: 100% !important;
        margin-bottom: 8px;
    }
}

/* ========== MODALS / OVERLAYS ========== */

@media (max-width: 600px) {
    /* Download progress modals */
    #youtube-download-overlay > div,
    #tiktok-download-overlay > div,
    #pinterest-download-overlay > div,
    #snapchat-download-overlay > div {
        padding: 24px 16px !important;
        min-width: 280px !important;
        max-width: 90vw !important;
        border-radius: 20px !important;
    }

    /* Loading overlay */
    #loadingOverlay {
        backdrop-filter: blur(2px);
    }

    #loadingOverlay .md-card {
        padding: 24px 16px !important;
        min-width: 280px !important;
        max-width: 90vw !important;
    }

    /* Error messages */
    .error-message,
    .alert {
        font-size: 14px !important;
        padding: 12px 16px !important;
    }
}

/* ========== FOOTER ========== */

@media (max-width: 768px) {
    footer {
        padding: 32px 16px !important;
    }

    footer .row {
        margin: 0 !important;
    }

    footer .col-md-4,
    footer .col-md-5,
    footer .col-md-3,
    footer .col-md-12 {
        padding: 0 !important;
        text-align: center !important;
        margin-bottom: 32px;
    }

    footer .col-md-3 {
        text-align: center !important;
    }

    footer .col-md-3 > div {
        text-align: center !important;
    }

    footer .footer-section {
        margin-bottom: 24px;
        width: 100%;
    }

    footer .footer-links {
        flex-direction: column;
        gap: 12px;
    }

    /* Stack platform badges in 2 columns on mobile */
    footer .col-md-5 > div {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        justify-items: stretch !important;
    }

    footer .platform-badge {
        width: 100% !important;
        max-width: 100% !important;
        justify-content: center;
    }
}

/* ========== ADMIN PANEL ========== */

@media (max-width: 1024px) {
    .admin-container {
        padding: 16px !important;
    }

    .admin-stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    .admin-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .admin-table {
        min-width: 600px;
    }
}

@media (max-width: 600px) {
    .admin-stats-grid {
        grid-template-columns: 1fr !important;
    }

    .admin-card {
        padding: 16px !important;
    }

    .admin-header {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .admin-actions {
        width: 100%;
        flex-direction: column;
        margin-top: 12px;
    }

    .admin-actions button {
        width: 100%;
    }
}

/* ========== HISTORY PAGE ========== */

@media (max-width: 600px) {
    .history-item {
        flex-direction: column;
        padding: 12px !important;
    }

    .history-thumbnail {
        width: 100% !important;
        max-width: 100%;
        margin-bottom: 12px;
    }

    .history-info {
        width: 100%;
    }

    .history-actions {
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }

    .history-actions button {
        width: 100%;
    }
}

/* ========== PRIVACY PAGE ========== */

@media (max-width: 600px) {
    .privacy-section {
        padding: 20px 16px !important;
    }

    .privacy-section h2 {
        font-size: 20px !important;
    }

    .privacy-section p {
        font-size: 14px !important;
        line-height: 1.6 !important;
    }
}

/* ========== MATERIAL DESIGN COMPONENTS ========== */

@media (max-width: 600px) {
    /* Chips */
    md-chip-set {
        gap: 6px !important;
    }

    /* Buttons */
    .md-filled-button,
    .md-outlined-button,
    .md-text-button {
        height: 44px !important; /* Better touch target */
        min-height: 44px !important;
    }

    /* Icon buttons */
    .md-icon-button {
        width: 44px !important;
        height: 44px !important;
    }

    /* Menus */
    .md-menu {
        max-width: 90vw !important;
    }
}

/* ========== UTILITIES ========== */

/* Hide on mobile */
@media (max-width: 600px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 600px) {
    .show-mobile {
        display: block !important;
    }
}

/* Touch-friendly spacing */
@media (max-width: 600px) {
    button,
    a[role="button"],
    input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Improve tap targets */
    a,
    button {
        padding: 8px;
    }

    /* Ensure nav links are tappable */
    .md-nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px !important;
    }

    .md-nav-link svg {
        flex-shrink: 0;
        stroke: var(--md-sys-color-on-surface);
    }

    /* Menu items */
    .md-menu-item {
        min-height: 48px;
        display: flex;
        align-items: center;
        padding: 12px 16px !important;
    }

    /* Platform badges in footer */
    .platform-badge {
        min-height: 44px;
        padding: 10px 14px !important;
    }
}

/* ========== LANDSCAPE MODE (MOBILE) ========== */

@media (max-width: 900px) and (orientation: landscape) {
    .md-nav-menu {
        max-height: 70vh;
        overflow-y: auto;
    }

    /* Reduce hero padding in landscape */
    main .container > div:first-child {
        padding: 24px 16px !important;
    }

    /* Modals in landscape */
    #youtube-download-overlay > div,
    #tiktok-download-overlay > div,
    #pinterest-download-overlay > div,
    #snapchat-download-overlay > div,
    #loadingOverlay .md-card {
        max-height: 85vh !important;
        overflow-y: auto !important;
    }

    /* Reduce typography in landscape */
    .md-headline-large {
        font-size: 24px !important;
    }

    .md-headline-medium {
        font-size: 20px !important;
    }
}

/* ========== TABLET OPTIMIZATIONS ========== */

@media (min-width: 601px) and (max-width: 904px) {
    .container {
        padding: 0 24px !important;
    }

    main.container[style*="max-width: 1200px"] {
        padding: 0 16px !important;
    }

    /* Search card on tablet */
    .md-card.md-card-filled[style*="max-width: 900px"] {
        max-width: 100% !important;
        padding: 32px 24px !important;
    }

    .md-card {
        padding: 32px 24px !important;
    }

    .video-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
