/* --- DECLARACIÓN DE VARIABLES Y RESPECTIVO COLOR --- */
:root {
    --bg-dark: #0a0e1a;
    --bg-panel: #151b2d;
    --bg-card: #1e293b;
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --success: #10b981;
    --success-light: #34d399;
    --error: #ef4444;
    --warning: #f59e0b;
    --purple: #8b5cf6;
    --cyan: #06b6d4;
    --text-main: #f1f5f9;
    --text-dim: #94a3b8;
    --border-color: #2d3748;
    --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --gradient-4: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 32px rgba(59, 130, 246, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 280px;
    background: rgba(21, 27, 45, 0.8);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255,255,255,0.05);
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.brand {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 48px;
    text-align: center;
    letter-spacing: 2px;
    text-transform: uppercase;
    filter: drop-shadow(0 0 20px rgba(59, 130, 246, 0.5));
}

.nav-btn {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    color: var(--text-dim);
    padding: 18px 24px;
    text-align: left;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 16px;
    margin-bottom: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    overflow: hidden;
}

.nav-btn::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 4px;
    background: var(--primary);
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-main);
    transform: translateX(8px);
    border-color: rgba(59, 130, 246, 0.3);
}

.nav-btn.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(139, 92, 246, 0.2) 100%);
    color: var(--text-main);
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.2);
}

.nav-btn.active::before {
    transform: scaleY(1);
}

.nav-btn span {
    font-size: 1.3rem;
    filter: drop-shadow(0 0 8px rgba(255,255,255,0.3));
}

/* --- MAIN CONTENT --- */
.main-content {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Scrollbar personalizada */
.main-content::-webkit-scrollbar { width: 8px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { 
    background: rgba(59, 130, 246, 0.3); 
    border-radius: 4px; 
}
.main-content::-webkit-scrollbar-thumb:hover { background: rgba(59, 130, 246, 0.5); }

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    padding: 24px 32px;
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    border: 1px solid rgba(255,255,255,0.05);
    box-shadow: var(--shadow-md);
}

h2 { 
    font-weight: 700; 
    font-size: 1.8rem;
    background: linear-gradient(135deg, var(--text-main) 0%, var(--text-dim) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(239, 68, 68, 0.1);
    padding: 12px 24px;
    border-radius: 50px;
    border: 1px solid rgba(239, 68, 68, 0.3);
    transition: all 0.3s ease;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--error);
    box-shadow: 0 0 20px var(--error);
    animation: pulse-red 2s infinite;
    transition: all 0.3s ease;
}

@keyframes pulse-red {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.1); }
}

.status-connected {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
}

.status-connected .status-dot { 
    background-color: var(--success); 
    box-shadow: 0 0 20px var(--success);
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.1); }
}

