/* Enhanced Editor Styles with Rich Text Features */

/* Editor Content Styling */
.editor {
    font-feature-settings: "liga" 1, "kern" 1, "mark" 1, "mkmk" 1;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
}

/* Rich Text Elements */
.editor h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    margin-top: 2rem;
    line-height: 1.2;
    color: var(--text-primary);
}

.editor h1:first-child {
    margin-top: 0;
}

.editor h2 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.875rem;
    margin-top: 1.75rem;
    line-height: 1.3;
    color: var(--text-primary);
}

.editor h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    margin-top: 1.5rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.editor h4 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.625rem;
    margin-top: 1.25rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.editor h5 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    margin-top: 1rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.editor h6 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    margin-top: 1rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.editor p {
    margin-bottom: 1rem;
    line-height: 1.8;
    color: var(--text-primary);
}

.editor p:last-child {
    margin-bottom: 0;
}

/* Text Formatting */
.editor strong, .editor b {
    font-weight: 700;
}

.editor em, .editor i {
    font-style: italic;
}

.editor u {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.editor s, .editor strike {
    text-decoration: line-through;
}

.editor sup {
    vertical-align: super;
    font-size: 0.75em;
    line-height: 0;
}

.editor sub {
    vertical-align: sub;
    font-size: 0.75em;
    line-height: 0;
}

/* Lists */
.editor ul {
    list-style-type: disc;
    margin: 1rem 0;
    padding-right: 2rem;
    padding-left: 0;
}

.editor ol {
    list-style-type: decimal;
    margin: 1rem 0;
    padding-right: 2rem;
    padding-left: 0;
}

.editor ul ul, .editor ol ol, .editor ul ol, .editor ol ul {
    margin: 0.5rem 0;
}

.editor li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
    text-align: right;
}

.editor li:last-child {
    margin-bottom: 0;
}

/* Nested list styling */
.editor ul ul {
    list-style-type: circle;
}

.editor ul ul ul {
    list-style-type: square;
}

/* Blockquotes */
.editor blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    background: var(--surface-color);
    border-right: 4px solid var(--primary-color);
    border-left: none;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    font-style: italic;
    color: var(--text-secondary);
}

.editor blockquote p {
    margin-bottom: 0;
}

/* Code */
.editor code {
    background: var(--surface-color);
    padding: 0.2em 0.4em;
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--primary-color);
    direction: ltr;
    unicode-bidi: embed;
}

.editor pre {
    background: var(--surface-color);
    padding: 1rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 1rem 0;
    direction: ltr;
}

.editor pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

/* Links */
.editor a {
    color: var(--primary-color);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color 0.2s ease;
}

.editor a:hover {
    color: var(--primary-hover);
    text-decoration-thickness: 2px;
}

.editor a:visited {
    color: #7c3aed;
}

/* Images */
.editor img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin: 1rem 0;
    display: block;
}

.editor img.inline {
    display: inline;
    margin: 0;
    vertical-align: middle;
}

/* Tables */
.editor table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    background: var(--background-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.editor th {
    background: var(--surface-color);
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
    padding: 0.75rem;
    border-bottom: 2px solid var(--border-color);
}

.editor td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    text-align: right;
}

.editor tr:last-child td {
    border-bottom: none;
}

.editor tr:hover {
    background: rgba(37, 99, 235, 0.05);
}

/* Horizontal Rule */
.editor hr {
    border: none;
    height: 2px;
    background: linear-gradient(to left, var(--border-color), var(--primary-color), var(--border-color));
    margin: 2rem 0;
    border-radius: 1px;
}

/* Indentation */
.editor .indent-1 { margin-right: 2rem; }
.editor .indent-2 { margin-right: 4rem; }
.editor .indent-3 { margin-right: 6rem; }
.editor .indent-4 { margin-right: 8rem; }

/* Text Alignment Classes */
.editor .text-right { text-align: right; }
.editor .text-left { text-align: left; }
.editor .text-center { text-align: center; }
.editor .text-justify { text-align: justify; }

