/* style.css - RISC-V SoC Simulator (Ripes-like Layout) */

/* --- RESET & BASE STYLES --- */
:root {
    --sidebar-width: 80px;
    --sidebar-bg: #2d3436;
    --sidebar-text: #b2bec3;
    --sidebar-active-bg: #0984e3;
    --sidebar-active-text: #ffffff;

    --header-height: 60px;
    --border-color: #dfe6e9;
    --bg-light: #f5f6fa;
    --bg-white: #ffffff;

    --primary-color: #6200ee;
    --accent-color: #018786;
    --error-color: #b00020;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-light);
    color: #333;
    overflow: hidden;
    /* Ngăn cuộn trang chính */
}

/* --- MAIN LAYOUT CONTAINER --- */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* --- 1. SIDEBAR STYLES --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
    z-index: 100;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.sidebar-item {
    width: 100%;
    height: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.75rem;
    border-left: 4px solid transparent;
}

.sidebar-item i {
    font-size: 28px;
    margin-bottom: 4px;
}

.sidebar-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.sidebar-item.active {
    color: var(--sidebar-active-text);
    background-color: rgba(9, 132, 227, 0.1);
    border-left-color: var(--sidebar-active-bg);
}

.sidebar-help {
    margin-top: auto;
    margin-bottom: 10px;
}

/* --- 2. MAIN CONTENT AREA --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-light);
    overflow: hidden;
    position: relative;
}

/* --- TOOLBAR --- */
.toolbar {
    height: var(--header-height);
    background-color: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.toolbar-group {
    display: flex;
    gap: 12px;
    align-items: center;
    min-width: max-content;
}

.separator {
    width: 1px;
    height: 32px;
    background-color: #e0e0e0;
    margin: 0 8px;
}

.success-btn {
    background-color: #00b894 !important;
    color: white !important;
}

.pause-btn {
    border-color: #f39c12 !important;
    color: #d35400 !important;
}

.stop-btn {
    border-color: var(--error-color) !important;
    color: var(--error-color) !important;
}

.mdc-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* [MỚI] Style cho thanh tốc độ */
.speed-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
    font-size: 0.8rem;
    color: #636e72;
    width: 120px;
}

.speed-control input[type=range] {
    width: 100%;
    cursor: pointer;
    height: 4px;
    background: #dfe6e9;
    border-radius: 2px;
    appearance: none;
    /* Xóa style mặc định của trình duyệt */
}

.speed-control input[type=range]::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: background .15s ease-in-out;
}

.speed-control input[type=range]::-webkit-slider-thumb:hover {
    background: var(--sidebar-active-bg);
}

/* --- VIEW SECTIONS (Tab Content) --- */
.view-section {
    display: none;
    /* Ẩn mặc định */
    flex: 1;
    padding: 15px;
    padding-bottom: 50px;
    /* 15px original padding + 35px for Log Terminal */
    overflow: hidden;
    height: calc(100vh - var(--header-height));
}

