/* =========================================
   CODERSTATION Dashboard – dashboard.css
   No-sidebar, single-viewport layout
   Enhanced CMP Visualization v2
   ========================================= */

/* ---- CSS Variables ---- */
:root {
    --bg-base:        #080d1a;
    --bg-topbar:      #0b1120;
    --bg-card:        #0f1829;
    --bg-card-hdr:    #0c1524;
    --border:         rgba(99,179,237,0.12);
    --text-primary:   #e8f1ff;
    --text-secondary: #7a93b8;
    --text-muted:     #445a78;
    --blue:           #3b82f6;
    --blue-dim:       rgba(59,130,246,0.18);
    --amber:          #f59e0b;
    --amber-dim:      rgba(245,158,11,0.18);
    --emerald:        #10b981;
    --emerald-dim:    rgba(16,185,129,0.18);
    --purple:         #a855f7;
    --purple-dim:     rgba(168,85,247,0.18);
    --red:            #ef4444;
    --cyan:           #06b6d4;
    --topbar-h:       48px;
    --footer-h:       32px;
    --radius:         10px;
    --radius-sm:      7px;
    --tr:             0.25s ease;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    height: 100%;
    overflow: hidden;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    font-size: 13px;
}
a { text-decoration: none; color: inherit; }

/* ---- App Shell ---- */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* =============================================
   TOPBAR
   ============================================= */
.topbar {
    height: 60px;
    background: rgba(13, 17, 23, 0.88);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 32px;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 170px;
}

.brand-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--blue), var(--purple));
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 16px;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.brand-name {
    display: block;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--text-primary);
    line-height: 1;
}

.brand-sub {
    font-size: 9px;
    font-weight: 600;
    color: var(--blue);
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Center Status */
.topbar-status {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--emerald);
    background: rgba(16, 185, 129, 0.1);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-dot.pulsing {
    width: 8px;
    height: 8px;
    background: var(--emerald);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--emerald);
    animation: statusPulse 2s infinite;
}

.status-meta {
    display: flex;
    gap: 16px;
    font-size: 10px;
    color: var(--text-secondary);
}

.meta-item i { margin-right: 4px; color: var(--blue); opacity: 0.8; }

/* Right Controls */
.topbar-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

.topbar-clock {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    min-width: 84px;
    text-align: center;
}

.control-group {
    display: flex;
    gap: 6px;
    padding-right: 16px;
    border-right: 1px solid rgba(255,255,255,0.1);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    text-align: right;
}

.user-name {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-role {
    display: block;
    font-size: 9px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--blue);
    cursor: pointer;
    transition: var(--tr);
}

.user-avatar:hover { transform: scale(1.1); box-shadow: 0 0 15px var(--blue); }
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* =============================================
   PAGE CONTENT
   ============================================= */
.page-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 8px 12px;
    gap: 8px;
    min-height: 0;
}

/* =============================================
   STATS STRIP
   ============================================= */
.stats-strip {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.stat-card {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
    transition: transform var(--tr), box-shadow var(--tr);
    min-width: 0;
}

.stat-card:hover { transform: translateY(-2px); }

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
}

