/* Mobile Responsive Styles for Rehoboth Hospital */

/* ========================================
   GLOBAL MOBILE STYLES
   ======================================== */

/* Ensure proper touch targets */
@media (max-width: 768px) {
    .btn {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }
    
    .form-control, .form-select {
        min-height: 44px;
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    .nav-link {
        padding: 0.75rem 1rem !important;
    }
    
    /* Better table scrolling */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Stack cards on mobile */
    .row > [class*="col-md-"], 
    .row > [class*="col-lg-"] {
        margin-bottom: 1rem;
    }
    
    /* Reduce padding on mobile */
    .content-wrapper {
        padding: 0.75rem !important;
    }
    
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    /* Card adjustments */
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-header {
        padding: 0.75rem 1rem;
    }
    
    /* Stat cards on mobile */
    .stat-card .card-body {
        padding: 0.75rem;
    }
    
    .stat-card h3 {
        font-size: 1.5rem;
    }
    
    .stat-card .stat-icon {
        font-size: 1.5rem !important;
    }
    
    /* Modal adjustments */
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    /* Alert adjustments */
    .alert-floating {
        left: 10px;
        right: 10px;
        min-width: auto !important;
    }
    
    /* Hide long text on mobile */
    .d-mobile-none {
        display: none !important;
    }
    
    /* Show mobile-only elements */
    .d-mobile-only {
        display: block !important;
    }
}

@media (min-width: 769px) {
    .d-mobile-only {
        display: none !important;
    }
}

/* ========================================
   SIDEBAR MOBILE STYLES
   ======================================== */

@media (max-width: 991px) {
    :root {
        --sidebar-width: 280px;
    }
    
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: none;
    }
    
    .sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100%;
    }
    
    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
}

/* ========================================
   TOP NAVBAR MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    .top-navbar {
        padding: 0.5rem 0.75rem !important;
        flex-wrap: wrap;
    }
    
    .top-navbar .text-muted {
        font-size: 0.75rem;
        display: none;
    }
    
    .top-navbar .dropdown-toggle {
        padding: 0.25rem 0.5rem;
        font-size: 0.875rem;
    }
    
    .top-navbar .badge {
        display: none;
    }
    
    /* Mobile hamburger button */
    #sidebarToggle {
        padding: 0.5rem;
        margin-right: 0.5rem;
    }
    
    #sidebarToggle i {
        font-size: 1.5rem !important;
    }
}

/* ========================================
   TABLE MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    /* Make tables more readable on mobile */
    .table {
        font-size: 0.85rem;
    }
    
    .table th, .table td {
        padding: 0.5rem;
        white-space: nowrap;
    }
    
    /* Hide less important columns on mobile */
    .table .d-mobile-hide {
        display: none !important;
    }
    
    /* Action buttons in tables */
    .table .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .table .btn-group {
        flex-direction: column;
        gap: 0.25rem;
    }
}

/* ========================================
   FORM MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.25rem;
    }
    
    .form-group, .mb-3 {
        margin-bottom: 0.75rem !important;
    }
    
    /* Stack form buttons */
    .form-actions, .btn-group-form {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .form-actions .btn {
        width: 100%;
    }
}

/* ========================================
   DASHBOARD SPECIFIC MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    /* Dashboard header */
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }
    
    .dashboard-header h4 {
        font-size: 1.25rem;
    }
    
    .dashboard-header .btn-group {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .dashboard-header .btn {
        flex: 1;
        min-width: 45%;
    }
    
    /* Patient queue items */
    .patient-queue-item {
        padding: 0.75rem;
    }
    
    .patient-queue-item .patient-name {
        font-size: 0.95rem;
    }
    
    .patient-queue-item .btn-group {
        flex-wrap: wrap;
        gap: 0.25rem;
        margin-top: 0.5rem;
    }
    
    .patient-queue-item .btn {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    
    /* Doctor dashboard sections */
    .doctor-section .card {
        margin-bottom: 1rem;
    }
    
    /* Vital signs cards */
    .vital-signs-card .row {
        flex-wrap: wrap;
    }
    
    .vital-signs-card .vital-item {
        flex: 0 0 50%;
        margin-bottom: 0.5rem;
    }
}

/* ========================================
   LOGIN PAGE MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    .login-container {
        padding: 1rem;
    }
    
    .login-card {
        margin: 0;
        border-radius: 10px;
    }
    
    .login-card .card-body {
        padding: 1.5rem;
    }
    
    .login-card h3 {
        font-size: 1.5rem;
    }
}

/* ========================================
   MAIN WEBSITE MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    /* Header adjustments */
    .header {
        padding: 10px 0;
    }
    
    .header .logo h1 {
        font-size: 1.25rem;
    }
    
    .header .logo .my-icon {
        width: 30px;
        height: 30px;
    }
    
    /* Mobile menu button */
    .mobile-nav-toggle {
        font-size: 28px;
        cursor: pointer;
        color: var(--nav-color);
        z-index: 9999;
    }
    
    /* Hero section */
    .hero {
        padding: 60px 0 30px;
    }
    
    .hero h2 {
        font-size: 1.75rem;
    }
    
    .hero p {
        font-size: 1rem;
    }
    
    /* Section padding */
    section {
        padding: 40px 0;
    }
    
    .section-title h2 {
        font-size: 1.5rem;
    }
    
    /* Footer */
    .footer {
        padding: 30px 0;
    }
    
    .footer .footer-links {
        margin-bottom: 1.5rem;
    }
}

