/**
 * QHSE JSA & HIRA Builder - Enterprise Stylesheet
 * Fully Integrated: Admin DataTables, Dialogs, Dashboards, and Gas Map UI/UX
 */

:root {
    --qhse-bg-main: #e2e8f0;
    --qhse-card-bg: #ffffff;
    --qhse-border: #cbd5e1;
    --qhse-border-subtle: #e2e8f0;
    --qhse-text-main: #0f172a;
    --qhse-text-muted: #64748b;
    --qhse-primary: #1d4ed8;
    --qhse-primary-hover: #1e40af;
    --qhse-secondary: #0f766e;
    --qhse-secondary-hover: #115e59;
    --qhse-danger: #dc2626;
    --qhse-danger-hover: #b91c1c;
    --qhse-success: #16a34a;
    --qhse-warning: #f59e0b;
    --qhse-radius: 10px;
    --qhse-radius-sm: 6px;
    --qhse-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --qhse-shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

/* Base App Container */
#qhse-hira-app, 
.qhse-workspace {
    position: relative;
    background: var(--qhse-bg-main);
    border: 1px solid var(--qhse-border);
    border-radius: var(--qhse-radius);
    padding: 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    color: var(--qhse-text-main);
    box-sizing: border-box;
    box-shadow: var(--qhse-shadow);
}
#qhse-hira-app * { box-sizing: border-box; }

/* RTL Support */
[dir="rtl"] #qhse-hira-app { text-align: right; }
[dir="rtl"] .qhse-zone-card, [dir="rtl"] .qhse-card { border-left: 1px solid var(--qhse-border); border-right: 4px solid var(--qhse-success); }
[dir="rtl"] .qhse-toast { transform: translateX(-120%); }
[dir="rtl"] .qhse-toast.show { transform: translateX(0); }

/* Toast Notifications */
#qhse-hira-toast-container { position: fixed; bottom: 25px; right: 25px; display: flex; flex-direction: column; gap: 10px; z-index: 999999; pointer-events: none; }
.qhse-toast { background: #ffffff; color: var(--qhse-text-main); padding: 12px 18px; border-radius: var(--qhse-radius); box-shadow: var(--qhse-shadow-md); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 10px; transform: translateX(120%); opacity: 0; transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease; border-left: 4px solid var(--qhse-border); pointer-events: auto; }
.qhse-toast.show { transform: translateX(0); opacity: 1; }
.qhse-toast-success { border-left-color: var(--qhse-success); }
.qhse-toast-error { border-left-color: var(--qhse-danger); }

/* Header & Controls */
.qhse-app-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; border-bottom: 1px solid var(--qhse-border); margin-bottom: 24px; padding-bottom: 20px; }
.qhse-brand h2 { margin: 4px 0 0 0; font-size: 22px; font-weight: 700; color: var(--qhse-text-main); }
.qhse-badge { background: #dbeafe; color: var(--qhse-primary); font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 3px 8px; border-radius: 20px; letter-spacing: 0.5px; }
.qhse-mode-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--qhse-text-muted); font-weight: 600; }
.qhse-mode-pill select { padding: 4px 8px; border-radius: 4px; border: 1px solid var(--qhse-border); cursor: pointer; }

/* Layout Grid */
.qhse-layout-grid { display: grid; grid-template-columns: 1fr 420px; gap: 24px; align-items: start; }
@media (max-width: 1080px) { .qhse-layout-grid { grid-template-columns: 1fr; } .qhse-side-column { position: static !important; } }
.qhse-main-column { display: flex; flex-direction: column; gap: 16px; }
.qhse-side-column { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 20px; }

