/* =========================================
   1. CSS Variables (Design Token)
   ========================================= */
:root {
    --primary: #1d4ed8;        /* HYSYS Dark Blue */
    --secondary: #0ea5e9;      /* Light Blue for accents */
    --accent: #ef4444;         /* Red for Energy streams / highlights */
    --dark: #0f172a;
    --card-bg: #1e293b;        /* Dark grey canvas */
    --border: #334155;
    --text: #f8fafc; 
    --text-dim: #94a3b8;
    --pipeline-color: #60a5fa; /* Industrial blue for material pipelines */
    --pipeline-width: 3px;     /* Thicker lines like HYSYS */
}

/* =========================================
   2. Base Styles & Reset
   ========================================= */
* { 
    box-sizing: border-box; 
}

body {
    background-color: #0b1120; /* Deep industrial dark background */
    color: var(--text); 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0; 
    min-height: 100vh; 
    overflow-x: hidden; 
    line-height: 1.6;
}

/* =========================================
   3. Navigation Bar
   ========================================= */
.navbar { 
    display: flex; 
    flex-wrap: wrap; 
    justify-content: space-between; 
    align-items: center; 
    padding: 1rem 5%; 
    background: var(--card-bg); 
    border-bottom: 2px solid var(--border); 
    position: sticky; 
    top: 0; 
    z-index: 1000; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.3); 
}

.logo { 
    font-size: 1.3rem; 
    font-weight: 800; 
    color: var(--secondary); 
    letter-spacing: 1px; 
}

.version { 
    font-size: 0.7rem; 
    background: var(--primary); 
    color: white; 
    padding: 3px 6px; 
    border-radius: 4px; 
    margin-left: 5px; 
    vertical-align: top;
}

.nav-link { 
    background: transparent; 
    border: none; 
    color: var(--text-dim); 
    padding: 10px 20px; 
    border-radius: 6px; 
    cursor: pointer; 
    font-weight: 600; 
    transition: 0.3s; 
}

.nav-link.active { 
    background: var(--primary); 
    color: white; 
}

/* =========================================
   4. Layout & Cards
   ========================================= */
.container { 
    max-width: 1200px; 
    margin: 1.5rem auto; 
    padding: 0 15px; 
}

.card { 
    background: var(--card-bg); 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    padding: 1.5rem; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.4); 
    margin-bottom: 25px; 
}

.hero-card { 
    border-top: 4px solid var(--primary); 
}

/* =========================================
   5. Forms & Inputs & Tag Instrumentation
   ========================================= */
.input-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); 
    gap: 15px; 
    margin: 20px 0; 
}

.tag-input-box {
    position: relative;
    background: #0f172a;
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    transition: border-color 0.2s ease;
}

.tag-input-box:focus-within {
    border-color: var(--secondary);
}

.tag-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.tag-id {
    font-size: 0.7rem;
    font-family: monospace;
    color: var(--secondary);
    background: rgba(14, 165, 233, 0.1);
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid rgba(14, 165, 233, 0.3);
    font-weight: bold;
}

.tag-live-dot {
    font-size: 0.65rem;
    color: #64748b;
    transition: color 0.3s ease;
}

.streaming .tag-live-dot {
    color: #10b981;
    animation: blinkDot 1s infinite alternate;
}

@keyframes blinkDot {
    from { opacity: 0.3; }
    to { opacity: 1; text-shadow: 0 0 6px #10b981; }
}

.tag-input-box label { 
    font-size: 0.8rem; 
    color: var(--text-dim); 
    margin-bottom: 4px; 
    display: block; 
    font-weight: 600;
}

input { 
    width: 100%; 
    padding: 8px 10px; 
    border-radius: 4px; 
    border: 1px solid var(--border); 
    background: #0b1120; 
    color: white; 
    outline: none; 
    transition: 0.3s; 
    font-family: monospace; 
    font-size: 0.95rem;
}

input:focus { 
    border-color: var(--secondary); 
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2); 
}

/* =========================================
   6. Real-Time Alarm & Advisory Banner
   ========================================= */
.alarm-banner {
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    transition: all 0.3s ease;
}

.alarm-banner.normal {
    border-left-color: #10b981 !important;
    color: #10b981 !important;
}

.alarm-banner.warning {
    border-left-color: #f59e0b !important;
    color: #f59e0b !important;
    background: #1c1917 !important;
}

.alarm-banner.critical {
    border-left-color: #ef4444 !important;
    color: #ef4444 !important;
    background: #200d0d !important;
    animation: pulseBorder 1.5s infinite;
}

@keyframes pulseBorder {
    0% { box-shadow: 0 0 5px rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.8); }
    100% { box-shadow: 0 0 5px rgba(239, 68, 68, 0.4); }
}

