/* ============================================
   ECOBUCK MONITOR - Professional Admin Theme
   ============================================ */

:root {
    --sidebar-bg: #1a1d2e;
    --sidebar-hover: #252840;
    --sidebar-active: #2d6ff7;
    --sidebar-text: #8b8fa3;
    --sidebar-text-active: #ffffff;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --topbar-height: 60px;
    --primary: #2d6ff7;
    --primary-dark: #1b4fd4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --bg-main: #f0f2f5;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
}

/* Login Page */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1d2e 0%, #2d3548 50%, #1a1d2e 100%);
    position: relative;
    overflow: hidden;
}

.login-wrapper::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 50%, rgba(45,111,247,0.08) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 50%, rgba(16,185,129,0.06) 0%, transparent 50%);
    animation: pulse 15s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.login-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 48px;
    width: 420px;
    max-width: 95vw;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
}

.login-card .logo-area {
    text-align: center;
    margin-bottom: 32px;
}

.login-card .logo-area img {
    height: 48px;
    margin-bottom: 16px;
}

.login-card .logo-area h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.login-card .logo-area p {
    color: var(--text-secondary);
    font-size: 13px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group .input-wrapper {
    position: relative;
}

.form-group .input-wrapper i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fafbfc;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45,111,247,0.1);
    background: #fff;
}

.btn-login {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    font-family: inherit;
}

.btn-login:hover { background: var(--primary-dark); }
.btn-login:active { transform: scale(0.99); }

.login-error {
    background: #fef2f2;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid #fecaca;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-muted);
}

/* App Wrapper */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: width 0.25s ease;
    overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed-width); }

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 16px 18px;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 64px;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
    background: white;
    padding: 2px;
    flex-shrink: 0;
}

.brand-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    white-space: nowrap;
}

.brand-name {
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

.brand-sub {
    color: var(--sidebar-text);
    font-size: 11px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: var(--radius);
    margin-bottom: 2px;
    transition: all 0.2s;
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
}

.nav-item i { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #c8cce0; }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-text-active); }

.nav-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 10px 14px;
}

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--sidebar-text);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px rgba(16,185,129,0.6);
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}

.sidebar.collapsed ~ .main-content { margin-left: var(--sidebar-collapsed-width); }

/* Top Navbar */
.top-navbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-toggle-sidebar {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.2s;
}

.btn-toggle-sidebar:hover { background: var(--bg-main); }

.page-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-item-top {
    position: relative;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 16px;
    transition: background 0.2s;
}

.nav-item-top:hover { background: var(--bg-main); }

.notification-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-dropdown {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: background 0.2s;
    position: relative;
}

.user-dropdown:hover { background: var(--bg-main); }

.user-avatar { font-size: 28px; color: var(--primary); }

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-role { font-size: 11px; color: var(--text-muted); }

.user-dropdown .fa-chevron-down {
    font-size: 10px;
    color: var(--text-muted);
}

.dropdown-menu-custom {
    position: absolute;
    top: 100%;
    right: 0;
    width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 200;
    margin-top: 8px;
}

.dropdown-header-custom {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.dropdown-header-custom strong { font-size: 14px; }
.dropdown-header-custom small { color: var(--text-muted); font-size: 12px; }

.dropdown-item-custom {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.15s;
    cursor: pointer;
    font-size: 13px;
}

.dropdown-item-custom:hover { background: var(--bg-main); }
.dropdown-item-custom i { width: 16px; color: var(--text-secondary); }

/* Page Content */
.page-content {
    flex: 1;
    padding: 24px;
}

/* Footer */
.app-footer {
    padding: 14px 24px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
}

.footer-version { font-weight: 500; }

/* ============================================
   COMPONENTS
   ============================================ */

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
}

.card-header h5 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header h5 i { color: var(--primary); }

