/* ── Mindmap Design Tokens ── */
:root {
    --mm-glass-bg: rgba(255,255,255,0.72);
    --mm-glass-border: rgba(255,255,255,0.35);
    --mm-glass-shadow: 0 4px 24px rgba(0,0,0,0.06);
    --mm-surface: #f8f9fb;
    --mm-panel-radius: 14px;
    --mm-transition: 0.25s cubic-bezier(0.4,0,0.2,1);
}
body.dark-mode {
    --mm-glass-bg: rgba(17,24,39,0.78);
    --mm-glass-border: rgba(255,255,255,0.08);
    --mm-glass-shadow: 0 4px 24px rgba(0,0,0,0.3);
    --mm-surface: #0f1117;
}

/* ── Landing Page ── */
.mindmap-landing {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}
.mindmap-landing header {
    text-align: center;
    margin-bottom: 2.5rem;
}
.mindmap-landing header h1 {
    font-size: 2rem;
    color: var(--text-color-headings);
    margin-bottom: 0.5rem;
}
.mindmap-landing header p {
    color: var(--text-color-muted);
    font-size: 1.05rem;
}

/* Card grid */
.mindmap-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}
.mindmap-card {
    display: block;
    text-decoration: none;
    color: inherit;
    background: var(--header-bg);
    border: 1px solid var(--border-color-light);
    border-radius: 12px;
    overflow: hidden;
    transition: transform var(--mm-transition), box-shadow var(--mm-transition), border-color var(--mm-transition);
}
.mindmap-card:hover {
    transform: translateY(-3px) scale(1.01);
    box-shadow: 0 8px 32px rgba(96,165,250,0.15), 0 0 0 1px rgba(96,165,250,0.2);
    border-color: var(--accent);
}
body.dark-mode .mindmap-card:hover {
    box-shadow: 0 8px 32px rgba(96,165,250,0.12), 0 0 0 1px rgba(96,165,250,0.25);
}

