/**
 * Responsive Styles for Tokutei Theme
 *
 * @package Tokutei
 * @since 1.0.0
 */

/* ==========================================================================
   Desktop (min-width: 769px) - Ensure proper flexbox layout
   ========================================================================== */

@media (min-width: 769px) {
    .header-inner {
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        justify-content: space-between;
    }

    .site-branding {
        flex-shrink: 0;
    }

    /* CRITICAL: Hide menu-toggle on desktop */
    .menu-toggle {
        display: none !important;
    }

    .main-navigation {
        display: flex !important;
        flex: 1;
        align-items: center;
    }

    .primary-menu-wrapper {
        display: block !important;
        flex: 1;
    }

    .header-actions {
        flex-shrink: 0;
        margin-left: auto;
    }

    .user-menu {
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .user-menu-dropdown {
        display: none;
    }

    .user-menu-dropdown.active {
        display: block;
    }
}

/* ==========================================================================
   Tablet (max-width: 1024px)
   ========================================================================== */

@media (max-width: 1024px) {
    .header-inner {
        padding: 0.75rem 0;
    }

    .primary-menu {
        gap: 0.25rem;
    }

    .primary-menu .menu-item a {
        padding: 0.625rem 1rem;
        font-size: 0.9375rem;
    }

    .hero-title {
        font-size: 2.5rem;
    }

    .section-title {
        font-size: 2rem;
    }

    .features-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
}

/* ==========================================================================
   Mobile (max-width: 768px)
   ========================================================================== */

@media (max-width: 768px) {
    /* Header - 3-column grid layout: logo | main-navigation (toggle) | user-link */
    .header-inner {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 0.5rem;
        align-items: center;
        position: relative;
        z-index: 100;
    }

    /* Logo - first column (left aligned) */
    .site-branding {
        grid-column: 1;
        grid-row: 1;
        justify-self: start;
        display: flex;
        align-items: center;
    }

    .site-logo img,
    .default-logo {
        max-height: 40px;
        max-width: 120px;
        display: block;
    }

    /* Main navigation - spans both rows */
    .main-navigation {
        grid-column: 1 / -1;
        grid-row: 1 / 3;
        display: contents; /* Make children participate in grid */
    }

    /* Menu toggle - visible and centered in column 2, row 1 */
    .menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        grid-column: 2;
        grid-row: 1;
        justify-self: center;
    }

    /* Primary menu wrapper - spans full width on row 2 */
    .primary-menu-wrapper {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
    }

    /* Header actions (user link) - third column (right aligned) */
    .header-actions {
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
    }

    .header-actions .user-menu {
        gap: 0;
    }

    .header-actions .user-link {
        font-size: 0.875rem;
        padding: 0.375rem 0.75rem;
        cursor: pointer;
        background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
        border: 2px solid #ff6b6b;
    }

    .header-actions .user-link img {
        width: 32px;
        height: 32px;
        border: 2px solid #ff6b6b;
    }

    .header-actions .user-link span {
        display: none;
    }

    /* Show user icon indicator on mobile for better recognition */
    .header-actions .user-link::after {
        opacity: 1;
        top: -6px;
        right: -6px;
        width: 22px;
        height: 22px;
        font-size: 12px;
    }

    /* Enhanced dropdown on mobile */
    .user-menu-dropdown {
        display: none;
        min-width: 300px;
        max-width: 90vw;
    }

    .user-menu-dropdown.active {
        display: block;
    }

    .user-info-header {
        padding: 1rem;
    }

    .user-display-name {
        font-size: 1rem;
    }

    .user-username {
        font-size: 0.8125rem;
    }

    .user-info-body {
        padding: 0.75rem;
    }

    .user-action-link {
        padding: 0.875rem 1rem;
        font-size: 0.9375rem;
    }

    /* Primary menu wrapper visibility controlled by grid positioning above */
    .primary-menu-wrapper.active {
        display: block;
    }

    .primary-menu {
        flex-direction: column;
        gap: 0;
        background: linear-gradient(135deg, #fff5f5 0%, #ffffff 100%);
        border-radius: 12px;
        padding: 0.5rem;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    .primary-menu .menu-item {
        width: 100%;
    }

    .primary-menu .menu-item a {
        width: 100%;
        padding: 1rem;
        justify-content: flex-start;
        border-radius: 8px;
    }

    .primary-menu .menu-item + .menu-item a {
        margin-top: 0.25rem;
    }

    /* Hero */
    .hero-section {
        padding: 4rem 0;
    }

    .hero-title {
        font-size: 2rem;
    }

    .hero-description {
        font-size: 1.125rem;
    }

    .hero-actions {
        flex-direction: column;
        align-items: center;
    }

    .hero-actions .btn {
        width: 100%;
        max-width: 300px;
    }

    /* Sections */
    section {
        padding: 3rem 0;
    }

    .section-title {
        font-size: 1.75rem;
        margin-bottom: 2rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    /* Features */
    .features-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .feature-card {
        padding: 2rem;
    }

    /* Posts Grid */
    .posts-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    /* CTA */
    .cta-section {
        padding: 4rem 0;
    }

    .cta-title {
        font-size: 2rem;
    }

    .cta-description {
        font-size: 1.125rem;
    }

    /* Footer */
    .footer-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .footer-widgets-grid {
        grid-template-columns: 1fr;
    }

    .footer-bottom-content {
        flex-direction: column;
        text-align: center;
    }

    /* Back to Top */
    .back-to-top {
        bottom: 1rem;
        right: 1rem;
        width: 45px;
        height: 45px;
    }
}

/* ==========================================================================
   Small Mobile (max-width: 480px)
   ========================================================================== */

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .site-container {
        padding: 0 1rem;
    }

    .hero-title {
        font-size: 1.75rem;
    }

    .hero-description {
        font-size: 1rem;
    }

    .section-title {
        font-size: 1.5rem;
    }

    .feature-card {
        padding: 1.5rem;
    }

    .feature-icon {
        font-size: 3rem;
    }

    .cta-title {
        font-size: 1.75rem;
    }

    .btn {
        padding: 0.875rem 1.5rem;
    }

    .btn-large {
        padding: 1rem 2rem;
        font-size: 1rem;
    }

    .contact-item {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ==========================================================================
   Landscape Orientation (Mobile)
   ========================================================================== */

@media (max-height: 500px) and (orientation: landscape) {
    .hero-section {
        padding: 2rem 0;
    }

    .cta-section {
        padding: 2rem 0;
    }
}

/* ==========================================================================
   Mobile Touch Targets - WCAG 2.1 Level AAA (44x44px minimum)
   ========================================================================== */

@media (max-width: 768px) {
    /* Navigation and menu items */
    .primary-menu a,
    .footer-menu a {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .menu-toggle {
        min-height: 44px;
        min-width: 44px;
        padding: 12px;
    }

    /* Buttons */
    .btn,
    button:not(.menu-toggle),
    input[type="submit"],
    input[type="button"],
    input[type="reset"] {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 16px;
    }

    /* Links in content */
    .entry-content a,
    .widget a {
        padding: 4px 0;
        display: inline-block;
        line-height: 1.6;
    }

    /* Social media links */
    .social-links a,
    .share-button {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 10px;
    }

    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="number"],
    input[type="date"],
    textarea,
    select {
        min-height: 44px;
        padding: 12px;
        font-size: 16px; /* Prevents iOS auto-zoom */
        line-height: 1.5;
    }

    textarea {
        min-height: 88px; /* At least 2 lines */
    }

    /* Checkboxes and radio buttons */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
        margin-right: 12px;
    }

    input[type="checkbox"] + label,
    input[type="radio"] + label {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 10px 0;
    }

    /* Pagination links */
    .pagination a,
    .pagination span {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 10px 12px;
    }

    /* Breadcrumb items */
    .breadcrumb-item a {
        min-height: 44px;
        padding: 10px 8px;
        display: inline-flex;
        align-items: center;
    }

    /* Back to top button */
    #back-to-top {
        min-width: 48px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Login/logout links */
    .login-link,
    .logout-link,
    .user-menu a {
        min-height: 44px;
        padding: 10px 16px;
        display: inline-flex;
        align-items: center;
    }

    /* Close buttons */
    .close,
    .modal-close,
    [aria-label*="close"],
    [aria-label*="Close"] {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }

    /* Card/item links */
    .post-card a,
    .grammar-card a,
    .exam-card a {
        min-height: 44px;
        padding: 12px;
    }

    /* Dropdown toggles */
    .dropdown-toggle,
    [aria-haspopup="true"] {
        min-height: 44px;
        padding: 12px 16px;
    }

    /* Tab navigation */
    .tab-list button,
    .tab-list a {
        min-height: 44px;
        padding: 12px 20px;
    }

    /* Accordion headers */
    .accordion-header,
    .accordion-toggle {
        min-height: 44px;
        padding: 12px 16px;
    }

    /* Icon-only buttons - slightly larger */
    button[aria-label]:not([aria-label=""]):empty,
    a[aria-label]:not([aria-label=""]):empty {
        min-width: 48px;
        min-height: 48px;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .site-header,
    .ad-banner-section,
    .site-footer,
    .back-to-top,
    .menu-toggle,
    .header-actions {
        display: none !important;
    }

    body {
        background: #fff;
    }

    body::before {
        display: none;
    }

    a {
        text-decoration: underline;
    }

    .content-wrapper {
        padding: 0;
    }
}
