/* ============================================
   NOTE EDITOR V2 - PREMIUM CLINICAL EDITOR
   ============================================
   ARCHITECTURE: Dark-first rich text editor with glass-morphism
   WHY: Original editor had poor cursor visibility, broken selection,
        invisible edit buttons, no depth/contrast, missing animations
   DESIGN: High-contrast dark theme, glowing cursor, visible selection,
           premium modals, smooth editing animations
   ============================================ */

/* ============================================
   CSS CUSTOM PROPERTIES
   ============================================ */
:root {
    /* Editor Palette */
    --editor-bg: rgba(15, 23, 42, 0.95);
    --editor-surface: rgba(30, 41, 59, 0.8);
    --editor-border: rgba(148, 163, 184, 0.15);

    /* Text Colors - High Contrast */
    --editor-text: #f1f5f9;
    --editor-text-secondary: #cbd5e1;
    --editor-text-muted: #94a3b8;

    /* Cursor & Selection - HIGHLY VISIBLE */
    --editor-cursor: #60a5fa;
    --editor-cursor-glow: 0 0 8px rgba(96, 165, 250, 0.6);
    --editor-selection-bg: rgba(99, 102, 241, 0.4);
    --editor-selection-text: #ffffff;

    /* AI Edit Highlighting */
    --editor-ai-pending: rgba(251, 191, 36, 0.25);
    --editor-ai-pending-border: rgba(251, 191, 36, 0.6);
    --editor-ai-accepted: rgba(34, 197, 94, 0.2);
    --editor-ai-rejected: rgba(239, 68, 68, 0.2);

    /* Accents */
    --editor-accent-primary: #6366f1;
    --editor-accent-blue: #3b82f6;
    --editor-accent-emerald: #10b981;
    --editor-accent-amber: #f59e0b;
    --editor-accent-red: #ef4444;

    /* Animation */
    --editor-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --editor-duration: 0.3s;
}

/* ============================================
   EDITOR CONTAINER
   ============================================ */
.note-output-section,
.sol-note-output {
    background: var(--editor-bg);
    border: 1px solid var(--editor-border);
    border-radius: 16px;
    overflow: hidden;
    position: relative;

    /* Depth with layered shadows */
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.03),
        0 4px 24px -4px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Editor Header/Toolbar */
.note-output-header,
.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(30, 41, 59, 0.6);
    border-bottom: 1px solid var(--editor-border);
    gap: 12px;
}

.note-output-header h4,
.editor-toolbar h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--editor-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.note-output-header h4 i,
.editor-toolbar h4 i {
    color: var(--editor-accent-blue);
    font-size: 18px;
}

/* ============================================
   SOL NOTE OUTPUT SECTION WRAPPER
   ============================================ */
.sol-note-output-section {
    background: var(--editor-bg);
    border-radius: 16px;
    overflow: hidden;
    margin-top: 16px;
}

.sol-note-editor-wrapper {
    display: flex;
    flex-direction: column;
    background: var(--editor-bg);
    border: 1px solid var(--editor-border);
    border-radius: 16px;
    overflow: hidden;
    position: relative;

    /* Depth with layered shadows */
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.03),
        0 4px 24px -4px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.sol-note-content {
    background: var(--editor-bg) !important;
    min-height: 400px;
}

/* ============================================
   STREAMING PROGRESS BAR
   ============================================ */
.sol-note-progress {
    padding: 16px 20px;
    background: rgba(30, 41, 59, 0.6);
    border-bottom: 1px solid var(--editor-border);
}

.sol-progress-bar {
    height: 6px;
    background: rgba(51, 65, 85, 0.6);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 10px;
}

.sol-progress-fill {
    height: 100%;
    background: linear-gradient(90deg,
        var(--editor-accent-primary) 0%,
        var(--editor-accent-blue) 50%,
        var(--editor-accent-emerald) 100%
    );
    background-size: 200% 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
    animation: progressShimmer 2s ease-in-out infinite;
}

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

.sol-progress-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sol-progress-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--editor-text);
}

.sol-progress-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--editor-text-muted);
    font-family: ui-monospace, 'SF Mono', monospace;
}

/* ============================================
   PM TOOLBAR (FORMATTING BAR)
   ============================================ */
.pm-toolbar,
.sol-pm-toolbar {
    display: flex !important;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    background: rgba(30, 41, 59, 0.8) !important;
    border-bottom: 1px solid var(--editor-border) !important;
    flex-wrap: wrap;
}