.stat-card--blue::before    { background: linear-gradient(90deg, var(--blue), var(--cyan)); }
.stat-card--blue:hover      { box-shadow: 0 6px 24px rgba(59,130,246,0.2); }
.stat-card--amber::before   { background: linear-gradient(90deg, var(--amber), #fbbf24); }
.stat-card--amber:hover     { box-shadow: 0 6px 24px rgba(245,158,11,0.2); }
.stat-card--emerald::before { background: linear-gradient(90deg, var(--emerald), #34d399); }
.stat-card--emerald:hover   { box-shadow: 0 6px 24px rgba(16,185,129,0.2); }
.stat-card--purple::before  { background: linear-gradient(90deg, var(--purple), #c084fc); }
.stat-card--purple:hover    { box-shadow: 0 6px 24px rgba(168,85,247,0.2); }

.stat-icon-wrap {
    width: 38px; height: 38px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.stat-card--blue    .stat-icon-wrap { background: var(--blue-dim);    color: var(--blue); }
.stat-card--amber   .stat-icon-wrap { background: var(--amber-dim);   color: var(--amber); }
.stat-card--emerald .stat-icon-wrap { background: var(--emerald-dim); color: var(--emerald); }
.stat-card--purple  .stat-icon-wrap { background: var(--purple-dim);  color: var(--purple); }

.stat-body { flex: 1; min-width: 0; }

.stat-value {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 1px;
    white-space: nowrap;
}

.stat-trend {
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.trend-up   { color: var(--emerald); }
.trend-down { color: var(--red); }

/* =============================================
   MID ROW
   ============================================= */
.mid-row {
    flex: 1;
    display: flex;
    gap: 8px;
    overflow: hidden;
    min-height: 0;
}

/* =============================================
   DIAGRAM CARD
   ============================================= */
.diagram-card {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid rgba(59,130,246,0.18);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Generic card header */
.card-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-card-hdr);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 6px;
}

.card-hdr-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-icon { color: var(--blue); font-size: 13px; }
.card-title-text { font-size: 12px; font-weight: 700; color: var(--text-primary); }

.legend-group { display: flex; gap: 6px; flex-wrap: wrap; }

.legend-item {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    letter-spacing: 0.02em;
}

.legend-client  { background: rgba(255, 255, 255, 0.12); color: #ffffff; border: 1px solid rgba(255, 255, 255, 0.25); }
.legend-ctrl    { background: rgba(168,85,247,0.12); color: #c084fc; border: 1px solid rgba(168,85,247,0.25); }
.legend-gw      { background: var(--blue-dim);       color: var(--blue);    border: 1px solid rgba(59,130,246,0.25); }
.legend-agent   { background: var(--amber-dim);      color: var(--amber);   border: 1px solid rgba(245,158,11,0.25); }
.legend-db      { background: var(--emerald-dim);    color: var(--emerald); border: 1px solid rgba(16,185,129,0.25); }

/* Live badge */
.live-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--emerald);
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 2px 8px;
    border-radius: 20px;
    flex-shrink: 0;
}

.live-dot {
    width: 5px; height: 5px;
    background: var(--emerald);
    border-radius: 50%;
    animation: pulse 1s infinite;
}

/* ---- DIAGRAM AREA ---- */
.diagram-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: 
        radial-gradient(circle at 50% 50%, rgba(13, 25, 48, 1) 0%, rgba(8, 13, 26, 1) 100%);
    min-height: 0;
}

/* Advanced Grid Overlay */
.diagram-area::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: 
        linear-gradient(rgba(59, 130, 246, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(59, 130, 246, 0.05) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

/* Depth Glow */
.diagram-area::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.1) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.connections-svg {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1;
    filter: drop-shadow(0 0 5px rgba(59, 130, 246, 0.2));
}

/* ---- CMP Nodes ---- */
.cmp-node {
    position: absolute;
    z-index: 10;
    transition: transform var(--tr), filter var(--tr);
    cursor: default;
}

.cmp-node:hover { transform: scale(1.07); z-index: 20; }

.cmp-node.node-flash { animation: nodeFlash 0.4s ease; }

.node-body {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    min-width: 120px;
    max-width: 170px;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), inset 0 0 10px rgba(255, 255, 255, 0.02);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cmp-node:hover .node-body {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
}

.node-icon-wrap {
    width: 30px; height: 30px;
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.node-name {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

.node-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 9px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.ndot {
    width: 5px; height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ndot-active { background: var(--emerald); box-shadow: 0 0 5px var(--emerald); animation: pulse 2s infinite; }
.ndot-busy   { background: var(--amber);   box-shadow: 0 0 5px var(--amber);   animation: pulse 1.3s infinite; }

/* Node type colours */
.node-client .node-body          { border-color: rgba(255, 255, 255, 0.3); background: rgba(255, 255, 255, 0.05); }
.node-client .node-icon-wrap     { background: rgba(255, 255, 255, 0.15); color: #ffffff; }
.node-client:hover .node-body    { border-color: #ffffff; box-shadow: 0 0 20px rgba(255, 255, 255, 0.2); }

.node-controller .node-body          { border-color: rgba(168, 85, 247, 0.3); background: rgba(168, 85, 247, 0.05); }
.node-controller .node-icon-wrap     { background: rgba(168, 85, 247, 0.15); color: var(--purple); }
.node-controller:hover .node-body    { border-color: var(--purple); box-shadow: 0 0 20px rgba(168, 85, 247, 0.2); }

.node-gateway .node-body          { border-color: rgba(59, 130, 246, 0.3); background: rgba(59, 130, 246, 0.05); }
.node-gateway .node-icon-wrap     { background: rgba(59, 130, 246, 0.15); color: var(--blue); }
.node-gateway:hover .node-body    { border-color: var(--blue); box-shadow: 0 0 20px rgba(59, 130, 246, 0.2); }

.node-agent .node-body          { border-color: rgba(245, 158, 11, 0.3); background: rgba(245, 158, 11, 0.05); }
.node-agent .node-icon-wrap     { background: rgba(245, 158, 11, 0.15); color: var(--amber); }
.node-agent:hover .node-body    { border-color: var(--amber); box-shadow: 0 0 20px rgba(245, 158, 11, 0.2); }

.node-model .node-body          { border-color: rgba(6, 182, 212, 0.3); background: rgba(6, 182, 212, 0.05); }
.node-model .node-icon-wrap     { background: rgba(6, 182, 212, 0.15); color: var(--cyan); }
.node-model:hover .node-body    { border-color: var(--cyan); box-shadow: 0 0 20px rgba(6, 182, 212, 0.2); }

.node-database .node-body          { border-color: rgba(16, 185, 129, 0.3); background: rgba(16, 185, 129, 0.05); }
.node-database .node-icon-wrap     { background: rgba(16, 185, 129, 0.15); color: var(--emerald); }
.node-database:hover .node-body    { border-color: var(--emerald); box-shadow: 0 0 20px rgba(16, 185, 129, 0.2); }

/* Data packets */
.packet {
    position: absolute;
    width: 6px; height: 6px;
    border-radius: 50%;
    z-index: 50;
    pointer-events: none;
    transform: translate(-50%, -50%);
    filter: blur(1px);
}

.packet::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: inherit;
    opacity: 0.4;
    filter: blur(4px);
    animation: packetPulse 0.4s infinite alternate;
}

@keyframes packetPulse {
    from { transform: scale(1);   opacity: 0.4; }
    to   { transform: scale(2.5); opacity: 0.1; }
}

/* =============================================
   RIGHT PANELS
   ============================================= */
.right-panels {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

.panel-card {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Activity Log */
.activity-log {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

.activity-log::-webkit-scrollbar { width: 3px; }
.activity-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.log-entry {
    display: flex;
    gap: 6px;
    font-size: 10.5px;
    padding: 4px 7px;
    border-radius: 5px;
    background: rgba(255,255,255,0.02);
    border-left: 2px solid transparent;
    animation: slideIn 0.25s ease;
    align-items: flex-start;
    flex-shrink: 0;
    transition: background 0.2s;
}

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

/* Color Mapping for Logs */
.log-client      { border-left-color: #ffffff; }
.log-client .log-source { color: #ffffff; }

.log-gateway     { border-left-color: var(--blue); }
.log-gateway .log-source { color: var(--blue); }

.log-security    { border-left-color: var(--red); }
.log-security .log-source { color: var(--red); }

.log-agent       { border-left-color: var(--amber); }
.log-agent .log-source { color: var(--amber); }

.log-response    { border-left-color: var(--cyan); }
.log-response .log-source { color: var(--cyan); }

.log-db          { border-left-color: var(--emerald); }
.log-db .log-source { color: var(--emerald); }

.log-time   { color: var(--text-muted); flex-shrink: 0; font-variant-numeric: tabular-nums; font-size: 9px; opacity: 0.8; }
.log-source { font-weight: 800; flex-shrink: 0; min-width: 82px; text-transform: uppercase; font-size: 9px; }
.log-msg    { color: var(--text-secondary); line-height: 1.3; }

/* Metrics */
.metrics-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    flex: 1;
    justify-content: center;
}

.metric-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.metric-label {
    font-size: 11px;
    color: var(--text-secondary);
    min-width: 102px;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.metric-label i { color: var(--blue); width: 12px; text-align: center; font-size: 11px; }

.metric-bar-wrap {
    flex: 1;
    height: 5px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
}

.metric-bar {
    height: 100%;
    border-radius: 3px;
    background: var(--blue);
    width: 0;
    transition: width 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Explicit Metric Colors */
#metric-gateway .metric-bar    { background: var(--blue); }
#metric-sentinel1 .metric-bar  { background: var(--amber); }
#metric-queryorch .metric-bar  { background: var(--amber); }
#metric-sentinel2 .metric-bar  { background: var(--cyan); }
#metric-requestorch .metric-bar { background: var(--cyan); }
#metric-response .metric-bar    { background: var(--cyan); }
#metric-security .metric-bar   { background: var(--red); } /* Red for Security Agent/Issues */

.metric-pct {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 30px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* =============================================
   FOOTER
   ============================================= */
.dashboard-footer {
    height: 44px;
    background: rgba(13, 17, 23, 0.9);
    backdrop-filter: blur(8px);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    z-index: 1000;
    position: relative;
}

.footer-left, .footer-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.footer-item i { margin-right: 6px; color: var(--blue); opacity: 0.6; }

.status-ok {
    color: var(--emerald);
    font-weight: 700;
}

.footer-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 600;
    opacity: 0.8;
}

.footer-version {
    background: rgba(59, 130, 246, 0.1);
    color: var(--blue);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-weight: 700;
}

/* =============================================
   KEYFRAMES
   ============================================= */
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.45; transform: scale(0.8); }
}

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

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes statusPulse {
    0% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { transform: scale(1.1); opacity: 0.8; box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes nodeFlash {
    0%   { filter: brightness(1);    box-shadow: none; }
    40%  { filter: brightness(2.2);  }
    100% { filter: brightness(1);    }
}

@keyframes scanline {
    0%   { background-position: 0 0; }
    100% { background-position: 0 100vh; }
}
