/* Responsive Design for Mobile and Tablet Devices */

/* Tablet Styles (768px and below) */
@media screen and (max-width: 768px) {
    /* Header adjustments */
    .header-content {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }
    
    .logo-section {
        justify-content: center;
    }
    
    .logo-section h1 {
        font-size: 1.25rem;
    }
    
    .brand-text {
        font-size: 0.75rem;
    }
    
    .header-actions {
        justify-content: center;
    }
    
    /* Toolbar responsive */
    .toolbar {
        padding: 0.5rem;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .toolbar::-webkit-scrollbar {
        display: none;
    }
    
    .toolbar-section {
        flex-shrink: 0;
    }
    
    .toolbar-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        font-size: 1.125rem;
    }
    
    .toolbar-select {
        min-width: 100px;
        font-size: 0.75rem;
    }
    
    .toolbar-separator {
        margin: 0 0.25rem;
    }
    
    /* Content area responsive */
    .content-area {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        order: 2;
    }
    
    .rtl-layout .sidebar {
        border-left: none;
        border-bottom: 1px solid var(--border-color);
        order: 2;
    }
    
    .editor-container {
        order: 1;
        flex: 1;
    }
    
    .rtl-layout .editor-container {
        order: 1;
    }
    
    /* Sidebar content */
    .sidebar-content {
        display: flex;
        gap: 1rem;
        overflow-x: auto;
        padding: 0.75rem;
    }
    
    .stats-panel,
    .recent-docs-panel {
        min-width: 250px;
        flex-shrink: 0;
        margin-bottom: 0;
    }
    
    .ad-container {
        min-width: 300px;
        min-height: 200px;
        margin-bottom: 0;
    }
    
    /* Document header */
    .document-header {
        padding: 0.75rem;
    }
    
    .document-title-wrapper {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }
    
    .document-title {
        font-size: 1.125rem;
        text-align: center;
    }
    
    .save-status {
        justify-content: center;
    }
    
    /* Editor wrapper */
    .editor-wrapper {
        padding: 1rem;
    }
    
    .document-container {
        box-shadow: none;
        border-radius: 0;
    }
    
    .editor {
        padding: 1rem;
        min-height: calc(100vh - 300px);
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Status bar */
    .status-bar {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem;
    }
    
    .status-left,
    .status-right {
        width: 100%;
        justify-content: center;
    }
    
    .zoom-controls {
        justify-content: center;
    }
    
    .zoom-slider {
        width: 150px;
    }
    
    /* Footer */
    .footer-links {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .footer-text {
        margin-top: 0.5rem;
        font-size: 0.75rem;
    }
    
    /* Modal responsive */
    .modal {
        padding: 0.5rem;
    }
    
    .modal-content {
        max-width: 100%;
        max-height: 95vh;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .form-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn {
        width: 100%;
        text-align: center;
    }
    
    .export-options {
        grid-template-columns: 1fr;
    }
}

/* Mobile Styles (480px and below) */
@media screen and (max-width: 480px) {
    /* Further mobile optimizations */
    .app-header {
        padding: 0.5rem;
    }
    
    .logo-section h1 {
        font-size: 1rem;
    }
    
    .brand-text {
        display: none;
    }
    
    .header-actions {
        gap: 0.25rem;
    }
    
    .install-btn,
    .share-btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
    }
    
    /* Compact toolbar for mobile */
    .toolbar {
        padding: 0.25rem;
        gap: 0.25rem;
    }
    
    .toolbar-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 1rem;
    }
    
    .toolbar-select {
        min-width: 80px;
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .toolbar-separator {
        height: 20px;
        margin: 0 0.125rem;
    }
    
    /* Hide less critical toolbar items on small screens */
    .toolbar-section:nth-child(n+6) {
        display: none;
    }
    
    /* Sidebar completely collapsed on mobile */
    .sidebar {
        display: none;
    }
    
    /* Full-width editor on mobile */
    .content-area {
        flex-direction: column;
    }
    
    .editor-container {
        width: 100%;
    }
    
    .editor-wrapper {
        padding: 0.5rem;
    }
    
    .editor {
        padding: 0.75rem;
        font-size: 16px;
        line-height: 1.6;
    }
    
    /* Simplified status bar */
    .status-bar {
        padding: 0.5rem;
    }
    
    .status-item {
        font-size: 0.75rem;
    }
    
    .zoom-controls {
        display: none; /* Hide zoom on very small screens */
    }
    
    /* Mobile modal adjustments */
    .modal-header h3 {
        font-size: 1rem;
    }
    
    .form-group label {
        font-size: 0.875rem;
    }
    
    .form-input {
        padding: 0.625rem;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Touch-friendly buttons */
    .export-btn {
        padding: 1.25rem;
        font-size: 1rem;
    }
    
    .btn {
        padding: 1rem 1.5rem;
        font-size: 1rem;
        min-height: 44px;
    }
}

/* Large Desktop Styles (1200px and above) */
@media screen and (min-width: 1200px) {
    .header-content,
    .footer-content {
        max-width: 1600px;
    }
    
    .sidebar {
        width: 380px;
    }
    
    .document-container {
        max-width: 21cm; /* A4 width */
    }
    
    .editor {
        padding: 3cm 2.5cm; /* A4 margins */
    }
    
    .toolbar {
        padding: 0.75rem 1.5rem;
    }
    
    .stats-panel,
    .recent-docs-panel {
        padding: 1.25rem;
    }
}

/* Ultra-wide Screens (1600px and above) */
@media screen and (min-width: 1600px) {
    .content-area {
        max-width: 1800px;
        margin: 0 auto;
    }
    
    .sidebar {
        width: 420px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Increase tap targets for touch devices */
    .toolbar-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .btn {
        min-height: 44px;
        padding: 0.75rem 1.5rem;
    }
    
    .modal-close {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .toolbar-btn:hover,
    .btn:hover,
    .export-btn:hover {
        background: initial;
        color: initial;
    }
    
    /* Use active states instead */
    .toolbar-btn:active {
        background: var(--surface-color);
        transform: scale(0.95);
    }
    
    .btn:active {
        transform: scale(0.95);
    }
}

/* Print Styles */
@media print {
    .app-header,
    .toolbar,
    .sidebar,
    .status-bar,
    .app-footer,
    .modal {
        display: none !important;
    }
    
    .content-area {
        flex-direction: column;
    }
    
    .editor-container {
        width: 100%;
    }
    
    .document-header {
        padding: 0;
        border: none;
        background: transparent;
    }
    
    .document-title {
        font-size: 1.5rem;
        text-align: center;
        margin-bottom: 1rem;
        color: black;
    }
    
    .editor-wrapper {
        padding: 0;
        background: white;
    }
    
    .document-container {
        max-width: none;
        box-shadow: none;
        border-radius: 0;
        background: white;
    }
    
    .editor {
        padding: 0;
        color: black;
        background: white;
        font-size: 12pt;
        line-height: 1.6;
        min-height: auto;
    }
    
    .save-status {
        display: none;
    }
}

/* Landscape Orientation (Mobile) */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .content-area {
        flex-direction: row;
    }
    
    .sidebar {
        width: 300px;
        max-height: none;
        border-bottom: none;
        border-right: 1px solid var(--border-color);
        order: 1;
    }
    
    .rtl-layout .sidebar {
        border-left: 1px solid var(--border-color);
        border-right: none;
        order: 2;
    }
    
    .editor-container {
        order: 2;
    }
    
    .rtl-layout .editor-container {
        order: 1;
    }
    
    .sidebar-content {
        flex-direction: column;
        overflow-x: visible;
        overflow-y: auto;
    }
    
    .stats-panel,
    .recent-docs-panel,
    .ad-container {
        min-width: auto;
        margin-bottom: 1rem;
    }
}

/* High DPI / Retina Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .editor {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    .toolbar-btn i,
    .status-item i {
        transform: translateZ(0); /* Force hardware acceleration */
    }
}

/* Reduced Motion Preference */
@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;
    }
    
    .loading-spinner {
        animation: none;
        border: 4px solid rgba(255, 255, 255, 0.3);
        border-top-color: white;
    }
}

/* Dark Mode Support (Future Enhancement) */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1a1a1a;
        --surface-color: #2d2d2d;
        --text-primary: #ffffff;
        --text-secondary: #a0a0a0;
        --border-color: #404040;
    }
    
    .editor {
        background: var(--background-color);
        color: var(--text-primary);
    }
}

/* Focus Visible Enhancement */
@media (prefers-reduced-motion: no-preference) {
    .toolbar-btn:focus-visible,
    .btn:focus-visible,
    .form-input:focus-visible {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
    }
}

/* Container Queries (Future Enhancement) */
@supports (container-type: inline-size) {
    .toolbar {
        container-type: inline-size;
    }
    
    @container (max-width: 600px) {
        .toolbar-section:nth-child(n+5) {
            display: none;
        }
    }
}