/* ═══════════════════════════════════════════════════════════
   Family Tree Visualization — Design System
   ═══════════════════════════════════════════════════════════ */

:root {
    /* Backgrounds */
    --bg-page: #0B0F19;
    /* Deep Space */
    --bg-canvas: transparent;
    --bg-panel: rgba(15, 23, 42, 0.85);
    --bg-tab-active: rgba(255, 255, 255, 0.1);
    --bg-tab-inactive: transparent;

    /* Nodes */
    --node-bg: rgba(255, 255, 255, 0.03);
    --node-border: rgba(255, 255, 255, 0.1);
    --node-border-hover: rgba(255, 255, 255, 0.3);
    --node-border-radius: 16px;
    --node-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --node-shadow-hover: 0 12px 48px 0 rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.2);

    /* Text */
    --text-primary: #FFFFFF;
    --text-secondary: #94A3B8;
    --text-link: #60A5FA;

    /* Node — status color accent (left border stripe) */
    --node-accent-active: #2ECC71;
    --node-accent-inactive: #64748B;
    --node-accent-unknown: #F59E0B;

    /* Node — unconfirmed root warning */
    --node-warning-bg: rgba(245, 158, 11, 0.1);
    --node-warning-border: #F59E0B;

    /* Tree connectors */
    --edge-color: rgba(148, 163, 184, 0.2);
    --edge-width: 2px;
    --edge-hover-color: rgba(255, 255, 255, 0.8);

    /* Expand/collapse button */
    --btn-expand-bg: rgba(255, 255, 255, 0.05);
    --btn-expand-color: #E2E8F0;

    /* Tabs */
    --tab-border: rgba(255, 255, 255, 0.1);
    --tab-active-indicator: #60A5FA;

    /* Side panel */
    --panel-width: 380px;
    --panel-border: rgba(255, 255, 255, 0.1);

    /* Family colors - Neon versions */
    --family-legofemeli: #FF4D4D;
    --family-prezydenty: #A855F7;
    --family-krolyky: #F97316;
    --family-bilyky: #10B981;
    --family-mongoly: #FBBF24;
}

/* ── Reset ── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    height: 100dvh;
    /* Dynamic viewport height — respects Safari toolbar */
    overflow: hidden;
    /* Prevent double-tap zoom on iOS */
    touch-action: manipulation;
    /* Prevent overscroll bounce on iOS */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--bg-page);
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: relative;
    /* Safe area padding for notched devices */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.ambient-background {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    z-index: 0;
    pointer-events: none;
    /* Deep space mesh gradient */
    background: radial-gradient(circle at 50% 50%, rgba(30, 58, 138, 0.2) 0%, transparent 60%),
        radial-gradient(circle at 80% 20%, rgba(88, 28, 135, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 20% 80%, rgba(15, 23, 42, 0.95) 0%, var(--bg-page) 100%);
    background-size: cover;
    transition: transform 0.1s ease-out;
    /* Will be updated via JS */
}

/* Ensure inputs and buttons inherit the correct font */
input,
button,
textarea,
select {
    font-family: inherit;
}

/* ═══════════════════════════════════════
   Header
   ═══════════════════════════════════════ */
.header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 32px;
    padding: 24px 32px 16px;
    background: transparent;
    border-bottom: none;
    flex-shrink: 0;
    position: relative;
    z-index: 40;
}

.header__left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header__logo {
    height: 36px;
    width: auto;
    object-fit: contain;
}

.header__title {
    font-family: 'Outfit', sans-serif;
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #FFFFFF 0%, rgba(255, 255, 255, 0.6) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

/* ═══════════════════════════════════════
   Search
   ═══════════════════════════════════════ */
.search {
    position: relative;
    flex: 0 1 320px;
}

.search__input {
    width: 100%;
    padding: 12px 20px;
    border: 1px solid var(--node-border);
    border-radius: 24px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    outline: none;
    transition: box-shadow 0.3s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.3s, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.search__input::placeholder {
    color: var(--text-secondary);
}

.search__input:focus {
    border-color: var(--text-link);
    box-shadow: 0 8px 32px rgba(96, 165, 250, 0.2);
}

.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--node-border);
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    max-height: 320px;
    overflow-y: auto;
}

