/* ================================================================
   DrHelper Global Responsive & Mobile-First Stylesheet
   Included in footer.php — applies to ALL pages (except consultation)
   ================================================================ */

/* --- PAGE LOADING OVERLAY --- */
#drh-page-loader {
    position: fixed; inset: 0; z-index: 99999;
    background: rgba(255,255,255,0.92);
    display: flex; align-items: center; justify-content: center;
    flex-direction: column; gap: 14px;
    transition: opacity 0.35s ease;
}
#drh-page-loader.drh-loader-hide { opacity: 0; pointer-events: none; }
#drh-page-loader .drh-loader-spinner {
    width: 44px; height: 44px;
    border: 4px solid #e2e8f0;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: drh-spin 0.7s linear infinite;
}
#drh-page-loader .drh-loader-text {
    font-family: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
    font-size: 13px; font-weight: 700; color: #64748b;
    letter-spacing: 0.3px;
}
@keyframes drh-spin { to { transform: rotate(360deg); } }

/* --- SAFE AREA & SMOOTH SCROLL --- */
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }

/* --- PREVENT HORIZONTAL OVERFLOW GLOBALLY --- */
html, body { overflow-x: hidden; max-width: 100vw; }
body, .main-content, main, .container, .container-fluid { overflow-x: clip; }
.row { max-width: 100%; }
[class*="col-"] { min-width: 0; }

/* --- GLOBAL INPUT TOUCH OPTIMIZATION --- */
@media (max-width: 991px) {
    input, select, textarea, button, .btn {
        font-size: 16px !important; /* prevents iOS zoom on focus */
    }
    input[type="date"], input[type="number"], input[type="tel"] {
        min-height: 44px;
    }
    .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    .btn-sm { min-height: 38px; }
}

/* --- TABLES: GLOBAL CARD CONVERSION on Mobile --- */
@media (max-width: 991px) {
    .table-responsive { overflow-x: auto !important; overflow-y: visible !important; -webkit-overflow-scrolling: touch; }

    /* Ensure all table containers scroll instead of pushing page width */
    table { word-break: break-word; }
    .table:not(.drh-mobile-cards) { display: table; width: 100%; }

    .drh-mobile-cards thead { display: none; }
    .drh-mobile-cards { border: none !important; }
    .drh-mobile-cards tbody { display: flex; flex-direction: column; gap: 10px; }
    .drh-mobile-cards tr {
        display: flex; flex-wrap: wrap;
        background: #fff; border: 1px solid #e2e8f0;
        border-radius: 14px; padding: 14px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.03);
        margin-bottom: 0;
    }
    .drh-mobile-cards td {
        border: none !important; padding: 4px 6px !important;
        display: flex; flex-direction: column;
    }
    .drh-mobile-cards td::before {
        content: attr(data-label);
        font-size: 9px; font-weight: 800;
        text-transform: uppercase; letter-spacing: 0.5px;
        color: #94a3b8; margin-bottom: 1px;
    }
    .drh-mobile-cards td:empty, .drh-mobile-cards td:blank { display: none; }
}

/* --- FORM RESPONSIVENESS --- */
@media (max-width: 991px) {
    .form-row, .row.form-row { margin-left: -4px; margin-right: -4px; }
    .form-row > [class*="col-"] { padding-left: 4px; padding-right: 4px; }

    .form-control, .form-control-sm, .custom-select {
        height: 44px; border-radius: 10px;
        background: #f8fafc; border: 1.5px solid #e2e8f0;
        font-weight: 600;
    }
    .form-control:focus, .custom-select:focus {
        background: #fff; border-color: #2563eb;
        box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
    }
    textarea.form-control { height: auto; min-height: 80px; }
}

