/**
 * The Flock - Mobile Responsiveness Enhancements
 * Optimized for all screen sizes including tablets
 */

/* =============================================================================
   BREAKPOINT REFERENCE
   ============================================================================= */
/*
   xs: 0 - 575px (mobile portrait)
   sm: 576px - 767px (mobile landscape)
   md: 768px - 991px (tablet portrait)
   lg: 992px - 1199px (tablet landscape / small desktop)
   xl: 1200px - 1399px (desktop)
   xxl: 1400px+ (large desktop)
*/

/* =============================================================================
   BASE MOBILE STYLES (Mobile First)
   ============================================================================= */

/* Root font size adjustments */
@media (max-width: 575px) {
    html {
        font-size: 14px;
    }
}

/* Container padding */
.container,
.container-fluid {
    padding-left: 1rem;
    padding-right: 1rem;
}

@media (min-width: 576px) {
    .container,
    .container-fluid {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}

@media (min-width: 992px) {
    .container,
    .container-fluid {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

/* =============================================================================
   MOBILE NAVIGATION — max-width: 767px to avoid overlap with tablet (768px+)
   ============================================================================= */

@media (max-width: 767px) {
    /* Main content adjustments when sidebar is hidden */
    #main-content {
        margin-left: 0 !important;
        padding-top: calc(60px + 1rem); /* 60px topbar + gap */
        min-height: calc(100vh - 60px);
    }

    /* Mobile topbar enhancements */
    .mobile-topbar {
        height: 60px;
        padding: 0.75rem 1rem;
    }

    .mobile-brand {
        font-size: 1rem;
        max-width: 200px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Sidebar in mobile mode */
    .sidebar-enhanced {
        width: 85vw;
        max-width: 320px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar-enhanced.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    /* Mobile close button */
    .mobile-sidebar-close {
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
        z-index: 10;
    }

    .mobile-close-btn {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.05);
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s;
    }

    .mobile-close-btn:hover {
        background: rgba(0, 0, 0, 0.1);
    }
}

/* =============================================================================
   TABLET STYLES (768px - 991px)
   ============================================================================= */

@media (min-width: 768px) and (max-width: 991px) {
    /* Sidebar can be collapsed on tablets */
    .sidebar-enhanced {
        width: 80px;
    }

    .sidebar-enhanced:hover {
        width: 240px;
    }

    .sidebar-enhanced .nav-item span,
    .sidebar-enhanced .nav-group-header,
    .sidebar-enhanced .user-info,
    .sidebar-enhanced .organization-info {
        opacity: 0;
        transition: opacity 0.2s;
    }

    .sidebar-enhanced:hover .nav-item span,
    .sidebar-enhanced:hover .nav-group-header,
    .sidebar-enhanced:hover .user-info,
    .sidebar-enhanced:hover .organization-info {
        opacity: 1;
    }

    /* Main content with collapsed sidebar */
    #main-content {
        margin-left: 80px;
        transition: margin-left 0.3s;
    }

    .sidebar-enhanced:hover ~ #main-content {
        margin-left: 240px;
    }
}

/* =============================================================================
   GRID LAYOUTS
   ============================================================================= */

/* Dashboard widgets grid */
.dashboard-widgets,
.widgets-grid {
    display: grid;
    gap: 1rem;
}

@media (max-width: 575px) {
    .dashboard-widgets,
    .widgets-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 576px) and (max-width: 991px) {
    .dashboard-widgets,
    .widgets-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .dashboard-widgets,
    .widgets-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
}

/* Members/Services grid */
.members-grid,
.services-grid,
.cards-grid {
    display: grid;
    gap: 1rem;
}

@media (max-width: 575px) {
    .members-grid,
    .services-grid,
    .cards-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 576px) and (max-width: 991px) {
    .members-grid,
    .services-grid,
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .members-grid,
    .services-grid,
    .cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    }
}

/* Quick actions */
.quick-actions-grid {
    display: grid;
    gap: 1rem;
}

