/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* x-cloak: hide until Alpine initializes */
[x-cloak] { display: none !important; }

:root {
    --app-font: Tahoma, Arial, sans-serif;
    --app-font-weight: bold;
}

/* Base */
body {
    font-family: var(--app-font);
    font-weight: var(--app-font-weight);
    background: #f0f2f5;
    color: #1a1a2e;
    direction: rtl;
}

/* â”€â”€â”€ Toolbar â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.toolbar {
    height: 64px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a2e;
    white-space: nowrap;
}

.toolbar-input {
    height: 36px;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 0 12px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    background: #fff;
    color: #1a1a2e;
    transition: border-color 0.15s;
}

.toolbar-input:focus {
    border-color: #4a90d9;
}

/* â”€â”€â”€ Tree container â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

#tree {
    width: 100%;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    overflow: hidden;
    background: #ffffff;
    position: relative;
}

/* â”€â”€â”€ Modal overlay â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 32px;
    min-width: 380px;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.modal-card h2 {
    font-size: 18px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 4px;
}

.modal-card h4 {
    font-size: 14px;
    font-weight: 600;
    color: #555;
    margin-top: 4px;
}

.modal-card label {
    font-size: 13px;
    font-weight: 600;
    color: #444;
    margin-bottom: -6px;
}

.modal-card p {
    font-size: 14px;
    color: #555;
}

/* â”€â”€â”€ Form elements inside modal â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.modal-card input,
.modal-card select,
.modal-card textarea {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    color: #1a1a2e;
    outline: none;
    transition: border-color 0.15s;
    background: #fff;
}

.modal-card input:focus,
.modal-card select:focus,
.modal-card textarea:focus {
    border-color: #4a90d9;
}

.modal-card textarea {
    resize: vertical;
    line-height: 1.5;
}

/* â”€â”€â”€ Modal actions â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* â”€â”€â”€ Buttons â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

button {
    cursor: pointer;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #4a90d9;
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: #357abd;
}

.btn-secondary {
    background: #f0f0f0;
    color: #333333;
}

.btn-secondary:hover:not(:disabled) {
    background: #e0e0e0;
}

.btn-danger {
    background: #e74c3c;
    color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
    background: #c0392b;
}

/* â”€â”€â”€ Person photo â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.person-photo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    margin: 0 auto 8px;
    border: 2px solid #e0e0e0;
}

/* â”€â”€â”€ Ancestors list â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.ancestors-list {
    padding-right: 20px;
    margin-top: 4px;
}

.ancestors-list li {
    padding: 4px 0;
    font-size: 14px;
    color: #333;
}

/* â”€â”€â”€ Error banner â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.error-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #e74c3c;
    color: #ffffff;
    padding: 12px 24px;
    z-index: 2000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
}

.error-banner:hover {
    background: #c0392b;
}

/* â”€â”€â”€ Loading overlay â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 1500;
    font-size: 18px;
    color: #4a90d9;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #4a90d9;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* OrgChart.js Arabic text fix */
.orgchart-container text {
    font-family: var(--app-font) !important;
}

.orgchart-container foreignObject div {
    font-family: var(--app-font) !important;
    direction: rtl !important;
    unicode-bidi: embed !important;
    text-align: center !important;
}

/* Force selected font on SVG text elements */
text[style] {
    font-family: var(--app-font) !important;
}

/* â”€â”€â”€ Make OrgChart nodes look clickable â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

#tree svg text {
    cursor: pointer !important;
}

/* Target only large node circles by radius â€” skip expand/collapse button */
#tree svg circle[r="30"],
#tree svg circle[r="35"],
#tree svg circle[r="40"],
#tree svg circle[r="45"],
#tree svg circle[r="50"] {
    cursor: pointer !important;
    transition: filter 0.2s ease !important;
}

#tree svg circle[r="30"]:hover,
#tree svg circle[r="35"]:hover,
#tree svg circle[r="40"]:hover,
#tree svg circle[r="45"]:hover,
#tree svg circle[r="50"]:hover {
    filter: brightness(1.2)
            drop-shadow(0 3px 8px rgba(74,144,217,0.5)) !important;
}

/* Explicitly reset collapse/expand button styles */
#tree svg g[cursor="pointer"] circle {
    cursor: pointer !important;
    transition: none !important;
    filter: none !important;
    animation: none !important;
}

