/**
 * Responsive CSS
 * 
 * Mobile-first responsive styles for Developer Portal theme
 * 
 * @package Developer_Portal
 */

/* ============================================
   MOBILE FIRST (Base styles are for mobile)
============================================ */

/* ============================================
   EXTRA SMALL DEVICES (320px and up)
============================================ */
@media (min-width: 320px) {
    .hero-title {
        font-size: 1.75rem;
    }
    
    .hero-description {
        font-size: 1rem;
    }
    
    .post-card-title {
        font-size: 1rem;
    }
}

/* ============================================
   SMALL DEVICES (480px and up)
============================================ */
@media (min-width: 480px) {
    .container {
        padding: 0 var(--spacing-lg);
    }
    
    .hero-title {
        font-size: 2rem;
    }
    
    .search-form {
        flex-direction: row;
    }
    
    .search-button {
        width: auto;
    }
}

/* ============================================
   MEDIUM DEVICES / TABLETS (640px and up)
============================================ */
@media (min-width: 640px) {
    .footer-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .post-navigation {
        grid-template-columns: 1fr 1fr;
    }
    
    .hero-title {
        font-size: 2.25rem;
    }
    
    .hero-description {
        font-size: 1.0625rem;
    }
    
    .single-post-title,
    .script-post-title {
        font-size: 2rem;
    }
    
    /* Ads */
    .ad-in-feed {
        grid-column: span 2;
    }
}

/* ============================================
   TABLETS / SMALL LAPTOPS (768px and up)
============================================ */
@media (min-width: 768px) {
    .main-navigation {
        display: flex;
    }
    
    .mobile-menu-toggle {
        display: none;
    }
    
    .mobile-navigation {
        display: none !important;
    }
    
    .hero-section {
        padding: var(--spacing-3xl) 0;
    }
    
    .hero-title {
        font-size: 2.75rem;
    }
    
    .hero-description {
        font-size: 1.125rem;
    }
    
    .single-post-title {
        font-size: 2.25rem;
    }
    
    .single-post-meta {
        flex-wrap: nowrap;
    }
    
    .footer-bottom {
        flex-direction: row;
        justify-content: space-between;
        text-align: left;
    }
    
    /* Hide mobile anchor ad on tablets and up */
    .ad-mobile-anchor {
        display: none !important;
    }
    
    /* Show header ad leaderboard */
    .ad-header {
        min-height: 90px;
    }
}

/* ============================================
   LAPTOPS / DESKTOPS (1024px and up)
============================================ */
@media (min-width: 1024px) {
    .footer-grid {
        grid-template-columns: 2fr 1fr 1fr 1fr;
    }
    
    .hero-title {
        font-size: 3rem;
    }
    
    .single-post-title,
    .script-post-title {
        font-size: 2.5rem;
    }
    
    /* Ads */
    .ad-in-feed {
        grid-column: span 3;
    }
    
    /* Sticky sidebar ad */
    .sticky-ad-wrapper {
        position: sticky;
        top: 90px;
    }
}

/* ============================================
   LARGE DESKTOPS (1280px and up)
============================================ */
@media (min-width: 1280px) {
    .container {
        padding: 0 var(--spacing-xl);
    }
    
    .hero-title {
        font-size: 3.25rem;
    }
}

/* ============================================
   EXTRA LARGE SCREENS (1536px and up)
============================================ */
@media (min-width: 1536px) {
    .post-card-content {
        padding: var(--spacing-lg);
    }
}

