:root {
    --accent-lamport: #f59e0b;
    --accent-vector: #6366f1;
    --accent-event: #22c55e;
    --accent-send: #ef4444;
    --accent-receive: #3b82f6;
    --clock-color: #06b6d4;
}

.tool-hero {
    margin-top: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.load-example-btn {
    margin-bottom: 12px;
    font-size: 0.875rem;
}

.load-example-btn svg {
    width: 16px;
    height: 16px;
}

.input-group[hidden] {
    display: none;
}

.mode-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.mode-btn:hover {
    border-color: var(--accent-lamport);
}

.mode-btn.active {
    border-color: var(--accent-lamport);
    background: rgba(245, 158, 11, 0.1);
}

.mode-btn svg {
    width: 24px;
    height: 24px;
}

.mode-btn span {
    font-size: 0.75rem;
    font-weight: 500;
}

.mode-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.4;
}

.process-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.process-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-input);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.process-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.process-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--process-color, var(--text-muted));
}

.process-name {
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.process-timestamp {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--clock-color);
}

.process-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.process-remove:hover {
    color: var(--accent-error);
}

.process-remove svg {
    width: 16px;
    height: 16px;
}

.hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}

.event-type-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 8px;
}

.event-type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.event-type-btn:hover {
    border-color: var(--accent-lamport);
}

.event-type-btn.active {
    border-color: var(--accent-event);
    background: rgba(34, 197, 94, 0.1);
}

.event-type-btn svg {
    width: 20px;
    height: 20px;
}

.event-type-btn span {
    font-size: 0.7rem;
    font-weight: 500;
}

.animation-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.animation-controls .tool-btn {
    padding: 12px;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.speed-control label {
    font-size: 0.875rem;
    white-space: nowrap;
}

.speed-control input[type="range"] {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-lamport);
    border-radius: 50%;
    cursor: pointer;
}

.speed-control input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent-lamport);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-lamport);
    width: 0%;
    transition: width 0.3s;
}

.event-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.main-layout {
    display: grid;
    grid-template-columns: 300px 1fr 280px;
    gap: 20px;
}

.main-layout > * {
    min-width: 0;
}

.visualization-panel,
.diagram-panel,
.diagram-container,
.timeline-view,
.timeline-content,
.timeline-container {
    min-width: 0;
}

.diagram-panel {
    min-height: 400px;
}

.diagram-container {
    position: relative;
    min-height: 400px;
    background: var(--bg-input);
    border-radius: 12px;
    overflow: hidden;
}

.diagram-panel.timeline-active {
    min-height: 0;
}

.diagram-container.timeline-active {
    min-height: 0;
    height: auto;
    overflow: hidden;
}

.diagram-container.timeline-active .timeline-view {
    position: relative;
    width: 100%;
    height: auto;
}

.diagram-mode-note {
    position: absolute;
    top: 16px;
    right: 16px;
    max-width: 280px;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--bg-card) 90%, transparent);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.45;
    pointer-events: none;
}

.diagram-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.diagram-container .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 12px;
}

.diagram-container .empty-state svg {
    width: 48px;
    height: 48px;
}

.diagram-container .empty-state p {
    font-size: 0.875rem;
}

.log-panel {
    min-height: 300px;
}

.log-container {
    height: 300px;
    overflow-y: auto;
    background: var(--bg-input);
    border-radius: 8px;
    padding: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
}

.log-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.log-entry {
    padding: 8px;
    margin-bottom: 8px;
    border-left: 3px solid var(--accent-lamport);
    background: var(--bg-card);
    border-radius: 0 4px 4px 0;
}

.log-entry.send {
    border-left-color: var(--accent-send);
}

.log-entry.receive {
    border-left-color: var(--accent-receive);
}

.log-entry.local {
    border-left-color: var(--accent-event);
}

.log-entry-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-weight: 600;
}

.log-entry-message {
    color: var(--text-muted);
}

.log-entry-timestamp {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.log-entry-id {
    color: var(--accent-lamport);
    font-weight: 500;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.action-buttons .tool-btn {
    padding: 8px 12px;
    font-size: 0.875rem;
}

.state-display {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.state-card {
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.state-card.current {
    border-color: var(--accent-lamport);
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.18);
}

.state-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-muted);
}

.state-empty p {
    font-size: 0.875rem;
}

.state-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.state-process-name {
    font-weight: 600;
    font-size: 1rem;
}

.state-timestamp {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    color: var(--clock-color);
}

.state-vector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.state-note {
    margin-top: 10px;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.vector-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: var(--bg-card);
    border-radius: 6px;
}

.vector-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.vector-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 6px;
}

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

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--accent-lamport);
}

.causality-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.causality-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.causality-section {
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

.causality-title {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.875rem;
}

.dependency-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dependency-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    padding: 6px;
    background: var(--bg-input);
    border-radius: 4px;
}

.dependency-item::before {
    content: '→';
    color: var(--text-muted);
}

.help-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 0.875rem;
    line-height: 1.5;
}

.help-content h3 {
    margin: 0;
    font-size: 0.875rem;
}

.help-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.help-content li {
    margin-bottom: 4px;
}

.help-content strong {
    color: var(--accent-lamport);
}

.view-toggles {
    display: flex;
    gap: 8px;
}

.view-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.view-actions .tool-btn,
.timeline-toolbar .tool-btn {
    padding: 8px 12px;
    font-size: 0.875rem;
}

.view-actions .tool-btn svg,
.timeline-toolbar .tool-btn svg {
    width: 16px;
    height: 16px;
}