.view-section.active {
    display: block;
    animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0.95;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- EDITOR VIEW LAYOUT --- */
.editor-layout {
    display: flex;
    height: 100%;
    gap: 15px;
}

.editor-left {
    flex: 3;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 400px;
}

.editor-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    min-width: 320px;
    max-width: 450px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

/* Code Area & CodeMirror Overrides */
.code-area {
    flex: 2;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.CodeMirror {
    height: 100% !important;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.5;
}

/* Placeholder mờ khi editor trống */
.CodeMirror pre.CodeMirror-placeholder {
    color: #b2bec3;
    pointer-events: none;
}

.CodeMirror-gutters {
    background-color: #f7f9fa;
    border-right: 1px solid #dfe6e9;
    white-space: nowrap;
}

/* Tăng khoảng cách cột breakpoint */
.breakpoints {
    width: 25px;
    text-align: center;
}

.CodeMirror-guttermarker-subtle {
    color: #e52d2d;
    font-size: 1.4em;
    line-height: 1.1;
    cursor: pointer;
}

/* RISC-V autocomplete popup */
.CodeMirror-hints {
    z-index: 2500;
    min-width: 360px;
    max-width: min(720px, calc(100vw - 40px));
    max-height: 320px;
    border: 1px solid #9db5e8;
    border-radius: 4px;
    background: #ffffff;
    box-shadow: 0 10px 24px rgba(45, 52, 54, 0.18);
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    padding: 4px;
}

.CodeMirror-hint {
    padding: 0;
    border-radius: 3px;
    white-space: normal;
    color: #2d3436;
}

li.CodeMirror-hint-active,
.CodeMirror-hints .CodeMirror-hint-active {
    background: #f3f8ff;
    color: #1f2d3d;
}

.riscv-hint-content {
    display: grid;
    grid-template-columns: minmax(92px, max-content) minmax(0, 1fr);
    gap: 8px 14px;
    align-items: baseline;
    padding: 7px 9px;
}

.riscv-hint-main {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.riscv-hint-label {
    color: #1d4ed8;
    font-weight: 700;
}

.CodeMirror-hint-active .riscv-hint-label {
    color: #0f3b82;
}

.riscv-hint-badge {
    border: 1px solid #d7dee8;
    border-radius: 3px;
    color: #607083;
    font-family: 'Roboto', sans-serif;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0;
    padding: 1px 4px;
    text-transform: uppercase;
}

.CodeMirror-hint-active .riscv-hint-badge {
    background: #ffffff;
    border-color: #b8c8dd;
    color: #46596f;
}

.CodeMirror-hint-active .riscv-hint-detail,
.CodeMirror-hint-active .riscv-hint-syntax,
.CodeMirror-hint-active .riscv-hint-example {
    color: #263545;
}

.riscv-hint-detail {
    min-width: 0;
    color: #3d4852;
    font-family: 'Roboto', sans-serif;
    font-size: 12px;
    line-height: 1.35;
}

.riscv-hint-syntax {
    grid-column: 1 / -1;
    color: #5f6f82;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.riscv-hint-example {
    grid-column: 1 / -1;
    color: #2f3a46;
    font-size: 12px;
    overflow-wrap: anywhere;
}

/* Console Area */
.console-area {
    flex: 1;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

/* === TAB STYLE (NEW) === */
.register-tabs {
    display: flex;
    background-color: #f1f2f6;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.tab-item {
    flex: 1;
    text-align: center;
    padding: 12px 10px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #636e72;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
}

.tab-item:hover {
    background-color: rgba(0, 0, 0, 0.03);
    color: #2d3436;
}

.tab-item:focus-visible {
    outline: 2px solid var(--sidebar-active-bg);
    outline-offset: -2px;
}

.tab-item.active {
    background-color: #fff;
    color: var(--sidebar-active-bg);
    border-bottom-color: var(--sidebar-active-bg);
    font-weight: 600;
}

.panel-header {
    background-color: #f1f2f6;
    padding: 10px 15px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #2d3436;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

#binaryOutput {
    margin: 0;
    padding: 12px;
    flex: 1;
    overflow: auto;
    font-family: 'Consolas', monospace;
    font-size: 0.85rem;
    background-color: #fff;
    color: #2d3436;
    white-space: pre-wrap;
    border: none;
}

/* --- REGISTER TABLE --- */
.register-container {
    flex: 1;
    overflow: auto;
    position: relative;
}

/* --- MEMORY VIEW LAYOUT --- */
.memory-layout {
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: 100%;
}

.memory-panel {
    flex: 1;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.memory-panel h3 {
    margin: 0;
    padding: 12px 15px;
    background-color: #f1f2f6;
    font-size: 1rem;
    border-bottom: 1px solid var(--border-color);
    color: #2d3436;
}

.memory-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background-color: #fff;
    border-bottom: 1px solid #eee;
}

.control-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.control-group input {
    padding: 6px 10px;
    border: 1px solid #dfe6e9;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
}

.control-group button {
    padding: 6px 12px;
    background-color: #f1f2f6;
    border: 1px solid #dfe6e9;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.control-group button:hover {
    background-color: #e1e2e6;
}

/* --- COMMON TABLE STYLES --- */
.table-scroll-container {
    flex: 1;
    overflow: auto;
}

.simple-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    font-family: 'Consolas', monospace;
}

.simple-table th {
    background-color: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 5;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid #dfe6e9;
    border-right: 1px solid #eee;
    color: #636e72;
    font-weight: 600;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

.simple-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f2f6;
    border-right: 1px solid #f5f6fa;
    color: #2d3436;
}

.simple-table tr:hover td {
    background-color: #f5f6fa;
}

/* Highlights */
.pc-highlight td {
    background-color: #dff9fb !important;
    color: #000;
}

.highlight td {
    background-color: #ffeaa7 !important;
    transition: background-color 0.5s ease;
}

.tlb-highlight td {
    background-color: #e6ffed !important; /* Soft green highlight for active TLB entry */
    color: #0f5132 !important;
    font-weight: 500;
}

.mmu-value-changed {
    animation: mmuValuePulse 0.85s ease-out;
}

@keyframes mmuValuePulse {
    0% {
        background-color: #fff2a8;
        box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.35), 0 0 0 0 rgba(245, 158, 11, 0.28);
    }
    45% {
        background-color: #dff9fb;
        box-shadow: inset 0 0 0 1px rgba(9, 132, 227, 0.2), 0 0 0 5px rgba(9, 132, 227, 0.08);
    }
    100% {
        background-color: transparent;
        box-shadow: inset 0 0 0 0 rgba(9, 132, 227, 0), 0 0 0 0 rgba(9, 132, 227, 0);
    }
}

/* --- I/O STYLES (LED Matrix) --- */
.io-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 20px;
    padding-bottom: 70px;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
    height: 100%;
    box-sizing: border-box;
}

.io-device-card {
    background: #fff;
    border: 1px solid #dfe6e9;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 340px;
    max-width: 100%;
    /* Vừa đủ cho canvas 320px + padding */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s;
}

#view-io .io-device-card {
    flex: 0 1 340px;
}

