/* Arabic RTL Custom Styles for Organizational Chart System */

/* Root Variables for Consistent Theming */
:root {
    --primary-color: #3b82f6;
    --primary-dark: #1d4ed8;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --border-radius: 0.5rem;
    --transition-all: all 0.3s ease-in-out;
}

/* Base RTL Adjustments */
* {
    box-sizing: border-box;
}

html[dir="rtl"] body {
    text-align: right;
    direction: rtl;
    unicode-bidi: bidi-override;
}

/* Typography Enhancements for Arabic */
.arabic-text {
    font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 400;
    line-height: 1.6;
    letter-spacing: 0.01em;
}

.arabic-title {
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
}

/* Organizational Chart Specific Styles */
.org-chart-container {
    position: relative;
    overflow: auto;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
}

.employee-card {
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin: 0.5rem;
    min-width: 200px;
    max-width: 280px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-all);
    cursor: pointer;
    position: relative;
    direction: rtl;
    text-align: right;
}

.employee-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.employee-card.dragging {
    opacity: 0.7;
    transform: rotate(5deg);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
}

.employee-card.drag-over {
    border-color: var(--success-color);
    background-color: #f0f9ff;
}

/* Employee Card Content */
.employee-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.employee-name-en {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 0.5rem;
    direction: ltr;
    text-align: left;
}

.employee-position {
    font-size: 0.875rem;
    color: var(--primary-color);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.employee-department {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    display: inline-block;
}

.employee-id {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    direction: ltr;
}

/* Department Sections */
.department-section {
    margin: 2rem 0;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-primary);
}

.department-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border-color);
}

.department-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.department-count {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: 500;
}

.department-employees {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}

/* Hierarchy Levels */
.hierarchy-level {
    margin-bottom: 3rem;
}

.level-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    border-right: 4px solid var(--primary-color);
}

/* Connection Lines */
.org-connection {
    position: absolute;
    border-right: 2px solid var(--border-color);
    border-bottom: 2px solid var(--border-color);
    z-index: 1;
}

.org-connection::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--primary-color);
    border-radius: 50%;
    bottom: -4px;
    right: -4px;
}

/* Summary Cards for Large Departments */
.department-summary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-all);
    min-width: 240px;
}

.department-summary:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

.summary-count {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.summary-label {
    font-size: 1rem;
    opacity: 0.9;
}

/* Search and Filter Highlights */
.employee-card.search-match {
    border-color: var(--warning-color);
    background: #fefce8;
}

.employee-card.filtered-out {
    opacity: 0.3;
    pointer-events: none;
}

/* Zoom Controls */
.zoom-controls {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    display: flex;
    gap: 0.5rem;
    z-index: 100;
}

.zoom-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-all);
    box-shadow: var(--shadow-sm);
}

.zoom-btn:hover {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-md);
}

/* Loading States */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: var(--border-radius);
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Toast Notifications */
.toast {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem 1.5rem;
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow-lg);
    animation: toast-slide-in 0.3s ease-out;
    max-width: 400px;
    direction: rtl;
    text-align: right;
}

.toast.success {
    border-color: var(--success-color);
    background: #f0fdf4;
    color: #166534;
}

.toast.error {
    border-color: var(--danger-color);
    background: #fef2f2;
    color: #991b1b;
}

.toast.warning {
    border-color: var(--warning-color);
    background: #fffbeb;
    color: #92400e;
}

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Print Styles */
@media print {
    .no-print {
        display: none !important;
    }
    
    .employee-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .department-section {
        break-inside: avoid;
    }
    
    body {
        background: white !important;
    }
}

/* Responsive Design */
@media (max-width: 1024px) {
    .department-employees {
        justify-content: center;
    }
    
    .employee-card {
        max-width: 240px;
    }
}

@media (max-width: 768px) {
    .employee-card {
        min-width: 180px;
        max-width: 200px;
        margin: 0.25rem;
        padding: 0.75rem;
    }
    
    .employee-name {
        font-size: 0.9rem;
    }
    
    .employee-position {
        font-size: 0.8rem;
    }
    
    .department-title {
        font-size: 1.1rem;
    }
    
    .zoom-controls {
        bottom: 1rem;
        left: 1rem;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-secondary: #000000;
    }
    
    .employee-card {
        border-width: 2px;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #f9fafb;
        --text-secondary: #d1d5db;
        --bg-primary: #1f2937;
        --bg-secondary: #111827;
        --border-color: #374151;
    }
    
    .employee-card {
        background: var(--bg-primary);
        color: var(--text-primary);
    }
    
    .department-section {
        background: var(--bg-primary);
    }
}