#tree svg g[cursor="pointer"] circle:hover {
    filter: none !important;
    transform: none !important;
}

#tree svg circle:first-of-type {
    animation: none !important;
}

/* Search result highlight color */
/* Applied via JS in ui.js highlightMatchingNodes() */
/* Orange = direct search match, Blue = ancestor or descendant context */

/* â”€â”€â”€ Success toast â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */

.success-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    background: #27ae60;
    color: white;
    padding: 14px 32px;
    border-radius: 30px;
    font-size: 15px;
    font-family: Tahoma, Arial, sans-serif;
    z-index: 3000;
    box-shadow: 0 4px 20px rgba(39, 174, 96, 0.4);
    white-space: nowrap;
}

/* --- Tree control buttons (expand/collapse all) --- */

.btn-tree-control {
    background: #eaf2fb;
    color: #2471a3;
    border: 1px solid #aed6f1;
    font-size: 13px;
    padding: 7px 14px;
}

.btn-tree-control:hover:not(:disabled) {
    background: #d6eaf8;
    border-color: #5dade2;
}

/* --- Settings Sidebar --- */

#settings-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100vh;
    background: white;
    z-index: 2001;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    font-family: Tahoma, Arial, sans-serif;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
}

.settings-header h3 {
    margin: 0;
    font-size: 16px;
    color: #1a1a2e;
}

.settings-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #666;
    padding: 4px 8px;
    border-radius: 4px;
}

.settings-close:hover {
    background: #eee;
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-demo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: #f0f4f8;
    border-radius: 12px;
}

.settings-demo-label {
    font-size: 12px;
    color: #666;
    font-weight: bold;
}

.settings-demo-shape {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 120px;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-label {
    font-size: 13px;
    color: #333;
    font-weight: bold;
}

.settings-shapes {
    display: flex;
    gap: 8px;
}

.shape-btn {
    flex: 1;
    padding: 8px 4px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 12px;
    font-family: Tahoma, Arial, sans-serif;
    color: #333;
    transition: all 0.2s;
}

.shape-btn:hover {
    border-color: #4a90d9;
    color: #4a90d9;
}

.shape-btn.active {
    border-color: #4a90d9;
    background: #e8f0fb;
    color: #4a90d9;
    font-weight: bold;
}

.settings-slider {
    width: 100%;
    accent-color: #4a90d9;
    cursor: pointer;
}

.settings-color {
    width: 100%;
    height: 40px;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    padding: 2px;
}

.settings-footer {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* --- Level Ruler --- */

#level-ruler {
    position: fixed;
    left: 0;
    top: 64px;
    bottom: 0;
    width: 52px;
    z-index: 50;
    pointer-events: none;
    display: none;
}

#ruler-bar {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #b0bec5;
}

#ruler-labels {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.ruler-level {
    position: absolute;
    left: 4px;
    width: 38px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-family: Tahoma, Arial, sans-serif;
    color: #ffffff;
    font-weight: bold;
    background: #4a90d9;
    border: 2px solid #2471a3;
    border-radius: 5px;
    pointer-events: none;
    transform: translateY(-50%);
    box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}

/* --- Mobile menu: hidden on desktop by default --- */
.btn-mobile-menu {
    display: none;
}

.mobile-menu-dropdown {
    display: none;
}

