/* styles.css - e-HPIA/CliSQi v6.0 */

/* =========================================
   0. GLOBAL TYPOGRAPHY
   ========================================= */
html {
    font-size: 105%;
}

/* =========================================
   1. THEME VARIABLES (LIGHT & DARK MODE)
   ========================================= */

/* Default (Dark Mode Theme) */
:root, [data-bs-theme="dark"] {
  --sidebar-width: 260px;
  --moh-primary: #3b82f6; 
  --moh-primary-hover: #60a5fa;

  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  
  --input-bg: #0f172a;
  --input-text: #f8fafc;
  
  --pill-bg: #334155;
  --pill-text: #94a3b8;
}

/* Light Mode Overrides (Cream & Royal Blue Theme) */
[data-bs-theme="light"] {
  --moh-primary: #1d4ed8; 
  --moh-primary-hover: #1e3a8a;
  
  --bg-main: #fdfcf8; 
  --bg-card: #ffffff;
  --bg-sidebar: #f8f9fa;
  
  --text-main: #000000; 
  --text-muted: #334155; 
  --border-color: #cbd5e1;
  
  --input-bg: #ffffff;
  --input-text: #000000;
  
  --pill-bg: #e2e8f0;
  --pill-text: #1e293b;
}

/* =========================================
   2. GENERAL STYLES
   ========================================= */
body { 
    background-color: var(--bg-main); 
    color: var(--text-main); 
    font-family: 'Inter', system-ui, sans-serif; 
    overflow-x: hidden; 
    transition: background-color 0.3s, color 0.3s;
}

