/* ============================================
   SocialDebug.Org -- Diagnostic Console Styles
   ============================================ */

/* CSS Custom Properties */
:root {
    /* Backgrounds */
    --bg-primary: #0d1117;
    --bg-panel: #161b22;
    --bg-elevated: #1c2430;

    /* Borders */
    --border-steel: #2a3a4a;
    --border-intervention: #2a4a3a;

    /* Text */
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-tertiary: #5a7a8a;
    --text-divider: #5a6a7a;

    /* Accent: Diagnostic Signal Colors */
    --color-critical: #da3633;
    --color-warning: #d29922;
    --color-nominal: #39d353;
    --color-info: #58a6ff;
    --color-structural: #bc8cff;
    --color-fault: #f0883e;

    /* Typography */
    --font-mono: 'IBM Plex Mono', monospace;
    --font-heading: 'DM Sans', sans-serif;
    --font-body: 'Source Sans 3', sans-serif;

    /* Animation */
    --ease-diagnostic: cubic-bezier(0.25, 0.46, 0.45, 0.94);

    /* Layout */
    --sidebar-width: 240px;
    --sidebar-collapsed: 48px;
    --grid-gap: 4px;
}

/* Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    line-height: 1.65;
    overflow-x: hidden;
    /* Dot-grid background pattern */
    background-image: radial-gradient(circle, #e6edf3 0.5px, transparent 0.5px);
    background-size: 16px 16px;
    background-position: 0 0;
    background-attachment: fixed;
}

/* Override the body bg with a layered approach so dots are subtle */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-primary);
    opacity: 0.97;
    z-index: -1;
    pointer-events: none;
}


/* ============================================
   INTAKE SCREEN
   ============================================ */
#intake-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.6s var(--ease-diagnostic);
}

#intake-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

#intake-screen.hidden {
    display: none;
}

#intake-cursor {
    width: 20px;
    height: 2px;
    background-color: var(--color-nominal);
    animation: blink-cursor 0.8s step-end infinite;
}

#intake-cursor.typing {
    animation: none;
    opacity: 1;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

#intake-text {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: 0.05em;
    margin-top: 16px;
    min-height: 24px;
    opacity: 0;
    transition: opacity 0.3s var(--ease-diagnostic);
}

#intake-text.visible {
    opacity: 1;
}

#intake-text.dimmed {
    opacity: 0.4;
}


/* ============================================
   MAIN INTERFACE
   ============================================ */
#main-interface {
    display: flex;
    min-height: 100vh;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s var(--ease-diagnostic), transform 0.8s var(--ease-diagnostic);
}

#main-interface.visible {
    opacity: 1;
    transform: translateY(0);
}


/* ============================================
   SIDEBAR NAVIGATION RAIL
   ============================================ */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-steel);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    z-index: 100;
    transition: width 0.3s var(--ease-diagnostic);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-steel);
}

.sidebar-logo {
    flex-shrink: 0;
}

.sidebar-title {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.08em;
}

.sidebar-nav-list {
    list-style: none;
    flex: 1;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s var(--ease-diagnostic);
}

.sidebar-nav-item:hover {
    background-color: var(--bg-elevated);
}

.sidebar-nav-item.active {
    background-color: var(--bg-elevated);
}

.nav-label {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    letter-spacing: 0.06em;
}

.sidebar-nav-item.active .nav-label {
    color: var(--text-primary);
}

.sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border-steel);
}

.sidebar-version {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    color: var(--text-tertiary);
}


/* ============================================
   STATUS INDICATOR DOTS
   ============================================ */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.nominal {
    background-color: var(--color-nominal);
    box-shadow: 0 0 6px var(--color-nominal);
}

.status-dot.warning {
    background-color: var(--color-warning);
    box-shadow: 0 0 6px var(--color-warning);
    animation: pulse-warning 2s ease-in-out infinite;
}

.status-dot.critical {
    background-color: var(--color-critical);
    box-shadow: 0 0 6px var(--color-critical);
}

.status-dot.info {
    background-color: var(--color-info);
    box-shadow: 0 0 6px var(--color-info);
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}


/* ============================================
   CONTENT AREA
   ============================================ */
#content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 32px 32px 64px 32px;
    position: relative;
    max-width: calc(100vw - var(--sidebar-width));
}

.content-section {
    margin-bottom: 64px;
}


/* ============================================
   SECTION DIVIDERS
   ============================================ */
.section-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 0;
    margin-bottom: 24px;
    position: relative;
}

.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background-color: var(--border-steel);
}

.divider-label {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    color: var(--text-divider);
    letter-spacing: 0.04em;
    padding: 0 16px;
    white-space: nowrap;
}


/* ============================================
   PANEL GRID
   ============================================ */
.panel-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--grid-gap);
    margin-bottom: var(--grid-gap);
}

