/* General Reset for Chart */
.org-chart-wrapper {
    margin: 40px auto;
    /*font-family: 'Sarabun', 'Prompt', sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto;*/
    background: #fdfdfd;
    padding: 20px;
    border-radius: 12px;
}

.org-chart-main-title {
    text-align: center;
    color: #444;
    font-weight: 700;
    margin-bottom: 20px;
    font-size: 28px;
}

.org-chart-container {
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 20px;
    text-align: center;
}

/* Tree Layout */
.org-tree {
    display: inline-block;
    white-space: nowrap;
}

.org-tree ul {
    padding-top: 20px;
    position: relative;
    transition: all 0.5s;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-left: 0;
    margin: 0;
}

.org-tree li {
    float: left;
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 5px 0 5px;
    transition: all 0.5s;
}

/* Connectors */
.org-tree li::before, .org-tree li::after{
    content: '';
    position: absolute; 
    top: 0; 
    right: 50%;
    border-top: 2px solid #b5b5b5;
    width: 50%; 
    height: 20px;
    z-index: 1;
}
.org-tree li::after {
    right: auto; 
    left: 50%;
    border-left: 2px solid #b5b5b5;
}

/* Cleanup connectors on edges */
.org-tree li:only-child::after, .org-tree li:only-child::before {
    display: none;
}
.org-tree li:only-child { padding-top: 0; }
.org-tree ul.layout-horizontal li:only-child {
    padding-top: 20px; /* If single child but standard layout, padding remains */
}
.org-tree ul.layout-horizontal li:only-child::before,
.org-tree ul.layout-horizontal li:only-child::after {
    display: none;
}
.org-tree li:first-child::before, .org-tree li:last-child::after{
    border: 0 none;
}
.org-tree li:last-child::before{
    border-right: 2px solid #b5b5b5;
    border-radius: 0 5px 0 0;
}
.org-tree li:first-child::after{
    border-radius: 5px 0 0 0;
}

/* Downward connectors from parents */
.org-tree ul.org-children::before {
    content: '';
    position: absolute; 
    top: 0; 
    left: 50%;
    border-left: 2px solid #b5b5b5;
    width: 0; 
    height: 20px;
    margin-left: -1px;
    z-index: 1;
}

/* --- Spine Layout (Multiple Rows) --- */
.org-spine-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}
.org-spine-line {
    position: absolute;
    top: 0;
    bottom: 50px; /* stops before the last row's connection */
    left: 50%;
    border-left: 2px solid #b5b5b5;
    margin-left: -1px;
    z-index: 0;
}
.org-spine-wrapper > ul.spine-row {
    margin-top: 30px;
    z-index: 2;
    padding-top: 20px; 
}
.org-spine-wrapper > ul.spine-row:first-of-type {
    margin-top: 0;
}
.org-spine-wrapper > ul.spine-row::before {
    /* Draw a line UP to connect to the spine or the row above */
    content: '';
    position: absolute;
    top: -30px; 
    left: 50%;
    height: 50px;
    border-left: 2px solid #b5b5b5;
    margin-left: -1px;
    z-index: 0;
}
.org-spine-wrapper > ul.spine-row:first-of-type::before {
    top: 0;
    height: 20px; /* standard height */
}

/* --- Grid Layout (3-Column) --- */
.org-tree ul.layout-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    padding-top: 20px;
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}
.org-tree ul.layout-grid::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: 2px solid #b5b5b5;
    width: 0;
    height: 20px;
    margin-left: -1px;
}
.org-tree ul.layout-grid li {
    padding: 0;
    margin: 0;
    float: none;
    display: flex;
    justify-content: center;
}
.org-tree ul.layout-grid li::before,
.org-tree ul.layout-grid li::after {
    display: none !important; /* Hide horizontal lines */
}
.org-tree ul.layout-grid .org-card {
    margin: 0;
    width: 100%;
    max-width: 100%;
}

/* Organizational Card Defaults */
.org-card {
    border: none;
    padding: 20px;
    text-decoration: none;
    color: #333;
    font-size: 14px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: auto;
    box-sizing: border-box;
    border-radius: 12px;
    background-color: #fff;
    min-width: 220px;
    max-width: 320px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.06);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    z-index: 2;
    white-space: normal; /* allow text wrapping inside card */
    margin: 0 10px;
}

.org-card:hover {
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    transform: translateY(-5px);
}

