html {
    scrollbar-gutter: stable;
}

/* Root Theme Variables */
:root {
    --bg-gradient: linear-gradient(135deg, #0f1016 0%, #151722 100%);
    --card-bg: rgba(22, 25, 38, 0.7);
    --card-border: rgba(255, 255, 255, 0.06);
    --text-primary: #f1f3f9;
    --text-secondary: #8e95a5;
    --accent: #10b981; /* Emerald Green */
    --accent-glow: rgba(16, 185, 129, 0.35);
    --pi-color: #3b82f6; /* Blue */
    --agy-color: #a855f7; /* Purple */
    --danger: #ef4444;
    --console-bg: #090a0f;
    --console-border: rgba(255, 255, 255, 0.03);
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'Fira Code', monospace;
}

/* Reset and Core Layout */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 0.75rem;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 1400px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Glassmorphism Card System */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Header Styling */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 1rem;
    position: relative;
    z-index: 100;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 1.75rem;
    color: var(--accent);
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.accent-text {
    color: var(--accent);
    font-weight: 400;
}

.header-subtitle {
    font-size: 0.9rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    opacity: 0.5;
    vertical-align: middle;
    display: inline-block;
}

.header-subtitle::before {
    content: "|";
    margin: 0 0.75rem;
    color: rgba(255, 255, 255, 0.15);
    font-weight: 300;
}

.mode-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    transition: all 0.3s ease;
}

.mode-none {
    background: rgba(142, 149, 165, 0.15);
    color: var(--text-secondary);
}

.mode-pi {
    background: rgba(59, 130, 246, 0.2);
    color: var(--pi-color);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.mode-agy {
    background: rgba(168, 85, 247, 0.2);
    color: var(--agy-color);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.2);
}

/* Workspace Layout */
.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
    }
}

/* Left Panel: Control Panel */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.action-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.action-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.action-btn:active {
    transform: translateY(0);
}

/* Mode Switcher Group */
.mode-selector-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mode-btn-group {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.25rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.mode-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.mode-btn.active[data-mode="PI"],
.mode-btn.active[data-source="PI"],
.mode-btn.active[data-source="WORKSPACE1"] {
    background: var(--pi-color);
    color: white;
}

.mode-btn.active[data-mode="AGY"],
.mode-btn.active[data-source="AGY"],
.mode-btn.active[data-source="WORKSPACE2"] {
    background: var(--agy-color);
    color: white;
}

.mode-btn.active[data-mode="NONE"] {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Health Panel / Telemetry Metrics */
.health-panel {
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.metric-card {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    padding: 0.6rem 0.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

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

.metric-value {
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

.backup-status-row {
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.15);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    border-left: 3px solid var(--text-secondary);
}

.status-value {
    font-weight: 600;
}

.status-success {
    color: var(--accent);
}

.status-unknown {
    color: var(--text-secondary);
}

/* Right Panel: HUD Console */
.hud-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 600px;
}

.hud-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hud-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.hud-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.highlight-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: #0f1016;
}

.highlight-btn:hover {
    background: #0d9488;
    box-shadow: 0 0 12px var(--accent-glow);
}

.context-provenance {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: var(--font-mono);
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
}

.context-provenance strong {
    color: var(--text-primary);
    font-weight: 600;
}

.hud-console-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--console-bg);
    border: 1px solid var(--console-border);
    border-radius: 8px;
    overflow: hidden;
}

.console-tab-bar {
    display: flex;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    padding: 0.75rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(255, 255, 255, 0.01);
}

.console-body {
    flex: 1;
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: var(--console-font-size, 0.9rem);
    line-height: 1.5;
    overflow-y: auto;
    white-space: pre-wrap;
}

.terminal-line {
    margin-bottom: 0.5rem;
}

.system-msg {
    color: var(--text-secondary);
}

.success-msg {
    color: var(--accent);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: #111827;
    border: 1px solid var(--accent);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.hidden {
    opacity: 0;
    transform: translate(-50%, 1rem);
    pointer-events: none;
}

/* Context Hub v2.2 Layout Refinement: sidecar cognitive instrument */
body {
    padding: 0.75rem;
}

.app-container {
    max-width: 100%;
    min-height: calc(100vh - 1.5rem);
    gap: 0.65rem;
}

.compact-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding-bottom: 0.55rem;
}

