/**
 * OBSERVABILITY UI (Tracing & Metrics)
 * High-fidelity Datadog/Jaeger styled components.
 */

:root {
    --trace-bg: rgba(10, 11, 14, 0.95);
    --trace-border: rgba(255, 255, 255, 0.08);
    --trace-accent: #0065FF;
    --trace-text: #E2E8F0;
    --trace-muted: #94A3B8;
}

html.light {
    --trace-bg: rgba(255, 255, 255, 0.98);
    --trace-border: rgba(0, 0, 0, 0.1);
    --trace-accent: #0052CC;
    --trace-text: #172B4D;
    --trace-muted: #64748B;
}

/* ── TRACE DRAWER ── */
#trace-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    visibility: hidden;
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.4s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.4s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.4s cubic-bezier(0.16, 1, 0.3, 1), color 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#trace-drawer.open {
    visibility: visible;
    opacity: 1;
}

.trace-content {
    background: var(--trace-bg);
    border-top: 1px solid var(--trace-border);
    width: 100%;
    max-height: 85vh;
    border-radius: 24px 24px 0 0;
    padding: 32px;
    box-shadow: 0 -20px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#trace-drawer.open .trace-content {
    transform: translateY(0);
}

/* ── HEADER ── */
.trace-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.trace-title-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.trace-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 700;
    background: rgba(0, 101, 255, 0.15);
    color: var(--trace-accent);
    padding: 2px 8px;
    border-radius: 4px;
    width: fit-content;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.trace-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--trace-text);
}

.trace-meta {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--trace-muted);
    display: flex;
    gap: 20px;
    margin-top: 8px;
}

.trace-meta strong {
    color: var(--trace-text);
}

#trace-close {
    background: var(--trace-border);
    border: 1px solid var(--trace-border);
    color: var(--trace-text);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

#trace-close:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(90deg);
}

/* ── WATERFALL GRID ── */
.trace-waterfall {
    flex: 1;
    overflow-y: auto;
    padding-right: 10px;
}

.trace-row {
    display: grid;
    grid-template-columns: 240px 1fr;
    border-bottom: 1px solid var(--trace-border);
    padding: 12px 0;
    opacity: 0;
    transform: translateX(-10px);
    animation: traceIn 0.5s forwards;
    animation-delay: var(--delay);
}

@keyframes traceIn {
    to { opacity: 1; transform: translateX(0); }
}

.trace-label-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-right: 20px;
}

.trace-service {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--trace-muted);
}

.trace-op {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--trace-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.trace-timeline-col {
    position: relative;
    display: flex;
    align-items: center;
}

.trace-bar-wrap {
    width: 100%;
    height: 18px;
    position: relative;
    background: var(--trace-border);
    border-radius: 3px;
}

.trace-bar {
    position: absolute;
    height: 100%;
    border-radius: 3px;
    min-width: 2px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.trace-bar.error {
    background: var(--ds-status-danger, #F15B50) !important;
    box-shadow: 0 0 10px rgba(241, 91, 80, 0.3);
}

.trace-duration {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: white;
    font-weight: 700;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* ── HUD TRIGGER BUTTON ── */
.trace-hud-btn {
    display: inline-flex;
    align-items: center;
    height: 38px;
    gap: 10px;
    background: rgba(0, 101, 255, 0.05);
    border: 1px solid rgba(0, 101, 255, 0.1);
    color: #0052CC;
    padding: 0 16px;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.trace-hud-btn:hover {
    background: rgba(0, 101, 255, 0.1);
    border-color: #0052CC;
    transform: translateY(-1px);
}

.trace-pulse {
    width: 6px;
    height: 6px;
    background: #0065FF;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

html.light .trace-hud-btn {
    background: rgba(0, 82, 204, 0.05);
    border-color: rgba(0, 82, 204, 0.2);
    color: #0052CC;
}

html.light .trace-pulse {
    background: #0052CC;
    box-shadow: 0 0 10px rgba(0, 82, 204, 0.3);
}

#chaos-inject-trace.chaos-active {
    background: rgba(239, 68, 68, 0.15) !important;
    border-color: rgba(239, 68, 68, 0.3) !important;
    color: #EF4444 !important;
}

html.light #chaos-inject-trace.chaos-active {
    background: rgba(211, 47, 47, 0.08) !important;
    border-color: rgba(211, 47, 47, 0.2) !important;
    color: #D32F2F !important;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 101, 255, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(0, 101, 255, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 101, 255, 0); }
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .trace-row { grid-template-columns: 140px 1fr; }
    .trace-service { font-size: 0.55rem; }
    .trace-op { font-size: 0.7rem; }
    .obs-blueprint-card { grid-column: span 1; }
}

/* ── INFRASTRUCTURE BLUEPRINT CARD ── */
.obs-blueprint-card {
    grid-column: span 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, rgba(0, 101, 255, 0.05) 0%, rgba(0, 101, 255, 0.02) 100%);
    border: 1px dashed rgba(0, 101, 255, 0.3);
    border-radius: 12px;
    padding: 24px;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.obs-blueprint-card:hover {
    background: rgba(0, 101, 255, 0.1);
    border-style: solid;
    border-color: #0065FF;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.obs-blueprint-card i {
    font-size: 1.5rem;
    color: #4facfe;
}

.obs-blueprint-card h4 {
    font-family: var(--font-display);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-primary);
    margin: 0;
}

.obs-blueprint-card span {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* ── INFRA MODAL ── */
.infra-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.4s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.4s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.4s cubic-bezier(0.16, 1, 0.3, 1), color 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.infra-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.infra-modal-content {
    width: 90%;
    max-width: 1000px;
    max-height: 85vh;
    background: var(--bg-base);
    border: 1px solid var(--trace-border);
    border-radius: 16px;
    padding: 32px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.4s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.4s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.4s cubic-bezier(0.16, 1, 0.3, 1), color 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: auto;
}

.infra-modal-overlay.active .infra-modal-content {
    transform: scale(1) translateY(0);
}

.infra-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 16px;
}

.infra-modal-title h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    margin: 0;
    color: var(--text-primary);
}

.infra-modal-title p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 4px 0 0;
}

.infra-modal-close {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.infra-modal-close:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #EF4444;
}

#infra-diagram-root {
    display: flex;
    justify-content: center;
    padding: 20px 0;
}

