/* ISP Organogram Pro v5.0 - style.css - FIXED */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.isp-wrapper {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f4f8;
    padding: 20px;
    border-radius: 12px;
    color: #333;
}

/* HEADER */
.isp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    background: #fff;
    padding: 14px 18px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,.07);
}
.isp-header h2  { color: #1a3a5c; font-size: 20px; font-weight: 700; margin-bottom: 3px; }
.isp-header p   { color: #777; font-size: 12px; }
.isp-header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.isp-badge      { padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 700; color: #fff; }
.isp-badge.editor { background: #e74c3c; }
.isp-badge.viewer { background: #27ae60; }

/* TABS - FIXED */
.isp-tabs {
    display: flex;
    gap: 3px;
    border-bottom: 3px solid #2980b9;
    margin-bottom: 16px;
    overflow-x: auto;
    flex-wrap: nowrap;
}
.isp-tab {
    padding: 9px 16px;
    border: none;
    background: #e8f0fe;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    border-radius: 7px 7px 0 0;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.isp-tab:hover  { background: #c5d8f5; color: #1a3a5c; }
.isp-tab.active { background: #2980b9; color: #fff; }

/* TAB CONTENT - CRITICAL FIX */
.isp-tab-content          { display: none !important; }
.isp-tab-content.active   { display: block !important; animation: isp-fade .3s ease; }
@keyframes isp-fade {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* TOOLBAR */
.isp-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    box-shadow: 0 1px 6px rgba(0,0,0,.06);
    flex-wrap: wrap;
}
.isp-hint          { font-size: 12px; color: #e74c3c; font-weight: 500; }
.isp-zoom-controls { display: flex; gap: 5px; }

/* CHART */
.isp-chart-wrap {
    overflow: auto;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 3px 18px rgba(0,0,0,.07);
    padding: 30px 20px;
    min-height: 400px;
}
.isp-chart-inner {
    display: inline-block;
    transform-origin: top left;
    transition: transform .2s;
    min-width: 100%;
}

/* TREE */
.isp-tree-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 0 10px;
}
.isp-tree-children {
    display: flex;
    justify-content: center;
    position: relative;
    padding-top: 20px;
    gap: 0;
}
.isp-tree-children::before {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    width: 2px; height: 20px;
    background: #2980b9;
    transform: translateX(-50%);
}
.isp-tree-children > .isp-tree-node { position: relative; }
.isp-tree-children > .isp-tree-node::before {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    width: 2px; height: 20px;
    background: #2980b9;
    transform: translateX(-50%);
}
.isp-tree-children > .isp-tree-node:not(:only-child)::after {
    content: '';
    position: absolute;
    top: 0;
    background: #2980b9;
    height: 2px;
}
.isp-tree-children > .isp-tree-node:not(:only-child):first-child::after  { left: 50%; right: -10px; }
.isp-tree-children > .isp-tree-node:not(:only-child):last-child::after   { left: -10px; right: 50%; }
.isp-tree-children > .isp-tree-node:not(:only-child):not(:first-child):not(:last-child)::after { left: -10px; right: -10px; }

/* NODE BOX - FIXED HOVER FOR BUTTONS */
.isp-node {
    display: inline-block;
    cursor: pointer;
    position: relative;
    padding: 10px 5px 0;
}
.isp-node-box {
    padding: 8px 11px;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    min-width: 110px;
    max-width: 155px;
    color: #fff;
    box-shadow: 0 3px 12px rgba(0,0,0,.2);
    border: 2px solid rgba(255,255,255,.25);
    line-height: 1.4;
    position: relative;
    transition: all .2s;
    user-select: none;
}
.isp-node:hover .isp-node-box { filter: brightness(1.1); transform: translateY(-2px); }
.isp-node-box.blue     { background: linear-gradient(135deg, #2980b9, #3498db); }
.isp-node-box.green    { background: linear-gradient(135deg, #27ae60, #2ecc71); }
.isp-node-box.executive { min-width: 130px; font-size: 13px; padding: 10px 13px; }

.node-icon   { font-size: 16px; display: block; margin-bottom: 2px; }
.node-title  { display: block; line-height: 1.3; }
.node-person {
    display: block;
    font-size: 9px;
    color: rgba(255,255,255,.85);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

/* NODE BUTTONS - FIXED: show on .isp-node hover */
.node-btns {
    position: absolute;
    top: -8px;
    right: -8px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .2s;
    z-index: 100;
}
.isp-node:hover .node-btns { opacity: 1; }
.node-btn {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 2px solid #fff;
    color: #fff;
    font-size: 9px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all .2s;
    line-height: 1;
    font-weight: 700;
}
.node-edit-btn { background: #2980b9; }
.node-add-btn  { background: #27ae60; }
.node-del-btn  { background: #e74c3c; }
.node-btn:hover { transform: scale(1.25); }

/* DRAG STATES */
.isp-node.dragging       { opacity: .4; }
.isp-tree-node.drag-over > .isp-node > .isp-node-box {
    box-shadow: 0 0 0 3px #f39c12 !important;
    filter: brightness(1.2);
}

/* DEPT GRID */
.isp-dept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}
.isp-dept-card {
    background: #fff;
    border-radius: 10px;
    padding: 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,.07);
    border-top: 4px solid #2980b9;
    cursor: pointer;
    transition: all .25s;
}
.isp-dept-card:hover    { transform: translateY(-3px); box-shadow: 0 7px 20px rgba(0,0,0,.12); }
.isp-dept-card.green    { border-top-color: #27ae60; }
.isp-card-head          { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.isp-card-icon {
    width: 38px; height: 38px;
    border-radius: 8px;
    background: linear-gradient(135deg, #2980b9, #3498db);
    display: flex; align-items: center; justify-content: center;
    font-size: 17px; flex-shrink: 0;
}
.isp-card-icon.green    { background: linear-gradient(135deg, #27ae60, #2ecc71); }
.isp-card-info          { flex: 1; }
.isp-card-info h4       { font-size: 13px; font-weight: 700; color: #1a3a5c; margin-bottom: 2px; line-height: 1.3; }
.card-person            { color: #27ae60; font-size: 11px; font-weight: 600; margin: 2px 0; }
.card-type              { color: #888; font-size: 11px; display: flex; align-items: center; gap: 5px; }
.color-dot              { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.color-dot.blue         { background: #2980b9; }
.color-dot.green        { background: #27ae60; }
.isp-card-edit {
    background: #e74c3c; color: #fff; border: none;
    border-radius: 6px; padding: 4px 9px; font-size: 11px;
    cursor: pointer; flex-shrink: 0; transition: background .2s;
}
.isp-card-edit:hover    { background: #c0392b; }
.isp-card-stats         { display: flex; gap: 6px; }
.badge                  { padding: 3px 9px; border-radius: 20px; font-size: 10px; font-weight: 600; }
.badge.blue             { background: #e8f4fd; color: #2980b9; }
.badge.green            { background: #e8f8f0; color: #27ae60; }

/* HIERARCHY */
.isp-hierarchy {
    background: #fff;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 2px 10px rgba(0,0,0,.07);
}
.isp-hier-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background .2s;
    margin-bottom: 3px;
    gap: 8px;
    border: 2px solid transparent;
}
.isp-hier-item:hover           { background: #f0f4f8; }
.isp-hier-item.drag-over-hier  { border-color: #27ae60; background: #e8f8f0; }
.isp-hier-item.dragging-hier   { opacity: .4; }
.isp-hier-left   { display: flex; align-items: center; gap: 8px; flex: 1; }
.isp-hier-grip   { font-size: 16px; color: #bbb; cursor: grab; flex-shrink: 0; padding: 0 4px; }
.isp-hier-grip:active { cursor: grabbing; }
.isp-hier-dot    { width: 10px; height: 10px; border-radius: 50%; background: #2980b9; flex-shrink: 0; }
.isp-hier-dot.green { background: #27ae60; }
.isp-hier-content { flex: 1; }
.isp-hier-title  { font-size: 13px; color: #1a3a5c; font-weight: 600; display: block; }
.isp-hier-name   { font-size: 11px; color: #27ae60; display: block; margin-top: 1px; }
.isp-hier-right  { display: flex; gap: 6px; flex-shrink: 0; }
.isp-hier-children {
    margin-left: 24px;
    border-left: 2px dashed #c8d8e8;
    padding-left: 14px;
    margin-top: 3px;
}

/* ACCORDION */
.isp-accordion { display: flex; flex-direction: column; gap: 8px; }
.isp-acc-item {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,.07);
    border-left: 4px solid #2980b9;
    overflow: hidden;
}
.isp-acc-item.g          { border-left-color: #27ae60; }
.isp-acc-item.green-acc  { border-left-color: #27ae60; }
.isp-acc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 15px;
    cursor: pointer;
    transition: background .2s;
    gap: 10px;
}
.isp-acc-head:hover     { background: #f8fafc; }
.isp-acc-left           { display: flex; align-items: center; gap: 10px; flex: 1; }
.acc-toggle             { font-size: 10px; color: #888; transition: transform .3s; flex-shrink: 0; }
.isp-acc-item.open .acc-toggle { transform: rotate(180deg); }
.acc-icon               { font-size: 17px; flex-shrink: 0; }
.isp-acc-left strong    { display: block; font-size: 13px; color: #1a3a5c; }
.isp-acc-left small     { font-size: 11px; color: #888; display: block; margin-top: 1px; }
.isp-acc-body           { display: none; padding: 0 15px 15px; }
.isp-acc-item.open .isp-acc-body { display: block; animation: isp-fade .2s ease; }

/* LISTS */
.isp-list { list-style: none; padding: 0; }
.isp-list li {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 8px 10px;
    background: #f8fafc;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 13px;
    color: #333;
    line-height: 1.5;
    border-left: 3px solid #2980b9;
}
.daily-list li  { border-left-color: #27ae60; }
.lnum {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 21px; height: 21px;
    background: #2980b9; color: #fff;
    border-radius: 50%;
    font-size: 10px; font-weight: 700;
    flex-shrink: 0; margin-top: 1px;
}
.lnum.g { background: #27ae60; }

/* MODAL */
.isp-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,.65);
    z-index: 999999;
    overflow-y: auto;
    padding: 20px;
}
.isp-modal {
    background: #fff;
    border-radius: 14px;
    max-width: 780px;
    margin: 20px auto;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    animation: isp-fade .3s ease;
}
.isp-modal-sm   { max-width: 500px; }
.isp-modal-hdr {
    background: linear-gradient(135deg, #1a3a5c, #2980b9);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.isp-modal-hdr h3,
.isp-modal-hdr-left h3 { color: #fff; font-size: 16px; }
.isp-modal-hdr-left    { display: flex; align-items: center; gap: 12px; }
.m-icon                { font-size: 24px; }
.isp-modal-hdr p       { color: rgba(255,255,255,.75); font-size: 12px; margin-top: 2px; }
.isp-modal-x {
    background: rgba(255,255,255,.2);
    border: none; color: #fff;
    font-size: 18px; cursor: pointer;
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: background .3s; flex-shrink: 0;
}
.isp-modal-x:hover     { background: rgba(255,255,255,.4); }
.isp-modal-body        { padding: 18px; }
.isp-modal-footer      { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }

/* MODAL TABS */
.isp-modal-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid #e8e8e8;
    margin-bottom: 16px;
    overflow-x: auto;
}
.isp-mtab {
    padding: 8px 15px;
    border: none; background: transparent;
    font-size: 12px; font-weight: 600; color: #888;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer; transition: all .25s;
    white-space: nowrap;
}
.isp-mtab.active           { color: #2980b9; border-bottom-color: #2980b9; }
.isp-mtab-content          { display: none; }
.isp-mtab-content.active   { display: block; animation: isp-fade .2s ease; }

/* FORM */
.isp-form-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.isp-form-group { display: flex; flex-direction: column; gap: 6px; }
.isp-form-group.full { grid-column: 1 / -1; }
.isp-form-group label { font-size: 12px; font-weight: 600; color: #555; }
.isp-inline-edit { display: flex; gap: 8px; }
.isp-input {
    flex: 1;
    padding: 8px 11px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color .3s;
    font-family: inherit;
}
.isp-input:focus  { border-color: #2980b9; }
.isp-select {
    width: 100%;
    padding: 8px 11px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    background: #fff;
    cursor: pointer;
}
.isp-select:focus { border-color: #2980b9; }
.isp-ta {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    resize: vertical;
    min-height: 180px;
    font-family: inherit;
    line-height: 1.7;
    outline: none;
}
.isp-ta:focus { border-color: #2980b9; }
.mt4          { margin-top: 4px; }

/* ICON PICKER */
.isp-icon-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
}
.icon-opt {
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all .2s;
    line-height: 1;
}
.icon-opt:hover  { border-color: #2980b9; background: #e8f4fd; }
.icon-opt.active { border-color: #2980b9; background: #2980b9; }

/* INFO GRID */
.isp-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.isp-info-item {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid #2980b9;
}
.isp-info-item label {
    display: block;
    font-size: 10px; color: #888;
    font-weight: 700; text-transform: uppercase;
    margin-bottom: 4px; letter-spacing: .5px;
}
.isp-info-item span { font-size: 13px; color: #333; font-weight: 500; }

/* CONTENT BAR */
.isp-content-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

/* SEARCH */
.isp-search {
    width: 100%; max-width: 350px;
    padding: 8px 13px;
    border: 2px solid #ddd;
    border-radius: 7px;
    font-size: 13px;
    outline: none;
    transition: border-color .3s;
}
.isp-search:focus { border-color: #2980b9; }

/* BUTTONS */
.isp-btn {
    padding: 7px 14px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 12px; font-weight: 600;
    transition: all .2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
}
.isp-btn:hover        { opacity: .85; transform: translateY(-1px); }
.isp-btn-edit         { background: #2980b9; color: #fff; }
.isp-btn-success      { background: #27ae60; color: #fff; }
.isp-btn-danger       { background: #e74c3c; color: #fff; }
.isp-btn-secondary    { background: #7f8c8d; color: #fff; }
.isp-btn-sm           { padding: 6px 12px; font-size: 11px; }
.isp-btn-xs           { padding: 4px 9px;  font-size: 11px; }

/* TOAST */
.isp-toast {
    position: fixed;
    bottom: 22px; right: 22px;
    background: #2c3e50; color: #fff;
    padding: 11px 20px;
    border-radius: 8px;
    font-size: 13px; font-weight: 500;
    z-index: 9999999;
    opacity: 0;
    transform: translateY(15px);
    transition: all .3s;
    pointer-events: none;
    max-width: 300px;
    box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.isp-toast.show { opacity: 1; transform: translateY(0); }
.isp-toast.ok   { background: #27ae60; }
.isp-toast.err  { background: #e74c3c; }
.isp-toast.info { background: #2980b9; }

/* LOGIN */
.isp-login-msg {
    text-align: center; padding: 30px;
    background: #f8f9fa; border-radius: 10px;
    font-size: 15px; color: #555;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .isp-wrapper       { padding: 10px; }
    .isp-node-box      { min-width: 85px; font-size: 10px; }
    .isp-dept-grid     { grid-template-columns: 1fr; }
    .isp-modal         { margin: 8px auto; }
    .isp-form-grid     { grid-template-columns: 1fr; }
    .isp-info-grid     { grid-template-columns: 1fr; }
}

@media print {
    .isp-tabs, .isp-toolbar, .isp-overlay { display: none !important; }
    .isp-tab-content, .isp-acc-body       { display: block !important; }
}