.compact-header .logo-area {
    align-self: flex-start;
}

.compact-header .header-nav {
    align-self: flex-end;
}

.compact-header h1 {
    font-size: 1.05rem;
    white-space: nowrap;
}

.compact-header .logo-icon {
    font-size: 1.25rem;
}

.source-control {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: nowrap;
}

.source-label {
    color: var(--text-secondary);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.compact-source-group {
    width: 120px;
    gap: 0.2rem;
    padding: 0.15rem;
}

.compact-source-group .mode-btn {
    padding: 0.35rem 0.45rem;
    font-size: 0.78rem;
}

.compact-provenance {
    padding: 0.45rem 0.65rem;
    gap: 0.55rem;
    font-size: 0.74rem;
    align-items: center;
}

.system-status-strip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.55rem;
    padding: 0.42rem 0.65rem;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(255, 255, 255, 0.025);
    box-shadow: none;
    backdrop-filter: none;
}

.system-status-strip strong,
.system-status-strip .status-success,
.system-status-strip .status-unknown {
    color: var(--text-secondary);
    font-weight: 500;
    text-shadow: none;
    box-shadow: none;
}

.status-prefix {
    color: var(--text-secondary);
    font-family: var(--font-sans);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.context-workspace {
    display: block;
    flex: 1;
    min-height: 0;
}

.context-primary-panel {
    height: calc(100vh - 10.2rem);
    min-height: 520px;
    padding: 0.85rem;
    gap: 0.65rem;
}

.hud-header h2 {
    margin-bottom: 0;
}

.hud-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
}

.console-tab-bar {
    flex: 0 0 auto;
}

.tab-btn {
    padding: 0.55rem 0.8rem;
    font-size: 0.78rem;
}