.view-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.view-toggle:hover {
    border-color: var(--accent-lamport);
    color: var(--text-primary);
}

.view-toggle.active {
    border-color: var(--accent-lamport);
    color: var(--accent-lamport);
    background: rgba(245, 158, 11, 0.1);
}

.view-toggle svg {
    width: 16px;
    height: 16px;
}

/* Diagram View */
.diagram-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.diagram-view.hidden {
    display: none;
}

/* Timeline View */
.timeline-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
}

.timeline-view:not(.hidden) {
    display: flex;
    flex-direction: column;
}

.timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}

.timeline-hint {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.timeline-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px 0;
    background: var(--bg-card);
}

.timeline-caption {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.timeline-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.timeline-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    width: 100%;
}

.timeline-container {
    position: relative;
    min-height: 100%;
    min-width: 100%;
    width: 100%;
    padding: 28px 28px 40px;
    background: var(--bg-card);
}

.timeline-scale-shell {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.timeline-scale-stage {
    position: relative;
    transform-origin: top left;
}

.timeline-frame {
    position: relative;
    min-height: 100%;
    min-width: 100%;
    width: max-content;
}

.timeline-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.timeline-time-direction {
    display: flex;
    justify-content: flex-end;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-right: 8px;
}

.timeline-lanes {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 34px;
    z-index: 1;
}

.timeline-row {
    display: grid;
    grid-template-columns: 52px 1fr;
    align-items: center;
    gap: 18px;
    min-height: 86px;
    position: relative;
}

.timeline-row-label {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    align-self: center;
}

.timeline-track {
    flex: 1;
    height: 86px;
    position: relative;
    overflow: visible;
}

.timeline-axis {
    position: absolute;
    top: 50%;
    left: 0;
    right: 18px;
    height: 2px;
    background: var(--text-primary);
    opacity: 0.9;
    transform: translateY(-50%);
}

.timeline-axis::after {
    content: '';
    position: absolute;
    right: -1px;
    top: 50%;
    width: 12px;
    height: 12px;
    border-top: 2px solid var(--text-primary);
    border-right: 2px solid var(--text-primary);
    transform: translateY(-50%) rotate(45deg);
    transform-origin: center;
}

.timeline-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 18px;
    height: 18px;
    padding: 0;
    border-radius: 50%;
    background: var(--text-primary);
    border: 3px solid var(--bg-input);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 3;
    appearance: none;
    -webkit-appearance: none;
}

.timeline-marker:hover {
    transform: translate(-50%, -50%) scale(1.15);
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.18);
}

.timeline-marker.current {
    box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.28);
}

.timeline-marker-label {
    position: absolute;
    bottom: calc(50% + 16px);
    left: 50%;
    transform: translateX(-50%);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.05rem;
    font-style: italic;
    color: var(--text-primary);
    pointer-events: none;
    white-space: nowrap;
}

.timeline-marker-time {
    position: absolute;
    top: calc(50% + 16px);
    left: 50%;
    transform: translateX(-50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-muted);
    pointer-events: none;
    white-space: nowrap;
}

.timeline-message-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 2;
}

.timeline-message-path {
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 1.3;
}

.timeline-message-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.66rem;
    fill: var(--text-muted);
}

.timeline-legend-box {
    position: absolute;
    right: 16px;
    bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 180px;
    padding: 12px 14px;
    background: color-mix(in srgb, var(--bg-card) 90%, transparent);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    z-index: 3;
}

.timeline-legend-row {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.timeline-legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-primary);
    flex: 0 0 auto;
}

.timeline-legend-arrow {
    position: relative;
    width: 46px;
    height: 2px;
    background: var(--text-muted);
    flex: 0 0 auto;
}

.timeline-legend-arrow::after {
    content: '';
    position: absolute;
    right: -1px;
    top: 50%;
    width: 10px;
    height: 10px;
    border-top: 2px solid var(--text-muted);
    border-right: 2px solid var(--text-muted);
    transform: translateY(-50%) rotate(45deg);
}

.timeline-popup {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 14px);
    transform: translateX(-50%);
    width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.timeline-popup::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--border-color);
}

.timeline-popup::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--bg-card);
    margin-top: -1px;
}

.timeline-popup-title {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.875rem;
}

.timeline-popup-content {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.dependency-item::before {
    content: '->';
    color: var(--text-muted);
}

.timeline-event-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.timeline-event-type {
    font-weight: 600;
}

.timeline-event-process {
    color: var(--accent-lamport);
}

.timeline-event-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
}

.timeline-message {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

/* Responsive */
@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 280px 1fr;
    }

    .sidebar:last-child {
        display: none;
    }
}

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

    .sidebar {
        order: 2;
    }

    .visualization-panel {
        order: 1;
    }
}

@media (max-width: 768px) {
    .diagram-panel {
        min-height: 300px;
    }

    .diagram-container {
        min-height: 300px;
    }

    .event-type-selector {
        grid-template-columns: repeat(3, 1fr);
    }

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

    .timeline-marker {
        width: 14px;
        height: 14px;
    }

    .timeline-row {
        grid-template-columns: 42px 1fr;
        gap: 12px;
        min-height: 74px;
    }

    .timeline-marker-label {
        font-size: 0.95rem;
    }

    .timeline-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .view-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .timeline-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .timeline-toolbar-actions {
        width: 100%;
    }

    .timeline-legend-box {
        position: static;
        margin-top: 18px;
        width: 100%;
        min-width: 0;
    }
}