.text-muted {
    color: var(--text-muted) !important;
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.center-screen { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 20px;}
.hidden { display: none !important; }

.card { 
    background-color: var(--bg-card); 
    border: 1px solid var(--border-color); 
    border-radius: 0.75rem; 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.text-moh { color: var(--moh-primary) !important; }

.form-control, .form-select { 
    background-color: var(--input-bg); 
    border-color: var(--border-color); 
    color: var(--input-text); 
}
.form-control:focus, .form-select:focus { 
    background-color: var(--input-bg); 
    border-color: var(--moh-primary); 
    color: var(--input-text); 
    box-shadow: 0 0 0 0.25rem rgba(59, 130, 246, 0.25); 
}

/* Make Top-Right Action Buttons Smaller */
.theme-toggle .btn {
    padding: 0.15rem 0.4rem; 
    font-size: 0.75rem;      
    line-height: 1.2;
}

/* =========================================
   3. LAYOUT & SIDEBAR
   ========================================= */
.sidebar { 
    position: fixed; top: 0; bottom: 0; left: 0; 
    width: var(--sidebar-width); 
    background-color: var(--bg-sidebar); 
    border-right: 1px solid var(--border-color); 
    z-index: 1050; 
    transition: transform 0.3s ease; 
    overflow-y: auto;
}
.main-content { 
    margin-left: var(--sidebar-width); 
    padding: 2rem; 
    transition: margin-left 0.3s; 
    min-height: 100vh; 
}

.mobile-header { 
    display: none; position: fixed; top: 0; left: 0; right: 0; height: 60px; 
    background-color: var(--bg-sidebar); 
    border-bottom: 1px solid var(--border-color); 
    z-index: 1040; align-items: center; padding: 0 1rem; 
}
.sidebar-overlay { 
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1045; 
}
.sidebar-overlay.show { display: block; }

@media (max-width: 992px) { 
    .sidebar { transform: translateX(-100%); } 
    .sidebar.show { transform: translateX(0); box-shadow: 10px 0 15px rgba(0,0,0,0.5); } 
    .main-content { margin-left: 0; padding: 5rem 1rem 1rem 1rem; } 
    .mobile-header { display: flex !important; }
}

.nav-link { 
    color: var(--text-muted); padding: 0.75rem 1.5rem; 
    border-radius: 0.5rem; margin: 0.25rem 1rem; 
    cursor: pointer; text-decoration: none !important; 
    display: flex; align-items: center; 
}
.nav-link:hover, .nav-link.active { 
    background: rgba(59, 130, 246, 0.1); 
    color: var(--moh-primary); 
    font-weight: 600;
}
.nav-link i { font-size: 1.2rem; margin-right: 0.75rem; }

/* =========================================
   SIDEBAR BUTTON CONTRAST FIX (LIGHT MODE)
   ========================================= */
[data-bs-theme="light"] .sidebar .btn-outline-info {
    color: #0369a1 !important; 
    border-color: #0369a1 !important;
    font-weight: 600;
}
[data-bs-theme="light"] .sidebar .btn-outline-info:hover {
    background-color: #0369a1 !important;
    color: #ffffff !important;
}

[data-bs-theme="light"] .sidebar .btn-outline-warning {
    color: #b45309 !important; 
    border-color: #b45309 !important;
    font-weight: 600;
}
[data-bs-theme="light"] .sidebar .btn-outline-warning:hover {
    background-color: #b45309 !important;
    color: #ffffff !important;
}

[data-bs-theme="light"] .sidebar .btn-outline-danger {
    color: #be123c !important; 
    border-color: #be123c !important;
    font-weight: 600;
}
[data-bs-theme="light"] .sidebar .btn-outline-danger:hover {
    background-color: #be123c !important;
    color: #ffffff !important;
}

/* =========================================
   4. COMPONENTS & UTILITIES
   ========================================= */
.service-reference {
    border: 1px solid var(--border-color); border-radius: 4px; padding: 10px; 
    font-size: 0.7rem; max-height: 50px; overflow-y: auto; 
    line-height: 1.5; margin-top: 8px; margin-bottom: 20px;
}
.service-checkbox-container { 
    max-height: 200px; overflow-y: auto; 
    background-color: var(--input-bg); 
    border: 1px solid var(--border-color); 
    border-radius: 6px; padding: 10px; 
}

@keyframes pulse-red { 
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); } 
    70% { box-shadow: 0 0 0 6px rgba(220, 53, 69, 0); } 
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); } 
}
.flag-alert { 
    animation: pulse-red 2s infinite; border-radius: 50%; display: inline-block; 
    width: 10px; height: 10px; background-color: #dc3545; 
    vertical-align: middle; margin-right: 5px; 
}

.discipline-pill { 
    font-size: 0.65rem; background-color: var(--pill-bg); 
    color: var(--pill-text); padding: 2px 6px; 
    border-radius: 4px; margin-top: 2px; display: inline-block; 
    font-weight: 600;
}

.inline-input { 
    background-color: var(--input-bg) !important; 
    border: 1px solid var(--border-color) !important; 
    color: var(--input-text) !important; 
    font-size: 0.85rem; padding: 0.25rem 0.5rem; width: 100%; 
}
.sortable { cursor: pointer; }
.sortable:hover { color: var(--moh-primary); }

.table-responsive { max-height: 70vh; overflow-y: auto; }
thead.sticky-top th { z-index: 10; box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); background-color: var(--bg-card); }
[data-bs-theme="dark"] thead.sticky-top th { box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.4); background-color: var(--bg-card); }

.table { color: var(--text-main); }
.table-hover tbody tr:hover { color: var(--text-main); }