.pm-toolbar-button {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--editor-text-secondary);
    cursor: pointer;
    font-size: 18px;
    transition: all 0.15s ease;
}

.pm-toolbar-button:hover {
    background: rgba(99, 102, 241, 0.2);
    color: var(--editor-text);
}

.pm-toolbar-button.is-active,
.pm-toolbar-button.active {
    background: var(--editor-accent-primary);
    color: white;
}

.pm-toolbar-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pm-toolbar-separator {
    width: 1px;
    height: 24px;
    background: rgba(148, 163, 184, 0.2);
    margin: 0 8px;
}

/* ============================================
   FLOATING EDIT BUTTON
   ============================================ */
.edit-selection-btn,
#editBtn {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: linear-gradient(135deg, var(--editor-accent-primary), var(--editor-accent-blue)) !important;
    color: white !important;
    border: none !important;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow:
        0 4px 16px -4px rgba(99, 102, 241, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
    z-index: 1000;
}

.edit-selection-btn:hover,
#editBtn:hover {
    transform: translateY(-2px);
    box-shadow:
        0 8px 24px -4px rgba(99, 102, 241, 0.7),
        0 0 0 1px rgba(255, 255, 255, 0.15);
}

.edit-selection-btn i,
#editBtn i {
    font-size: 16px;
}

/* ============================================
   TIPTAP/PROSEMIRROR EDITOR CORE
   ============================================ */
.ProseMirror,
.tiptap,
#tiptap-editor .ProseMirror,
[data-tiptap-editor] .ProseMirror {
    /* Force dark background */
    background: var(--editor-bg) !important;
    color: var(--editor-text) !important;

    /* Comfortable reading area */
    padding: 24px 28px !important;
    min-height: 400px;
    max-height: 70vh;
    overflow-y: auto;

    /* Typography */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    line-height: 1.7;
    letter-spacing: -0.01em;

    /* Focus state */
    outline: none !important;
}

/* Focus ring on editor container */
.ProseMirror-focused,
.tiptap:focus-within {
    box-shadow: inset 0 0 0 2px rgba(99, 102, 241, 0.3);
}

/* ============================================
   CURSOR - HIGHLY VISIBLE
   ============================================ */
.ProseMirror .ProseMirror-cursor,
.ProseMirror > .ProseMirror-gapcursor::after {
    border-color: var(--editor-cursor) !important;
    border-left-width: 2px !important;
}

/* Blinking cursor with glow */
@keyframes cursorBlink {
    0%, 100% {
        opacity: 1;
        box-shadow: var(--editor-cursor-glow);
    }
    50% {
        opacity: 0.4;
        box-shadow: none;
    }
}

.ProseMirror:focus .ProseMirror-cursor {
    animation: cursorBlink 1s ease-in-out infinite;
}

/* Caret color for native input */
.ProseMirror {
    caret-color: var(--editor-cursor) !important;
}

/* Gap cursor (between blocks) */
.ProseMirror .ProseMirror-gapcursor:after {
    border-top: 2px solid var(--editor-cursor) !important;
    width: 24px;
}

/* ============================================
   TEXT SELECTION - FIXED VISIBILITY
   ============================================ */
.ProseMirror ::selection,
.ProseMirror *::selection,
.tiptap ::selection,
.tiptap *::selection {
    background: var(--editor-selection-bg) !important;
    color: var(--editor-selection-text) !important;
}

/* Mozilla selection */
.ProseMirror ::-moz-selection,
.ProseMirror *::-moz-selection,
.tiptap ::-moz-selection,
.tiptap *::-moz-selection {
    background: var(--editor-selection-bg) !important;
    color: var(--editor-selection-text) !important;
}

/* Selected node decoration */
.ProseMirror .ProseMirror-selectednode {
    outline: 2px solid var(--editor-accent-primary) !important;
    outline-offset: 2px;
    border-radius: 4px;
}

/* ============================================
   TYPOGRAPHY HIERARCHY
   ============================================ */
.ProseMirror h1,
.ProseMirror h2,
.ProseMirror h3,
.ProseMirror h4,
.ProseMirror h5,
.ProseMirror h6 {
    color: var(--editor-text) !important;
    font-weight: 600;
    margin: 1.5em 0 0.5em;
    line-height: 1.3;
}

.ProseMirror h1 { font-size: 1.75em; }
.ProseMirror h2 { font-size: 1.5em; }
.ProseMirror h3 { font-size: 1.25em; }
.ProseMirror h4 { font-size: 1.1em; }