/* Mermaid SVG Overrides */
#infra-diagram-root svg {
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
/* ─── INFRA DASHBOARD WIDGETS ─── */
.infra-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-top: 32px;
}

.infra-widget {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}
html.dark .infra-widget { box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.3); }

.infra-widget .widget-header {
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
html.dark .infra-widget .widget-header { background: rgba(255, 255, 255, 0.02); }

.infra-widget .widget-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.infra-widget .widget-status {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.infra-widget .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.infra-widget .status-dot.green { background: #10B981; box-shadow: 0 0 8px rgba(16, 185, 129, 0.4); }
.infra-widget .status-dot.blue { background: #3B82F6; box-shadow: 0 0 8px rgba(59, 130, 246, 0.4); }

.infra-widget .widget-body {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.infra-widget .metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border);
}
.infra-widget .metric-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.infra-widget .metric-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.infra-widget .metric-val {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.infra-widget .term-line {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-primary);
    line-height: 1.5;
    text-align: left;
}
.infra-widget .term-line .prompt { color: #8B5CF6; font-weight: 700; margin-right: 6px; }
.infra-widget .term-line.success { color: #10B981; }
.infra-widget .term-line.highlight { color: #3B82F6; font-weight: 600; }
.infra-widget .term-line.summary { color: var(--text-muted); margin-top: 8px; font-size: 0.75rem; border-top: 1px dashed var(--border); padding-top: 8px; }

.infra-widget .widget-footer {
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.01);
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    text-align: right;
}
html.dark .infra-widget .widget-footer { background: rgba(255, 255, 255, 0.01); }

/* Pipeline Tracker */
.pipeline-track {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    width: 100%;
}
.pipe-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}
.pipe-node.active { color: #10B981; }
.pipe-node.argocd { color: #F97316; }

.pipe-node i {
    font-size: 1.2rem;
    background: var(--bg-1);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid currentColor;
}
.pipe-node span {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    text-transform: uppercase;
    font-weight: 600;
}
.pipe-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin: 0 10px;
    transform: translateY(-10px);
}
.pipe-line.active { background: #10B981; }

.commit-info {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.02);
    padding: 8px 12px;
    border-radius: 6px;
    margin-top: 12px;
    border: 1px solid var(--border);
    text-align: left;
}
html.dark .commit-info { background: rgba(255, 255, 255, 0.03); }
.commit-info .hash { color: var(--accent-indigo); font-weight: 700; }

/* ─── MOBILE OPTIMIZATION ( < 768px ) ─── */
@media (max-width: 767px) {
    .infra-dashboard-grid {
        grid-template-columns: 1fr;
    }
    .trace-content {
        padding: 24px 16px !important;
        max-height: 92vh !important;
        border-radius: 16px 16px 0 0 !important;
    }

    .trace-header {
        margin-bottom: 20px !important;
        gap: 12px;
    }

    .trace-title {
        font-size: 1.1rem !important;
    }

    .trace-meta {
        font-size: 0.65rem !important;
        flex-direction: column;
        gap: 4px;
    }

    .trace-meta span {
        display: block;
    }

    .trace-waterfall {
        padding: 0 !important;
    }

    .trace-row {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
        padding: 12px 0 !important;
    }

    .trace-label-col {
        width: 100% !important;
        padding-right: 0 !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .trace-timeline-col {
        width: 100% !important;
    }

    .trace-bar-wrap {
        height: 14px !important;
    }

    .trace-duration {
        font-size: 0.6rem !important;
    }

    .trace-footer {
        flex-direction: column !important;
        gap: 16px !important;
        align-items: flex-start !important;
        margin-top: 16px !important;
    }

    /* Infra Modal Mobile Fixes */
    .infra-modal-content {
        width: 95% !important;
        padding: 20px !important;
        max-height: 90vh !important;
    }

    .infra-modal-header {
        margin-bottom: 16px !important;
    }

    .infra-modal-title h2 {
        font-size: 1rem !important;
    }

    #infra-diagram-root {
        overflow-x: auto !important;
        justify-content: flex-start !important;
        padding: 10px 0 !important;
        -webkit-overflow-scrolling: touch;
    }

    #infra-diagram-root svg {
        min-width: 600px !important;
        height: auto !important;
    }
}
