/* raca-energy-project/client/static/css/style.css */

/* * ==========================================================================
 * RACA ENERGY MONITORING SYSTEM - ULTIMATE DESIGN FRAMEWORK
 * Version: 4.5.0 (Fixed Mobile Charts & Responsive Layouts)
 * Author: Raca Dev Team
 * Description: A comprehensive, scalable, and robust design system.
 * ==========================================================================
 */

/* * ==========================================================================
 * 1. CORE CONFIGURATION
 * ==========================================================================
 */

/* --- 1.1 Imports & Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@100;200;300;400;500;600;700;800;900&display=swap');

/* --- 1.2 Design Tokens (Variables) --- */
:root {
    /* ------------------------------------
       PALETTE: BRANDING
    ------------------------------------ */
    --brand-primary: #ff6b35;
    --brand-primary-hover: #e85a2d;
    --brand-primary-active: #d14d22;
    --brand-primary-light: rgba(255, 107, 53, 0.15);
    --brand-primary-fade: rgba(255, 107, 53, 0.05);

    --brand-secondary: #00b894; /* Modern Teal/Green */
    --brand-secondary-hover: #00a180;
    --brand-secondary-active: #00896c;
    --brand-secondary-light: rgba(0, 184, 148, 0.15);

    --brand-accent: #0984e3; /* Reliable Blue */
    --brand-accent-hover: #0074d9;

    /* ------------------------------------
       PALETTE: DATA VISUALIZATION
    ------------------------------------ */
    --data-elec: #f1c40f;
    --data-elec-light: rgba(241, 196, 15, 0.2);
    --data-water: #0984e3;
    --data-water-light: rgba(9, 132, 227, 0.2);
    --data-gas: #00cec9;
    --data-gas-light: rgba(0, 206, 201, 0.2);
    --data-heat: #d63031;
    --data-heat-light: rgba(214, 48, 49, 0.2);
    --data-unknown: #b2bec3;

    /* ------------------------------------
       PALETTE: SEMANTIC STATES
    ------------------------------------ */
    --status-success: #00b894;
    --status-success-bg: #e6fffa;
    --status-warning: #fdcb6e;
    --status-warning-bg: #fffbeb;
    --status-danger: #d63031;
    --status-danger-bg: #fff5f5;
    --status-info: #74b9ff;
    --status-info-bg: #ebf8ff;

    /* ------------------------------------
       THEME: LIGHT (Default)
    ------------------------------------ */
    --bg-app: #f0f4f8;      /* Slate-50: Soft cool grey base */
    --bg-panel: #ffffff;    /* Pure white for cards */
    --bg-element: #f8fafc;  /* Slate-50 for inputs/wells */
    --bg-hover: #f1f5f9;    /* Slate-100 for hover states */
    --bg-active: #e2e8f0;   /* Slate-200 for active states */

    --text-primary: #1e293b;   /* Slate-800: High contrast text */
    --text-secondary: #64748b; /* Slate-500: Medium contrast */
    --text-tertiary: #94a3b8;  /* Slate-400: Low contrast */
    --text-inverse: #ffffff;
    --text-disabled: #cbd5e1;

    --border-light: #e2e8f0;   /* Slate-200 */
    --border-medium: #cbd5e1;  /* Slate-300 */
    --border-dark: #94a3b8;    /* Slate-400 */
    --border-focus: rgba(255, 107, 53, 0.4);

    /* ------------------------------------
       EFFECTS: SHADOWS & DEPTH
    ------------------------------------ */
    --elevation-0: none;
    --elevation-1: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --elevation-2: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --elevation-3: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --elevation-4: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --elevation-inner: inset 0 2px 4px 0 rgba(0,0,0,0.06);
    --elevation-glow: 0 0 15px rgba(255, 107, 53, 0.5);

    /* ------------------------------------
       LAYOUT: SPACING & SIZING
    ------------------------------------ */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-pill: 9999px;
    --radius-circle: 50%;

    --spacing-xs: 0.25rem; /* 4px */
    --spacing-sm: 0.5rem;  /* 8px */
    --spacing-md: 1rem;    /* 16px */
    --spacing-lg: 1.5rem;  /* 24px */
    --spacing-xl: 2rem;    /* 32px */
    --spacing-xxl: 3rem;   /* 48px */

    --header-height: 80px;
    --nav-height: 70px;

    /* ------------------------------------
       TYPOGRAPHY
    ------------------------------------ */
    --font-main: 'Vazirmatn', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: 'Courier New', Courier, monospace;

    --text-xs: 0.75rem;    /* 12px */
    --text-sm: 0.875rem;   /* 14px */
    --text-base: 1rem;     /* 16px */
    --text-lg: 1.125rem;   /* 18px */
    --text-xl: 1.25rem;    /* 20px */
    --text-2xl: 1.5rem;    /* 24px */
    --text-3xl: 1.875rem;  /* 30px */
    --text-4xl: 2.25rem;   /* 36px */

    --fw-light: 300;
    --fw-normal: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;
    --fw-black: 900;

    --lh-none: 1;
    --lh-tight: 1.25;
    --lh-snug: 1.375;
    --lh-base: 1.6;
    --lh-relaxed: 1.625;

    /* ------------------------------------
       ANIMATION
    ------------------------------------ */
    --ease-bounce: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 150ms;
    --duration-norm: 300ms;
    --duration-slow: 500ms;

    /* ------------------------------------
       Z-INDEX SCALE
    ------------------------------------ */
    --z-negative: -1;
    --z-elevate: 10;
    --z-sticky: 100;
    --z-drawer: 200;
    --z-overlay: 300;
    --z-modal: 1000;
    --z-popover: 1100;
    --z-toast: 2000;
    --z-tooltip: 2100;
}

/* ------------------------------------
   THEME: DARK MODE (Slate/Navy Base)
------------------------------------ */
[data-theme="dark"] {
    /* Rich Navy/Slate Tones */
    --bg-app: #0f172a;      /* Slate-900: Deep background */
    --bg-panel: #1e293b;    /* Slate-800: Card background */
    --bg-element: #334155;  /* Slate-700: Inputs/Wells */
    --bg-hover: #475569;    /* Slate-600: Hover states */
    --bg-active: #64748b;   /* Slate-500: Active states */

    --text-primary: #f1f5f9;   /* Slate-100 */
    --text-secondary: #cbd5e1; /* Slate-300 */
    --text-tertiary: #94a3b8;  /* Slate-400 */
    --text-inverse: #0f172a;
    --text-disabled: #475569;

    --border-light: #334155;   /* Slate-700 */
    --border-medium: #475569;  /* Slate-600 */
    --border-dark: #64748b;    /* Slate-500 */

    /* Adjust shadows for dark mode visibility */
    --elevation-1: 0 1px 3px 0 rgba(0, 0, 0, 0.5);
    --elevation-2: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --elevation-3: 0 10px 15px -3px rgba(0, 0, 0, 0.5);

    /* Adjust brand opacity for better contrast */
    --brand-primary-light: rgba(255, 107, 53, 0.25);
    --brand-secondary-light: rgba(0, 184, 148, 0.25);
}

/* * ==========================================================================
 * 2. CSS RESET & NORMALIZATION
 * ==========================================================================
 */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Strict Font Enforcement */
    font-family: var(--font-main) !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    height: 100%;
}

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    line-height: var(--lh-base);
    direction: rtl;
    text-align: right;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--duration-norm), color var(--duration-norm);
}

/* Media Element Resets */
img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
}

/* Form Element Resets */
input, button, textarea, select {
    font: inherit;
    color: inherit;
    border: none;
    background: transparent;
    outline: none;
}

/* List Resets */
ul, ol {
    list-style: none;
}

/* Link Resets */
a {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

/* * ==========================================================================
 * 3. TYPOGRAPHY SYSTEM
 * ==========================================================================
 */

h1, h2, h3, h4, h5, h6 {
    margin-bottom: var(--spacing-sm);
    font-weight: var(--fw-bold);
    line-height: var(--lh-tight);
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); text-transform: uppercase; letter-spacing: 0.05em; }

p {
    margin-bottom: var(--spacing-md);
    max-width: 65ch; /* Optimal reading width */
}

small { font-size: var(--text-xs); }
strong { font-weight: var(--fw-bold); }
em { font-style: italic; }

