/* Mobile-First Responsive Enhancements for NotesApp */

/* Touch-friendly interactions */
@media (pointer: coarse) {
    button, .btn, .nav-link, a[role="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1rem;
    }
    
    input, textarea, select {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Improved focus states for mobile */
@media (max-width: 768px) {
    button:focus,
    .btn:focus,
    input:focus,
    textarea:focus,
    select:focus,
    a:focus {
        outline: 3px solid var(--primary);
        outline-offset: 2px;
    }
}

/* Smooth scrolling and momentum scrolling */
* {
    -webkit-overflow-scrolling: touch;
}

html {
    scroll-behavior: smooth;
}

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Improved tap targets */
.tap-target {
    position: relative;
}

.tap-target::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    z-index: -1;
}

/* Mobile-specific utilities */
.mobile-hidden {
    display: none !important;
}

.mobile-visible {
    display: block !important;
}

@media (min-width: 769px) {
    .mobile-hidden {
        display: block !important;
    }
    
    .mobile-visible {
        display: none !important;
    }
}

/* Improved table responsiveness */
.responsive-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

@media (max-width: 768px) {
    .responsive-table {
        min-width: 600px;
        font-size: 0.85rem;
    }
    
    .responsive-table th,
    .responsive-table td {
        padding: 0.5rem 0.4rem;
        white-space: nowrap;
    }
    
    .responsive-table .action-column {
        position: sticky;
        right: 0;
        background-color: var(--surface-color);
        border-left: 1px solid var(--border-color);
    }
}

/* Card stacking for mobile */
@media (max-width: 768px) {
    .card-grid {
        display: block !important;
    }
    
    .card-grid > * {
        margin-bottom: 1rem;
        width: 100% !important;
    }
}

/* Form improvements for mobile */
@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
    }
    
    .form-row > * {
        width: 100% !important;
        margin-bottom: 0.75rem;
    }
    
    .form-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .form-actions .btn {
        width: 100%;
    }
}

/* Modal/Dialog mobile improvements */
@media (max-width: 768px) {
    .dialog-overlay {
        padding: 1rem;
    }
    
    .dialog-content {
        width: 100% !important;
        max-width: none !important;
        margin: 0;
        max-height: 90vh;
        border-radius: var(--radius);
    }
    
    .dialog-header {
        padding: 1rem;
        position: sticky;
        top: 0;
        background-color: var(--card);
        border-bottom: 1px solid var(--border);
        z-index: 10;
    }
    
    .dialog-footer {
        padding: 1rem;
        position: sticky;
        bottom: 0;
        background-color: var(--card);
        border-top: 1px solid var(--border);
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .dialog-footer .btn {
        width: 100%;
    }
}

/* Loading states */
.loading {
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--border);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Safe area padding for devices with notches */
@supports (padding: max(0px)) {
    .safe-area {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* Accessibility improvements */
@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;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    * {
        border-color: var(--foreground) !important;
    }
    
    .btn, button {
        border: 2px solid currentColor !important;
    }
}

/* Print styles */
@media print {
    .no-print,
    .mobile-nav-toggle,
    .mobile-nav-menu,
    .main-nav,
    .nav-links-footer {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .container {
        background: white !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0;
        margin: 0;
    }
}

/* Sidebar collapse on mobile */
@media (max-width: 768px) {
    /* Hide left sidebar navigation */
    aside, .sidebar, .w-64 {
        display: none !important;
    }
    /* Stack main container and make content full width */
    .flex.h-screen {
        flex-direction: column;
    }
    .flex.h-screen > .flex-1 {
        width: 100% !important;
        height: auto !important;
    }
    /* Remove fixed height on screen-filling elements */
    .h-screen {
        height: auto !important;
        min-height: 100vh;
    }
}

/* Center-align headers and actions on mobile */
@media (max-width: 768px) {
    /* Headers and section titles */
    .header,
    .workspace-header,
    .activity-header,
    .form-header,
    .dialog-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    /* Actions and buttons */
    .workspace-actions,
    .form-actions,
    .dialog-footer,
    .activity-actions {
        justify-content: center !important;
    }
    .btn,
    .footer-button,
    .nav-link {
        display: block;
        margin: 0.5rem auto;
        text-align: center;
    }
}