.pagination { margin-bottom: 0; }
.page-link { background-color: var(--bg-card); border-color: var(--border-color); color: var(--text-muted); font-size: 0.85rem; }
.page-link:hover { background-color: var(--pill-bg); color: var(--text-main); border-color: var(--border-color); }
.page-item.active .page-link { background-color: var(--moh-primary); border-color: var(--moh-primary); color: #fff; }
.page-item.disabled .page-link { background-color: var(--bg-main); border-color: var(--border-color); color: var(--text-muted); }

#loadingOverlay { 
    position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 2000; 
    display: flex; justify-content: center; align-items: center; backdrop-filter: blur(2px); 
}
.spinner { 
    width: 3rem; height: 3rem; border: 4px solid var(--moh-primary); 
    border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; 
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   5. PVF FORM STYLES (SCREEN)
   ========================================= */
/* Hidden on screen – only shown when printing PVF */
#pvf-container {
    display: none;
    background: white;
    color: black;
    padding: 25px 40px;
    font-family: 'Times New Roman', serif;
    max-width: 210mm;
    margin: 0 auto;
}
.pvf-logo-container { text-align: center; margin-bottom: 10px; }
.pvf-header-title { text-align: center; font-weight: bold; font-size: 16px; margin-bottom: 5px; text-transform: uppercase; }
.pvf-header-sub { text-align: center; font-size: 12px; margin-bottom: 15px; }
.pvf-section { border: 2px solid #000; margin-bottom: 15px; padding: 10px 15px; position: relative; }
.pvf-section-title { position: absolute; top: -10px; left: 15px; background: white; padding: 0 10px; font-weight: bold; font-size: 12px; }
.pvf-row { display: flex; margin-bottom: 8px; align-items: center; }
.pvf-label { font-weight: bold; width: 180px; font-size: 12px; flex-shrink: 0; }
.pvf-value { border-bottom: 1px dotted #000; flex-grow: 1; padding-left: 10px; font-size: 12px; }
.pvf-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.pvf-table th, .pvf-table td { border: 1px solid black; padding: 8px; text-align: left; vertical-align: top; }
.pvf-table th { background-color: #f0f0f0; text-align: center; font-weight: bold; }
.pvf-check-group { display: inline-flex; align-items: center; margin-right: 20px; }
.pvf-check { display: inline-block; width: 14px; height: 14px; border: 1px solid black; margin-right: 5px; text-align: center; line-height: 12px; font-size: 12px; vertical-align: middle; flex-shrink: 0; }
.pvf-check.checked::after { content: 'X'; font-weight: bold; }
.pvf-sig-box { border: 1px solid black; height: 95px; padding: 10px; font-size: 11px; position: relative; }
.pvf-sig-title { font-weight: bold; margin-bottom: 15px; text-decoration: underline; font-size: 12px; }
.pvf-sig-content { font-family: 'Courier New', monospace; white-space: pre-wrap; line-height: 1.2; font-size: 12px; }
.print-director-col { display: none; } 

/* =========================================
   6. PRINT STYLES — SHARED RESET
      Applied to BOTH PVF and List modes
   ========================================= */
@media print {

    /* --- 6a. Page Setup --- */
    @page {
        size: A4 portrait;
        margin: 1cm;
    }

    /* --- 6b. Hard reset of dark-mode variables --- */
    :root,
    [data-bs-theme="dark"],
    [data-bs-theme="light"] {
        --bg-main:   #ffffff !important;
        --bg-card:   #ffffff !important;
        --bg-sidebar:#ffffff !important;
        --text-main: #000000 !important;
        --text-muted:#000000 !important;
        --border-color: #999999 !important;
        --input-bg:  #ffffff !important;
        --input-text:#000000 !important;
        --bs-body-bg:#ffffff !important;
        --bs-body-color: #000000 !important;
    }

    /* --- 6c. Base document reset --- */
    html, body {
        background: white !important;
        background-color: white !important;
        color: black !important;
        height: auto !important;
        overflow: visible !important;
        font-size: 10pt !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-text-size-adjust: 100% !important;
        text-size-adjust: 100% !important;
    }

    /* --- 6d. Strip Bootstrap dark-card styling --- */
    .bg-dark, .table-dark, .card {
        background-color: transparent !important;
        color: black !important;
        border: none !important;
        box-shadow: none !important;
    }
    .text-white { color: black !important; }
    .badge { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

    /* --- 6e. Always hide UI chrome --- */
    .sidebar,
    .mobile-header,
    .btn-toolbar,
    .no-print,
    .btn,
    .navbar-toggler,
    header,
    #bulkActions,
    #loadingOverlay,
    .pagination,
    .theme-toggle,
    .filters,
    .sidebar-overlay {
        display: none !important;
    }

    /* =========================================
       7. PRINT MODE A — PVF FORM
          Uses explicit .printing-pvf class.
          This replaces the old body:not(.printing-list)
          approach which was unreliable on Android Chrome —
          the print engine evaluated :not() against the
          default (no-class) body state, causing the blank
          PVF to appear whenever printing the list.
       ========================================= */

    /* Safety net: hide PVF for ALL print modes by default.
       Only .printing-pvf below can reveal it. */
    #pvf-container {
        display: none !important;
    }

    /* Hide the whole app layout in PVF mode */
    body.printing-pvf #appLayout {
        display: none !important;
    }

    /* Show PVF only when JS has explicitly set .printing-pvf */
    body.printing-pvf #pvf-container {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        z-index: auto !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* PVF inner element fixes */
    body.printing-pvf .pvf-section-title {
        background: #ffffff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    body.printing-pvf .pvf-table th {
        background-color: #f0f0f0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    body.printing-pvf .pvf-sig-box {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }
    body.printing-pvf .pvf-row {
        break-inside: avoid !important;
    }

    /* =========================================
       8. PRINT MODE B — LIST / TABLE VIEW
          Triggered when body HAS .printing-list
       ========================================= */

    /* Redundant but explicit — belt-and-braces */
    body.printing-list #pvf-container {
        display: none !important;
    }

    /* Show the app layout */
    body.printing-list #appLayout {
        display: block !important;
    }

    body.printing-list .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        min-height: auto !important;
    }

    /* Remove overflow clipping so full table renders */
    body.printing-list .table-responsive,
    body.printing-list .overflow-hidden,
    body.printing-list [style*="overflow"] {
        overflow: visible !important;
        max-height: none !important;
        height: auto !important;
        display: block !important;
    }

    /* Proper table print behaviour */
    body.printing-list table {
        width: 100% !important;
        page-break-inside: auto !important;
        border-collapse: collapse !important;
        color: black !important;
        table-layout: fixed !important;
        word-wrap: break-word !important;
    }
    body.printing-list thead {
        display: table-header-group !important;
    }
    body.printing-list tr {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        page-break-after: auto !important;
    }
    body.printing-list th,
    body.printing-list td {
        border: 1px solid #000 !important;
        padding: 4px 6px !important;
        font-size: 8.5pt !important;
        vertical-align: top !important;
        background-color: white !important;
        color: black !important;
        word-break: break-word !important;
    }
    body.printing-list th {
        background-color: #eeeeee !important;
        font-weight: bold !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Card wrapper in list mode */
    body.printing-list .card {
        border: 1px solid #000 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    /* Director column (only shown in list print) */
    body.printing-list .print-director-col {
        display: table-cell !important;
        width: 120px !important;
        text-align: center !important;
        vertical-align: bottom !important;
        font-size: 8pt !important;
    }
    body.printing-list .director-box {
        border: 1px solid #000 !important;
        height: 40px !important;
        margin-top: 5px !important;
    }

    /* ---- View isolation: hide all views, then show only the active one ---- */
    body.printing-list #view_dashboard,
    body.printing-list #view_approver,
    body.printing-list #view_history,
    body.printing-list #view_users,
    body.printing-list #view_indicators,
    body.printing-list #view_logs {
        display: none !important;
    }

    body.printing-list.print-dashboard  #view_dashboard  { display: block !important; }
    body.printing-list.print-approver   #view_approver   { display: block !important; }
    body.printing-list.print-history    #view_history    { display: block !important; }
    body.printing-list.print-users      #view_users      { display: block !important; }
    body.printing-list.print-indicators #view_indicators { display: block !important; }
    body.printing-list.print-logs       #view_logs       { display: block !important; }
}