@media (max-width: 575px) {
    .quick-actions-grid {
        grid-template-columns: 1fr;
    }

    .quick-actions-buttons {
        flex-direction: column;
    }

    .quick-action-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (min-width: 576px) {
    .quick-actions-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
}

/* =============================================================================
   PAGE HEADERS
   ============================================================================= */

@media (max-width: 575px) {
    .page-header,
    .modern-page-header {
        margin-top: 1rem;
        margin-bottom: 1rem;
    }

    .page-header .header-content,
    .modern-page-header .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .page-title,
    .modern-page-header .page-title {
        font-size: 1.5rem;
    }

    .page-subtitle,
    .modern-page-header .page-subtitle {
        font-size: 0.875rem;
    }

    .header-actions,
    .page-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .header-actions .btn,
    .page-actions .btn {
        flex: 1;
        min-width: 120px;
    }
}

/* =============================================================================
   BUTTONS
   ============================================================================= */

@media (max-width: 575px) {
    /* Stack buttons on mobile */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }

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

    /* Full width buttons on mobile for primary actions */
    .btn-mobile-full {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    /* Smaller button text on mobile */
    .btn {
        font-size: 0.875rem;
        padding: 0.625rem 1rem;
    }

    .btn-sm {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }
}

/* =============================================================================
   FORMS
   ============================================================================= */

@media (max-width: 575px) {
    /* Single column forms on mobile */
    .form-grid,
    .form-row {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .form-grid .span-2,
    .form-row .col-md-6,
    .form-row .col-lg-4 {
        grid-column: span 1;
    }

    /* Full width form controls */
    .form-control,
    .form-select,
    .form-textarea {
        width: 100%;
    }

    /* Form actions */
    .form-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

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

/* =============================================================================
   TABLES
   ============================================================================= */

@media (max-width: 767px) {
    /* Card-style tables on mobile */
    .table-responsive-cards {
        display: block;
    }

    .table-responsive-cards thead {
        display: none;
    }

    .table-responsive-cards tbody,
    .table-responsive-cards tr {
        display: block;
    }

    .table-responsive-cards tr {
        background: white;
        border: 1px solid var(--border, #e2e8f0);
        border-radius: var(--radius-lg, 0.75rem);
        margin-bottom: 1rem;
        padding: 1rem;
    }

    .table-responsive-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border: none;
        border-bottom: 1px solid var(--border-light, #f1f5f9);
    }

    .table-responsive-cards td:last-child {
        border-bottom: none;
    }

    .table-responsive-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary, #64748b);
        flex: 0 0 40%;
        text-align: left;
    }

    /* Horizontal scroll for complex tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-responsive table {
        min-width: 600px;
    }
}

/* =============================================================================
   CARDS
   ============================================================================= */

@media (max-width: 575px) {
    .card,
    .modern-card,
    .widget-card {
        border-radius: var(--radius, 0.375rem);
    }

    .card-body,
    .widget-card {
        padding: 1rem;
    }

    .card-header,
    .card-footer {
        padding: 0.75rem 1rem;
    }

    /* Member cards */
    .member-card-header,
    .service-card-header {
        padding: 0.75rem;
    }

    .member-card-body,
    .service-card-body {
        padding: 0.75rem;
    }

    .member-card-footer,
    .service-card-footer {
        padding: 0.5rem 0.75rem;
    }
}

/* =============================================================================
   MODALS
   ============================================================================= */

@media (max-width: 575px) {
    .modal-dialog {
        margin: 0.5rem;
        max-height: calc(100vh - 1rem);
    }

    .modal-content {
        border-radius: var(--radius-lg, 0.75rem);
        max-height: calc(100vh - 1rem);
    }

    .modal-header,
    .modal-footer {
        padding: 0.75rem 1rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 12rem);
        overflow-y: auto;
    }

    .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

/* =============================================================================
   FILTER BAR
   ============================================================================= */

@media (max-width: 767px) {
    .filter-bar {
        padding: 0.75rem;
    }

    .filter-bar-content {
        flex-direction: column;
        gap: 0.75rem;
    }

    .search-section {
        width: 100%;
        max-width: none;
    }

    .filter-section {
        width: 100%;
        flex-wrap: wrap;
    }

    .filter-tabs {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }

    .filter-tab {
        flex-shrink: 0;
    }
}

/* =============================================================================
   FOOTER
   ============================================================================= */

@media (max-width: 767px) {
    .site-footer {
        padding: 1.5rem 1rem;
    }

    .footer-content {
        flex-direction: column;
        gap: 1.5rem;
    }

    .footer-section {
        text-align: center;
    }

    .footer-brand {
        justify-content: center;
    }

    .footer-links {
        text-align: center;
    }

    .footer-bottom {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }
}

/* =============================================================================
   BANNERS
   ============================================================================= */

@media (max-width: 575px) {
    .organization-banner,
    .super-admin-banner {
        padding: 1rem;
        border-radius: var(--radius-lg, 0.75rem);
        margin: 0 0 1rem 0;
    }

    .organization-name,
    .banner-title {
        font-size: 1.25rem;
    }

    .organization-banner-content {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .organization-banner-logo-fallback {
        width: 50px;
        height: 50px;
    }
}

/* =============================================================================
   UTILITY CLASSES
   ============================================================================= */

/* Hide on mobile */
@media (max-width: 575px) {
    .hide-mobile,
    .d-mobile-none {
        display: none !important;
    }
}

/* Hide on tablet */
@media (min-width: 576px) and (max-width: 991px) {
    .hide-tablet,
    .d-tablet-none {
        display: none !important;
    }
}

/* Hide on desktop */
@media (min-width: 992px) {
    .hide-desktop,
    .d-desktop-none {
        display: none !important;
    }
}

/* Show only on mobile */
@media (min-width: 576px) {
    .show-mobile-only,
    .d-mobile-only {
        display: none !important;
    }
}

/* Text alignment responsive */
@media (max-width: 575px) {
    .text-mobile-center {
        text-align: center !important;
    }

    .text-mobile-left {
        text-align: left !important;
    }
}

/* Stack on mobile */
@media (max-width: 575px) {
    .stack-mobile {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .stack-mobile > * {
        width: 100%;
    }
}

/* =============================================================================
   TOUCH INTERACTIONS
   ============================================================================= */

@media (hover: none) {
    /* Remove hover effects on touch devices */
    .card:hover,
    .btn:hover,
    .widget-card:hover {
        transform: none;
    }

    /* Active states for touch feedback */
    .btn:active {
        transform: scale(0.98);
    }

    .card:active,
    .widget-card:active {
        transform: scale(0.99);
    }
}

/* =============================================================================
   MOBILE WIDGET & CARD IMPROVEMENTS
   ============================================================================= */

@media (max-width: 767px) {
    /* Compact stat cards on mobile */
    .dashboard-widget {
        padding: 0.875rem 1rem;
        margin-bottom: 0;
        min-height: auto;
        border-radius: 12px;
    }

    .dashboard-widget .widget-header {
        margin-bottom: 0;
    }

    .dashboard-widget .widget-value {
        font-size: 1.75rem;
        margin-bottom: 0.125rem;
    }

    .dashboard-widget .widget-subtitle {
        font-size: 0.75rem;
        margin-top: 0;
    }

    .dashboard-widget .widget-icon {
        width: 32px;
        height: 32px;
        border-radius: 8px;
    }

    .dashboard-widget .widget-icon svg,
    .dashboard-widget .widget-icon i {
        width: 16px;
        height: 16px;
    }

    /* Tighter spacing between stat rows */
    .row.g-3 {
        --bs-gutter-y: 0.75rem;
        --bs-gutter-x: 0.75rem;
    }

    .row.g-3.mb-4 {
        margin-bottom: 1rem !important;
    }

    /* Better page header on mobile */
    .page-header {
        margin-bottom: 1rem;
    }

    .page-header .page-title {
        font-size: 1.25rem;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .page-header .page-title svg,
    .page-header .page-title i {
        width: 22px;
        height: 22px;
    }

    .page-header .page-subtitle {
        font-size: 0.8rem;
        margin-top: 0.125rem;
    }

    /* Compact filter controls */
    .page-header .d-flex.gap-2 {
        gap: 0.5rem !important;
    }

    .page-header .btn-group .btn-sm {
        padding: 0.375rem 0.75rem;
        font-size: 0.8rem;
    }

    .page-header .form-select-sm {
        padding: 0.375rem 2rem 0.375rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Container fluid padding on mobile */
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Prayer/crisis card improvements on mobile */
    .prayer-card .card-body {
        padding: 0.875rem !important;
    }

    .prayer-card .row.g-3 {
        --bs-gutter-y: 0.5rem;
    }

    /* Modern card compactness */
    .modern-card .card-header {
        padding: 0.75rem 1rem;
    }

    .modern-card .card-body {
        padding: 0.875rem 1rem;
    }

    /* Stat card icon backgrounds - ensure visibility on white */
    .stat-card, .info-card {
        border-radius: 12px;
    }
}

/* =============================================================================
   PRINT STYLES
   ============================================================================= */

@media print {
    /* Hide navigation and non-essential elements */
    .sidebar-enhanced,
    .mobile-topbar,
    .site-footer,
    .skip-link,
    .toast-container,
    .modal-backdrop {
        display: none !important;
    }

    /* Reset main content margin */
    #main-content {
        margin-left: 0 !important;
        padding-top: 0 !important;
    }

    /* Ensure content fits on page */
    body {
        font-size: 12pt;
    }

    .card,
    .table {
        break-inside: avoid;
    }

    /* Print-friendly colors */
    * {
        background: white !important;
        color: black !important;
    }
}
