/* =========================================================
   Sanjyra — modern tree (used on tree2.html)
   Класс-обёртка: .sm-tree-app
   Само дерево: .sm-tree (заменяет старый .tree)
   ========================================================= */

.sm-tree-app {
    --st-line:       rgba(212, 175, 55, 0.55);
    --st-line-dim:   rgba(212, 175, 55, 0.20);
    --st-node-bg:    linear-gradient(135deg, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.12) 100%);
    --st-node-bg-h:  linear-gradient(135deg, rgba(212,175,55,0.18) 0%, rgba(255,215,107,0.08) 100%);
    --st-node-fg:    #f0f3f9;
    --st-node-fg-h:  #ffd76b;
    --st-node-border: rgba(255, 255, 255, 0.18);
    --st-node-border-h: rgba(212, 175, 55, 0.7);
    --st-zoom: 1;

    margin: 24px auto;
    max-width: 1320px;
    padding: 0 16px;
    position: relative;
    z-index: 2;
}

/* ---------- TOOLBAR ---------- */
.sm-tree-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    margin-bottom: 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 999px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 80px;
    z-index: 5;
}

.sm-tree-search {
    flex: 1 1 240px;
    min-width: 180px;
    background: rgba(0, 0, 0, 0.25) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: #fff !important;
    border-radius: 999px;
    padding: 8px 16px 8px 38px;
    font-size: 14px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffd76b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>") !important;
    background-repeat: no-repeat !important;
    background-position: 12px center !important;
    background-size: 16px 16px !important;
    transition: border-color .25s ease, box-shadow .25s ease;
}
.sm-tree-search::placeholder { color: rgba(255,255,255,0.45); }
.sm-tree-search:focus {
    border-color: rgba(212, 175, 55, 0.7) !important;
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.18) !important;
    outline: none;
}

.sm-tree-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #f0f3f9;
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s ease;
    white-space: nowrap;
}
.sm-tree-btn:hover {
    background: rgba(212, 175, 55, 0.15);
    border-color: rgba(212, 175, 55, 0.6);
    color: #ffd76b;
    transform: translateY(-1px);
}

.sm-tree-zoom {
    display: inline-flex; align-items: center;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 4px;
    gap: 2px;
}
.sm-tree-zoom button {
    width: 32px; height: 32px;
    background: transparent;
    border: 0;
    color: #f0f3f9;
    border-radius: 999px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: background .2s ease, color .2s ease;
}
.sm-tree-zoom button:hover {
    background: rgba(212, 175, 55, 0.20);
    color: #ffd76b;
}
.sm-tree-zoom-level {
    min-width: 48px;
    text-align: center;
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    font-variant-numeric: tabular-nums;
}

/* ---------- CANVAS ---------- */
.sm-tree-canvas {
    position: relative;
    overflow: auto;
    border-radius: 18px;
    background:
        radial-gradient(ellipse at top, rgba(212, 175, 55, 0.06) 0%, transparent 60%),
        rgba(0, 0, 0, 0.20);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 20px 16px 24px;
    min-height: 280px;
    max-height: 78vh;
    box-shadow: inset 0 0 60px rgba(0,0,0,0.4);
    -webkit-overflow-scrolling: touch;
    scrollbar-color: rgba(212,175,55,0.4) rgba(0,0,0,0.3);
    scrollbar-width: thin;
}
.sm-tree-canvas::-webkit-scrollbar { width: 10px; height: 10px; }
.sm-tree-canvas::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 999px; }
.sm-tree-canvas::-webkit-scrollbar-thumb { background: rgba(212,175,55,0.4); border-radius: 999px; }
.sm-tree-canvas::-webkit-scrollbar-thumb:hover { background: rgba(212,175,55,0.7); }

.sm-tree-canvas.is-fullscreen {
    max-height: none;
    height: 100vh;
    border-radius: 0;
}

.sm-tree-fs-btn {
    position: absolute;
    right: 12px; top: 12px;
    z-index: 10;
}

/* ---------- ДЕРЕВО ---------- */
.sm-tree {
    transform: scale(var(--st-zoom));
    transform-origin: top center;
    transition: transform .35s cubic-bezier(.2,.8,.2,1);
    padding: 8px 0;
    width: max-content;
    min-width: 100%;
    margin: 0 auto;
    opacity: 0;
    animation: sm-tree-fade-in .8s ease-out .15s forwards;
}

.sm-tree ul {
    padding-top: 28px;
    position: relative;
    transition: all .35s ease;
    list-style: none;
    margin: 0;
    display: flex;
    justify-content: center;
}

.sm-tree li {
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 28px 6px 6px 6px;
    transition: all .35s ease;
    flex: 0 0 auto;
}

/* Линии-соединители: к родителю */
.sm-tree li::before,
.sm-tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-top: 1.5px solid var(--st-line);
    width: 50%;
    height: 28px;
    pointer-events: none;
    transition: border-color .3s ease;
}
.sm-tree li::after {
    right: auto;
    left: 50%;
    border-left: 1.5px solid var(--st-line);
}
.sm-tree li:only-child::before,
.sm-tree li:only-child::after { display: none; }
.sm-tree li:only-child { padding-top: 0; }
.sm-tree li:first-child::before,
.sm-tree li:last-child::after { border: 0 none; }
.sm-tree li:last-child::before {
    border-right: 1.5px solid var(--st-line);
    border-radius: 0 6px 0 0;
}
.sm-tree li:first-child::after { border-radius: 6px 0 0 0; }
.sm-tree ul ul::before {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    border-left: 1.5px solid var(--st-line);
    width: 0;
    height: 28px;
    pointer-events: none;
    transition: border-color .3s ease;
}

