/* =========================================
   CONFIGURACIÓN DE VARIABLES Y TEMAS
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Tema Claro (Default) */
    --bg-light: #f4f7f6;
    --text-light: #2c3e50;
    --card-bg-light: #ffffff;
    --header-bg-light: #ffffff;
    --border-light: #e1e4e8;
    --shadow-light: rgba(0,0,0,0.05);
    
    /* Tema Oscuro */
    --bg-dark: #121212;
    --text-dark: #e0e0e0;
    --card-bg-dark: #1e1e1e;
    --header-bg-dark: #1e1e1e;
    --border-dark: #333;
    --shadow-dark: rgba(0,0,0,0.5);

    /* Semáforo de Estados */
    --status-active: #10b981;   /* Verde Esmeralda */
    --status-inactive: #ef4444; /* Rojo Vibrante */
    --status-warning: #f59e0b;  /* Ambar */
    --status-unknown: #6b7280;  /* Gris */

    /* Colores de Interfaz */
    --primary-color: #3b82f6;   /* Azul Real */
    --primary-hover: #2563eb;
    
    /* Inputs */
    --input-bg-light: #f9fafb;
    --input-border-light: #d1d5db;
    --input-focus-shadow: rgba(59, 130, 246, 0.25);
    --input-bg-dark: #27272a;
    --input-border-dark: #3f3f46;
}

/* RESET & BASE */
* { box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-light);
    margin: 0; padding: 0;
    transition: background-color 0.3s ease, color 0.3s ease;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* El scroll lo maneja el main */
    -webkit-tap-highlight-color: transparent; /* Mejora tactil en móviles */
}

/* --- MODO OSCURO --- */
body.dark-mode {
    background-color: var(--bg-dark);
    color: var(--text-dark);
}

/* =========================================
   LOGIN OVERLAY (PANTALLA DE BLOQUEO)
   ========================================= */
.login-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(244, 247, 246, 0.95); /* Fondo casi opaco */
    z-index: 9999;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.4s ease;
    backdrop-filter: blur(5px);
}
body.dark-mode .login-overlay { background-color: rgba(18, 18, 18, 0.95); }

.login-card {
    background: var(--card-bg-light);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    text-align: center;
    width: 90%; max-width: 400px;
    border: 1px solid var(--border-light);
}
body.dark-mode .login-card {
    background: var(--card-bg-dark);
    border-color: var(--border-dark);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.login-logo img { height: 60px; margin-bottom: 20px; }
.login-card h2 { margin: 0 0 10px; font-weight: 700; }
.login-card p { margin: 0 0 25px; color: #6b7280; font-size: 0.9em; }

.login-input {
    width: 100%; padding: 12px 15px; margin-bottom: 20px;
    border: 1px solid var(--input-border-light); border-radius: 8px;
    font-size: 1em; text-align: center;
}
body.dark-mode .login-input {
    background: var(--input-bg-dark); border-color: var(--input-border-dark); color: white;
}
.login-btn {
    width: 100%; padding: 12px; background: var(--primary-color);
    color: white; border: none; border-radius: 8px; font-weight: 600; font-size: 1em;
    cursor: pointer; transition: background 0.2s;
}
.login-btn:hover { background: var(--primary-hover); }
.login-btn:disabled { opacity: 0.7; cursor: wait; }

.login-error { color: var(--status-inactive); font-size: 0.9em; margin-top: 15px; font-weight: 600; }

/* =========================================
   HEADER
   ========================================= */
header {
    position: relative; flex-shrink: 0; width: 100%; z-index: 100; 
    background-color: var(--header-bg-light); 
    padding: 12px 20px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border-light);
}
body.dark-mode header {
    background-color: var(--header-bg-dark);
    border-color: var(--border-dark);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
}

.header-left { display: flex; align-items: center; gap: 15px; }
.van-logo { height: 35px; width: auto; }
header h1 { margin: 0; font-size: 1.2em; font-weight: 700; }

.header-right { display: flex; align-items: center; gap: 10px; }

/* Botones del Header */
.header-action-btn {
    padding: 8px 14px; border-radius: 8px; border: none; cursor: pointer;
    font-weight: 600; font-size: 0.85em;
    display: flex; align-items: center; gap: 8px;
    background-color: var(--primary-color); color: white;
    transition: transform 0.1s, opacity 0.2s;
}
.header-action-btn:active { transform: scale(0.96); }

/* Filtro */
.filter-group select {
    padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border-light);
    background: var(--bg-light); color: var(--text-light); cursor: pointer;
}
body.dark-mode .filter-group select {
    background: var(--input-bg-dark); border-color: var(--input-border-dark); color: white;
}

