/* Mobile responsiveness improvements for MCC Health Services */

:root {
    --sidebar-width: 260px;
}

.btn-group-custom {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: nowrap;
}

.btn-group-custom .btn {
    min-height: 36px !important;
    height: 36px !important;
    padding: 0 12px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 8px !important;
    flex: 0 0 auto;
}

/* Specific for square icon-only buttons */
.btn-action-icon {
    width: 36px !important;
    padding: 0 !important;
    flex: 0 0 36px !important;
}

/* Base Responsive Typography */
@media (max-width: 767.98px) {
    html {
        font-size: 14px;
    }

    h2 {
        font-size: 1.4rem !important;
        letter-spacing: -0.5px;
    }

    h5 {
        font-size: 1.05rem !important;
    }

    .text-muted {
        font-size: 0.85rem;
    }
}

/* Sidebar Toggle Header - only show on mobile */
.mobile-header {
    display: none;
    background: #FFFFFF;
    padding: 10px 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 1001;
    align-items: center;
    justify-content: space-between;
}

@media (max-width: 991.98px) {
    .mobile-header {
        display: flex;
    }

    .sidebar {
        left: -260px !important;
        top: 0 !important;
        height: 100% !important;
        width: 260px !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1050;
    }

    .sidebar.show {
        left: 0 !important;
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.15);
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 15px !important;
        padding-bottom: 90px !important;
        /* Space for footer */
    }

    footer {
        margin-left: 0 !important;
        width: 100% !important;
        position: fixed !important;
        /* Keep fixed but adjust width */
        bottom: 0;
        padding: 12px !important;
        background: rgba(255, 255, 255, 0.9) !important;
        backdrop-filter: blur(10px);
        border-top: 1px solid rgba(0, 0, 0, 0.05) !important;
    }

    /* Adjust cards for mobile grid */
    .row.g-4>.col-md-3,
    .row.g-3>.col-md-3 {
        width: 50% !important;
    }

    .stat-card-icon-container {
        width: 40px;
        height: 40px;
        font-size: 1rem;
        margin-right: 8px;
    }

    .stat-value {
        font-size: 1rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(43, 54, 116, 0.4);
        backdrop-filter: blur(2px);
        z-index: 1045;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }
}

/* Smaller mobile screens */
@media (max-width: 575.98px) {

    .row.g-4>.col-md-3,
    .row.g-3>.col-md-3 {
        width: 100% !important;
    }


    .card {
        padding: 15px !important;
        border-radius: 16px !important;
    }

    /* Stack buttons and ensure they are easy to tap */
    .d-flex.justify-content-between.align-items-center.flex-wrap,
    .text-end,
    .text-center,
    .d-flex.justify-content-end,
    .d-flex.gap-3 {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        display: flex !important;
    }

    .header-actions,
    .btn-group,
    .btn-group-custom,
    .d-flex.gap-2 {
        display: flex !important;
        width: 100% !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        align-items: center !important;
    }

    .header-actions .btn,
    .btn-group .btn,
    .d-flex.gap-2 .btn,
    .text-end .btn,
    .d-flex.justify-content-end .btn {
        flex: 1 1 auto;
        justify-content: center;
        margin: 0 !important;
    }

    /* Keep small action buttons from stretching too much */
    .btn-group-custom .btn-action-icon {
        flex: 0 0 36px !important;
        width: 36px !important;
    }

    /* Search Box and Form Column improvements */
    .search-box form .col-md-2,
    .search-box form .col-md-4,
    .search-box form .col-md-6,
    .search-box form .col-md-8,
    .form-section .row>div {
        width: 100% !important;
    }

    .search-box .btn {
        width: 100%;
        margin-top: 10px;
    }

    /* Stats cards specific */
    .stats-card {
        padding: 15px !important;
        margin-bottom: 12px !important;
    }
}

/* Table responsiveness enhancements */
@media (max-width: 991.98px) {

    .table-custom th:nth-child(4),
    .table-custom td:nth-child(4),
    .table-custom th:nth-child(5),
    .table-custom td:nth-child(5) {
        display: none;
        /* Hide less critical columns */
    }
}

@media (max-width: 767.98px) {

    .table-custom th:nth-child(3),
    .table-custom td:nth-child(3),
    .table-custom th:nth-child(6),
    .table-custom td:nth-child(6) {
        display: none;
    }

    .table-custom td {
        padding: 12px 10px;
        font-size: 0.85rem;
    }

    .table-responsive {
        border-radius: 12px;
        border: 1px solid #eee;
    }

    /* Action buttons in table - now handled globally */
}

/* Messenger Specific Responsiveness */
@media (max-width: 991.98px) {
    .messenger-workspace {
        margin-left: 0 !important;
        width: 100% !important;
        flex-direction: column;
        height: calc(100vh - 60px);
    }

    .conv-col {
        width: 100% !important;
        height: 100%;
    }

    .chat-col {
        position: fixed;
        top: 60px;
        left: 0;
        width: 100%;
        height: calc(100vh - 60px);
        z-index: 1200;
        display: none !important;
        background: #fff;
    }

    .chat-col.show {
        display: flex !important;
    }

    .messenger-header-mobile {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 15px;
        background: #fff;
        border-bottom: 1px solid #f0f0f0;
    }
}

/* Form and Modal Adjustments */
@media (max-width: 575.98px) {
    .form-section {
        padding: 15px !important;
        border-radius: 12px !important;
    }

    .modal-dialog {
        margin: 10px;
    }

    .modal-content {
        border-radius: 16px !important;
    }

    /* Add record specific fixes */
    .header-section {
        padding: 15px !important;
        margin-bottom: 20px !important;
    }

    .header-section h1 {
        font-size: 1.25rem !important;
    }

    .form-container {
        padding: 0 10px !important;
    }

    .btn-lg {
        width: 100%;
        padding: 12px !important;
        font-size: 1rem !important;
    }
}

/* Patient Messenger Adjustments */
@media (max-width: 767.98px) {
    .main-container {
        height: 100vh !important;
        border-radius: 0 !important;
    }

    .search-screen {
        padding: 20px !important;
    }
}

/* Login Page Mobile Fixes */
@media (max-width: 480px) {
    .login-container {
        padding: 15px;
    }

    .login-header {
        padding: 30px 20px 10px;
    }

    .login-body {
        padding: 10px 20px 30px;
    }
}

/* Better touch targets for mobile */
.nav-link,
.btn,
.form-control,
.form-select {
    min-height: 48px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

.btn-sm,
.table .btn,
.btn-group-custom .btn {
    min-height: 36px !important;
    height: 36px !important;
    padding: 0 12px !important;
    font-size: 0.85rem;
}

.btn-group-custom .btn {
    padding: 0 !important;
}

/* Fix for overlapping elements on very small screens */
@media (max-width: 360px) {
    .mobile-header h5 {
        font-size: 0.9rem !important;
    }
}