.search-dropdown--open {
    display: block;
}

.search-dropdown__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.12s;
}

.search-dropdown__item:first-child {
    border-radius: 7px 7px 0 0;
}

.search-dropdown__item:last-child {
    border-radius: 0 0 7px 7px;
}

.search-dropdown__item:hover,
.search-dropdown__item--active {
    background: rgba(255, 255, 255, 0.1);
}

.search-dropdown__name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.search-dropdown__family {
    font-size: 11px;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

/* Search Dropdown Badges by family */
.search-dropdown__item[data-family="\041B\0435\0433\043E\0444\0435\043C\0435\043B\0456"] .search-dropdown__family,
.search-dropdown__item[data-family="Легофемелі"] .search-dropdown__family {
    background: var(--family-legofemeli);
    color: white;
}

.search-dropdown__item[data-family="\041F\0440\0435\0437\0438\0434\0435\043D\0442\0438"] .search-dropdown__family,
.search-dropdown__item[data-family="Президенти"] .search-dropdown__family {
    background: var(--family-prezydenty);
    color: white;
}

.search-dropdown__item[data-family="\041A\0440\043E\043B\0438\043A\0438"] .search-dropdown__family,
.search-dropdown__item[data-family="Кролики"] .search-dropdown__family {
    background: var(--family-krolyky);
    color: white;
}

.search-dropdown__item[data-family="\0411\0456\043B\0438\043A\0438"] .search-dropdown__family,
.search-dropdown__item[data-family="Білики"] .search-dropdown__family {
    background: var(--family-bilyky);
    color: white;
}

.search-dropdown__item[data-family="\041C\043E\043D\0433\043E\043B\0438"] .search-dropdown__family,
.search-dropdown__item[data-family="Монголи"] .search-dropdown__family {
    background: var(--family-mongoly);
    color: white;
}

.search-dropdown__empty {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

/* ═══════════════════════════════════════
   Tabs
   ═══════════════════════════════════════ */
.tabs {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    /* Dark subtle border */
    border-radius: 16px;
    padding: 6px;
    margin: 0 32px 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    overflow-x: auto;
    position: relative;
    z-index: 30;
    align-self: flex-start;
}

.tab {
    padding: 8px 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border: none;
    background: transparent;
    border-radius: 10px;
    transition: color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
    position: relative;
    margin-right: 4px;
}

.tab:last-child {
    margin-right: 0;
}

.tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.tab--active {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 4px 12px rgba(0, 0, 0, 0.2);
    /* Elevated pill */
    font-weight: 700;
}

.tab--active[data-family="\041B\0435\0433\043E\0444\0435\043C\0435\043B\0456"],
.tab--active[data-family="Легофемелі"] {
    color: var(--family-legofemeli);
}

.tab--active[data-family="\041F\0440\0435\0437\0438\0434\0435\043D\0442\0438"],
.tab--active[data-family="Президенти"] {
    color: var(--family-prezydenty);
}

.tab--active[data-family="\041A\0440\043E\043B\0438\043A\0438"],
.tab--active[data-family="Кролики"] {
    color: var(--family-krolyky);
}

.tab--active[data-family="\0411\0456\043B\0438\043A\0438"],
.tab--active[data-family="Білики"] {
    color: var(--family-bilyky);
}

.tab--active[data-family="\041C\043E\043D\0433\043E\043B\0438"],
.tab--active[data-family="Монголи"] {
    color: var(--family-mongoly);
}

.tab--disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tab__no-root {
    font-size: 10px;
    color: var(--node-accent-unknown);
    margin-left: 4px;
}

/* ═══════════════════════════════════════
   Main Container
   ═══════════════════════════════════════ */
.main-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.canvas-wrapper {
    flex: 1;
    background: var(--bg-canvas);
    position: relative;
    overflow: hidden;
}

.tree-svg {
    width: 100%;
    height: 100%;
    display: block;
    /* Prevent browser gestures from interfering with D3 zoom/pan on iOS */
    touch-action: none;
}

/* ── Empty State ── */
.canvas-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    background: rgba(15, 23, 42, 0.8);
    padding: 32px 48px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.canvas-empty-state.hidden {
    display: none;
}

.empty-state__icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.8;
}

.empty-state__text {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 600;
}

/* ═══════════════════════════════════════
   Tree Nodes (rendered via foreignObject)
   ═══════════════════════════════════════ */

/* Info row for photo nodes — horizontal layout for accent + content + button */
.tree-node__info-row {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
}

.tree-node {
    width: 200px;
    /* Solid background fallback — backdrop-filter is unreliable inside SVG foreignObject in Safari */
    background: rgba(15, 23, 42, 0.95);
    border: 1.5px solid var(--node-border);
    border-radius: var(--node-border-radius);
    box-shadow: var(--node-shadow);
    cursor: pointer;
    transition: box-shadow 0.3s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.3s, background 0.3s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    overflow: hidden;
    /* Layout containment — allows browser to skip re-layout of other nodes */
    contain: layout style;
    user-select: none;
    -webkit-user-select: none;
    /* Prevent iOS callout on long-press */
    -webkit-touch-callout: none;
    /* Prevent iOS Safari from consuming touch events inside foreignObject */
    touch-action: none;
}

/* Photo variant — vertical card layout */
.tree-node--has-photo {
    flex-direction: column;
}

/* ── Node Photo (top half of card) ── */
.node-photo-wrapper {
    width: 100%;
    height: 140px;
    overflow: hidden;
    flex-shrink: 0;
}

/* Use div+background-image instead of <img> to avoid iOS Safari foreignObject rendering bug
   where <img> elements escape their container and render at SVG root (top-left corner) */
.node-photo {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: block;
}

/* ── Avatar Fallback (gradient circle with initials) ── */
.avatar-fallback {
    width: 100%;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.3) 0%, rgba(168, 85, 247, 0.3) 100%);
    flex-shrink: 0;
}