/* Arabic Number Formatting */
.arabic-numbers {
    direction: ltr;
    unicode-bidi: bidi-override;
}

/* OrgChart.js Arabic RTL Customizations */
.rtl-org-chart {
    direction: rtl;
    text-align: right;
    font-family: 'Noto Sans Arabic', system-ui, -apple-system, sans-serif;
}

/* OrgChart.js Base Overrides */
.rtl-org-chart .orgchart {
    direction: rtl;
    text-align: center;
    overflow: visible;
    position: relative;
    padding: 20px;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    min-height: 500px;
}

.rtl-org-chart .orgchart .node {
    cursor: pointer;
    direction: rtl;
    text-align: right;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    transition: var(--transition-all);
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    min-width: 200px;
    max-width: 280px;
    margin: 10px;
    overflow: hidden;
    position: relative;
}

.rtl-org-chart .orgchart .node:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.rtl-org-chart .orgchart .node.selected,
.rtl-org-chart .orgchart .node.search-highlight {
    border-color: var(--warning-color);
    background-color: #fefce8;
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
}

/* Custom Node Styling */
.org-chart-node {
    padding: 12px;
    direction: rtl;
    text-align: right;
    position: relative;
    border-radius: var(--border-radius);
    background: var(--bg-primary);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.org-chart-node .node-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
    position: relative;
}

.org-chart-node .employee-id {
    background: var(--primary-color);
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
    direction: ltr;
    text-align: left;
    position: absolute;
    top: -2px;
    left: -2px;
}

