/**
 * Estilos para Modales Administrativos: Monitor MQTT y Heartbeat
 * Archivo: css/adminModales.css
 */

/* Contenedor de acciones admin en el header */
.admin-barra-acciones {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-admin-nav {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}

.btn-admin-nav:hover {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-admin-nav svg {
    color: #4fc3f7;
}

#btn-admin-heartbeat svg {
    color: #ff5252;
}

/* Backdrop de los modales */
.modal-admin-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    padding: 20px;
    box-sizing: border-box;
}

.modal-admin-backdrop.activo {
    opacity: 1;
    visibility: visible;
}

/* Diálogo del modal */
.modal-admin-dialog {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 1100px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(226, 232, 240, 0.8);
}

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

/* Encabezado */
.modal-admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.modal-admin-titulo-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-admin-icono {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #e0f2fe;
    color: #0284c7;
}

.modal-icono-hb {
    background: #fee2e2;
    color: #dc2626;
}

.modal-admin-titulo-wrapper h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
}

.modal-subtitulo {
    margin: 2px 0 0 0;
    font-size: 12px;
    color: #64748b;
}

.btn-cerrar-admin-modal {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.btn-cerrar-admin-modal:hover {
    background: #f1f5f9;
    color: #0f172a;
}

/* Tarjetas KPI */
.mqtt-kpi-bar, .hb-kpi-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    padding: 16px 24px;
    background: #ffffff;
    border-bottom: 1px solid #f1f5f9;
}

.kpi-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kpi-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    font-weight: 600;
}

.kpi-value {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
}

.kpi-fecha {
    font-size: 13px;
    color: #334155;
    font-weight: 600;
}

.kpi-online {
    color: #16a34a;
}

.kpi-offline {
    color: #dc2626;
}

/* Sistema Canónico de Badges de Estado */
.badge-estado,
.badge-estado-online,
.badge-estado-offline,
.badge-online,
.badge-offline {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: var(--radius-pill, 9999px);
    font-size: var(--text-xs, 12px);
    font-weight: 600;
    line-height: 1.2;
}

