/**
 * Admin Dashboard Mobile Optimization
 * Responsive design for mobile, tablet, and desktop breakpoints
 * 
 * Breakpoints:
 * - 320px: Small phones
 * - 576px: Tablets and large phones (Bootstrap sm)
 * - 768px: Tablets (Bootstrap md)
 * - 1024px: Large tablets and small laptops
 * - 1440px: Desktops
 */

/* ──────────────────────────────────────────────────
   SMALL PHONES (320px - 575px)
   ────────────────────────────────────────────────── */

@media (max-width: 575.98px) {
    /* Typography */
    body {
        font-size: 14px;
        line-height: 1.5;
    }
    
    h1 { font-size: 20px; }
    h2 { font-size: 18px; }
    h3 { font-size: 16px; }
    h4 { font-size: 14px; }
    
    /* Navigation */
    .navbar {
        padding: 0.5rem 0.75rem;
    }
    
    .navbar-brand {
        font-size: 16px;
    }
    
    .navbar-toggler {
        padding: 0.25rem 0.5rem;
    }
    
    /* Search bar */
    .dashboard-search {
        min-width: 100% !important;
        margin-bottom: 0.5rem;
    }
    
    .search-shortcut {
        display: none;
    }
    
    /* Buttons */
    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 13px;
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    .btn-sm {
        padding: 0.375rem 0.5rem;
        font-size: 12px;
    }
    
    /* Forms */
    .form-control,
    .form-select {
        padding: 0.6rem 0.75rem;
        font-size: 16px; /* Prevents iOS zoom */
        border-radius: 0.375rem;
    }
    
    /* Cards and containers */
    .card,
    .section-surface,
    .hero-card {
        margin-bottom: 0.75rem;
        border-radius: 0.75rem;
        padding: 1rem;
    }
    
    /* Grid layouts */
    .hero-grid,
    .widget-grid {
        grid-template-columns: 1fr !important;
        gap: 0.5rem;
    }
    
    /* Tables */
    .table {
        font-size: 12px;
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.25rem;
    }
    
    /* Modals */
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-header {
        padding: 0.75rem;
    }
    
    .modal-body {
        padding: 0.75rem;
    }
    
    .modal-footer {
        padding: 0.5rem;
        gap: 0.25rem;
    }
    
    /* Alerts */
    .alert {
        padding: 0.75rem;
        margin-bottom: 0.5rem;
        font-size: 13px;
    }
    
    /* Pagination */
    .pagination {
        font-size: 12px;
        gap: 0.25rem;
    }
    
    .page-link {
        padding: 0.375rem 0.5rem;
        min-width: 32px;
        min-height: 32px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Dropdowns */
    .dropdown-menu {
        min-width: 160px;
        font-size: 13px;
    }
    
    .dropdown-item {
        padding: 0.5rem 0.75rem;
    }
    
    /* Badges */
    .badge {
        font-size: 11px;
        padding: 0.4rem 0.6rem;
    }
    
    /* Collapse animations */
    .collapse {
        transition: all 0.3s ease-in-out;
    }
    
    /* Input groups */
    .input-group {
        display: flex;
        flex-wrap: wrap;
    }
    
    .input-group > .form-control,
    .input-group > .form-select {
        flex: 1 1 100%;
    }
    
    .input-group-append,
    .input-group-prepend {
        width: 100%;
    }
    
    /* Search modal */
    .global-search-modal.active {
        padding-top: 10px;
    }
    
    .search-container {
        max-width: calc(100% - 10px);
        max-height: 90vh;
    }
    
    .search-shortcuts {
        display: none !important;
    }
}

/* ──────────────────────────────────────────────────
   TABLETS AND LARGE PHONES (576px - 767px)
   ────────────────────────────────────────────────── */

@media (min-width: 576px) and (max-width: 767.98px) {
    /* Navigation */
    .navbar {
        padding: 0.75rem 1rem;
    }
    
    .dashboard-search {
        min-width: min(100%, 300px);
    }
    
    /* Grid layouts */
    .hero-grid,
    .widget-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }
    
    /* Cards */
    .card,
    .section-surface,
    .hero-card {
        padding: 1.125rem;
    }
    
    /* Buttons */
    .btn {
        padding: 0.5rem 0.875rem;
        font-size: 14px;
    }
    
    /* Forms */
    .form-control,
    .form-select {
        padding: 0.6rem 0.75rem;
        font-size: 14px;
    }
    
    /* Tables */
    .table {
        font-size: 13px;
    }
    
    .table th,
    .table td {
        padding: 0.6rem 0.5rem;
    }
    
    /* Modals */
    .modal-dialog {
        margin: 1rem;
        max-width: calc(100% - 2rem);
    }
}

/* ──────────────────────────────────────────────────
   TABLETS (768px - 1023px)
   ────────────────────────────────────────────────── */