/* Theme Colors (Applying colors contextually to specific elements) */
li.theme-blue .org-card { border: none; }
li.theme-blue .org-card-position { color: #89CDE9; font-weight: 700; }
li.theme-blue .org-card-assistant-wrapper { background: rgba(137, 205, 233, 0.1); }
li.theme-blue .org-card-assistant-role, li.theme-blue .org-card-assistant-name { color: #89CDE9; }
li.theme-blue .org-card-img { border-color: #89CDE9; }

li.theme-green .org-card { border: none; }
li.theme-green .org-card-position { color: #4dc2aa; font-weight: 700; }
li.theme-green .org-card-assistant-wrapper { background: rgba(77, 194, 170, 0.1); }
li.theme-green .org-card-assistant-role, li.theme-green .org-card-assistant-name { color: #4dc2aa; }
li.theme-green .org-card-img { border-color: #4dc2aa; }


/* Internal Card Elements */
.org-card-img {
    margin: 0 auto 15px auto;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #fff;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    overflow: hidden;
}

.org-card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.org-avatar-placeholder {
    font-size: 32px;
    font-weight: bold;
    color: #aaa;
    text-transform: uppercase;
}

.org-prefix {
    font-size: 13px;
    font-weight: 500;
    color: #666;
    margin-right: 2px;
}

.org-card-name {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 5px;
    line-height: 1.25;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.org-card-position {
    font-size: 11px;
    color: #666;
    margin-bottom: 10px;
    line-height: 1.35;
    min-height: 48px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
}

.org-card-assistant-wrapper {
    background: #fafafa;
    padding: 8px 10px;
    border-radius: 8px;
    line-height: 1.3;
    margin-top: 5px;
    min-height: 48px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
}

.org-card-assistant-role {
    font-size: 10px;
    opacity: 0.8;
    margin-bottom: 2px;
}

.org-card-assistant-name {
    font-size: 11px;
    font-weight: 600;
}

/* Section Title Block */
.org-card-section-title {
    background-color: #666 !important;
    color: #fff !important;
    text-align: center;
    padding: 12px 15px !important;
    min-width: unset !important;
    height: auto !important;
    border-radius: 8px !important;
    box-shadow: none !important;
}
.org-card-section-title .org-card-name {
    color: #fff !important;
    font-size: 15px !important;
    margin: 0 !important;
}

li.theme-blue .org-card-section-title { background-color: #89CDE9 !important; }
li.theme-green .org-card-section-title { background-color: #4dc2aa !important; }
li.theme-gray .org-card-section-title { background-color: #B5B1C8 !important; }

/* SVG Avatar Fallback */
.org-avatar-placeholder svg {
    width: 60%;
    height: 60%;
    margin-top: 5px; /* slight visual balance */
}

/* Shift 3rd item in a 5-item list */
.org-tree ul.layout-horizontal > li:nth-child(3):nth-last-child(3) {
    margin-right: 50px; /* Slight shift to left to let spine bypass */
}
/* Bridge the horizontal connector gap caused by margin-right */
.org-tree ul.layout-horizontal > li:nth-child(3):nth-last-child(3)::after {
    width: calc(50% + 50px);
}

/* Make horizontal cards smaller to fit 5 per row */
.org-tree ul.layout-horizontal .org-card {
    width: 190px;
    min-width: 190px;
    max-width: 190px;
    padding: 12px;
    margin: 0 2px;
    height: auto;
}
.org-tree ul.layout-horizontal .org-card-name {
    font-size: 13px;
}
.org-tree ul.layout-horizontal .org-card-position {
    font-size: 10.5px;
    line-height: 1.3;
}
.org-tree ul.layout-horizontal .org-card-assistant-name {
    font-size: 10px;
}
.org-tree ul.layout-horizontal .org-card-assistant-role {
    font-size: 9px;
}
.org-tree ul.layout-horizontal .org-card-img {
    width: 60px;
    height: 60px;
}

/* Hide top connection */
ul.hide-top-connection::before {
    display: none !important;
}

/* Dummy Node to help balance horizontal rows in spine layout */
.org-dummy-node {
    visibility: hidden !important;
}
.org-tree li:has(+ li.org-dummy-node:last-child)::after {
    border: 0 none !important;
}
.org-tree li:has(+ li.org-dummy-node:last-child)::before {
    border-right: 2px solid #b5b5b5 !important;
    border-radius: 0 5px 0 0 !important;
}

/* Responsive adjustments */
@media screen and (max-width: 900px) {
    .org-tree ul.layout-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media screen and (max-width: 768px) {
    .org-card {
        min-width: 140px;
        padding: 15px;
    }
    .org-card-img {
        width: 60px;
        height: 60px;
    }
    .org-card-name { font-size: 14px; }
    .org-card-position { font-size: 12px; }
    .org-card-assistant { font-size: 11px; }
    
    .org-tree ul.layout-grid {
        grid-template-columns: 1fr;
    }
}
