/* ============================================
   ARIA — BỘ NÃO 3D (BRAIN 3D)
   Overlay mô hình não người mô phỏng: panel vùng não + sân khấu 3D + thẻ chi tiết
   Dùng token theme (--bg-*, --text-*, --accent*) nên chạy đúng ở cả 4 giao diện
   ============================================ */

.brain3d-content {
    width: 96vw;
    height: 92vh;
    max-width: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.brain3d-header {
    padding: 14px 18px;
    margin: 0;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-2);
    gap: 12px;
}
.brain3d-header h2 { font-size: 15.5px; }
.brain3d-stats {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.brain3d-body { flex: 1; display: flex; min-height: 0; }

/* ── Panel trái ── */
.brain3d-side {
    width: 272px;
    flex-shrink: 0;
    padding: 14px;
    border-right: 1px solid var(--border-light);
    background: var(--bg-1);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.b3d-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-faint);
}
.b3d-search input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 12.5px;
}
.b3d-search input::placeholder { color: var(--text-faint); }

.b3d-section h4 {
    margin: 0 0 8px;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.b3d-list-chips { display: flex; flex-direction: column; gap: 3px; }

.b3d-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
    transition: background var(--t), color var(--t), border-color var(--t);
}
.b3d-chip:hover { background: var(--surface-hover); color: var(--text); }
.b3d-chip.active {
    background: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--text);
    font-weight: 600;
}
.b3d-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.b3d-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 8px currentColor;
}
.b3d-chip-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b3d-chip-count {
    font-size: 11px;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

.b3d-toggles { display: flex; flex-direction: column; gap: 8px; }
.b3d-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--text-muted);
    cursor: pointer;
}
.b3d-toggle input { accent-color: var(--accent); }
.b3d-btn {
    margin-top: 4px;
    padding: 7px 10px;
    border: 1px solid var(--border-light);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
    transition: all var(--t);
}
.b3d-btn:hover { border-color: var(--accent); color: var(--accent-bright); }
.b3d-hint {
    margin: auto 0 0;
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text-faint);
}

/* ── Sân khấu 3D ── */
.brain3d-stage {
    position: relative;
    flex: 1;
    min-width: 0;
    background:
        radial-gradient(circle at 50% 42%, var(--accent-glow), transparent 62%),
        var(--bg-0);
    overflow: hidden;
}
#brain3d-canvas-host { position: absolute; inset: 0; cursor: grab; }
#brain3d-canvas-host:active { cursor: grabbing; }
#brain3d-canvas-host.disabled { display: none; }
.brain3d-gl { display: block; width: 100%; height: 100%; }

/* Nút phóng to / thu nhỏ / reset nổi trên sân khấu */
.b3d-viewbtns {
    position: absolute;
    top: 14px;
    right: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 6;
}
.b3d-iconbtn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-light);
    border-radius: 9px;
    background: var(--bg-2);
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--t);
}
.b3d-iconbtn:hover { border-color: var(--accent); color: var(--accent-bright); }
.b3d-iconbtn.wide { width: 34px; font-size: 11px; }

/* Trạng thái tải / lỗi */
.b3d-loader,
.b3d-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    z-index: 5;
    background: var(--bg-0);
}
.b3d-loader.hidden { display: none; }
.b3d-loader .spin {
    width: 26px; height: 26px;
    border: 2px solid var(--border-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: b3dSpin 0.85s linear infinite;
}
@keyframes b3dSpin { to { transform: rotate(360deg); } }
.b3d-fallback { display: none; }
.b3d-fallback.show { display: flex; }
.b3d-fallback .warn { font-size: 26px; }

/* Tooltip neuron */
.b3d-tooltip {
    position: fixed;
    z-index: 1200;
    width: 300px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-1);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.42);
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.12s, transform 0.12s, visibility 0.12s;
    pointer-events: none;
}
.b3d-tooltip.show { opacity: 1; visibility: visible; transform: none; }
.b3d-tip-head { font-size: 12.5px; font-weight: 700; margin-bottom: 5px; }
.b3d-tip-body { font-size: 12.5px; line-height: 1.55; color: var(--text); }
.b3d-tip-sub { margin-top: 6px; font-size: 11px; color: var(--text-faint); }

