/* ============================================
   MOBILE-FIRST RESPONSIVE STYLES
   ============================================ */

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

/* Mobile Navigation - Bottom Tab Bar - Touch devices in any orientation */
@media (max-width: 1024px) and (hover: none) {
    /* Show mobile header */
    .mobile-header {
        display: flex;
    }
    
    /* Move top-bar to bottom and show only nav */
    .top-bar {
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
        z-index: 1000;
    }
    
    body.dark-mode .top-bar {
        box-shadow: 0 -2px 8px rgba(0,0,0,0.3);
    }
    
    .top-bar .container {
        padding: 8px 4px 12px 4px !important;
        max-width: 100% !important;
        display: flex;
        justify-content: center;
    }
    
    /* Hide logo and logout on mobile, only show nav */
    .top-bar .container > div:first-child,
    .top-bar .container > div:last-child {
        display: none !important;
    }
    
    /* Ensure nav is visible and centered */
    .top-bar .nav {
        display: flex !important;
    }
    
    /* Mobile nav styling */
    .nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 100%;
        gap: 0;
        margin: 0;
    }
    
    .nav-link {
        flex-direction: column !important;
        gap: 2px !important;
        padding: 8px 4px !important;
        font-size: 0.65rem !important;
        flex: 1;
        text-align: center;
        min-width: 0;
        white-space: nowrap;
        border-radius: 0 !important;
    }
    
    .nav-link .material-icons {
        font-size: 22px !important;
    }
    
    /* Hide Dashboard from bottom nav on mobile */
    .nav-link.mobile-hide {
        display: none !important;
    }
    
    /* Show short nav labels on mobile */
    .nav-label {
        display: block !important;
        font-size: 0.65rem !important;
    }
    
    /* Active state for mobile nav */
    .nav-link.active {
        background: none !important;
        color: var(--primary-color) !important;
    }
    
    .nav-link:hover {
        background: none !important;
    }
    
    /* Mobile header dashboard button */
    .mobile-header-actions .nav-link {
        padding: 8px !important;
        flex-direction: row !important;
        gap: 0 !important;
        font-size: 1rem !important;
    }
    
    .mobile-header-actions .nav-link.active {
        color: var(--primary-color) !important;
    }
    
    /* Add padding to main content for bottom nav */
    main.container {
        padding-bottom: 80px !important;
    }
    
    /* Mobile header with logo and actions */
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: var(--surface);
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        z-index: 999;
        padding: 12px 16px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    body.dark-mode .mobile-header {
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    }
    
    .mobile-header-logo {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .mobile-header-logo h1 {
        margin: 0;
        font-size: 1.25rem;
    }
    
    .mobile-header-actions {
        display: flex;
        gap: 4px;
        align-items: center;
    }
    
    .mobile-header-actions .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Add padding to page content for mobile header */
    #mainApp .py-lg {
        padding-top: 68px !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
        padding-bottom: 12px !important;
    }
    
    /* Ensure main content has proper spacing */
    #mainApp main.container {
        padding: 0 !important;
    }
}

/* Compact Cards on Mobile */
@media (max-width: 1024px) and (hover: none) {
    .card {
        padding: 14px;
        margin-bottom: 12px;
    }
    
    .stat-card {
        padding: 10px;
    }
    
    .stat-value {
        font-size: 1.4rem;
        margin: 6px 0;
    }
    
    h1 {
        font-size: 1.6rem;
        margin-bottom: 8px;
    }
    
    h2 {
        font-size: 1.35rem;
    }
    
    h3 {
        font-size: 1.15rem;
    }
    
    /* Page header styling */
    .flex.items-center.justify-between.mb-lg {
        margin-bottom: 16px;
    }
    
    .flex.items-center.justify-between.mb-lg h1 {
        margin: 0;
        font-size: 1.5rem;
    }
}

/* Responsive Grids */
@media (max-width: 1024px) and (hover: none) {
    .grid-4,
    .grid-3,
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    /* Special case: forms with 4 columns should wrap better */
    .form-group .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile-Friendly Tables */
@media (max-width: 1024px) and (hover: none) {
    .data-table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }
    
    .data-table table {
        font-size: 0.85rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 8px 6px;
        white-space: nowrap;
    }
    
    /* REMOVE ALL STICKY - everything scrolls together */
    .data-table *,
    .data-table td,
    .data-table th,
    .data-table tr,
    .data-table tbody,
    .data-table thead {
        position: static !important;
        left: auto !important;
        z-index: auto !important;
    }
}

/* Touch-Friendly Buttons */
@media (max-width: 1024px) and (hover: none) {
    .btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 0.95rem;
    }
    
    .btn-sm {
        min-height: 38px;
        padding: 8px 12px;
    }
    
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }
    
    .btn-block {
        width: 100%;
    }
}

