/**
 * Mobile Responsive CSS - Full Mobile Optimization
 * Implements mobile-first design principles with touch-friendly interfaces
 */

/* ========================================
   MOBILE-FIRST BASE STYLES
   ======================================== */

/* Ensure proper box-sizing */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Improve touch scrolling on iOS */
body {
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* ========================================
   TOUCH TARGET IMPROVEMENTS
   ======================================== */

/* Minimum touch target size: 44x44px (Apple) / 48x48px (Google) */
@media (max-width: 768px) {
    /* All interactive elements */
    button,
    .toolbar-btn,
    .toolbar-btn-small,
    .sejda-toolbar-btn,
    .sejda-pos-btn-inline,
    .btn,
    a.btn {
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 10px 16px !important;
        font-size: 16px !important;
        touch-action: manipulation; /* Disable double-tap zoom */
    }
    
    /* Toolbar icons */
    .toolbar-icon {
        font-size: 20px !important;
    }
    
    /* Increase tap area for small controls */
    .sejda-pos-btn-inline {
        width: 44px !important;
        height: 44px !important;
        font-size: 18px !important;
    }
    
    /* Text boxes and interactive areas */
    .text-box {
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    /* Input fields */
    input[type="text"],
    input[type="number"],
    textarea,
    select {
        min-height: 44px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 12px !important;
    }
}

/* ========================================
   RESPONSIVE LAYOUT - SMALL PHONES
   ======================================== */

@media (max-width: 480px) {
    /* Body adjustments */
    body {
        font-size: 16px !important;
        line-height: 1.6;
    }
    
    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }
    
    /* Main container */
    .main-container,
    .pdf-container {
        padding: 8px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 70px !important; /* FIX: Extra space for fixed HUD on mobile */
    }
    
    /* Canvas area */
    #pdfCanvas {
        max-width: 100% !important;
        width: 100% !important;
        height: auto !important;
    }
    
    .canvas-container {
        padding: 0 !important;
        padding-bottom: 5rem !important; /* FIX: Ensure HUD doesn't block PDF content on mobile */
        margin: 0 !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Dialogs and modals */
    .dialog,
    .modal,
    .sejda-toolbar {
        min-width: 280px !important;
        width: 95vw !important;
        max-width: 95vw !important;
        left: 2.5vw !important;
        right: 2.5vw !important;
        margin: 0 !important;
    }
    
    /* Edit panels */
    .edit-panel,
    .sidebar,
    .right-panel {
        width: 100% !important;
        max-width: 100% !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        max-height: 70vh !important;
        border-radius: 16px 16px 0 0 !important;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25) !important;
        transform: translateY(100%);
        transition: transform 0.3s ease-in-out;
    }
    
    .edit-panel.active,
    .sidebar.active,
    .right-panel.active {
        transform: translateY(0);
    }
    
    /* Toolbar optimization */
    .toolbar-container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1000 !important;
        background: white !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    }
    
    .toolbar-header {
        padding: 8px 12px !important;
    }
    
    .toolbar-title h1 {
        font-size: 18px !important;
        margin: 0 !important;
    }
    
    .toolbar-content {
        display: flex !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        padding: 8px !important;
        gap: 8px !important;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
    }
    
    .toolbar-content::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }
    
    .toolbar-group {
        display: flex !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
    }
    
    /* Floating toolbar adjustments */
    .sejda-toolbar {
        position: fixed !important;
        bottom: 80px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        max-width: calc(100vw - 32px) !important;
        padding: 12px !important;
    }
    
    .sejda-toolbar-row {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
    
    /* Page navigation */
    .page-navigation {
        position: fixed !important;
        bottom: 16px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        background: white !important;
        padding: 12px 20px !important;
        border-radius: 24px !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
        display: flex !important;
        gap: 12px !important;
        align-items: center !important;
    }
    
    .page-navigation button {
        min-width: 44px !important;
        min-height: 44px !important;
        border-radius: 50% !important;
    }
}

/* ========================================
   RESPONSIVE LAYOUT - MEDIUM PHONES
   ======================================== */

