/* =========================================
   1. GLOBAL VARIABLES & RESETS
   ========================================= */
:root {
    --bg-color: #0f172a;      /* Deep teal background */
    --border-color: #0f4c61;  /* Lighter teal border/hover */
    --text-color: #ffffff;    /* White text */
    --accent-color: #d2ba63;  /* Gold accent */
    --blue-800: #2b4053;
    --blue-900: #1e3a8a;
    --white: #ffffff;
    
    /* Accordion / Table Colors */
    --blue-50: #eff6ff; 
    --gray-700: #374151;
    --emerald-100: #d1fae5;
    --green-800: #065f46;
}

body {
    font-family: 'Inter', 'Ubuntu', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    width: 100vw;
    min-height: 100vh;
    overflow-x: hidden;
    /* Prevent "pull-to-refresh" rubber banding */
    overscroll-behavior-y: none;
    /* Handle iPhone Notch / Safe Areas */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right); 
}
.auto-light-mode {
    /* Lower inversion + brightness shift creates a softer light-blue look */
    filter: invert(0.9) hue-rotate(185deg) brightness(1.1) contrast(0.9);
    background-color: #f0f7ff !important; /* Forces a very light sky-blue base */
}

/* Ensure data elements remain sharp and legible */
.auto-light-mode img, 
.auto-light-mode i, 
.auto-light-mode .pulse-dot,
.auto-light-mode .highcharts-container,
.auto-light-mode iframe {
    /* Double-invert to restore original brand colors (Green/Red/Gold) */
    filter: invert(1) hue-rotate(175deg) brightness(0.9) contrast(1.1);
}


.light-mode {
    --bg-color: #f1f5f9;  /* Light Gray */
    --panel-bg: #ffffff;  /* Pure White Panels */
    --text-color: #1e293b; /* Dark Slate Text */
    --border-color: #cbd5e1;
    --card-bg: #ffffff;
}
.light-mode .ts-control {
    background: #ffffff !important;
    color: #1e293b !important;
    border: 1px solid var(--border-color) !important;
}
.mode-group-container {
    display: flex; 
    gap: 2px; 
    background: #001a24; 
    padding: 2px; 
    border-radius: 4px; 
    border: 1px solid #444; 
    height: 32px; 
    box-sizing: border-box; 
    align-items: center;
}


.mode-group-btn {
    border: none; 
    font-size: 0.9rem; 
    font-weight: bold; 
    padding: 0 5px; 
    height: 26px; 
    cursor: pointer; 
    border-radius: 3px; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    transition: background 0.2s ease;
}