.ProseMirror p {
    color: var(--editor-text) !important;
    margin: 0.75em 0;
}

.ProseMirror strong,
.ProseMirror b {
    color: #ffffff !important;
    font-weight: 600;
}

.ProseMirror em,
.ProseMirror i {
    color: var(--editor-text-secondary);
    font-style: italic;
}

/* Lists */
.ProseMirror ul,
.ProseMirror ol {
    padding-left: 1.5em;
    margin: 0.75em 0;
}

.ProseMirror li {
    color: var(--editor-text);
    margin: 0.25em 0;
}

.ProseMirror li::marker {
    color: var(--editor-accent-blue);
}

/* ============================================
   CLINICAL SECTION STYLING
   ============================================ */
/* Problem headers */
.ProseMirror .problem-header,
.ProseMirror h3[data-problem],
.ProseMirror strong:first-child {
    color: #60a5fa !important;
    font-weight: 700;
    border-bottom: 1px solid rgba(96, 165, 250, 0.2);
    padding-bottom: 4px;
    margin-bottom: 8px;
}

/* Clinical sections (A&P, HPI, etc.) */
.ProseMirror .clinical-section {
    background: rgba(30, 41, 59, 0.4);
    border-left: 3px solid var(--editor-accent-blue);
    padding: 12px 16px;
    margin: 12px 0;
    border-radius: 0 8px 8px 0;
}

/* Medication highlights */
.ProseMirror .medication,
.ProseMirror [data-type="medication"] {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 500;
}

/* Lab values */
.ProseMirror .lab-value,
.ProseMirror [data-type="lab"] {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: ui-monospace, 'SF Mono', monospace;
    font-size: 0.9em;
}

/* ============================================
   AI EDIT DECORATIONS
   ============================================ */
/* Pending AI edit - yellow highlight */
.ProseMirror .ai-edit-pending,
.ProseMirror [data-ai-edit="pending"],
.ai-highlight,
.edit-highlight {
    background: var(--editor-ai-pending) !important;
    border: 1px dashed var(--editor-ai-pending-border);
    border-radius: 4px;
    padding: 2px 4px;
    margin: 0 -4px;
    position: relative;

    /* Pulse animation while AI is processing */
    animation: aiEditPulse 2s ease-in-out infinite;
}

@keyframes aiEditPulse {
    0%, 100% {
        background: var(--editor-ai-pending);
        box-shadow: 0 0 0 0 rgba(251, 191, 36, 0);
    }
    50% {
        background: rgba(251, 191, 36, 0.35);
        box-shadow: 0 0 20px -4px rgba(251, 191, 36, 0.4);
    }
}

/* Accepted AI edit - green flash */
.ProseMirror .ai-edit-accepted,
.ProseMirror [data-ai-edit="accepted"] {
    background: var(--editor-ai-accepted);
    animation: aiAccepted 0.5s ease-out;
}

@keyframes aiAccepted {
    0% {
        background: rgba(34, 197, 94, 0.5);
        transform: scale(1.02);
    }
    100% {
        background: transparent;
        transform: scale(1);
    }
}

/* Rejected AI edit - red flash */
.ProseMirror .ai-edit-rejected,
.ProseMirror [data-ai-edit="rejected"] {
    background: var(--editor-ai-rejected);
    animation: aiRejected 0.5s ease-out;
}

@keyframes aiRejected {
    0% {
        background: rgba(239, 68, 68, 0.4);
    }
    100% {
        background: transparent;
    }
}

/* ============================================
   STREAMING/LOADING STATE
   ============================================ */
.editor-streaming,
.streaming-overlay {
    position: relative;
}

.editor-streaming::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--editor-accent-primary) 50%,
        transparent 100%
    );
    animation: streamingBar 1.5s ease-in-out infinite;
}

@keyframes streamingBar {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 8px 12px;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 12px;
    margin: 8px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--editor-accent-primary);
    border-radius: 50%;
    animation: typingDot 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

/* ============================================
   BUBBLE MENU (Selection Toolbar)
   ============================================ */
.bubble-menu,
.tippy-box[data-theme="bubble-menu"],
.ProseMirror-menubar {
    background: rgba(30, 41, 59, 0.98) !important;
    border: 1px solid rgba(148, 163, 184, 0.2) !important;
    border-radius: 12px !important;
    padding: 6px 8px !important;
    display: flex;
    gap: 4px;

    /* Premium shadow */
    box-shadow:
        0 8px 32px -8px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.05) !important;

    /* Entry animation */
    animation: bubbleMenuEnter 0.2s var(--editor-ease);
}

