/* ==========================================================================
   1. GLOBAL STYLES & DOT GRID CANVAS
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: #080c14;
    color: #f3f4f6;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    padding: 0;
    height: 100vh;
}

.app-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==========================================================================
   2. APP HEADER & TOOLBAR (GLASSMORPHISM)
   ========================================================================== */
.app-header {
    width: 100%;
    background: rgba(13, 20, 35, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 16px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo {
    font-size: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 3s infinite ease-in-out;
}

.brand h1 {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: #ffffff;
    margin: 0;
}

.brand .hint {
    font-size: 0.72rem;
    color: #9ca3af;
    margin-top: 2px;
}

/* Controls inside header */
.controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.global-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: #e5e7eb;
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.global-btn svg {
    opacity: 0.8;
}

.global-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
    color: #ffffff;
    transform: translateY(-1px);
}

.global-btn:active {
    transform: translateY(0);
}

.btn-reset {
    border-color: rgba(239, 68, 68, 0.2);
}

.btn-reset:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
}

.btn-add-dept {
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
    border: none;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25);
    color: #ffffff;
}

.btn-add-dept:hover {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4);
}

.btn-export {
    border-color: rgba(59, 130, 246, 0.3);
}

.btn-export:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.4);
    color: #60a5fa;
}

.btn-import {
    border-color: rgba(16, 185, 129, 0.3);
}

.btn-import:hover {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.4);
    color: #34d399;
}

.btn-divider {
    width: 1px;
    height: 18px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 6px;
}

/* ==========================================================================
   3. EDITABLE TEXT OVERRIDES (PREMIUM INLINE INPUTS)
   ========================================================================== */
[contenteditable="true"] {
    outline: none;
    border-bottom: 1px dashed transparent;
    transition: all 0.2s ease;
    min-height: 1.2em;
    min-width: 50px;
    display: block;
}

[contenteditable="true"]:hover {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 4px;
    cursor: text;
}

[contenteditable="true"]:focus {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    border-bottom-color: #6366f1;
}

/* ==========================================================================
   4. ORGANIGRAM LAYOUT & NODES (DEPARTMENTS)
   ========================================================================== */
.chart-container {
    display: flex;
    justify-content: safe center;
    align-items: flex-start;
    flex-wrap: nowrap;
    gap: 64px;
    padding: 60px 40px;
    width: 100%;
    flex-grow: 1;
    box-sizing: border-box;
    overflow: auto;
    background-color: #080c14;
    background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 24px 24px;
}

/* Target feedback when dragging department over empty canvas */
.chart-container.container-hover {
    background: rgba(16, 185, 129, 0.03);
    outline: 2px dashed rgba(16, 185, 129, 0.2);
    outline-offset: -12px;
}

.empty-hint {
    color: #4b5563;
    font-size: 0.95rem;
    padding: 60px;
    font-style: italic;
    width: 100%;
    text-align: center;
}

.org-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.org-department {
    position: relative;
    background: rgba(17, 24, 39, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 24px 20px 20px 20px;
    min-width: 280px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 1px 1px rgba(255, 255, 255, 0.05);
    z-index: 2;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: grab;
}

.org-department:active {
    cursor: grabbing;
}

.org-department:hover {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), inset 0 1px 1px rgba(255, 255, 255, 0.08);
}

.department-title {
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 1px;
    color: #9ca3af;
    margin-bottom: 20px;
    text-transform: uppercase;
    text-align: center;
}

.delete-dept-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: #4b5563;
    font-size: 1.1rem;
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.delete-dept-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

/* Drag-Hover feedbacks for departments */
.dept-dragging {
    opacity: 0.15;
    border: 1px dashed #6366f1 !important;
}

.dept-hover {
    border-color: #10b981 !important;
    background: rgba(16, 185, 129, 0.06) !important;
    box-shadow: 0 0 25px rgba(16, 185, 129, 0.18) !important;
    transform: scale(1.015);
}

/* ==========================================================================
   5. PERSON CARDS (PREMIUM DARK CARDS & ACCENTS)
   ========================================================================== */
.org-card {
    position: relative;
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 14px 16px;
    width: 240px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: grab;
}

.org-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.org-card:active {
    cursor: grabbing;
}