/* Font Size Classes */
.editor .font-small { font-size: 0.875em; }
.editor .font-large { font-size: 1.125em; }
.editor .font-xlarge { font-size: 1.25em; }

/* Highlight Text */
.editor mark, .editor .highlight {
    background: rgba(255, 235, 59, 0.3);
    padding: 0.1em 0.2em;
    border-radius: 2px;
}

/* Selection Styling */
.editor::selection {
    background: rgba(37, 99, 235, 0.2);
    color: inherit;
}

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

/* Focus Styling */
.editor:focus {
    outline: none;
}

/* Placeholder Styling */
.editor[data-placeholder]:empty::before {
    content: attr(data-placeholder);
    color: var(--text-secondary);
    font-style: italic;
    pointer-events: none;
    opacity: 0.7;
}

/* Page Break Simulation */
.editor .page-break {
    page-break-after: always;
    break-after: page;
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 2px dashed var(--border-color);
}

/* Print Styles */
@media print {
    .editor {
        background: white;
        color: black;
        font-size: 12pt;
        line-height: 1.6;
        margin: 0;
        padding: 1in;
        box-shadow: none;
    }
    
    .editor a {
        color: black;
        text-decoration: underline;
    }
    
    .editor .page-break {
        page-break-after: always;
        break-after: page;
        border-bottom: none;
        margin-bottom: 0;
        padding-bottom: 0;
    }
}

/* Urdu-specific enhancements */
.editor.urdu-mode {
    font-family: 'Noto Nastaliq Urdu', 'Jameel Noori Nastaleeq', 'Mehr Nastaliq Web', serif;
    line-height: 2.2;
    letter-spacing: 0.02em;
    word-spacing: 0.1em;
    text-align: right;
    direction: rtl;
}

/* Urdu punctuation spacing */
.editor .urdu-punctuation::after {
    content: ' ';
    white-space: pre;
}

/* Diacritics support */
.editor .with-diacritics {
    font-feature-settings: "mark" 1, "mkmk" 1, "liga" 1;
    text-rendering: optimizeLegibility;
}

/* Mixed content handling */
.editor .mixed-content {
    unicode-bidi: plaintext;
}

.editor .english-text {
    direction: ltr;
    unicode-bidi: embed;
    display: inline;
    font-family: Inter, sans-serif;
}

.editor .urdu-text {
    direction: rtl;
    unicode-bidi: embed;
    display: inline;
}

/* Zoom levels */
.zoom-50 .editor { font-size: 7px; }
.zoom-75 .editor { font-size: 10.5px; }
.zoom-100 .editor { font-size: 14px; }
.zoom-125 .editor { font-size: 17.5px; }
.zoom-150 .editor { font-size: 21px; }
.zoom-175 .editor { font-size: 24.5px; }
.zoom-200 .editor { font-size: 28px; }

/* Cursor enhancements */
.editor {
    cursor: text;
    caret-color: var(--primary-color);
}

/* Content editability indicators */
.editor[contenteditable="true"] {
    outline: none;
    position: relative;
}

.editor[contenteditable="false"] {
    cursor: default;
    opacity: 0.7;
}

/* Error and validation styling */
.editor .spelling-error {
    text-decoration: underline wavy red;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.editor .grammar-error {
    text-decoration: underline wavy blue;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

/* Find and replace highlighting */
.editor .search-highlight {
    background: rgba(255, 193, 7, 0.4);
    border-radius: 2px;
    padding: 0 2px;
}

.editor .search-current {
    background: rgba(255, 87, 34, 0.4);
    border-radius: 2px;
    padding: 0 2px;
    box-shadow: 0 0 4px rgba(255, 87, 34, 0.6);
}

/* Smooth transitions */
.editor * {
    transition: color 0.2s ease, background-color 0.2s ease;
}

/* Performance optimizations */
.editor {
    will-change: contents;
    contain: content;
}