/* ============================
   Responsive Tree - Desktop/Mobile Switch
   ============================ */

.bjj-tree-desktop {
    display: block;
}

.bjj-tree-mobile {
    display: none;
}

@media (max-width: 1100px) {
    .bjj-tree-desktop {
        display: none;
    }
    
    .bjj-tree-mobile {
        display: block;
    }
}

/* ============================
   Prevent page-level overflow
   ============================ */

body {
    overflow-x: hidden;
}

/* ============================
   Horizontal Tree (Desktop)
   ============================ */

.bjj-horizontal-tree {
    width: 100%;
    max-width: 100vw;
    overflow-x: auto;
    overflow-y: visible;
    padding: 30px 10px 50px;
    position: relative;
    cursor: grab;
    -webkit-overflow-scrolling: touch;
}

.bjj-horizontal-tree:active {
    cursor: grabbing;
}

/* Scroll hint */
.bjj-scroll-hint {
    display: none;
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    color: #666;
    font-size: 12px;
    letter-spacing: 0.5px;
    z-index: 5;
    animation: bjj-pulse 2s ease-in-out infinite;
}

.bjj-horizontal-tree.is-scrollable .bjj-scroll-hint {
    display: block;
}

@keyframes bjj-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.bjj-htree-container {
    display: flex;
    justify-content: center;
    min-width: fit-content;
    padding: 0 20px;
}

/* ============================
   Node Wrapper
   ============================ */

.bjj-htree-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* ============================
   Card Styling
   ============================ */

.bjj-htree-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(10px, 1.2vw, 16px) clamp(12px, 1.5vw, 20px);
    background: linear-gradient(135deg, #1a1a1a 0%, #252525 100%);
    border: 2px solid #333;
    border-radius: 10px;
    text-decoration: none;
    color: #fff;
    min-width: clamp(100px, 11vw, 160px);
    max-width: clamp(120px, 14vw, 200px);
    position: relative;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}

.bjj-htree-card:hover {
    border-color: #c41e3a;
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(196, 30, 58, 0.3);
}

/* ============================
   Dropdown Card + Expand Button (Gen 4+)
   Card is always a link. Button sits below as "View Students" bar.
   ============================ */

/* Card inside a dropdown node gets extra bottom padding for the bar */
.bjj-htree-node.has-dropdown > .bjj-htree-card {
    padding-bottom: clamp(30px, 3vw, 42px);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
}

/* When expanded, card gets the red accent */
.bjj-htree-node.has-dropdown.is-expanded > .bjj-htree-card {
    border-color: #c41e3a;
    background: linear-gradient(135deg, #2a1515 0%, #1a1a1a 100%);
}

/* Hover: only shift the card, not the whole node */
.bjj-htree-node.has-dropdown > .bjj-htree-card:hover {
    transform: none;
}

/* Expand button — renders as the "View Students" / "Hide Students" bar */
.bjj-htree-expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(100% - 0px);
    min-width: clamp(100px, 11vw, 160px);
    max-width: clamp(120px, 14vw, 200px);
    padding: 6px 0;
    margin-top: -2px;
    background: #c41e3a;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    border: 2px solid #c41e3a;
    border-top: none;
    border-radius: 0 0 10px 10px;
    cursor: pointer;
    transition: background 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}

.bjj-htree-expand-btn:hover {
    background: #e0223f;
}

.bjj-htree-expand-btn[aria-expanded="true"] {
    background: #333;
    border-color: #333;
}

.bjj-htree-expand-btn[aria-expanded="true"]:hover {
    background: #444;
}

/* Label text for the expand button */
.bjj-htree-expand-btn::after {
    content: 'View Students';
}

.bjj-htree-expand-btn[aria-expanded="true"]::after {
    content: 'Hide Students';
}

/* Hide the count badge and caret inside the expand button — use the text label instead */
.bjj-htree-expand-btn .bjj-htree-count {
    position: static;
    background: rgba(255,255,255,0.2);
    border: none;
    min-width: 18px;
    height: 18px;
    font-size: 9px;
    margin-right: 6px;
}

.bjj-htree-expand-btn .bjj-caret {
    display: none;
}

/* Photo */
.bjj-htree-photo {
    width: clamp(40px, 4.5vw, 65px);
    height: clamp(40px, 4.5vw, 65px);
    border-radius: 50%;
    overflow: hidden;
    background: #c41e3a;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: clamp(6px, 0.8vw, 12px);
    border: 2px solid #444;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.bjj-htree-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bjj-htree-photo .bjj-initials {
    color: #fff;
    font-size: clamp(15px, 1.8vw, 24px);
    font-weight: 700;
}

/* Info */
.bjj-htree-info {
    text-align: center;
}

.bjj-htree-name {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-weight: 700;
    font-size: clamp(11px, 1.1vw, 14px);
    margin-bottom: 2px;
    text-align: center;
    line-height: 1.3;
}