.console-body {
    padding: 0.8rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.glass-card {
    padding: 0.75rem;
}

/* Keep automatic refresh visually quiet: no content-area transition/flash. */
.console-body,
.console-body * {
    transition: none !important;
    animation: none !important;
}

@media (max-width: 900px) {
    .app-container {
        max-width: 100%;
    }

    .compact-header {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .header-nav {
        width: 100%;
        justify-content: center;
    }

    .source-control {
        width: 100%;
        justify-content: space-between;
    }

    .compact-source-group {
        flex: 1;
        max-width: 180px;
    }

    .context-primary-panel {
        height: calc(100vh - 12.2rem);
        min-height: 440px;
    }
}

/* Unified Folded Document Reader styling */
.unified-document {
    display: flex;
    flex-direction: column;
    background: var(--console-bg);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.5;
    overflow: hidden;
}

.document-section {
    display: flex;
    flex-direction: column;
}

.document-line {
    display: flex;
    align-items: flex-start;
}

.line-number {
    width: 2.8rem;
    text-align: right;
    padding-right: 0.75rem;
    color: rgba(255, 255, 255, 0.15);
    user-select: none;
    flex-shrink: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    margin-right: 0.75rem;
}

.line-content {
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-primary);
}

.document-fold {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.025);
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
    margin: 0.75rem 0;
    padding: 0.65rem 0;
    width: 100%;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.document-fold:hover {
    background: rgba(255, 255, 255, 0.06);
    border-top-style: solid;
    border-bottom-style: solid;
    border-color: var(--accent, #3b82f6);
}

.document-fold:hover .fold-message {
    opacity: 1;
    color: var(--accent, #3b82f6);
}

.fold-indicator {
    display: none;
}

.fold-message {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-family: var(--font-sans);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    opacity: 0.65;
    font-weight: 700;
    user-select: none;
    text-align: center;
    transition: color 0.2s ease, opacity 0.2s ease;
}

.document-middle {
    background: rgba(255, 255, 255, 0.015);
    border-left: 2px dashed var(--accent, #3b82f6);
}

.document-middle .line-number {
    color: rgba(255, 255, 255, 0.25);
}

/* Composition-based differentiation instead of labels */
.document-head {
    background: rgba(255, 255, 255, 0.005);
}

.document-tail {
    background: linear-gradient(to bottom, rgba(16, 185, 129, 0.01) 0%, rgba(16, 185, 129, 0.02) 100%);
}

.document-tail .line-number {
    color: rgba(16, 185, 129, 0.35);
    border-right-color: rgba(16, 185, 129, 0.1);
}

/* Layout adjustments to ensure both windows fit simultaneously without scrollbars */
.app-container {
    gap: 0.42rem;
}

.compact-header {
    padding-bottom: 0.35rem;
}

.compact-provenance {
    padding: 0.32rem 0.55rem;
}

.system-status-strip {
    padding: 0.3rem 0.55rem;
}

.context-primary-panel {
    height: calc(100vh - 8.2rem);
    min-height: 250px;
    padding: 0.5rem;
    gap: 0.38rem;
    resize: vertical;
    overflow: hidden;
}

.hud-header {
    min-height: 0;
}

.hud-header h2 {
    font-size: 1.05rem;
    line-height: 1.1;
}

.hud-btn {
    padding: 0.28rem 0.6rem;
}

.tab-btn {
    padding: 0.38rem 0.65rem;
}

.console-body {
    padding: 0.38rem;
    overflow-y: auto;
}

/* Stabilized 3-Column Header Layout */
.hud-header {
    display: grid !important;
    grid-template-columns: 1fr auto 1fr !important;
    align-items: center !important;
    width: 100% !important;
}

.hud-title {
    justify-self: start;
    margin-bottom: 0;
}

.hud-actions {
    justify-self: end;
}

.timeline-nav {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    padding: 0.15rem;
}

.nav-arrow-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.nav-arrow-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
}

.nav-arrow-btn:disabled {
    color: rgba(255, 255, 255, 0.12);
    cursor: not-allowed;
}

.timeline-indicator {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 0 0.45rem;
    color: var(--text-secondary);
    min-width: 72px;
    text-align: center;
    user-select: none;
}

/* Historical Context Visual Distinction */
.timeline-indicator.historical-active {
    color: #f59e0b; /* Warm warning amber */
    font-weight: 700;
    text-shadow: 0 0 8px rgba(245, 158, 11, 0.2);
}

.hud-panel.historical-active {
    border-color: rgba(245, 158, 11, 0.22) !important;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.42), 0 0 16px rgba(245, 158, 11, 0.04) !important;
}

.unified-document.historical-active {
    border-top: 2px solid rgba(245, 158, 11, 0.3) !important;
}

/* History tab checkbox list styling */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    user-select: none;
    max-height: 100%;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.history-item {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.1);
}

.history-item.selected {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.45);
    box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.12) inset;
}

.history-item label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.history-checkbox {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 16px;
    height: 16px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.history-checkbox:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.history-checkbox:checked::after {
    content: "✓";
    color: #0f1016;
    font-size: 0.75rem;
    font-weight: 700;
}

.history-time {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.8rem;
    flex-shrink: 0;
}

.history-name {
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Navigation Header Styles */
.app-header.compact-header {
    display: flex;
    flex-direction: column;
}

.header-nav {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    width: 320px;
    justify-content: flex-end;
}

.nav-row-1 {
    justify-content: flex-end;
}

.nav-row-2 {
    width: 100%;
    justify-content: flex-start;
}
.workspace-selector {
    flex-wrap: wrap;
    gap: 0.3rem;
    align-self: stretch;
}
.workspace-selector-label {
    align-self: center;
    color: rgba(142, 149, 165, 0.78);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    margin-right: 0.12rem;
    text-transform: uppercase;
}
.workspace-slot {
    min-width: 2.28rem;
    text-align: center;
}
.operational-slot {
    border-color: rgba(255, 255, 255, 0.08);
}
.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: all 0.2s ease-in-out;
}
.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}
.nav-link.active {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--accent);
}

/* Terminal Console Layout */
.console-workspace {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}
.console-panel {
    height: calc(100vh - 8.2rem);
    min-height: 400px;
    display: flex;
    flex-direction: column;
    resize: vertical;
    overflow: hidden;
}