#view-io .io-device-card:nth-child(2) {
    flex-basis: 600px;
    width: auto !important;
}

#view-io .io-device-card:nth-child(3) {
    flex-basis: 300px;
    width: auto !important;
}

.io-device-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.io-header {
    background-color: #2d3436;
    color: #fff;
    padding: 12px 15px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
}

.io-body {
    padding: 10px;
    background-color: #fff;
    /* Nền trắng mặc định */
    display: flex;
    justify-content: center;
    align-items: center;
}

.led-matrix-body {
    background-color: #636e72;
    /* Nền xám đậm làm nổi bật LED */
    min-height: auto;
}

.uart-console-body {
    background-color: #fff;
    padding: 15px;
    display: block !important;
    min-height: auto;
}

.led-matrix-body canvas {
    background-color: #000;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    cursor: crosshair;
    border-radius: 2px;
    width: min(320px, 100%);
    height: auto;
    aspect-ratio: 1 / 1;
}

#view-io .io-device-card:nth-child(3) .io-body {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    justify-content: stretch;
    gap: 8px;
}

#keyboardInput {
    box-sizing: border-box;
    min-width: 0;
}

.uart-console-body>div:last-of-type>div {
    flex-wrap: wrap;
}

#uartInput {
    min-width: 0;
}

@media (max-width: 520px) {
    .uart-console-body>div:last-of-type>div {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    #uartInput {
        grid-column: 1 / -1;
        width: 100% !important;
    }
}

.io-footer {
    padding: 10px 15px;
    background-color: #f1f2f6;
    border-top: 1px solid #dfe6e9;
    font-size: 0.85rem;
    color: #636e72;
    text-align: center;
}

/* --- PLACEHOLDER VIEWS --- */
.placeholder-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #b2bec3;
    text-align: center;
}

.placeholder-view i {
    font-size: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.placeholder-view h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: #636e72;
}

/* --- HELP VIEW --- */
.help-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 15px;
    height: 100%;
    min-height: 0;
}