/* --- Mobile responsive rules --- */
@media (max-width: 768px) {

    /* Toolbar — stack into two rows on mobile */
    .toolbar {
        height: auto !important;
        min-height: 56px !important;
        flex-wrap: wrap !important;
        padding: 8px 12px !important;
        gap: 8px !important;
        align-items: center !important;
    }

    .toolbar-left,
    .toolbar-right {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    /* Hide less important toolbar items on mobile */
    /* Keep: title, search, add, print */
    /* Hide: expand all, collapse all, A4 toggle */
    .btn-tree-control {
        display: none !important;
    }

    /* Make search inputs shorter on mobile */
    .toolbar-input {
        width: 100px !important;
        min-width: unset !important;
        font-size: 13px !important;
        height: 32px !important;
    }

    /* Smaller buttons on mobile */
    button {
        padding: 7px 12px !important;
        font-size: 13px !important;
    }

    /* App title smaller on mobile */
    .app-title {
        font-size: 14px !important;
    }

    /* Tree fills remaining height after toolbar */
    #tree {
        height: calc(100dvh - 110px) !important;
        width: 100% !important;
        position: relative !important;
    }

    /* Modal full width on mobile */
    .modal-card {
        min-width: unset !important;
        width: calc(100vw - 32px) !important;
        max-width: 100% !important;
        padding: 20px 16px !important;
        margin: 16px !important;
        max-height: 85vh !important;
    }

    /* Settings sidebar full width on mobile */
    #settings-sidebar {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Hide ruler on mobile — not enough space */
    #level-ruler {
        display: none !important;
    }

    /* Success toast full width on mobile */
    .success-toast {
        left: 16px !important;
        right: 16px !important;
        transform: none !important;
        text-align: center !important;
        white-space: normal !important;
        bottom: 16px !important;
    }

    /* Error banner smaller text on mobile */
    .error-banner {
        font-size: 13px !important;
        padding: 10px 16px !important;
    }

    /* Mobile menu button — only visible on mobile */
    .btn-mobile-menu {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 32px;
        padding: 0 !important;
        font-size: 20px !important;
        background: #f0f4f8 !important;
        border: 1px solid #d0e0f0 !important;
        border-radius: 6px !important;
        color: #4a90d9 !important;
    }

    .mobile-menu-dropdown {
        position: fixed;
        top: auto;
        left: 12px;
        background: white;
        border: 1px solid #ddd;
        border-radius: 8px;
        box-shadow: 0 4px 16px rgba(0,0,0,0.15);
        z-index: 500;
        display: flex;
        flex-direction: column;
        min-width: 160px;
        overflow: hidden;
    }

    .mobile-menu-item {
        padding: 12px 16px !important;
        text-align: right !important;
        border-bottom: 1px solid #f0f0f0 !important;
        background: white !important;
        color: #333 !important;
        font-size: 14px !important;
        border-radius: 0 !important;
    }

    .mobile-menu-item:last-child {
        border-bottom: none !important;
    }

    .mobile-menu-item:hover {
        background: #f0f4f8 !important;
    }
}

/* --- Toggle Switch --- */

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #ccc;
    border-radius: 24px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #4a90d9;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* --- Re-focus floating button --- */

#refocus-btn {
    position: fixed;
    bottom: 32px;
    left: 32px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #4a90d9;
    color: white;
    border: none;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.4);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    padding: 0;
}

#refocus-btn:hover {
    background: #357abd;
    transform: scale(1.1);
}

#refocus-btn:active {
    transform: scale(0.95);
}

@media print {
    #refocus-btn {
        display: none !important;
    }
}

/* --- Detail Drawer --- */

.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    justify-content: flex-end;
}

.detail-drawer {
    position: relative;
    width: 360px;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    overflow: visible;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
    flex-shrink: 0;
}

.drawer-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #1a1a2e;
}

.drawer-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #666;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}

.drawer-close:hover {
    background: #eee;
    color: #333;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.drawer-details {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.drawer-detail-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 14px;
    color: #333;
    line-height: 1.5;
}

.drawer-detail-label {
    font-weight: 600;
    color: #555;
    white-space: nowrap;
    flex-shrink: 0;
}

.drawer-ancestors {
    border-top: 1px solid #eee;
    padding-top: 16px;
}

.drawer-ancestors h4 {
    font-size: 13px;
    font-weight: 700;
    color: #555;
    margin: 0 0 8px 0;
}

.drawer-footer {
    padding: 16px 24px;
    border-top: 1px solid #eee;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
    background: #fafafa;
}

.drawer-footer button {
    flex: 1;
    min-width: 80px;
    padding: 8px 12px;
    font-size: 13px;
}

@media (max-width: 768px) {
    .detail-drawer {
        width: 100% !important;
    }
}

@media print {
    .drawer-overlay {
        display: none !important;
    }
}

/* --- Field validation errors --- */

.field-error {
    color: #e74c3c;
    font-size: 12px;
    margin: -4px 0 0 0;
    padding: 0;
    font-family: Tahoma, Arial, sans-serif;
}

.settings-select {
    width: 100%;
    height: 40px;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 0 12px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    background: white;
    color: #333;
    outline: none;
}

.settings-select:focus {
    border-color: #4a90d9;
}