.bjj-htree-name .bjj-verified {
    color: #28a745;
    font-size: clamp(9px, 0.9vw, 12px);
}

.bjj-htree-rank {
    font-size: clamp(10px, 0.9vw, 12px);
    color: #999;
}

/* Student count badge (on regular non-dropdown cards) */
.bjj-htree-count {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    background: #c41e3a;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    border: 2px solid #111;
    gap: 2px;
}

/* Children container */
.bjj-htree-children {
    display: flex;
    justify-content: center;
    padding-top: clamp(30px, 3.5vw, 50px);
    position: relative;
    gap: clamp(8px, 1vw, 16px);
}

/* ============================
   Connection Lines
   ============================ */

/* Vertical line down from parent */
.bjj-htree-node.has-children:not(.has-dropdown) > .bjj-htree-card::after {
    content: '';
    position: absolute;
    bottom: calc(clamp(15px, 1.8vw, 25px) * -1);
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 0;
    background: #c41e3a;
    transition: height 0.4s ease-out;
}

.bjj-htree-node.has-children:not(.has-dropdown).lines-visible > .bjj-htree-card::after {
    height: clamp(15px, 1.8vw, 25px);
}

/* Horizontal connector line */
.bjj-htree-children::before {
    content: '';
    position: absolute;
    top: clamp(15px, 1.8vw, 25px);
    left: var(--line-left, 50%);
    right: var(--line-right, 50%);
    height: 2px;
    background: #c41e3a;
    transform: scaleX(0);
    transition: transform 0.5s ease-out 0.2s;
}

.bjj-htree-node.lines-visible > .bjj-htree-children::before {
    transform: scaleX(1);
}

.bjj-htree-children[data-count="1"]::before {
    display: none;
}

/* Vertical line up from each child */
.bjj-htree-children > .bjj-htree-node::before {
    content: '';
    position: absolute;
    top: calc(clamp(15px, 1.8vw, 25px) * -1);
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 0;
    background: #c41e3a;
    transition: height 0.4s ease-out 0.4s;
}

.lines-visible > .bjj-htree-children > .bjj-htree-node::before {
    height: clamp(15px, 1.8vw, 25px);
}

/* ============================
   Root Node (Larger)
   ============================ */

.bjj-htree-node[data-depth="0"] > .bjj-htree-card {
    min-width: clamp(110px, 12vw, 170px);
    padding: clamp(14px, 1.4vw, 20px) clamp(16px, 1.6vw, 24px);
    border-color: #c41e3a;
    background: linear-gradient(135deg, #2a1515 0%, #1a1a1a 100%);
}

.bjj-htree-node[data-depth="0"] > .bjj-htree-card .bjj-htree-photo {
    width: clamp(50px, 5.5vw, 75px);
    height: clamp(50px, 5.5vw, 75px);
    border-color: #c41e3a;
}

.bjj-htree-node[data-depth="0"] > .bjj-htree-card .bjj-htree-name {
    font-size: clamp(12px, 1.2vw, 16px);
}

/* ============================
   Depth-based line colors
   ============================ */

.bjj-htree-node[data-depth="1"] .bjj-htree-children::before,
.bjj-htree-node[data-depth="1"] .bjj-htree-children > .bjj-htree-node::before,
.bjj-htree-node[data-depth="1"].has-children:not(.has-dropdown) > .bjj-htree-card::after {
    background: #aa3333;
}

.bjj-htree-node[data-depth="2"] .bjj-htree-children::before,
.bjj-htree-node[data-depth="2"] .bjj-htree-children > .bjj-htree-node::before,
.bjj-htree-node[data-depth="2"].has-children:not(.has-dropdown) > .bjj-htree-card::after {
    background: #666;
}

/* ============================
   Card Animation
   ============================ */

.bjj-htree-node {
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.bjj-htree-node.visible {
    opacity: 1;
    transform: translateY(0);
}

.bjj-htree-node[data-depth="0"] { transition-delay: 0s; }
.bjj-htree-node[data-depth="1"] { transition-delay: 0.15s; }
.bjj-htree-node[data-depth="2"] { transition-delay: 0.3s; }

/* ============================
   Vertical Dropdown (Desktop - Gen 4+)
   ============================ */

.bjj-htree-dropdown {
    position: relative;
    margin-top: 12px;
    width: clamp(240px, 22vw, 320px);
    z-index: 20;
    animation: bjj-dropdown-in 0.3s ease-out;
}

@keyframes bjj-dropdown-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Connector line from card to dropdown */
.bjj-dropdown-connector {
    width: 2px;
    height: 12px;
    background: #c41e3a;
    margin: 0 auto;
}

/* Dropdown list */
.bjj-dropdown-list {
    list-style: none;
    padding: 0;
    margin: 0;
    background: #151515;
    border: 1px solid #333;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

/* Dropdown item */
.bjj-dropdown-item {
    border-bottom: 1px solid #222;
}

.bjj-dropdown-item:last-child {
    border-bottom: none;
}

/* Dropdown row */
.bjj-dropdown-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
}

/* Toggle button in dropdown */
.bjj-dropdown-toggle {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid #c41e3a;
    background: transparent;
    color: #c41e3a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    flex-shrink: 0;
    margin-left: 8px;
    transition: all 0.2s;
}

.bjj-dropdown-toggle:hover {
    background: #c41e3a;
    color: #fff;
}

.bjj-dropdown-spacer {
    width: 26px;
    flex-shrink: 0;
    margin-left: 8px;
}

/* Dropdown card */
.bjj-dropdown-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 10px 4px;
    text-decoration: none;
    color: #fff;
    flex: 1;
    min-width: 0;
    transition: background 0.2s;
    border-radius: 6px;
}

.bjj-dropdown-card:hover {
    background: rgba(196, 30, 58, 0.1);
}

/* Dropdown photo */
.bjj-dropdown-photo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: #c41e3a;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid #333;
}

