/* =========================================
   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
   ========================================= */
.input-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); 
    gap: 15px; 
    margin: 20px 0; 
}

.input-grid label { 
    font-size: 0.85rem; 
    color: var(--text-dim); 
    margin-bottom: 5px; 
    display: block; 
    font-weight: 600;
}

input { 
    width: 100%; 
    padding: 10px; 
    border-radius: 4px; 
    border: 1px solid var(--border); 
    background: #0f172a; 
    color: white; 
    outline: none; 
    transition: 0.3s; 
    font-family: monospace; 
    font-size: 1rem;
}

input:focus { 
    border-color: var(--secondary); 
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2); 
}

/* =========================================
   6. Buttons
   ========================================= */
.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); 
}

/* =========================================
   7. PFD Canvas (HYSYS Mode)
   ========================================= */
.pfd-container { 
    position: relative; 
    width: 100%; 
    overflow-x: auto; /* يسمح بالتمرير فقط في الشاشات الصغيرة جداً */
    padding: 20px; 
    background: #0f172a; 
    border-radius: 8px;
}

/* 1. خلفية هندسية احترافية للوحة الرسم */
.pfd-canvas { 
    position: relative; 
    width: 1050px; 
    height: 580px; 
    background-color: #1e293b;
    /* إضافة شبكة (Grid) شفافة تشبه البرامج الهندسية */
    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); 
}

/* 2. تنسيق خطوط SVG الجديدة وحركة التدفق */
#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; }
}

/* Equipment Interactive Hover */
.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)); /* توهج أخضر عند التأشير */
}

/* -----------------------------------------
   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;
    /* تمت إزالة direction: rtl; لكي يتغير الاتجاه أوتوماتيكياً مع زر اللغة */
}
.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); }

.pfd-pipelines { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    z-index: 1; 
    pointer-events: none; 
}

.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: crosshair;
}

.eq-node:hover { 
    transform: translate(-50%, -52%); 
    filter: drop-shadow(0 0 8px rgba(255,255,255,0.2)); 
}

.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);
}

/* Stream Tags */
.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;
}

/* =========================================
   8. 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;
}

/* =========================================
   9. Pages & Animations
   ========================================= */
.page { 
    display: none; 
    animation: fadeIn 0.3s ease; 
}

.page.active { 
    display: block; 
}

@keyframes fadeIn { 
    from { opacity: 0; } 
    to { opacity: 1; } 
}

/* =========================================
   10. 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; 
    direction: rtl; /* Note: RTL handled dynamically via JS now, but kept for fallback */
}

.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;
}