.org-card.dragging {
    opacity: 0.35;
    transform: scale(0.97);
}

/* Avatar Initials Badge */
.card-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: #ffffff;
    flex-shrink: 0;
}

.card-info {
    flex-grow: 1;
    text-align: left;
    overflow: hidden;
}

.org-name {
    font-size: 0.72rem;
    font-weight: 500;
    color: #9ca3af;
    margin-bottom: 0;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.org-role {
    font-size: 0.85rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Delete Button on Card */
.delete-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: none;
    border: none;
    color: #4b5563;
    font-size: 1rem;
    cursor: pointer;
    opacity: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.org-card:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ==========================================================================
   6. ROLE GROUPS & GRADIANT ACCENTS
   ========================================================================== */
.department-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    width: 100%;
    margin-bottom: 12px;
}

.role-group {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
}

.staff-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.heads-row {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 24px;
    width: 100%;
    padding-bottom: 4px;
}

.head-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.assistants-row {
    padding-top: 14px;
    border-top: 1px dashed rgba(255, 255, 255, 0.08);
}

.team-row {
    border-top: 1px dashed rgba(255, 255, 255, 0.08);
    padding-top: 14px;
}

/* Card Role Coloring via Gradient Accents */
.org-card.type-head {
    border-top: 3px solid #f43f5e;
    background: linear-gradient(to bottom, rgba(244, 63, 94, 0.03), transparent) #111827;
}

.org-card.type-head .card-avatar {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
}

.org-card.type-assistant {
    width: 210px;
    border-top: 3px solid #fbbf24;
    background: linear-gradient(to bottom, rgba(251, 191, 36, 0.03), transparent) #111827;
    padding: 10px 12px;
}

.org-card.type-assistant .card-avatar {
    background: linear-gradient(135deg, #fbbf24, #d97706);
}

.org-card.type-member {
    border-top: 3px solid #3b82f6;
    background: linear-gradient(to bottom, rgba(59, 130, 246, 0.03), transparent) #111827;
}

.org-card.type-member .card-avatar {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

/* Visual Feedback: Head highlight when dropping assistant */
.org-card.type-head.assign-hover {
    box-shadow: 0 0 0 3px #fbbf24, 0 8px 24px rgba(251, 191, 36, 0.2);
    transform: translateY(-2px);
}

/* ==========================================================================
   7. DEPARTMENT CONTROLS & ADD BUTTONS
   ========================================================================== */
.dept-controls {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 16px;
}

.dept-controls .add-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: #9ca3af;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.dept-controls .add-btn svg {
    opacity: 0.7;
}

.dept-controls .add-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    transform: translateY(-1px);
}

.dept-controls .add-btn:active {
    transform: translateY(0);
}

.dept-controls .add-btn.btn-head-add:hover {
    border-color: rgba(244, 63, 94, 0.3);
    background: rgba(244, 63, 94, 0.04);
    color: #f43f5e;
}

.dept-controls .add-btn.btn-asst-add:hover {
    border-color: rgba(251, 191, 36, 0.3);
    background: rgba(251, 191, 36, 0.04);
    color: #fbbf24;
}

.dept-controls .add-btn.btn-member-add:hover {
    border-color: rgba(59, 130, 246, 0.3);
    background: rgba(59, 130, 246, 0.04);
    color: #3b82f6;
}

.dept-controls .add-btn.sub-dept-btn:hover {
    border-color: rgba(168, 85, 247, 0.3);
    background: rgba(168, 85, 247, 0.04);
    color: #c084fc;
}

/* ==========================================================================
   8. SVG CONNECTION LINES (GLOWING INTERACTIVE PATHS)
   ========================================================================== */
.connector-svg {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    pointer-events: none;
}

.connector-path {
    fill: none;
    stroke: rgba(148, 163, 184, 0.5);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.2s ease, stroke-width 0.2s ease;
}

/* Glowing Neon highlight on hover */
.connector-group:hover .connector-path {
    stroke: #f43f5e;
    stroke-width: 4;
    filter: drop-shadow(0 0 4px rgba(244, 63, 94, 0.4));
}

.connector-path-interactive {
    fill: none;
    stroke: transparent;
    stroke-width: 15;
    cursor: pointer;
    pointer-events: stroke;
}

.sub-departments {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 48px;
    position: relative;
    padding-top: 36px;
}

/* ==========================================================================
   9. INTERACTION MODALS (GLASMORPHISM & PREMIUM STYLING)
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(8, 12, 20, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.25s ease-out;
}

.modal-box {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 32px;
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 440px;
    text-align: center;
    border-top: 4px solid #8b5cf6;
    animation: scaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-box h3 {
    margin-bottom: 14px;
    color: #ffffff;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.3px;
}

.modal-box p {
    color: #9ca3af;
    font-size: 0.92rem;
    line-height: 1.6;
    margin-bottom: 24px;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-btn {
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-move {
    background-color: #3b82f6;
    color: white;
}

.btn-move:hover {
    background-color: #2563eb;
    transform: translateY(-1px);
}

.btn-link {
    background-color: #10b981;
    color: white;
}

.btn-link:hover {
    background-color: #059669;
    transform: translateY(-1px);
}

.btn-delete-all {
    background-color: #ef4444;
    color: white;
}

.btn-delete-all:hover {
    background-color: #dc2626;
    transform: translateY(-1px);
}

.btn-cancel {
    background-color: rgba(255, 255, 255, 0.05);
    color: #9ca3af;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-cancel:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* ==========================================================================
   10. ANIMATIONS
   ========================================================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        filter: drop-shadow(0 0 2px rgba(99, 102, 241, 0.3));
    }
    50% {
        transform: scale(1.05);
        filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.6));
    }
}

/* ==========================================================================
   11. ZOOMING & ZOOM WORKSPACE
   ========================================================================== */
.chart-zoom-container {
    display: flex;
    justify-content: safe center;
    align-items: flex-start;
    flex-wrap: nowrap;
    gap: 64px;
    transform-origin: center top;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 2px 4px;
}

.zoom-level-text {
    font-size: 0.78rem;
    font-weight: 700;
    color: #9ca3af;
    min-width: 46px;
    text-align: center;
    user-select: none;
    font-variant-numeric: tabular-nums;
}

.btn-zoom {
    background: none !important;
    border: none !important;
    padding: 6px !important;
    height: 28px !important;
    width: 28px !important;
    min-width: unset !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px !important;
    transition: all 0.15s ease !important;
}

.btn-zoom:hover {
    background: rgba(255, 255, 255, 0.06) !important;
    color: #ffffff !important;
}

/* ==========================================================================
   12. DRAG AND DROP REORDERING ACCENTS
   ========================================================================== */
.org-department.dept-hover-left {
    box-shadow: -4px 0 0 #10b981, 0 10px 30px -10px rgba(0, 0, 0, 0.5) !important;
    border-left-color: #10b981 !important;
}

.org-department.dept-hover-right {
    box-shadow: 4px 0 0 #10b981, 0 10px 30px -10px rgba(0, 0, 0, 0.5) !important;
    border-right-color: #10b981 !important;
}

.org-card.card-hover-left {
    box-shadow: -4px 0 0 #6366f1, 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

.org-card.card-hover-right {
    box-shadow: 4px 0 0 #6366f1, 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

.department-cards.cards-hover {
    background: rgba(99, 102, 241, 0.02);
    outline: 1px dashed rgba(99, 102, 241, 0.2);
    border-radius: 8px;
}

/* ==========================================================================
   13. COLLAPSE / EXPAND TOGGLE BUTTON
   ========================================================================== */
.collapse-toggle {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #9ca3af;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    padding: 0;
}

.collapse-toggle:hover {
    background: #1f2937;
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateX(-50%) scale(1.15);
}

.collapse-toggle svg {
    transition: transform 0.2s ease;
}

.collapse-toggle.is-collapsed svg {
    transform: rotate(180deg);
}

/* Glow indicator when collapsed to show hidden children exist */
.org-department.is-collapsed {
    border-bottom: 2.5px solid #10b981;
}

.collapse-toggle.is-collapsed {
    background: #10b981;
    color: #080c14;
    border-color: #10b981;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.collapse-toggle.is-collapsed:hover {
    background: #059669;
    color: #ffffff;
    border-color: #059669;
}

.btn-toggle-collapse:hover {
    border-color: rgba(99, 102, 241, 0.3);
    background: rgba(99, 102, 241, 0.04);
    color: #818cf8;
}