/* Узлы (a) */
.sm-tree li > a {
    display: inline-block;
    position: relative;
    padding: 8px 16px;
    background: var(--st-node-bg);
    border: 1px solid var(--st-node-border);
    border-radius: 12px;
    color: var(--st-node-fg);
    font-family: 'Ubuntu Condensed', 'Istok Web', sans-serif;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-decoration: none;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow:
        0 4px 14px rgba(0,0,0,0.3),
        inset 0 1px 0 rgba(255,255,255,0.08);
    transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease, background .25s ease, color .25s ease;
    white-space: nowrap;
}
.sm-tree li > a:hover,
.sm-tree li > a:focus {
    background: var(--st-node-bg-h);
    color: var(--st-node-fg-h);
    border-color: var(--st-node-border-h);
    box-shadow:
        0 0 24px rgba(212, 175, 55, 0.45),
        0 8px 22px rgba(0,0,0,0.4),
        inset 0 1px 0 rgba(255,255,255,0.12);
    transform: translateY(-2px);
}

/* Корневой узел (1-й уровень) — крупнее, золотой */
.sm-tree > ul > li > a {
    background: linear-gradient(135deg, #d4af37 0%, #ffd76b 100%);
    color: #1a1408;
    border-color: rgba(212, 175, 55, 0.8);
    font-size: 17px;
    padding: 10px 22px;
    box-shadow:
        0 0 32px rgba(212, 175, 55, 0.5),
        0 8px 24px rgba(0,0,0,0.35);
}
.sm-tree > ul > li > a:hover {
    color: #1a1408;
    background: linear-gradient(135deg, #ffd76b 0%, #fff7c2 100%);
    box-shadow: 0 0 40px rgba(255, 215, 107, 0.65), 0 10px 28px rgba(0,0,0,0.4);
    transform: translateY(-3px) scale(1.02);
}

/* 2-й уровень — золотая обводка */
.sm-tree > ul > li > ul > li > a {
    border-color: rgba(212, 175, 55, 0.45);
    box-shadow:
        0 4px 14px rgba(0,0,0,0.3),
        0 0 14px rgba(212, 175, 55, 0.15),
        inset 0 1px 0 rgba(255,255,255,0.08);
}

/* Toggle-кнопка (показывает/скрывает поддерево) */
.sm-tree__toggle {
    display: inline-flex;
    align-items: center; justify-content: center;
    width: 22px; height: 22px;
    margin-left: 6px;
    border: 1px solid rgba(212, 175, 55, 0.5);
    background: rgba(0, 0, 0, 0.4);
    color: #ffd76b;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    transition: background .2s ease, transform .2s ease, color .2s ease;
    vertical-align: middle;
}
.sm-tree__toggle:hover {
    background: rgba(212, 175, 55, 0.25);
    transform: scale(1.12);
    color: #fff;
}

.sm-tree li.is-collapsed > ul { display: none !important; }
.sm-tree li.is-collapsed > .sm-tree__toggle { background: rgba(212, 175, 55, 0.25); }

/* Поиск: подсветка совпадений */
.sm-tree li.is-match > a {
    box-shadow:
        0 0 0 2px var(--st-node-fg-h),
        0 0 30px rgba(255, 215, 107, 0.7),
        inset 0 1px 0 rgba(255,255,255,0.12) !important;
    border-color: var(--st-node-fg-h) !important;
    animation: sm-tree-pop .5s ease-out;
}
.sm-tree.is-searching li:not(.is-match):not(.has-match-descendant) > a {
    opacity: 0.25;
    filter: grayscale(0.6);
}
.sm-tree.is-searching li.has-match-descendant > a {
    border-color: rgba(212, 175, 55, 0.5) !important;
}

/* ---------- ANIMATIONS ---------- */
@keyframes sm-tree-fade-in {
    from { opacity: 0; transform: scale(calc(var(--st-zoom) * 0.96)); }
    to   { opacity: 1; transform: scale(var(--st-zoom)); }
}
@keyframes sm-tree-pop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}

/* ---------- MOBILE ---------- */
@media (max-width: 768px) {
    .sm-tree-app { padding: 0 8px; }
    .sm-tree-toolbar {
        padding: 10px;
        border-radius: 18px;
        top: 70px;
    }
    .sm-tree-search { flex: 1 1 100%; order: -1; }
    .sm-tree-btn { font-size: 12px; padding: 6px 10px; }
    .sm-tree-canvas {
        max-height: 70vh;
        padding: 14px 8px;
        border-radius: 14px;
    }
    .sm-tree li { padding: 22px 4px 4px 4px; }
    .sm-tree li > a {
        font-size: 12px;
        padding: 6px 10px;
        border-radius: 10px;
    }
    .sm-tree > ul > li > a {
        font-size: 14px;
        padding: 8px 14px;
    }
    .sm-tree li::before,
    .sm-tree li::after,
    .sm-tree ul ul::before { height: 22px; }
    .sm-tree__toggle { width: 18px; height: 18px; font-size: 10px; }
    .sm-tree ul { padding-top: 22px; }
}

@media (max-width: 480px) {
    .sm-tree-toolbar { gap: 6px; }
    .sm-tree-zoom button { width: 28px; height: 28px; }
    .sm-tree-zoom-level { min-width: 38px; font-size: 11px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .sm-tree { animation: none; opacity: 1; }
    .sm-tree li.is-match > a { animation: none; }
}