/* Code styles */
code, kbd, samp, pre {
    font-family: var(--font-mono) !important;
    font-size: var(--text-sm);
}

pre {
    background: var(--bg-element);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

/* Text Utilities */
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }
.text-left { text-align: left !important; }
.text-justify { text-align: justify !important; }

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-break {
    word-break: break-word;
    overflow-wrap: break-word;
}

/* * ==========================================================================
 * 4. LAYOUT SYSTEM
 * ==========================================================================
 */

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
    /* Ensure space for bottom nav */
    padding-bottom: calc(var(--nav-height) + var(--spacing-xl));
}

/* *** FIX: Increased padding so title doesn't overlap header when slider is hidden *** */
.content {
    padding-top: 50px;
    padding-bottom: var(--spacing-lg);
    animation: contentFadeIn var(--duration-norm) var(--ease-smooth);
}

@keyframes contentFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Flexbox Grid System --- */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: calc(var(--spacing-md) * -0.5);
    margin-left: calc(var(--spacing-md) * -0.5);
}

.col {
    flex: 1 0 0%; /* Flex-grow, flex-shrink, flex-basis */
    padding-right: calc(var(--spacing-md) * 0.5);
    padding-left: calc(var(--spacing-md) * 0.5);
}

.col-auto { flex: 0 0 auto; width: auto; }
.col-1 { flex: 0 0 8.333333%; max-width: 8.333333%; }
.col-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }
.col-3 { flex: 0 0 25%; max-width: 25%; }
.col-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
.col-5 { flex: 0 0 41.666667%; max-width: 41.666667%; }
.col-6 { flex: 0 0 50%; max-width: 50%; }
.col-7 { flex: 0 0 58.333333%; max-width: 58.333333%; }
.col-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }
.col-9 { flex: 0 0 75%; max-width: 75%; }
.col-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
.col-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
.col-12 { flex: 0 0 100%; max-width: 100%; }

/* --- CSS Grid System --- */
.grid {
    display: grid;
    gap: var(--spacing-lg);
}

.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* --- Page State Management --- */
.page {
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.page.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* * ==========================================================================
 * 5. COMPONENT: HEADER
 * ==========================================================================
 */

.header {
    background: var(--bg-panel);
    background-image: linear-gradient(135deg, var(--brand-primary) 0%, #ff9f43 100%);
    color: var(--text-inverse);
    padding: 30px 20px 60px 20px; /* Overlap padding */
    text-align: center;
    border-bottom-left-radius: 40px;
    border-bottom-right-radius: 40px;
    box-shadow: var(--elevation-3);
    position: relative;
    z-index: var(--z-sticky);
    margin-bottom: -30px; /* Pull content up into header */
    overflow: hidden;
}

/* Header Background Texture (Optional) */
.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 10% 20%, rgba(255,255,255,0.1) 0%, transparent 20%),
                radial-gradient(circle at 90% 80%, rgba(255,255,255,0.1) 0%, transparent 20%);
    pointer-events: none;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 900;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header .subtitle {
    font-size: 0.95rem;
    opacity: 0.9;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.header-controls {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    gap: 10px;
    z-index: 2;
}

.header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-md);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    font-size: 1.2rem;
    transition: all var(--duration-fast);
    backdrop-filter: blur(8px);
    box-shadow: var(--elevation-1);
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px) scale(1.05);
    box-shadow: var(--elevation-2);
}

.header-btn:active {
    transform: translateY(0) scale(0.95);
}

/* * ==========================================================================
 * 6. COMPONENT: CONNECTION STATUS (PILL)
 * ==========================================================================
 */

.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    background: var(--bg-panel);
    border-radius: var(--radius-pill);
    box-shadow: var(--elevation-2);
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0 auto 25px auto;
    width: fit-content;
    border: 1px solid var(--border-light);
    position: relative;
    z-index: var(--z-elevate);
    transition: all var(--duration-norm);
}

.connection-status.connected {
    border-color: var(--status-success);
    color: var(--status-success);
}

.connection-status.disconnected {
    border-color: var(--status-danger);
    color: var(--status-danger);
    animation: shake 0.5s ease-in-out;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: currentColor;
    /* FIX: Added proper display and shrink properties */
    display: inline-block;
    flex-shrink: 0;
}

.connection-status.connected .status-indicator {
    box-shadow: 0 0 0 2px rgba(0, 184, 148, 0.2);
    animation: pulseStatus 2s infinite;
}

.refresh-info {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-right: 10px;
    border-right: 1px solid var(--border-light);
    padding-right: 10px;
    font-weight: 400;
}

/* * ==========================================================================
 * 7. COMPONENT: PROJECT SLIDER (GLASSMORPHISM)
 * ==========================================================================
 */

#projectSliderContainer {
    background: transparent;
    padding: 0 20px;
    /* فاصله از بالا برای تداخل نداشتن با هدر */
    margin-top: 40px;
    margin-bottom: 30px;
    border: none;

    /* FIX: تغییر مهم برای فعال‌سازی اسکرول در موبایل */
    overflow-x: auto !important;
    overflow-y: hidden;

    /* Fix for z-index layering */
    position: relative;
    z-index: 110;

    /* اسکرول نرم برای موبایل */
    -webkit-overflow-scrolling: touch;
}

/* مخفی کردن اسکرول‌بار کانتینر اصلی */
#projectSliderContainer::-webkit-scrollbar {
    display: none;
}

.project-slider {
    display: flex;
    gap: 20px;
    /* اسکرول افقی */
    overflow-x: auto;
    padding: 15px 10px 25px 10px; /* Padding for hover growth and shadow */
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide Firefox scrollbar */
}

.project-slider::-webkit-scrollbar { display: none; }

.project-slide {
    flex: 0 0 160px;
    height: 110px;
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    border: 1px solid var(--border-light);
    box-shadow: var(--elevation-1);
    transition: all var(--duration-norm) var(--ease-smooth);
    position: relative;
    scroll-snap-align: center;
    overflow: hidden;
}

/* Glass effect overlay */
.project-slide::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0));
    pointer-events: none;
}

/* Hover State */
.project-slide:hover:not(.active) {
    transform: translateY(-4px);
    box-shadow: var(--elevation-2);
    border-color: var(--brand-primary-light);
}

/* Active State */
.project-slide.active {
    background: var(--bg-panel);
    border-color: var(--brand-primary);
    box-shadow: 0 12px 24px -8px var(--brand-primary-light);
    transform: translateY(-6px) scale(1.02);
}

.project-slide p {
    font-weight: 700;
    font-size: 0.95rem;
    margin: 0;
    color: var(--text-primary);
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 1;
}

.project-slide span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 6px;
    z-index: 1;
    background: var(--bg-element);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
}

/* Add New Project Slide */
.project-slide-add {
    /* Added dimensions to match slides */
    flex: 0 0 160px;
    height: 110px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    position: relative;
    scroll-snap-align: center;

    border: 2px dashed var(--border-dark);
    background: transparent;
    color: var(--text-tertiary);
    box-shadow: none;
}

.project-slide-add:hover {
    border-color: var(--brand-primary);
    color: var(--brand-primary);
    background: var(--brand-primary-fade);
    transform: translateY(-2px);
    box-shadow: none;
}

.project-slide-add span {
    font-size: 2.5rem;
    line-height: 0;
    margin-bottom: 12px;
    background: transparent; /* Override tag background */
    padding: 0;
}

/* Slide Actions (Edit/Delete) */
.project-slide-actions {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transform: translateY(-5px);
    transition: all 0.2s ease;
    z-index: 2;
}

.project-slide:hover .project-slide-actions {
    opacity: 1;
    transform: translateY(0);
}

.project-slide-actions button {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
    background: var(--bg-element);
    color: var(--text-secondary);
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.project-slide-actions button:hover {
    background: var(--brand-primary);
    color: white;
    border-color: var(--brand-primary);
}

.project-slide-actions button:hover {
    background: var(--brand-primary);
    color: white;
    border-color: var(--brand-primary);
}

/* * ==========================================================================
 * 8. COMPONENT: UNIT & DEVICE CARDS
 * ==========================================================================
 */

.unit-section {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--elevation-1);
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

.unit-section:hover {
    box-shadow: var(--elevation-2);
}

/* Decorative Sidebar */
.unit-section::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--brand-primary);
}