.panel {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-steel);
    border-radius: 2px;
    overflow: hidden;
}

.panel-4col {
    grid-column: span 4;
}

.panel-6col {
    grid-column: span 6;
}

.panel-8col {
    grid-column: span 8;
}

.panel-12col {
    grid-column: span 12;
}


/* ============================================
   PANEL HEADER
   ============================================ */
.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-steel);
    background-color: var(--bg-elevated);
}

.panel-title {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    flex: 1;
}

.panel-timestamp {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    color: var(--text-tertiary);
    letter-spacing: 0.02em;
}


/* ============================================
   PANEL BODY
   ============================================ */
.panel-body {
    padding: 16px;
}

.body-text {
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.65;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.body-text:last-child {
    margin-bottom: 0;
}

.annotation-text {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 300;
    color: var(--text-tertiary);
    font-style: italic;
}


/* ============================================
   METRIC ROWS
   ============================================ */
.metric-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(42, 58, 74, 0.4);
}

.metric-row:last-child {
    border-bottom: none;
}

.metric-label {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    flex: 1;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.critical-text { color: var(--color-critical); }
.warning-text { color: var(--color-warning); }
.nominal-text { color: var(--color-nominal); }
.info-text { color: var(--color-info); }


/* ============================================
   SPARKLINES
   ============================================ */
.sparkline {
    width: 120px;
    height: 24px;
    flex-shrink: 0;
}

.sparkline-path {
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sparkline-path.declining {
    stroke: var(--color-critical);
}

.sparkline-path.stable {
    stroke: var(--text-secondary);
}

.sparkline-path.improving {
    stroke: var(--color-nominal);
}


/* ============================================
   ALERT ITEMS
   ============================================ */
.alert-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(42, 58, 74, 0.3);
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-severity {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 2px;
    flex-shrink: 0;
}

.critical-alert .alert-severity {
    color: var(--color-critical);
    background-color: rgba(218, 54, 51, 0.12);
}

.warning-alert .alert-severity {
    color: var(--color-warning);
    background-color: rgba(210, 153, 34, 0.12);
}

.info-alert .alert-severity {
    color: var(--color-info);
    background-color: rgba(88, 166, 255, 0.12);
}

.alert-message {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.5;
    flex: 1;
}

.alert-time {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    color: var(--text-tertiary);
    flex-shrink: 0;
}


/* ============================================
   TIMELINE
   ============================================ */
.timeline {
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 3px;
    top: 8px;
    bottom: 8px;
    width: 1px;
    background-color: var(--border-steel);
}

.timeline-entry {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
    position: relative;
}

.timeline-date {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    letter-spacing: 0.02em;
    flex-shrink: 0;
    width: 70px;
}

.timeline-event {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.5;
    flex: 1;
}

.timeline-entry .status-dot {
    margin-top: 4px;
}


/* ============================================
   GEOGRAPHIC GRID
   ============================================ */
.geo-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.geo-region {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.region-indicator {
    width: 80px;
    height: 80px;
}

.region-label {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    text-align: center;
}

.region-status {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
}


/* ============================================
   DEPENDENCY DIAGRAM
   ============================================ */
.dependency-diagram {
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
    display: block;
}

.dep-node {
    fill: var(--bg-elevated);
    stroke: var(--border-steel);
    stroke-width: 1;
}

.dep-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    fill: var(--text-secondary);
    text-anchor: middle;
}

.dep-edge {
    stroke: var(--text-secondary);
    stroke-width: 1;
}

.dep-edge-critical {
    stroke: var(--color-critical);
    stroke-width: 1.5;
    stroke-dasharray: 4 2;
}


/* ============================================
   FAULT LINE
   ============================================ */
.fault-line-container {
    position: relative;
    padding: 48px 0;
    text-align: center;
}

.fault-line-svg {
    width: 100%;
    height: 120px;
    display: block;
}

.fault-main-line {
    fill: none;
    stroke: var(--color-fault);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.fault-branch-line {
    fill: none;
    stroke: var(--color-fault);
    stroke-width: 1;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.6;
}

/* Initially hidden for animation */
.fault-main-line,
.fault-branch-line {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
}

.fault-main-line.animate {
    animation: draw-fault 1.5s var(--ease-diagnostic) forwards;
}

.fault-branch-line.animate {
    animation: draw-branch 0.6s var(--ease-diagnostic) forwards;
    animation-delay: 1.5s;
}

@keyframes draw-fault {
    to { stroke-dashoffset: 0; }
}

@keyframes draw-branch {
    to { stroke-dashoffset: 0; }
}

.fault-line-container.glow-flash .fault-main-line {
    filter: url(#fault-glow) drop-shadow(0 0 8px var(--color-fault));
}

.fault-line-title {
    font-family: var(--font-heading);
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.2;
    margin-top: 32px;
    opacity: 0;
    transition: opacity 0.8s var(--ease-diagnostic);
}

.fault-line-title.visible {
    opacity: 1;
}


/* ============================================
   ROOT CAUSE SECTION
   ============================================ */
.root-cause-section .panel {
    background-color: var(--bg-primary);
}

.root-cause-section .panel-header {
    background-color: var(--bg-panel);
}


/* ============================================
   CAUSAL CHAIN DIAGRAM
   ============================================ */
.causal-chain {
    width: 100%;
    max-width: 700px;
    display: block;
    margin: 0 auto;
}

.causal-node {
    fill: var(--bg-elevated);
    stroke: var(--border-steel);
    stroke-width: 1;
}

.causal-node.critical-node {
    stroke: var(--color-critical);
    stroke-width: 1.5;
}

.causal-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    fill: var(--text-secondary);
    text-anchor: middle;
}

.causal-edge {
    stroke: var(--text-secondary);
    stroke-width: 1;
}

.causal-edge-critical {
    stroke: var(--color-critical);
    stroke-width: 1.5;
}

.causal-arrow {
    fill: var(--text-secondary);
}

.causal-arrow-critical {
    fill: var(--color-critical);
}


/* ============================================
   DIAGNOSIS ENTRIES
   ============================================ */
.diagnosis-entry {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(42, 58, 74, 0.4);
}

.diagnosis-entry:last-child {
    border-bottom: none;
}

.diagnosis-code {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--color-info);
    letter-spacing: 0.04em;
}

.diagnosis-description {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.5;
}

.diagnosis-severity {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
}


/* ============================================
   TRACE ENTRIES
   ============================================ */
.trace-entry {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(42, 58, 74, 0.3);
}

.trace-entry:last-child {
    border-bottom: none;
}

.trace-id {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--color-structural);
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.trace-text {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.5;
}


/* ============================================
   INTERVENTION SECTION
   ============================================ */
.intervention-section .intervention-panel {
    border-color: var(--border-intervention);
}

.intervention-section .intervention-panel .panel-header {
    border-bottom-color: var(--border-intervention);
}


/* ============================================
   SESSION END
   ============================================ */
.session-end-content {
    padding: 48px 0 64px 0;
    text-align: center;
}

.session-end-text {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    margin-bottom: 8px;
}

.session-end-timestamp {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    color: var(--text-tertiary);
    letter-spacing: 0.02em;
}


/* ============================================
   TRACE OVERLAY
   ============================================ */
.trace-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.trace-line {
    fill: none;
    stroke: var(--color-info);
    stroke-width: 1;
    opacity: 0.4;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
}

.trace-line.animate {
    animation: draw-trace 0.8s var(--ease-diagnostic) forwards;
}

@keyframes draw-trace {
    to { stroke-dashoffset: 0; }
}

.trace-node {
    fill: var(--color-structural);
    opacity: 0;
}

.trace-node.pulse {
    animation: node-pulse 0.6s var(--ease-diagnostic) forwards;
}

@keyframes node-pulse {
    0% { opacity: 0; transform-origin: center; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}


/* ============================================
   REVEAL ANIMATIONS
   ============================================ */
.reveal-panel {
    opacity: 0;
    transition: opacity 400ms var(--ease-diagnostic), transform 400ms var(--ease-diagnostic), filter 600ms var(--ease-diagnostic);
}

.reveal-panel[data-reveal="slide"] {
    transform: translateX(40px);
}

.reveal-panel[data-reveal="blur"] {
    filter: blur(8px);
}

.reveal-panel.revealed {
    opacity: 1;
    transform: translateX(0);
    filter: blur(0);
}


/* ============================================
   RESPONSIVE: TABLET
   ============================================ */
@media (max-width: 1200px) {
    :root {
        --sidebar-width: 48px;
    }

    .sidebar-title,
    .nav-label,
    .sidebar-version {
        display: none;
    }

    .sidebar-nav-item {
        justify-content: center;
        padding: 10px 4px;
    }

    .sidebar-header {
        justify-content: center;
    }

    .panel-4col {
        grid-column: span 6;
    }

    .panel-8col {
        grid-column: span 12;
    }

    .geo-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   RESPONSIVE: MOBILE
   ============================================ */
@media (max-width: 768px) {
    #sidebar {
        display: none;
    }

    #content {
        margin-left: 0;
        max-width: 100vw;
        padding: 16px;
    }

    .panel-grid {
        grid-template-columns: 1fr;
    }

    .panel-4col,
    .panel-6col,
    .panel-8col,
    .panel-12col {
        grid-column: span 1;
    }

    .geo-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .fault-line-title {
        font-size: 28px;
    }

    .metric-row {
        flex-wrap: wrap;
    }

    .sparkline {
        width: 100%;
        margin-top: 4px;
    }
}