/* ============================================
   MOBILE-SPECIFIC FIXES
============================================ */
@media (max-width: 767px) {
    /* Reduce spacing on mobile */
    .hero-section {
        padding: var(--spacing-2xl) 0;
    }
    
    .posts-section {
        padding: var(--spacing-lg) 0;
    }
    
    /* Stack search form on very small screens */
    .search-form {
        flex-direction: column;
    }
    
    .search-button {
        width: 100%;
    }
    
    /* Sidebar below content on mobile */
    .main-content.with-sidebar {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        margin-top: var(--spacing-xl);
    }
    
    /* Mobile navigation styles */
    .mobile-navigation {
        max-height: 80vh;
        overflow-y: auto;
    }
    
    .mobile-nav-menu li a {
        padding: var(--spacing-md) var(--spacing-lg);
        font-size: 1.0625rem;
    }
    
    /* Post card adjustments */
    .post-card-title {
        font-size: 1rem;
        -webkit-line-clamp: 2;
    }
    
    .post-card-excerpt {
        display: none;
    }
    
    /* Single post adjustments */
    .single-post-header {
        padding: var(--spacing-xl) 0;
    }
    
    .single-post-title {
        font-size: 1.5rem;
    }
    
    .single-post-content {
        padding: var(--spacing-md);
    }
    
    /* Footer adjustments */
    .site-footer {
        padding: var(--spacing-2xl) 0 var(--spacing-xl);
    }
    
    .footer-grid {
        gap: var(--spacing-lg);
    }
    
    /* Comments adjustments */
    .comments-section {
        padding: var(--spacing-md);
    }
    
    /* Mobile anchor ad space */
    .ad-mobile-anchor {
        display: flex;
        min-height: 50px;
    }
    
    /* Add padding at bottom for mobile anchor ad */
    body {
        padding-bottom: 60px;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .nav-menu li a,
    .mobile-nav-menu li a {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .search-button,
    .hero-button,
    .pagination a,
    .pagination span {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .post-card:hover {
        transform: none;
    }
    
    .post-card:active {
        transform: scale(0.98);
    }
    
    /* Remove hover-dependent image zoom */
    .post-card:hover .post-card-image img {
        transform: none;
    }
}

/* ============================================
   REDUCED MOTION
============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .post-card:hover {
        transform: none;
    }
    
    .post-card:hover .post-card-image img {
        transform: none;
    }
}

/* ============================================
   HIGH CONTRAST MODE
============================================ */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #0000EE;
        --gray-200: #767676;
        --gray-400: #545454;
    }
    
    .post-card {
        border-width: 2px;
    }
    
    .nav-menu li a:focus,
    .search-input:focus,
    .hero-button:focus {
        outline: 3px solid currentColor;
        outline-offset: 2px;
    }
}

/* ============================================
   PRINT STYLES
============================================ */
@media print {
    /* Hide non-essential elements */
    .site-header,
    .hero-section,
    .search-section,
    .sidebar,
    .ad-space,
    .ad-widget,
    .pagination,
    .post-navigation,
    .related-posts,
    .comments-section,
    .site-footer,
    .ad-mobile-anchor,
    .share-buttons {
        display: none !important;
    }
    
    /* Reset colors for print */
    body {
        background: white;
        color: black;
        font-size: 12pt;
        line-height: 1.5;
    }
    
    .single-post-title {
        color: black;
        font-size: 18pt;
    }
    
    .single-post-content {
        max-width: 100%;
        padding: 0;
        border: none;
        box-shadow: none;
    }
    
    /* Ensure images don't break across pages */
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    /* Show link URLs */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }
}

/* ============================================
   SIDEBAR SEARCH SPECIFIC
============================================ */
.sidebar-search {
    display: flex;
    gap: var(--spacing-xs);
}

.sidebar-search .search-input {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
}

.sidebar-search .search-button {
    padding: var(--spacing-sm);
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   WIDGET SEARCH STYLES
============================================ */
.widget-search .search-form {
    display: flex;
    gap: var(--spacing-xs);
}

/* ============================================
   CATEGORY TAGS IN NO RESULTS
============================================ */
.category-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    justify-content: center;
    margin-top: var(--spacing-md);
}

.category-tags a {
    display: inline-block;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--gray-100);
    color: var(--gray-600);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.category-tags a:hover {
    background: var(--primary-color);
    color: var(--white);
}

/* ============================================
   SEARCH OVERLAY
============================================ */
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 20vh;
}

.search-overlay.active {
    display: flex;
}

.search-overlay-inner {
    width: 100%;
    max-width: 600px;
    padding: 0 var(--spacing-md);
}