.avatar-fallback__initials {
    font-family: 'Outfit', sans-serif;
    font-size: 42px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* ── Photo Shimmer Loading — disabled inside foreignObject for iOS Safari compatibility ── */
/* .photo-shimmer uses position:absolute which breaks inside SVG foreignObject on iOS */
.photo-shimmer {
    display: none;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

/* ── Family color gradient overlay on photo ── */
/* Disabled: position:absolute pseudo-elements break inside SVG foreignObject on iOS Safari */
/*
.node-photo-wrapper::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(to top, var(--node-bg), transparent);
    pointer-events: none;
}
*/

/* ── Side Panel Photo ── */
.panel-photo-wrapper {
    display: flex;
    justify-content: center;
    padding: 16px 16px 8px;
}

.panel-photo {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transition: opacity 0.4s ease;
}

.panel-avatar-fallback {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.3) 0%, rgba(168, 85, 247, 0.3) 100%);
    border: 3px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.panel-avatar-fallback__initials {
    font-family: 'Outfit', sans-serif;
    font-size: 42px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 2px;
}

/* ── Search Dropdown Avatar ── */
.search-dropdown__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-right: 8px;
}

.search-dropdown__avatar-fallback {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.3) 0%, rgba(168, 85, 247, 0.3) 100%);
    flex-shrink: 0;
    margin-right: 8px;
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
}

.tree-node:hover {
    border-color: var(--node-border-hover);
    box-shadow: var(--node-shadow-hover);
}

.tree-node--active {
    border-color: var(--node-border-hover);
    background: rgba(255, 255, 255, 0.08);
}

.tree-node--forced-root {
    background: var(--node-warning-bg);
    border-color: var(--node-warning-border);
}

.tree-node--orphan {
    border-style: dashed;
    border-color: var(--node-accent-unknown);
    background: rgba(245, 158, 11, 0.05);
}

.tree-node--search-target {
    border-color: var(--text-link);
    box-shadow: 0 0 0 1px var(--text-link), 0 8px 32px rgba(96, 165, 250, 0.3);
    background: rgba(96, 165, 250, 0.1);
}

.tree-node--active-path {
    border-color: var(--text-link);
    box-shadow: 0 0 0 1px var(--text-link), 0 4px 20px rgba(96, 165, 250, 0.2);
}

.tree-node__accent {
    width: 4px;
    flex-shrink: 0;
    border-radius: var(--node-border-radius) 0 0 var(--node-border-radius);
    /* keep inner radius smooth */
}

