/* =====================================================
   EnergyMonitor - Premium Dark Theme CSS
   ===================================================== */

/* ── Variables ── */
:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #0f1629;
    --bg-card: #141b2d;
    --bg-card-hover: #1a2340;
    --bg-surface: #1e2842;
    --bg-input: #1a2340;

    --text-primary: #e8eaed;
    --text-secondary: #8b95a5;
    --text-muted: #5c6678;
    --text-heading: #ffffff;

    --accent-primary: #3b82f6;
    --accent-primary-glow: rgba(59, 130, 246, 0.3);
    --accent-green: #10b981;
    --accent-green-glow: rgba(16, 185, 129, 0.3);
    --accent-amber: #f59e0b;
    --accent-amber-glow: rgba(245, 158, 11, 0.3);
    --accent-red: #ef4444;
    --accent-red-glow: rgba(239, 68, 68, 0.3);
    --accent-purple: #8b5cf6;
    --accent-purple-glow: rgba(139, 92, 246, 0.3);
    --accent-cyan: #06b6d4;
    --accent-cyan-glow: rgba(6, 182, 212, 0.3);

    --border-color: rgba(255,255,255,0.06);
    --border-active: rgba(59,130,246,0.4);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 20px rgba(59,130,246,0.15);

    --sidebar-width: 260px;
    --topbar-height: 60px;

    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

a { color: var(--accent-primary); text-decoration: none; }
a:hover { color: #60a5fa; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* =====================================================
   AUTH PAGES (Login / Register)
   ===================================================== */
.auth-body {
    background: var(--bg-primary);
    min-height: 100vh;
}

.auth-container {
    display: flex;
    min-height: 100vh;
}

/* Hero Panel */
.auth-hero {
    flex: 0 0 45%;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.auth-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        radial-gradient(circle at 20% 30%, var(--accent-primary-glow) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, var(--accent-cyan-glow) 0%, transparent 50%);
    animation: heroGlow 8s ease-in-out infinite alternate;
}

@keyframes heroGlow {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

.hero-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 2rem;
}

.hero-icon-group { margin-bottom: 2rem; }

.hero-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-cyan));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
}

.pulse-glow {
    animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 20px var(--accent-primary-glow); }
    50% { box-shadow: 0 0 50px var(--accent-primary-glow), 0 0 80px var(--accent-cyan-glow); }
}

.hero-content h1 {
    font-size: 2.5rem;
    font-weight: 800;
    color: white;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

.hero-content p {
    color: rgba(255,255,255,0.7);
    font-size: 1.05rem;
    max-width: 320px;
    margin: 0 auto 2rem;
}

.hero-features {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    max-width: 280px;
    margin: 0 auto;
}

.hero-feature {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.08);
    transition: var(--transition);
}

.hero-feature:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.15);
}

.hero-feature i {
    color: var(--accent-primary);
    font-size: 0.9rem;
    width: 20px;
    text-align: center;
}

.hero-feature span {
    color: rgba(255,255,255,0.8);
    font-size: 0.88rem;
}

.hero-stats {
    display: flex;
    gap: 2rem;
    margin-top: 2rem;
    justify-content: center;
}

.hero-stat {
    text-align: center;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--accent-primary);
    font-family: var(--font-mono);
}

.stat-label {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Form Panel */
.auth-form-panel {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--bg-secondary);
}

.auth-form-wrapper {
    width: 100%;
    max-width: 440px;
}

.mobile-logo {
    display: none;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.mobile-logo i { font-size: 1.3rem; }

.auth-form-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-heading);
    margin-bottom: 0.25rem;
}

.auth-form-header p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.92rem;
}

/* Form Elements */
.auth-form { display: flex; flex-direction: column; gap: 1.1rem; }

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group .optional {
    font-weight: 400;
    text-transform: none;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.input-group {
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: var(--transition);
    overflow: hidden;
}

.input-group:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-glow);
}

.input-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    color: var(--text-muted);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.input-group input,
.form-group input:not([type="checkbox"]),
.form-group select {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    padding: 0.75rem 0.75rem 0.75rem 0;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
}

.form-group input:not(.input-group input):not([type="checkbox"]) {
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    transition: var(--transition);
}

.form-group input:not(.input-group input):focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-glow);
}

.form-group select {
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    width: 100%;
    cursor: pointer;
    transition: var(--transition);
}

.form-group select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-glow);
}

input::placeholder { color: var(--text-muted); }

.toggle-password {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 12px;
    font-size: 0.9rem;
    transition: var(--transition);
}

.toggle-password:hover { color: var(--accent-primary); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-input);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.checkbox-label input[type="checkbox"]:checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.checkbox-label input[type="checkbox"]:checked::after {
    content: '✓';
    display: block;
    text-align: center;
    color: white;
    font-size: 0.7rem;
    line-height: 14px;
}

