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

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --accent: #3b82f6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.header-stats {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    font-weight: 600;
}

.status-badge.healthy {
    border: 2px solid var(--success);
}

.status-badge.warning {
    border: 2px solid var(--warning);
}

.status-badge.error {
    border: 2px solid var(--error);
}

#status-icon {
    font-size: 1.2rem;
}

.status-badge.healthy #status-icon {
    color: var(--success);
}

.status-badge.warning #status-icon {
    color: var(--warning);
}

.status-badge.error #status-icon {
    color: var(--error);
}

.budget, .uptime {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.budget span:last-child,
.uptime span:last-child {
    color: var(--text-primary);
    font-weight: 600;
    margin-left: 0.25rem;
}

/* Time Range Selector */
/* time-range-selector removed — always shows 24h */

/* Grid Layout */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
}

.card h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.count-badge {
    font-size: 0.875rem;
    background: var(--accent);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 600;
}

/* Stats Grid */
.health-grid,
.costs-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.stat {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 0.5rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-value.cost {
    color: var(--accent);
}

/* Restart count color coding */
.stat-value.restart-count.restart-low {
    color: var(--success);
}

.stat-value.restart-count.restart-medium {
    color: var(--warning);
}

.stat-value.restart-count.restart-high {
    color: var(--error);
}

.stat-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Chart Container */
.chart-container {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.chart-container h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.chart-container canvas {
    max-height: 200px;
}

/* Workers List */
.workers-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
}

.worker-item {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 0.5rem;
    border-left: 3px solid var(--accent);
    cursor: pointer;
    transition: all 0.2s;
}

.worker-item:hover {
    background: var(--border-color);
    transform: translateX(4px);
}

.worker-item.in_progress {
    border-left-color: var(--accent);
}

.worker-item.completed {
    border-left-color: var(--success);
}

.worker-item.failed {
    border-left-color: var(--error);
}

.worker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.worker-id {
    font-weight: 600;
    font-size: 0.9rem;
}

.worker-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    text-transform: capitalize;
    font-weight: 600;
}

.worker-status.in_progress {
    background: var(--accent);
    color: white;
}

.worker-status.completed {
    background: var(--success);
    color: white;
}

.worker-status.failed {
    background: var(--error);
    color: white;
}

.worker-progress {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.worker-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    gap: 1rem;
}

/* Actions List */
.actions-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
}

.action-item {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
}

.action-time {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}

.action-text {
    color: var(--text-primary);
}

.action-text strong {
    color: var(--accent);
}

/* Model Costs */
.model-costs {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.model-costs h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.model-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.model-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 0.25rem;
}

.model-name {
    font-weight: 600;
}

.model-cost {
    color: var(--accent);
    font-weight: 600;
}

.model-count {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 5% auto;
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
}

.close {
    color: var(--text-secondary);
    float: right;
    font-size: 2rem;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: var(--text-primary);
}

.modal-body {
    margin-top: 1rem;
}

.modal-section {
    margin-bottom: 1.5rem;
}

.modal-section h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.modal-field {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 0.5rem;
    color: var(--text-primary);
}

.modal-field.task-desc {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

.modal-field ul {
    list-style: none;
    padding: 0;
}

.modal-field li {
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border-color);
}

.modal-field li:last-child {
    border-bottom: none;
}

.modal-field code {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* External link in card heading */
.external-link {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--accent);
    text-decoration: none;
    margin-left: 0.75rem;
}

.external-link:hover {
    text-decoration: underline;
}

/* Vault type bar */
.type-bar-container {
    margin: 1rem 0;
}

.type-bar-container h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.type-bar {
    display: flex;
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    gap: 2px;
}

.type-bar-segment {
    height: 100%;
    min-width: 2px;
    transition: opacity 0.2s;
}

.type-bar-segment:hover {
    opacity: 0.8;
}