@keyframes bubbleMenuEnter {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.bubble-menu button,
.ProseMirror-menubar button {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--editor-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.15s ease;
}

.bubble-menu button:hover,
.ProseMirror-menubar button:hover {
    background: rgba(99, 102, 241, 0.2);
    color: var(--editor-text);
}

.bubble-menu button.is-active,
.ProseMirror-menubar button.active {
    background: var(--editor-accent-primary);
    color: white;
}

/* Divider in bubble menu */
.bubble-menu .divider {
    width: 1px;
    height: 24px;
    background: rgba(148, 163, 184, 0.2);
    margin: 0 4px;
}

/* ============================================
   EDIT MODAL - ACCEPT/REJECT
   ============================================ */
#editModal,
.edit-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;

    /* Backdrop */
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    /* Entry animation */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s;
}

#editModal:not([hidden]),
#editModal.show,
.edit-modal.show {
    opacity: 1;
    visibility: visible;
    display: flex;
}

#editModal[hidden],
.edit-modal[hidden] {
    display: none !important;
}

/* Modal Surface */
#editModal > div,
.edit-modal-surface {
    background: rgba(15, 23, 42, 0.98) !important;
    border: 1px solid rgba(148, 163, 184, 0.15) !important;
    border-radius: 20px !important;
    padding: 0 !important;
    max-width: 480px;
    width: 100%;
    overflow: hidden;

    /* Premium shadow */
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.05),
        0 24px 64px -16px rgba(0, 0, 0, 0.6),
        0 0 48px -16px rgba(99, 102, 241, 0.2) !important;

    /* Entry animation */
    transform: translateY(20px) scale(0.96);
    animation: editModalEnter 0.35s var(--editor-ease) forwards;
}

@keyframes editModalEnter {
    to {
        transform: translateY(0) scale(1);
    }
}

/* Modal Header */
.edit-modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.edit-modal-header i {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--editor-accent-primary);
    border-radius: 12px;
}

.edit-modal-header h4 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--editor-text);
}

.edit-modal-header p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--editor-text-muted);
}

/* Modal Body - Edit Preview */
.edit-modal-body,
#editModal .edit-preview {
    padding: 20px 24px;
    max-height: 300px;
    overflow-y: auto;
}

.edit-preview-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--editor-text-muted);
    margin-bottom: 8px;
}

.edit-preview-text {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 12px;
    padding: 16px;
    color: var(--editor-text);
    font-size: 14px;
    line-height: 1.6;
}

/* Comparison Grid Layout */
.edit-comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.edit-comparison-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Modified text column highlight */
.edit-preview-modified {
    border-color: rgba(34, 197, 94, 0.4) !important;
    background: rgba(30, 41, 59, 0.6) !important;
}

/* Diff highlighting in preview */
.edit-preview-text del,
.edit-preview-text .removed {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    text-decoration: line-through;
    padding: 1px 4px;
    border-radius: 3px;
}

.edit-preview-text ins,
.edit-preview-text .added {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
    text-decoration: none;
    padding: 1px 4px;
    border-radius: 3px;
}

/* Edit preview label with icon */
.edit-preview-label i {
    color: var(--editor-accent-emerald);
    margin-right: 4px;
}

/* Diff highlighting classes (used by pm-editor.js) */
.diff-removed {
    background: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
    text-decoration: line-through;
    text-decoration-color: rgba(239, 68, 68, 0.6);
    padding: 2px 4px;
    border-radius: 3px;
    margin: 0 1px;
}

.diff-added {
    background: rgba(34, 197, 94, 0.25);
    color: #86efac;
    text-decoration: none;
    padding: 2px 4px;
    border-radius: 3px;
    margin: 0 1px;
    font-weight: 500;
}

/* Modal Footer - Action Buttons */
.edit-modal-footer,
#editModal .modal-actions {
    padding: 16px 24px 20px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: rgba(15, 23, 42, 0.5);
    border-top: 1px solid rgba(148, 163, 184, 0.08);
}

/* Button Base */
.edit-modal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

/* Accept Button */
.edit-modal-btn.accept,
#editModal .btn-accept,
.btn-accept-edit {
    background: linear-gradient(135deg, var(--editor-accent-emerald), #059669) !important;
    color: white !important;
    border: none !important;
    box-shadow: 0 4px 12px -2px rgba(16, 185, 129, 0.4);
}

.edit-modal-btn.accept:hover,
#editModal .btn-accept:hover,
.btn-accept-edit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px -2px rgba(16, 185, 129, 0.5) !important;
}