/* =========================================
   7. Dashboard Styling
   ========================================= */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.kpi-card {
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-left: 4px solid var(--secondary);
    background: linear-gradient(145deg, #1e293b, #0f172a);
}

.kpi-title {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: bold;
    color: #10b981;
    font-family: monospace;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 25px;
}

.chart-card {
    min-height: 320px;
    padding: 20px;
}

/* =========================================
   8. Buttons & Presets Toolbar
   ========================================= */
.btn-run { 
    width: 100%; 
    padding: 12px; 
    border-radius: 6px; 
    border: none; 
    background: var(--primary); 
    color: white; 
    font-weight: bold; 
    font-size: 1.1rem; 
    cursor: pointer; 
    transition: 0.2s; 
    text-transform: uppercase; 
    letter-spacing: 1px;
}

.btn-run:hover { 
    background: #2563eb; 
    transform: translateY(-1px); 
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.4); 
}

.btn-preset {
    background: #0f172a;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-preset:hover {
    color: var(--text);
    border-color: var(--secondary);
    background: rgba(14, 165, 233, 0.1);
}

.btn-preset.active {
    background: rgba(14, 165, 233, 0.2);
    color: var(--secondary);
    border-color: var(--secondary);
    box-shadow: 0 0 10px rgba(14, 165, 233, 0.3);
}

/* =========================================
   9. PFD Canvas (SCADA / HYSYS Mode)
   ========================================= */
.pfd-container { 
    position: relative; 
    width: 100%; 
    overflow-x: auto; 
    padding: 20px; 
    background: #0f172a; 
    border-radius: 8px;
}

.pfd-canvas { 
    position: relative; 
    width: 1050px; 
    height: 580px; 
    background-color: #1e293b;
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: center center;
    border-radius: 8px; 
    border: 1px solid var(--border); 
    margin: 0 auto; 
    box-shadow: inset 0 0 50px rgba(0,0,0,0.6); 
}

#pfd-svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.svg-pipe {
    fill: none;
    stroke: #3b82f6;
    stroke-width: 3.5;
    stroke-linejoin: round;
    stroke-linecap: round;
    filter: drop-shadow(0 0 3px rgba(59, 130, 246, 0.5));
}

.svg-pipe.glycol {
    stroke: #10b981;
    filter: drop-shadow(0 0 3px rgba(16, 185, 129, 0.5));
}

.flow-anim {
    stroke-dasharray: 12, 8;
    animation: pipeFlow 1s linear infinite;
}

@keyframes pipeFlow {
    from { stroke-dashoffset: 20; }
    to { stroke-dashoffset: 0; }
}

.eq-node { 
    position: absolute; 
    transform: translate(-50%, -50%); 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    z-index: 2; 
    transition: all 0.2s ease; 
    cursor: pointer;
}

.eq-node:hover { 
    transform: translate(-50%, -55%); 
    filter: drop-shadow(0 0 12px rgba(16, 185, 129, 0.6)); 
}

.eq-svg { 
    display: block; 
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.5)); 
}

.eq-name { 
    font-size: 0.75rem; 
    font-weight: bold; 
    margin-top: 6px; 
    color: #10b981; 
    font-family: monospace; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.hysys-tag { 
    position: absolute; 
    font-size: 0.75rem; 
    font-family: Arial, sans-serif;
    background: #1e3a8a; 
    color: white; 
    padding: 6px 12px; 
    border-radius: 8px; 
    font-weight: normal; 
    z-index: 3; 
    border: 1px solid #60a5fa; 
    box-shadow: 2px 2px 5px rgba(0,0,0,0.6); 
    white-space: pre-line; 
    text-align: center; 
    line-height: 1.3;
}

.hysys-tag strong { 
    display: block; 
    font-size: 0.85rem; 
    border-bottom: 1px solid rgba(255,255,255,0.3); 
    margin-bottom: 3px; 
    padding-bottom: 2px;
}

/* =========================================
   10. Tables & Reports
   ========================================= */
.report-card { 
    background: #0f172a; 
    border: 1px solid var(--border); 
    margin-bottom: 2rem; 
    padding: 1.5rem; 
    border-radius: 8px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.3); 
}

.report-card h3 { 
    color: var(--secondary); 
    border-bottom: 1px solid var(--border); 
    padding-bottom: 10px; 
    margin-top: 0; 
}

.table-responsive { 
    width: 100%; 
    overflow-x: auto; 
}

.eq-table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 15px; 
    font-size: 0.85rem; 
    font-family: monospace; 
}

.eq-table th, 
.eq-table td { 
    border: 1px solid var(--border); 
    padding: 8px 12px; 
    text-align: center; 
}