@media (min-width: 481px) and (max-width: 767px) {
    body {
        font-size: 16px;
    }
    
    .toolbar-content {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .dialog,
    .modal {
        min-width: 320px !important;
        width: 90vw !important;
        max-width: 500px !important;
    }
    
    .edit-panel {
        width: 320px !important;
    }
}

/* ========================================
   RESPONSIVE LAYOUT - TABLETS
   ======================================== */

@media (min-width: 768px) and (max-width: 1024px) {
    .toolbar-content {
        justify-content: flex-start;
    }
    
    .edit-panel {
        width: 320px !important;
    }
    
    .sidebar {
        width: 240px !important;
    }
    
    /* Touch targets still important on tablets */
    button,
    .toolbar-btn {
        min-width: 40px !important;
        min-height: 40px !important;
    }
}

/* ========================================
   HAMBURGER MENU (Mobile)
   ======================================== */

@media (max-width: 768px) {
    /* Hamburger button */
    .hamburger-menu {
        display: block !important;
        position: fixed;
        top: 16px;
        right: 16px;
        z-index: 10001;
        width: 48px;
        height: 48px;
        background: var(--primary-color, #3b82f6);
        border: none;
        border-radius: 50%;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 0;
    }
    
    .hamburger-menu span {
        display: block;
        width: 24px;
        height: 3px;
        background: white;
        border-radius: 2px;
        transition: all 0.3s ease;
    }
    
    .hamburger-menu.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    
    .hamburger-menu.active span:nth-child(2) {
        opacity: 0;
    }
    
    .hamburger-menu.active span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -7px);
    }
    
    /* Mobile menu overlay */
    .mobile-menu-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9999;
        backdrop-filter: blur(4px);
    }
    
    .mobile-menu-overlay.active {
        display: block;
    }
    
    /* Mobile menu drawer */
    .mobile-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        max-width: 85vw;
        height: 100vh;
        background: white;
        z-index: 10000;
        overflow-y: auto;
        transition: right 0.3s ease;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
    }
    
    .mobile-menu.active {
        right: 0;
    }
    
    .mobile-menu-header {
        padding: 20px;
        background: var(--primary-color, #3b82f6);
        color: white;
    }
    
    .mobile-menu-content {
        padding: 16px;
    }
    
    .mobile-menu-section {
        margin-bottom: 24px;
    }
    
    .mobile-menu-section h3 {
        font-size: 14px;
        text-transform: uppercase;
        color: #6b7280;
        margin-bottom: 12px;
        font-weight: 600;
    }
    
    .mobile-menu-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px;
        border-radius: 8px;
        cursor: pointer;
        transition: background 0.2s;
        font-size: 16px;
    }
    
    .mobile-menu-item:hover,
    .mobile-menu-item:active {
        background: #f3f4f6;
    }
    
    .mobile-menu-item .icon {
        font-size: 24px;
        width: 32px;
        text-align: center;
    }
}

/* Hide hamburger on desktop */
@media (min-width: 769px) {
    .hamburger-menu,
    .mobile-menu-overlay,
    .mobile-menu {
        display: none !important;
    }
}

/* ========================================
   IMPROVED SCROLLING
   ======================================== */

@media (max-width: 768px) {
    /* Smooth scrolling */
    html {
        scroll-behavior: smooth;
    }
    
    /* Better scrollbars on mobile */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    
    ::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 2px;
    }
}

/* ========================================
   TOUCH GESTURES & INTERACTIONS
   ======================================== */

@media (max-width: 768px) {
    /* Prevent text selection during touch interactions */
    .canvas-container,
    .toolbar-btn,
    .sejda-toolbar {
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Active state for touch */
    button:active,
    .toolbar-btn:active,
    .btn:active {
        transform: scale(0.95);
        transition: transform 0.1s;
    }
    
    /* Ripple effect container */
    .ripple {
        position: relative;
        overflow: hidden;
    }
    
    .ripple::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.5);
        transform: translate(-50%, -50%);
        transition: width 0.6s, height 0.6s;
    }
    
    .ripple:active::after {
        width: 200px;
        height: 200px;
    }
}

/* ========================================
   SPACING & TYPOGRAPHY
   ======================================== */