.unit-header {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
}

.unit-header i {
    color: var(--text-tertiary);
}

.unit-devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

/* -- Device Card -- */
.device-card {
    background: var(--bg-element);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: all 0.3s var(--ease-smooth);
    cursor: pointer;
    position: relative;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    min-height: 180px;
}

.device-card:hover {
    background: var(--bg-panel);
    transform: translateY(-6px);
    box-shadow: var(--elevation-2);
    border-color: var(--border-light);
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.device-type-text {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--brand-primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    background: var(--brand-primary-fade);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

/* DN Value Badge */
.badge-dn {
    background-color: var(--brand-secondary);
    color: white;
    padding: 2px 6px;
    border-radius: var(--radius-md);
    font-size: 0.7rem;
    font-weight: 700;
    margin-right: 5px;
    vertical-align: middle;
}

/* --- Fix for Device Status Dot & Group --- */

/* 1. Add flex container for Battery + Connection icons */
.status-group {
    display: flex;
    align-items: center;
    gap: 8px; /* Space between battery and connection dot */
}

/* 2. Fix the Dot rendering */
.device-status-dot {
    display: inline-block; /* REQUIRED: allows span to respect width/height */
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--text-tertiary);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);

    /* Prevent circle from becoming an oval in flex layouts */
    flex-shrink: 0;
}

/* 3. States */
.device-status-dot.online {
    background-color: var(--status-success);
    box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.15);
    animation: pulseStatus 3s infinite;
}

.device-status-dot.offline {
    background-color: var(--status-danger);
}

.device-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
    line-height: 1.4;
}

.device-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.protocol-badge {
    display: inline-block;
    background-color: var(--bg-app);
    border: 1px solid var(--border-light);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.device-actions {
    margin-top: auto;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    opacity: 0; /* Hidden by default */
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.device-card:hover .device-actions {
    opacity: 1;
    transform: translateY(0);
}

/* * ==========================================================================
 * 9. COMPONENT: CONSUMPTION BOXES
 * ==========================================================================
 */

/* Container for equal height */
.top-box-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    margin-bottom: 20px;
}

@media (min-width: 768px) {
    .top-box-container {
        flex-direction: row;
    }
    .top-box-container > .consumption-box {
        flex: 1;
        width: 50%;
    }
}

.consumption-box {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    padding: 25px;
    box-shadow: var(--elevation-2);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 320px; /* Fixed height ensures alignment */
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.consumption-box:hover {
    transform: translateY(-4px);
    box-shadow: var(--elevation-3);
}

/* Header */
.consumption-box h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 12px;
    margin-bottom: 12px;
    font-weight: 700;
}

/* Date */
.consumption-box .date-info {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    text-align: center;
    font-weight: 500;
    background: var(--bg-element);
    display: inline-block;
    margin: 0 auto 15px auto;
    padding: 4px 12px;
    border-radius: var(--radius-pill);
}

/* Content Wrapper */
.consumption-value-container,
#todayConsumptionContent,
#monthConsumptionContent,
#yesterdayConsumptionContent {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

/* The Big Number */
.consumption-value {
    font-size: 3.8rem;
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1;
    font-family: var(--font-main) !important;
    text-shadow: 2px 2px 0px var(--bg-app); /* subtle depth */
}

/* Force colors for data types */
#total-today-energy, #total-month-energy, #total-yesterday-energy { color: var(--data-elec) !important; }
#total-today-gas, #total-month-gas, #total-yesterday-gas { color: var(--data-gas) !important; }
#total-today-heat, #total-month-heat, #total-yesterday-heat { color: var(--data-heat) !important; }
#total-today-water, #total-month-water, #total-yesterday-water { color: var(--data-water) !important; }

/* Details Grid (Min/Max/Avg) */
.values-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px; /* Gap creates the border effect */
    background: var(--border-light); /* Border color */
    border-radius: var(--radius-md);
    margin-top: auto;
    overflow: hidden;
    border: 1px solid var(--border-light);
}

.values-grid > div {
    background: var(--bg-element);
    padding: 10px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.values-grid > div span:first-child {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-bottom: 2px;
}

.values-grid > div strong {
    font-size: 0.95rem;
    color: var(--text-primary);
}

/* * ==========================================================================
 * 10. COMPONENT: SETTINGS (GRID & CARDS)
 * ==========================================================================
 */

#userProfilePage .content {
    max-width: 900px;
    margin: 0 auto;
}

#userProfilePage form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 25px;
}

@media (min-width: 768px) {
    #userProfilePage form {
        grid-template-columns: repeat(2, 1fr);
    }
    /* Full width items */
    #userProfilePage form button[type="submit"],
    #userProfilePage .checkbox-group {
        grid-column: span 2;
    }
    #userProfilePage .user-profile {
        grid-column: span 2;
    }
}

/* Profile Header Card */
.user-profile {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    box-shadow: var(--elevation-1);
    border: 1px solid var(--border-light);
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
}

/* Background Pattern */
.user-profile::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100px;
    background: linear-gradient(to right, var(--brand-secondary), var(--brand-accent));
    opacity: 0.1;
    z-index: 0;
}

.profile-avatar {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, var(--brand-secondary), #55efc4);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: white;
    margin: 0 auto 20px;
    box-shadow: 0 8px 20px rgba(0, 184, 148, 0.3);
    position: relative;
    z-index: 1;
    border: 4px solid var(--bg-panel);
}

/* Settings Input Cards */
#userProfilePage .form-group {
    background: var(--bg-panel);
    padding: 25px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--elevation-1);
    margin-bottom: 0; /* Grid handles spacing */
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}

#userProfilePage .form-group:focus-within {
    border-color: var(--brand-primary);
    box-shadow: var(--elevation-2);
    transform: translateY(-2px);
}

#userProfilePage label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

#userProfilePage input {
    background: var(--bg-element);
    border: 1px solid transparent;
    font-size: 1.1rem;
    font-weight: 600;
}

/* * ==========================================================================
 * 11. FORM ELEMENTS (ADVANCED)
 * ==========================================================================
 */

.form-group {
    margin-bottom: var(--spacing-lg);
    position: relative;
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-element);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s ease;
    text-align: right;
    direction: rtl;
}

.form-input:hover {
    background: var(--bg-app);
}

.form-input:focus {
    background: var(--bg-panel);
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 4px var(--brand-primary-light);
}

.form-input::placeholder {
    color: var(--text-tertiary);
    opacity: 1;
}

/* Input Unit Suffix */
.input-unit {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%); /* Adjust based on label height if needed */
    color: var(--text-tertiary);
    font-size: 0.9rem;
    font-weight: 600;
    pointer-events: none;
}

/* Checkboxes - Custom Style */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: var(--spacing-lg);
    cursor: pointer;
    padding: 15px;
    background: var(--bg-element);
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.checkbox-group:hover {
    background: var(--bg-hover);
}

.checkbox-group input[type="checkbox"] {
    appearance: none;
    width: 22px;
    height: 22px;
    border: 2px solid var(--border-dark);
    border-radius: 6px;
    background: var(--bg-panel);
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.checkbox-group input[type="checkbox"]:checked {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
}

.checkbox-group input[type="checkbox"]:checked::after {
    content: '✔';
    color: white;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
}

/* Select Dropdown */
select.form-input {
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: left 1rem center;
    background-size: 1rem;
    padding-left: 2.5rem; /* Make space for arrow on left (RTL) */
}

/* * ==========================================================================
 * 12. BUTTON SYSTEM
 * ==========================================================================
 */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s var(--ease-bounce);
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-hover));
    color: white;
    box-shadow: 0 4px 12px var(--brand-primary-light);
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Ripple Effect Element (Optional JS enhancement target) */
.btn::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.1);
    opacity: 0;
    transition: opacity 0.2s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px var(--brand-primary-light);
    filter: brightness(1.1);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px var(--brand-primary-light);
}

.btn:disabled {
    background: var(--bg-active);
    color: var(--text-tertiary);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* Button Sizes */
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }
.btn-lg { padding: 16px 32px; font-size: 1.15rem; }

/* Variant: Secondary/Ghost */
.btn-small {
    padding: 6px 14px;
    font-size: 0.8rem;
    width: auto;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    box-shadow: none;
    border-radius: var(--radius-sm);
}

