/* RTL Overrides for Arabic Layout */
[dir="rtl"] .app-layout {
    direction: rtl;
}

[dir="rtl"] .app-sidebar {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid var(--border-color);
}

[dir="rtl"] .nav-menu a {
    border-left: none;
    border-right: 3px solid transparent;
}

[dir="rtl"] .nav-menu a.active {
    border-left-color: transparent;
    border-right-color: var(--primary-color);
}

[data-theme="dark"][dir="rtl"] .nav-menu a.active {
    border-right-color: #0A84FF;
}

[dir="rtl"] .sidebar-collapsed .nav-menu a[title]:hover::after {
    left: auto;
    right: calc(100% + 8px);
}

[dir="rtl"] .breadcrumb-separator {
    transform: rotate(180deg);
}

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

[dir="rtl"] .org-switcher-dropdown {
    left: auto;
    right: 0;
}

[dir="rtl"] .org-switcher-option {
    text-align: right;
    flex-direction: row-reverse;
}

[dir="rtl"] .page-header-left {
    flex-direction: row-reverse;
}

[dir="rtl"] .form-actions {
    flex-direction: row-reverse;
}

[dir="rtl"] th {
    text-align: right;
}

[dir="rtl"] td {
    text-align: right;
}

[dir="rtl"] .badge {
    margin-left: 0;
    margin-right: 0.25rem;
}

[dir="rtl"] .sidebar-admin-badge {
    margin-left: 0;
    margin-right: 0;
}

[dir="rtl"] .auth-container {
    direction: rtl;
}

[dir="rtl"] .auth-form-group label {
    text-align: right;
}

[dir="rtl"] .auth-input {
    direction: ltr;
    text-align: left;
}

[dir="rtl"] .auth-error,
[dir="rtl"] .auth-success {
    text-align: right;
}

[dir="rtl"] .stat-card {
    text-align: right;
}

[dir="rtl"] .stat-card-primary,
[dir="rtl"] .stat-card-success,
[dir="rtl"] .stat-card-warning,
[dir="rtl"] .stat-card-info,
[dir="rtl"] .stat-card-danger {
    border-left: none;
    border-right: 3px solid;
}

[dir="rtl"] .activity-feed-item {
    flex-direction: row-reverse;
}

[dir="rtl"] a.recent-patient-item {
    flex-direction: row-reverse;
}

[dir="rtl"] .digest-content ul {
    padding-left: 0;
    padding-right: 1.25rem;
}


/* Patient hero RTL. The new two-column hero uses CSS Grid + flexbox which are
   direction-aware by default, so most of the layout mirrors without explicit rules.
   Only the actions row needs row-reverse to keep the button visual order consistent
   with LTR (primary action trailing-side of the cluster). */
[dir="rtl"] .patient-hero-actions {
    flex-direction: row-reverse;
}

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

[dir="rtl"] .tab-header-actions {
    flex-direction: row-reverse;
}

/* Patient Overview RTL */
[dir="rtl"] .vital-row {
    flex-direction: row-reverse;
}

[dir="rtl"] .clinical-status-row {
    flex-direction: row-reverse;
}

[dir="rtl"] .clinical-status-row-arrow {
    transform: scaleX(-1);
}

[dir="rtl"] .ai-summary-header {
    flex-direction: row-reverse;
}

/* Observation sub-tabs + charts + lab panels RTL */
[dir="rtl"] .lab-panel-section summary::before {
    margin-right: 0;
    margin-left: 0.5rem;
    border-left: none;
    border-right: 5px solid var(--text-muted-color);
}

[dir="rtl"] .lab-panel-table th {
    text-align: right;
}

[dir="rtl"] .vital-chart-unit {
    margin-left: 0;
    margin-right: 0.25rem;
}

@media (max-width: 767px) {
    [dir="rtl"] .app-sidebar {
        right: auto;
        left: auto;
        transform: translateX(100%);
    }

    [dir="rtl"] .app-sidebar.mobile-open {
        transform: translateX(0);
    }
}

/* Progress bar text position for RTL */
[dir="rtl"] .file-uploader-progress-text {
    right: auto;
    left: 0;
}

/* Audit History Panel RTL */
[dir="rtl"] .audit-panel {
    animation-name: audit-panel-slide-in-rtl;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
}

@keyframes audit-panel-slide-in-rtl {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/* On mobile bottom sheet, restore slide-up animation (not horizontal slide) */
@media (max-width: 767px) {
    [dir="rtl"] .audit-panel {
        animation-name: audit-panel-slide-up;
    }
}

[dir="rtl"] .audit-field-diff-arrow {
    transform: scaleX(-1);
}

/* ---- Encounter Type Picker ---- */

[dir="rtl"] .encounter-type-picker-toggle {
    text-align: right;
}

[dir="rtl"] .encounter-type-card {
    text-align: right;
    border-left: 1px solid transparent;
    border-right: 3px solid transparent;
}

[dir="rtl"] .encounter-type-card.is-selected {
    border-left-color: transparent;
    border-right-color: var(--primary-color);
}
