/* ================================================================
   BMW Genealogy Tree v2  —  modern binary MLM visualization
   ================================================================ */

/* ── Root container ─────────────────────────────────────────── */
.bmw-tree-root {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    background: #f1f5f9;
    border-radius: .75rem;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    position: relative;
    min-height: 600px;
    display: flex;
    flex-direction: column;
}

/* ── Controls bar ───────────────────────────────────────────── */
.bmw-tree-controls {
    display:      flex;
    align-items:  center;
    gap:          .75rem;
    flex-wrap:    wrap;
    padding:      .875rem 1.25rem;
    background:   #1e293b;
    border-bottom: 1px solid #334155;
}

/* Search */
.bmw-tree-search-wrap {
    position: relative;
    flex:     1;
    min-width: 180px;
    max-width: 300px;
}
.bmw-tree-search-icon {
    position:  absolute;
    left:      .7rem;
    top:       50%;
    transform: translateY(-50%);
    color:     #94a3b8;
    font-size: .78rem;
    pointer-events: none;
}
.bmw-tree-search {
    width:         100%;
    padding:       .45rem .45rem .45rem 2.1rem;
    background:    #0f172a;
    border:        1px solid #334155;
    border-radius: .4rem;
    color:         #e2e8f0;
    font-size:     .82rem;
    outline:       none;
    box-sizing:    border-box;
}
.bmw-tree-search::placeholder { color: #64748b; }
.bmw-tree-search:focus { border-color: #4f46e5; box-shadow: 0 0 0 2px rgba(79,70,229,.2); }
.bmw-tree-search-clear {
    position:  absolute;
    right:     .4rem;
    top:       50%;
    transform: translateY(-50%);
    background: transparent;
    border:    none;
    color:     #64748b;
    font-size: 1rem;
    cursor:    pointer;
    line-height: 1;
    padding:   0 .2rem;
}
.bmw-tree-search-clear:hover { color: #e2e8f0; }

/* Level filter */
.bmw-tree-level-wrap {
    display:     flex;
    align-items: center;
    gap:         .3rem;
}
.bmw-tree-ctrl-label {
    font-size:   .72rem;
    color:       #94a3b8;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-right: .1rem;
}
.bmw-tree-level-btn {
    padding:       .3rem .65rem;
    background:    #1e293b;
    border:        1px solid #334155;
    border-radius: .35rem;
    color:         #94a3b8;
    font-size:     .78rem;
    font-weight:   600;
    cursor:        pointer;
    transition:    all .15s;
}
.bmw-tree-level-btn:hover,
.bmw-tree-level-btn.active {
    background:   #4f46e5;
    border-color: #4f46e5;
    color:        #fff;
}

/* Zoom controls */
.bmw-tree-zoom-wrap {
    display:     flex;
    align-items: center;
    gap:         .3rem;
    margin-left: auto;
}
.bmw-tree-zoom-btn {
    width:         34px;
    height:        34px;
    background:    #1e293b;
    border:        1px solid #334155;
    border-radius: .35rem;
    color:         #94a3b8;
    font-size:     .8rem;
    cursor:        pointer;
    display:       flex;
    align-items:   center;
    justify-content: center;
    transition:    all .15s;
}
.bmw-tree-zoom-btn:hover { background: #4f46e5; border-color: #4f46e5; color: #fff; }

/* ── Stats bar ──────────────────────────────────────────────── */
.bmw-tree-stats {
    display:     flex;
    align-items: center;
    gap:         .5rem 1.5rem;
    flex-wrap:   wrap;
    padding:     .6rem 1.25rem;
    background:  #0f172a;
    border-bottom: 1px solid #1e293b;
}
.bmw-tree-stat-item {
    font-size:   .78rem;
    color:       #94a3b8;
    display:     flex;
    align-items: center;
    gap:         .35rem;
}
.bmw-tree-stat-item i { font-size: .75rem; }
.bmw-stat-left  i { color: #818cf8; }
.bmw-stat-right i { color: #67e8f9; }

/* ── Viewport & canvas ─────────────────────────────────────── */
.bmw-tree-viewport {
    flex:       1;
    overflow:   hidden;
    position:   relative;
    min-height: 460px;
    background: #f8fafc;
    background-image:
        radial-gradient(circle, #cbd5e1 1px, transparent 1px);
    background-size: 28px 28px;
}
.bmw-tree-canvas {
    position:         absolute;
    top:              0;
    left:             0;
    transform-origin: 0 0;
    will-change:      transform;
}
.bmw-tree-svg {
    position: absolute;
    top: 0; left: 0;
    pointer-events: none;
    overflow: visible;
}
.bmw-tree-nodes {
    position: absolute;
    top: 0; left: 0;
}

/* ── SVG connection paths ───────────────────────────────────── */
.bmw-tree-path {
    stroke:       #cbd5e1;
    stroke-width: 2px;
    fill:         none;
    opacity:      .7;
}
.bmw-tree-path-left  { stroke: #818cf8; }
.bmw-tree-path-right { stroke: #67e8f9; }

/* ── Node card ─────────────────────────────────────────────── */
.bmw-gnode {
    position:  absolute;
    width:     210px;
    z-index:   1;
}
.bmw-gnode-inner {
    background:    #fff;
    border-radius: .75rem;
    border:        2px solid #e2e8f0;
    overflow:      hidden;
    cursor:        pointer;
    transition:    border-color .2s, box-shadow .2s, transform .15s;
    box-shadow:    0 2px 8px rgba(0,0,0,.06);
}
.bmw-gnode-inner:hover {
    border-color: #4f46e5;
    box-shadow:   0 6px 24px rgba(79,70,229,.2);
    transform:    translateY(-2px);
}
.bmw-gnode-left  .bmw-gnode-inner { border-top: 3px solid #818cf8; }
.bmw-gnode-right .bmw-gnode-inner { border-top: 3px solid #67e8f9; }
.bmw-gnode-me    .bmw-gnode-inner { border-top: 3px solid #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,.15); }

/* Avatar row */
.bmw-gnode-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         .75rem .875rem .4rem;
    position:        relative;
}
.bmw-gnode-avatar {
    width:         48px;
    height:        48px;
    border-radius: 50%;
    object-fit:    cover;
    border:        2px solid #e2e8f0;
    background:    #f1f5f9;
}
.bmw-gnode-pos {
    font-size:   .6rem;
    font-weight: 800;
    padding:     .2rem .5rem;
    border-radius: 999px;
    line-height: 1;
}
.bmw-gnode-pos-l { background: rgba(129,140,248,.12); color: #4f46e5; }
.bmw-gnode-pos-r { background: rgba(103,232,249,.12); color: #0891b2; }
.bmw-gnode-me-badge {
    display:         flex;
    align-items:     center;
    justify-content: center;
    width:           20px;
    height:          20px;
    border-radius:   50%;
    background:      #10b981;
    color:           #fff;
    font-size:       .55rem;
    margin-left:     .3rem;
}

/* Body text */
.bmw-gnode-body {
    padding: .1rem .875rem .5rem;
}
.bmw-gnode-name {
    font-size:     .9rem;
    font-weight:   700;
    color:         #0f172a;
    white-space:   nowrap;
    overflow:      hidden;
    text-overflow: ellipsis;
}
.bmw-gnode-username {
    font-size:     .72rem;
    color:         #94a3b8;
    margin-bottom: .4rem;
    white-space:   nowrap;
    overflow:      hidden;
    text-overflow: ellipsis;
}
.bmw-gnode-rank {
    display:       inline-flex;
    align-items:   center;
    gap:           .3rem;
    font-size:     .68rem;
    font-weight:   700;
    padding:       .2rem .55rem;
    border-radius: 999px;
}
.bmw-gnode-rank i { font-size: .65rem; }

/* Footer stats */
.bmw-gnode-footer {
    display:     flex;
    justify-content: space-between;
    padding:     .45rem .875rem;
    background:  #f8fafc;
    border-top:  1px solid #f1f5f9;
    font-size:   .72rem;
    color:       #64748b;
    gap:         .5rem;
}
.bmw-gnode-footer span {
    display:     flex;
    align-items: center;
    gap:         .3rem;
}
.bmw-gnode-footer i { font-size: .65rem; color: #94a3b8; }

/* Toggle expand/collapse button */
.bmw-gnode-toggle {
    display:         flex;
    align-items:     center;
    justify-content: center;
    gap:             .3rem;
    margin:          6px auto 0;
    padding:         .25rem .6rem;
    background:      #fff;
    border:          1px solid #e2e8f0;
    border-radius:   999px;
    font-size:       .65rem;
    font-weight:     600;
    color:           #64748b;
    cursor:          pointer;
    transition:      all .15s;
    width:           auto;
}
.bmw-gnode-toggle:hover { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.bmw-gnode-toggle.is-collapsed { background: #f8fafc; }
.bmw-gnode-toggle-count {
    background:    #e2e8f0;
    border-radius: 999px;
    padding:       0 .4rem;
    font-size:     .6rem;
    color:         #64748b;
}
.bmw-gnode-toggle:hover .bmw-gnode-toggle-count { background: rgba(255,255,255,.3); color: #fff; }

/* Search states */
.bmw-gnode-match .bmw-gnode-inner {
    border-color: #f59e0b !important;
    box-shadow:   0 0 0 3px rgba(245,158,11,.2) !important;
}
.bmw-gnode-dim { opacity: .2; pointer-events: none; }
.bmw-gnode-dim .bmw-gnode-inner { border-color: #e2e8f0 !important; }

/* ── Detail panel ───────────────────────────────────────────── */
.bmw-tree-panel {
    position:   absolute;
    top:        0;
    right:      -340px;
    width:      320px;
    height:     100%;
    background: #fff;
    border-left: 1px solid #e2e8f0;
    box-shadow: -4px 0 24px rgba(0,0,0,.1);
    transition: right .28s cubic-bezier(.4,0,.2,1);
    z-index:    100;
    overflow-y: auto;
    overflow-x: hidden;
    display:    flex;
    flex-direction: column;
}
.bmw-tree-panel.is-open { right: 0; }
.bmw-tree-panel-close {
    position:   absolute;
    top:        .75rem;
    right:      .75rem;
    background: #f1f5f9;
    border:     none;
    width:      28px;
    height:     28px;
    border-radius: 50%;
    font-size:  1.1rem;
    line-height: 1;
    cursor:     pointer;
    color:      #64748b;
    display:    flex;
    align-items: center;
    justify-content: center;
    z-index:    101;
    transition: background .15s;
}
.bmw-tree-panel-close:hover { background: #ef4444; color: #fff; }
.bmw-tree-panel-body { padding: 1.5rem 1.25rem; }

/* Panel content */
.bmw-panel-avatar-wrap {
    display:     flex;
    align-items: center;
    gap:         1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid #e2e8f0;
}
.bmw-panel-avatar {
    width:         64px;
    height:        64px;
    border-radius: 50%;
    object-fit:    cover;
    border:        2px solid #e2e8f0;
    flex-shrink:   0;
}
.bmw-panel-name {
    font-size:   1rem;
    font-weight: 700;
    color:       #0f172a;
    margin-bottom: .2rem;
}
.bmw-panel-username {
    font-size: .78rem;
    color:     #94a3b8;
    margin-bottom: .4rem;
}
.bmw-panel-rank {
    display:     inline-flex;
    align-items: center;
    gap:         .3rem;
    font-size:   .72rem;
    font-weight: 700;
    padding:     .2rem .65rem;
    border-radius: 999px;
}
.bmw-panel-table {
    width:           100%;
    border-collapse: separate;
    border-spacing:  0;
    font-size:       .82rem;
}
.bmw-panel-table th,
.bmw-panel-table td {
    padding:     .55rem .5rem;
    border-bottom: 1px solid #f1f5f9;
}
.bmw-panel-table th {
    color:      #94a3b8;
    font-weight: 600;
    width:       40%;
}
.bmw-panel-table td { color: #0f172a; }
.bmw-panel-link {
    display:     flex;
    align-items: center;
    gap:         .4rem;
    margin-top:  1rem;
    padding:     .625rem 1rem;
    background:  #4f46e5;
    color:       #fff;
    border-radius: .5rem;
    font-size:   .82rem;
    font-weight: 600;
    text-decoration: none;
    justify-content: center;
    transition:  background .15s;
}
.bmw-panel-link:hover { background: #3730a3; color: #fff; text-decoration: none; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
    .bmw-tree-controls { gap: .5rem; }
    .bmw-tree-search-wrap { max-width: 100%; }
    .bmw-tree-level-wrap  { order: 3; }
    .bmw-tree-zoom-wrap   { margin-left: 0; }
    .bmw-tree-panel       { width: 100%; right: -100%; }
    .bmw-tree-viewport    { min-height: 360px; }
}