.badge-estado--online,
.badge-estado-online,
.badge-online {
    background: var(--color-success-050, #f0fdf4);
    color: var(--color-success-800, #065f46);
    border: 1px solid var(--color-success-100, #d1fae5);
}

.badge-estado--offline,
.badge-estado-offline,
.badge-offline {
    background: var(--color-danger-050, #fef2f2);
    color: var(--color-danger-800, #991b1b);
    border: 1px solid var(--color-danger-100, #fee2e2);
}

.badge-estado--alerta {
    background: var(--color-warning-050, #fffbeb);
    color: var(--color-warning-800, #92400e);
    border: 1px solid var(--color-warning-100, #fef3c7);
}

.badge-estado--neutro {
    background: var(--color-neutral-100, #f1f5f9);
    color: var(--color-neutral-700, #334155);
    border: 1px solid var(--color-neutral-300, #cbd5e1);
}

/* Barra de Herramientas */
.mqtt-toolbar, .hb-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 24px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.toolbar-grupo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.toolbar-info {
    font-size: 13px;
    color: #475569;
}

.filtro-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.filtro-icono {
    position: absolute;
    left: 10px;
    color: #94a3b8;
    pointer-events: none;
    display: flex;
}

.filtro-input-wrapper input {
    padding-left: 32px !important;
}

.toolbar-grupo input, .select-limite {
    padding: 6px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 12px;
    outline: none;
    font-family: inherit;
    background: #ffffff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.toolbar-grupo input:focus, .select-limite:focus {
    border-color: #0284c7;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.toolbar-grupo input {
    min-width: 200px;
}

.toolbar-acciones {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-autorefresh {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    user-select: none;
}

.pulsador-verde {
    width: 8px;
    height: 8px;
    background-color: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 0 rgba(34, 197, 94, 0.4);
    animation: pulsarVerde 1.5s infinite;
}

@keyframes pulsarVerde {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.rotando .icono svg {
    animation: girar 0.6s linear infinite;
}

@keyframes girar {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Tabla de Mensajes / Dispositivos */
.mqtt-tabla-wrap, .hb-tabla-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    min-height: 280px;
    max-height: 480px;
    background: #ffffff;
}

.mqtt-tabla, .hb-tabla {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
}

.mqtt-tabla thead th, .hb-tabla thead th {
    position: sticky;
    top: 0;
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 1px solid #cbd5e1;
    z-index: 10;
}

.mqtt-tabla tbody td, .hb-tabla tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: #1e293b;
    vertical-align: middle;
}

.mqtt-fila:hover, .hb-fila:hover {
    background: #f8fafc;
}

.mqtt-tabla-vacia, .hb-tabla-vacia {
    text-align: center;
    color: #94a3b8;
    padding: 40px !important;
    font-style: italic;
}

.badge-topico {
    display: inline-block;
    max-width: 210px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: #e2e8f0;
    color: #334155;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
}

.badge-qos {
    font-size: 10px;
    color: #64748b;
    background: #f1f5f9;
    padding: 2px 4px;
    border-radius: 4px;
}

.col-payload {
    font-family: monospace;
    color: #0284c7;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.btn-tabla-ver {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-tabla-ver:hover {
    background: #0284c7;
    color: #ffffff;
    border-color: #0284c7;
}

/* Estilos de Heartbeat específicos */
.hb-subtopico {
    font-size: var(--text-xs, 11px);
    color: var(--color-neutral-600, #475569);
    font-family: var(--font-mono, monospace);
}

.hb-disp-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hb-disp-val {
    font-weight: 700;
    width: 36px;
}

.hb-disp-bar {
    flex: 1;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.hb-disp-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.hb-bateria-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.hb-bateria-icono {
    display: flex;
}

.hb-bateria-val {
    font-weight: 600;
    width: 34px;
}

.hb-bateria-bar {
    width: 50px;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.hb-bateria-fill {
    height: 100%;
    border-radius: 3px;
}

/* Pie de modal */
.modal-admin-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}

.footer-info {
    font-size: 11px;
    color: #64748b;
}

.footer-info code {
    background: #e2e8f0;
    padding: 2px 4px;
    border-radius: 4px;
    color: #1e293b;
}

/* Inspector de Payload */
.mqtt-inspector-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.mqtt-inspector-backdrop.activo {
    opacity: 1;
    visibility: visible;
}

.mqtt-inspector-dialog {
    background: #1e293b;
    color: #f8fafc;
    border-radius: 10px;
    width: 90%;
    max-width: 640px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid #334155;
}

.mqtt-inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid #334155;
}

.mqtt-inspector-titulo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mqtt-inspector-titulo h4 {
    margin: 0;
    font-size: 15px;
    color: #ffffff;
}

.btn-cerrar-inspector {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    padding: 4px;
    border-radius: 4px;
}

.btn-cerrar-inspector:hover {
    color: #ffffff;
    background: #334155;
}

.mqtt-inspector-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px 18px;
    background: #0f172a;
    font-size: 12px;
    border-bottom: 1px solid #334155;
}

.mqtt-inspector-meta span {
    color: #38bdf8;
    font-family: monospace;
}

.mqtt-inspector-code-wrap {
    padding: 12px 18px;
    flex: 1;
    overflow-y: auto;
}

.mqtt-inspector-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
}

.btn-copiar-payload {
    background: #334155;
    border: 1px solid #475569;
    color: #f8fafc;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s;
}

.btn-copiar-payload:hover {
    background: #0284c7;
    border-color: #0284c7;
}

.mqtt-pre {
    margin: 0;
    padding: 12px;
    background: #090d16;
    border-radius: 6px;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 12px;
    color: #a5f3fc;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 350px;
    border: 1px solid #1e293b;
}
