/* AEGIS Monitor Dashboard */
:root {
    --bg: #0f1923;
    --bg-secondary: #1a2836;
    --text: #e0e6ed;
    --text-muted: #7f8c9b;
    --green: #2ecc71;
    --yellow: #f1c40f;
    --red: #e74c3c;
    --blue: #3498db;
    --orange: #e67e22;
    --gray: #95a5a6;
    --border: #2c3e50;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
}

/* Top metrics bar */
.metrics-bar {
    display: flex;
    gap: 24px;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.metrics-bar h1 {
    font-size: 16px;
    font-weight: 700;
    margin-right: 24px;
    white-space: nowrap;
}

.metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.metric .value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
}

.metric .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.metric.r0 .value { color: var(--blue); }
.metric.threats .value { color: var(--red); }
.metric.quarantined .value { color: var(--yellow); }
.metric.killswitched .value { color: var(--orange, #e67e22); }
.metric.clusters .value { color: var(--green); }
.metric.agents .value { color: var(--text); }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 8px;
}

.status-dot.connected { background: var(--green); }
.status-dot.disconnected { background: var(--red); }

/* Main layout */
.main-layout {
    display: flex;
    height: calc(100vh - 52px);
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    cursor: pointer;
    font-size: 13px;
}

.filter-group input[type="checkbox"] {
    accent-color: var(--blue);
}

.color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

/* Graph canvas */
.graph-container {
    flex: 1;
    position: relative;
}

#graph-canvas {
    width: 100%;
    height: 100%;
}

/* Graph legend */
.graph-legend {
    position: absolute;
    bottom: 10px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15, 25, 35, 0.88);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 12px;
    font-size: 11px;
    color: var(--text-muted);
    z-index: 5;
    pointer-events: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-aegis {
    background: #2ecc71;
    width: 12px;
    height: 12px;
}

.legend-no-aegis {
    background: #7a9a7e;
    width: 8px;
    height: 8px;
}

.legend-sep {
    color: var(--border);
    margin: 0 2px;
}

/* Agent detail popup */
.agent-popup {
    display: none;
    position: absolute;
    top: 20px;
    right: 20px;
    width: 320px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.agent-popup.visible { display: block; }

.agent-popup .close-btn {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
}

.agent-popup h3 {
    font-size: 14px;
    margin-bottom: 12px;
}

.agent-popup .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.agent-popup .detail-row .label { color: var(--text-muted); }

/* Event log */
.event-log {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px;
    background: rgba(15, 25, 35, 0.95);
    border-top: 1px solid var(--border);
    overflow-y: auto;
    padding: 8px 16px;
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
}

.event-log .event {
    padding: 2px 0;
    color: var(--text-muted);
}

.event-log .event.threat { color: var(--red); }
.event-log .event.compromise { color: var(--red); font-weight: 600; }
.event-log .event.heartbeat { color: var(--gray); }
.event-log .event.killswitch { color: var(--yellow); font-weight: 600; }

/* Killswitch panel */
.killswitch-panel { border-top: 1px solid var(--border); padding-top: 12px; }

.ks-status-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.ks-status-text.ks-active {
    color: var(--red);
    font-weight: 600;
}

.ks-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.ks-btn {
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ks-block-swarm, .ks-block-agent {
    background: var(--red);
    color: #fff;
}
.ks-block-swarm:hover, .ks-block-agent:hover {
    background: #c0392b;
}

.ks-unblock-swarm, .ks-unblock-agent {
    background: var(--green);
    color: #fff;
}
.ks-unblock-swarm:hover, .ks-unblock-agent:hover {
    background: #27ae60;
}

.ks-rule {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
}

.ks-rule-scope {
    color: var(--red);
    font-weight: 600;
    flex: 1;
}

.ks-rule-reason {
    color: var(--text-muted);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ks-rule-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
}
.ks-rule-delete:hover {
    color: var(--red);
}

.ks-popup-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* Topic clusters metric */
.metric.topic-clusters .value { color: #1abc9c; }

/* Topic view toggle button */
.topic-toggle-btn {
    background: var(--bg-secondary);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    pointer-events: all;
}
.topic-toggle-btn:hover { color: var(--text); border-color: var(--blue); }
.topic-toggle-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Topic Clusters panel */
.topic-clusters-panel {
    position: absolute;
    bottom: 120px;
    left: 0;
    right: 0;
    max-height: 300px;
    background: rgba(15, 25, 35, 0.95);
    border-top: 1px solid var(--border);
    z-index: 6;
    display: none;
}
.topic-clusters-panel.visible { display: block; }

.topic-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    user-select: none;
}
.topic-panel-header:hover { color: var(--text); }
.topic-panel-arrow { font-size: 10px; }
.topic-panel-header.collapsed .topic-panel-arrow { transform: rotate(-90deg); }

.topic-panel-body {
    overflow-y: auto;
    max-height: 260px;
    padding: 8px 16px;
}

/* Tab bar */
.topic-tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}
.topic-tab {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 11px;
    cursor: pointer;
}
.topic-tab:hover { color: var(--text); }
.topic-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Centroid cards */
#topic-centroid-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.centroid-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-left: 3px solid var(--blue);
    border-radius: 4px;
    padding: 8px 12px;
    min-width: 220px;
    max-width: 320px;
    flex: 1 1 220px;
    cursor: pointer;
    transition: opacity 0.2s;
}
.centroid-card:hover { border-color: var(--text-muted); }
.centroid-card.dissolved { opacity: 0.55; }
.centroid-card.expanded { max-width: 100%; flex-basis: 100%; }

.centroid-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    flex-wrap: wrap;
}
.centroid-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.centroid-count {
    color: var(--text-muted);
    font-size: 11px;
    margin-left: auto;
}
.centroid-lifetime {
    color: var(--text-muted);
    font-size: 10px;
    margin-left: 6px;
}
.centroid-dissolved-badge {
    background: var(--red);
    color: #fff;
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 4px;
    text-transform: uppercase;
}

.centroid-statuses {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 4px;
}
.centroid-compromised {
    color: var(--red);
    font-size: 11px;
    margin-top: 2px;
}

/* Status badges */
.status-badge {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
}
.status-badge-active { background: #2ecc7133; color: #2ecc71; }
.status-badge-compromised { background: #e74c3c33; color: #e74c3c; }
.status-badge-quarantined { background: #f1c40f33; color: #f1c40f; }

/* Dendrogram */
.dendro-container {
    position: relative;
    overflow-x: auto;
    min-height: 200px;
}
.dendro-container canvas {
    display: block;
}
.dendro-tooltip {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 11px;
    color: var(--text);
    z-index: 10;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.dendro-payload {
    color: var(--text-muted);
    font-size: 10px;
    max-height: 80px;
    overflow: hidden;
    word-break: break-all;
    margin-top: 2px;
}