.help-nav-panel,
.help-section,
.help-empty-state {
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.help-nav-panel {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.help-title-block {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.help-title-block>i {
    color: var(--sidebar-active-bg);
    font-size: 30px;
    margin-top: 2px;
}

.help-title-block h2 {
    margin: 0 0 4px;
    font-size: 1rem;
    color: #2d3436;
    line-height: 1.2;
}

.help-title-block p {
    margin: 0;
    color: #636e72;
    font-size: 0.82rem;
    line-height: 1.45;
}

.help-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fbfcfd;
}

.help-search i {
    color: #636e72;
    font-size: 20px;
}

.help-search input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 0.86rem;
    color: #2d3436;
}

.help-nav-list {
    overflow: auto;
    padding: 4px 8px 12px;
}

.help-nav-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: #53606a;
    text-align: left;
    padding: 9px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.84rem;
    line-height: 1.25;
    transition: background 0.15s ease, color 0.15s ease;
}

.help-nav-item:hover {
    background: #f1f2f6;
    color: #2d3436;
}

.help-nav-item.active {
    background: #e8f3ff;
    color: var(--sidebar-active-bg);
    font-weight: 600;
}

.help-content {
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
    scroll-behavior: smooth;
}

.help-section {
    padding: 18px;
    margin-bottom: 15px;
    overflow-x: auto;
}

.help-section.hidden {
    display: none;
}

.help-section h2,
.help-section h3,
.help-section p {
    letter-spacing: 0;
}

.help-section h2 {
    margin: 0 0 12px;
    color: #1f2d35;
    font-size: 1.22rem;
    line-height: 1.25;
}

.help-section h3 {
    margin: 18px 0 8px;
    color: #2d3436;
    font-size: 0.98rem;
    line-height: 1.35;
}

.help-section p {
    margin: 0 0 12px;
    color: #53606a;
    font-size: 0.9rem;
    line-height: 1.55;
}

.help-section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 12px;
}

.help-chip-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    min-width: 180px;
}

.help-chip-row span {
    border: 1px solid #cfe0ef;
    background: #f3f9ff;
    color: #286b9d;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 0.72rem;
    font-weight: 600;
}

.help-callout {
    border-left: 4px solid var(--sidebar-active-bg);
    background: #f7fbff;
    color: #2d3436;
    padding: 10px 12px;
    margin: 12px 0 14px;
    font-size: 0.88rem;
    line-height: 1.5;
}

.help-source-note {
    font-size: 0.82rem !important;
    color: #636e72 !important;
}

.help-source-note a {
    color: var(--sidebar-active-bg);
    text-decoration: none;
    font-weight: 600;
}

.help-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0 14px;
    font-size: 0.84rem;
}

.help-table th,
.help-table td {
    border: 1px solid #e7ebef;
    padding: 9px 10px;
    vertical-align: top;
    line-height: 1.45;
}

.help-table th {
    background: #f5f7f9;
    color: #53606a;
    font-weight: 700;
    text-align: left;
}

.help-table td {
    color: #2d3436;
    overflow-wrap: break-word;
}

.help-table td:first-child {
    white-space: nowrap;
}

.help-table.compact td,
.help-table.compact th {
    padding: 7px 9px;
}

.instruction-table td:nth-child(2),
.instruction-table td:nth-child(3),
.help-table code {
    white-space: nowrap;
}

.help-steps,
.help-list {
    margin: 0 0 12px;
    padding-left: 22px;
    color: #2d3436;
    font-size: 0.9rem;
    line-height: 1.55;
}

.help-steps li,
.help-list li {
    margin-bottom: 7px;
}

.help-two-column {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.help-code {
    position: relative;
    margin: 12px 0 4px;
    padding: 12px;
    border: 1px solid #dfe6e9;
    border-radius: 6px;
    background: #151a1f;
    color: #d8dee9;
    overflow: auto;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.84rem;
    line-height: 1.5;
}

/* Nút Copy ở góc trên-phải mỗi code block trong Help */
.help-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 26px;
    padding: 0 8px;
    border: 1px solid rgba(216, 222, 233, 0.35);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.08);
    color: #d8dee9;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.help-copy-btn i {
    font-size: 15px;
    line-height: 1;
}

