/*
 * AttroTechAAA - Mobile Responsiveness Enhancements
 * Optimized for tablets and smartphones
 * Breakpoints: Mobile (<768px), Tablet (768-1024px), Desktop (>1024px)
 */

/* ═══════════════════════════════════════════════════════════════
   1. MOBILE SIDEBAR OPTIMIZATION
═══════════════════════════════════════════════════════════════ */

/* Mobile: Bottom sheet navigation instead of sidebar */
@media (max-width: 767px) {
    /* Hide desktop sidebar */
    .fi-sidebar {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        height: auto !important;
        max-height: 70vh !important;
        transform: translateY(calc(100% - 60px)) !important;
        transition: transform var(--dur-mid) var(--ease-spring) !important;
        z-index: 40 !important;
        border-radius: 16px 16px 0 0 !important;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15) !important;
    }

    .fi-sidebar[data-open="true"] {
        transform: translateY(0) !important;
    }

    /* Sidebar toggle button */
    .fi-sidebar-toggle-mobile {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 60px !important;
        background: linear-gradient(to top, rgba(10, 20, 38, 0.98), rgba(10, 20, 38, 0.95)) !important;
        backdrop-filter: blur(12px) !important;
        -webkit-backdrop-filter: blur(12px) !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        z-index: 41 !important;
        border-top: 1px solid var(--dk-border) !important;
    }

    html:not(.dark) .fi-sidebar-toggle-mobile {
        background: linear-gradient(to top, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.95)) !important;
    }

    .fi-sidebar-toggle-mobile svg {
        width: 24px !important;
        height: 24px !important;
        color: var(--attro-cyan) !important;
    }

    .fi-sidebar-toggle-mobile span {
        font-size: 14px !important;
        font-weight: 600 !important;
        color: var(--dk-text) !important;
    }

    html:not(.dark) .fi-sidebar-toggle-mobile span {
        color: var(--lt-text) !important;
    }

    /* Compact sidebar items on mobile */
    .fi-sidebar-item {
        padding: 12px 16px !important;
        min-height: 48px !important; /* Touch-friendly */
    }

    .fi-sidebar-item a {
        font-size: 15px !important;
        padding: 8px 12px !important;
    }

    /* Sidebar group headers */
    .fi-sidebar-group-label {
        font-size: 11px !important;
        padding: 12px 16px 6px !important;
        text-transform: uppercase !important;
        letter-spacing: 0.08em !important;
    }
}