.tree-node__accent--active {
    background: var(--node-accent-active);
}

.tree-node__accent--inactive {
    background: var(--node-accent-inactive);
}

.tree-node__accent--unknown {
    background: var(--node-accent-unknown);
}

/* Tree Nodes - left accent by family */
.tree-node__accent[data-family="\041B\0435\0433\043E\0444\0435\043C\0435\043B\0456"],
.tree-node__accent[data-family="Легофемелі"] {
    background: var(--family-legofemeli) !important;
}

.tree-node__accent[data-family="\041F\0440\0435\0437\0438\0434\0435\043D\0442\0438"],
.tree-node__accent[data-family="Президенти"] {
    background: var(--family-prezydenty) !important;
}

.tree-node__accent[data-family="\041A\0440\043E\043B\0438\043A\0438"],
.tree-node__accent[data-family="Кролики"] {
    background: var(--family-krolyky) !important;
}

.tree-node__accent[data-family="\0411\0456\043B\0438\043A\0438"],
.tree-node__accent[data-family="Білики"] {
    background: var(--family-bilyky) !important;
}

.tree-node__accent[data-family="\041C\043E\043D\0433\043E\043B\0438"],
.tree-node__accent[data-family="Монголи"] {
    background: var(--family-mongoly) !important;
}

.tree-node__content {
    flex: 1;
    padding: 8px 10px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.tree-node__name {
    font-family: 'Outfit', sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tree-node__warning {
    font-size: 12px;
    cursor: help;
}

.tree-node__meta {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.tree-node__no-mentees {
    font-size: 10px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 2px;
}

.tree-node__orphan-label {
    font-size: 9px;
    color: var(--node-accent-unknown);
    font-style: italic;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Expand/Collapse Button (side strip — default for non-photo nodes) ── */
.tree-node__expand-btn {
    width: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--btn-expand-bg);
    color: var(--btn-expand-color);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.tree-node__expand-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #FFFFFF;
}

.tree-node__expand-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}



/* ── Loading Spinner on Expand Button ── */
.tree-node__spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #FFFFFF;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Error tooltip on expand button ── */
.tree-node__error-tooltip {
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: #E74C3C;
    color: white;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
}

/* ── Tree Edge Paths ── */
/* Ensure touch-action propagates to all elements inside foreignObject */
.tree-svg foreignObject,
.tree-svg foreignObject * {
    touch-action: none;
}

.tree-link {
    fill: none;
    stroke: var(--edge-color);
    stroke-width: var(--edge-width);
    transition: stroke 0.3s ease, stroke-width 0.3s ease, opacity 0.3s ease, filter 0.3s ease;
}

/* Subtle effect: when hovering over SVG, dim the un-hovered links */
.tree-svg:hover .tree-link {
    opacity: 0.3;
}

.tree-svg .tree-link:hover {
    stroke: var(--edge-hover-color);
    stroke-width: 3px;
    opacity: 1;
    cursor: pointer;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.5));
}

.tree-link--active-path {
    stroke: var(--text-link);
    stroke-width: 3px;
    opacity: 1 !important;
    filter: drop-shadow(0 0 12px rgba(96, 165, 250, 0.6));
    stroke-dasharray: 8;
    animation: flow 1s linear infinite;
}

@keyframes flow {
    from {
        stroke-dashoffset: 16;
    }

    to {
        stroke-dashoffset: 0;
    }
}

/* ═══════════════════════════════════════
   Side Panel
   ═══════════════════════════════════════ */
.side-panel {
    width: var(--panel-width);
    background: var(--bg-panel);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(120%);
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
    position: absolute;
    right: 24px;
    top: 24px;
    bottom: 24px;
    z-index: 50;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.side-panel--open {
    transform: translateX(0);
}

.panel__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}

.panel__name {
    font-family: 'Outfit', sans-serif;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    word-break: break-word;
}

.panel__family {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-link);
    margin-top: 2px;
}

.panel__close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
    line-height: 1;
    transition: color 0.15s;
}

.panel__close:hover {
    color: var(--text-primary);
}

.panel__body {
    padding: 16px;
    flex: 1;
}

/* ── Panel Sections ── */
.panel-section {
    margin-bottom: 16px;
}