.help-code:hover .help-copy-btn,
.help-copy-btn:focus-visible {
    opacity: 1;
}

.help-copy-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(216, 222, 233, 0.6);
    color: #ffffff;
}

.help-copy-btn.is-copied {
    opacity: 1;
    background: rgba(46, 204, 113, 0.22);
    border-color: rgba(46, 204, 113, 0.6);
    color: #b7f5cf;
}

@media (max-width: 900px) {
    .help-copy-btn {
        opacity: 1;
    }
}

.help-example-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.help-example {
    border: 1px solid #e3e8ee;
    border-radius: 6px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    min-height: 160px;
    background: #fbfcfd;
}

.help-example h3 {
    margin-top: 0;
}

.help-sample-button {
    height: 34px;
    border: 1px solid var(--sidebar-active-bg);
    border-radius: 6px;
    background: #ffffff;
    color: var(--sidebar-active-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    transition: background 0.15s ease, color 0.15s ease;
}

.help-sample-button i {
    font-size: 18px;
}

.help-sample-button:hover {
    background: var(--sidebar-active-bg);
    color: #fff;
}

.help-empty-state {
    text-align: center;
    color: #636e72;
    padding: 36px 18px;
}

.help-empty-state i {
    display: block;
    font-size: 42px;
    color: #b2bec3;
    margin-bottom: 8px;
}

.help-content code {
    font-family: 'Fira Code', 'Consolas', monospace;
    background: #f1f3f5;
    color: #2d3436;
    padding: 1px 4px;
    border-radius: 4px;
}

.help-code code {
    background: transparent;
    color: inherit;
    padding: 0;
    border-radius: 0;
}

@media (max-width: 1280px) {
    .help-layout {
        grid-template-columns: 240px minmax(0, 1fr);
    }

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

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

    .help-nav-panel {
        max-height: 245px;
    }

    .help-section-header,
    .help-two-column {
        grid-template-columns: 1fr;
        display: grid;
    }

    .help-chip-row {
        justify-content: flex-start;
    }
}

/* --- MDC OVERRIDES --- */
.mdc-button {
    height: 36px;
    font-size: 0.8rem;
}

.cache-layout {
    display: flex;
    height: 100%;
}

.cache-detail-layout {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    width: 100%;
}

.cache-panel {
    min-width: 0;
    display: none;
    overflow: hidden;
}

.cache-panel.active-cache-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.cache-tabs {
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-white);
    flex-shrink: 0;
}

.cache-panel .table-scroll-container {
    max-height: calc(100vh - 310px);
}

.cache-stats {
    padding: 12px 15px;
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.4;
}

.cache-stats-inline {
    border-bottom: 1px solid #eef1f4;
    background: #fbfcfd;
    font-size: 0.8rem;
}

@media (max-width: 1400px) {
    .cache-panel .table-scroll-container {
        max-height: 360px;
    }
}

/* ==========================================================================
   SYSTEM LOG TERMINAL
   ========================================================================== */

.system-log-terminal {
    --system-log-collapsed-height: 35px;
    --system-log-expanded-height: 300px;
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    /* Offset for sidebar */
    width: calc(100% - var(--sidebar-width));
    height: var(--system-log-collapsed-height);
    /* Collapsed height */
    background: #1e1e1e;
    color: #a4b0be;
    font-family: 'Courier New', monospace;
    z-index: 1000;
    border-top: 1px solid #444;
    transition: height 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.5);
}

.system-log-terminal.expanded {
    height: clamp(180px, var(--system-log-expanded-height), calc(100vh - 72px));
}

.system-log-terminal.resizing {
    transition: none;
    user-select: none;
}

.system-log-terminal .log-resize-handle {
    position: absolute;
    top: -5px;
    left: 0;
    right: 0;
    height: 10px;
    cursor: ns-resize;
    z-index: 2;
    opacity: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease;
}

.system-log-terminal.expanded .log-resize-handle {
    opacity: 1;
    pointer-events: auto;
}

