/* =========================================================
   CureGuard CLOUD HMI V1.2 - Unified Industrial UI
   ========================================================= */

:root {
    --cg-purple: #6f42c1;
    --cg-dark: #212529;
    --cg-light: #f4f6f9;
    
    --status-ok: #28a745;
    --status-alert: #dc3545;
    --status-warning: #ffc107; 
    --status-stale: #868e96;

    --bg-ok-soft: #d4edda;
    --bg-alert-soft: #f8d7da;
    --bg-warning-soft: #fff3cd;
    
    --radius-sm: 4px;   
    --radius-md: 6px;   
    --radius-lg: 10px;  
    
    --sidebar-width: 22%; 
}

/* --- 1. RESET & BASE --- */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; display: flex; height: 100vh; background: var(--cg-light); overflow: hidden; color: #333; }
.hidden-section { display: none !important; }

/* Text Color Helpers */
.text-status-ok { color: var(--status-ok) !important; }
.text-status-warning { color: var(--status-warning) !important; }
.text-status-alert { color: var(--status-alert) !important; }

/* --- 2. LAYOUT: SIDEBAR --- */
#left-panel { width: var(--sidebar-width); background: var(--cg-dark); color: white; padding: 20px; border-right: 1px solid #1a1d20; display: flex; flex-direction: column; z-index: 10; box-shadow: 2px 0 10px rgba(0,0,0,0.1); }
#cg-logo { width: 100%; height: auto; margin-bottom: 25px; display: block; background-color: #ffffff; padding: 8px 12px; border-radius: var(--radius-md); box-shadow: 0 2px 4px rgba(0,0,0,0.15); }
.unit-info { font-size: 0.85rem; color: #adb5bd; margin-bottom: 20px; border-bottom: 1px solid #343a40; padding-bottom: 15px; }

/* --- 3. LAYOUT: MAIN WINDOW & HEADERS --- */
#main-window { width: 100%; display: flex; flex-direction: column; overflow-y: auto; background: var(--cg-light); }
.view-container { display: none; padding: 30px; flex: 1; }
.view-container.active { display: block; }
#global-header { position: sticky; top: 0; z-index: 100; background: white; padding: 15px 30px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border-bottom: 1px solid #e9ecef; }
.section-label { font-size: 0.8rem; font-weight: 800; color: #6c757d; margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.5px; }

/* --- 4. BUTTONS & UI COMPONENTS --- */
.primary-action-btn { padding: 12px 30px; font-size: 1rem; font-weight: 800; text-transform: uppercase; border-radius: var(--radius-md); cursor: pointer; transition: all 0.2s ease; letter-spacing: 0.5px; }
.primary-action-btn:hover:not(:disabled) { box-shadow: 0 4px 8px rgba(0,0,0,0.15); transform: translateY(-1px); }
.action-btn { padding: 10px 20px; font-weight: bold; border-radius: var(--radius-sm); border: none; font-size: 0.85rem; cursor: pointer; transition: background-color 0.2s, transform 0.1s; text-transform: uppercase; }
.action-btn:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }

.sidebar-alerts-btn { width: 100%; padding: 15px; margin-bottom: 20px; background: #343a40; color: white; font-weight: 800; cursor: pointer; transition: 0.3s; border: none; border-radius: var(--radius-sm); text-align: left; font-size: 1rem; letter-spacing: 0.5px; }
.sidebar-alerts-btn.active-nav { background-color: var(--cg-purple) !important; border-left: 4px solid #fff; }

.logout-btn { margin-top: auto; margin-bottom: 20px; background: transparent; color: #6c757d; border: 2px solid #6c757d; padding: 15px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 800; font-size: 0.9rem; letter-spacing: 1px; transition: all 0.2s; text-transform: uppercase; text-align: center; }
.logout-btn:hover { background: var(--cg-dark); color: white; border-color: var(--cg-purple); box-shadow: 0 4px 12px rgba(111, 66, 193, 0.3); }

/* --- 5. FORMS & INPUTS --- */
.form-section { margin-bottom: 25px; padding-bottom: 20px; border-bottom: 1px solid #e9ecef; }
.sub-label { display: block; font-size: 0.75rem; color: #6c757d; margin-bottom: 6px; font-weight: 800; letter-spacing: 0.5px; }
.industrial-input, input[type="datetime-local"], select { width: 100%; padding: 12px; border: 1px solid #ced4da; border-radius: var(--radius-sm); font-family: monospace; font-size: 0.95rem; color: #495057; background-color: #fff; transition: border-color 0.15s, box-shadow 0.15s; }
.industrial-input:focus { border-color: var(--cg-purple); outline: 0; box-shadow: 0 0 0 3px rgba(111, 66, 193, 0.15); }
.mode-control-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 25px; padding: 20px; background: white; border-radius: var(--radius-lg); border: 1px solid #dee2e6; box-shadow: 0 2px 6px rgba(0,0,0,0.03); }

/* --- 6. GRID & STATUS VISUALS (10-Foot Walk-By Rules) --- */
.hmi-grid-container { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.sensor-block { background-color: #f8f9fa; border: 4px solid #ced4da; border-radius: var(--radius-lg); padding: 15px 20px; text-align: center; cursor: pointer; transition: all 0.2s ease-in-out; color: #495057; box-shadow: 0 4px 8px rgba(0,0,0,0.03); display: flex; flex-direction: column; justify-content: center; min-height: 180px; }
.sensor-block:hover { transform: translateY(-2px); box-shadow: 0 8px 16px rgba(0,0,0,0.1); border-color: #adb5bd; }
.sensor-block .node-label { font-size: 0.8rem; color: #adb5bd; font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: auto; }
.sensor-block h3 { font-size: 1.5rem; text-transform: uppercase; margin-bottom: 0; font-weight: 900; letter-spacing: 0.5px; color: #212529; }
.deviation-value { font-size: 4.5rem; font-weight: 900; color: inherit; line-height: 1; letter-spacing: -2px; margin-top: 15px; margin-bottom: auto; }

.sensor-block.status-ok { border: 4px solid var(--status-ok) !important; color: var(--status-ok); background-color: white !important; }
.sensor-block.status-warning { border: 4px solid #d39e00 !important; background-color: var(--status-warning) !important; color: #212529 !important; }
.sensor-block.status-warning h3, .sensor-block.status-warning .node-label { color: #212529 !important; border-bottom-color: rgba(0,0,0,0.1); }
.sensor-block.status-alert { border: 4px solid #bd2130 !important; background-color: var(--status-alert) !important; color: white !important; }
.sensor-block.status-alert h3, .sensor-block.status-alert .node-label { color: white !important; border-bottom-color: rgba(255,255,255,0.2); }
.sensor-block.status-stale { background: repeating-linear-gradient( 45deg, #e9ecef, #e9ecef 20px, #dee2e6 20px, #dee2e6 40px ) !important; border: 4px solid #ced4da !important; color: #6c757d; }
.sensor-block.status-stale h3, .sensor-block.status-stale .node-label { color: #6c757d !important; border-bottom-color: #dee2e6; }

/* --- 7. DATA TABLES, WELLS & GRAPHS --- */
.diagnostic-split { display: flex; flex-direction: row; gap: 25px; margin: 25px 0; align-items: flex-start; width: 100%; }
.split-col { flex: 1 1 50%; min-width: 0; background: white; padding: 25px; border-radius: var(--radius-lg); border: 1px solid #dee2e6; box-shadow: 0 2px 8px rgba(0,0,0,0.02); min-height: 250px; }
.status-checklist { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.status-checklist td, .status-checklist th { padding: 10px 8px; border-bottom: 1px solid #e9ecef; text-align: left; }
.status-checklist tbody tr:nth-child(even) { background-color: rgba(0,0,0,0.015); }
.status-checklist tbody tr:hover { background-color: rgba(0,0,0,0.03); }
.readout-cell { font-family: monospace; font-weight: bold; color: var(--cg-purple); font-size: 0.9rem; }

.dygraph-chart-host { width: 100%; height: 320px; margin-bottom: 25px; border: 1px solid #ced4da; background: #fff; border-radius: var(--radius-md); padding: 10px 10px 25px 10px; box-shadow: inset 0 1px 4px rgba(0,0,0,0.02); }

.compact-readouts { display: flex; gap: 15px; margin-top: 20px; }
.readout-box { flex: 1; padding: 15px; background: #f8f9fa; border-radius: var(--radius-md); text-align: center; border: 1px solid #e9ecef; box-shadow: inset 0 2px 4px rgba(0,0,0,0.03); }
.readout-box label { display: block; font-size: 0.75rem; color: #6c757d; text-transform: uppercase; margin-bottom: 5px; font-weight: 800; }
.readout-box span { font-family: monospace; font-weight: 900; font-size: 1.4rem; color: #212529; }

/* --- 8. DAILY DIGEST & REPORTING --- */
.digest-date-item { padding: 15px 20px; border-bottom: 1px solid #eee; cursor: pointer; transition: all 0.2s ease-in-out; font-weight: bold; color: #555; display: flex; justify-content: space-between; align-items: center; }
.digest-date-item:hover { background-color: #f8f9fa; color: var(--cg-purple); }
.digest-date-item.active { background-color: var(--cg-purple); color: white; }
.digest-sidebar { width: 280px; background: #fff; border-radius: var(--radius-lg); border: 1px solid #dee2e6; box-shadow: 0 4px 12px rgba(0,0,0,0.05); overflow: hidden; flex-shrink: 0; }
.digest-sidebar-header { background: var(--cg-dark); color: white; padding: 15px 20px; font-weight: 900; letter-spacing: 1px; }
.digest-main-panel { flex: 1; background: #fff; padding: 30px; border-radius: var(--radius-lg); border: 1px solid #dee2e6; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.digest-big-number { font-size: 48px; display: block; margin-top: 10px; font-weight: 900; line-height: 1; }

/* --- 9. LINE UV1 & MINIMAP --- */
.nav-line-separator { border-top: 2px solid #343a40 !important; margin-top: 10px; }
.uv-zone-header { padding: 15px 20px; font-weight: 900; font-size: 16px; border-radius: var(--radius-md) var(--radius-md) 0 0; border: 1px solid #ced4da; border-bottom: none; }
.uv-zone-mc8 { background: #e3f2fd; color: #0d47a1; } 
.uv-zone-mc6 { background: #f3e5f5; color: #4a148c; } 
.uv-zone-body { border: 1px solid #ced4da; border-top: none; padding: 25px; border-radius: 0 0 var(--radius-md) var(--radius-md); background: #fff; margin-bottom: 25px; box-shadow: 0 4px 8px rgba(0,0,0,0.02); }
.uv-flow-arrow { text-align: center; font-size: 20px; font-weight: 900; color: #adb5bd; margin: 30px 0; letter-spacing: 3px; display: flex; align-items: center; justify-content: center; gap: 15px; }
.uv-flow-arrow::before, .uv-flow-arrow::after { content: ""; flex: 1; height: 2px; background: #dee2e6; }
.uv-minimap { position: sticky; top: 20px; background: #fff; border: 1px solid #dee2e6; padding: 20px; border-radius: var(--radius-md); box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.uv-minimap-link { display: block; padding: 8px 10px; color: #495057; text-decoration: none; font-size: 13px; border-left: 3px solid transparent; margin-bottom: 4px; transition: all 0.2s; font-weight: bold; }
.uv-minimap-link:hover { background: #f8f9fa; color: var(--cg-purple); border-left-color: var(--cg-purple); }
.uv-minimap-section { font-size: 11px; font-weight: 900; color: #adb5bd; margin: 15px 0 5px 0; text-transform: uppercase; letter-spacing: 1px; }

/* Conformance Scorecard */
.report-scorecard { display: flex; gap: 20px; margin-bottom: 30px; }
.report-card { flex: 1; padding: 25px; background: #f8f9fa; border: 1px solid #e9ecef; border-radius: var(--radius-md); text-align: center; box-shadow: inset 0 2px 4px rgba(0,0,0,0.03); }
.report-card-title { font-size: 12px; color: #6c757d; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; }
.report-card-value { font-size: 42px; font-weight: 900; margin-top: 10px; color: var(--cg-purple); line-height: 1; }
.badge-pass { background: var(--status-ok); color: white; padding: 4px 8px; border-radius: var(--radius-sm); font-weight: bold; font-size: 12px; }
.badge-fail { background: var(--status-alert); color: white; padding: 4px 8px; border-radius: var(--radius-sm); font-weight: bold; font-size: 12px; }

/* --- 10. LOGIN SCREEN --- */
.login-body { background-color: var(--cg-dark); justify-content: center; align-items: center; }
.login-card { background: #fff; padding: 40px; border-radius: var(--radius-lg); box-shadow: 0 10px 30px rgba(0,0,0,0.5); width: 350px; display: flex; flex-direction: column; }
.login-card img { width: 200px; align-self: center; margin-bottom: 30px; }
.login-error { color: var(--status-alert); font-size: 0.85rem; font-weight: bold; margin-top: 15px; text-align: center; display: none; }

/* --- 11. PRINT STYLES --- */
@media print {
    @page { margin: 1cm; size: auto; }
    html, body, #main-window { height: auto !important; overflow: visible !important; background: white; -webkit-print-color-adjust: exact; padding: 0 !important; margin: 0 !important; display: block !important; }
    .view-container { display: none !important; }
    .view-container.active { display: block !important; height: auto !important; overflow: visible !important; padding: 0 !important; }
    #left-panel, #global-header, .mode-control-bar, .no-print, .uv-minimap { display: none !important; }
    .report-card { border: 2px solid #000; background: white; -webkit-print-color-adjust: exact; }
    .badge-pass, .badge-fail { -webkit-print-color-adjust: exact; border: 1px solid #000; }
    #uv1-workspace { display: block !important; width: 100%; margin-top: 0; }
    #uv1-conveyor-main { display: flex !important; flex-direction: column !important; }
    #uv1-conformance-section { order: -1 !important; display: block !important; page-break-after: always; break-after: page; margin-top: 0 !important; position: relative; }
    .status-checklist { page-break-after: always; break-after: page; }
    .dygraph-chart-host, .uv-zone-body > div { page-break-inside: avoid !important; break-inside: avoid !important; }
    .print-only-logo { display: block; position: absolute; top: 0; right: 0; height: 40px; }
}