.bjj-dropdown-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bjj-dropdown-photo .bjj-initials {
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}

/* Dropdown info */
.bjj-dropdown-info {
    flex: 1;
    min-width: 0;
}

.bjj-dropdown-name {
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.3;
}

.bjj-verified-small {
    color: #28a745;
    font-size: 10px;
}

.bjj-dropdown-rank {
    font-size: 11px;
    color: #888;
}

/* Dropdown student count */
.bjj-dropdown-count {
    padding: 3px 8px;
    background: #c41e3a;
    border-radius: 10px;
    font-size: 10px;
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Nested dropdown children */
.bjj-dropdown-children {
    list-style: none;
    padding: 0;
    margin: 0;
    margin-left: 34px;
    padding-left: 16px;
    border-left: 2px solid #333;
}

.bjj-dropdown-children .bjj-dropdown-item {
    border-bottom: none;
}

.bjj-dropdown-children .bjj-dropdown-row {
    padding: 2px 4px;
}

.bjj-dropdown-children .bjj-dropdown-card {
    padding: 8px 10px 8px 4px;
}

.bjj-dropdown-children .bjj-dropdown-photo {
    width: 30px;
    height: 30px;
}

.bjj-dropdown-children .bjj-dropdown-photo .bjj-initials {
    font-size: 11px;
}

.bjj-dropdown-children .bjj-dropdown-name {
    font-size: 12px;
}

.bjj-dropdown-children .bjj-dropdown-rank {
    font-size: 10px;
}

/* Deeper nesting */
.bjj-dropdown-children .bjj-dropdown-children {
    margin-left: 30px;
    border-left-color: #2a2a2a;
}

/* ============================
   Collapsible Tree (Mobile)
   ============================ */

.bjj-collapsible-tree {
    max-width: 100%;
    padding: 20px;
}

.bjj-tree-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #333;
}

.bjj-expand-all,
.bjj-collapse-all {
    padding: 8px 16px;
    background: #222;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.bjj-expand-all:hover,
.bjj-collapse-all:hover {
    background: #c41e3a;
    border-color: #c41e3a;
}

.bjj-tree-root {
    list-style: none;
    padding: 0;
    margin: 0;
}

.bjj-tree-children {
    list-style: none;
    padding: 0;
    margin: 0;
    margin-left: 20px;
    padding-left: 20px;
    border-left: 2px solid #c41e3a;
}

.bjj-tree-node {
    position: relative;
    padding: 8px 0;
}

.bjj-tree-children > .bjj-tree-node::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 32px;
    width: 20px;
    height: 2px;
    background: #c41e3a;
}

.bjj-node-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bjj-toggle-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #c41e3a;
    background: #111;
    color: #c41e3a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    flex-shrink: 0;
}

.bjj-toggle-btn:hover {
    background: #c41e3a;
    color: #fff;
}

.bjj-toggle-spacer {
    width: 28px;
    flex-shrink: 0;
}

.bjj-node-card-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    text-decoration: none;
    color: #fff;
    flex: 1;
    transition: all 0.2s;
}

.bjj-node-card-inline:hover {
    border-color: #c41e3a;
}

.bjj-node-photo-small {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
    background: #c41e3a;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bjj-node-photo-small img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bjj-node-photo-small .bjj-initials {
    color: #fff;
    font-size: 18px;
    font-weight: 700;
}

.bjj-node-details {
    flex: 1;
    min-width: 0;
}

.bjj-node-name {
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.bjj-verified-check {
    color: #28a745;
    font-size: 12px;
}

.bjj-node-rank {
    font-size: 12px;
    color: #999;
}

.bjj-student-count {
    padding: 4px 10px;
    background: #c41e3a;
    border-radius: 12px;
    font-size: 11px;
    color: #fff;
    white-space: nowrap;
}