/* Card accent strip */
.mindmap-card-accent {
    height: 4px;
    background: linear-gradient(270deg, #f0c040, #60a5fa, #34d399, #e07bdb, #ff8a6b);
    background-size: 200% 100%;
}

.mindmap-card-body {
    padding: 1.5rem;
}
.mindmap-card h2 {
    font-size: 1.2rem;
    color: var(--text-color-headings);
    margin: 0 0 0.4rem;
}
.mindmap-card-source {
    font-size: 0.85rem;
    color: var(--text-color-muted);
    margin-bottom: 0.75rem;
}
.mindmap-card p {
    font-size: 0.95rem;
    color: var(--text-color);
    line-height: 1.7;
    margin-bottom: 0.75rem;
}

/* Card stats row */
.mindmap-card-stats {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.mindmap-card-badge {
    display: inline-block;
    font-size: 0.8rem;
    padding: 0.2rem 0.7rem;
    border-radius: 12px;
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}
body.dark-mode .mindmap-card-badge {
    background: rgba(96,165,250,0.15);
    color: #60a5fa;
}

/* ── Mindmap Page ── */
.mindmap-page {
    width: 100vw;
    margin-inline: calc(-50vw + 50%);
    margin-top: -2rem;
    margin-bottom: -3rem;
}

/* ── SVG Wrapper ── */
.mindmap-wrapper {
    width: 100%;
    height: calc(100dvh - 57px);
    min-height: 500px;
    position: relative;
    overflow: hidden;
    background: var(--mm-surface);
    box-shadow: inset 0 2px 30px rgba(0,0,0,0.04);
}
body.dark-mode .mindmap-wrapper {
    box-shadow: inset 0 2px 30px rgba(0,0,0,0.2);
}

/* ── Toolbar ── */
.mindmap-toolbar {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    gap: 4px;
    background: var(--mm-glass-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--mm-glass-border);
    border-radius: 24px;
    padding: 5px 10px;
    box-shadow: var(--mm-glass-shadow);
    flex-wrap: wrap;
    justify-content: center;
}
.mindmap-toolbar button {
    font-family: var(--font-arabic), sans-serif;
    font-size: 12px;
    padding: 5px 12px;
    border: none;
    border-radius: 16px;
    background: transparent;
    color: var(--text-color-muted);
    cursor: pointer;
    transition: background var(--mm-transition), color var(--mm-transition), transform 0.15s ease;
    white-space: nowrap;
}
.mindmap-toolbar button:hover {
    background: var(--accent-light);
    color: var(--accent);
    transform: scale(1.05);
}
body.dark-mode .mindmap-toolbar button:hover {
    background: rgba(96,165,250,0.12);
    color: #60a5fa;
}
.mindmap-toolbar button.active {
    background: var(--accent);
    color: #fff;
}
body.dark-mode .mindmap-toolbar button.active {
    background: #60a5fa;
    color: #0f1117;
}

/* ── Hint ── */
.mindmap-hint {
    position: absolute;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--text-color-muted);
    z-index: 10;
    pointer-events: none;
    white-space: nowrap;
    opacity: 0.7;
    transition: opacity 0.6s ease;
}
.mindmap-hint.fade-out {
    opacity: 0;
}

/* ── Legend ── */
.mindmap-legend {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 20;
    font-size: 11px;
    background: var(--mm-glass-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--mm-glass-border);
    border-radius: var(--mm-panel-radius);
    padding: 10px 14px;
    box-shadow: var(--mm-glass-shadow);
    direction: rtl;
}
.mindmap-legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 16px;
}
.mindmap-legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 3px 0;
    color: var(--text-color-muted);
}
.mindmap-legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}
.mindmap-legend-toggle {
    display: none;
    font-size: 11px;
    color: var(--text-color-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 0;
    font-family: var(--font-arabic), sans-serif;
}

/* ── Info Panel ── */
.mindmap-info {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 20;
    max-width: 360px;
    background: var(--mm-glass-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--mm-glass-border);
    border-radius: var(--mm-panel-radius);
    box-shadow: var(--mm-glass-shadow);
    direction: rtl;
    text-align: right;
    max-height: 55vh;
    overflow: hidden;
    /* Slide-in animation */
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
    transition: opacity var(--mm-transition), transform var(--mm-transition);
}
.mindmap-info.visible {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}
.mindmap-info-accent {
    height: 3px;
    border-radius: var(--mm-panel-radius) var(--mm-panel-radius) 0 0;
    transition: background var(--mm-transition);
}
.mindmap-info-content {
    padding: 14px 18px 16px;
    overflow-y: auto;
    max-height: calc(55vh - 3px);
}
.mindmap-info-close {
    position: absolute;
    top: 10px;
    left: 10px;
    background: none;
    border: none;
    color: var(--text-color-muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
    transition: background var(--mm-transition);
}
.mindmap-info-close:hover {
    background: rgba(0,0,0,0.06);
}
body.dark-mode .mindmap-info-close:hover {
    background: rgba(255,255,255,0.08);
}
.mindmap-info-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 8px;
    font-family: var(--font-arabic), 'Noto Naskh Arabic', sans-serif;
}
.mindmap-info-body {
    font-size: 13px;
    line-height: 2.1;
    color: var(--text-color);
    font-family: var(--font-arabic), 'Noto Naskh Arabic', sans-serif;
}

/* ── SVG ── */
.mindmap-svg {
    width: 100%;
    height: 100%;
    cursor: grab;
}
.mindmap-svg.dragging {
    cursor: grabbing;
}

/* ── SVG Node Styles ── */
.mm-node { transition: opacity 0.15s ease; }
.mm-node:hover { opacity: 0.8; }
@keyframes circle-pulse {
    0%, 100% { stroke-opacity: 0.9; }
    50% { stroke-opacity: 0.4; }
}
.mm-node-selected circle {
    animation: circle-pulse 2s ease-in-out infinite;
}

/* ── Mobile ── */
@media (max-width: 768px) {
    .mindmap-page {
        margin-top: -1rem;
    }
    .mindmap-wrapper {
        height: calc(100dvh - 50px);
        min-height: 400px;
    }
    .mindmap-toolbar {
        top: 8px;
        padding: 4px 8px;
        gap: 3px;
        max-width: 95vw;
    }
    .mindmap-toolbar button {
        font-size: 11px;
        padding: 4px 8px;
    }
    .mindmap-hint {
        top: 48px;
        font-size: 10px;
    }

    /* Info panel as bottom sheet */
    .mindmap-info {
        right: 0;
        left: 0;
        bottom: 0;
        max-width: none;
        border-radius: var(--mm-panel-radius) var(--mm-panel-radius) 0 0;
        max-height: 45vh;
        transform: translateY(20px);
    }
    .mindmap-info.visible {
        transform: translateY(0);
    }
    .mindmap-info-accent {
        border-radius: var(--mm-panel-radius) var(--mm-panel-radius) 0 0;
    }

    /* Hide legend when info visible */
    .mindmap-legend.legend-hidden {
        opacity: 0;
        pointer-events: none;
    }

    .mindmap-legend {
        left: 8px;
        bottom: 8px;
        max-height: 40vh;
        overflow-y: auto;
        transition: opacity 0.2s ease;
    }
    .mindmap-legend-grid {
        grid-template-columns: 1fr;
    }
    .mindmap-legend.collapsed .mindmap-legend-item {
        display: none;
    }
    .mindmap-legend-toggle {
        display: block;
    }
    .mindmap-cards {
        grid-template-columns: 1fr;
    }
    .mm-node circle {
        stroke-width: 8px;
        stroke-opacity: 0;
        paint-order: stroke;
    }
}

/* ── Mobile Landscape ── */
@media (max-width: 768px) and (orientation: landscape) {
    .mindmap-toolbar { top: 4px; padding: 3px 6px; }
    .mindmap-toolbar button { font-size: 10px; padding: 3px 6px; }
    .mindmap-hint { top: 36px; font-size: 9px; }
    .mindmap-legend { bottom: 4px; left: 4px; font-size: 10px; padding: 6px 10px; }
    .mindmap-info { max-height: 40vh; }
}
