/* Nosaya Responsive Design */

/* Desktop (Default) - Already handled in global.css */

/* Tablet (768px - 1023px) */
@media (max-width: 1023px) {
    .container {
        padding: 0 var(--spacing-md);
    }

    /* Sidebar - collapsed on tablet */
    .sidebar {
        width: var(--sidebar-collapsed-width);
    }

    .sidebar-header .logo-text,
    .sidebar-link span,
    .sidebar-footer-link span {
        display: none;
    }

    .sidebar-link,
    .sidebar-footer-link {
        justify-content: center;
        padding: var(--spacing-sm);
    }

    /* Main content - collapsed sidebar margin on tablet */
    .main-content {
        margin-left: var(--sidebar-collapsed-width);
    }



    /* Cards */
    .card {
        padding: var(--spacing-md);
    }

    /* Typography */
    h1 { font-size: var(--text-3xl); }
    h2 { font-size: var(--text-2xl); }
    h3 { font-size: var(--text-xl); }
}

/* Mobile (320px - 767px) */
@media (max-width: 767px) {
    /* Layout */
    .container {
        padding: 0 var(--spacing-sm);
        max-width: 100%;
    }

    /* Auth pages specific improvements */
    .auth-container {
        padding: var(--spacing-lg) var(--spacing-md);
        min-height: 100vh;
    }

    .auth-card {
        padding: var(--spacing-xl) var(--spacing-lg);
        max-width: 100%;
    }

    /* Onboarding specific improvements */
    .onboarding-container {
        padding: var(--spacing-md);
    }

    .onboarding-card {
        padding: var(--spacing-lg);
    }

    .onboarding-title {
        font-size: var(--text-2xl);
    }

    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-sm);
    }

    .notification-checkbox {
        padding: var(--spacing-md);
    }

    .onboarding-actions {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .onboarding-actions .btn {
        width: 100%;
    }

    /* Mobile sidebar - slide-out drawer */
    .sidebar {
        display: flex;
        position: fixed;
        left: -100%;
        width: 280px;
        max-width: 85vw;
        transform: none;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1050;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        height: 100vh;
        overflow-y: auto;
    }

    .sidebar.mobile-open {
        left: 0;
        transform: none;
    }

    /* Hide sidebar completely in mobile when Arabic (RTL) is selected */
    [dir="rtl"] .sidebar {
        display: none !important;
    }

    /* Hide mobile sidebar overlay in RTL */
    [dir="rtl"] .mobile-sidebar-overlay {
        display: none !important;
    }

    /* RTL adjustments for mobile */
    [dir="rtl"] .main-content {
        margin-left: 0;
        margin-right: 0;
        width: 100%;
        max-width: 100%;
    }

    [dir="rtl"] .header {
        margin-left: 0;
        margin-right: 0;
        width: 100%;
        max-width: 100%;
    }

    [dir="rtl"] .page-content {
        padding-right: var(--spacing-md);
        padding-left: var(--spacing-md);
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    [dir="rtl"] .app-container {
        direction: rtl;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    [dir="rtl"] body {
        overflow-x: hidden;
        width: 100%;
    }

    /* RTL adjustments for dashboard components */
    [dir="rtl"] .dash-stats-grid {
        width: 100%;
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    [dir="rtl"] .dash-stat-card {
        width: 100%;
    }

    [dir="rtl"] .dash-charts-row {
        width: 100%;
        flex-direction: column;
        gap: var(--spacing-md);
    }

    [dir="rtl"] .dash-chart-card,
    [dir="rtl"] .dash-completion-card {
        width: 100%;
    }

    .mobile-sidebar-close {
        display: flex !important;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
    }

    .mobile-sidebar-overlay {
        display: none;
    }

    .mobile-sidebar-overlay.active {
        display: block;
        animation: fadeIn 0.3s ease-out;
    }

    /* Hide mobile menu toggle */
    .mobile-menu-toggle {
        display: none !important;
        pointer-events: none !important;
    }

    /* Enhanced Touch Targets */
    .btn,
    .card-interactive,
    .tab {
        min-height: 48px;
        min-width: 48px;
    }

    .notification-bell {
        min-width: 44px;
        min-height: 44px;
    }

    .user-menu-button {
        min-width: 44px;
        min-height: 44px;
        padding: var(--spacing-sm);
    }

    /* Main content - no sidebar margin on mobile */
    .main-content {
        margin-left: 0;
        padding-bottom: calc(var(--bottom-nav-height) + var(--spacing-md));
    }

    /* Header */
    .header {
        padding: var(--spacing-sm) var(--spacing-md);
        height: auto;
        min-height: 56px;
        margin-left: 0;
        gap: var(--spacing-sm);
        padding-top: max(var(--spacing-sm), env(safe-area-inset-top));
        display: flex;
        align-items: center;
    }

    .header-content {
        gap: var(--spacing-xs);
        flex: 1;
        display: flex;
        align-items: center;
    }

    .header-title {
        font-size: var(--text-lg);
    }

    .header-actions {
        gap: var(--spacing-xs);
    }

    /* Hide search bar on mobile header */
    .search-bar {
        display: none;
    }

    /* Hide mockup demos on mobile */
    .hero-mockup,
    .planner-demo,
    .focus-demo {
        display: none;
    }



    /* Compact user menu button on mobile */
    .user-menu-button {
        padding: 4px 8px;
    }

    .user-menu-button .user-info {
        display: none;
    }

    /* Compact coin display on mobile */
    .coin-display {
        font-size: var(--text-sm);
    }

    /* Compact notification bell on mobile */
    .notification-bell {
        width: 36px;
        height: 36px;
    }

    /* Cards */
    .card {
        padding: var(--spacing-md);
        border-radius: var(--radius-lg);
        margin-bottom: var(--spacing-md);
    }

    .card-header {
        padding-bottom: var(--spacing-sm);
        margin-bottom: var(--spacing-sm);
    }

    .card-title {
        font-size: var(--text-lg);
    }

    .card:hover {
        transform: none;
    }

    /* Buttons */
    .btn {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: var(--text-sm);
    }

    .btn-lg {
        padding: var(--spacing-md) var(--spacing-lg);
        font-size: var(--text-base);
    }

    /* Forms */
    .form-input,
    .form-select,
    .form-textarea {
        padding: var(--spacing-md);
        font-size: 16px; /* Prevent iOS zoom */
        min-height: 44px;
    }

    .form-checkbox,
    .form-radio {
        width: 1.5rem;
        height: 1.5rem;
    }

    /* Modal */
    .modal {
        margin: var(--spacing-sm);
        max-height: calc(100vh - var(--spacing-lg));
        border-radius: var(--radius-lg);
        width: calc(100% - var(--spacing-lg));
        max-width: none;
        box-sizing: border-box;
        position: relative;
        z-index: var(--z-modal);
    }

    .modal-backdrop {
        padding: var(--spacing-sm);
        box-sizing: border-box;
        overflow: hidden;
        align-items: center;
        justify-content: center;
    }

    .modal-backdrop.positioned {
        align-items: flex-start;
        justify-content: flex-start;
    }

    .modal-backdrop.positioned .modal {
        position: absolute;
        margin: 0;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--spacing-md);
    }

    /* Page selector modal specific mobile styles */
    #pageSelectorModal .modal {
        max-width: 95%;
        max-height: 85vh;
    }

    #pageSelectorModal .page-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--spacing-sm);
    }

    #pageSelectorModal .page-card {
        padding: var(--spacing-sm);
    }

    #pageSelectorModal .page-icon {
        font-size: 1.25rem;
    }

    #pageSelectorModal .page-name {
        font-size: var(--text-xs);
    }

    /* Improved Scroll Experience */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Safe Area Support for Notched Devices */
    @supports (padding: max(0px)) {
        .main-content {
            padding-bottom: max(var(--spacing-md), env(safe-area-inset-bottom));
        }
    }

    /* Performance Optimizations for Mobile */
    .card,
    .feature-card,
    .gh-card,
    .gamify-card,
    .hero-mockup,
    .planner-demo,
    .focus-demo,
    .stats-preview {
        transform: none !important;
        perspective: none !important;
        transform-style: flat !important;
    }

    .card:hover,
    .feature-card:hover,
    .gh-card:hover,
    .gamify-card:hover,
    .hero-mockup:hover,
    .planner-demo:hover,
    .focus-demo:hover,
    .stats-preview:hover {
        transform: translateY(-4px) !important;
    }

    /* Simplified animations for mobile */
    .animate-float3d,
    .animate-tilt3d,
    .animate-pulse3d {
        animation: none !important;
    }

    /* Optimize for GPU acceleration */
    .card,
    .btn {
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    /* Reduce complex shadows on mobile */
    .card,
    .feature-card,
    .gh-card,
    .gamify-card {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    .card:hover,
    .feature-card:hover,
    .gh-card:hover,
    .gamify-card:hover {
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
    }

    /* Improved Typography for Mobile */
    body {
        font-size: 16px;
        line-height: 1.5;
    }

    p {
        margin-bottom: var(--spacing-md);
        font-size: var(--text-base);
    }

    /* Better spacing between sections */
    section {
        padding: var(--spacing-xl) 0;
    }

    /* Improved reading experience */
    .feature-description,
    .gh-description,
    .gamify-description {
        font-size: var(--text-sm);
        line-height: 1.6;
    }

    /* Better button spacing */
    .btn-group {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .btn-group .btn {
        width: 100%;
    }

    /* Improve list spacing */
    ul, ol {
        margin-bottom: var(--spacing-md);
        padding-left: var(--spacing-md);
    }

    li {
        margin-bottom: var(--spacing-sm);
    }

    /* Better form spacing */
    .form-group {
        margin-bottom: var(--spacing-md);
    }

    /* Improve header spacing */
    .header {
        margin-bottom: var(--spacing-md);
    }

    /* Better card spacing */
    .card {
        margin-bottom: var(--spacing-md);
    }

    /* Improve stats display */
    .stat-number {
        font-size: var(--text-xl);
    }

    .stat-label {
        font-size: var(--text-xs);
    }

    /* Mobile-specific UI improvements */
    /* Smooth scroll snap for horizontal lists */
    .features-grid,
    .goals-habits-grid,
    .gamification-features {
        scroll-snap-type: y mandatory;
    }

    .feature-card,
    .gh-card,
    .gamify-card {
        scroll-snap-align: start;
    }

    /* Better mobile sidebar interactions */
    .sidebar-link:active,
    .sidebar-footer-link:active {
        background-color: var(--primary-100);
        transform: scale(0.98);
    }

    /* Better scroll behavior */
    html {
        scroll-behavior: smooth;
    }

    /* Improve horizontal scrolling for tables */
    .table-responsive {
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        scroll-snap-align: start;
    }

    /* Pull-to-refresh hint */
    .main-content::before {
        content: '';
        position: absolute;
        top: -60px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 40px;
        background: var(--primary-100);
        border-radius: 50%;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .main-content:active::before {
        opacity: 1;
    }

    /* Better scrollbar styling for mobile */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }

    ::-webkit-scrollbar-thumb {
        background: var(--primary-300);
        border-radius: var(--radius-full);
    }

    /* Hide scrollbars but keep functionality */
    .navbar-menu,
    .table-responsive {
        scrollbar-width: thin;
        -ms-overflow-style: none;
    }

    .navbar-menu::-webkit-scrollbar,
    .table-responsive::-webkit-scrollbar {
        display: none;
    }

    /* Improved touch feedback for interactive elements */
    .card-interactive:active,
    .feature-card:active,
    .gh-card:active,
    .gamify-card:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    /* Better loading states for mobile */
    .loading-spinner {
        width: 32px;
        height: 32px;
        border-width: 3px;
    }

    /* Improved modal experience on mobile */
    .modal {
        width: 95%;
        max-height: 85vh;
        margin: var(--spacing-sm);
        position: relative;
        z-index: var(--z-modal);
    }

    .modal-backdrop {
        align-items: center;
        justify-content: center;
    }

    .modal-backdrop.positioned {
        align-items: flex-start;
        justify-content: flex-start;
    }

    .modal-backdrop.positioned .modal {
        position: absolute;
        margin: 0;
    }

    .modal-body {
        max-height: calc(85vh - 180px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Better toast notifications on mobile */
    .toast-container {
        position: fixed;
        top: var(--spacing-lg);
        bottom: auto;
        left: var(--spacing-sm);
        right: var(--spacing-sm);
        z-index: var(--z-modal);
        max-width: none;
    }

    .toast {
        margin-bottom: var(--spacing-sm);
        min-width: auto;
    }

    .toast-close {
        width: 36px;
        height: 36px;
        font-size: 1.25rem;
    }

    /* Improve image handling on mobile */
    img {
        max-width: 100%;
        height: auto;
        object-fit: cover;
    }

    /* Better video handling */
    video {
        max-width: 100%;
        height: auto;
    }

    /* Improved accessibility for mobile */
    .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;
    }

    /* Focus states for keyboard navigation */
    :focus-visible {
        outline: 3px solid var(--primary-400);
        outline-offset: 2px;
    }
}

/* Small Mobile (320px - 374px) */
@media (max-width: 374px) {
    .container {
        padding: 0 var(--spacing-xs);
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .btn {
        width: 100%;
    }

    .btn-group {
        flex-direction: column;
    }

    .btn-group .btn {
        width: 100%;
    }

    /* Page selector modal for very small screens */
    #pageSelectorModal .page-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Large Desktop (1440px+) */
@media (min-width: 1440px) {
    .container {
        max-width: 1400px;
    }
}

/* Print Styles */
@media print {
    .header,
    .btn,
    .modal-backdrop,
    .toast-container,
    .sidebar,
    .bottom-nav,
    .navbar {
        display: none !important;
    }

    .main-content {
        padding: 0;
        margin: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid var(--border);
    }

    body {
        background-color: white;
        color: black;
    }

    .app-container {
        display: block;
    }
}

/* Touch Devices */
@media (hover: none) and (pointer: coarse) {
    .btn:hover,
    .card-interactive:hover,
    .tab:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.98);
    }

    .card-interactive:active {
        transform: scale(0.98);
    }

    /* Larger touch targets */
    .btn,
    .tab {
        min-height: 44px;
        min-width: 44px;
    }

    .form-checkbox,
    .form-radio {
        width: 1.5rem;
        height: 1.5rem;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Retina-specific adjustments if needed */
}

/* Landscape Orientation */
@media (max-height: 500px) and (orientation: landscape) {
    .modal {
        max-height: 90vh;
    }

    .focus-timer {
        font-size: var(--text-3xl);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