.btn-primary-auth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--accent-primary), #2563eb);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.85rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 0.5rem;
}

.btn-primary-auth:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px var(--accent-primary-glow);
}

.btn-primary-auth:active { transform: translateY(0); }

.auth-footer {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-footer a {
    font-weight: 600;
    color: var(--accent-primary);
}

/* Alerts */
.alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    margin-bottom: 0.5rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.alert-danger {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    color: #fca5a5;
}

.alert-success {
    background: rgba(16,185,129,0.1);
    border: 1px solid rgba(16,185,129,0.2);
    color: #6ee7b7;
}

.alert-warning {
    background: rgba(245,158,11,0.1);
    border: 1px solid rgba(245,158,11,0.2);
    color: #fcd34d;
}

/* =====================================================
   APP LAYOUT (Dashboard / Settings)
   ===================================================== */
.energy-body { background: var(--bg-primary); min-height: 100vh; }

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    text-decoration: none;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-cyan));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: white;
}

.logo-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.3px;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.nav-section { margin-bottom: 1.25rem; }

.nav-section-title {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 2px;
}

.nav-link:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(59,130,246,0.15), rgba(6,182,212,0.1));
    color: var(--accent-primary);
    border: 1px solid rgba(59,130,246,0.2);
}

.nav-link i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
}

.sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid var(--border-color);
}

.user-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.user-email {
    font-size: 0.72rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--accent-red);
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
}

.logout-btn:hover {
    background: rgba(239,68,68,0.1);
    color: var(--accent-red);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.breadcrumb-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.breadcrumb-icon { color: var(--accent-primary); }
.breadcrumb-separator { color: var(--text-muted); }
.breadcrumb-current { color: var(--text-primary); font-weight: 600; }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.device-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.9rem;
    background: var(--bg-card);
    border-radius: 100px;
    border: 1px solid var(--border-color);
    font-size: 0.8rem;
}

.device-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: var(--transition);
}

.device-dot.online {
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green-glow);
    animation: dotPulse 2s infinite;
}

.device-dot.offline {
    background: var(--accent-red);
}

@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.device-label { color: var(--text-secondary); }

.page-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

/* =====================================================
   DASHBOARD
   ===================================================== */

/* Device Status Banner */
.device-status-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    transition: var(--transition);
}

.device-status-banner.online {
    background: rgba(16,185,129,0.08);
    border: 1px solid rgba(16,185,129,0.2);
}

.device-status-banner.offline {
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.2);
}

.banner-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.status-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.device-status-banner.online .status-pulse {
    background: var(--accent-green);
    animation: dotPulse 2s infinite;
}

.device-status-banner.offline .status-pulse {
    background: var(--accent-red);
}

.status-text { color: var(--text-secondary); }
.status-text strong { color: var(--text-primary); }