@media (max-width: 480px) {
    /* Headings */
    h1 { font-size: 24px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }
    
    /* Paragraphs */
    p {
        font-size: 16px !important;
        line-height: 1.6 !important;
    }
    
    /* Better spacing */
    .section-spacing {
        margin-bottom: 24px !important;
    }
    
    .card,
    .panel {
        padding: 16px !important;
        margin: 8px !important;
    }
}

/* ========================================
   FORM IMPROVEMENTS
   ======================================== */

@media (max-width: 768px) {
    /* Form groups */
    .form-group {
        margin-bottom: 20px !important;
    }
    
    /* Labels */
    label {
        font-size: 16px !important;
        margin-bottom: 8px !important;
        display: block !important;
    }
    
    /* Inputs */
    input,
    textarea,
    select {
        width: 100% !important;
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 12px 16px !important;
        border-radius: 8px !important;
    }
    
    /* File upload */
    input[type="file"] {
        padding: 16px !important;
    }
    
    /* Checkbox and radio */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
    }
}

/* ========================================
   LOADING & FEEDBACK
   ======================================== */

@media (max-width: 768px) {
    .spinner {
        width: 48px !important;
        height: 48px !important;
        border-width: 4px !important;
    }
    
    .loading-message {
        font-size: 18px !important;
        margin-top: 16px !important;
    }
    
    /* Toast notifications */
    .toast,
    .notification {
        bottom: 80px !important; /* Above navigation */
        left: 16px !important;
        right: 16px !important;
        width: auto !important;
        font-size: 16px !important;
        padding: 16px !important;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Focus indicators for keyboard navigation */
@media (max-width: 768px) {
    *:focus {
        outline: 3px solid var(--primary-color, #3b82f6) !important;
        outline-offset: 2px !important;
    }
    
    /* Skip to content link */
    .skip-to-content {
        position: fixed;
        top: -100px;
        left: 16px;
        z-index: 10002;
        background: var(--primary-color, #3b82f6);
        color: white;
        padding: 12px 24px;
        border-radius: 8px;
        text-decoration: none;
        font-size: 16px;
        transition: top 0.3s;
    }
    
    .skip-to-content:focus {
        top: 16px;
    }
}

/* ========================================
   LANDSCAPE MODE
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .toolbar-container {
        position: static !important;
    }
    
    .page-navigation {
        bottom: 8px !important;
        padding: 8px 16px !important;
    }
    
    .sejda-toolbar {
        bottom: 60px !important;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .toolbar-container,
    .hamburger-menu,
    .mobile-menu,
    .page-navigation,
    .sejda-toolbar,
    button {
        display: none !important;
    }
    
    .main-container,
    #pdfCanvas {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Show/hide helpers */
.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
}

/* Full width on mobile */
@media (max-width: 768px) {
    .mobile-full-width {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Text alignment */
@media (max-width: 480px) {
    .mobile-text-center {
        text-align: center !important;
    }
}

/* Hide floating feedback button on mobile */
@media (max-width: 768px) {
    #feedback-button {
        display: none !important;
    }
    
    /* Hide fixed dark mode toggle button on mobile */
    .dark-mode-toggle {
        display: none !important;
    }
    
    /* Hide header bar with logo and site name on mobile */
    .toolbar-header {
        display: none !important;
    }
    
    /* Hide footer section on mobile */
    #main-footer {
        display: none !important;
    }
    
    /* Hide toolbar help/resource buttons on mobile */
    .toolbar-group:has(.toolbar-btn-small[title="Tutorials"]),
    .toolbar-group:has(.toolbar-btn-small[title="Blog"]) {
        display: none !important;
    }
    
    /* Hide offline indicator on mobile (not using PWA) */
    .offline-indicator {
        display: none !important;
    }
    
    /* Hide green floating edit button on mobile */
    .mobile-edit-trigger {
        display: none !important;
    }
    
    /* Hide original hamburger menu on mobile (top-left) */
    .hamburger-menu {
        display: none !important;
    }
    
    /* Show HUD hamburger menu on mobile */
    .hud-hamburger-menu {
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        padding: 0.5rem;
        cursor: pointer;
        color: #495057;
        transition: color 0.2s ease;
    }
    
    .hud-hamburger-menu:hover,
    .hud-hamburger-menu:active {
        color: #667eea;
    }
    
    .hud-hamburger-menu svg {
        width: 24px;
        height: 24px;
    }
}
