/* Buddy Allocator Simulator — Linux-style tree & memory layout styling */

/* Module navigation hub (consistent with other pages) */
.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;
}

/* Compact label for the free-process row */
.compact-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.5rem 0 0.25rem;
    display: block;
}

.control-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-items: center;
}

.control-actions select {
    flex: 1;
    min-width: 140px;
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
}

/* Mode status */
.mode-status {
    margin-top: 0.9rem;
    padding: 0.7rem 0.9rem;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Two-panel layout: tree (left) + memory (right) */
.buddy-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    align-items: start;
}

@media (max-width: 900px) {
    .buddy-layout {
        grid-template-columns: 1fr;
    }
}

/* Buddy tree */
.buddy-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    max-height: 480px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.15);
}

.buddy-tree .muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.tree-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tree-node {
    padding: 0.4rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card-2);
    color: var(--text);
    font-family: Consolas, monospace;
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    min-width: 64px;
}

.tree-node:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.tree-node .node-size {
    display: block;
    font-size: 0.78rem;
}

.tree-node .node-proc {
    display: block;
    font-size: 0.62rem;
    color: var(--text-muted);
    font-family: "Segoe UI", sans-serif;
    font-weight: 600;
}

.tree-node.split {
    border-style: dashed;
    color: var(--text-muted);
}

.tree-node.free {
    background: #1a2333;
    border-color: #22c55e;
    color: #bbf7d0;
}

.tree-node.allocated {
    background: rgba(34, 197, 94, 0.25);
    border-color: #22c55e;
    color: #bbf7d0;
}

.tree-node.selected {
    outline: 3px solid var(--primary);
    outline-offset: -1px;
}

.tree-node.buddy {
    outline: 3px solid #f59e0b;
    outline-offset: -1px;
}

.tree-node.path {
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.6);
}

.tree-node.splitting {
    animation: buddyPulse 0.25s ease-in-out 3;
    border-color: #f59e0b;
}

.tree-node.merging {
    animation: buddyMergePulse 0.25s ease-in-out 3;
    border-color: #06b6d4;
}

@keyframes buddyPulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.7); }
}

@keyframes buddyMergePulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.5); box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.4); }
}

/* Memory layout horizontal view */
.buddy-layout-view {
    display: flex;
    width: 100%;
    height: 84px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #0d1524;
}

.layout-block {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    color: #e2e8f0;
    border-right: 1px solid rgba(0, 0, 0, 0.35);
    overflow: hidden;
    white-space: nowrap;
    text-align: center;
    cursor: pointer;
    transition: filter 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.layout-block:last-child {
    border-right: none;
}

.layout-block .blk-name {
    font-size: 0.72rem;
    font-weight: 700;
}

.layout-block .blk-size {
    font-size: 0.6rem;
    opacity: 0.8;
}

.layout-block.free {
    background: #1a2333;
    color: #64748b;
    border-left: 1px dashed #2a3b54;
}

.layout-block.selected {
    outline: 3px solid var(--primary);
    outline-offset: -2px;
}

.layout-block.buddy {
    outline: 3px solid #f59e0b;
    outline-offset: -2px;
}

.layout-addr {
    display: flex;
    justify-content: space-between;
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-family: Consolas, monospace;
}

/* Free lists */
.free-lists {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
}

.free-lists .muted {
    width: 100%;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.free-chip {
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-card-2);
    color: var(--text);
    font-family: Consolas, monospace;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.free-chip:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.free-chip.active {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.2);
    color: #bbf7d0;
}

/* Allocation search panel */
.search-panel {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-height: 60px;
}

.search-panel .muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.search-step {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    background: var(--bg);
    border-left: 3px solid var(--border);
    font-family: Consolas, monospace;
    font-size: 0.78rem;
    animation: buddySlideIn 0.25s ease;
}

.search-step.ok { border-left-color: #22c55e; }
.search-step.fail { border-left-color: #ef4444; }
.search-step.split { border-left-color: #f59e0b; }
.search-step.alloc { border-left-color: #3b82f6; }

@keyframes buddySlideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Statistics dashboard */
.buddy-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

@media (max-width: 900px) {
    .buddy-stats { grid-template-columns: repeat(2, 1fr); }
}

.buddy-stats .stat {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.8rem 0.5rem;
    text-align: center;
}

.buddy-stats .stat-value {
    font-family: Consolas, monospace;
}

.buddy-stats .stat-value.used { color: #60a5fa; }
.buddy-stats .stat-value.free { color: var(--success); }

/* Fragmentation / utilization progress bar */
.frag-bar-wrap {
    margin-top: 1rem;
}

.frag-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.frag-bar {
    height: 12px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    overflow: hidden;
}

.frag-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #22c55e, #3b82f6, #a78bfa);
    transition: width 0.4s ease;
}

/* Event timeline */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 260px;
    overflow-y: auto;
}

.timeline .muted { color: var(--text-muted); font-size: 0.85rem; }

.timeline-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.45rem 0.7rem;
    border-radius: 6px;
    background: var(--bg);
    border-left: 3px solid var(--border);
    font-size: 0.8rem;
    animation: buddySlideIn 0.25s ease;
}

.timeline-time {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-family: Consolas, monospace;
    white-space: nowrap;
    padding-top: 0.1rem;
}

.timeline-item.split { border-left-color: #f59e0b; }
.timeline-item.merge { border-left-color: #06b6d4; }
.timeline-item.allocated { border-left-color: #22c55e; }
.timeline-item.freed { border-left-color: #60a5fa; }
.timeline-item.failed { border-left-color: #ef4444; }
.timeline-item.reset { border-left-color: var(--text-muted); }
.timeline-item.rename { border-left-color: #a78bfa; }

.timeline-actions { margin-top: 0; }

/* Educational panel */
.edu-panel {
    font-size: 0.88rem;
}

.edu-panel summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.4rem;
}

.edu-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    color: var(--text);
    line-height: 1.6;
}

.edu-content h3 {
    font-size: 0.95rem;
    color: var(--text);
    margin-top: 0.4rem;
}

.edu-content code {
    background: var(--bg-card-2);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.82rem;
}

.edu-content ul {
    padding-left: 1.2rem;
}

.edu-content li {
    margin-bottom: 0.3rem;
}