.status-text { 
    font-size: 0.9rem; 
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.status-connected .status-text { color: var(--success); }
.status-badge:not(.status-connected) .status-text { color: var(--error); }

/* --- VISTAS --- */
.view-section { 
    display: none; 
    animation: fadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.view-section.active { display: flex; flex-direction: column; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- CARDS --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.card {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(20px);
    padding: 32px;
    border-radius: 24px;
    border: 1px solid rgba(255,255,255,0.05);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 4px;
    background: var(--gradient-1);
    transform: scaleX(0);
    transition: transform 0.4s ease;
}

.card:nth-child(2)::before { background: var(--gradient-2); }
.card:nth-child(3)::before { background: var(--gradient-3); }
.card:nth-child(4)::before { background: var(--gradient-4); }

.card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    border-color: rgba(59, 130, 246, 0.3);
}

.card:hover::before {
    transform: scaleX(1);
}

.card-label { 
    color: var(--text-dim); 
    font-size: 0.85rem; 
    text-transform: uppercase; 
    letter-spacing: 2px; 
    margin-bottom: 12px;
    font-weight: 600;
}

.card-value { 
    font-size: 2.5rem; 
    font-weight: 800;
    background: linear-gradient(135deg, var(--text-main) 0%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* --- CAMERA PANEL PREMIUM --- */
.camera-panel {
    flex: 1;
    min-height: 400px;
    background: rgba(15, 23, 42, 0.8);
    border-radius: 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    border: 2px solid rgba(59, 130, 246, 0.2);
    overflow: hidden;
    box-shadow: 
        inset 0 0 80px rgba(0,0,0,0.5),
        0 0 40px rgba(59, 130, 246, 0.1);
}

.camera-panel::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(59, 130, 246, 0.03) 2px,
        rgba(59, 130, 246, 0.03) 4px
    );
    animation: scanline 8s linear infinite;
    pointer-events: none;
}

@keyframes scanline {
    0% { transform: translateY(0); }
    100% { transform: translateY(50%); }
}

.camera-placeholder {
    color: var(--text-dim);
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    z-index: 1;
    opacity: 0.6;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.detection-result {
    margin-top: 32px;
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary) 0%, var(--cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    z-index: 2;
    padding: 20px 48px;
    border-radius: 20px;
    background-color: rgba(59, 130, 246, 0.1);
    border: 2px solid rgba(59, 130, 246, 0.3);
    box-shadow: 0 0 40px rgba(59, 130, 246, 0.3);
    backdrop-filter: blur(10px);
}

/* --- ESTADÍSTICAS PREMIUM --- */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 32px;
}

.chart-card {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(20px);
    border-radius: 28px;
    padding: 32px;
    border: 1px solid rgba(255,255,255,0.05);
    box-shadow: var(--shadow-md);
    transition: all 0.4s ease;
}

.chart-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(59, 130, 246, 0.2);
}

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

.chart-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 28px;
    color: var(--text-main);
    padding-bottom: 16px;
    border-bottom: 2px solid rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chart-wrapper {
    position: relative;
    height: 320px;
    width: 100%;
}

/* Métricas en tiempo real premium */
.realtime-metrics {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-top: 32px;
}

.metric-box {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.8) 100%);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 20px;
    padding: 28px;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.metric-box::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(135deg, transparent 0%, rgba(59, 130, 246, 0.1) 100%);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.metric-box:hover {
    transform: translateY(-6px) scale(1.03);
    box-shadow: var(--shadow-lg), 0 0 40px rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.3);
}

.metric-box:hover::before {
    opacity: 1;
}

.metric-icon {
    font-size: 2.8rem;
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(139, 92, 246, 0.2) 100%);
    border-radius: 20px;
    border: 2px solid rgba(59, 130, 246, 0.3);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.2);
    z-index: 1;
}

.metric-info {
    flex: 1;
    z-index: 1;
}

.metric-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 600;
}

.metric-value {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--text-main) 0%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Botones premium */
.controls-area {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(20px);
    padding: 32px;
    border-radius: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(255,255,255,0.05);
    box-shadow: var(--shadow-md);
}

.btn-group { display: flex; gap: 16px; }

