:root {
    /* --- LIGHT MODE VARIABLES --- */
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --card-bg: rgba(255, 255, 255, 0.9);
    --text-main: #2d3436;
    --text-light: #636e72;
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    --border-color: #ffffff;
    
    /* Brand Colors */
    --clr-solar: #00b894;
    --clr-grid: #ff7675;
    --clr-inv: #fdcb6e;
    --clr-batt: #0984e3;
    
    /* Nav */
    --nav-bg: #2d3436;
    --nav-text: #ffffff;
}

[data-theme="dark"] {
    /* --- DARK MODE VARIABLES --- */
    --bg-gradient: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    --card-bg: rgba(30, 30, 30, 0.85);
    --text-main: #dfe6e9;
    --text-light: #b2bec3;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    --border-color: #444;
    
    /* Nav */
    --nav-bg: rgba(0, 0, 0, 0.8);
    --nav-text: #ffffff;
}

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-main);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* --- Navigation --- */
.dashboard-nav {
    background: var(--nav-bg);
    color: var(--nav-text);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.theme-toggle {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--nav-text);
    padding: 6px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}
.theme-toggle:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.05);
}

/* --- Layout --- */
.main-container {
    max-width: 1300px;
    margin: 30px auto;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* Top Row Grid */
.top-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
}
@media (min-width: 1000px) {
    .top-row {
        grid-template-columns: 450px 1fr; /* Diagram Fixed Width */
    }
}

/* --- SOLAR DIAGRAM CONTAINER --- */
#solar_data {
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--shadow);
    position: relative;
    height: 480px; 
    width: 100%;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Background Lines SVG */
#solar_data svg.lines-svg {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1;
}

/* --- Circles (Nodes) --- */
.circle {
    position: absolute;
    width: 110px; height: 110px;
    background: var(--card-bg);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    /* border: removed to let rings show */
}

/* Positions */
.pos-solar { top: 30px; left: 30px; }
.pos-grid { bottom: 30px; left: 30px; }
.pos-home { top: 30px; right: 30px; }
.pos-batt { bottom: 30px; right: 30px; }
.pos-inv { 
    top: 50%; left: 50%; 
    transform: translate(-50%, -50%); 
    width: 130px; height: 130px; 
}

/* --- GAUGE RINGS --- */
.circle svg.ring-svg {
    position: absolute;
    width: 100%; height: 100%;
    transform: rotate(-90deg); /* Start from top */
}

.circle svg circle {
    fill: none;
    stroke-width: 6;
    stroke-linecap: round;
}

/* Grey Track */
.circle svg circle.track {
    stroke: rgba(0,0,0,0.1);
}

/* Colored Progress Fill */
.circle svg circle.progress {
    stroke: var(--clr);
    stroke-dasharray: 314; /* 2 * pi * 50 */
    stroke-dashoffset: 314; /* Start empty */
    transition: stroke-dashoffset 1s ease-out;
}

/* --- Content Inside Circle --- */
.info-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 6;
    text-align: center;
    line-height: 1.2;
}
.info-box img { width: 30px; height: 30px; margin-bottom: 2px; }
.info-box span { font-weight: 800; font-size: 0.9rem; color: var(--text-main); }
.info-box small { font-size: 0.7rem; color: var(--text-light); font-weight: 600; }

/* --- Status Icons (Cross/Check) --- */
.status-icon {
    position: absolute;
    top: -5px; right: -5px;
    width: 25px; height: 25px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    z-index: 10;
    border: 2px solid #fff;
}
.status-icon.error { display: flex; color: red; }

/* --- Line Animations --- */
.line-path {
    fill: none;
    stroke-width: 4;
    stroke-dasharray: 12;
    opacity: 0.8;
    transition: stroke 0.3s;
}
.anim-flow { animation: dash 1s linear infinite; }
.anim-stop { animation: none; stroke: #ccc !important; opacity: 0.2; }

/* --- Animation Direction Fix --- */

/* ব্যাটারি থেকে ইনভার্টারের দিকে অ্যানিমেশন (Discharging) */
.anim-flow-reverse { 
    animation: dash-reverse 1s linear infinite; 
}

@keyframes dash-reverse { 
    to { stroke-dashoffset: 24; } /* পজিটিভ ভ্যালু মানে উল্টো দিকে প্রবাহ */
}

@keyframes dash { to { stroke-dashoffset: -24; } }


/* --- Stats Cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    align-content: start;
}

.stat-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-bottom: 5px solid #ccc; 
    transition: transform 0.3s ease;
}
.stat-card:hover { transform: translateY(-5px); }

.stat-card.solar { border-bottom-color: var(--clr-solar); }
.stat-card.grid  { border-bottom-color: var(--clr-grid); }
.stat-card.inv   { border-bottom-color: var(--clr-inv); }
.stat-card.batt  { border-bottom-color: var(--clr-batt); }

.stat-card h4 { margin: 0; font-size: 0.85rem; text-transform: uppercase; color: var(--text-light); letter-spacing: 1px; }
.stat-card .value { font-size: 1.8rem; font-weight: 800; margin: 10px 0; color: var(--text-main); }
.stat-card .sub-text { font-size: 0.8rem; opacity: 0.7; }

/* --- Charts & Table --- */
.chart-box, .table-row {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(5px);
}
.charts-row { display: grid; grid-template-columns: 1fr; gap: 30px; }
@media (min-width: 992px) { .charts-row { grid-template-columns: 2fr 1fr; } }

input[type="text"] {
    background: rgba(0,0,0,0.05); border: 1px solid rgba(0,0,0,0.1);
    padding: 10px; border-radius: 8px; color: var(--text-main);
}
table { width: 100%; border-collapse: collapse; }
table th, table td { padding: 12px; border-bottom: 1px solid rgba(0,0,0,0.05); text-align: center;}

/* --- Smart Alert Styles --- */
#system-alert {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #ff4757; /* লাল রং */
    color: white;
    padding: 12px 25px;
    border-radius: 50px;
    box-shadow: 0 10px 20px rgba(255, 71, 87, 0.3);
    font-weight: bold;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.4s ease;
    font-family: 'DM Sans', sans-serif;
}