.system-log-terminal .log-resize-handle::after {
    content: "";
    width: 72px;
    height: 3px;
    border-radius: 999px;
    background: #6b7280;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);
}

.system-log-terminal .log-resize-handle:hover::after,
.system-log-terminal.resizing .log-resize-handle::after {
    background: #c8d0d8;
}

.system-log-terminal .log-header {
    height: 35px;
    background: #2d2d2d;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    font-weight: bold;
    color: #e0e0e0;
    font-family: var(--mdc-typography-font-family, Roboto, sans-serif);
    border-bottom: 1px solid #444;
    cursor: pointer;
    flex-shrink: 0;
}

.system-log-terminal .log-title-group {
    display: flex;
    align-items: baseline;
    gap: 12px;
    min-width: 0;
}

.system-log-terminal .log-stats {
    font-size: 0.72rem;
    font-weight: 500;
    color: #9aa5b1;
    white-space: nowrap;
}

.system-log-terminal .log-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.system-log-terminal .log-btn {
    height: 24px !important;
    line-height: normal;
    font-size: 0.75rem;
    color: #e0e0e0 !important;
    border-color: #666 !important;
    padding: 0 8px !important;
}

.system-log-terminal .log-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.system-log-terminal #logToggleBtn {
    color: #e0e0e0;
    width: 28px;
    height: 28px;
    padding: 0;
    transition: transform 0.3s;
    background: transparent;
    border: none;
    cursor: pointer;
}

.system-log-terminal.expanded #logToggleBtn {
    transform: rotate(180deg);
}

.system-log-terminal .log-filter-bar {
    display: none;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding: 8px 12px;
    background: #242424;
    border-bottom: 1px solid #3b3b3b;
    font-family: var(--mdc-typography-font-family, Roboto, sans-serif);
}

.system-log-terminal.expanded .log-filter-bar {
    display: flex;
}

.system-log-terminal .log-search-box {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 230px;
    max-width: 360px;
    height: 30px;
    padding: 0 9px;
    border: 1px solid #555;
    border-radius: 4px;
    background: #151515;
    color: #d8dee9;
}

.system-log-terminal .log-search-box .material-icons {
    font-size: 18px;
    color: #98a2b3;
}

.system-log-terminal .log-search-box input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: #f1f5f9;
    font: 0.8rem/1.2 var(--mdc-typography-font-family, Roboto, sans-serif);
}

.system-log-terminal .log-search-box input::placeholder {
    color: #8b96a7;
}

.system-log-terminal .log-level-box {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    color: #cbd5e1;
    font-size: 0.75rem;
    font-weight: 600;
}

.system-log-terminal .log-level-box select {
    height: 30px;
    border: 1px solid #555;
    border-radius: 4px;
    background: #151515;
    color: #f1f5f9;
    padding: 0 8px;
    font: 0.78rem var(--mdc-typography-font-family, Roboto, sans-serif);
}

.system-log-terminal .log-module-filters {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 2 1 440px;
    flex-wrap: wrap;
    min-width: 260px;
}

.system-log-terminal .log-filter-chip {
    height: 28px;
    border: 1px solid #50545c;
    border-radius: 4px;
    background: #20242b;
    color: #cbd5e1;
    cursor: pointer;
    font: 600 0.75rem/1 var(--mdc-typography-font-family, Roboto, sans-serif);
    padding: 0 9px;
}

.system-log-terminal .log-filter-chip:hover {
    border-color: #8ba3b8;
    background: #2b313a;
}

.system-log-terminal .log-filter-chip.active {
    border-color: #14b8a6;
    background: #0f766e;
    color: #ffffff;
}

.system-log-terminal .log-filter-chip:focus-visible,
.system-log-terminal .log-search-box:focus-within,
.system-log-terminal .log-level-box select:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}

.system-log-terminal .log-content {
    --system-log-row-height: 18px;
    display: none;
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: auto;
    padding: 10px 15px;
    font-size: 13px;
    line-height: var(--system-log-row-height);
    white-space: normal;
    word-break: normal;
}

