/* Paging Simulator — MMU virtual address translation styling */

.muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Module navigation hub */
.module-nav {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.module-link {
    padding: 0.45rem 1rem;
    border-radius: var(--radius-pill);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.module-link:hover {
    border-color: var(--primary);
    color: var(--text);
    background: var(--primary-soft);
}

.module-link.active {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
}

/* Badges */
.badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-pill);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--success);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.btn-warning {
    background: #f59e0b;
    color: #fff;
}

.btn-warning:hover {
    background: #d97706;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
}

.btn-info {
    background: #06b6d4;
    color: #fff;
}

.btn-info:hover {
    background: #0891b2;
    box-shadow: 0 4px 14px rgba(6, 182, 212, 0.4);
}

/* Memory hierarchy */
.hierarchy {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.hierarchy-stage {
    background: var(--bg-card-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem 1.6rem;
    font-weight: 700;
    font-size: 0.9rem;
    min-width: 220px;
    text-align: center;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
}

.hierarchy-stage .arrow {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
}

.hierarchy-arrow {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Derived config */
.derived-config {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
    margin-top: 1rem;
}

.derived-config .stat {
    background: var(--bg-card-2);
}

/* Address breakdown */
.address-breakdown {
    margin-top: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    line-height: 1.6;
}

.address-breakdown h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.addr-binary {
    display: flex;
    align-items: center;
    font-family: Consolas, monospace;
    font-size: 1.1rem;
    letter-spacing: 2px;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.bit-group {
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    color: #fff;
    font-weight: 700;
}

.vpn-bits {
    background: rgba(59, 130, 246, 0.85);
}

.offset-bits {
    background: rgba(34, 197, 94, 0.85);
}

.breakdown-labels {
    display: flex;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.vpn-label {
    padding-left: 0.6rem;
}

.offset-label {
    padding-left: 0.6rem;
}

.translation-formula {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Info rows: label on left, value on right */
.info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0.6rem 0.75rem;
    background: var(--bg-card-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 0;
}

.info-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--text);
    min-width: 0;
}

.info-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.5);
    color: #60a5fa;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.info-value {
    font-family: Consolas, monospace;
    font-weight: 700;
    color: var(--success);
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

@media (max-width: 720px) {
    .info-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .info-value {
        text-align: left;
        white-space: normal;
        word-break: break-word;
    }
}

/* Pipeline (step-by-step animation) */
.pipeline {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 120px;
}

.pipeline .muted {
    color: var(--text-muted);
}

.step {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    opacity: 0.45;
    transition: opacity 0.3s ease, transform 0.3s ease, border-color 0.3s ease;
}

.step.active {
    opacity: 1;
    border-color: var(--primary);
    transform: translateX(6px);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.25);
}

.step.done {
    opacity: 0.8;
}

.step-badge {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
    color: #fff;
}

.step-badge.virtual { background: #3b82f6; }
.step-badge.pageTable { background: #d97706; }
.step-badge.frames { background: #16a34a; }
.step-badge.tlb-hit { background: #ca8a04; }
.step-badge.tlb-miss { background: #7c3aed; }
.step-badge.page-fault { background: #dc2626; }
.step-badge.result { background: #059669; }
.step-badge.step-default { background: #475569; }

.step-title {
    font-weight: 700;
    font-size: 0.88rem;
    margin-bottom: 0.15rem;
}

.step-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: Consolas, monospace;
}

.pipeline-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    align-items: center;
}

.pipeline-counter {
    margin-left: auto;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Dashboard: TLB + Page Table + Physical Memory */
.dashboard {
    display: flex;
    align-items: stretch;
    gap: 1rem;
    min-height: 100vh;
    padding: 1rem;
}

.dashboard .card {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    border-radius: 14px;
    padding: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.dashboard .card-header {
    flex-shrink: 0;
    margin-bottom: 1rem;
}

/* TLB panel — fixed content */
.dashboard .card:first-child .mini-table {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    display: block;
    width: 100%;
}

/* Page Table panel — independent scroll */
.dashboard .card:nth-child(2) .table-wrap {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    width: 100%;
}

/* Page Table: structured table with aligned columns */
.dashboard .card:nth-child(2) .mini-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.dashboard .card:nth-child(2) .mini-table th,
.dashboard .card:nth-child(2) .mini-table td {
    padding: 0.5rem 0.4rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Physical Memory panel — CSS grid blocks, independent scroll */
.dashboard .card:last-child .frames-grid {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 6px;
    align-content: start;
    width: 100%;
}

/* Responsive: stack vertically on smaller screens */
@media (max-width: 1000px) {
    .dashboard {
        flex-direction: column;
        min-height: auto;
    }

    .dashboard .card {
        width: 100%;
        flex: none;
    }

    .dashboard .card:first-child .mini-table,
    .dashboard .card:nth-child(2) .table-wrap,
    .dashboard .card:last-child .frames-grid {
        max-height: 320px;
    }
}

/* Mini tables (TLB, page table) */
.mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.mini-table th,
.mini-table td {
    padding: 0.4rem 0.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.mini-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.highlight-row {
    background: rgba(59, 130, 246, 0.25) !important;
    border-left: 3px solid var(--primary);
}

/* Physical frames grid */
.frames-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 6px;
    max-height: 320px;
    overflow-y: auto;
}

.frame {
    height: 52px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.62rem;
    font-weight: 700;
    text-align: center;
    white-space: pre-line;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.frame.free {
    background: #1e293b;
    border: 1px dashed var(--border);
    color: var(--text-muted);
}

.frame.occupied {
    background: rgba(34, 197, 94, 0.25);
    border: 1px solid #22c55e;
    color: #bbf7d0;
}

.frame.highlight {
    transform: scale(1.15);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.6), 0 6px 16px rgba(0, 0, 0, 0.4);
    background: rgba(59, 130, 246, 0.4);
    border-color: var(--primary);
    z-index: 2;
}

/* Statistics colors */
.stat-value.tlb-hit-color { color: #eab308; }
.stat-value.tlb-miss-color { color: #a78bfa; }
.stat-value.tlb-hit-rate { color: var(--success); }
.stat-value.page-fault-color { color: var(--danger); }