/* --- MODAL RESPONSIVENESS --- */
@media (max-width: 991px) {
    .modal-dialog {
        margin: 8px !important; max-width: calc(100vw - 16px) !important;
    }
    .modal-content { border-radius: 18px !important; }
    .modal-header { padding: 14px 16px; }
    .modal-body { padding: 14px 16px; }
    .modal-footer { padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
    .modal-footer .btn { flex: 1; min-width: 120px; }
    .modal-title { font-size: 16px !important; }
}

/* --- CARD RESPONSIVENESS --- */
@media (max-width: 991px) {
    .card, .work-card, .app-panel, .emr-table-card {
        border-radius: 14px !important;
    }
    .card-body, .card-body-ocr { padding: 12px !important; }
}

/* --- BADGE & TAG SYSTEM --- */
@media (max-width: 991px) {
    .badge, .status-badge, .doctor-tag, .wait-tag, .inv-badge {
        font-size: 10px; padding: 4px 8px;
    }
}

/* --- ALERT/TOAST MOBILE --- */
@media (max-width: 991px) {
    .alert { font-size: 13px; padding: 10px 14px; border-radius: 12px; }
}

/* --- DROPDOWN MENUS MOBILE --- */
@media (max-width: 991px) {
    .dropdown-menu {
        min-width: calc(100vw - 30px) !important;
        max-width: calc(100vw - 30px) !important;
        border-radius: 14px !important;
    }
}

/* --- PAGINATION --- */
@media (max-width: 991px) {
    .pagination-app, .pagination { flex-wrap: wrap; justify-content: center; gap: 4px; }
    .page-link-app, .page-link { min-width: 38px; min-height: 38px; }
}

/* --- UTILITY CLASSES --- */
.drh-hide-mobile { }
.drh-hide-desktop { display: none !important; }
@media (max-width: 991px) {
    .drh-hide-mobile { display: none !important; }
    .drh-hide-desktop { display: flex !important; }
}
.drh-text-truncate-2 {
    display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}

/* --- HEADER MOBILE REFINEMENTS --- */
@media (max-width: 991px) {
    .emr-header {
        height: 56px !important;
        padding: 0 8px 0 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 8px !important;
        position: relative;
    }
    .header-left {
        display: flex !important;
        align-items: center !important;
        flex-direction: row !important;
        gap: 10px !important;
        flex: 1 1 auto;
        min-width: 0;
    }
    .hospital-name { font-size: 13px !important; max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .user-badge { font-size: 10px !important; }
    #sidebar-toggle {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 44px !important;
        height: 44px !important;
        border: none !important;
        background: transparent !important;
        font-size: 22px !important;
        margin-right: 8px !important;
        position: static !important;
    }
}
@media (max-width: 480px) {
    .emr-header { padding: 0 4px 0 44px !important; }
    .hospital-name { font-size: 12px !important; max-width: 90px; }
}

/* --- SIDEBAR MOBILE: APP-LIKE OVERLAY --- */
@media (max-width: 991px) {
    .emr-sidebar.active {
        box-shadow: 0 0 60px rgba(0,0,0,0.3);
    }
    #sidebar-toggle {
        width: 42px !important; height: 42px !important;
        top: 8px !important; left: 8px !important;
        border-radius: 12px !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.08) !important;
    }
}

/* --- FOOTER MOBILE --- */
@media (max-width: 991px) {
    .emr-footer {
        padding: 16px 12px !important;
        font-size: 11px;
    }
}

/* --- MAIN CONTENT MOBILE --- */
@media (max-width: 991px) {
    .main-content, main, .main-shell, .app-layout, .rf-shell, .sk-shell,
    .rx-shell, .ts-shell, .sync-main,
    [class*="main-content"], [class*="main-shell"] {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 10px !important;
        padding-top: 8px !important;
        box-sizing: border-box !important;
    }
    /* Prevent any child from pushing content wider than viewport */
    .main-content *, main *, .main-shell *, .app-layout *,
    .rf-shell *, .sk-shell *, .rx-shell * {
        max-width: 100%;
        box-sizing: border-box;
    }
    /* Allow tables and pre-formatted text to scroll internally */
    .main-content table, main table, .main-shell table,
    .main-content pre, main pre { max-width: none; }
}
@media (max-width: 480px) {
    .main-content, main, .main-shell, .app-layout,
    .rf-shell, .sk-shell, .rx-shell, .ts-shell, .sync-main { padding: 6px !important; }
}

/* --- PRINT: HIDE MOBILE ARTIFACTS --- */
@media print {
    #drh-page-loader,
    #sidebar-toggle,
    .emr-sidebar { display: none !important; }
    .main-content, main { margin-left: 0 !important; width: 100% !important; }
}

/* --- GLOBAL OVERFLOW SAFETY: Row/Form containers --- */
@media (max-width: 991px) {
    .row, .form-row { margin-left: 0; margin-right: 0; overflow-x: hidden; }
    .row > [class*="col-"], .form-row > [class*="col-"] {
        padding-left: 4px; padding-right: 4px;
    }
    /* Images must never exceed container */
    img { max-width: 100%; height: auto; }
    /* Fixed-width inline elements should shrink */
    [style*="min-width"] { min-width: 0 !important; }
    /* Nav pill/tab overflow: horizontal scrollable instead of page-pushing */
    .nav-pills, .nav-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .nav-pills .nav-link, .nav-tabs .nav-link { white-space: nowrap; flex-shrink: 0; }
}
@media (max-width: 576px) {
    /* Extra safety for small phones */
    .container, .container-fluid { padding-left: 6px; padding-right: 6px; }
    .row { margin-left: -3px; margin-right: -3px; }
    .row > [class*="col-"] { padding-left: 3px; padding-right: 3px; }
}