.system-log-terminal.expanded .log-content {
    display: block;
}

.log-virtual-spacer {
    position: relative;
    min-width: 100%;
    pointer-events: none;
}

.log-virtual-items {
    position: absolute;
    top: 10px;
    left: 15px;
    min-width: calc(100% - 30px);
    will-change: transform;
}

.log-line {
    display: block;
    height: var(--system-log-row-height);
    line-height: var(--system-log-row-height);
    min-width: max-content;
    white-space: pre;
    word-break: normal;
}

/* Scrollbar styling for log terminal */
.log-content::-webkit-scrollbar {
    width: 10px;
}

.log-content::-webkit-scrollbar-track {
    background: #1e1e1e;
}

.log-content::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 5px;
}

.log-content::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* Log Colors based on level */
.log-error {
    color: #ff5252;
}

.log-warn {
    color: #ffa502;
}

.log-info {
    color: #00ff00;
}

.log-debug {
    color: #a4b0be;
}

.log-cycle {
    color: #2ecc71;
}

@media (max-width: 760px) {
    .system-log-terminal .log-title-group {
        gap: 8px;
    }

    .system-log-terminal .log-filter-bar {
        gap: 8px;
        padding: 8px;
    }

    .system-log-terminal .log-search-box,
    .system-log-terminal .log-module-filters {
        max-width: none;
        min-width: 100%;
    }
}

/* --- MMU LAYOUT & PREMIUM STYLES --- */
.mmu-layout {
    display: flex;
    height: 100%;
}

.mmu-detail-layout {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    width: 100%;
}

.mmu-panel {
    min-width: 0;
    display: none;
    overflow: hidden;
}

.mmu-panel.active-mmu-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.mmu-panel .table-scroll-container {
    max-height: calc(100vh - 310px);
}

.mmu-config-note {
    padding: 8px 12px;
    border-bottom: 1px solid #eef1f4;
    background: #fbfcfd;
    font-family: 'Consolas', monospace;
    font-size: 0.85rem;
    color: #636e72;
    flex-shrink: 0;
}

/* --- SoC DIAGRAM PREMIUM STYLES --- */
#view-processor {
    padding: 8px 12px 50px;
    box-sizing: border-box;
}

.soc-view-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    overflow: hidden;
    background-color: var(--bg-light);
    padding: 0;
    box-sizing: border-box;
}

.soc-svg-wrapper {
    width: 100%;
    min-width: 0;
    max-width: none;
    height: 100%;
    max-height: 100%;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    padding: clamp(6px, 0.65vw, 12px);
    box-sizing: border-box;
    position: relative;
    flex: 1 1 auto;
}

.soc-svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}

/* SoC Block Cards inside foreignObject */
.soc-block {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px 10px;
    box-sizing: border-box;
    border-radius: 8px;
    border: 2px solid #ccc;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1),
                box-shadow 0.2s cubic-bezier(0.25, 0.8, 0.25, 1),
                background-color 0.25s ease;
    user-select: none;
    position: relative;
}

.soc-block:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
}

.soc-block i {
    font-size: 23px;
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    flex-shrink: 0;
}

.soc-block-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    padding: 0 8px;
    box-sizing: border-box;
    min-width: 0;
    flex: 1 1 auto;
}

