/* =============================================================
   IBS Org Chart – Front-End Styles  v1.1.1
   Fonts: Baskerville (headlines) + Work Sans (body) per IBS style guide
   ============================================================= */

@import url('https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;600&display=swap');

/* ---- CSS Custom Properties (overridden by JS from saved colors) ---- */
.ibs-oc-wrapper {
    --oc-primary:    #575B8C;
    --oc-accent:     #CC3F0C;
    --oc-lt-blue:    #A2B6DB;
    --oc-lt-grey:    #DCDCDC;
    --oc-text:       #333333;
    --oc-modal-bg:   #575B8C;
    --oc-card-w:     130px;
    --oc-card-h:     140px;
    --oc-radius:     10px;
    --oc-line:       1.5px;
    --oc-font-body:  'Work Sans', 'Helvetica Neue', sans-serif;
    --oc-font-head:  Baskerville, 'Baskerville Old Face', Georgia, serif;

    font-family: var(--oc-font-body);
    color: var(--oc-text);

    /*
     * FIX #1: Self-contained layout so we are not dependent on the
     * page/theme for overflow behavior. The scroll area is a child
     * element (.ibs-oc-tree-scroll), not the wrapper itself.
     */
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

/* ================================================================
   CONTROLS (search + toggle) — never scroll, always centered
   Full reset of margins/padding/line-height so theme button
   and input global rules cannot push things out of alignment.
   ================================================================ */
.ibs-oc-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    margin: 0 0 20px 0;
    padding: 0;
    line-height: 1;
    box-sizing: border-box;
    float: none;
    clear: both;
}

/* ---- Search Bar ---- */
.ibs-oc-search-wrap {
    position: relative;
    width: 100%;
    max-width: 400px;
    /* Lock to exact input height so the absolutely-positioned icon always centres */
    height: 42px;
    margin: 0;
    padding: 0;
    line-height: 1;
    box-sizing: border-box;
    display: block;
    float: none;
}
.ibs-oc-search {
    display: block !important;
    width: 100% !important;
    height: 42px !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 0 16px 0 40px !important;
    border: 1.5px solid var(--oc-lt-grey) !important;
    border-radius: 24px !important;
    font-family: var(--oc-font-body) !important;
    font-size: 14px !important;
    line-height: 1 !important;
    color: var(--oc-text) !important;
    background: #fff !important;
    transition: border-color 0.2s;
    box-sizing: border-box !important;
    box-shadow: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    margin: 0 !important;
    vertical-align: top;
    transform: none !important;
    top: 0 !important;
    position: absolute !important;
    left: 0 !important;
}
.ibs-oc-search:focus {
    outline: none;
    border-color: var(--oc-primary);
    box-shadow: none;
}
.ibs-oc-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    pointer-events: none;
    display: flex;
    align-items: center;
    line-height: 1;
}
.ibs-oc-search-icon svg { display: block; }

.ibs-oc-search-results-count {
    text-align: center;
    font-size: 12px;
    color: #888;
    margin-bottom: 6px;
    line-height: 1.4;
}

/* ---- View Toggle ---- */
.ibs-oc-toggle {
    display: -webkit-inline-flex;
    display: inline-flex;
    align-items: center;
    gap: 0;
    margin: 0;
    padding: 0;
    border: 1.5px solid var(--oc-primary);
    border-radius: 6px;
    overflow: hidden;
    max-width: 100%;
    line-height: normal;
    vertical-align: top;
    /* Hard-set height so theme global button rules can't inflate it */
    height: 42px;
    box-sizing: border-box;
}
.ibs-oc-tab {
    -webkit-appearance: none !important;
    appearance: none !important;
    display: -webkit-inline-flex !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px;
    height: 100% !important;
    min-height: 0 !important;
    padding: 0 18px !important;
    margin: 0 !important;
    font-family: var(--oc-font-body) !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    line-height: 1 !important;
    cursor: pointer;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: var(--oc-primary) !important;
    transition: background 0.18s, color 0.18s;
    white-space: nowrap;
    text-decoration: none !important;
    box-shadow: none !important;
    vertical-align: middle;
    /* Prevent any theme transforms from throwing off baseline */
    transform: none !important;
    top: auto !important;
    position: relative !important;
}
.ibs-oc-tab:not(:last-child) {
    border-right: 1.5px solid var(--oc-primary) !important;
}
.ibs-oc-tab.active,
.ibs-oc-tab:hover {
    background: var(--oc-primary) !important;
    color: #fff !important;
    text-decoration: none !important;
}
.ibs-oc-tab:focus {
    outline: 2px solid var(--oc-accent);
    outline-offset: -2px;
    box-shadow: none;
}
.ibs-oc-tab svg { display: inline-block; vertical-align: middle; flex-shrink: 0; position: relative; top: -1px; }

/* ---- No-results ---- */
.ibs-oc-no-results {
    text-align: center;
    padding: 32px 20px;
    color: #888;
    font-size: 14px;
}

/* ================================================================
   TREE SCROLL CONTAINER  (FIX #1)
   The tree lives in its own scrollable inner div. Even if a theme
   ancestor has overflow:hidden, scrolling works here because it is
   a block-level scroll container in normal flow.
   ================================================================ */