#theme-toggle {
    background: transparent; border: none; font-size: 1.2em; cursor: pointer; color: #6b7280;
    padding: 8px; border-radius: 50%;
}
body.dark-mode #theme-toggle { color: #fbbf24; }

/* Spinner */
.spinner {
    border: 3px solid rgba(0,0,0,0.1); border-left-color: var(--primary-color);
    border-radius: 50%; width: 20px; height: 20px;
    animation: spin 1s linear infinite; margin-left: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   CONTENIDO PRINCIPAL
   ========================================= */
main { flex-grow: 1; overflow-y: auto; padding: 20px; width: 100%; }
.content-container { max-width: 1400px; margin: 0 auto; padding-bottom: 40px; }

.global-error {
    background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5;
    padding: 10px; margin-bottom: 20px; border-radius: 8px; text-align: center;
}

/* Secciones */
.service-section h2 {
    font-size: 1.2em; border-bottom: 2px solid var(--border-light);
    padding-bottom: 8px; margin-bottom: 15px; font-weight: 700;
}
body.dark-mode .service-section h2 { border-color: var(--border-dark); }

.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

/* =========================================
   TARJETAS (CARDS)
   ========================================= */
.status-card {
    background-color: var(--card-bg-light);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--border-light);
    display: flex; overflow: hidden; position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}
body.dark-mode .status-card {
    background-color: var(--card-bg-dark); border-color: var(--border-dark);
}
.status-card:hover { transform: translateY(-2px); box-shadow: 0 8px 15px rgba(0,0,0,0.1); }

/* Barra de estado lateral */
.status-bar { width: 6px; flex-shrink: 0; }
.status-card.active .status-bar { background-color: var(--status-active); }
.status-card.inactive .status-bar { background-color: var(--status-inactive); }
.status-card.unknown .status-bar { background-color: var(--status-unknown); }

.card-content { padding: 15px; flex-grow: 1; display: flex; flex-direction: column; }