/* Mobile Form Inputs */
@media (max-width: 1024px) and (hover: none) {
    .text-input,
    .select-input,
    .textarea-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 10px 12px;
        min-height: 44px;
    }
    
    .form-group {
        margin-bottom: 14px;
    }
    
    label {
        margin-bottom: 4px;
        font-size: 0.85rem;
        font-weight: 500;
        display: block;
    }
    
    /* Grid form fields should align properly */
    form .grid-2,
    form .grid-3,
    form .grid-4 {
        gap: 12px;
    }
}

/* Mobile Modal/Dialog */
@media (max-width: 1024px) and (hover: none) {
    [style*="position: fixed"][style*="z-index: 1000"] > .card {
        max-width: 95% !important;
        margin: 16px;
        max-height: 85vh !important;
    }
}

/* Compact Flex Layouts */
@media (max-width: 1024px) and (hover: none) {
    .flex.items-center.justify-between {
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .flex.gap-lg {
        gap: 8px;
    }
    
    .flex.gap-md {
        gap: 6px;
    }
}

/* Hide desktop-only elements on mobile */
@media (max-width: 1024px) and (hover: none) {
    .hide-mobile {
        display: none !important;
    }
}

/* Adjust spacing for mobile */
@media (max-width: 1024px) and (hover: none) {
    .mb-xl {
        margin-bottom: 20px;
    }
    
    .mb-lg {
        margin-bottom: 14px;
    }
    
    .mb-md {
        margin-bottom: 10px;
    }
    
    .mb-sm {
        margin-bottom: 6px;
    }
    
    .mb-xs {
        margin-bottom: 4px;
    }
    
    /* Page title spacing */
    h1 + p.text-secondary {
        margin-top: -8px;
    }
}

/* Better text readability on mobile */
@media (max-width: 1024px) and (hover: none) {
    body {
        font-size: 15px;
        line-height: 1.5;
    }
    
    .text-sm {
        font-size: 0.85rem;
    }
    
    .text-xs {
        font-size: 0.75rem;
    }
}

/* Mobile Badge Sizing */
@media (max-width: 1024px) and (hover: none) {
    .badge {
        padding: 4px 8px;
        font-size: 0.75rem;
    }
}

/* Compact Alerts */
@media (max-width: 1024px) and (hover: none) {
    .alert {
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .alert .material-icons {
        font-size: 20px;
    }
}

/* Auth Screen Mobile Optimization */
@media (max-width: 1024px) and (hover: none) {
    #authScreen .container,
    #pendingScreen .container {
        padding: 16px !important;
    }
    
    #authScreen .card,
    #pendingScreen .card {
        padding: 24px 20px;
    }
}

/* Horizontal Scroll Indicator */
@media (max-width: 1024px) and (hover: none) {
    .data-table::-webkit-scrollbar {
        height: 6px;
    }
    
    .data-table::-webkit-scrollbar-track {
        background: var(--surface);
    }
    
    .data-table::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 3px;
    }
    
    body.dark-mode .data-table::-webkit-scrollbar-thumb {
        background: #555;
    }
}

/* Pull-to-refresh safe area */
@media (max-width: 1024px) and (hover: none) {
    body {
        overscroll-behavior-y: contain;
    }
}

/* iOS safe area support */
@supports (padding: max(0px)) {
    @media (max-width: 1024px) and (hover: none) {
        .top-bar {
            padding-bottom: max(8px, env(safe-area-inset-bottom));
        }
        
        #mainApp .py-lg {
            padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
        }
        
        main {
            margin-bottom: max(70px, calc(70px + env(safe-area-inset-bottom))) !important;
        }
    }
}

/* Better button alignment in flex containers */
@media (max-width: 1024px) and (hover: none) {
    .flex.items-center.justify-between {
        gap: 10px;
    }
    
    .flex.gap-sm {
        gap: 6px;
    }
    
    .flex.gap-md {
        gap: 8px;
    }
    
    /* Action buttons in page headers */
    .flex.items-center.justify-between > .btn,
    .flex.items-center.justify-between > .flex {
        font-size: 0.85rem;
    }
    
    .flex.items-center.justify-between .btn .material-icons {
        font-size: 18px;
    }
}

/* Improve table row spacing on mobile */
@media (max-width: 1024px) and (hover: none) {
    .reading-item {
        padding: 10px 0;
    }
}

/* Better form layout on mobile */
@media (max-width: 1024px) and (hover: none) {
    /* When grids are in forms, ensure proper spacing */
    form > .grid-2,
    form > .grid-3, 
    form > .grid-4 {
        margin-bottom: 0;
    }
    
    /* Ensure form action buttons are properly sized */
    form .flex.gap-sm {
        margin-top: 8px;
    }
    
    form .btn-block {
        margin-top: 4px;
    }
}