.panel-section__title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.panel-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    font-size: 13px;
}

.panel-row__label {
    color: var(--text-secondary);
    font-weight: 400;
    flex-shrink: 0;
    margin-right: 8px;
}

.panel-row__value {
    color: var(--text-primary);
    font-weight: 500;
    text-align: right;
    word-break: break-word;
}

/* ── Mentor Link ── */
.panel-mentor-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-link);
    cursor: pointer;
    font-weight: 500;
    transition: color 0.15s;
}

.panel-mentor-link:hover {
    color: #3572a5;
    text-decoration: underline;
}

.panel-mentor-link__arrow {
    font-size: 12px;
}

/* ── Social Links ── */
.panel-social-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.panel-social-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-link);
    text-decoration: none;
    transition: background 0.15s;
}

.panel-social-link:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ── Mentees List ── */
.panel-mentees-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    padding: 6px 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.panel-mentees-toggle__arrow {
    font-size: 12px;
    transition: transform 0.2s;
}

.panel-mentees-toggle__arrow--open {
    transform: rotate(180deg);
}

.panel-mentees-list {
    display: none;
    padding-top: 6px;
}

.panel-mentees-list--open {
    display: block;
}

.panel-mentee-item {
    padding: 4px 0 4px 10px;
    font-size: 12px;
    color: var(--text-link);
    cursor: pointer;
    transition: color 0.15s;
}

.panel-mentee-item:hover {
    color: #93C5FD;
}

.panel-mentee-item::before {
    content: '·';
    margin-right: 6px;
    font-weight: 700;
}

.panel-divider {
    height: 1px;
    background: var(--panel-border);
    margin: 12px 0;
}

/* ═══════════════════════════════════════
   Utility
   ═══════════════════════════════════════ */
.hidden {
    display: none !important;
}

/* ── Expand All Button ── */
.expand-all-btn {
    margin: 0 32px 12px;
    padding: 8px 20px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s, border-color 0.2s;
    align-self: flex-start;
    letter-spacing: 0.01em;
}

.expand-all-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.expand-all-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ── Scrollbar styling ── */
.side-panel::-webkit-scrollbar {
    width: 6px;
}

.side-panel::-webkit-scrollbar-track {
    background: transparent;
}

.side-panel::-webkit-scrollbar-thumb {
    background: var(--node-border);
    border-radius: 3px;
}