.btn {
    padding: 16px 32px;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font-weight: 700;
    color: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.btn::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.btn:hover:not(:disabled)::before {
    left: 100%;
}

.btn:hover:not(:disabled) { 
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.btn:active:not(:disabled) { 
    transform: translateY(-1px);
}

.btn:disabled { 
    opacity: 0.3; 
    cursor: not-allowed;
    filter: grayscale(1);
}

.btn-primary { 
    background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
}

.btn-success { 
    background: linear-gradient(135deg, var(--success) 0%, var(--success-light) 100%);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.btn-danger { 
    background: linear-gradient(135deg, var(--error) 0%, #dc2626 100%);
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
}

/* Console logs premium */
.logs-window {
    flex: 1;
    background: rgba(10, 14, 26, 0.8);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 20px;
    padding: 24px;
    font-family: 'Fira Code', 'Consolas', monospace;
    color: var(--text-main);
    overflow-y: auto;
    font-size: 0.9rem;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.5);
}

.log-entry { 
    margin-bottom: 12px; 
    padding: 12px 16px;
    background: rgba(255,255,255,0.02);
    border-radius: 12px;
    border-left: 3px solid var(--primary);
    transition: all 0.3s ease;
}

.log-entry:hover {
    background: rgba(255,255,255,0.05);
    transform: translateX(4px);
}

.log-time { 
    color: var(--primary); 
    margin-right: 12px; 
    font-weight: 700;
    font-size: 0.85rem;
}

/* ── Colores utilitarios ── */
.text-primary { color: var(--primary) !important; -webkit-text-fill-color: var(--primary) !important; }
.text-success  { color: var(--success) !important; -webkit-text-fill-color: var(--success) !important; }
.text-danger   { color: var(--error) !important;   -webkit-text-fill-color: var(--error) !important; }

/* ── Tarjetas de métricas del dashboard ── */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.metric-card {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 16px;
    padding: 20px 24px;
    box-shadow: var(--shadow-sm);
}
.metric-card .metric-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}
.metric-card .metric-value {
    font-size: 1.6rem;
    font-weight: 800;
}

/* ── Cámara en vivo ── */
.camera-panel {
    position: relative;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}
.camera-panel img#camera-feed {
    width: 100%;
    max-height: 460px;
    object-fit: contain;
    background: #000;
    display: block;
}
.detection-detail {
    font-size: 0.85rem;
    color: var(--text-dim);
    padding: 6px 0 12px;
    text-align: center;
}

/* ── Tarjeta educativa de residuo ── */
.eco-info-card {
    width: 100%;
    margin-top: 14px;
    padding: 18px 22px;
    border-radius: 18px;
    background: rgba(30, 41, 59, 0.95);
    border: 2px solid rgba(59, 130, 246, 0.35);
    display: flex;
    align-items: center;
    gap: 20px;
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-md);
    transition: border-color 0.4s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.caneca-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 12px;
    padding: 12px 16px;
    min-width: 170px;
    flex-shrink: 0;
    transition: background 0.4s ease, border-color 0.4s ease;
    border: 2px solid rgba(59, 130, 246, 0.4);
    background: rgba(59, 130, 246, 0.12);
}

.caneca-icon { font-size: 2rem; line-height: 1; }

.caneca-nombre {
    font-size: 1rem;
    font-weight: 800;
    color: var(--primary);
    transition: color 0.3s ease;
}

.caneca-subtitulo {
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 2px;
}

.eco-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.eco-fact {
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 500;
    line-height: 1.45;
}

.eco-tip {
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.4;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar { width: 80px; padding: 24px 12px; }
    .brand { font-size: 1.2rem; margin-bottom: 32px; }
    .nav-btn span { font-size: 1.5rem; }
    .nav-btn:not(.active) { justify-content: center; padding: 18px; }
    .nav-btn:not(.active) span:last-child { display: none; }
}

@media (max-width: 768px) {
    body { flex-direction: column; overflow: auto; }
    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        min-height: unset;
    }
    .brand { margin-bottom: 0; font-size: 1.3rem; }
    .nav-btn { margin-bottom: 0; padding: 10px 16px; font-size: 0.85rem; }
    .main-content { padding: 16px; }
    header { padding: 14px 16px; margin-bottom: 16px; }
    h2 { font-size: 1.2rem; }

    /* Métricas: 2 columnas en móvil */
    .metrics-row { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
    .metric-card { padding: 14px 16px; }
    .metric-card .metric-value { font-size: 1.3rem; }

    /* Cámara */
    .camera-panel { border-radius: 14px; }
    #cam-video { max-height: 280px; }
    .detection-result { font-size: 1.3rem; padding: 12px 24px; }

    /* Tarjeta educativa: vertical en móvil */
    .eco-info-card { flex-direction: column; gap: 12px; padding: 14px; }
    .caneca-indicator { min-width: unset; width: 100%; }

    /* Estadísticas */
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .stats-container { grid-template-columns: 1fr; }
    .chart-wrapper { height: 220px; }
    .controls-area { flex-direction: column; gap: 16px; }
    .realtime-metrics { grid-template-columns: 1fr 1fr; }
}