.btn-small:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
    background: var(--bg-element);
}

/* Variant: Danger */
.btn-danger {
    background: var(--status-danger);
    color: white;
    box-shadow: 0 4px 12px rgba(214, 48, 49, 0.2);
}

.btn-danger:hover {
    background: #c0392b;
    box-shadow: 0 8px 20px rgba(214, 48, 49, 0.3);
}

/* Variant: Success */
.btn-success {
    background: var(--status-success);
    color: white;
}

/* * ==========================================================================
 * 13. COMPONENT: MODERN ADD BUTTON (FAB)
 * ==========================================================================
 */

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 5px;
}

.section-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-primary);
    position: relative;
}

.section-header h2::after {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--brand-primary);
    border-radius: var(--radius-pill);
    margin-top: 5px;
}

/* The Circular Green Button */
#addDeviceBtn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--brand-secondary);
    color: white;
    border: none;
    box-shadow: 0 5px 15px rgba(0, 184, 148, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 300;
    line-height: 0;
    cursor: pointer;
    transition: all 0.4s var(--ease-bounce);
    padding: 0;
    position: relative;
}

#addDeviceBtn::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.5);
    opacity: 0;
    transform: scale(1.2);
    transition: all 0.4s;
}

#addDeviceBtn:hover {
    transform: scale(1.1) rotate(90deg);
    background: var(--brand-secondary-hover);
    box-shadow: 0 10px 25px rgba(0, 184, 148, 0.5);
}

#addDeviceBtn:hover::before {
    opacity: 1;
    transform: scale(1);
}

/* * ==========================================================================
 * 14. MODALS (GLASSMORPHISM)
 * ==========================================================================
 */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6); /* Dark overlay */
    backdrop-filter: blur(8px);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal:not(.hidden) { opacity: 1; visibility: visible; }

.modal-content {
    background: var(--bg-panel);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-xl);
    padding: 35px;
    box-shadow: var(--elevation-4);
    transform: scale(0.95) translateY(20px);
    transition: transform 0.4s var(--ease-bounce);
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--border-light);
}

.modal:not(.hidden) .modal-content {
    transform: scale(1) translateY(0);
}

/* Modal Header */
.modal-content h2 {
    text-align: center;
    color: var(--brand-primary);
    font-size: 1.5rem;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-light);
}

/* Close Button */
.close {
    position: absolute;
    left: 20px;
    top: 20px;
    font-size: 1.5rem;
    color: var(--text-tertiary);
    cursor: pointer;
    background: var(--bg-element);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.close:hover {
    color: var(--status-danger);
    background: var(--bg-app);
    border-color: var(--status-danger);
    transform: rotate(90deg);
}

/* * ==========================================================================
 * 15. NAVIGATION (FLOATING DOCK)
 * ==========================================================================
 */

.bottom-nav {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    min-width: 320px;
    max-width: 90%;
    height: 70px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 5px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1), 0 5px 15px rgba(0,0,0,0.05);
    z-index: var(--z-nav);
    border: 1px solid rgba(255,255,255,0.5);
}

[data-theme="dark"] .bottom-nav {
    background: rgba(30, 41, 59, 0.85);
    border-color: rgba(255,255,255,0.1);
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
}

.nav-tab {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 8px 12px;
    position: relative;
    transition: all 0.3s ease;
    border-radius: 12px;
}

.nav-tab:hover {
    color: var(--text-secondary);
    background: rgba(0,0,0,0.03);
}

.nav-icon {
    font-size: 1.6rem;
    margin-bottom: 0;
    transition: transform 0.3s var(--ease-bounce);
}

.nav-tab span:not(.nav-icon) {
    font-size: 0.7rem;
    font-weight: 700;
    opacity: 0;
    height: 0;
    overflow: hidden;
    transition: all 0.3s;
    white-space: nowrap;
}

/* Active State Animation */
.nav-tab.active {
    color: var(--brand-primary);
    background: var(--brand-primary-fade);
}

.nav-tab.active .nav-icon {
    transform: translateY(-2px);
}

.nav-tab.active span:not(.nav-icon) {
    opacity: 1;
    height: auto;
    margin-top: 2px;
}

/* * ==========================================================================
 * 16. ALERTS & NOTIFICATIONS
 * ==========================================================================
 */

.alert {
    padding: 15px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 15px;
    border-right: 4px solid transparent;
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    gap: 5px;
    box-shadow: var(--elevation-1);
    position: relative;
    overflow: hidden;
}

.alert::before {
    content: '';
    position: absolute;
    top: 0; bottom: 0; right: 0;
    width: 100%;
    background: linear-gradient(to left, rgba(0,0,0,0.02), transparent);
    pointer-events: none;
}

.alert.critical {
    border-color: var(--status-danger);
    background: var(--status-danger-bg);
    color: #721c24;
}

.alert.warning {
    border-color: var(--status-warning);
    background: var(--status-warning-bg);
    color: #856404;
}

.alert.info {
    border-color: var(--status-info);
    background: var(--status-info-bg);
    color: #0c5460;
}

/* Floating Toast Notification */
.notification-box {
    /* ... existing styles ... */
    background: var(--bg-panel); /* Use panel color for consistency */
    color: var(--text-primary);
    border-right-color: transparent !important; /* Reset custom border */
    border: 1px solid var(--border-light);
    box-shadow: var(--elevation-3); /* Use existing shadow */
    transition: transform 0.4s var(--ease-bounce), opacity 0.3s;
}

.notification-box.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.notification-box.success { background: var(--status-success); color: white; }
.notification-box.error { background: var(--status-danger); color: white; }
.notification-box.info { background: var(--brand-accent); color: white; }

/* * ==========================================================================
 * 17. TABLES & CHARTS
 * ==========================================================================
 */

.history-table-container {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    overflow: hidden;
    box-shadow: var(--elevation-1);
    margin-bottom: 20px;
    max-height: 500px;
    overflow-y: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.history-table th,
.history-table td {
    padding: 16px 20px;
    text-align: right;
    border-bottom: 1px solid var(--border-light);
}

.history-table thead th {
    background-color: var(--bg-element);
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.history-table tbody tr:hover {
    background-color: var(--bg-hover);
}

/* Charts Container */
.chart-container {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    padding: 25px; /* Increased padding */
    box-shadow: var(--elevation-2); /* Enhanced shadow */
    border: 1px solid var(--border-light);
    margin-bottom: 30px;
    position: relative;
    width: 100%; /* Ensure full width */
}

.chart-title {
    font-size: 1.4rem; /* Larger Title */
    font-weight: 800;
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-primary);
}

/* *** Explicit Chart Wrapper Styles (Fixed Height & Width) *** */
.chart-wrapper {
    position: relative;
    height: 500px; /* Default desktop height */
    width: 100%;
    min-width: 0; /* Flexbox/Grid fix */
}

/* Time Selector Tabs */
.time-selector {
    display: flex;
    gap: 8px; /* کاهش فاصله بین دکمه‌ها */
    margin-bottom: 20px;
    overflow-x: auto; /* فعال‌سازی اسکرول افقی */
    padding: 5px;
    background: var(--bg-element);
    border-radius: var(--radius-pill);

    width: fit-content;      /* عرض متناسب با محتوا */
    max-width: 100%;         /* جلوگیری از بیرون زدن از صفحه */

    border: 1px solid var(--border-light);

    /* مخفی کردن اسکرول‌بار برای زیبایی */
    scrollbar-width: none;  /* Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
    -webkit-overflow-scrolling: touch; /* اسکرول نرم در iOS */
}

/* مخفی کردن اسکرول‌بار در کروم/سافاری */
.time-selector::-webkit-scrollbar {
    display: none;
}

.time-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 20px;
    border-radius: var(--radius-pill);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap; /* جلوگیری از شکستن متن دکمه */
    flex-shrink: 0;      /* جلوگیری از فشرده شدن دکمه‌ها در موبایل */
}

.time-btn:hover {
    color: var(--text-primary);
    background: rgba(0,0,0,0.03);
}

.time-btn.active {
    background: var(--bg-panel);
    color: var(--brand-primary);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    font-weight: 800;
    border: 1px solid var(--border-light);
}

