/* =========================================================
   5.03 System Bus Widget
   ========================================================= */

.system-bus-widget {
    margin: 1.5rem 0;
    padding: 1.25rem;
    border-radius: 24px;
    background: linear-gradient(135deg, #f8fafc, #eef2ff);
    border: 1px solid #dbeafe;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

.bus-widget-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1.2rem;
}

.bus-mode-btn,
.bus-widget-controls button {
    border: none;
    border-radius: 999px;
    padding: 0.65rem 1rem;
    font-weight: 700;
    cursor: pointer;
    background: white;
    color: #334155;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.bus-mode-btn:hover,
.bus-widget-controls button:hover {
    transform: translateY(-2px);
}

.bus-mode-btn.active {
    background: #0f172a;
    color: white;
}

.bus-simulation-panel {
    display: grid;
    grid-template-columns: 180px minmax(260px, 1fr) 220px;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
    border-radius: 22px;
    background: white;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

.bus-component {
    min-height: 110px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
    border: 2px solid #cbd5e1;
    background: #f8fafc;
    color: #0f172a;
    transition: all 0.25s ease;
}

.bus-component.active-node {
    transform: scale(1.03);
    border-color: #2563eb;
    box-shadow: 0 14px 32px rgba(37, 99, 235, 0.16);
}

.component-label {
    font-size: 1.15rem;
    font-weight: 850;
}

.component-small {
    margin-top: 0.35rem;
    font-size: 0.82rem;
    color: #64748b;
}

.bus-targets {
    display: grid;
    gap: 0.85rem;
}

.bus-targets .bus-component {
    min-height: 88px;
}

.bus-lines {
    position: relative;
    display: grid;
    gap: 1rem;
    padding: 0.8rem 0;
}

.bus-line {
    position: relative;
    height: 42px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 850;
    letter-spacing: 0.02em;
    color: #0f172a;
    opacity: 0.45;
    transition: opacity 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.bus-line::before,
.bus-line::after {
    content: "";
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
}

.bus-line::after {
    right: -8px;
    border-left: 14px solid currentColor;
}

.data-line::before,
.control-line::before {
    left: -8px;
    border-right: 14px solid currentColor;
}

.address-line {
    background: #dbeafe;
    color: #1d4ed8;
}

.data-line {
    background: #dcfce7;
    color: #15803d;
}

.control-line {
    background: #ffedd5;
    color: #c2410c;
}

.bus-line.active-line {
    opacity: 1;
    transform: scaleY(1.08);
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.10);
}

.bus-pulse {
    position: absolute;
    left: 8px;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #0f172a;
    box-shadow: 0 0 0 8px rgba(15, 23, 42, 0.10);
    opacity: 0;
    transform: translateY(-50%);
    pointer-events: none;
}

.bus-pulse.animate-forward {
    opacity: 1;
    animation: busPulseForward 1.1s ease-in-out forwards;
}

.bus-pulse.animate-backward {
    opacity: 1;
    animation: busPulseBackward 1.1s ease-in-out forwards;
}

.bus-pulse.address-pulse { top: 29px; background: #2563eb; }
.bus-pulse.data-pulse { top: 87px; background: #16a34a; }
.bus-pulse.control-pulse { top: 145px; background: #ea580c; }

@keyframes busPulseForward {
    from { left: 8px; }
    to { left: calc(100% - 30px); }
}

@keyframes busPulseBackward {
    from { left: calc(100% - 30px); }
    to { left: 8px; }
}

.bus-status-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    margin: 1rem 0;
}

.bus-status-card {
    padding: 0.9rem 1rem;
    border-radius: 18px;
    background: white;
    border: 1px solid #e2e8f0;
}

.bus-status-card strong,
.bus-status-card span {
    display: block;
}

.bus-status-card span {
    margin-top: 0.35rem;
    color: #64748b;
    font-size: 0.9rem;
}

.bus-status-card.active-status {
    border-color: #2563eb;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.12);
}

.bus-step-card {
    padding: 1rem 1.1rem;
    border-radius: 20px;
    background: #0f172a;
    color: white;
}

.bus-step-card h3 {
    margin: 0.25rem 0 0.4rem;
    color: white;
}

.bus-step-card p {
    color: #e2e8f0;
}

.bus-step-counter {
    margin: 0;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #bfdbfe !important;
    font-weight: 800;
}

.bus-widget-controls {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.bus-widget-controls button {
    background: white;
    color: #0f172a;
}

@media (max-width: 820px) {
    .bus-simulation-panel {
        grid-template-columns: 1fr;
    }

    .bus-lines {
        min-height: 180px;
    }

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