/* ========================================
   IVF PORTAL MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    .ivf-portal-header {
        padding: 1rem;
    }
    
    .ivf-portal-header h1 {
        font-size: 1.5rem;
    }
    
    .ivf-stage-card {
        padding: 0.75rem;
    }
    
    .ivf-timeline {
        padding-left: 1rem;
    }
}

/* ========================================
   PRINT STYLES (hide mobile elements)
   ======================================== */

@media print {
    .sidebar,
    .top-navbar,
    #sidebarToggle,
    .sidebar-overlay,
    .mobile-nav-toggle {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn {
        min-height: 48px;
    }
    
    .nav-link {
        min-height: 48px;
        display: flex;
        align-items: center;
    }
    
    /* Remove hover effects that don't work on touch */
    .table-hover tbody tr:hover {
        background-color: inherit;
    }
    
    /* Better scrolling */
    .table-responsive,
    .card-body,
    .modal-body {
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   LANDSCAPE MOBILE ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        width: 220px;
    }
    
    .modal-dialog {
        max-height: 90vh;
        margin: 1rem auto;
    }
    
    .modal-body {
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* ========================================
   SMALL MOBILE (< 375px)
   ======================================== */

@media (max-width: 375px) {
    .content-wrapper {
        padding: 0.5rem !important;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    h4 {
        font-size: 1.1rem;
    }
    
    .btn {
        font-size: 0.875rem;
    }
    
    .stat-card h3 {
        font-size: 1.25rem;
    }
}

/* ========================================
   DOCTOR DASHBOARD MOBILE STYLES
   ======================================== */

@media (max-width: 991px) {
    /* Doctor dashboard page specific */
    .doctor-dashboard-page .row {
        margin-left: -5px;
        margin-right: -5px;
    }
    
    .doctor-dashboard-page .row > [class*="col-"] {
        padding-left: 5px;
        padding-right: 5px;
    }
    
    /* Patient queue on mobile */
    .doctor-dashboard-page .patient-queue {
        max-height: 300px;
        overflow-y: auto;
    }
    
    /* Selected patient card */
    .selected-patient-card {
        position: sticky;
        top: 0;
        z-index: 100;
        margin-bottom: 10px;
    }
    
    /* Doctor sections */
    .doctor-section {
        padding: 10px;
    }
    
    /* Form inputs in doctor dashboard */
    .doctor-dashboard-page textarea {
        min-height: 80px;
    }
    
    /* Accordion items */
    .doctor-dashboard-page .accordion-button {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
    
    .doctor-dashboard-page .accordion-body {
        padding: 0.75rem;
    }
}

@media (max-width: 576px) {
    /* Extra small screens */
    .doctor-dashboard-page .card-header {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    
    .doctor-dashboard-page .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .doctor-dashboard-page .btn-group .btn {
        width: 100%;
        margin-bottom: 5px;
        border-radius: 5px !important;
    }
    
    /* Patient list items */
    .patient-list-item {
        padding: 8px;
    }
    
    .patient-list-item .patient-name {
        font-size: 0.9rem;
    }
    
    /* Vital signs display */
    .vital-display .row > div {
        margin-bottom: 8px;
    }
}

/* ========================================
   PHARMACY DASHBOARD MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    .pharmacy-dashboard-page .stat-card .card-body {
        padding: 0.75rem;
    }
    
    .pharmacy-dashboard-page .stat-card h3 {
        font-size: 1.25rem;
    }
    
    /* Drug inventory table */
    #inventoryTable th,
    #inventoryTable td {
        font-size: 0.8rem;
        padding: 0.4rem;
    }
}

/* ========================================
   RECEPTION DASHBOARD MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    .reception-dashboard-page .quick-action-card {
        margin-bottom: 10px;
    }
    
    .reception-dashboard-page .patient-queue-item {
        padding: 10px;
    }
}

/* ========================================
   NURSE DASHBOARD MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
    .nurse-dashboard-page .vital-input-group {
        margin-bottom: 10px;
    }
    
    .nurse-dashboard-page .patient-card {
        margin-bottom: 10px;
    }
}

/* ========================================
   COMPREHENSIVE DASHBOARD MOBILE STYLES
   ======================================== */

/* --- Top Navbar Mobile --- */
@media (max-width: 768px) {
    .top-navbar .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .top-navbar .dropdown .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }
    .top-navbar .dropdown-menu {
        position: fixed !important;
        top: auto !important;
        bottom: 0;
        left: 0 !important;
        right: 0;
        width: 100%;
        border-radius: 16px 16px 0 0;
        transform: none !important;
        max-height: 70vh;
        overflow-y: auto;
    }
}

/* --- Quick Action Cards --- */
@media (max-width: 768px) {
    .quick-action-card,
    .action-card {
        margin-bottom: 0.75rem;
    }
    .quick-action-card .card-body,
    .action-card .card-body {
        padding: 0.75rem;
    }
    .quick-action-card h6,
    .action-card h6 {
        font-size: 0.8rem;
    }
    .quick-action-card .btn,
    .action-card .btn {
        width: 100%;
        margin-top: 0.5rem;
    }
}

/* --- Stat Cards Grid (all dashboards) --- */
@media (max-width: 576px) {
    .row.g-3 > [class*="col-"],
    .row.g-4 > [class*="col-"] {
        flex: 0 0 50%;
        max-width: 50%;
    }
    .stat-card .card-body,
    .stat-card {
        padding: 0.65rem !important;
    }
    .stat-card h2,
    .stat-card .stat-value {
        font-size: 1.25rem !important;
    }
    .stat-card h6,
    .stat-card .stat-label {
        font-size: 0.65rem !important;
    }
    .stat-card .stat-icon,
    .stat-icon-box {
        width: 36px !important;
        height: 36px !important;
        font-size: 1.1rem !important;
    }
    .stat-card .bg-primary.bg-opacity-10,
    .stat-card .bg-success.bg-opacity-10,
    .stat-card .bg-warning.bg-opacity-10,
    .stat-card .bg-danger.bg-opacity-10,
    .stat-card .bg-info.bg-opacity-10 {
        padding: 0.5rem !important;
    }
}

/* --- Card Header Responsive --- */
@media (max-width: 768px) {
    .card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }
    .card-header .d-flex,
    .card-header .btn-group {
        width: 100%;
        flex-wrap: wrap;
    }
    .card-header .btn-group .btn {
        flex: 1;
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
    }
    .card-header .input-group {
        width: 100% !important;
    }
    .card-header input[type="month"] {
        width: 100% !important;
    }
}

/* --- Button Groups on Mobile --- */
@media (max-width: 576px) {
    .btn-group:not(.btn-group-sm) {
        flex-wrap: wrap;
    }
    .d-flex.gap-2 {
        flex-wrap: wrap;
    }
    .d-flex.gap-3 {
        flex-wrap: wrap;
    }
}

/* --- Tables: Better Horizontal Scroll Hint --- */
@media (max-width: 768px) {
    .table-responsive {
        position: relative;
    }
    .table-responsive::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
        pointer-events: none;
        z-index: 1;
    }
}

/* --- Telemedicine Dashboard Mobile --- */
@media (max-width: 768px) {
    .telemedicine-page .tm-header {
        padding: 20px 16px;
        border-radius: 12px;
    }
    .telemedicine-page .tm-header h2 {
        font-size: 1.2rem;
    }
    .telemedicine-page .tm-card {
        padding: 14px;
    }
}

/* --- HMO Dashboard Mobile --- */
@media (max-width: 768px) {
    .hmo-search-box {
        flex-direction: column;
    }
    .hmo-search-box .form-control,
    .hmo-search-box .btn {
        width: 100%;
    }
    .accordion-button {
        padding: 0.65rem 0.75rem;
        font-size: 0.875rem;
    }
    .accordion-body {
        padding: 0.75rem;
    }
}

/* --- Accounts Dashboard Mobile --- */
@media (max-width: 768px) {
    #admittedList .list-group-item {
        padding: 0.65rem;
    }
    #billingDetails .table td,
    #billingDetails .table th {
        padding: 0.4rem;
        font-size: 0.8rem;
    }
}