/* * ==========================================================================
 * تنظیمات مخصوص موبایل
 * ==========================================================================
 */

/* 1. Mobile Landscape: Shorten height significantly so X-axis is visible */
@media (max-width: 768px) and (orientation: landscape) {
    .chart-wrapper {
        height: 300px !important; /* Force override */
    }
}

/* 2. General Mobile (Portrait): Reduce height from 500px to 350px for better fit */
@media (max-width: 768px) {
    .chart-wrapper {
        height: 350px; /* More comfortable height for mobile portrait */
    }
}

/* 3. Time Selector & Button Optimizations for Mobile */
@media (max-width: 767px) {
    .time-selector {
        width: 100%;             /* Take full width */
        border-radius: 12px;     /* Softer corners */
        justify-content: flex-start; /* Aligns right in RTL (Correct) */
        padding: 4px;
        overflow-x: auto;        /* Ensure scrolling works */
    }

    .time-btn {
        padding: 6px 14px;       /* Smaller buttons */
        font-size: 0.85rem;      /* Smaller text */
        white-space: nowrap;     /* Prevent text wrapping */
    }

    /* Optional: Ensure the container holding the chart doesn't add too much padding */
    .chart-container {
        padding: 15px;
    }
}

/* * ==========================================================================
 * 18. UTILITY CLASSES (EXTENDED)
 * ==========================================================================
 */