.eq-table th { 
    background: #1e293b; 
    color: var(--secondary); 
    font-size: 0.8rem; 
    text-transform: uppercase;
}

.eq-table .total-row td { 
    background: rgba(16, 185, 129, 0.1); 
    color: #10b981; 
    font-weight: bold; 
    border-top: 2px solid #10b981; 
}

.energy-table th { 
    color: #f59e0b; 
}

.energy-table .duty-row td { 
    background: rgba(245, 158, 11, 0.1); 
    border-top: 2px solid #f59e0b; 
    font-size: 1rem; 
    color: #fcd34d;
}

/* =========================================
   11. Equipment Details Modal
   ========================================= */
.eq-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(5px);
    z-index: 99999; display: none; justify-content: center; align-items: center;
    opacity: 0; transition: opacity 0.3s ease; 
    font-family: 'Tajawal', sans-serif;
}
.eq-modal.show { display: flex; opacity: 1; }
.eq-modal-content {
    background: var(--card-bg); border: 1px solid var(--primary);
    border-radius: 12px; width: 90%; max-width: 450px;
    padding: 25px; box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    transform: translateY(-20px); transition: transform 0.3s ease;
    color: var(--text);
}
.eq-modal.show .eq-modal-content { transform: translateY(0); }
.eq-modal-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 15px;}
.eq-modal-title { font-size: 1.3rem; font-weight: bold; color: var(--secondary); }
.eq-modal-close { background: none; border: none; color: var(--accent); font-size: 1.8rem; cursor: pointer; line-height: 1;}
.eq-modal-close:hover { color: #f87171; }
.eq-stat-box { background: #0b1120; padding: 15px; border-radius: 8px; margin-top: 15px; border-right: 4px solid var(--primary); }

/* =========================================
   12. Pages & Animations
   ========================================= */
.page { 
    display: none; 
    animation: fadeIn 0.3s ease; 
}

.page.active { 
    display: block; 
}

@keyframes fadeIn { 
    from { opacity: 0; } 
    to { opacity: 1; } 
}

/* =========================================
   13. Chatbot Styles
   ========================================= */
#chatbot-wrapper { 
    position: fixed; 
    bottom: 20px; 
    right: 20px; 
    z-index: 9999; 
    font-family: 'Tajawal', sans-serif;
}

#chatbot-toggle { 
    background: var(--primary); 
    color: white; 
    border: none; 
    padding: 12px 20px; 
    border-radius: 30px; 
    font-size: 1.1rem; 
    cursor: pointer; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); 
    font-weight: bold;
}

#chatbot-window { 
    width: 350px; 
    height: 450px; 
    background: var(--card-bg); 
    border: 1px solid var(--border); 
    border-radius: 12px; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); 
    transition: 0.3s; 
    position: absolute; 
    bottom: 60px; 
    right: 0;
}

#chatbot-window.hidden { 
    display: none; 
}

.chat-header { 
    background: var(--primary); 
    color: white; 
    padding: 15px; 
    font-weight: bold; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

#chat-messages { 
    flex: 1; 
    padding: 15px; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
    background: #0b1120; 
}

.bot-msg { 
    background: #1e293b; 
    color: #10b981; 
    padding: 10px 15px; 
    border-radius: 10px 10px 10px 0; 
    align-self: flex-start; 
    max-width: 85%; 
    font-size: 0.9rem; 
    border: 1px solid #334155;
}

.user-msg { 
    background: var(--primary); 
    color: white; 
    padding: 10px 15px; 
    border-radius: 10px 10px 0 10px; 
    align-self: flex-end; 
    max-width: 85%; 
    font-size: 0.9rem;
}

.chat-input-area { 
    display: flex; 
    border-top: 1px solid var(--border); 
    background: var(--card-bg); 
    padding: 10px;
}

.chat-input-area input { 
    flex: 1; 
    padding: 10px; 
    border: none; 
    background: #0f172a; 
    color: white; 
    border-radius: 5px; 
    outline: none; 
}

.chat-input-area button { 
    background: var(--secondary); 
    border: none; 
    padding: 10px 15px; 
    margin-left: 5px; 
    border-radius: 5px; 
    color: white; 
    cursor: pointer; 
    font-weight: bold;
}

/* Compact Executive Dashboard Layout */
#dashboard-page .kpi-card {
    min-height: unset;
    border-radius: 6px;
}

#dashboard-page .chart-card {
    border-radius: 6px;
    background: #111a2e;
}

@media (max-width: 1024px) {
    .dashboard-charts-layout {
        grid-template-columns: 1fr !important;
    }
}

#dashboard-page.active {
    display: flex;
}