/* --- Panel 1: Entity Context (AppMode) --- */
.app-mode-b .panel-1 { border: 1px solid #818cf8; } /* Business (Blue) */
.app-mode-c .panel-1 { border: 1px solid #10b981; } /* Customer (Green) */
.app-mode-s .panel-1 { border: 1px solid yellow; } /* Site (Amber) */

/* --- Panels 2 & 3: Data Context (SelectMode) --- */

/* P - PV Mode (Amber) */
.select-mode-p .panel-2, .select-mode-p .panel-3 { border: 1px solid #facc15; }
.select-mode-p h2 { color: #fbbf24 !important; }

/* F - Financial Mode (Green) */
.select-mode-f .panel-2, .select-mode-f .panel-3 { border: 1px solid #22c55e; }
.select-mode-f h2 { color: #10b981 !important; }

/* M - Meters Mode (Blue) */
.select-mode-m .panel-2, .select-mode-m .panel-3 { border: 1px solid #38bdf8; }
.select-mode-m h2 { color: #38bdf8 !important; }

/* Common Panel Styling */
.panel-1, .panel-2, .panel-3 {
    transition: all 0.3s ease-in-out;
}
* {
    /* Remove tap highlight on mobile */
    -webkit-tap-highlight-color: transparent;
    /* Disable text selection for app-like feel */
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box;
}

/* Allow text selection ONLY on inputs */
input, textarea, .selectable {
    user-select: text;
    -webkit-user-select: text;
}

/* Scrollbar Hiding */
::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

dash-app { 
    display: block; 
    min-height: 100vh; 
    width: 100vw; 
    overflow-x: hidden; 
    background-color: var(--bg-color); 
    color: white; 
}

/* =========================================
   2. UTILITY CLASSES & COMPONENTS
   ========================================= */
.loading-screen { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    height: 100vh; 
}
.utility-card2 { 
    display: flex; 
    flex-direction: column; 
    padding: 1px; 
    transition: transform 0.1s ease, opacity 0.1s ease;
    cursor: pointer;
}
.utility-card { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    padding: 1px; 
    transition: transform 0.1s ease, opacity 0.1s ease;
    cursor: pointer;
}

.utility-card:active {
    transform: scale(0.97);
    opacity: 0.8;
}

.checkmark-icon { 
    width: 1.5rem; 
    height: 1.5rem; 
    color: #10b981; 
    opacity: 0; 
    transition: opacity 200ms ease-in-out; 
}

.item {
    cursor: pointer;
    transition: background-color 0.2s;
}
.item:hover { background-color: #f3f4f6; color: black; }
.item.selected { background-color: rgba(30, 69, 234, 0.2); border-left: 4px solid #1e45ea; }
.item.selected .checkmark-icon { opacity: 1; }

.vbar { display:block; height:2rem; width:0.4rem; position:absolute; top:0; left:0.5rem; }

/* =========================================
   3. DATE & NAVIGATION CONTROLS
   ========================================= */
.date-control-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: 5px;
    gap: 8px;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    user-select: none;
}

.date-display-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
}

#date-text {
    font-weight: 700;
    font-size: 1rem;
    min-width: 110px;
    text-align: center;
    letter-spacing: 0.5px;
}

.nav-btn {
    background: #333;
    color: white;
    border: none;
    padding: 5px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.1s ease;
    
}

.nav-btn:hover { background-color: #444; }
.nav-btn:active { transform: scale(0.97); opacity: 0.8; }

.toggle-container { 
    display: flex; 
    align-items: center; 
    gap: 0px; 
    cursor: pointer; 
    background: #1a4d5e; 
    padding: 4px 12px; 
    border-radius: 20px; 
    font-size: 0.75rem; 
    border: 1px solid #444; 
}

.picker-wrapper {
    position: relative;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
    min-height: 44px;
    min-width: 44px;
}
.picker-wrapper:hover { background-color: var(--border-color); }

input[type="date"], 
input[type="month"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: transparent;
    border: none;
    outline: none;
    /* CRITICAL: Remove the reserved space */
    padding: 0 !important;
    margin: 0 !important;
    width: auto !important;
    min-width: 0 !important;
}
/* Optional: Ensure the text fills the space and stays centered */
input[type="date"], input[type="month"] {
    text-align: center;
    cursor: pointer;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    cursor: pointer;
    background: transparent;
    color: transparent;
}

input[type="date"], input[type="month"] {
    position: relative; /* Required for the absolute indicator above */
    overflow: hidden;
}
#DATE2 {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0; z-index: 10; cursor: pointer;
    -webkit-appearance: none; appearance: none;
    margin: 0; padding: 0; border: none;
}
.auto-light-mode iframe[src*="flow7.php"] {
    filter: invert(0.9) hue-rotate(180deg) brightness(0.8) contrast(1.2) !important;
    background: #002d3d !important;
    border-radius: 8px;
}

/* 2. LIGHT MODE: Only apply white background if auto-light-mode IS present */
.auto-light-mode iframe[src*="flow7.php"] {
    filter: none !important;
    background: black !important;
}

/* =========================================
   4. LAYOUT & GRID SYSTEMS
   ========================================= */
.main-header {
    display: flex;
    justify-content: space-between;
    padding: 5px 15px;
    background-color: #002d3d;
    color: white;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.main-wrapper {
    display: flex; 
    flex-direction: row;
    background: var(--bg-color); 
    padding: 5px; 
    gap: 5px;     
    width: 100vw;
    min-height: calc(100vh - 65px); /* Full height minus header */
}

/* RIGHT container takes 2 parts (66.6%) */
#RIGHT {
    flex: 2;
    display: flex;
    flex-direction: row; /* Aligns HOME2 and HOME3 side-by-side */
    gap: 1px;
    min-width: 0;
}

/* Ensure Analytics and Monitor are equal width within the RIGHT panel */
#HOME2, #HOME3 {
    flex: 1;
    min-width: 0;
}
#SIDEBAR, #HOME2, #HOME3 {
    flex: 1;
    min-width: 0; /* Allow shrinking if necessary */
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: visible; /* Handle internal scrolling */
}

/* Styles moved from PHP inline */
#HOME2, #HOME3 {
    background: #002d3d; 

}
.content-container { flex: 1 1 auto; display: flex; flex-direction: row; padding: 0px;  overflow-x: auto; }

.grid-table { display: grid; }
.dash-columns { grid-template-columns: 3fr 0rem repeat(4, 1fr); }
.live { grid-template-columns: repeat(4, 1fr); }
.grid-columns { grid-template-columns: repeat(6, 1fr); }
.tou-columns { grid-template-columns: 1.5fr repeat(4, 1fr); }
.history-columns { grid-template-columns:1fr 0.5fr 8px 0.5fr 8px 0.5fr 8px 0.5fr 0.5fr; }
.history-columnsm { grid-template-columns:1fr 5fr; }

.grid-cell, .grid-cell0 { font-size: 1rem; display: flex; }
.grid-cell { padding: 5px 0px 0 0px; }

/* History Section */
.history-row { background: white; color: black; margin-bottom: 0px; }
.history-chart-wrapper { height: 12rem; width: 100%; margin-top: 0px; }

/* =========================================
   5. ACCORDION & DATA DISPLAY
   ========================================= */
/* Shoelace Overrides */

sl-details.custom-accordion::part(header) { padding: 0; background-color: var(--bg-color);border-radius:0; }
sl-details.custom-accordion::part(summary) { padding: 0; }
sl-details.custom-accordion::part(summary-icon) { display: none; }
sl-details::part(content) { padding: 0; }

/* Legacy/Manual Accordion Styles */
.accordion-item { border-radius: 0; box-shadow: 0 4px 6px rgba(0,0,0,0.1); overflow: hidden; }
.accordion-header { display: grid; align-items: center; text-align: left; font-weight: 600; font-size: 1rem; color: black; transition: background-color 0.2s; }
.accordion-content { min-height: 2rem; border-bottom:1px solid lightgrey;color: black; align-items: center; font-size: 0.95rem; padding-bottom: 0; display: grid; }

.accordion-content.meter-content { width: 100%; font-size: 0.95rem; grid-template-columns: repeat(var(--col-count, 6), 1fr); }
.accordion-content.meter-content2 { width: 100%; font-size: 0.95rem; grid-template-columns: repeat(var(--col-count, 7), 1fr); }

.main-title-col { display: flex; }

/* Data Coloring Classes */
.bh{background-color:blue;} .bm{background-color:#9999ff;} .bl{background-color:#ccccff;}
.gh{background-color:green;} .gm{background-color:#99ff99;} .gl{background-color:#ccffcc;}
.sh{background-color:#f3d153;} .sm{background-color:#f7e397;} .sl{background-color:#fbf1cb;}
.th{background-color:#999} .tm{background-color:#bbb;} .tl{background-color:#ddd;}
.lh{background-color:#cc5500} .lm{background-color:#ff6f00;} .ll{background-color:#ff9d56;}

/* =========================================
   6. THIRD PARTY OVERRIDES
   ========================================= */
/* Highcharts */
.highcharts-fullscreen { background-color: #ffffff !important; }

/* Tom Select (Dark Theme to match App) */
.ts-control {
    font-size: 1rem !important;
    line-height: 1 !important;
    background-color: #1e293b !important;
    color: white !important;
    border: 1px solid #334155 !important;
    border-radius: 6px !important;
    padding: 8px 15px !important; /* Adjusted for better touch */
    box-shadow: none !important;
    display: flex; 
    align-items: center;
}
.ts-control input { font-size: 1.2rem; color: white !important; }
.ts-control .item { color: white !important; }

.ts-dropdown {
    background-color: #1e293b !important;
    border: 1px solid #334155 !important;
    color: white !important;
    margin-top: 4px !important;
    border-radius: 6px !important;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3) !important;
    z-index: 1000;
}
.ts-dropdown .option {
    font-size: 1.2rem !important;
    padding: 10px 12px !important;
    color: #e2e8f0 !important;
    border-bottom: 1px solid #222;
}
.ts-dropdown .active { background-color: #334155 !important; color: white !important; }
.ts-dropdown .selected { background-color: #334155 !important; font-weight: bold; }

/* =========================================
   7. RESPONSIVE / MOBILE
   ========================================= */
/* Mobile Navigation Bar */
.mobile-nav {
    display: none; /* Hidden on desktop */
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #002d3d;
    border-top: 1px solid #444;
    justify-content: space-around;
    padding: 10px 0;
    z-index: 1000;
}

.nav-item {
    color: #888;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.8rem;
    cursor: pointer;
}

.nav-item.active {
    color: #efc119; /* Gold/Yellow active color */
}

.nav-item i {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

/* Mobile Media Query */
@media (max-width: 768px) {
    .main-wrapper {
        flex-direction: column;
        padding-bottom: 70px; /* Space for the nav bar */
    }

    .mobile-nav {
        display: flex;
    }

    /* Hide panels by default on mobile unless they are active */
    #SIDEBAR, #HOME2, #HOME3,#ICONS {
        display: none;
        width: 100% !important;
        flex: none !important;
    }
   
    /* Logic to show the correct panel based on activePane */
    dash-app[active-pane="sidebar"] #SIDEBAR { display: block; }
    dash-app[active-pane="analytics"] #HOME2 { display: block; }
    dash-app[active-pane="monitor"] #HOME3 { display: block; }
    dash-app[active-pane="history"] #HOME3 { display: block; }
}

/* Mobile-specific sticky behavior */
@media (max-width: 767px) {
    .date-section {
        position: -webkit-sticky; /* Support for older Safari */
        position: sticky;
        top: 0;
        z-index: 100; /* Keeps it above accordions */
        background-color: #002d3d;
        border-bottom: 1px solid #444;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }
    
    /* Optional: Smooth the transition for the main wrapper */
   .main-wrapper {
        display: block !important; /* Stack vertically for sticky scroll context */
        overflow: visible !important;
    }
}