/* تنظیمات پایه صفحه */
.chart-wrapper {
    width: 100%;
    min-height: 100vh;
    background: #f7f9fc;
    padding: 40px 20px;
    overflow-x: auto;
    box-sizing: border-box;
}

.loader {
    text-align: center;
    font-size: 16px;
    color: #4a5c72;
    margin-top: 50px;
    font-weight: bold;
}

/* =========================================
   ساختار درخت (Tree Structure)
   ========================================= */
.tree {
    display: flex;
    justify-content: center;
    width: 100%;
}

.tree ul {
    padding-top: 30px;
    position: relative;
    display: flex;
    justify-content: center;
    transition: all 0.5s;
    padding-right: 0;
}

.tree li {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 30px 10px 0 10px;
    transition: all 0.5s;
    list-style: none;
}

/* خطوط اتصال درخت (CSS Pseudo-elements) */
.tree li::before, .tree li::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 50%;
    height: 30px;
    border-top: 2px solid #b7c7d9;
}

.tree li::after {
    left: auto;
    right: 50%;
    border-left: 2px solid #b7c7d9;
}

/* حذف خطوط اضافی برای تک فرزندها و اولین/آخرین فرزندها */
.tree li:only-child::after, .tree li:only-child::before { display: none; }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-left: 2px solid #b7c7d9; border-radius: 0 0 0 5px; }
.tree li:first-child::after { border-radius: 0 0 5px 0; }

/* خط عمودی اتصال والد به فرزندان */
.tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-right: 2px solid #b7c7d9;
    width: 0;
    height: 30px;
}

/* =========================================
   استایل کارت‌ها (Nodes)
   ========================================= */
.node-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #ffffff;
    border: 1px solid #d8e2ef;
    border-radius: 12px;
    padding: 10px 16px;
    min-width: 140px;
    max-width: 220px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    z-index: 2;
}

.node-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(47, 128, 237, 0.15);
    border-color: #2f80ed;
}

/* استایل تفکیک شده برای ریشه، دسته‌بندی و سامانه */
.node-card.is-root {
    background: linear-gradient(135deg, #16324f 0%, #2a4d74 100%);
    color: #ffffff;
    border: none;
    font-size: 16px;
    padding: 14px 20px;
    font-weight: bold;
}

.node-card.is-category {
    background: #eef5ff;
    border: 1px solid #c6dbf7;
    border-bottom: 3px solid #2f80ed;
}

.node-card.is-system {
    background: #ffffff;
    border: 1px solid #e3eaf3;
}

/* آیکون‌ها و لوگوها */
.node-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 6px;
    background: #f1f5f9;
    flex-shrink: 0;
}

.node-icon-default {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: #e2e8f0;
    font-size: 18px;
    flex-shrink: 0;
}

.node-title {
    font-size: 13px;
    font-weight: 600;
    color: #16324f;
    white-space: normal;
    text-align: right;
    line-height: 1.4;
}

.is-root .node-title {
    color: #ffffff;
    font-size: 15px;
}

/* =========================================
   استایل مودال (پنجره بازشونده)
   ========================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 25, 40, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

.modal-box {
    background: #fff;
    border-radius: 16px;
    max-width: 440px;
    width: 100%;
    padding: 24px;
    position: relative;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
    direction: rtl;
    animation: pop .2s ease-out;
}

@keyframes pop {
    from { transform: scale(.9); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 15px;
    left: 15px;
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    color: #4a5c72;
    transition: background 0.2s;
}
.modal-close:hover { background: #e2e8f0; }

.modal-head {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid #e3eaf3;
    padding-bottom: 15px;
}

.modal-logo {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 12px;
    background: #f1f5f9;
}

.modal-title {
    font-size: 18px;
    font-weight: bold;
    color: #16324f;
    margin: 0;
}

.modal-desc {
    font-size: 14px;
    line-height: 1.8;
    color: #4a5c72;
    margin-bottom: 20px;
}

.modal-link {
    display: inline-block;
    background: #2f80ed;
    color: #fff;
    text-decoration: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: bold;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
    transition: background 0.2s, box-shadow 0.2s;
}
.modal-link:hover {
    background: #1c6fd8;
    box-shadow: 0 4px 15px rgba(47,128,237,.4);
}