/* --- Admin Dashboard Mobile --- */
@media (max-width: 768px) {
    .admin-header-card {
        flex-direction: column;
        text-align: center;
    }
    .admin-header-card .btn-group {
        width: 100%;
        justify-content: center;
    }
}

/* --- IVF Dashboards Mobile --- */
@media (max-width: 768px) {
    .ivf-patient-list .list-group-item {
        padding: 0.65rem;
    }
    .ivf-patient-list .badge {
        font-size: 0.65rem;
    }
}

/* --- Modals: Full-Screen on Mobile --- */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        min-height: 100vh;
    }
    .modal-content {
        border-radius: 0 !important;
        min-height: 100vh;
    }
    .modal-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: #fff;
    }
    .modal-footer {
        position: sticky;
        bottom: 0;
        z-index: 10;
        background: #fff;
    }
    .modal-body {
        max-height: none;
        overflow-y: auto;
    }
}

/* --- Cashier/Matron Sidebar Mobile Close on Link Click --- */
@media (max-width: 991px) {
    .cashier-sidebar,
    .matron-sidebar {
        z-index: 1000;
    }
    .cashier-sidebar .nav-link,
    .matron-sidebar .nav-link {
        padding: 12px 16px;
    }
}

/* --- SuperAdmin Layout Mobile --- */
@media (max-width: 991px) {
    .sa-footer {
        text-align: center;
    }
    .sa-footer .d-flex {
        flex-direction: column;
        gap: 0.25rem;
    }
}