.search-overlay-form {
    display: flex;
    gap: var(--spacing-sm);
}

.search-overlay-input {
    flex: 1;
    padding: var(--spacing-lg);
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--white);
    color: var(--white);
    font-size: 1.5rem;
}

.search-overlay-input:focus {
    outline: none;
}

.search-overlay-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.search-overlay-close {
    padding: var(--spacing-md);
    color: var(--white);
    background: transparent;
    border: none;
    cursor: pointer;
}

.search-results {
    margin-top: var(--spacing-xl);
    color: var(--white);
}

/* ============================================
   PLACEHOLDER IMAGE STYLES
============================================ */
.post-card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-200);
    color: var(--gray-400);
}

/* ============================================
   SHARE BUTTONS
============================================ */
.share-buttons {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-xl);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--gray-200);
}

.share-label {
    font-weight: 500;
    color: var(--gray-600);
    margin-right: var(--spacing-sm);
}

.share-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--gray-100);
    color: var(--gray-600);
    transition: all var(--transition-fast);
}

.share-button:hover {
    background: var(--primary-color);
    color: var(--white);
}

.share-twitter:hover {
    background: #1DA1F2;
}

.share-facebook:hover {
    background: #4267B2;
}

.share-linkedin:hover {
    background: #0077B5;
}

.share-whatsapp:hover {
    background: #25D366;
}

/* ============================================
   BREADCRUMBS
============================================ */
.breadcrumbs {
    padding: var(--spacing-md) 0;
    font-size: 0.875rem;
}

.breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-xs);
    list-style: none;
    padding: 0;
    margin: 0;
}

.breadcrumbs li {
    display: flex;
    align-items: center;
}

.breadcrumbs li:not(:last-child)::after {
    content: '/';
    margin-left: var(--spacing-xs);
    color: var(--gray-400);
}

.breadcrumbs a {
    color: var(--gray-500);
}

.breadcrumbs a:hover {
    color: var(--primary-color);
}

.breadcrumbs li:last-child span {
    color: var(--gray-700);
}

/* ============================================
   LOADING STATES
============================================ */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   THEME TOGGLE RESPONSIVE
============================================ */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.theme-toggle:hover {
    background: var(--surface-hover);
    color: var(--primary);
    border-color: var(--primary);
}

.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.theme-toggle .sun-icon {
    display: block;
}

.theme-toggle .moon-icon {
    display: none;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: none;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: block;
}

@media (max-width: 767px) {
    .theme-toggle {
        width: 36px;
        height: 36px;
    }
    
    .theme-toggle .sun-icon,
    .theme-toggle .moon-icon {
        width: 18px;
        height: 18px;
    }
}

/* ============================================
   MOBILE DROPDOWN MENUS
============================================ */
@media (max-width: 767px) {
    .mobile-nav-menu .has-dropdown > a {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .mobile-nav-menu .has-dropdown > a .dropdown-arrow {
        transition: transform 0.3s ease;
    }
    
    .mobile-nav-menu .has-dropdown.active > a .dropdown-arrow {
        transform: rotate(180deg);
    }
    
    .mobile-nav-menu .sub-menu {
        display: none;
        padding-left: var(--spacing-lg);
        background: var(--surface);
    }
    
    .mobile-nav-menu .has-dropdown.active > .sub-menu {
        display: block;
    }
    
    .mobile-nav-menu .sub-menu li a {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 0.9375rem;
        color: var(--text-secondary);
    }
    
    .mobile-nav-menu .sub-menu li a:hover {
        color: var(--primary);
    }
    
    /* Submenu toggle button */
    .submenu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        background: transparent;
        border: none;
        color: var(--text-secondary);
        cursor: pointer;
        padding: 0;
        margin-left: auto;
    }
    
    .submenu-toggle:hover {
        color: var(--primary);
    }
}