/* --- Hamburger menu button --- */

.btn-menu-toggle {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #f0f4f8;
    border: 1px solid #d0e0f0;
    color: #4a90d9;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-menu-toggle:hover {
    background: #dceeff;
}

/* --- Main menu drawer --- */

.main-menu-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: white;
    z-index: 1501;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    font-family: inherit;
}

.menu-user-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 20px 20px;
    background: #f8f9fa;
}

.menu-user-icon {
    font-size: 32px;
}

.menu-username {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a2e;
}

.menu-role {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
}

.menu-divider {
    height: 1px;
    background: #eee;
    margin: 4px 0;
}

.menu-items {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px 0;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    background: none;
    border: none;
    border-radius: 0;
    font-size: 15px;
    font-family: inherit;
    color: #1a1a2e;
    cursor: pointer;
    text-align: right;
    width: 100%;
    transition: background 0.15s;
}

.menu-item:hover {
    background: #f0f4f8;
}

.menu-item-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.menu-item-logout {
    color: #e74c3c;
    margin-top: auto;
    padding: 16px 20px;
}

.menu-item-logout:hover {
    background: #fdecea;
}

/* --- Print modal options --- */

.print-option-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.print-radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    padding: 8px 12px;
    border: 1px solid #eee;
    border-radius: 8px;
    transition: border-color 0.2s, background 0.2s;
}

.print-radio-label:hover {
    border-color: #4a90d9;
    background: #f0f7ff;
}

.print-radio-label input {
    width: 16px;
    height: 16px;
    accent-color: #4a90d9;
    cursor: pointer;
}

/* --- Result badge --- */

.result-badge {
    background: #4a90d9;
    color: white;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 12px;
    white-space: nowrap;
}

/* --- AI Button --- */

.btn-ai-toggle {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: opacity 0.2s, transform 0.15s;
    flex-shrink: 0;
}

.btn-ai-toggle:hover {
    opacity: 0.85;
    transform: scale(1.05);
}

/* --- AI Drawer --- */

.ai-drawer {
    width: 380px;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.ai-instruction {
    font-size: 13px;
    color: #666;
    text-align: center;
    margin: 0;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 8px;
}

.ai-node-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid #eee;
    border-radius: 10px;
    background: #fafafa;
}

.ai-node-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #444;
    flex-wrap: wrap;
}