.org-chart-node .node-toggle {
    width: 16px;
    height: 16px;
    background: var(--bg-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.org-chart-node .node-content {
    flex: 1;
    padding-top: 8px;
}

.org-chart-node .employee-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.3;
    word-wrap: break-word;
}

.org-chart-node .employee-name-en {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 6px;
    direction: ltr;
    text-align: left;
    font-family: system-ui;
}

.org-chart-node .employee-position {
    font-size: 0.875rem;
    color: var(--primary-color);
    font-weight: 500;
    margin-bottom: 6px;
    line-height: 1.2;
}

.org-chart-node .employee-department {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 3px 8px;
    border-radius: 12px;
    display: inline-block;
    max-width: 100%;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

/* Node Type Styling */
.org-chart-node.executive-node {
    border-color: #dc2626;
    background: linear-gradient(135deg, #fef2f2, #ffffff);
}

.org-chart-node.executive-node .employee-name {
    color: #dc2626;
}

.org-chart-node.manager-node {
    border-color: #059669;
    background: linear-gradient(135deg, #f0fdf4, #ffffff);
}

.org-chart-node.manager-node .employee-name {
    color: #059669;
}

.org-chart-node.employee-node {
    border-color: var(--primary-color);
}

.org-chart-node.virtual-root-node {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    text-align: center;
}

.org-chart-node.virtual-root-node .employee-name,
.org-chart-node.virtual-root-node .employee-position,
.org-chart-node.virtual-root-node .employee-department {
    color: white;
}

/* Connection Lines for RTL */
.rtl-org-chart .orgchart .lines {
    stroke: var(--border-color);
    stroke-width: 2px;
    fill: none;
}

.rtl-org-chart .orgchart .lines .topLine,
.rtl-org-chart .orgchart .lines .rightLine,
.rtl-org-chart .orgchart .lines .leftLine,
.rtl-org-chart .orgchart .lines .bottomLine {
    stroke: var(--primary-color);
    stroke-width: 2px;
}

/* RTL Direction Specific Adjustments */
.rtl-org-chart.dir-r2l .orgchart {
    direction: rtl;
}

.rtl-org-chart.dir-l2r .orgchart {
    direction: ltr;
}

.rtl-org-chart.dir-t2b .orgchart {
    writing-mode: horizontal-tb;
}

.rtl-org-chart.dir-b2t .orgchart {
    writing-mode: horizontal-tb;
}

/* Drag and Drop Styling for OrgChart */
.rtl-org-chart .orgchart .node.drag-selected {
    opacity: 0.7;
    transform: scale(1.05);
    z-index: 1000;
    border-color: var(--warning-color);
    box-shadow: 0 8px 25px rgba(245, 158, 11, 0.3);
}

.rtl-org-chart .orgchart .node.drop-zone {
    border-color: var(--success-color);
    background-color: #f0fdf4;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

.rtl-org-chart .orgchart .node.drop-forbidden {
    border-color: var(--danger-color);
    background-color: #fef2f2;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.3);
    cursor: not-allowed;
}

/* Export Button Styling */
.rtl-org-chart .orgchart .exportBtn {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: 'Noto Sans Arabic', sans-serif;
    font-size: 0.875rem;
    z-index: 100;
    transition: var(--transition-all);
}

.rtl-org-chart .orgchart .exportBtn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

/* Pan and Zoom Controls */
.rtl-org-chart .orgchart .control-panel {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 100;
}

.rtl-org-chart .orgchart .control-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-all);
}

.rtl-org-chart .orgchart .control-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.1);
}

/* Expand/Collapse Icons */
.rtl-org-chart .orgchart .node .toggleBtn {
    position: absolute;
    bottom: -10px;
    right: 50%;
    transform: translateX(50%);
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    color: white;
    border: 2px solid var(--bg-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    z-index: 10;
}

.rtl-org-chart .orgchart .node .toggleBtn:hover {
    background: var(--primary-dark);
    transform: translateX(50%) scale(1.1);
}

/* Loading and Animation States */
.rtl-org-chart.loading {
    position: relative;
}

.rtl-org-chart.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1000;
    transform: translate(-50%, -50%);
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Node Animation Entrance */
.rtl-org-chart .orgchart .node {
    animation: nodeAppear 0.5s ease-out;
}

@keyframes nodeAppear {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Search Results Highlighting */
.rtl-org-chart .orgchart .node.search-highlight {
    animation: searchPulse 2s infinite;
}

@keyframes searchPulse {
    0%, 100% {
        box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
    }
    50% {
        box-shadow: 0 0 25px rgba(245, 158, 11, 0.6);
    }
}

/* Responsive Design for OrgChart */
@media (max-width: 1024px) {
    .org-chart-node {
        min-width: 160px;
        max-width: 200px;
        padding: 10px;
    }
    
    .org-chart-node .employee-name {
        font-size: 0.9rem;
    }
    
    .org-chart-node .employee-position {
        font-size: 0.8rem;
    }
}

@media (max-width: 768px) {
    .rtl-org-chart .orgchart {
        padding: 10px;
    }
    
    .org-chart-node {
        min-width: 140px;
        max-width: 180px;
        margin: 5px;
    }
    
    .org-chart-node .employee-name {
        font-size: 0.85rem;
        line-height: 1.2;
    }
    
    .org-chart-node .employee-position {
        font-size: 0.75rem;
    }
    
    .org-chart-node .employee-department {
        font-size: 0.7rem;
    }
    
    .rtl-org-chart .orgchart .exportBtn {
        font-size: 0.75rem;
        padding: 6px 10px;
    }
}

/* Print Styles for OrgChart */
@media print {
    .rtl-org-chart .orgchart {
        background: white !important;
        padding: 0;
    }
    
    .org-chart-node {
        border: 2px solid #000 !important;
        background: white !important;
        box-shadow: none !important;
        color: black !important;
        break-inside: avoid;
    }
    
    .org-chart-node * {
        color: black !important;
    }
    
    .rtl-org-chart .orgchart .exportBtn,
    .rtl-org-chart .orgchart .control-panel {
        display: none !important;
    }
    
    .rtl-org-chart .orgchart .lines {
        stroke: #000 !important;
    }
}

/* Accessibility Improvements */
.org-chart-node:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

.org-chart-node[aria-selected="true"] {
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

/* High Contrast Mode for OrgChart */
@media (prefers-contrast: high) {
    .rtl-org-chart .orgchart .node {
        border-width: 3px;
        border-color: #000;
    }
    
    .rtl-org-chart .orgchart .lines {
        stroke: #000;
        stroke-width: 3px;
    }
    
    .org-chart-node .employee-name {
        font-weight: 700;
    }
}

/* Dark Mode Support for OrgChart */
@media (prefers-color-scheme: dark) {
    .rtl-org-chart .orgchart {
        background-color: var(--bg-secondary);
    }
    
    .org-chart-node {
        background: var(--bg-primary);
        border-color: var(--border-color);
        color: var(--text-primary);
    }
    
    .org-chart-node .employee-name,
    .org-chart-node .employee-position,
    .org-chart-node .employee-department {
        color: var(--text-primary);
    }
    
    .org-chart-node .employee-name-en {
        color: var(--text-secondary);
    }
}

/* Custom Scrollbar for Chart Viewport */
#chart-viewport::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#chart-viewport::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

#chart-viewport::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

#chart-viewport::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}