/* ============================================
   DESKTOP DROPDOWN MENUS
============================================ */
@media (min-width: 768px) {
    .nav-menu .menu-item-has-children > a {
        display: flex;
        align-items: center;
        gap: 4px;
    }
    
    .nav-menu .menu-item-has-children > a .dropdown-arrow {
        transition: transform 0.3s ease;
    }
    
    .nav-menu .menu-item-has-children:hover > a .dropdown-arrow {
        transform: rotate(180deg);
    }
    
    .nav-menu .sub-menu {
        position: absolute;
        top: 100%;
        left: 0;
        min-width: 200px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-lg);
        padding: var(--spacing-sm) 0;
        opacity: 0;
        visibility: hidden;
        transform: translateY(10px);
        transition: all 0.25s ease;
        z-index: 100;
    }
    
    .nav-menu .menu-item-has-children:hover > .sub-menu {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
    
    .nav-menu .sub-menu li {
        display: block;
    }
    
    .nav-menu .sub-menu li a {
        display: block;
        padding: var(--spacing-sm) var(--spacing-lg);
        color: var(--text-secondary);
        white-space: nowrap;
        transition: all 0.2s ease;
    }
    
    .nav-menu .sub-menu li a:hover {
        background: var(--surface-hover);
        color: var(--primary);
    }
    
    /* Nested submenus */
    .nav-menu .sub-menu .menu-item-has-children > .sub-menu {
        top: 0;
        left: 100%;
        margin-left: -1px;
    }
}

/* ============================================
   SEARCH OVERLAY IMPROVEMENTS
============================================ */
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    z-index: 10000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.search-overlay.active {
    opacity: 1;
    visibility: visible;
}

.search-overlay-inner {
    width: 100%;
    max-width: 700px;
    padding: 0 var(--spacing-lg);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.search-overlay.active .search-overlay-inner {
    transform: translateY(0);
}

.search-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-xl);
}

.search-overlay-title {
    color: white;
    font-size: 1.125rem;
    font-weight: 600;
}

.search-overlay-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--radius-full);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-overlay-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.search-overlay-form {
    position: relative;
    display: flex;
    align-items: center;
}

.search-overlay-input {
    width: 100%;
    padding: var(--spacing-lg) var(--spacing-xl);
    padding-right: 60px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-xl);
    color: white;
    font-size: 1.25rem;
    transition: all 0.2s ease;
}

.search-overlay-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.15);
}

.search-overlay-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.search-overlay-submit {
    position: absolute;
    right: 8px;
    width: 44px;
    height: 44px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-lg);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.search-overlay-submit:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.search-results-container {
    margin-top: var(--spacing-xl);
    max-height: 50vh;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-sm);
    transition: all 0.2s ease;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.search-result-thumb {
    width: 80px;
    height: 60px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.search-result-content {
    flex: 1;
}

.search-result-title {
    color: white;
    font-weight: 600;
    margin-bottom: 4px;
}

.search-result-date {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.875rem;
}

/* ============================================
   DARK THEME RESPONSIVE ADJUSTMENTS
============================================ */
[data-theme="dark"] {
    .post-card {
        background: var(--surface);
        border-color: var(--border);
    }
    
    .widget {
        background: var(--surface);
        border-color: var(--border);
    }
    
    .sidebar-search .search-input {
        background: var(--surface);
        border-color: var(--border);
        color: var(--text-primary);
    }
    
    .share-button {
        background: var(--surface);
        color: var(--text-secondary);
    }
    
    .breadcrumbs a {
        color: var(--text-secondary);
    }
    
    .category-tags a {
        background: var(--surface);
        color: var(--text-secondary);
    }
    
    .single-post-content {
        background: var(--surface);
    }
    
    /* Code blocks in dark mode */
    pre, code {
        background: var(--bg-secondary);
    }
}

/* ============================================
   HEADER ACTIONS RESPONSIVE
============================================ */
.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

@media (max-width: 767px) {
    .header-actions {
        gap: var(--spacing-xs);
    }
    
    .search-toggle {
        width: 36px;
        height: 36px;
    }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
============================================ */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: var(--spacing-sm) var(--spacing-md);
    z-index: 10000;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Hide focus ring for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