.card-body { padding: 20px; }

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.kpi-icon.blue { background: rgba(45,111,247,0.1); color: var(--primary); }
.kpi-icon.green { background: rgba(16,185,129,0.1); color: var(--success); }
.kpi-icon.orange { background: rgba(245,158,11,0.1); color: var(--warning); }
.kpi-icon.red { background: rgba(239,68,68,0.1); color: var(--danger); }
.kpi-icon.cyan { background: rgba(6,182,212,0.1); color: var(--info); }
.kpi-icon.purple { background: rgba(139,92,246,0.1); color: #8b5cf6; }

.kpi-content { flex: 1; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 4px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.kpi-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.kpi-sub .trend-up { color: var(--success); }
.kpi-sub .trend-down { color: var(--danger); }

/* Charts */
.chart-container {
    position: relative;
    width: 100%;
    height: 300px;
}

.chart-container.tall { height: 400px; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 24px; }

@media (max-width: 1200px) {
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .sidebar { display: none; }
    .main-content { margin-left: 0 !important; }
}

/* Status badges */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-status.online { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-status.offline { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-status.warning { background: rgba(245,158,11,0.1); color: var(--warning); }
.badge-status.info { background: rgba(6,182,212,0.1); color: var(--info); }
.badge-status.conforme { background: rgba(16,185,129,0.08); color: var(--success); }

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Tables */
.table-modern {
    width: 100%;
    border-collapse: collapse;
}

.table-modern th {
    text-align: left;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border-color);
    background: #f8fafc;
}

.table-modern td {
    padding: 12px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.table-modern tr:hover td { background: #f8fafc; }
.table-modern tr:last-child td { border-bottom: none; }

/* Voltage display */
.voltage-display {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.voltage-phase {
    background: #f8fafc;
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.voltage-phase .phase-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 6px;
}

.voltage-phase .phase-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.voltage-phase .phase-unit {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Page headers */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Section spacing */
.section-gap { margin-bottom: 24px; }

/* Gauge-like display */
.gauge-value {
    text-align: center;
    padding: 20px;
}

.gauge-value .value {
    font-size: 36px;
    font-weight: 700;
    color: var(--primary);
}

.gauge-value .unit {
    font-size: 14px;
    color: var(--text-secondary);
}

.gauge-value .label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Info pairs */
.info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.info-row:last-child { border-bottom: none; }
.info-row .info-label { color: var(--text-secondary); font-weight: 500; }
.info-row .info-value { color: var(--text-primary); font-weight: 600; }

/* Tab-like buttons */
.tab-group {
    display: flex;
    gap: 4px;
    background: var(--bg-main);
    padding: 4px;
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.tab-btn.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.tab-btn:hover:not(.active) { color: var(--text-primary); }

/* Weather icons mapping */
.weather-icon { font-size: 24px; }

/* Readings comparison */
.reading-card {
    border-left: 4px solid var(--primary);
    background: #f8fafc;
    padding: 16px;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 12px;
}

.reading-card.after { border-left-color: var(--success); }

.reading-card .reading-date {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.reading-card .reading-values {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

.reading-card .rv-item .rv-label { font-size: 11px; color: var(--text-muted); }
.reading-card .rv-item .rv-value { font-size: 16px; font-weight: 700; }

/* Responsive sidebar */
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .sidebar-footer span:not(.status-dot) {
    display: none;
}

.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .nav-item i { font-size: 18px; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 16px 8px; }
.sidebar.collapsed .connection-status { justify-content: center; }

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-content > * { animation: fadeIn 0.3s ease; }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================
   Display Replica Cells
   ============================================ */
.display-cell {
    background: rgba(255,255,255,0.03);
    border: 1px solid #222;
    border-radius: 4px;
    padding: 5px 8px;
    text-align: center;
}
.display-label {
    font-size: 9px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
    font-family: 'Courier New', monospace;
}
.display-val {
    font-family: 'Courier New', monospace;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
}
.display-val.red { color: #ef4444; }
.display-val.green { color: #10b981; }
.display-val.yellow { color: #eab308; }
.display-val.cyan { color: #06b6d4; }

/* Print styles */
@media print {
    .sidebar, .top-navbar, .app-footer { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0; }
    .card { break-inside: avoid; }
}