.relay-badge {
    padding: 0.3rem 0.7rem;
    border-radius: 100px;
    font-size: 0.78rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.relay-badge.ON {
    background: rgba(16,185,129,0.15);
    color: var(--accent-green);
    border: 1px solid rgba(16,185,129,0.3);
}

.relay-badge.OFF {
    background: rgba(239,68,68,0.15);
    color: var(--accent-red);
    border: 1px solid rgba(239,68,68,0.3);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.1rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    opacity: 0;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--border-active);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.stat-card:hover::before { opacity: 1; }

.stat-card.highlight {
    border-color: rgba(59,130,246,0.3);
    background: linear-gradient(180deg, rgba(59,130,246,0.08) 0%, var(--bg-card) 100%);
}

.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.stat-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.stat-icon.voltage { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.stat-icon.current { background: rgba(6,182,212,0.15); color: var(--accent-cyan); }
.stat-icon.power { background: rgba(59,130,246,0.15); color: var(--accent-primary); }
.stat-icon.energy { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.stat-icon.frequency { background: rgba(139,92,246,0.15); color: var(--accent-purple); }
.stat-icon.pf { background: rgba(236,72,153,0.15); color: #ec4899; }

.stat-card#cardVoltage::before { background: var(--accent-amber); }
.stat-card#cardCurrent::before { background: var(--accent-cyan); }
.stat-card#cardPower::before { background: var(--accent-primary); }
.stat-card#cardEnergy::before { background: var(--accent-green); }
.stat-card#cardFrequency::before { background: var(--accent-purple); }
.stat-card#cardPF::before { background: #ec4899; }

.stat-value-group {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
    margin-bottom: 0.2rem;
}

.stat-main-value {
    font-size: 1.6rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-heading);
    letter-spacing: -0.5px;
}

.stat-unit {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.stat-card .stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-trend {
    font-size: 0.72rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.stat-trend.up { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.stat-trend.down { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.stat-trend.neutral { background: rgba(255,255,255,0.05); color: var(--text-muted); }

/* Cost Summary */
.cost-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.cost-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.2rem;
    transition: var(--transition);
}

.cost-card:hover {
    border-color: var(--border-active);
}

.cost-card-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cost-info { flex: 1; }

.cost-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    display: block;
}

.cost-values { display: flex; flex-direction: column; }

.cost-energy {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.cost-money {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-heading);
    font-family: var(--font-mono);
}

.cost-icon-wrap {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.cost-icon-wrap.today { background: rgba(59,130,246,0.12); color: var(--accent-primary); }
.cost-icon-wrap.month { background: rgba(139,92,246,0.12); color: var(--accent-purple); }
.cost-icon-wrap.rate { background: rgba(16,185,129,0.12); color: var(--accent-green); }

.cost-diff {
    margin-top: 0.75rem;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-color);
}

.cost-diff.up { color: var(--accent-red); }
.cost-diff.down { color: var(--accent-green); }

.cost-action {
    display: block;
    margin-top: 0.75rem;
    font-size: 0.78rem;
    color: var(--accent-primary);
    font-weight: 500;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-color);
}

.cost-action:hover { color: #60a5fa; }

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.2rem;
}

.chart-card.main-chart {
    grid-column: 1 / -1;
}

.chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chart-title-group h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 0.15rem;
}

.chart-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chart-controls {
    display: flex;
    gap: 0.3rem;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    padding: 0.2rem;
}

.chart-period-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.35rem 0.7rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font-body);
}

.chart-period-btn:hover { color: var(--text-primary); }

.chart-period-btn.active {
    background: var(--accent-primary);
    color: white;
}

.chart-wrapper {
    position: relative;
    height: 280px;
}

.chart-card.secondary-chart .chart-wrapper {
    height: 220px;
}

/* =====================================================
   SETTINGS PAGE
   ===================================================== */
.settings-page { max-width: 1100px; }

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-heading);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.page-header h1 i { color: var(--accent-primary); font-size: 1.2rem; }

.page-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-title-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.section-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.section-icon.tariff { background: rgba(16,185,129,0.12); color: var(--accent-green); }
.section-icon.device { background: rgba(59,130,246,0.12); color: var(--accent-primary); }

.section-title-group h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 0.15rem;
}

.section-title-group p {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.btn-action {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-action:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-primary-glow);
}

/* Active Tariff Card */
.active-tariff-card {
    background: linear-gradient(135deg, rgba(16,185,129,0.08) 0%, rgba(6,182,212,0.05) 100%);
    border: 1px solid rgba(16,185,129,0.2);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    position: relative;
}

.tariff-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: rgba(16,185,129,0.2);
    color: var(--accent-green);
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.tariff-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.tariff-rate {
    display: flex;
    align-items: baseline;
    gap: 0.25rem;
}

.rate-symbol {
    font-size: 1.2rem;
    color: var(--accent-green);
    font-weight: 600;
}

.rate-value {
    font-size: 2.2rem;
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--text-heading);
    letter-spacing: -1px;
}

.rate-unit {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-left: 0.3rem;
}

.tariff-dates {
    display: flex;
    gap: 1.5rem;
    margin-top: 0.75rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.tariff-dates i { color: var(--accent-primary); margin-right: 0.25rem; }

/* Tariff List */
.tariff-list { margin-top: 1rem; }

.list-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
}

.tariff-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.tariff-item:last-child { border-bottom: none; }