/* Reject Button */
.edit-modal-btn.reject,
#editModal .btn-reject,
.btn-reject-edit {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #fca5a5 !important;
    border: 1px solid rgba(239, 68, 68, 0.3) !important;
}

.edit-modal-btn.reject:hover,
#editModal .btn-reject:hover,
.btn-reject-edit:hover {
    background: rgba(239, 68, 68, 0.25) !important;
    border-color: rgba(239, 68, 68, 0.5) !important;
}

/* Cancel Button */
.edit-modal-btn.cancel,
#editModal .btn-cancel {
    background: rgba(51, 65, 85, 0.5);
    color: var(--editor-text-secondary);
    border: 1px solid rgba(148, 163, 184, 0.15);
}

.edit-modal-btn.cancel:hover,
#editModal .btn-cancel:hover {
    background: rgba(51, 65, 85, 0.7);
    color: var(--editor-text);
}

/* ============================================
   LLM EDIT INSTRUCTION MODAL
   ============================================ */
#editInstructionModal,
.edit-instruction-modal {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;

    /* Backdrop */
    background: rgba(2, 6, 23, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);

    /* Entry animation */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s;
}

#editInstructionModal:not([hidden]),
#editInstructionModal.show,
.edit-instruction-modal.show {
    opacity: 1;
    visibility: visible;
    display: flex;
}

#editInstructionModal[hidden],
.edit-instruction-modal[hidden] {
    display: none !important;
}

/* Instruction Modal Surface */
#editInstructionModal > div,
.edit-instruction-surface {
    background: rgba(15, 23, 42, 0.98) !important;
    border: 1px solid rgba(148, 163, 184, 0.15) !important;
    border-radius: 24px !important;
    padding: 0 !important;
    max-width: 520px;
    width: 100%;
    overflow: hidden;
    position: relative;

    /* Gradient accent bar */
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.05),
        0 32px 80px -20px rgba(0, 0, 0, 0.6),
        0 0 60px -20px rgba(99, 102, 241, 0.25) !important;

    /* Entry animation */
    transform: translateY(24px) scale(0.95);
    animation: instructionModalEnter 0.4s var(--editor-ease) forwards;
}

@keyframes instructionModalEnter {
    to {
        transform: translateY(0) scale(1);
    }
}

/* Top accent bar */
#editInstructionModal > div::before,
.edit-instruction-surface::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg,
        var(--editor-accent-primary) 0%,
        var(--editor-accent-blue) 50%,
        var(--editor-accent-emerald) 100%
    );
}

/* Instruction Header */
.edit-instruction-header {
    padding: 28px 28px 20px;
    text-align: center;
}

.edit-instruction-header i {
    width: 56px;
    height: 56px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(59, 130, 246, 0.15));
    color: var(--editor-accent-primary);
    border-radius: 16px;
    margin-bottom: 16px;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.edit-instruction-header h4 {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 600;
    color: var(--editor-text);
}

.edit-instruction-header p {
    margin: 0;
    font-size: 14px;
    color: var(--editor-text-muted);
}

/* Selected Text Preview */
.edit-instruction-selection {
    margin: 0 24px;
    padding: 16px;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 12px;
    position: relative;
}

.edit-instruction-selection::before {
    content: 'SELECTED TEXT';
    position: absolute;
    top: -8px;
    left: 12px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--editor-text-muted);
    background: rgba(15, 23, 42, 0.98);
    padding: 0 6px;
}

.edit-instruction-selection p {
    margin: 0;
    color: var(--editor-text-secondary);
    font-size: 14px;
    line-height: 1.5;
    font-style: italic;
}

/* Instruction Input */
.edit-instruction-input {
    padding: 20px 24px;
}

.edit-instruction-input label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--editor-text);
    margin-bottom: 10px;
}

.edit-instruction-input textarea,
#editInstructionModal textarea {
    width: 100%;
    min-height: 100px;
    padding: 16px;
    background: rgba(30, 41, 59, 0.6) !important;
    border: 1px solid rgba(148, 163, 184, 0.15) !important;
    border-radius: 12px !important;
    color: var(--editor-text) !important;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    transition: all 0.2s ease;
}

.edit-instruction-input textarea:focus,
#editInstructionModal textarea:focus {
    outline: none !important;
    border-color: var(--editor-accent-primary) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
}