/* Thẻ chi tiết neuron */
.brain3d-detail {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 330px;
    max-height: 64%;
    overflow-y: auto;
    z-index: 6;
}
.b3d-hint-empty {
    margin: 0;
    padding: 10px 12px;
    border: 1px dashed var(--border-light);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-faint);
    font-size: 12px;
    line-height: 1.6;
}
.b3d-card {
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-2);
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.4);
}
.b3d-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 9px; }
.b3d-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--c, var(--accent));
    background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--c, var(--accent)) 40%, transparent);
}
.b3d-pin { font-size: 12px; }
.b3d-region { margin-left: auto; font-size: 11px; color: var(--text-faint); }
.b3d-content {
    margin: 0;
    font-size: 12.5px;
    line-height: 1.65;
    color: var(--text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.b3d-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.b3d-tags span {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--accent-subtle);
    color: var(--accent-bright);
}
.b3d-meta { margin-top: 9px; font-size: 11px; color: var(--text-faint); }
.b3d-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.b3d-actions button {
    flex: 1 1 auto;
    padding: 7px 10px;
    border: 1px solid var(--border-light);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--t);
}
.b3d-actions button:hover { border-color: var(--accent); color: var(--text); }
.b3d-actions button.primary {
    border-color: transparent;
    background: var(--accent);
    color: #ffffff;
    font-weight: 600;
}
.b3d-actions button.primary:hover { background: var(--accent-bright); color: #ffffff; }
.b3d-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.b3d-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}
.b3d-row:hover { border-color: var(--accent); color: var(--text); }
.b3d-row-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Chọn mật độ lưới nơ-ron ── */
.b3d-select-row { justify-content: space-between; }
.b3d-select-row select {
    flex: 0 0 auto;
    padding: 3px 6px;
    border: 1px solid var(--border-light);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

/* ── Bản đồ 2D trải phẳng — cùng dữ liệu với mô hình 3D ── */
.b3d-flatmap {
    position: absolute;
    left: 14px;
    bottom: 14px;
    width: 288px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--bg-1);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.42);
    overflow: hidden;
    z-index: 6;
    transition: all var(--t);
}
.b3d-flatmap.hidden { display: none; }
.b3d-flatmap.expanded {
    top: 14px;
    right: 14px;
    bottom: 14px;
    left: 14px;
    width: auto;
    z-index: 8;
}
.b3d-flatmap-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 9px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-2);
}
.b3d-flatmap-title {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.b3d-flatmap-count {
    margin-left: auto;
    font-size: 10.5px;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.b3d-flatmap-btn {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    transition: all var(--t);
}
.b3d-flatmap-btn:hover { border-color: var(--accent); color: var(--accent-bright); }
#b3d-flatmap-canvas { display: block; width: 100%; height: 176px; cursor: crosshair; }
.b3d-flatmap.expanded #b3d-flatmap-canvas { height: auto; flex: 1 1 auto; }
.b3d-flatmap-foot {
    margin: 0;
    padding: 6px 9px;
    border-top: 1px solid var(--border-light);
    color: var(--text-faint);
    font-size: 10.5px;
    line-height: 1.5;
}

/* ── Responsive ── */
@media (max-width: 980px) {
    .brain3d-content { width: 100vw; height: 100vh; border-radius: 0; }
    .b3d-flatmap { display: none; }
    .brain3d-body { flex-direction: column; }
    .brain3d-side {
        width: 100%;
        max-height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--border-light);
    }
    .b3d-hint { display: none; }
    .brain3d-detail { position: fixed; right: 10px; left: 10px; bottom: 10px; width: auto; max-height: 42%; }
    .brain3d-stats { display: none; }
}