.soc-block-name {
    font-weight: 700;
    font-size: 0.82rem;
    color: #2d3436;
    margin: 0;
    max-width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.soc-block-status {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.6rem;
    color: #636e72;
    margin: 2px 0 0 0;
    max-width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.soc-block-address {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.53rem;
    color: #7f8c8d;
    margin-top: 2px;
    max-width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Color Grouping for SoC Blocks */
/* 1. Compute Group (RISC-V Core, DMA) */
.group-compute {
    background-color: #ffeef0;
    border-color: #ff7688;
    color: #d63031;
}
.group-compute:hover {
    background-color: #ffdce0;
}
.group-compute i {
    color: #d63031;
}

/* 2. Memory Hierarchy (MMU, Cache, Memory) */
.group-memory {
    background-color: #e8f4fd;
    border-color: #74b9ff;
    color: #0984e3;
}
.group-memory:hover {
    background-color: #d2e9fc;
}
.group-memory i {
    color: #0984e3;
}

/* 3. Interconnect (TileLink Buses) */
.group-bus {
    background-color: #f3f0ff;
    border-color: #b39ddb;
    color: #6c5ce7;
}
.group-bus:hover {
    background-color: #e8e2ff;
}
.group-bus i {
    color: #6c5ce7;
}

/* 4. Peripherals (UART, LED, Key, Mouse) */
.group-peripheral {
    background-color: #fefbeb;
    border-color: #ffe066;
    color: #e67e22;
}
.group-peripheral:hover {
    background-color: #fff9db;
}
.group-peripheral i {
    color: #e67e22;
}

/* Diagram Path Connections */
.flow-line {
    stroke: #718096;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    opacity: 0.7;
    pointer-events: none;
    vector-effect: non-scaling-stroke;
    transition: stroke 0.6s ease, stroke-dasharray 0.6s ease, stroke-width 0.6s ease, opacity 0.6s ease;
}

.flow-core {
    stroke: #5f7f95;
}

.flow-uh {
    stroke: #6c5ce7;
}

.flow-ul {
    stroke: #e67e22;
}

.flow-dma {
    stroke: #ff7688;
}

.flow-dma-regs {
    stroke: #b86b6b;
}

.flow-alias {
    opacity: 0;
    pointer-events: none;
}

.flow-line.active {
    stroke: #0984e3; /* Vibrant blue transaction highlight */
    stroke-width: 3.8;
    stroke-dasharray: 10 6;
    opacity: 1;
    animation: flowPulse 0.4s linear infinite;
    transition: none; /* Instant highlight when triggered */
}

/* Highlight specifically for write/DMA operations */
.flow-line.active-write {
    stroke: #e67e22; /* Amber-orange for write/MMIO operations */
}

@keyframes flowPulse {
    to {
        stroke-dashoffset: -16;
    }
}

/* Marker Arrowheads styling */
.arrow-head {
    fill: context-stroke;
}

.soc-pulse {
    fill: #0984e3;
    opacity: 0.9;
    pointer-events: none;
}

.soc-pulse-write {
    fill: #e67e22;
}

@media (prefers-reduced-motion: reduce) {
    .flow-line.active {
        animation: none;
    }

    .soc-pulse {
        display: none;
    }
}

/* Address & Description overlays */
.addr-label {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.7rem;
    font-weight: 600;
    fill: #5d6d73;
    paint-order: stroke;
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 5px;
    stroke-linejoin: round;
}

/* Educational Tooltips / Description Cards */
.soc-tooltip {
    position: absolute;
    bottom: 10px;
    left: 14px;
    right: 14px;
    background: rgba(45, 52, 54, 0.95);
    color: #dfe6e9;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    line-height: 1.4;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    z-index: 200;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    opacity: 0;
    transform: translateY(5px);
}

.soc-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.soc-tooltip i {
    color: #ffd43b;
    font-size: 20px;
    flex-shrink: 0;
}

.soc-tooltip-content strong {
    color: #fff;
}

/* Legend Area */
.soc-legend {
    display: none;
    flex-wrap: wrap;
    justify-content: center;
    gap: 9px 12px;
    margin-top: 8px;
    width: 100%;
    max-width: 1180px;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 7px 10px;
    box-sizing: border-box;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: #2d3436;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    border: 1.5px solid #ccc;
}
.legend-compute { background-color: #ffeef0; border-color: #ff7688; }
.legend-memory { background-color: #e8f4fd; border-color: #74b9ff; }
.legend-bus { background-color: #f3f0ff; border-color: #b39ddb; }
.legend-peripheral { background-color: #fefbeb; border-color: #ffe066; }

.legend-bus-type {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 10px;
    color: #636e72;
}
.legend-bus-line {
    width: 22px;
    height: 2px;
    border-radius: 1.5px;
}
.legend-line-uh { background-color: #6c5ce7; }
.legend-line-ul { background-color: #e67e22; }