@media (min-width: 768px) and (max-width: 1023.98px) {
    /* Navigation */
    .navbar-collapse {
        margin-top: 0.75rem;
    }
    
    .dashboard-search {
        min-width: min(100%, 350px);
    }
    
    /* Grid layouts */
    .hero-grid,
    .widget-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 1rem;
    }
    
    /* Off-canvas sidebar for mobile navigation */
    .sidebar-offcanvas {
        position: fixed;
        top: 0;
        left: -300px;
        width: 300px;
        height: 100vh;
        background: var(--bg-primary);
        border-right: 1px solid var(--border-color);
        transition: left 0.3s ease-in-out;
        z-index: 1040;
        overflow-y: auto;
    }
    
    .sidebar-offcanvas.show {
        left: 0;
    }
    
    .sidebar-toggle {
        display: inline-block;
        cursor: pointer;
    }
    
    /* Hamburger menu button */
    .hamburger {
        width: 40px;
        height: 40px;
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        background: none;
        border: none;
        cursor: pointer;
    }
    
    .hamburger span {
        width: 24px;
        height: 2px;
        background: var(--text-primary);
        transition: all 0.3s ease-in-out;
        display: block;
    }
    
    /* Forms - better spacing */
    .form-group {
        margin-bottom: 1rem;
    }
    
    /* Tables - responsive with horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Modals */
    .modal-dialog {
        margin: 1.5rem auto;
    }
}

/* ──────────────────────────────────────────────────
   DESKTOPS (1024px+)
   ────────────────────────────────────────────────── */

@media (min-width: 1024px) {
    /* Default desktop styles - already defined in main CSS */
    
    .sidebar-offcanvas {
        display: none;
    }
}

/* ──────────────────────────────────────────────────
   LANDSCAPE ORIENTATION
   ────────────────────────────────────────────────── */

@media (orientation: landscape) and (max-height: 600px) {
    /* Reduce vertical padding for small viewport height */
    .navbar {
        padding: 0.5rem 1rem;
    }
    
    .section-surface,
    .hero-card,
    .card {
        padding: 0.75rem;
        margin-bottom: 0.5rem;
    }
    
    .hero-grid {
        gap: 0.5rem;
    }
    
    .metric-value {
        font-size: 1.5rem;
    }
    
    /* Hide less important elements */
    .sidebar-offcanvas {
        display: none;
    }
}

/* ──────────────────────────────────────────────────
   TOUCH DEVICE OPTIMIZATIONS
   ────────────────────────────────────────────────── */

@media (hover: none) and (pointer: coarse) {
    /* Touch devices - larger touch targets */
    
    button,
    a.btn,
    .btn,
    .dropdown-item,
    .nav-link {
        min-height: 48px;
        min-width: 48px;
        padding: 0.75rem 1rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Remove hover effects - not applicable on touch */
    button:hover,
    a.btn:hover,
    .btn:hover,
    .nav-link:hover {
        text-decoration: none;
        background-color: var(--bg-secondary);
        transition: background-color 0.2s ease;
    }
    
    /* Add active/focus states for touch feedback */
    button:active,
    button:focus,
    .btn:active,
    .btn:focus {
        transform: scale(0.98);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
    
    /* Form inputs */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    textarea {
        min-height: 48px;
        font-size: 16px; /* Prevents iOS zoom */
        padding: 0.75rem;
    }
    
    /* Checkboxes and radios */
    .form-check-input {
        width: 24px;
        height: 24px;
        cursor: pointer;
        margin-top: 0.3rem;
    }
    
    /* Select dropdown */
    select {
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.75rem center;
        background-size: 20px;
        padding-right: 2.5rem;
    }
    
    /* Remove double tap zoom delay */
    a, button, input, select, textarea {
        touch-action: manipulation;
    }
}

/* ──────────────────────────────────────────────────
   PRINT STYLES
   ────────────────────────────────────────────────── */

@media print {
    /* Hide navigation and controls */
    .navbar,
    .btn,
    .modal,
    .modal-backdrop,
    .sidebar-offcanvas {
        display: none !important;
    }
    
    /* Optimize for print */
    body {
        background: white;
        color: black;
    }
    
    .section-surface,
    .hero-card,
    .card {
        page-break-inside: avoid;
        border: 1px solid #000;
        box-shadow: none;
    }
    
    /* Ensure tables print properly */
    .table {
        border-collapse: collapse;
    }
    
    .table th,
    .table td {
        border: 1px solid #000;
    }
}

/* ──────────────────────────────────────────────────
   ACCESSIBILITY - REDUCED MOTION
   ────────────────────────────────────────────────── */

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

/* ──────────────────────────────────────────────────
   DARK MODE - PRINT
   ────────────────────────────────────────────────── */

@media print {
    html[data-theme="dark"] {
        --bg-primary: white;
        --bg-secondary: #f5f5f5;
        --text-primary: black;
        --text-secondary: #666;
        --border-color: #ccc;
    }
}

/* ──────────────────────────────────────────────────
   UTILITY CLASSES FOR RESPONSIVE
   ────────────────────────────────────────────────── */

.hide-mobile {
    display: none;
}

@media (min-width: 576px) {
    .hide-mobile {
        display: block;
    }
}

.show-mobile {
    display: block;
}

@media (min-width: 576px) {
    .show-mobile {
        display: none;
    }
}

.hide-tablet {
    display: block;
}

@media (min-width: 768px) and (max-width: 1023.98px) {
    .hide-tablet {
        display: none;
    }
}

.hide-desktop {
    display: block;
}

@media (min-width: 1024px) {
    .hide-desktop {
        display: none;
    }
}