.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.header-title-box { display: flex; align-items: center; gap: 10px; }
.card-icon { font-size: 1.4em; color: var(--primary-color); }
body.dark-mode .card-icon { color: #60a5fa; }
.card-header h3 { margin: 0; font-size: 1em; font-weight: 700; }

.card-description { font-size: 0.85em; color: #6b7280; margin: 0 0 15px 0; line-height: 1.4; flex-grow: 1; }
body.dark-mode .card-description { color: #9ca3af; }

/* Botones Editar/Borrar (Ocultos hasta hover en PC) */
.header-actions { display: flex; gap: 5px; opacity: 1; } 
@media (min-width: 768px) { .header-actions { opacity: 0; transition: opacity 0.2s; } .status-card:hover .header-actions { opacity: 1; } }

.delete-service-btn, .edit-service-btn {
    background: transparent; border: none; cursor: pointer; color: #9ca3af; padding: 4px;
}
.delete-service-btn:hover { color: var(--status-inactive); }
.edit-service-btn:hover { color: var(--primary-color); }
.mute-icon { color: #f59e0b; padding-right: 5px; }

/* Barras de Rendimiento */
.performance-stats { margin-bottom: 10px; font-size: 0.75em; }
.stat-row { display: flex; align-items: center; margin-bottom: 4px; }
.stat-label { width: 35px; font-weight: 600; }
.progress-track { flex-grow: 1; height: 5px; background: #e5e7eb; border-radius: 10px; margin: 0 8px; overflow: hidden; }
body.dark-mode .progress-track { background: #374151; }
.progress-bar { height: 100%; border-radius: 10px; }

.bg-success { background-color: var(--status-active); }
.bg-warning { background-color: var(--status-warning); }
.bg-danger { background-color: var(--status-inactive); }

/* Detalles Footer */
.card-footer {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border-light);
    font-size: 0.8em;
}
body.dark-mode .card-footer { border-color: var(--border-dark); }

.badge { padding: 3px 8px; border-radius: 12px; font-weight: 700; color: white; font-size: 0.8em; }
.badge.active { background-color: var(--status-active); }
.badge.inactive { background-color: var(--status-inactive); }
.badge.unknown { background-color: var(--status-unknown); }

.latency-value.green { color: var(--status-active); }
.latency-value.yellow { color: var(--status-warning); }
.latency-value.red { color: var(--status-inactive); }

/* Overrides para estados críticos */
.status-card.inactive { border-color: var(--status-inactive); box-shadow: 0 4px 12px rgba(239,68,68,0.1); }
.status-card.inactive .card-icon { color: var(--status-inactive); }

/* =========================================
   MODALES Y FORMULARIOS
   ========================================= */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    z-index: 2000; display: none; justify-content: center; align-items: center;
    opacity: 0; transition: opacity 0.3s;
}
.modal-overlay.active { opacity: 1; }

.modal-card {
    background: var(--card-bg-light); width: 95%; max-width: 600px; max-height: 90vh;
    border-radius: 16px; display: flex; flex-direction: column;
    box-shadow: 0 20px 25px rgba(0,0,0,0.2);
}
body.dark-mode .modal-card { background: #1f2937; color: white; }

.modal-header {
    padding: 15px 20px; border-bottom: 1px solid var(--border-light);
    display: flex; justify-content: space-between; align-items: center;
}
body.dark-mode .modal-header { border-color: var(--border-dark); }

.close-x-btn { background: none; border: none; font-size: 1.5em; cursor: pointer; color: #9ca3af; }

.admin-form { display: flex; flex-direction: column; overflow: hidden; flex-grow: 1; }
.form-scroll-area { padding: 20px; overflow-y: auto; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 15px; }
.form-group { display: flex; flex-direction: column; margin-bottom: 15px; }
.form-group.full-width { grid-column: span 2; }
.form-group label { font-size: 0.8em; font-weight: 700; margin-bottom: 5px; text-transform: uppercase; color: #6b7280; }

.form-group input, .form-group select {
    padding: 10px; border: 1px solid var(--border-light); border-radius: 8px;
    background: white; color: var(--text-light);
}
body.dark-mode .form-group input, body.dark-mode .form-group select {
    background: #374151; border-color: #4b5563; color: white;
}

.form-actions {
    padding: 15px 20px; background: var(--bg-light);
    border-top: 1px solid var(--border-light);
    display: flex; justify-content: flex-end; gap: 10px;
}
body.dark-mode .form-actions { background: #111827; border-color: var(--border-dark); }

.submit-btn { background: var(--status-active); color: white; padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; }
.cancel-btn { background: transparent; border: 1px solid #d1d5db; padding: 10px 20px; border-radius: 8px; cursor: pointer; color: #4b5563; }
body.dark-mode .cancel-btn { color: white; border-color: #4b5563; }

/* TOGGLE SWITCH (Notificaciones) */
.notification-toggle-container {
    display: flex; align-items: center; gap: 10px; margin-bottom: 20px;
    padding: 10px; background: rgba(0,0,0,0.03); border-radius: 8px;
}
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 24px;
}
.slider:before {
    position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px;
    background-color: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--status-active); }
input:checked + .slider:before { transform: translateX(20px); }

/* =========================================
   LOGS VIEW
   ========================================= */
.logs-list-container {
    background: var(--card-bg-light); border: 1px solid var(--border-light);
    border-radius: 8px; height: 60vh; overflow-y: auto;
}
body.dark-mode .logs-list-container { background: var(--card-bg-dark); border-color: var(--border-dark); }

.log-entry {
    padding: 10px 15px; border-bottom: 1px solid var(--border-light);
    font-size: 0.85em; display: grid; grid-template-columns: 140px 100px 1fr; gap: 10px; align-items: center;
}
body.dark-mode .log-entry { border-color: var(--border-dark); }

.log-action { padding: 2px 6px; border-radius: 4px; font-weight: 700; text-align: center; }
.action-down { background: #fee2e2; color: #b91c1c; }
.action-up { background: #d1e7dd; color: #0f5132; }

/* =========================================
   RESPONSIVE (MOVIL)
   ========================================= */
@media (max-width: 768px) {
    header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .header-right { width: 100%; justify-content: space-between; }
    .form-grid { grid-template-columns: 1fr; }
    .form-group.full-width { grid-column: span 1; }
    .services-grid { grid-template-columns: 1fr; }
    
    .log-entry { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
}