/**
 * ProseMirror Editor Styles for Medical Documentation
 *
 * ARCHITECTURE: Medical-focused editor styling with clinical section support
 * WHY: Professional EMR-quality appearance with visual hierarchy for clinical sections
 * TRADEOFF: Custom styles vs default ProseMirror theme - chose medical domain specificity
 */

/* ===== PROSEMIRROR CORE ===== */

.ProseMirror {
    /* ARCHITECTURE: Medical note styling matching Quill's clean appearance */
    font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary, #1a1a1a);
    padding: 1.5rem;
    min-height: 300px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-light, #e0e0e0);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s ease;
}

.ProseMirror:focus {
    border-color: var(--primary-color, #4285f4);
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
}

.ProseMirror.ProseMirror-focused {
    border-color: var(--primary-color, #4285f4);
}

/* Empty state placeholder */
.ProseMirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    color: var(--text-tertiary, #9e9e9e);
    pointer-events: none;
    height: 0;
}

/* ===== TYPOGRAPHY ===== */

.ProseMirror h1 {
    font-size: 1.8rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem 0;
    color: var(--text-primary, #1a1a1a);
    border-bottom: 2px solid var(--border-medium, #d0d0d0);
    padding-bottom: 0.5rem;
}

.ProseMirror h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin: 1.25rem 0 0.75rem 0;
    color: var(--text-primary, #1a1a1a);
}

.ProseMirror h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem 0;
    color: var(--text-secondary, #424242);
}

.ProseMirror p {
    margin: 0.5rem 0;
}

.ProseMirror strong {
    font-weight: 600;
    color: var(--text-primary, #1a1a1a);
}

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

.ProseMirror u {
    text-decoration: underline;
}

/* ===== LISTS ===== */

.ProseMirror ul,
.ProseMirror ol {
    padding-left: 2rem;
    margin: 0.75rem 0;
}

.ProseMirror li {
    margin: 0.25rem 0;
}

.ProseMirror li p {
    margin: 0.25rem 0;
}

/* Nested lists */
.ProseMirror ul ul,
.ProseMirror ol ol,
.ProseMirror ul ol,
.ProseMirror ol ul {
    margin: 0.25rem 0;
}

/* ===== TRACK CHANGES / SUGGESTIONS ===== */

.ProseMirror .suggestion {
    /* ARCHITECTURE: Visual diff highlighting for LLM edits */
    /* WHY: Users need clear visual feedback for accept/reject decisions */
    padding: 2px 4px;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.ProseMirror .suggestion.insert {
    background-color: rgba(76, 175, 80, 0.2);
    border-bottom: 2px solid #4caf50;
}

.ProseMirror .suggestion.delete {
    background-color: rgba(244, 67, 54, 0.2);
    text-decoration: line-through;
    border-bottom: 2px solid #f44336;
}

.ProseMirror .suggestion:hover {
    opacity: 0.8;
}

/* ===== CLINICAL SECTION MARKERS ===== */

.ProseMirror .clinical-section {
    /* WHY: Structured medical documentation requires visual section delineation */
    padding: 1rem;
    margin: 1rem 0;
    border-left: 4px solid var(--primary-color, #4285f4);
    background: rgba(66, 133, 244, 0.05);
    border-radius: 4px;
}

.ProseMirror .clinical-section.hpi {
    border-left-color: #4285f4;
    background: rgba(66, 133, 244, 0.05);
}

.ProseMirror .clinical-section.assessment {
    border-left-color: #f4b400;
    background: rgba(244, 180, 0, 0.05);
}

.ProseMirror .clinical-section.plan {
    border-left-color: #0f9d58;
    background: rgba(15, 157, 88, 0.05);
}

/* ===== SELECTION ===== */

.ProseMirror ::selection {
    background: rgba(66, 133, 244, 0.3);
}

.ProseMirror ::-moz-selection {
    background: rgba(66, 133, 244, 0.3);
}

/* ===== TOOLBAR (will be added in HTML) ===== */

.pm-toolbar {
    /* ARCHITECTURE: Minimal clinical formatting toolbar */
    /* TRADEOFF: Fewer options vs cleaner medical documentation */
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-secondary, #f5f5f5);
    border: 1px solid var(--border-light, #e0e0e0);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    flex-wrap: wrap;
}

.pm-toolbar-button {
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-light, #e0e0e0);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary, #616161);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pm-toolbar-button:hover {
    background: var(--bg-tertiary, #eeeeee);
    border-color: var(--border-medium, #d0d0d0);
}

.pm-toolbar-button.active {
    background: var(--primary-color, #4285f4);
    color: white;
    border-color: var(--primary-color, #4285f4);
}

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

.pm-toolbar-separator {
    width: 1px;
    background: var(--border-light, #e0e0e0);
    margin: 0 0.25rem;
}

/* ===== STREAMING GENERATION OVERLAY ===== */

.streaming-generation-overlay {
    /* ARCHITECTURE: Progress feedback during LLM generation */
    /* WHY: Users need visual confirmation that generation is active */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    padding: 1.5rem;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
    animation: slideDown 0.3s ease;
}

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

.streaming-generation-overlay.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.streaming-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary, #1a1a1a);
}

.streaming-header i {
    font-size: 1.5rem;
    color: var(--primary-color, #4285f4);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.streaming-progress-container {
    position: relative;
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary, #eeeeee);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.streaming-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color, #4285f4), #0f9d58);
    border-radius: 4px;
    transition: width 0.3s ease;
    animation: shimmer 2s linear infinite;
}

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

.streaming-progress-text {
    position: absolute;
    top: -20px;
    right: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary, #616161);
}

.streaming-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--text-tertiary, #9e9e9e);
    align-items: center;
}

.streaming-stats span {
    font-family: var(--font-mono, 'SF Mono', Monaco, monospace);
}

.streaming-error {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(244, 67, 54, 0.1);
    border-left: 4px solid #f44336;
    border-radius: 4px;
    color: #d32f2f;
    font-weight: 500;
}

.streaming-error i {
    font-size: 1.5rem;
    color: #f44336;
}

/* ===== EDIT BUTTON ===== */

#editBtn {
    /* ARCHITECTURE: Contextual edit button on text selection */
    /* WHY: Matches Quill UX - appears above selection for LLM editing */
    position: absolute;
    z-index: 100;
    padding: 0.5rem 1rem;
    background: var(--primary-color, #4285f4);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    display: none;
}

#editBtn:hover {
    background: #3367d6;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#editBtn::before {
    content: '✏️ ';
}

/* ===== CANCEL BUTTON ===== */

#cancelEditBtn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.75rem 1.5rem;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.4);
    z-index: 1000;
    display: none;
    transition: all 0.2s ease;
}

#cancelEditBtn:hover {
    background: #d32f2f;
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(244, 67, 54, 0.5);
}

/* ===== DARK MODE SUPPORT ===== */

@media (prefers-color-scheme: dark) {
    .ProseMirror {
        background: var(--bg-primary-dark, #1e1e1e);
        color: var(--text-primary-dark, #e0e0e0);
        border-color: var(--border-dark, #424242);
    }

    .ProseMirror h1,
    .ProseMirror h2,
    .ProseMirror h3 {
        color: var(--text-primary-dark, #e0e0e0);
        border-bottom-color: var(--border-dark, #424242);
    }

    .pm-toolbar {
        background: var(--bg-secondary-dark, #2a2a2a);
        border-color: var(--border-dark, #424242);
    }

    .pm-toolbar-button {
        background: var(--bg-primary-dark, #1e1e1e);
        color: var(--text-secondary-dark, #b0b0b0);
        border-color: var(--border-dark, #424242);
    }

    .pm-toolbar-button:hover {
        background: var(--bg-tertiary-dark, #333333);
    }

    .streaming-generation-overlay {
        background: rgba(30, 30, 30, 0.95);
    }
}

/* ===== RESPONSIVE DESIGN ===== */

@media (max-width: 768px) {
    .ProseMirror {
        font-size: 14px;
        padding: 1rem;
    }

    .pm-toolbar {
        padding: 0.5rem;
        gap: 0.25rem;
    }

    .pm-toolbar-button {
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
    }

    #editBtn {
        font-size: 0.85rem;
        padding: 0.4rem 0.8rem;
    }

    #cancelEditBtn {
        bottom: 1rem;
        right: 1rem;
        padding: 0.6rem 1.2rem;
        font-size: 0.85rem;
    }
}