.ibs-oc-tree-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    /* nudge scrollbar below the tree, not flush with the edge */
    padding-bottom: 8px;
}

/*
 * FIX #2 (centering): tree is min-content wide so it can be as wide as needed,
 * and margin: 0 auto centers it when it fits in the container.
 */
.ibs-oc-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 8px 32px 24px;
    min-width: max-content;
    margin: 0 auto;
}

/* ================================================================
   CONNECTOR LINES — FIX #4
   All connectors are explicit pixel-height divs so we can reason
   about their exact position. The horizontal bar is absolutely
   positioned by JS after the row is in the DOM.
   ================================================================ */

/* Vertical stem from a card downward to its children */
.ibs-oc-v-stem {
    width: var(--oc-line);
    background: var(--oc-lt-blue);
    margin: 0 auto;
    flex-shrink: 0;
}

/*
 * FIX #3: Departments stack VERTICALLY, not horizontally.
 * Each dept-group is a row: label → cards.
 * The groups are stacked in a column under the manager's stem.
 */
.ibs-oc-dept-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

/* Each department block: label pill + short line + cards */
.ibs-oc-dept-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Line between stacked dept groups */
.ibs-oc-dept-connector {
    width: var(--oc-line);
    height: 10px;
    background: var(--oc-lt-blue);
    margin: 0 auto;
}

.ibs-oc-dept-label {
    font-family: var(--oc-font-body);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #fff;
    background: var(--oc-primary);
    border-radius: 3px;
    padding: 3px 10px;
    white-space: nowrap;
}

/* Short line from dept label pill down to its cards */
.ibs-oc-dept-label-line {
    width: var(--oc-line);
    height: 10px;
    background: var(--oc-lt-blue);
    margin: 0 auto;
}

/* ================================================================
   SIBLINGS ROW — FIX #4
   Cards that share a manager are laid out in .ibs-oc-sibling-row.
   A horizontal bar div is inserted by JS, absolutely positioned so
   it spans exactly between the centers of the leftmost and rightmost
   child-columns. Each child-column has a short drop-line from the
   bar down to the card.
   ================================================================ */
.ibs-oc-children-cluster {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ibs-oc-sibling-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    justify-content: center;
    position: relative; /* h-bar is absolute inside here */
}

/* The horizontal connecting bar — left/right/top set by JS */
.ibs-oc-h-bar {
    position: absolute;
    height: var(--oc-line);
    background: var(--oc-lt-blue);
    pointer-events: none;
}

.ibs-oc-child-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Drop line from the h-bar down to the top of the card */
.ibs-oc-drop-line {
    width: var(--oc-line);
    background: var(--oc-lt-blue);
    flex-shrink: 0;
}

/* Tiled grid for many cards in one dept — wraps gracefully */
.ibs-oc-tile-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
    max-width: 560px;
}

/* ---- Employee Card ---- */
.ibs-oc-card {
    width: var(--oc-card-w);
    height: var(--oc-card-h);
    background: #fff;
    border: 1px solid var(--oc-lt-grey);
    border-top: 3px solid var(--oc-primary);
    border-radius: var(--oc-radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 8px 8px;
    cursor: pointer;
    transition: box-shadow 0.18s, transform 0.15s;
    text-align: center;
    gap: 5px;
    box-sizing: border-box;
    flex-shrink: 0;
    font-size: 13px;
    line-height: 1.3;
    text-decoration: none;
    color: var(--oc-text);
}
.ibs-oc-card:hover {
    box-shadow: 0 4px 18px rgba(87, 91, 140, 0.18);
    transform: translateY(-2px);
}
.ibs-oc-card:focus {
    outline: 2px solid var(--oc-primary);
    outline-offset: 2px;
    box-shadow: none;
}

.ibs-oc-avatar {
    width: 50px;
    height: 50px;
    min-width: 50px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--oc-lt-grey);
    flex-shrink: 0;
    background: var(--oc-lt-grey);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.ibs-oc-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 50%;
}
.ibs-oc-avatar-initials {
    font-size: 16px;
    font-weight: 600;
    color: var(--oc-primary);
    line-height: 1;
}

.ibs-oc-card-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--oc-text);
    line-height: 1.3;
    word-break: break-word;
    hyphens: auto;
}
.ibs-oc-card-title {
    font-size: 10px;
    color: #888;
    line-height: 1.3;
    word-break: break-word;
}

/* ================================================================
   LIST VIEWS
   ================================================================ */
.ibs-oc-list {
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
}

.ibs-oc-section-label {
    font-family: var(--oc-font-head);
    font-size: 13px;
    font-weight: normal;
    letter-spacing: 0.05em;
    color: #fff;
    background: var(--oc-primary);
    padding: 6px 16px;
    border-radius: 4px;
    margin: 20px 0 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
    box-sizing: border-box;
}
.ibs-oc-section-label:first-child { margin-top: 0; }
.ibs-oc-section-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
    border-radius: 50%;
    background: rgba(255,255,255,0.4);
}