/* যখন কোনো সমস্যা নেই, তখন লুকিয়ে থাকবে */
.alert-hide {
    top: -100px !important; /* স্ক্রিনের বাইরে */
    opacity: 0;
}

/* যখন সমস্যা হবে, তখন দেখাবে */
.alert-show {
    top: 20px !important;
    opacity: 1;
    animation: bounceIn 0.5s;
}

@keyframes bounceIn {
    0% { transform: translateX(-50%) scale(0.8); }
    50% { transform: translateX(-50%) scale(1.1); }
    100% { transform: translateX(-50%) scale(1); }
}

/* Savings Card Style */
.stat-card.savings {
    border-bottom-color: #27ae60; /* Green Color */
}

/* --- Mobile Alert Fix --- */
@media screen and (max-width: 1024px) {
    #system-alert {
        top: 60px !important; /* নিচে নামানো হলো যাতে ডেট টাইম দেখা যায় */
        width: 80%; /* চওড়া কমানো হলো */
        padding: 8px 15px; /* প্যাডিং কমানো হলো */
        font-size: 0.8rem; /* ফন্ট ছোট করা হলো */
        justify-content: center;
        white-space: nowrap; /* এক লাইনে রাখার জন্য */
    }
    
    .alert-show {
        top: 60px !important; /* মোবাইলে দেখানোর পজিশন */
    }
    
    /* ১. চার্টকে টাচ স্ক্রল ইগনোর করতে বলা হচ্ছে (Vertical Scroll Allow) */
    canvas {
        touch-action: pan-y !important; 
    }

    /* ২. মোবাইলে চার্টের উচ্চতা কমিয়ে ২৫০px করা হলো যাতে স্ক্রিন ব্লক না হয় */
    .chart-box div[style*="height:350px"] {
        height: 250px !important; 
    }
    
    /* ৩. চার্টের বক্সের নিচে গ্যাপ বাড়ানো হলো */
    .chart-box {
        margin-bottom: 20px;
    }
}

/* --- UNIVERSAL MOBILE & DESKTOP VIEW FIX --- */

/* ১. মেইন কন্টেইনার ফিক্স (যাতে স্ক্রিনের বাইরে না যায়) */
.main-container {
    width: 100%;
    max-width: 1300px;
    margin: 20px auto;
    padding: 0 10px; /* প্যাডিং কমানো হলো মোবাইলের জন্য */
    box-sizing: border-box;
    overflow-x: hidden; /* হরাইজন্টাল স্ক্রল বন্ধ */
}

/* ২. নেভিগেশন বার ফিক্স (OnePlus এবং অন্যান্য মোবাইলের জন্য) */
.dashboard-nav {
    display: flex;
    flex-wrap: wrap; /* কন্টেন্ট বেশি হলে নিচে নামবে, ভাঙবে না */
    justify-content: space-between;
    padding: 10px 15px;
    gap: 10px;
}

.dashboard-nav > div {
    flex-shrink: 0;
}

/* ৩. সোলার ডায়াগ্রাম (Diagram) রেসপন্সিভ ফিক্স */
#solar_data {
    width: 100%;
    max-width: 450px;
    margin: 0 auto; /* মাঝখানে রাখার জন্য */
    height: auto;
    aspect-ratio: 1 / 1.1; /* হাইট অটোমেটিক অ্যাডজাস্ট হবে */
}

/* ৪. চার্ট বক্স ফিক্স */
.chart-box {
    width: 100%;
    box-sizing: border-box;
}

/* ৫. মোবাইল ভিউতে ডিজাইন ভাঙা রোধ করতে */
@media screen and (max-width: 480px) {
    h2 { font-size: 1.1rem !important; }
    #live_date, #live_time { font-size: 0.75rem !important; }
    .theme-toggle { padding: 5px; width: 30px; height: 30px; }
}

/* ৬. ক্যানভাস বা চার্ট স্ক্রল প্রোবলেম ফিক্স */
canvas {
    max-width: 100% !important;
    touch-action: pan-y !important;
}