.edit-instruction-input textarea::placeholder,
#editInstructionModal textarea::placeholder {
    color: var(--editor-text-muted);
}

/* Instruction meta row (error + character count) */
.edit-instruction-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 4px;
}

.edit-instruction-error {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #fca5a5;
}

.edit-instruction-error[hidden] {
    display: none;
}

.edit-instruction-error i {
    color: var(--editor-accent-red);
}

.edit-instruction-charcount {
    font-size: 12px;
    color: var(--editor-text-muted);
    font-family: ui-monospace, 'SF Mono', monospace;
}

/* Instruction Footer */
.edit-instruction-footer {
    padding: 16px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Submit Edit Button */
.edit-instruction-btn.submit,
#editInstructionModal .btn-submit,
.btn-apply-edit {
    background: linear-gradient(135deg, var(--editor-accent-primary), var(--editor-accent-blue)) !important;
    color: white !important;
    border: none !important;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px -4px rgba(99, 102, 241, 0.5);
}

.edit-instruction-btn.submit:hover,
#editInstructionModal .btn-submit:hover,
.btn-apply-edit:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px -4px rgba(99, 102, 241, 0.6) !important;
}

/* Loading state during edit */
.edit-instruction-btn.submit.loading,
.btn-apply-edit.loading {
    pointer-events: none;
    opacity: 0.7;
}

.edit-instruction-btn.submit.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: btnSpinner 0.8s linear infinite;
}

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

/* Cancel Button */
.edit-instruction-btn.cancel,
#editInstructionModal .btn-cancel {
    background: rgba(51, 65, 85, 0.5) !important;
    color: var(--editor-text-secondary) !important;
    border: 1px solid rgba(148, 163, 184, 0.15) !important;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.edit-instruction-btn.cancel:hover,
#editInstructionModal .btn-cancel:hover {
    background: rgba(51, 65, 85, 0.7) !important;
    color: var(--editor-text) !important;
}

/* ============================================
   EDITOR ACTION BUTTONS
   ============================================ */
.editor-actions,
.note-output-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(15, 23, 42, 0.5);
    border-top: 1px solid var(--editor-border);
}

.editor-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(51, 65, 85, 0.4);
    border: 1px solid rgba(148, 163, 184, 0.12);
    color: var(--editor-text-secondary);
}

.editor-action-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--editor-text);
}

.editor-action-btn i {
    font-size: 16px;
}

/* Primary action button */
.editor-action-btn.primary {
    background: linear-gradient(135deg, var(--editor-accent-primary), var(--editor-accent-blue));
    border: none;
    color: white;
    box-shadow: 0 2px 8px -2px rgba(99, 102, 241, 0.4);
}

.editor-action-btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px -2px rgba(99, 102, 241, 0.5);
}

/* Danger button */
.editor-action-btn.danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.editor-action-btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
}

/* ============================================
   PLACEHOLDER TEXT
   ============================================ */
.ProseMirror p.is-editor-empty:first-child::before,
.ProseMirror .is-empty::before {
    content: attr(data-placeholder);
    color: var(--editor-text-muted);
    font-style: italic;
    pointer-events: none;
    float: left;
    height: 0;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
.ProseMirror::-webkit-scrollbar,
.edit-modal-body::-webkit-scrollbar {
    width: 8px;
}

.ProseMirror::-webkit-scrollbar-track,
.edit-modal-body::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.5);
    border-radius: 4px;
}

.ProseMirror::-webkit-scrollbar-thumb,
.edit-modal-body::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.2);
    border-radius: 4px;
}

.ProseMirror::-webkit-scrollbar-thumb:hover,
.edit-modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.35);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 600px) {
    .ProseMirror {
        padding: 16px 18px !important;
        font-size: 14px;
    }

    #editModal > div,
    #editInstructionModal > div {
        max-width: calc(100vw - 32px);
        border-radius: 16px !important;
    }

    .edit-modal-footer,
    .edit-instruction-footer {
        flex-direction: column;
    }

    .edit-modal-btn,
    .edit-instruction-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .ProseMirror .ai-edit-pending,
    .ai-highlight,
    .edit-highlight {
        animation: none;
    }

    #editModal > div,
    #editInstructionModal > div {
        animation: none;
        transform: none;
    }

    .bubble-menu {
        animation: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .ProseMirror ::selection {
        background: #0066cc !important;
        color: #ffffff !important;
    }

    .ProseMirror {
        border: 2px solid #ffffff;
    }
}