.ai-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ai-dot-1 { background: #8b5cf6; }
.ai-dot-2 { background: #f59e0b; }

.ai-slot-btn {
    font-size: 11px;
    padding: 3px 8px;
    border: 1px dashed #aaa;
    border-radius: 4px;
    background: white;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.ai-slot-btn.active,
.ai-slot-btn:hover {
    border-color: #8b5cf6;
    color: #8b5cf6;
    background: #f5f0ff;
}

.ai-selected-node {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
}

.ai-selected-node-1 {
    background: #f5f0ff;
    color: #8b5cf6;
    border: 1px solid #ddd6fe;
}

.ai-selected-node-2 {
    background: #fffbeb;
    color: #d97706;
    border: 1px solid #fde68a;
}

.ai-clear-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    color: #999;
    padding: 0 4px;
}

.ai-clear-btn:hover { color: #e74c3c; }

.ai-search-wrap { position: relative; }

.ai-search-input {
    width: 100%;
    height: 36px;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 0 12px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}

.ai-search-input:focus { border-color: #8b5cf6; }

.ai-search-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
}

.ai-search-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.15s;
}

.ai-search-item:hover { background: #f5f0ff; }

.ai-features {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-features-label {
    font-size: 12px;
    color: #888;
    margin: 0;
    text-align: center;
}

.ai-feature-btn {
    padding: 12px 16px;
    background: white;
    border: 1px solid #e0d4ff;
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    color: #5b21b6;
    cursor: pointer;
    text-align: right;
    transition: all 0.2s;
}

.ai-feature-btn:hover:not(:disabled) {
    background: #f5f0ff;
    border-color: #8b5cf6;
}

.ai-feature-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    color: #8b5cf6;
    font-size: 14px;
}

.ai-error {
    background: #fdecea;
    color: #e74c3c;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

.ai-response {
    background: linear-gradient(135deg, #f5f0ff, #faf5ff);
    border: 1px solid #ddd6fe;
    border-radius: 12px;
    overflow: hidden;
    scroll-margin-top: 16px;
}

.ai-response-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(139, 92, 246, 0.1);
    font-size: 13px;
    font-weight: 600;
    color: #5b21b6;
}

.ai-copy-btn {
    background: none;
    border: 1px solid #8b5cf6;
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 11px;
    color: #8b5cf6;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.ai-copy-btn:hover {
    background: #8b5cf6;
    color: white;
}

.ai-response-text {
    padding: 14px;
    font-size: 14px;
    line-height: 1.8;
    color: #2d1b69;
    white-space: pre-wrap;
}

.ai-panel-container {
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    width: 380px;
    z-index: 1200;
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

.ai-panel-container > .detail-drawer {
    pointer-events: all;
    height: 100%;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
}

.ai-panel-container .drawer-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.ai-panel-container .detail-drawer {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

@media (max-width: 768px) {
    .ai-drawer { width: 100% !important; }
    .ai-panel-container { width: 100%; }
}

.ai-response-modal {
    max-width: 560px;
    min-width: 340px;
    width: 90vw;
    max-height: 80vh;
    gap: 16px;
}

.ai-response-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 15px;
    font-weight: 700;
    color: #5b21b6;
    padding-bottom: 12px;
    border-bottom: 1px solid #ede9fe;
}

.ai-response-context {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-context-tag {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.ai-context-1 {
    background: #f5f0ff;
    color: #8b5cf6;
    border: 1px solid #ddd6fe;
}

.ai-context-2 {
    background: #fffbeb;
    color: #d97706;
    border: 1px solid #fde68a;
}

.ai-response-text-modal {
    font-size: 15px;
    line-height: 1.9;
    color: #1a1a2e;
    white-space: pre-wrap;
    overflow-y: auto;
    max-height: 50vh;
    padding: 4px 0;
}

/* --- Storage mode badge --- */

.storage-mode-badge {
    display: inline-block;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
    font-weight: normal;
}

.badge-cookies {
    background: #e0f0ff;
    color: #2471a3;
}

.badge-db {
    background: #e8f8ee;
    color: #1e8449;
}

/* --- Save to DB button --- */

.btn-save-db {
    background: #1e8449;
    color: white;
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-save-db:hover:not(:disabled) {
    background: #196f3d;
}

.btn-save-db:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Settings divider --- */

.settings-divider {
    height: 1px;
    background: #eee;
    margin: 8px 0;
}

/* --- Storage toggle row --- */

.storage-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #eee;
}

.storage-toggle-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
    color: #333;
    font-weight: 600;
}

.storage-toggle-desc {
    font-size: 11px;
    color: #888;
    font-weight: normal;
}

/* App Footer */
.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 32px;
    background: rgba(255,255,255,0.92);
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #666;
    z-index: 50;
    backdrop-filter: blur(4px);
    pointer-events: none;
}

/* Adjust tree height when footer visible */
@media screen {
    body:has(.app-footer) #tree {
        height: calc(100vh - 64px - 32px);
        height: calc(100dvh - 64px - 32px);
    }
}

/* --- Zoom stepper floating --- */

.zoom-stepper-float {
    position: fixed;
    bottom: 40px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 200;
}

.zoom-btn-float {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    border: 1px solid #d0e0f0;
    color: #4a90d9;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    transition: background 0.15s, transform 0.1s;
    line-height: 1;
}

.zoom-btn-float:hover {
    background: #f0f7ff;
    transform: scale(1.1);
}

.zoom-reset-float {
    font-size: 14px;
    color: #888;
}

body:has(.app-footer) .zoom-stepper-float {
    bottom: 48px;
}

@media print {
    .zoom-stepper-float {
        display: none !important;
    }
}

/* Footer in print */
@media print {
    .app-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        text-align: center;
        font-size: 11px;
        color: #333;
        border-top: 1px solid #ccc;
        padding: 4px 0;
        background: white;
        pointer-events: none;
    }
}

/* ── Company Branding — Micro Badge ── */
.company-footer {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 900;
    user-select: none;
    pointer-events: all;
    direction: ltr;
}

.company-footer a {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(74, 114, 153, 0.25);
    border-radius: 20px;
    padding: 4px 10px 4px 6px;
    backdrop-filter: blur(6px);
    opacity: 0.72;
    transition: opacity 0.25s ease, box-shadow 0.25s ease;
    cursor: pointer;
}

.company-footer a:hover {
    opacity: 1;
    box-shadow: 0 2px 10px rgba(74, 114, 153, 0.22);
}

.company-footer-logo {
    display: block;
    height: 22px;
    width: auto;
    overflow: hidden;
    flex-shrink: 0;
}

.company-footer-powered {
    font-family: 'Arial', sans-serif;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 2px;
    color: #4A7299;
    text-transform: uppercase;
    white-space: nowrap;
    line-height: 1;
}

/* Mobile */
@media (max-width: 768px) {
    .company-footer {
        bottom: 44px;
        right: 10px;
    }

    .company-footer a {
        padding: 3px 8px 3px 4px;
        gap: 4px;
    }

    .company-footer-logo {
        height: 16px;
    }

    .company-footer-powered {
        font-size: 7px;
        letter-spacing: 1px;
    }
}

.company-footer-divider { display: none; }
.company-footer-arabic  { display: none; }

/* ============================================
   MOBILE RESPONSIVE — max-width: 768px
   ============================================ */

@media (max-width: 768px) {

  /* Toolbar: allow wrapping, tighter padding */
  .toolbar {
    flex-wrap: nowrap;
    padding: 6px 8px;
    gap: 4px;
    min-height: 48px;
  }

  /* Right side: shrink inputs */
  .toolbar-right {
    gap: 4px;
    flex-shrink: 1;
    min-width: 0;
  }

  .app-title {
    font-size: 14px;
    white-space: nowrap;
  }

  .toolbar-input {
    min-width: 80px !important;
    width: 80px !important;
    font-size: 11px;
    padding: 4px 6px;
  }

  .result-badge {
    display: none;
  }

  /* Left side: show only hamburger, hide all other buttons */
  .toolbar-left {
    gap: 4px;
    flex-shrink: 0;
  }

  /* Hide expand/collapse + node-action buttons on mobile toolbar */
  .toolbar-left .btn-tree-control,
  .toolbar-left .btn-primary,
  .toolbar-left .btn-secondary {
    display: none !important;
  }

  /* Keep hamburger visible */
  .btn-menu-toggle {
    display: flex !important;
  }

  /* Fix drawers cut off by browser URL bar */
  .main-menu-drawer {
    height: 100dvh !important;
    max-height: 100dvh !important;
  }

  /* Settings panel scroll fix */
  .settings-panel {
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow-y: auto;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* Mobile Bottom Action Bar */
.mobile-action-bar {
  display: none; /* hidden on desktop */
}

@media (max-width: 768px) {

  /* Show bar on mobile */
  .mobile-action-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    background: #fff;
    border-top: 1px solid #dde3ed;
    padding: 6px 8px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    gap: 6px;
    justify-content: center;
    align-items: center;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  }

  .mob-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 20px;
    font-family: inherit;
    cursor: pointer;
    min-width: 44px;
    height: 44px;
    transition: opacity 0.15s;
  }

  .mob-btn-secondary {
    background: #f0f4fa;
    color: #4a7ab5;
    border: 1px solid #dde3ed;
  }

  .mob-btn-primary {
    background: #4a7ab5;
    color: #fff;
  }

  .mob-btn-success {
    background: #27ae60;
    color: #fff;
  }

  .mob-btn-danger {
    background: #f5f5f5;
    color: #e74c3c;
    border: 1px solid #e74c3c;
  }

  /* Push tree up so bar doesn't overlap it */
  #tree {
    padding-bottom: 72px;
  }

  /* Push zoom stepper fully above the action bar */
  .zoom-stepper-float {
    bottom: 140px !important;
  }

  /* Push company watermark above action bar */
  .company-footer {
    bottom: 120px !important;
  }

  /* Push app footer above action bar, make it thinner */
  .app-footer {
    bottom: 64px !important;
    z-index: 901;
    padding: 4px 12px !important;
    font-size: 11px !important;
    min-height: unset !important;
  }
}

/* ============================================================
   BILINGUAL — RTL / LTR LAYOUT OVERRIDES + LANG TOGGLE
   ============================================================ */

/* --- Toolbar direction --- */
[dir="ltr"] .toolbar {
  flex-direction: row-reverse;
}

[dir="ltr"] .toolbar-right {
  flex-direction: row-reverse;
}

[dir="ltr"] .toolbar-left {
  flex-direction: row-reverse;
}

/* --- Main menu drawer ---
   AR: slides in from the left (default)
   EN: slides in from the right               */
.main-menu-drawer {
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
  bottom: 0;
  width: 280px;
  box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  transform: translateX(0);
}

[dir="ltr"] .main-menu-drawer {
  left: auto;
  right: 0;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
}

/* --- Detail drawer ---
   AR: slides in from the right (default)
   EN: slides in from the left               */
[dir="ltr"] .detail-drawer {
  right: auto;
  left: 0;
}

[dir="ltr"] .detail-drawer
  [x-transition\:enter-start] {
  transform: translateX(-100%);
}

/* --- Settings sidebar ---
   AR: anchored to the right (default)
   EN: anchored to the left                  */
[dir="ltr"] #settings-sidebar {
  right: auto;
  left: 0;
}

/* --- AI panel ---
   AR: sits on the left, tree shifts right (default)
   EN: sits on the right, tree shifts left           */
[dir="ltr"] .ai-panel-container {
  left: auto;
  right: 0;
}

[dir="ltr"] #tree[style*="margin-left"] {
  margin-left: 0 !important;
  margin-right: 380px;
}