/* Tablet: Collapsible sidebar */
@media (min-width: 768px) and (max-width: 1024px) {
    .fi-sidebar {
        width: 72px !important;
    }

    .fi-sidebar-item-label {
        display: none !important;
    }

    .fi-sidebar-item a {
        justify-content: center !important;
        padding: 12px !important;
    }

    .fi-sidebar-group-label {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   2. TOUCH-FRIENDLY INTERACTIONS
═══════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    /* Minimum touch target size: 44x44px (Apple HIG) */
    button,
    .fi-btn,
    .fi-ta-action,
    .fi-icon-btn,
    a[role="button"],
    input[type="submit"],
    input[type="button"] {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 12px 16px !important;
    }

    /* Larger tap targets for table actions */
    .fi-ta-action {
        padding: 10px 14px !important;
        font-size: 14px !important;
    }

    /* Form inputs - larger on mobile */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    textarea,
    select,
    .fi-input,
    .fi-select-input {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        padding: 12px 14px !important;
        min-height: 44px !important;
    }

    /* Checkbox and radio - larger hit area */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px !important;
        height: 24px !important;
        margin-right: 12px !important;
    }

    /* Switch/toggle - easier to tap */
    .fi-toggle {
        min-width: 52px !important;
        height: 32px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   3. RESPONSIVE TABLES
═══════════════════════════════════════════════════════════════ */

/* Mobile: Card-based table layout */
@media (max-width: 767px) {
    .fi-ta-container {
        overflow-x: visible !important;
    }

    .fi-ta-table {
        display: block !important;
        width: 100% !important;
    }

    .fi-ta-table thead {
        display: none !important; /* Hide headers on mobile */
    }

    .fi-ta-table tbody {
        display: block !important;
    }

    .fi-ta-row {
        display: block !important;
        margin-bottom: 16px !important;
        border: 1px solid var(--lt-border) !important;
        border-radius: 12px !important;
        padding: 16px !important;
        background: var(--lt-surface) !important;
    }

    html.dark .fi-ta-row {
        border-color: var(--dk-border) !important;
        background: var(--dk-surface) !important;
    }

    .fi-ta-cell {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 8px 0 !important;
        border-bottom: 1px solid rgba(148, 163, 184, 0.1) !important;
    }

    .fi-ta-cell:last-child {
        border-bottom: none !important;
    }

    /* Show column labels from data-label attribute */
    .fi-ta-cell::before {
        content: attr(data-label) !important;
        font-weight: 600 !important;
        font-size: 12px !important;
        text-transform: uppercase !important;
        letter-spacing: 0.05em !important;
        color: var(--lt-muted) !important;
        margin-right: 12px !important;
        flex-shrink: 0 !important;
    }

    html.dark .fi-ta-cell::before {
        color: var(--dk-muted) !important;
    }

    /* Actions become horizontal scroll on mobile */
    .fi-ta-actions {
        display: flex !important;
        gap: 8px !important;
        overflow-x: auto !important;
        padding: 8px 0 !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .fi-ta-action {
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }
}

/* Tablet: Scrollable tables with sticky first column */
@media (min-width: 768px) and (max-width: 1024px) {
    .fi-ta-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .fi-ta-table {
        min-width: 800px !important;
    }

    /* Sticky first column for context */
    .fi-ta-cell:first-child {
        position: sticky !important;
        left: 0 !important;
        z-index: 10 !important;
        background: inherit !important;
        box-shadow: 4px 0 8px rgba(0, 0, 0, 0.05) !important;
    }

    html.dark .fi-ta-cell:first-child {
        box-shadow: 4px 0 8px rgba(0, 0, 0, 0.2) !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   4. RESPONSIVE DASHBOARD WIDGETS
═══════════════════════════════════════════════════════════════ */

/* Mobile: Single column widgets */
@media (max-width: 767px) {
    .fi-stats-overview-widget {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .fi-stats-overview-stat {
        min-height: 120px !important;
        padding: 16px !important;
    }

    .fi-stats-overview-stat-label {
        font-size: 13px !important;
    }

    .fi-stats-overview-stat-value {
        font-size: 28px !important;
        margin: 8px 0 !important;
    }

    .fi-stats-overview-stat-description {
        font-size: 12px !important;
    }

    /* Chart widgets - full width */
    .fi-chart-widget {
        margin: 0 -16px !important;
        width: calc(100% + 32px) !important;
    }

    .fi-chart-widget canvas {
        height: 240px !important;
    }

    /* Reduce widget padding */
    .fi-widget {
        padding: 16px !important;
    }
}

/* Tablet: Two column grid */
@media (min-width: 768px) and (max-width: 1024px) {
    .fi-stats-overview-widget {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .fi-chart-widget canvas {
        height: 280px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   5. RESPONSIVE MODALS & DRAWERS
═══════════════════════════════════════════════════════════════ */

/* Mobile: Full-screen modals */
@media (max-width: 767px) {
    .fi-modal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    .fi-modal-header {
        padding: 16px !important;
        min-height: 56px !important;
    }

    .fi-modal-body {
        padding: 16px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .fi-modal-footer {
        padding: 16px !important;
        position: sticky !important;
        bottom: 0 !important;
        background: inherit !important;
        border-top: 1px solid var(--lt-border) !important;
    }

    html.dark .fi-modal-footer {
        border-color: var(--dk-border) !important;
    }

    /* Action buttons stack vertically on mobile */
    .fi-modal-footer .fi-btn {
        width: 100% !important;
        margin-bottom: 8px !important;
    }

    .fi-modal-footer .fi-btn:last-child {
        margin-bottom: 0 !important;
    }
}

/* Tablet: Side drawers become bottom sheets */
@media (max-width: 1024px) {
    .fi-drawer {
        max-width: 100vw !important;
        width: 100vw !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   6. RESPONSIVE TYPOGRAPHY
═══════════════════════════════════════════════════════════════ */

/* Mobile: Larger base font for readability */
@media (max-width: 767px) {
    html {
        font-size: 16px !important;
    }

    h1 {
        font-size: 24px !important;
        line-height: 1.3 !important;
    }

    h2 {
        font-size: 20px !important;
        line-height: 1.35 !important;
    }

    h3 {
        font-size: 18px !important;
        line-height: 1.4 !important;
    }

    p {
        font-size: 15px !important;
        line-height: 1.6 !important;
    }

    small,
    .text-sm {
        font-size: 13px !important;
    }

    .text-xs {
        font-size: 12px !important;
    }
}

/* Tablet: Slightly smaller than desktop */
@media (min-width: 768px) and (max-width: 1024px) {
    h1 {
        font-size: 28px !important;
    }

    h2 {
        font-size: 22px !important;
    }

    h3 {
        font-size: 18px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   7. RESPONSIVE SPACING & LAYOUT
═══════════════════════════════════════════════════════════════ */

/* Mobile: Reduced spacing */
@media (max-width: 767px) {
    .fi-main {
        padding: 16px !important;
    }

    .fi-section {
        margin-bottom: 16px !important;
        padding: 16px !important;
    }

    .fi-grid {
        gap: 12px !important;
    }

    /* Forms - full width inputs */
    .fi-form-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .fi-field {
        margin-bottom: 16px !important;
    }

    /* Buttons stack on mobile */
    .fi-btn-group {
        flex-direction: column !important;
        width: 100% !important;
    }

    .fi-btn-group .fi-btn {
        width: 100% !important;
        margin-bottom: 8px !important;
    }

    /* Filters collapse */
    .fi-filters {
        display: none !important;
    }

    .fi-filters[data-open="true"] {
        display: block !important;
    }

    /* Pagination - simplified */
    .fi-pagination {
        padding: 12px !important;
    }

    .fi-pagination .fi-btn {
        padding: 10px 12px !important;
        font-size: 13px !important;
    }
}

/* Tablet: Medium spacing */
@media (min-width: 768px) and (max-width: 1024px) {
    .fi-main {
        padding: 24px !important;
    }

    .fi-section {
        padding: 20px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   8. SWIPE GESTURES SUPPORT
═══════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    /* Enable smooth scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Pull-to-refresh indicator (future enhancement) */
    .fi-pull-to-refresh {
        display: none;
        text-align: center;
        padding: 16px;
        color: var(--lt-muted);
        font-size: 13px;
    }

    html.dark .fi-pull-to-refresh {
        color: var(--dk-muted);
    }

    /* Swipeable tabs (future) */
    .fi-tabs-list {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }

    .fi-tabs-list::-webkit-scrollbar {
        display: none !important;
    }

    .fi-tabs-tab {
        flex-shrink: 0 !important;
        padding: 12px 16px !important;
        white-space: nowrap !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   9. MOBILE-SPECIFIC OPTIMIZATIONS
═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
    /* Hide non-essential elements on mobile */
    .fi-hide-on-mobile {
        display: none !important;
    }

    /* Show mobile-only elements */
    .fi-show-on-mobile {
        display: block !important;
    }

    /* Command palette - full screen on mobile */
    #command-palette-modal {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    /* Toast notifications - full width on mobile */
    .fi-toast {
        left: 16px !important;
        right: 16px !important;
        max-width: calc(100vw - 32px) !important;
    }

    /* Search bar - prominent on mobile */
    .fi-search-input {
        font-size: 16px !important;
        padding: 12px 16px !important;
    }

    /* Breadcrumbs - simplified */
    .fi-breadcrumbs {
        font-size: 13px !important;
        padding: 8px 0 !important;
    }

    .fi-breadcrumb-item {
        display: none !important;
    }

    .fi-breadcrumb-item:last-child {
        display: inline-block !important;
    }

    /* Page header - compact */
    .fi-page-header {
        padding: 16px 0 !important;
    }

    .fi-page-header-heading {
        font-size: 22px !important;
    }

    .fi-page-header-actions {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .fi-page-header-actions .fi-btn {
        flex: 1 1 auto !important;
        min-width: 120px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   10. LANDSCAPE MODE OPTIMIZATION
═══════════════════════════════════════════════════════════════ */

@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce vertical space usage */
    .fi-header {
        padding: 8px 16px !important;
    }

    .fi-page-header-heading {
        font-size: 18px !important;
    }

    /* Compact modals in landscape */
    .fi-modal {
        max-height: 90vh !important;
    }

    /* Hide keyboard shortcut hints in landscape */
    kbd {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   11. SAFE AREA INSETS (iPhone X+)
═══════════════════════════════════════════════════════════════ */

@supports (padding: max(0px)) {
    @media (max-width: 767px) {
        body {
            padding-left: env(safe-area-inset-left) !important;
            padding-right: env(safe-area-inset-right) !important;
        }

        .fi-sidebar-toggle-mobile {
            padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
        }

        .fi-main {
            padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
        }
    }
}

/* ═══════════════════════════════════════════════════════════════
   12. PRINT STYLES (BONUS)
═══════════════════════════════════════════════════════════════ */

@media print {
    /* Hide navigation and UI chrome */
    .fi-sidebar,
    .fi-topbar,
    .fi-btn,
    .fi-modal,
    .fi-toast {
        display: none !important;
    }

    /* Optimize for printing */
    body {
        background: white !important;
        color: black !important;
    }

    .fi-main {
        padding: 0 !important;
        max-width: 100% !important;
    }

    /* Ensure tables print properly */
    .fi-ta-table {
        page-break-inside: auto !important;
    }

    .fi-ta-row {
        page-break-inside: avoid !important;
        page-break-after: auto !important;
    }
}