/* ── Responsive ── */
@media (max-width: 768px) {

    /* Header spans vertically */
    .header {
        flex-wrap: wrap;
        padding: 16px 16px 12px;
        padding-top: max(16px, env(safe-area-inset-top));
        gap: 16px;
    }

    .header__left {
        width: 100%;
        justify-content: center;
    }

    .header__title {
        font-size: 24px;
    }

    /* Search bar takes full width on its own row */
    .search {
        flex: 1 1 100%;
    }

    /* Make dropdown cover the screen width properly */
    .search-dropdown {
        position: fixed;
        top: 130px;
        /* Below the wrapped header */
        left: 16px;
        right: 16px;
        width: auto;
        max-height: 50vh;
        z-index: 2000;
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    }

    /* Tabs scrolling and margin adjustment */
    .tabs {
        margin: 0 16px 12px;
        padding: 6px;
        -webkit-overflow-scrolling: touch;
        /* Ensure it spans full width and allows smooth scroll */
        width: calc(100% - 32px);
        justify-content: flex-start;
        /* Hide scrollbar for a cleaner look */
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab {
        padding: 8px 16px;
        font-size: 13px;
        flex-shrink: 0;
        /* Important: prevents tabs from squishing on mobile */
    }

    .tab__no-root {
        display: none;
        /* Hide on mobile to save space */
    }

    /* Side Panel acts as a bottom sheet / full overlay */
    .side-panel {
        width: 100%;
        right: 0;
        left: 0;
        top: auto;
        bottom: 0;
        height: 100%;
        max-height: calc(100% - 20px);
        max-height: calc(100dvh - 20px);
        /* Dynamic viewport for Safari */
        border-radius: 24px 24px 0 0;
        border-right: none;
        border-left: none;
        border-bottom: none;
        transform: translateY(120%);
        transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
        z-index: 1000;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Drag handle indicator for bottom sheet UX */
    .side-panel::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
        margin: 8px auto 4px;
        flex-shrink: 0;
    }

    .side-panel--open {
        transform: translateY(0);
    }

    .panel__close {
        font-size: 32px;
        /* Easier to tap */
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Tree nodes on mobile - smaller to fit more screen */
    .tree-node {
        width: 160px;
    }

    /* Node photos smaller on mobile */
    .node-photo-wrapper {
        height: 110px;
    }

    .avatar-fallback {
        height: 110px;
    }

    .avatar-fallback__initials {
        font-size: 34px;
    }

    /* Panel photo smaller on mobile */
    .panel-photo {
        width: 120px;
        height: 120px;
    }

    .panel-avatar-fallback {
        width: 120px;
        height: 120px;
        font-size: 28px;
    }

    /* Expand All button on mobile */
    .expand-all-btn {
        margin: 0 16px 10px;
        padding: 8px 16px;
        font-size: 13px;
        width: calc(100% - 32px);
        text-align: center;
    }

    /* Ensure tap targets are at least 44px */
    .panel-mentees-toggle {
        min-height: 44px;
    }

    .panel-mentee-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .panel-mentor-link {
        min-height: 44px;
    }

    .panel-social-link {
        min-height: 44px;
        padding: 8px 12px;
    }

    /* Disable hover effects on touch devices to avoid sticky hovers */
    .tree-node:hover {
        border-color: var(--node-border);
        box-shadow: var(--node-shadow);
    }

    .tree-node--active {
        border-color: var(--node-border-hover);
        background: rgba(255, 255, 255, 0.08);
    }

    /* Disable link hover dim on touch */
    .tree-svg:hover .tree-link {
        opacity: 1;
    }
}

@media (max-width: 480px) {
    .quiz-modal {
        padding: 24px;
        margin: 16px;
        max-height: 90vh;
        max-height: 90dvh;
        /* Dynamic viewport for Safari */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .quiz-title {
        font-size: 24px;
    }

    .quiz-subtitle {
        font-size: 14px;
        margin-bottom: 24px;
    }

    .header__title {
        font-size: 20px;
    }

    .search__input {
        padding: 10px 16px;
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    .search-dropdown {
        top: 120px;
    }

    .tree-node {
        width: 140px;
    }

    .tree-node__name {
        font-size: 13px;
    }

    .tree-node__meta {
        font-size: 10px;
    }

    .node-photo-wrapper {
        height: 90px;
    }

    .avatar-fallback {
        height: 90px;
    }

    .avatar-fallback__initials {
        font-size: 28px;
    }

    .panel__name {
        font-size: 18px;
    }

    .panel__body {
        padding: 12px;
    }

    .panel-row {
        font-size: 12px;
        flex-direction: column;
        gap: 2px;
    }

    .panel-row__value {
        text-align: left;
    }
}

/* ═══════════════════════════════════════
   Quiz Gate
   ═══════════════════════════════════════ */
.quiz-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.7);
    /* Dark sophisticated overlay */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.quiz-modal {
    background: var(--bg-panel);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    max-width: 480px;
    width: 100%;
    border: 1px solid var(--panel-border);
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: 0.1s;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

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

.quiz-title {
    font-family: 'Outfit', sans-serif;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-align: center;
}

.quiz-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    text-align: center;
    line-height: 1.5;
}

.quiz-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.quiz-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.quiz-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.quiz-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--node-border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.2);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.quiz-input:focus {
    border-color: var(--text-link);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.quiz-error {
    color: #FCA5A5;
    background: rgba(239, 68, 68, 0.1);
    padding: 10px;
    border-radius: 6px;
    font-size: 13px;
    text-align: center;
    font-weight: 500;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.quiz-submit {
    margin-top: 12px;
    background: #FFFFFF;
    color: #0F172A;
    font-family: inherit;
    font-weight: 600;
    font-size: 15px;
    padding: 14px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.quiz-submit:hover:not(:disabled) {
    background: #F8FAFC;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(255, 255, 255, 0.2);
}

.quiz-submit:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

.quiz-submit:disabled {
    background: rgba(255, 255, 255, 0.5);
    cursor: not-allowed;
    opacity: 0.7;
    box-shadow: none;
    transform: none;
}