/* --- Level ruler ---
   AR: on the left (default)
   EN: on the right                          */
[dir="ltr"] #level-ruler {
  left: auto;
  right: 0;
}

/* --- Zoom stepper float ---
   AR: bottom-left (default)
   EN: bottom-right                          */
[dir="ltr"] .zoom-stepper-float {
  left: auto;
  right: 16px;
}

/* --- Company footer badge ---
   AR: bottom-right (default)
   EN: bottom-left                           */
[dir="ltr"] .company-footer {
  right: auto;
  left: 12px;
}

/* --- Mobile action bar ---
   reverse button order in LTR              */
[dir="ltr"] .mobile-action-bar {
  flex-direction: row-reverse;
}

/* --- Text alignment in modals and drawers --- */
[dir="ltr"] .modal-card,
[dir="ltr"] .detail-drawer,
[dir="ltr"] #settings-sidebar {
  text-align: left;
}

[dir="ltr"] .modal-actions {
  flex-direction: row;
}

[dir="ltr"] .drawer-header {
  flex-direction: row-reverse;
}

[dir="ltr"] .drawer-detail-row {
  flex-direction: row;
}

[dir="ltr"] .menu-user-header {
  flex-direction: row;
}

/* --- Success toast ---
   AR: appears bottom-right (default)
   EN: appears bottom-left                   */