/* Spacing */
.m-0 { margin: 0 !important; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.ml-auto { margin-left: auto !important; }
.mr-auto { margin-right: auto !important; }
.mx-auto { margin-left: auto !important; margin-right: auto !important; }

.w-100 { width: 100% !important; }
.h-100 { height: 100% !important; }

/* Flex */
.d-flex { display: flex !important; }
.d-block { display: block !important; }
.d-inline-block { display: inline-block !important; }
.flex-wrap { flex-wrap: wrap !important; }
.align-items-center { align-items: center !important; }
.justify-content-center { justify-content: center !important; }
.justify-content-between { justify-content: space-between !important; }

/* Colors */
.bg-primary { background-color: var(--brand-primary) !important; }
.bg-secondary { background-color: var(--brand-secondary) !important; }
.text-primary { color: var(--brand-primary) !important; }
.text-white { color: white !important; }

/* Visibility */
.hidden { display: none !important; }
.invisible { visibility: hidden !important; }
.visible { visibility: visible !important; }
.overflow-hidden { overflow: hidden !important; }

/* * ==========================================================================
 * 19. ANIMATIONS
 * ==========================================================================
 */

@keyframes pulseStatus {
    0% { box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(0, 184, 148, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 184, 148, 0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spin {
    animation: spin 1s linear infinite;
}

/* * ==========================================================================
 * 20. PRINT STYLES
 * ==========================================================================
 */

@media print {
    .header, .bottom-nav, .project-slider, .header-controls, #addDeviceBtn, .time-selector {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .container {
        max-width: 100%;
        width: 100%;
        box-shadow: none;
        padding: 0;
    }

    .consumption-box, .chart-container, .device-card, .unit-section {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* * ==========================================================================
 * 21. RESPONSIVE UTILITIES
 * ==========================================================================
 */

/* Mobile Optimized */
@media (max-width: 767px) {
    .header {
        padding: 20px 15px 40px 15px;
        border-radius: 0 0 25px 25px;
    }

    .header h1 { font-size: 1.5rem; }

    .unit-devices-grid {
        grid-template-columns: 1fr; /* Stack cards */
    }

    /* --- IMPROVED BOTTOM NAV (For Admin with many tabs) --- */
    .bottom-nav {
        bottom: 15px;
        width: 95%;
        padding: 5px 10px;
        overflow-x: auto; /* Allow scrolling if tabs exceed width */
        justify-content: flex-start; /* Align start to allow scrolling */
        gap: 5px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Hide scrollbar */
    }

    .bottom-nav::-webkit-scrollbar { display: none; }

    .nav-tab {
        min-width: 65px; /* Ensure minimum clickable width */
        flex-shrink: 0; /* Prevent tabs from shrinking too much */
        padding: 6px;
    }

    .nav-tab span:not(.nav-icon) {
        font-size: 0.65rem; /* Slightly smaller text for density */
    }

    .filter-row, .alert-filters {
        flex-direction: column;
        gap: 15px;
    }

    /* --- IMPROVED TABLES (User Management) --- */
    .history-table-container {
        overflow-x: auto;
        border-radius: var(--radius-md);
    }

    .history-table th,
    .history-table td {
        padding: 12px 10px; /* Reduced padding for mobile */
        font-size: 0.8rem; /* Compact font */
        white-space: nowrap; /* Prevent text wrapping breaking layout */
    }

    /* Stack action buttons in table if needed */
    .history-table td .btn-small {
        margin: 0 2px;
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    /* --- MOBILE MODALS --- */
    .modal-content {
        width: 95%; /* Use more screen width */
        padding: 25px 20px; /* Reduce padding */
        max-height: 90vh; /* Allow taller modals */
        margin: 10px;
    }

    /* --- ADMIN PROJECT SLIDER ACTIONS --- */
    /* Make edit/delete buttons larger for touch */
    .project-slide-actions {
        opacity: 1; /* Always visible on mobile since no hover */
        top: 5px;
        left: 5px;
        transform: translateY(0);
    }

    .project-slide-actions button {
        width: 32px; /* Larger touch target */
        height: 32px;
        font-size: 0.9rem;
        background: var(--bg-panel); /* Ensure visibility against background */
        box-shadow: var(--elevation-1);
    }

    /* Larger touch targets for inputs */
    .btn, .form-input, .nav-tab {
        min-height: 48px;
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) {
    .unit-devices-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* High DPI/Retina */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .form-input, .btn, .consumption-box, .device-card {
        border-width: 0.5px;
    }
}

/* End of Stylesheet */
/* * ==========================================================================
 * LOGIN PAGE REDESIGN (MODERN GLASSMORPHISM)
 * ==========================================================================
 */

.modern-login {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-app);
    overflow: hidden;
    z-index: 9999;
}

/* --- Animated Background Blobs --- */
.login-bg-shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.6;
    animation: floatShape 10s infinite ease-in-out alternate;
}

.shape-1 {
    width: 500px; height: 500px;
    background: var(--brand-primary);
    top: -10%; right: -10%;
    animation-delay: 0s;
}

.shape-2 {
    width: 400px; height: 400px;
    background: var(--brand-secondary);
    bottom: -10%; left: -5%;
    animation-delay: -2s;
}

.shape-3 {
    width: 300px; height: 300px;
    background: var(--brand-accent);
    bottom: 20%; right: 20%;
    opacity: 0.4;
    animation-delay: -5s;
}

@keyframes floatShape {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(30px, 50px) rotate(10deg); }
}

/* --- Glass Card --- */
.login-card-modern {
    width: 100%;
    max-width: 440px;
    padding: 40px;
    border-radius: 32px;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow:
        0 20px 40px rgba(0, 0, 0, 0.05),
        0 1px 3px rgba(0, 0, 0, 0.1),
        inset 0 0 0 1px rgba(255, 255, 255, 0.6);
    text-align: center;
    animation: cardFadeIn 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
    margin: 20px;
}

[data-theme="dark"] .login-card-modern {
    background: rgba(30, 41, 59, 0.7);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
}

@keyframes cardFadeIn {
    from { opacity: 0; transform: translateY(30px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- Header & Logo --- */
.login-header { margin-bottom: 35px; }

.logo-circle {
    width: 70px; height: 70px;
    background: linear-gradient(135deg, var(--brand-primary), #ff9f43);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: white;
    margin: 0 auto 20px;
    box-shadow: 0 10px 20px rgba(255, 107, 53, 0.3);
    transform: rotate(-10deg);
}

.app-title {
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 5px;
    color: var(--text-primary);
    letter-spacing: -1px;
}

.app-subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* --- Modern Inputs --- */
.login-form { display: flex; flex-direction: column; gap: 20px; }

.input-group-modern {
    position: relative;
    background: var(--bg-element);
    border-radius: 18px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 15px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    text-align: right;
}

.input-group-modern:focus-within {
    background: var(--bg-panel);
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 4px var(--brand-primary-light);
    transform: translateY(-2px);
}

.input-icon {
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
}

.input-group-modern:focus-within .input-icon { color: var(--brand-primary); }

.input-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.input-wrapper label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 700;
    margin-bottom: 2px;
}

.modern-input {
    background: transparent;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0;
    height: 24px;
    width: 100%;
}

.modern-input::placeholder { color: var(--text-disabled); font-weight: 400; }

/* --- Checkbox --- */
.form-actions {
    display: flex;
    justify-content: flex-start;
    margin-top: 5px;
}

.custom-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    user-select: none;
}

.custom-checkbox input { display: none; }

.checkmark {
    width: 20px; height: 20px;
    border: 2px solid var(--border-medium);
    border-radius: 6px;
    position: relative;
    transition: all 0.2s;
}

.custom-checkbox input:checked ~ .checkmark {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
}

.custom-checkbox input:checked ~ .checkmark::after {
    content: '';
    position: absolute;
    left: 6px; top: 2px;
    width: 5px; height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* --- Login Button --- */
.btn-login-modern {
    margin-top: 10px;
    background: linear-gradient(135deg, var(--brand-primary), #ff9f43);
    color: white;
    border: none;
    border-radius: 18px;
    padding: 16px;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 20px var(--brand-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-login-modern:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 30px var(--brand-primary-light);
    filter: brightness(1.1);
}

.btn-login-modern:active { transform: translateY(-1px); }

.arrow-icon { transition: transform 0.3s; }
.btn-login-modern:hover .arrow-icon { transform: translateX(-5px); } /* RTL Direction */

/* --- Footer --- */
.login-footer {
    margin-top: 40px;
    border-top: 1px solid var(--border-light);
    padding-top: 20px;
    font-size: 0.8rem;
    color: var(--text-tertiary);
    line-height: 1.6;
}

.login-footer .copyright { opacity: 0.7; }

/* --- Responsive --- */
@media (max-width: 480px) {
    .login-card-modern {
        padding: 30px 20px;
        margin: 15px;
    }
    .app-title { font-size: 1.75rem; }
    .shape-1 { width: 300px; height: 300px; }
}

/* --- Notifications Styling (Added) --- */
.notification-box {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    z-index: 10000;
    min-width: 300px;
    max-width: 90%;
    padding: 15px 20px;
    border-radius: 8px;
    background: white;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    border-right: 6px solid transparent; /* RTL colored border */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* Show State */
.notification-box.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(10px);
}

/* Notification Types - Colors */

/* Success (Green) */
.notification-box.success {
    background-color: #e8f5e9;
    color: #2e7d32;
    border-right-color: #2e7d32;
}
.notification-box.success::before {
    content: '✓';
    font-weight: bold;
    font-size: 1.2rem;
}

/* Error (Red) */
.notification-box.error {
    background-color: #ffebee;
    color: #c62828;
    border-right-color: #c62828;
}
.notification-box.error::before {
    content: '✕';
    font-weight: bold;
    font-size: 1.2rem;
}

/* Info (Blue) */
.notification-box.info {
    background-color: #e3f2fd;
    color: #1565c0;
    border-right-color: #1565c0;
}
.notification-box.info::before {
    content: 'ℹ';
    font-weight: bold;
    font-size: 1.2rem;
}

/* Warning (Orange) */
.notification-box.warning {
    background-color: #fff3e0;
    color: #ef6c00;
    border-right-color: #ef6c00;
}
.notification-box.warning::before {
    content: '⚠';
    font-weight: bold;
    font-size: 1.2rem;
}

/* Dark Mode Support */
[data-theme="dark"] .notification-box {
    background-color: #333;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}
[data-theme="dark"] .notification-box.success { background-color: #1b3320; color: #81c784; }
[data-theme="dark"] .notification-box.error { background-color: #3e2723; color: #e57373; }
[data-theme="dark"] .notification-box.info { background-color: #1a237e; color: #64b5f6; }
[data-theme="dark"] .notification-box.warning { background-color: #3e2723; color: #ffcc80; }

/* * ==========================================================================
 * 22. FIXES & PATCHES
 * ==========================================================================
 */

/* Fix Unit Name Visibility in Device Page */
#deviceUnitDisplay {
    /* Override inline HTML styles */
    background-color: var(--bg-element) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-light) !important;

    /* Match other UI badges */
    font-weight: 700 !important;
    box-shadow: var(--elevation-1);
}

/* * ==========================================================================
 * 23. REVISED PROFILE CARD (FIXED LAYOUT)
 * ==========================================================================
 */

.profile-info-card {
    background: var(--bg-panel);
    border-radius: 24px; /* More rounded */
    box-shadow: var(--elevation-3); /* Deeper shadow */
    border: 1px solid var(--border-light);
    overflow: hidden;
    margin-bottom: 30px;
    max-width: 600px; /* Limit width for better look */
    margin-left: auto;
    margin-right: auto;
    position: relative;
}

.profile-header-section {
    background: linear-gradient(135deg, var(--brand-primary), #ff9f43); /* Orange Brand Gradient */
    padding: 40px 20px;
    text-align: center;
    color: white;
    position: relative;
}

.profile-header-section::after {
    content: '';
    position: absolute;
    bottom: -20px;
    left: 0;
    width: 100%;
    height: 40px;
    background: var(--bg-panel);
    border-radius: 50% 50% 0 0; /* Curve effect */
}

.profile-avatar-large {
    width: 100px;
    height: 100px;
    background: white;
    color: var(--brand-primary);
    border-radius: 50%;
    font-size: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px auto;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    border: 4px solid rgba(255,255,255,0.5);
    position: relative;
    z-index: 2;
}

.profile-name {
    font-size: 1.6rem;
    font-weight: 900;
    margin-bottom: 8px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.profile-role-badge {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(4px);
    padding: 6px 16px;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.4);
}

.profile-details-grid {
    display: grid;
    grid-template-columns: 1fr; /* Stack on mobile */
    gap: 1px;
    background: var(--border-light);
    margin-top: 10px;
    border-top: 1px solid var(--border-light);
}

@media (min-width: 600px) {
    .profile-details-grid {
        grid-template-columns: 1fr 1fr; /* Two columns on desktop */
    }
}

.profile-detail-item {
    background: var(--bg-panel);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: background 0.2s;
}

.profile-detail-item:hover {
    background: var(--bg-element);
}

.profile-label {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    font-weight: 700;
}

/* --- PROFILE VALUES (Strict Centering) --- */
.profile-value {
    font-size: 1.3rem;
    color: var(--text-primary);
    font-weight: 800;
    width: 100%;
    display: block;
    text-align: center !important; /* Force Center */
}

/* Use this for Phone Numbers to keep order correct (0912...) */
.dir-ltr {
    direction: ltr !important;
    text-align: center !important; /* Force Center even in LTR */
    unicode-bidi: embed;
    display: block;
}

/* Use this for Usernames/Units to auto-detect language */
.dir-auto {
    direction: auto !important;
    text-align: center !important;
    display: block;
}
/* Settings Card Adjustment */
.settings-card {
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-panel);
    border-radius: 20px;
    padding: 25px;
    border: 1px solid var(--border-light);
    box-shadow: var(--elevation-1);
}
/* * ==========================================================================
 * 24. FORCE PROFILE ALIGNMENT (ID-BASED FIX)
 * ==========================================================================
 */

/* 1. Force ALL profile values to Center */
#profileUsername,
#profileMobile,
#profileUnit,
#profileProject {
    display: block !important;
    width: 100% !important;
    text-align: center !important;
    font-weight: 800 !important;
    font-size: 1.3rem !important;
    color: var(--text-primary) !important;
}

/* 2. Specific Handling for Mobile Number (Force English Direction) */
#profileMobile {
    direction: ltr !important;
    unicode-bidi: embed !important;
}

/* 3. Specific Handling for Text (Let Browser Decide Direction) */
#profileUsername,
#profileUnit,
#profileProject {
    direction: auto !important;
}

/* * ==========================================================================
 * 25. NUCLEAR PROFILE FIX (Flex Centering)
 * ==========================================================================
 */

/* 1. The Parent Container: Forces children to the center */
.profile-detail-item {
    background: var(--bg-panel);
    padding: 20px;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important; /* Strictly Center Horizontally */
    justify-content: center !important;
    text-align: center !important;
    border: 1px solid transparent; /* Fix potential border rendering issues */
}

/* 2. The Label: Uppercase and muted */
.profile-label {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    font-weight: 700;
    margin-bottom: 8px;
    width: auto !important; /* Shrink to fit */
}

/* 3. The Value: Big text, shrink to fit */
.profile-value {
    font-size: 1.4rem !important;
    color: var(--text-primary) !important;
    font-weight: 800 !important;
    width: auto !important; /* Shrink to fit (Key Fix) */
    max-width: 100%;
    display: inline-block !important; /* Behaves like text */
}

/* 4. Phone Number Specifics (Corrects order 0912...) */
#profileMobile {
    direction: ltr !important;
    unicode-bidi: embed !important;
    font-family: var(--font-main) !important; /* Ensure font consistency */
}

/* 5. Ensure Grid layouts don't stretch items weirdly */
.profile-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1px;
    background-color: var(--border-light);
    border-top: 1px solid var(--border-light);
}
/* Force Farsi Font on Profile Values */
#profileMobile, #profileUnit, #profileUsername {
    font-family: 'Vazirmatn', Tahoma, sans-serif !important;
    font-variant-numeric: tabular-nums; /* Aligns numbers nicely */
}

/* Ensure the grid lines are visible */
.profile-details-grid {
    gap: 1px;
    background-color: rgba(0,0,0,0.1); /* Darker line color */
    border-top: 1px solid rgba(0,0,0,0.1);
}

/* * ==========================================================================
 * 26. UNIFIED ACTION DIALOGS (CONFIRM/INFO)
 * Uses existing .modal structure but with smaller content card.
 * ==========================================================================
 */
.app-dialog-modal {
    /* Inherits fixed position and overlay backdrop from .modal (Section 14) */
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
}

.app-dialog-content {
    /* Overrides default large modal size to be smaller for dialogs */
    width: 100%;
    max-width: 380px !important; /* Smaller size for dialogs */
    min-height: 0;
    padding: 30px;
    text-align: center;
    /* Inherits border-radius, shadow, etc., from .modal-content (Section 14) */
}

.app-dialog-content h2 {
    font-size: var(--text-xl);
    font-weight: var(--fw-bold);
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.app-dialog-content p {
    font-size: var(--text-base);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
    line-height: var(--lh-base);
    padding: 0 var(--spacing-sm);
}

.app-dialog-content .close {
    /* Keep close button style, but slightly smaller for dialogs */
    width: 30px;
    height: 30px;
    font-size: 1.2rem;
    left: 15px;
    top: 15px;
}

.dialog-icon-container {
    font-size: 3rem;
    margin-bottom: 15px;
    line-height: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 50px;
}

.dialog-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: var(--spacing-lg);
}

.dialog-actions .btn {
    width: auto; /* Buttons should auto-size in the dialog */
    min-width: 120px;
}

/* --- Dialog States (Visual Feedback) --- */

/* Default/Info State */
.app-dialog-content.info .dialog-icon-container { color: var(--brand-accent); }
.app-dialog-content.info h2 { color: var(--brand-accent); }

/* Success State */
.app-dialog-content.success {
    border-top: 5px solid var(--status-success);
}
.app-dialog-content.success .dialog-icon-container { color: var(--status-success); }
.app-dialog-content.success h2 { color: var(--status-success); }

/* Warning State */
.app-dialog-content.warning {
    border-top: 5px solid var(--status-warning);
}
.app-dialog-content.warning .dialog-icon-container { color: var(--status-warning); }
.app-dialog-content.warning h2 { color: var(--status-warning); }
.app-dialog-content.warning #appDialogConfirmBtn {
    background: linear-gradient(135deg, var(--status-warning), #f0a30a);
    box-shadow: 0 4px 12px rgba(253, 203, 110, 0.5);
}

/* Error/Danger State */
.app-dialog-content.error {
    border-top: 5px solid var(--status-danger);
}
.app-dialog-content.error .dialog-icon-container { color: var(--status-danger); }
.app-dialog-content.error h2 { color: var(--status-danger); }
.app-dialog-content.error #appDialogConfirmBtn {
    background: linear-gradient(135deg, var(--status-danger), #b33939);
    box-shadow: 0 4px 12px rgba(214, 48, 49, 0.4);
}


/* Adjusting the existing floating toast system for unification */
/* The existing .notification-box styling is very custom, but I'll ensure it respects tokens */
.notification-box {
    /* ... existing styles ... */
    background: var(--bg-panel); /* Use panel color for consistency */
    color: var(--text-primary);
    border-right-color: transparent !important; /* Reset custom border */
    border: 1px solid var(--border-light);
    box-shadow: var(--elevation-3); /* Use existing shadow */
    transition: transform 0.4s var(--ease-bounce), opacity 0.3s;
}

/* Unified look for toast based on type */
.notification-box.success { border-right-color: var(--status-success) !important; color: var(--status-success); }
.notification-box.error { border-right-color: var(--status-danger) !important; color: var(--status-danger); }
.notification-box.info { border-right-color: var(--brand-accent) !important; color: var(--brand-accent); }
.notification-box.warning { border-right-color: var(--status-warning) !important; color: var(--status-warning); }

.notification-box.success::before,
.notification-box.error::before,
.notification-box.info::before,
.notification-box.warning::before {
    /* Use a consistent text primary color for the icon in toasts */
    color: var(--text-primary);
    font-weight: 900;
}
.notification-box.success::before { content: '✓'; color: var(--status-success); }
.notification-box.error::before { content: '✕'; color: var(--status-danger); }
.notification-box.info::before { content: 'ℹ'; color: var(--brand-accent); }
.notification-box.warning::before { content: '⚠'; color: var(--status-warning); }


/* Ensure the existing modal close button inherits the new color scheme */
.modal-content .close {
    background: var(--bg-element);
    color: var(--text-tertiary);
    border: 1px solid transparent;
}
.modal-content .close:hover {
    color: var(--status-danger);
    background: var(--bg-app);
    border-color: var(--status-danger);
}
/* ================================================================= */
/* === FIX: SCROLLABLE BOTTOM NAV FOR ADMIN/MANAGER              === */
/* ================================================================= */

@media (max-width: 768px) {
    .bottom-nav {
        /* تغییر چیدمان برای اسکرول */
        justify-content: flex-start; /* آیتم‌ها از ابتدای خط شروع شوند */
        overflow-x: auto;            /* فعال‌سازی اسکرول افقی */
        overflow-y: hidden;
        white-space: nowrap;         /* جلوگیری از شکستن خط */

        /* بهبود تجربه اسکرول در موبایل */
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory; /* توقف نرم روی آیتم‌ها */

        /* تنظیم پدینگ برای جلوگیری از چسبیدن اولین/آخرین آیتم */
        padding: 0 5px 5px 5px;
    }

    .nav-tab {
        /* جلوگیری از فشرده شدن دکمه‌ها */
        flex: 0 0 auto;              /* اندازه ثابت بگیرد و کوچک نشود */
        min-width: 75px;             /* حداقل عرض برای هر دکمه */
        width: auto;                 /* عرض بر اساس محتوا */
        padding: 5px 15px;           /* فضای کافی اطراف آیکون و متن */

        scroll-snap-align: start;    /* تراز شدن هنگام اسکرول */
    }

    /* مخفی کردن اسکرول‌بار برای زیبایی (در عین حال اسکرول کار می‌کند) */
    .bottom-nav::-webkit-scrollbar {
        display: none; /* برای کروم، سافاری و اپرا */
    }
    .bottom-nav {
        -ms-overflow-style: none;  /* برای IE و Edge */
        scrollbar-width: none;     /* برای فایرفاکس */
    }

    /* کوچک کردن متن‌ها برای جا شدن بهتر */
    .nav-tab span:not(.nav-icon) {
        font-size: 0.7rem;
        white-space: nowrap; /* متن در یک خط بماند */
    }

    .nav-tab .nav-icon {
        font-size: 1.3rem;
        margin-bottom: 4px;
        display: block; /* آیکون حتماً بالای متن باشد */
    }
}

/* * ==========================================================================
 * 27. BILLING & GENERIC CARDS (DARK MODE SUPPORT)
 * ==========================================================================
 */

.card {
    /* استفاده از !important برای نادیده گرفتن استایل‌های inline احتمالی در HTML */
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;

    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;

    /* استفاده از متغیرهای سایه و حاشیه برای هماهنگی با تم */
    box-shadow: var(--elevation-1);
    border: 1px solid var(--border-light);

    transition: background-color var(--duration-norm), border-color var(--duration-norm);
}

/* هاور روی کارت‌ها برای حس تعاملی بهتر */
.card:hover {
    box-shadow: var(--elevation-2);
    border-color: var(--border-medium);
}

/* اصلاح تیترهای داخل کارت */
.card h3 {
    color: var(--text-primary) !important;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
}

/* اصلاح جدول‌های داخل کارت قبض */
.card .history-table-container {
    background: transparent; /* حذف پس‌زمینه اضافه */
    box-shadow: none;        /* حذف سایه اضافه داخل کارت */
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
}

/* هدر جدول در حالت شب */
.card .history-table thead th {
    background-color: var(--bg-element);
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-light);
}

/* سلول‌های جدول */
.card .history-table td {
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

/* هاور روی ردیف‌های جدول */
.card .history-table tbody tr:hover {
    background-color: var(--bg-hover) !important;
}

/* متن‌های خالی (مثل "پروژه‌ای انتخاب نشده است") */
.card .history-table tbody tr td[colspan] {
    color: var(--text-tertiary);
    font-style: italic;
    background: transparent;
}

/* ورودی‌ها در صفحه قبض */
#billingPage .form-input {
    background-color: var(--bg-element);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
}

#billingPage .form-input:focus {
    background-color: var(--bg-panel);
    border-color: var(--brand-primary);
}

/* لیبل‌ها */
#billingPage .form-label {
    color: var(--text-secondary);
}

/* --- Professional Alert Cards (PAC) --- */
.pro-alert-card {
    background: white;
    border-radius: 12px;
    display: flex;
    overflow: hidden;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: all 0.2s ease;
    border: 1px solid #eee;
    cursor: pointer;
    position: relative;
}

.pro-alert-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.pro-alert-card.unread {
    background-color: #fffdf5; /* Light yellow tint for unread */
    border-left: 1px solid #e0e0e0;
}

/* Sidebar Color Coding */
.pac-sidebar { width: 6px; flex-shrink: 0; }
.severity-critical .pac-sidebar { background: #ff4757; }
.severity-warning .pac-sidebar { background: #ffa502; }
.severity-info .pac-sidebar { background: #1e90ff; }
.resolved .pac-sidebar { background: #2ed573; } /* Green for resolved */

.pac-content {
    flex-grow: 1;
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pac-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f1f2f6;
    padding-bottom: 8px;
}

.pac-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text-primary);
}

.pac-device-name { font-size: 1.05rem; }

.pac-unit-badge {
    background: #f1f2f6;
    color: #57606f;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
}

.pac-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pac-badge.new {
    background: #ff4757;
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    animation: pulse 2s infinite;
}

.pac-time {
    font-size: 0.8rem;
    color: #a4b0be;
    direction: ltr;
}

.pac-body {
    font-size: 0.95rem;
    color: #2f3542;
    line-height: 1.6;
}

.pac-footer {
    font-size: 0.8rem;
    color: #747d8c;
    margin-top: 5px;
    display: flex;
    justify-content: space-between;
}

.pac-details strong { color: var(--text-primary); }

/* --- Alert Filter Bar --- */
.alert-toolbar {
    background: white;
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 140px;
}

.toolbar-group label {
    font-size: 0.8rem;
    color: #747d8c;
    font-weight: 600;
}

.toolbar-select {
    padding: 8px;
    border: 1px solid #ced6e0;
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
}

/* Pagination */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
}

.btn-page {
    background: white;
    border: 1px solid #ced6e0;
    padding: 5px 15px;
    border-radius: 6px;
    cursor: pointer;
}
.btn-page:hover { background: #f1f2f6; }

.btn-action-text {
    background: none; border: none; color: var(--brand-primary);
    font-weight: 700; cursor: pointer; font-size: 0.9rem;
}
/* ==========================================================================
   DARK MODE FIXES FOR ALERTS TAB
   Add this to the end of style.css
   ========================================================================== */

/* 1. Filter Toolbar Fixes */
[data-theme="dark"] .alert-toolbar {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-light);
    box-shadow: var(--elevation-1);
}

[data-theme="dark"] .toolbar-group label {
    color: var(--text-secondary);
}

[data-theme="dark"] .toolbar-select {
    background-color: var(--bg-element);
    color: var(--text-primary);
    border-color: var(--border-light);
}

/* 2. Alert Card Container Fixes */
[data-theme="dark"] .pro-alert-card {
    background-color: var(--bg-panel);
    border-color: var(--border-light);
    box-shadow: var(--elevation-1);
}

/* 3. Alert Content Text Fixes */
[data-theme="dark"] .pac-title {
    color: var(--text-primary);
}

[data-theme="dark"] .pac-body {
    color: var(--text-secondary); /* Was hardcoded dark grey */
}

[data-theme="dark"] .pac-time {
    color: var(--text-tertiary);
    direction: ltr; /* Ensure time displays correctly */
}

[data-theme="dark"] .pac-footer {
    color: var(--text-tertiary);
}

[data-theme="dark"] .pac-details strong {
    color: var(--text-primary);
}

/* 4. Internal Borders & Badges */
[data-theme="dark"] .pac-header {
    border-bottom-color: var(--border-light);
}

[data-theme="dark"] .pac-unit-badge {
    background-color: var(--bg-element);
    color: var(--text-secondary);
}

/* 5. Unread State Fix (Subtle tint instead of bright yellow) */
[data-theme="dark"] .pro-alert-card.unread {
    background-color: var(--brand-primary-fade); /* Uses your brand fade variable */
    border-left-color: var(--brand-primary);
}

/* 6. Pagination Buttons Fix */
[data-theme="dark"] .btn-page {
    background-color: var(--bg-panel);
    color: var(--text-primary);
    border-color: var(--border-light);
}

[data-theme="dark"] .btn-page:hover {
    background-color: var(--bg-hover);
    border-color: var(--text-secondary);
}

/* --- Utility Tabs (Billing Page) --- */
.utility-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    min-height: 40px; /* Prevent layout jump */
}

.utility-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-element);
    border: 1px solid var(--border-light);
    border-radius: 20px; /* Pill shape */
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.utility-tab:hover {
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.utility-tab.active {
    background: var(--brand-primary);
    color: white;
    border-color: var(--brand-primary);
    box-shadow: 0 4px 10px var(--brand-primary-light);
}

/* Specific Utility Colors when active (Optional Override) */
.utility-tab.active[data-type="water"] { background: var(--data-water); border-color: var(--data-water); }
.utility-tab.active[data-type="electricity"] { background: var(--data-elec); border-color: var(--data-elec); color: #333; }
.utility-tab.active[data-type="gas"] { background: var(--data-gas); border-color: var(--data-gas); }
.utility-tab.active[data-type="heat"] { background: var(--data-heat); border-color: var(--data-heat); }

/* --- BATTERY HEALTH INDICATORS --- */

.device-status-icon {
    font-size: 1rem;
    margin-left: 5px;
    animation: fadeIn 0.5s ease;
}

.battery-low {
    color: #f1c40f; /* Yellow/Orange */
    text-shadow: 0 0 5px rgba(241, 196, 15, 0.4);
}

.battery-critical {
    color: #e74c3c; /* Red */
    animation: pulseCritical 1.5s infinite;
    text-shadow: 0 0 5px rgba(231, 76, 60, 0.4);
}

@keyframes pulseCritical {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.1); }
    100% { opacity: 1; transform: scale(1); }
}

/* Device Detail Page Status Text */
#deviceBatteryStatus {
    font-weight: 700;
}

#deviceBatteryStatus.status-ok {
    color: var(--status-success);
}

#deviceBatteryStatus.status-low {
    color: var(--status-warning);
}

#deviceBatteryStatus.status-critical {
    color: var(--status-danger);
    animation: shake 2s infinite;
}

/* Dark Mode Adjustments */
[data-theme="dark"] .battery-low {
    color: #ffd700;
}
[data-theme="dark"] .battery-critical {
    color: #ff6b6b;
}