/* Zone Cards (Legacy compatibility & New Gas Map Themes) */
.qhse-zone-card, .qhse-card { background: var(--qhse-card-bg); border: 1px solid var(--qhse-border); border-radius: var(--qhse-radius); padding: 16px 18px; box-shadow: var(--qhse-shadow); box-sizing: border-box; }
.qhse-card-title { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.qhse-zone-card h4, .qhse-card-title h3, .qhse-card-title h4 { margin: 0; font-size: 14px; font-weight: 800; color: var(--qhse-text-main); text-transform: uppercase; letter-spacing: 0.5px; }

.qhse-card-slate  { background: #ffffff; border-top: 4px solid #475569; }
.qhse-card-teal   { background: #f0fdfa; border-top: 4px solid #0f766e; }
.qhse-card-blue   { background: #f0f9ff; border-top: 4px solid #0284c7; }
.qhse-card-orange { background: #fff7ed; border-top: 4px solid #f59e0b; }
.qhse-card-purple { background: #faf5ff; border-top: 4px solid #a855f7; }
.qhse-card-green  { background: #f0fdf4; border-top: 4px solid #16a34a; }
.qhse-card-red    { background: #fef2f2; border-top: 4px solid #dc2626; }

/* Form Fields & Grids */
.qhse-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .qhse-form-grid { grid-template-columns: 1fr; } }
.qhse-field label { display: block; font-size: 11px; font-weight: 700; color: var(--qhse-text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.3px; }
.qhse-field input, .qhse-field select, .qhse-field textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--qhse-border); border-radius: var(--qhse-radius-sm); font-size: 13px; background-color: #fff; color: var(--qhse-text-main); box-shadow: inset 0 1px 2px rgba(0,0,0,0.02); transition: border-color 0.2s, box-shadow 0.2s; }
.qhse-field input:focus, .qhse-field select:focus, .qhse-field textarea:focus { outline: none; border-color: var(--qhse-primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12); }

/* Matrix Numerical Selectors */
.matrix-select { width: 54px !important; padding: 6px 8px !important; font-weight: bold; text-align: center; border-radius: 4px !important; }
.init-res, .res-res { width: 100px !important; text-align: center; font-size: 11px !important; font-weight: 800 !important; border: none !important; border-radius: 4px !important; color: #ffffff !important; }

/* Dynamic Hazard Container & Items */
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.qhse-hazard-block { background: #ffffff; border: 1px solid var(--qhse-border); border-radius: var(--qhse-radius); padding: 14px 16px; margin-bottom: 12px; border-left: 4px solid var(--qhse-primary); transition: box-shadow 0.2s, transform 0.2s; animation: fadeSlideIn 0.3s ease-out forwards; }
.qhse-hazard-block:hover { box-shadow: var(--qhse-shadow); }
.sortable-ghost { opacity: 0.4; background-color: #eff6ff !important; border: 1px dashed var(--qhse-primary) !important; }

/* Buttons */
.qhse-btn-action-primary, .qhse-btn-action-secondary, .qhse-btn-action-danger { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; font-size: 13px; font-weight: 700; border-radius: var(--qhse-radius-sm); border: none; cursor: pointer; transition: all 0.2s ease; width: 100%; box-shadow: 0 1px 3px rgba(0,0,0,0.1); text-decoration: none; }
.qhse-btn-action-primary { background: var(--qhse-primary); color: #fff; }
.qhse-btn-action-primary:hover:not(:disabled) { background: var(--qhse-primary-hover); transform: translateY(-1px); }
.qhse-btn-action-primary:disabled { background-color: #94a3b8 !important; color: #f1f5f9 !important; cursor: not-allowed !important; box-shadow: none !important; }
.qhse-btn-action-secondary { background: #ffffff; color: #1e293b; border: 1px solid var(--qhse-border); }
.qhse-btn-action-secondary:hover:not(:disabled) { background: #f8fafc; border-color: #94a3b8; transform: translateY(-1px); }
.qhse-btn-action-danger { background: var(--qhse-danger); color: #fff; }
.qhse-btn-action-danger:hover:not(:disabled) { background: var(--qhse-danger-hover); transform: translateY(-1px); }

/* Select2 UI/UX Enhancements & Fixes */
.select2-container--default .select2-selection--multiple { border: 1px solid var(--qhse-border) !important; border-radius: var(--qhse-radius-sm) !important; min-height: 40px !important; height: auto !important; padding: 4px !important; background-color: #ffffff !important; display: flex !important; }
.select2-container--default .select2-selection--multiple .select2-selection__rendered { display: flex !important; flex-wrap: wrap !important; gap: 4px !important; padding: 0 !important; margin: 0 !important; box-sizing: border-box !important; list-style: none !important; width: 100%; }
.select2-container--default .select2-selection--multiple .select2-selection__choice { background-color: #eff6ff !important; border: 1px solid #bfdbfe !important; color: #1e3a8a !important; font-size: 12px !important; font-weight: 600 !important; padding: 4px 8px 4px 24px !important; border-radius: 4px !important; margin: 0 !important; position: relative !important; white-space: normal !important; word-break: break-word !important; line-height: 1.4 !important; display: flex !important; align-items: center !important; max-width: 100% !important; box-sizing: border-box; }
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove { color: #3b82f6 !important; position: absolute !important; left: 6px !important; top: 50% !important; transform: translateY(-50%) !important; border: none !important; font-size: 16px !important; padding: 0 !important; margin: 0 !important; background: transparent !important; }
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover { color: var(--qhse-danger) !important; background: transparent !important; }
.select2-container--default .select2-selection--multiple .select2-search--inline { display: flex !important; margin: 0 !important; flex-grow: 1; }
.select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field { min-width: 150px !important; color: var(--qhse-text-main) !important; font-size: 13px !important; font-family: inherit !important; margin: 0 !important; padding: 4px !important; }
.select2-container--open .select2-dropdown { z-index: 99999 !important; border: 1px solid var(--qhse-primary) !important; box-shadow: 0 10px 25px rgba(0,0,0,0.1) !important; border-radius: var(--qhse-radius-sm) !important; overflow: hidden !important; }
.select2-results__option { padding: 10px 14px !important; font-size: 13px !important; border-bottom: 1px solid var(--qhse-border-subtle) !important; color: var(--qhse-text-main) !important; line-height: 1.4 !important; word-break: break-word !important; white-space: normal !important; }
.select2-results__option:last-child { border-bottom: none !important; }

/* Readability Hover Fixes */
.select2-results__option--highlighted[aria-selected],
.select2-results__option--highlighted[aria-selected]:hover { background-color: #e2e8f0 !important; color: #0f172a !important; font-weight: 700 !important; }
.qhse-btn-action-primary:disabled, .qhse-btn-action-primary:disabled:hover { background-color: #e2e8f0 !important; color: #64748b !important; cursor: not-allowed !important; box-shadow: none !important; }





.select2-results__option[aria-selected="true"] { background-color: #eff6ff !important; color: var(--qhse-text-muted) !important; position: relative; }

/* Assessment Dimension Groups */
.dim-group { display: none; }
.dim-group.active { display: block; }
.hidden { display: none !important; }

/* ==========================================================================
   ADMIN LIBRARY & DATATABLES ENHANCEMENTS
   ========================================================================== */
.qhse-table-card { background: #ffffff; border-radius: var(--qhse-radius); border: 1px solid var(--qhse-border); box-shadow: var(--qhse-shadow); overflow: hidden; margin-top: 15px; clear: both; width: 100%; }
.dataTables_wrapper { padding: 0 !important; clear: both; width: 100%; }
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { float: none !important; margin: 0 !important; text-align: left !important; }
.qhse-dt-controls { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: #ffffff; border-bottom: 1px solid var(--qhse-border-subtle); flex-wrap: wrap; gap: 10px; }
.qhse-dt-footer { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: #f8fafc; border-top: 1px solid var(--qhse-border-subtle); flex-wrap: wrap; gap: 10px; }
.dataTables_wrapper .dataTables_filter input { border: 1px solid var(--qhse-border) !important; border-radius: var(--qhse-radius-sm) !important; padding: 7px 12px !important; margin-left: 8px !important; width: 240px !important; font-size: 13px !important; box-shadow: inset 0 1px 2px rgba(0,0,0,0.02) !important; }
.dataTables_wrapper .dataTables_filter input:focus { outline: none !important; border-color: var(--qhse-primary) !important; box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1) !important; }
.dataTables_wrapper .dataTables_length select { border: 1px solid var(--qhse-border) !important; border-radius: var(--qhse-radius-sm) !important; padding: 4px 8px !important; margin: 0 4px !important; font-size: 13px !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button { padding: 5px 12px !important; margin: 0 2px !important; border-radius: var(--qhse-radius-sm) !important; border: 1px solid transparent !important; cursor: pointer !important; font-size: 12px !important; font-weight: 600 !important; display: inline-block !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current { background: var(--qhse-primary) !important; color: #ffffff !important; border: 1px solid var(--qhse-primary-hover) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover:not(.current) { background: #f1f5f9 !important; border: 1px solid var(--qhse-border) !important; color: #0f172a !important; }

/* ==========================================================================
   QHSE PROFESSIONAL DIALOG SYSTEM
   ========================================================================== */
.qhse-dialog-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 999999; opacity: 0; visibility: hidden; transition: opacity 0.2s ease, visibility 0.2s; }
.qhse-dialog-overlay.active { opacity: 1; visibility: visible; }
.qhse-dialog-box { background: #ffffff; border-radius: var(--qhse-radius); width: 100%; max-width: 400px; padding: 24px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); transform: scale(0.95); transition: transform 0.2s ease; }
.qhse-dialog-overlay.active .qhse-dialog-box { transform: scale(1); }
.qhse-dialog-title { font-size: 16px; font-weight: 800; color: #0f172a; margin-top: 0; margin-bottom: 8px; }
.qhse-dialog-text { font-size: 13px; color: #475569; margin-bottom: 20px; line-height: 1.5; }
.qhse-dialog-input { width: 100%; padding: 10px; border: 1px solid var(--qhse-border); border-radius: 4px; margin-bottom: 20px; font-size: 13px; box-sizing: border-box; display: none; }
.qhse-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ==========================================================================
   FRONTEND DASHBOARD & PAGINATION
   ========================================================================== */
.qhse-dash-table th { font-weight: 700; color: #475569; border-bottom: 2px solid #cbd5e1; }
.qhse-btn-dash { border: none; background: transparent; cursor: pointer; font-size: 11px; font-weight: bold; padding: 4px 8px; border-radius: 4px; transition: background 0.2s; }
.qhse-btn-dash:hover { background: #f1f5f9; }
.qhse-btn-dash.edit { color: #1d4ed8; }
.qhse-btn-dash.download { color: #16a34a; }
.qhse-btn-dash.delete { color: #dc2626; }
.qhse-btn-pag { background: #ffffff; border: 1px solid #cbd5e1; border-radius: 4px; padding: 6px 12px; font-size: 12px; cursor: pointer; color: #475569; font-weight: bold; transition: all 0.2s ease; }
.qhse-btn-pag.active { background: #1d4ed8; color: #ffffff; border-color: #1e40af; }
.qhse-btn-pag:hover:not(.active) { background: #f1f5f9; }

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */
@media print {
    .qhse-side-column, .qhse-app-header, #qhse-frontend-dashboard, .qhse-btn-action-primary, .qhse-btn-action-secondary, .qhse-btn-action-danger, .btn-remove-hazard, #hira-client-logo, .hz-photo { display: none !important; }
    .qhse-layout-grid { display: block !important; width: 100% !important; }
    #qhse-hira-app, .qhse-card, .qhse-hazard-block { box-shadow: none !important; border: 1px solid #ccc !important; padding: 10px !important; margin-bottom: 10px !important; }
    .qhse-field input, .qhse-field select, .qhse-field textarea { border: none !important; background: transparent !important; border-bottom: 1px solid #ccc !important; padding: 4px 0 !important; }
}