.type-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.type-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.type-label-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Top nodes list */
.top-nodes-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.top-node-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.top-node-id {
    font-family: monospace;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.top-node-count {
    color: var(--accent);
    font-weight: 600;
    flex-shrink: 0;
}

/* Library detail rows */
.lib-detail {
    margin-top: 0.75rem;
}

.stat-value-text {
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-top: 0.25rem;
    line-height: 1.4;
}

/* Worker category list */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.category-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.category-name {
    width: 70px;
    font-weight: 600;
    text-transform: capitalize;
}

.category-bar-wrap {
    flex: 1;
    background: var(--bg-tertiary);
    border-radius: 3px;
    height: 8px;
    overflow: hidden;
}

.category-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--accent);
    transition: width 0.3s;
}

.category-stats {
    color: var(--text-secondary);
    font-size: 0.75rem;
    white-space: nowrap;
    min-width: 80px;
    text-align: right;
}

/* Footer */
.footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auto-refresh {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#refresh-indicator {
    color: var(--success);
    animation: pulse 2s ease-in-out infinite;
}

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

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* ─── Story Panels ─── */

.story-panel {
    background: #0a0a0a;
    border: 1px solid #2a2a2a;
    border-radius: 0.75rem;
    padding: 1.75rem 2rem;
    margin-bottom: 1.5rem;
}

/* Panel A — Hero */

.hero-panel {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 2.5rem;
    align-items: center;
    border-color: #E8553A;
}

.hero-title {
    font-family: 'Courier New', Courier, monospace;
    font-size: 3rem;
    font-weight: 700;
    color: #E8553A;
    letter-spacing: 0.05em;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.hero-tagline {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.875rem;
    color: #94a3b8;
    margin-bottom: 1.25rem;
    letter-spacing: 0.03em;
}

.hero-desc {
    font-size: 0.875rem;
    color: #cbd5e1;
    line-height: 1.75;
}

/* Architecture Diagram */

.hero-diagram {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.arch-label {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: #E8553A;
    margin-bottom: 0.75rem;
}

.arch-diagram {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
}

.arch-node {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.75rem;
    color: #E8553A;
    background: #110a08;
    border: 1px solid #5a2010;
    border-radius: 3px;
    padding: 0.3rem 0.7rem;
    white-space: nowrap;
}

.arch-node-io {
    border-color: #E8553A;
    color: #ff7a5a;
}

.arch-node-cluster {
    border-style: dashed;
    color: #f59e0b;
    border-color: #7a5000;
    background: #110d04;
}

.arch-connector {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.75rem;
    color: #4a3a30;
    padding: 0.1rem 0.7rem;
    line-height: 1.2;
}

/* Panel B — Scope */

.scope-header {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: #E8553A;
    margin-bottom: 1.5rem;
}

.scope-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    text-align: center;
}

.scope-stat-value {
    font-family: 'Courier New', Courier, monospace;
    font-size: 2.75rem;
    font-weight: 700;
    color: #f1f5f9;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.scope-stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
}

/* Panel C — Timeline */

.timeline {
    display: flex;
    flex-direction: column;
}

.timeline-item {
    display: flex;
    gap: 1rem;
    padding-bottom: 1.25rem;
    padding-left: 0.5rem;
    position: relative;
}

/* Vertical connector line between items */
.timeline-item:not(.timeline-item-last) {
    border-left: 1px solid #2a2a2a;
}

.timeline-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #5a2010;
    border: 1px solid #E8553A;
    flex-shrink: 0;
    margin-top: 4px;
    margin-left: -5px;
}

.timeline-dot-active {
    background: #E8553A;
    box-shadow: 0 0 6px rgba(232, 85, 58, 0.5);
}

.timeline-content {
    padding-bottom: 0;
    padding-left: 0.5rem;
}

.timeline-date {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.7rem;
    color: #E8553A;
    margin-bottom: 0.2rem;
    letter-spacing: 0.03em;
}

.timeline-text {
    font-size: 0.875rem;
    color: #94a3b8;
    line-height: 1.5;
}

/* ─── End Story Panels ─── */

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-stats {
        flex-wrap: wrap;
        gap: 1rem;
    }


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

    .health-grid,
    .costs-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 1rem;
    }

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

    .hero-title {
        font-size: 2rem;
    }

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

    .scope-stat-value {
        font-size: 2rem;
    }
}
