/* RTL (Right-to-Left) Styles for Urdu Language Support */

/* Global RTL Layout */
.rtl-layout {
    direction: rtl;
    text-align: right;
}

/* Override specific elements that should remain LTR */
.ltr-content {
    direction: ltr !important;
    text-align: left !important;
}

/* Header adjustments for RTL */
.rtl-layout .header-content {
    direction: ltr; /* Keep header LTR for better UX with English elements */
}

.rtl-layout .logo-section {
    flex-direction: row-reverse;
}

.rtl-layout .header-actions {
    flex-direction: row-reverse;
}

/* Toolbar RTL adjustments */
.rtl-layout .toolbar {
    direction: ltr; /* Keep toolbar LTR for consistent icon alignment */
}

.rtl-layout .toolbar-section {
    flex-direction: row;
}

/* Sidebar RTL */
.rtl-layout .sidebar {
    border-right: none;
    border-left: 1px solid var(--border-color);
    order: 2;
}

.rtl-layout .editor-container {
    order: 1;
}

.rtl-layout .content-area {
    flex-direction: row-reverse;
}

/* Document title RTL */
.rtl-layout .document-title {
    text-align: right;
    direction: rtl;
}

/* Editor RTL enhancements with proper BiDi support */
.rtl-layout .editor {
    direction: rtl;
    text-align: start;
    unicode-bidi: plaintext;
}

/* Proper BiDi text rendering - avoid overriding all children */
.rtl-layout .editor p {
    direction: rtl;
    text-align: start;
    unicode-bidi: plaintext;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.rtl-layout .editor div {
    direction: rtl;
    text-align: start;
    unicode-bidi: plaintext;
}

/* Handle mixed content (English in Urdu text) */
.rtl-layout .editor .ltr-text {
    direction: ltr;
    display: inline;
    unicode-bidi: embed;
}

/* RTL list styles */
.rtl-layout .editor ul,
.rtl-layout .editor ol {
    padding-right: 2rem;
    padding-left: 0;
    text-align: right;
}

.rtl-layout .editor li {
    text-align: right;
    direction: rtl;
}

/* RTL table styles */
.rtl-layout .editor table {
    direction: rtl;
}

.rtl-layout .editor th,
.rtl-layout .editor td {
    text-align: right;
    direction: rtl;
}

/* Status bar RTL */
.rtl-layout .status-bar {
    direction: ltr; /* Keep status bar LTR for numbers and controls */
}

.rtl-layout .status-left {
    order: 2;
}

.rtl-layout .status-right {
    order: 1;
}

/* Modal RTL adjustments */
.rtl-layout .modal-content {
    direction: rtl;
    text-align: right;
}

.rtl-layout .modal-header {
    flex-direction: row-reverse;
}

.rtl-layout .form-actions {
    justify-content: flex-start;
    flex-direction: row-reverse;
}

/* Footer RTL */
.rtl-layout .footer-links {
    flex-direction: row-reverse;
}

/* Specific RTL typography for Urdu */
.urdu-text {
    font-family: 'Noto Nastaliq Urdu', 'Jameel Noori Nastaleeq', 'Mehr Nastaliq Web', serif;
    direction: rtl;
    text-align: right;
    line-height: 1.8;
    letter-spacing: 0.02em;
    word-spacing: 0.1em;
}

/* Urdu font cascade */
@font-face {
    font-family: 'Jameel Noori Nastaleeq';
    src: url('https://fonts.cdnfonts.com/s/15451/JameelNooriNastaleeq.woff') format('woff');
    font-display: swap;
}

@font-face {
    font-family: 'Mehr Nastaliq Web';
    src: url('https://fonts.cdnfonts.com/s/19775/mehrnas.woff2') format('woff2');
    font-display: swap;
}

/* Urdu punctuation spacing */
.rtl-layout .editor .urdu-punctuation {
    margin-left: 0.2em;
    margin-right: 0;
}

/* RTL form elements */
.rtl-layout .form-input {
    text-align: right;
    direction: rtl;
}

.rtl-layout .form-input[type="url"],
.rtl-layout .form-input[type="email"] {
    direction: ltr;
    text-align: left;
}

/* RTL search and replace */
.rtl-layout #find-text,
.rtl-layout #replace-text {
    direction: rtl;
    text-align: right;
}

/* Ensure proper bidi handling for mixed content */
.bidi-embed {
    unicode-bidi: embed;
}

.bidi-isolate {
    unicode-bidi: isolate;
}

.bidi-override {
    unicode-bidi: bidi-override;
}

/* RTL-specific animations and transitions */
@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

.rtl-layout .slide-in-right {
    animation: slideInFromRight 0.3s ease-out;
}

.rtl-layout .slide-in-left {
    animation: slideInFromLeft 0.3s ease-out;
}

/* RTL scrollbar positioning */
.rtl-layout .sidebar {
    scrollbar-gutter: stable both-edges;
}

/* Improve RTL text selection */
.rtl-layout .editor::selection {
    background: rgba(37, 99, 235, 0.2);
    color: inherit;
}

.rtl-layout .editor *::selection {
    background: rgba(37, 99, 235, 0.2);
    color: inherit;
}

/* RTL cursor positioning improvements */
.rtl-layout .editor {
    cursor: text;
}

.rtl-layout .editor:empty::before {
    cursor: text;
}

/* Handle RTL in specific UI components */
.rtl-layout .toolbar-btn[title] {
    direction: ltr; /* Keep tooltips in LTR for better readability */
}

/* Export modal RTL */
.rtl-layout .export-btn {
    text-align: right;
    flex-direction: row-reverse;
}

.rtl-layout .export-btn i {
    margin-left: 0;
    margin-right: 0.75rem;
}

/* Recent documents RTL */
.rtl-layout .recent-docs-list li {
    text-align: right;
    direction: rtl;
}

/* Statistics panel RTL */
.rtl-layout .stat-item {
    flex-direction: row-reverse;
}

/* Zoom controls RTL adjustment */
.rtl-layout .zoom-controls {
    flex-direction: row-reverse;
}

/* Special handling for numbers and English text in RTL context */
.ltr-number {
    direction: ltr;
    unicode-bidi: embed;
    display: inline;
}

.rtl-layout .ltr-number {
    direction: ltr;
    unicode-bidi: embed;
}

/* Urdu-specific line height and spacing adjustments */
.rtl-layout .editor {
    line-height: 2.2; /* Better for Urdu script */
    word-spacing: 0.1em;
}

/* Handle Urdu diacritics properly */
.rtl-layout .editor .urdu-diacritics {
    font-feature-settings: "mark" 1, "mkmk" 1;
    text-rendering: optimizeLegibility;
}

/* RTL table cell alignment */
.rtl-layout .editor table th,
.rtl-layout .editor table td {
    text-align: right;
}

/* Ensure proper RTL alignment for block elements */
.rtl-layout .editor h1,
.rtl-layout .editor h2,
.rtl-layout .editor h3,
.rtl-layout .editor h4,
.rtl-layout .editor h5,
.rtl-layout .editor h6,
.rtl-layout .editor p,
.rtl-layout .editor div,
.rtl-layout .editor blockquote {
    text-align: right;
    direction: rtl;
}

/* Handle inline code and special elements */
.rtl-layout .editor code {
    direction: ltr;
    unicode-bidi: embed;
}

.rtl-layout .editor a {
    direction: rtl;
    text-align: right;
}