/* --- Records Dashboard Mobile --- */
@media (max-width: 768px) {
    #doctorDocsBody td,
    #dispensesBody td,
    #labBody td,
    #regBody td,
    #ancBody td {
        font-size: 0.8rem;
        padding: 0.4rem;
    }
}

/* --- Doctor Dashboard Navigation (Section Tabs) --- */
@media (max-width: 991px) {
    .doctor-nav-sidebar {
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        margin-bottom: 1rem;
    }
    .doctor-nav-sidebar .nav {
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    .doctor-nav-sidebar .nav-link {
        padding: 0.4rem 0.75rem !important;
        font-size: 0.8rem;
        white-space: nowrap;
    }
    .doctor-nav-sidebar .nav-link i {
        margin-right: 4px !important;
    }
    .doctor-nav-sidebar .nav-link span.d-none {
        display: inline !important;
    }
}

/* --- Floating Action Button (FAB) for mobile navigation --- */
.mobile-fab {
    display: none;
}

@media (max-width: 768px) {
    .mobile-fab {
        display: flex;
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--primary-color, #0f766e);
        color: #fff;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0,0,0,0.25);
        z-index: 998;
        font-size: 1.5rem;
        border: none;
        cursor: pointer;
        transition: transform 0.2s;
    }
    .mobile-fab:hover {
        transform: scale(1.1);
    }
}

/* --- Bottom Safe Area (for notched phones) --- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .content-wrapper {
            padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)) !important;
        }
        .modal-footer {
            padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
        }
    }
}

/* --- Prevent Horizontal Overflow --- */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
    }
    .main-content {
        overflow-x: hidden;
    }
    .row {
        margin-left: 0;
        margin-right: 0;
    }
}

/* --- Collapsible Section Headers on Mobile --- */
@media (max-width: 768px) {
    .card > .card-header[data-bs-toggle="collapse"] {
        padding: 0.65rem 0.75rem;
    }
    .card > .card-header[data-bs-toggle="collapse"] span {
        font-size: 0.85rem;
    }
    .card > .card-header .btn-group-sm .btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }
}

/* --- Print Receipt / Invoice on Mobile --- */
@media (max-width: 768px) {
    .receipt-container,
    .invoice-container {
        padding: 0.5rem !important;
        font-size: 0.85rem;
    }
}