.tariff-item-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.tariff-item-name {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

.tariff-item-rate {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.badge-active {
    padding: 0.15rem 0.5rem;
    background: rgba(16,185,129,0.15);
    color: var(--accent-green);
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 600;
}

.tariff-item-actions {
    display: flex;
    gap: 0.3rem;
    align-items: center;
}

.inline-form { display: inline; }

.btn-icon {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    transition: var(--transition);
}

.btn-icon.edit:hover {
    background: rgba(59,130,246,0.1);
    color: var(--accent-primary);
    border-color: rgba(59,130,246,0.3);
}

.btn-icon.delete:hover {
    background: rgba(239,68,68,0.1);
    color: var(--accent-red);
    border-color: rgba(239,68,68,0.3);
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    color: var(--accent-amber);
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}

.empty-state p {
    font-size: 0.85rem;
}

/* API Key Card */
.api-key-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.api-key-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.api-key-header h3 {
    font-size: 0.95rem;
    color: var(--text-heading);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.api-key-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.api-key-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.75rem;
}

.api-key-display code {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--accent-amber);
    word-break: break-all;
}

.btn-copy {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    width: 34px;
    height: 34px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-copy:hover {
    background: rgba(59,130,246,0.1);
    color: var(--accent-primary);
}

.api-key-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.api-endpoint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.endpoint-label { font-weight: 600; }

.api-endpoint code {
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    font-size: 0.75rem;
}

.btn-warning-small {
    background: rgba(245,158,11,0.1);
    border: 1px solid rgba(245,158,11,0.2);
    color: var(--accent-amber);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-warning-small:hover {
    background: rgba(245,158,11,0.2);
}

/* Device Form */
.device-form { margin-bottom: 1.5rem; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.form-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    display: block;
}

.btn-primary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn-secondary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

/* Code Example */
.code-example {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.code-example h3 {
    font-size: 0.95rem;
    color: var(--text-heading);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.code-example h3 i { color: var(--accent-primary); }

.code-example p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.code-example p code {
    font-family: var(--font-mono);
    color: var(--accent-amber);
    font-size: 0.8rem;
}

.code-example pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow-x: auto;
}

.code-example pre code {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--accent-green);
    white-space: pre;
    line-height: 1.7;
}

/* =====================================================
   MODALS
   ===================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s;
}

.modal-overlay.show .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.05rem;
    color: var(--text-heading);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-header h3 i { color: var(--accent-primary); }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    transition: var(--transition);
}

.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 992px) {
    .charts-grid { grid-template-columns: 1fr; }
    .cost-summary-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close { display: block; }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: all;
    }

    .main-content {
        margin-left: 0;
    }

    .menu-toggle { display: flex; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }

    .form-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }

    .auth-hero { display: none; }
    .mobile-logo { display: flex; }

    .device-status-banner {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-main-value { font-size: 1.3rem; }
    .page-content { padding: 1rem; }
    .section-header { flex-direction: column; align-items: flex-start; }
}

/* =====================================================
   ANIMATIONS
   ===================================================== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.stat-card { animation: fadeInUp 0.5s ease backwards; }
.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.2s; }
.stat-card:nth-child(5) { animation-delay: 0.25s; }
.stat-card:nth-child(6) { animation-delay: 0.3s; }

.cost-card { animation: fadeInUp 0.5s ease backwards; }
.cost-card:nth-child(1) { animation-delay: 0.35s; }
.cost-card:nth-child(2) { animation-delay: 0.4s; }
.cost-card:nth-child(3) { animation-delay: 0.45s; }

.chart-card { animation: fadeInUp 0.5s ease backwards; animation-delay: 0.5s; }

/* Stat value update flash */
.stat-main-value.updated {
    animation: valuePulse 0.4s ease;
}

@keyframes valuePulse {
    0% { color: var(--accent-primary); text-shadow: 0 0 10px var(--accent-primary-glow); }
    100% { color: var(--text-heading); text-shadow: none; }
}

/* =====================================================
   RELAY TOGGLE & MODAL
   ===================================================== */
.relay-toggle-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.2rem 0.5rem;
}

.relay-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.relay-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.relay-switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.relay-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-card-hover);
    border: 1px solid var(--text-muted);
    transition: .4s;
    border-radius: 24px;
}

.relay-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: .4s;
    border-radius: 50%;
}

input:checked + .relay-slider {
    background-color: rgba(16, 185, 129, 0.2);
    border-color: var(--accent-green);
}

input:checked + .relay-slider:before {
    transform: translateX(22px);
    background-color: var(--accent-green);
    box-shadow: 0 0 10px var(--accent-green-glow);
}

.relay-status-text {
    font-size: 0.8rem;
    font-weight: 700;
}
.relay-status-text.ON { color: var(--accent-green); }
.relay-status-text.OFF { color: var(--text-muted); }

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(10, 14, 26, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    width: 90%;
    max-width: 400px;
    padding: 1.5rem;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal-box {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-heading);
}

.modal-icon {
    font-size: 1.5rem;
}
.warning-icon { color: var(--accent-amber); }
.danger-icon { color: var(--accent-red); }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-align: center;
}

.modal-body .text-danger {
    color: var(--accent-red);
    font-weight: 600;
    margin-bottom: 1.5rem;
}

/* Swipe to Confirm */
.swipe-container {
    width: 100%;
    height: 50px;
    background: var(--bg-surface);
    border-radius: 25px;
    position: relative;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.swipe-track {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.swipe-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    user-select: none;
    pointer-events: none;
    animation: swipePulse 2s infinite;
}

@keyframes swipePulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.swipe-button {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-cyan));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1rem;
    cursor: grab;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    z-index: 2;
    transition: background 0.3s;
}
.swipe-button:active { cursor: grabbing; }

.swipe-button.danger-mode {
    background: linear-gradient(135deg, var(--accent-red), #b91c1c);
}