[dir="ltr"] .success-toast {
  right: auto;
  left: 24px;
}

/* ============================================================
   LANGUAGE TOGGLE PILL
   ============================================================ */

.menu-lang-toggle {
  display: flex;
  justify-content: center;
  padding: 12px 16px 16px;
}

.lang-pill {
  display: flex;
  align-items: center;
  gap: 0;
  background: #f0f2f5;
  border: 1.5px solid #d0d5dd;
  border-radius: 20px;
  padding: 4px 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #888;
  transition: border-color 0.2s;
  letter-spacing: 0.5px;
  width: 88px;
  justify-content: center;
}

.lang-pill:hover {
  border-color: #4a90d9;
}

.lang-pill span {
  padding: 3px 10px;
  border-radius: 14px;
  transition: background 0.2s, color 0.2s;
  line-height: 1.4;
}

.lang-sep {
  color: #ccc;
  padding: 0 !important;
  font-weight: 300;
  font-size: 14px;
  border-radius: 0 !important;
  background: none !important;
}

.lang-active {
  background: #4a90d9;
  color: #fff !important;
}

.other-data-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: transparent;
    border: none;
    border-top: 1px solid #e0e0e0;
    padding: 10px 2px;
    margin-top: 8px;
    font: inherit;
    font-weight: 600;
    color: #555;
    cursor: pointer;
}
.other-data-toggle:hover { color: #000; }
.other-data-section { padding-top: 4px; }

/* Requester info section in Add Person modal */
.requester-fields {
    border-top: 1px solid #d0d0d0;
    margin-top: 16px;
    padding-top: 14px;
}
.requester-fields label {
    font-weight: normal;
    color: #888;
}