.ibs-oc-list-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--oc-lt-grey);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
    line-height: 1.3;
    text-decoration: none;
    color: var(--oc-text);
    box-sizing: border-box;
}
.ibs-oc-list-row:hover {
    background: rgba(87, 91, 140, 0.06);
    text-decoration: none;
}
.ibs-oc-list-row:last-child { border-bottom: none; }

.ibs-oc-list-avatar {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--oc-lt-grey);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.ibs-oc-list-avatar img {
    width: 100%; height: 100%;
    object-fit: cover; border-radius: 50%;
}
.ibs-oc-list-avatar-initials {
    font-size: 13px;
    font-weight: 600;
    color: var(--oc-primary);
    line-height: 1;
}

.ibs-oc-list-name {
    font-size: 14px; font-weight: 600;
    color: var(--oc-text); line-height: 1.3;
}
.ibs-oc-list-sub {
    font-size: 12px; color: #888;
    margin-top: 1px; line-height: 1.3;
}

.ibs-oc-loading {
    text-align: center; color: #888;
    padding: 32px; font-size: 14px;
}

/* ================================================================
   MODAL
   ================================================================ */
.ibs-oc-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(51,51,51,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    padding: 16px;
}
.ibs-oc-modal-backdrop[hidden] { display: none !important; }

.ibs-oc-modal-box {
    background: #fff;
    border-radius: 12px;
    width: 360px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 50px rgba(51,51,51,0.25);
    animation: ibs-oc-modal-in 0.2s ease;
}
@keyframes ibs-oc-modal-in {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

.ibs-oc-modal-header {
    background: var(--oc-modal-bg);
    padding: 20px 48px 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    border-radius: 12px 12px 0 0;
}
.ibs-oc-modal-avatar {
    width: 64px; height: 64px; min-width: 64px;
    border-radius: 50%; overflow: hidden;
    border: 3px solid rgba(255,255,255,0.3);
    flex-shrink: 0;
    background: var(--oc-lt-blue);
    display: flex; align-items: center; justify-content: center;
    box-sizing: border-box;
}
.ibs-oc-modal-avatar img {
    width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.ibs-oc-modal-avatar-initials {
    font-size: 22px; font-weight: 600; color: #fff; line-height: 1;
}
.ibs-oc-modal-name {
    font-family: var(--oc-font-head);
    font-size: 18px; color: #fff; line-height: 1.2;
}
.ibs-oc-modal-job-title {
    font-size: 12px; color: rgba(255,255,255,0.75);
    margin-top: 3px; line-height: 1.3;
}
.ibs-oc-modal-close {
    position: absolute; top: 12px; right: 14px;
    background: transparent; border: none;
    color: rgba(255,255,255,0.7); font-size: 22px;
    cursor: pointer; line-height: 1; padding: 4px;
    border-radius: 4px; transition: color 0.15s; box-shadow: none;
}
.ibs-oc-modal-close:hover { color: #fff; }

.ibs-oc-modal-body {
    padding: 20px; display: flex; flex-direction: column; gap: 14px;
}
.ibs-oc-modal-body p.ibs-oc-modal-bio,
.ibs-oc-wrapper .ibs-oc-modal-bio,
#ibs-org-chart-root .ibs-oc-modal-bio,
#ibs-oc-modal-bio,
#ibs-oc-modal-bio p,
#ibs-oc-modal-bio li,
#ibs-oc-modal-bio span {
    font-size: 13px !important;
    line-height: 1.65 !important;
    color: #555 !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: var(--oc-font-body) !important;
    font-weight: 400 !important;
}
#ibs-oc-modal-bio p + p {
    margin-top: 0.6em !important;
}
.ibs-oc-modal-dl {
    display: flex; flex-direction: column; gap: 8px;
    margin: 0; padding: 0; list-style: none;
}
.ibs-oc-modal-row {
    display: flex; gap: 10px; font-size: 13px;
    align-items: flex-start; line-height: 1.4;
}
.ibs-oc-modal-row dt {
    font-weight: 600; color: var(--oc-primary);
    min-width: 90px; flex-shrink: 0;
}
.ibs-oc-modal-row dd { color: var(--oc-text); margin: 0; word-break: break-word; }
.ibs-oc-modal-row a { color: var(--oc-accent); text-decoration: none; font-weight: 600; }
.ibs-oc-modal-row a:hover { text-decoration: underline; }

.ibs-oc-dept-pill {
    display: inline-block;
    background: var(--oc-lt-blue);
    color: var(--oc-text);
    border-radius: 20px;
    padding: 2px 10px;
    font-size: 11px;
    margin: 2px 3px 2px 0;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 600px) {
    .ibs-oc-toggle {
        display: flex; width: 100%; border-radius: 8px;
    }
    .ibs-oc-tab {
        flex: 1; justify-content: center;
        padding: 10px 6px; font-size: 12px;
        border-right: none !important;
        border-bottom: 1.5px solid var(--oc-primary);
    }
    .ibs-oc-tab:last-child { border-bottom: none; }
    .ibs-oc-tab svg { display: none; }
}
