/**
 * Tiptap Editor — Modern Clinical Editor Styles
 * 
 * ARCHITECTURE: Modern, minimal design inspired by Notion/Linear/Craft
 * FEATURES: Bubble menu, slash commands, focus mode, smooth animations
 */

/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
    /* Typography */
    --tt-font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --tt-font-heading: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --tt-font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
    
    /* Colors - Light mode */
    --tt-bg: #ffffff;
    --tt-bg-subtle: #fafbfc;
    --tt-bg-muted: #f3f4f6;
    --tt-text: #1a1a2e;
    --tt-text-soft: #4a5568;
    --tt-text-muted: #9ca3af;
    --tt-border: #e5e7eb;
    --tt-border-focus: #3b82f6;
    
    /* Accent */
    --tt-accent: #3b82f6;
    --tt-accent-soft: rgba(59, 130, 246, 0.1);
    --tt-accent-hover: #2563eb;
    
    /* Clinical section colors */
    --tt-section-hpi: #3b82f6;
    --tt-section-pe: #8b5cf6;
    --tt-section-assessment: #f59e0b;
    --tt-section-plan: #10b981;
    
    /* Shadows */
    --tt-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --tt-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --tt-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
    --tt-shadow-float: 0 4px 20px rgba(0, 0, 0, 0.15);
    
    /* Animation */
    --tt-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --tt-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    
    /* Spacing */
    --tt-radius: 8px;
    --tt-radius-lg: 12px;
}

/* Dark mode */
[data-theme="dark"] {
    --tt-bg: #0f0f14;
    --tt-bg-subtle: #16161d;
    --tt-bg-muted: #1e1e28;
    --tt-text: #f0f0f5;
    --tt-text-soft: #a0a0b0;
    --tt-text-muted: #6b6b7b;
    --tt-border: #2a2a35;
    --tt-border-focus: #60a5fa;
    --tt-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --tt-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
    --tt-shadow-float: 0 4px 20px rgba(0, 0, 0, 0.5);
}


/* ===== EDITOR CONTAINER ===== */
.tiptap {
    font-family: var(--tt-font-body);
    font-size: 16px;
    line-height: 1.75;
    color: var(--tt-text);
    background: var(--tt-bg);
    
    padding: 2rem 2.5rem;
    min-height: 400px;
    max-height: 70vh;
    overflow-y: auto;
    
    border: 1px solid var(--tt-border);
    border-radius: var(--tt-radius-lg);
    
    outline: none;
    transition: border-color 0.2s var(--tt-ease), box-shadow 0.2s var(--tt-ease);
    
    /* Smooth text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Also target ProseMirror class (Tiptap uses this internally) */
.ProseMirror {
    font-family: var(--tt-font-body);
    font-size: 16px;
    line-height: 1.75;
    color: var(--tt-text);
    background: var(--tt-bg);
    
    padding: 2rem 2.5rem;
    min-height: 400px;
    overflow-y: auto;
    
    border: 1px solid var(--tt-border);
    border-radius: 0 0 var(--tt-radius-lg) var(--tt-radius-lg);
    border-top: none;
    
    outline: none;
    transition: all 0.2s var(--tt-ease);
}

.ProseMirror:focus,
.tiptap:focus {
    border-color: var(--tt-border-focus);
    box-shadow: 0 0 0 3px var(--tt-accent-soft);
}

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


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

.ProseMirror h1,
.ProseMirror h2,
.ProseMirror h3,
.ProseMirror h4 {
    font-family: var(--tt-font-heading);
    font-weight: 600;
    color: var(--tt-text);
    letter-spacing: -0.025em;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.ProseMirror h1 {
    font-size: 1.75rem;
    font-weight: 700;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--tt-border);
}

.ProseMirror h2 {
    font-size: 1.375rem;
    color: var(--tt-text);
    position: relative;
    padding-left: 1rem;
}

/* Accent bar for H2 */
.ProseMirror h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.2em;
    bottom: 0.2em;
    width: 3px;
    background: var(--tt-accent);
    border-radius: 2px;
}

.ProseMirror h3 {
    font-size: 1.125rem;
    color: var(--tt-text-soft);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.ProseMirror h4 {
    font-size: 1rem;
    font-weight: 600;
}

.ProseMirror p {
    margin: 0.75em 0;
}

.ProseMirror strong {
    font-weight: 600;
    color: var(--tt-text);
}

.ProseMirror em {
    font-style: italic;
}

.ProseMirror u {
    text-decoration: underline;
    text-decoration-color: var(--tt-accent);
    text-underline-offset: 3px;
}


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

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

.ProseMirror li {
    margin: 0.25em 0;
    position: relative;
}

.ProseMirror ul > li::marker {
    color: var(--tt-accent);
}

.ProseMirror ol > li::marker {
    color: var(--tt-accent);
    font-weight: 600;
}

.ProseMirror li p {
    margin: 0.125em 0;
}


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

.ProseMirror ::selection {
    background: var(--tt-accent-soft);
}


/* ===== BUBBLE MENU ===== */

.tiptap-bubble-menu {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    
    background: var(--tt-bg);
    border: 1px solid var(--tt-border);
    border-radius: var(--tt-radius);
    box-shadow: var(--tt-shadow-float);
    
    /* Animation */
    animation: bubble-in 0.15s var(--tt-ease-spring);
}

@keyframes bubble-in {
    from {
        opacity: 0;
        transform: translateY(4px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.tiptap-bubble-menu button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    
    background: transparent;
    border: none;
    border-radius: 6px;
    
    color: var(--tt-text-soft);
    font-size: 14px;
    font-weight: 500;
    
    cursor: pointer;
    transition: all 0.15s var(--tt-ease);
}

.tiptap-bubble-menu button:hover {
    background: var(--tt-bg-muted);
    color: var(--tt-text);
}

.tiptap-bubble-menu button.is-active {
    background: var(--tt-accent);
    color: white;
}

.tiptap-bubble-menu button i {
    font-size: 16px;
}

.tiptap-bubble-menu .bubble-separator {
    width: 1px;
    height: 20px;
    background: var(--tt-border);
    margin: 0 4px;
}

/* AI Edit button special styling */
.tiptap-bubble-menu .ai-edit-btn {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    color: white;
    padding: 0 12px;
    margin-left: 4px;
}

.tiptap-bubble-menu .ai-edit-btn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.tiptap-bubble-menu .ai-edit-btn i {
    font-size: 14px;
}


/* ===== SLASH COMMAND MENU ===== */

.tiptap-slash-menu {
    position: fixed;
    z-index: 9999;
    
    width: 280px;
    max-height: 320px;
    overflow-y: auto;
    
    background: var(--tt-bg);
    border: 1px solid var(--tt-border);
    border-radius: var(--tt-radius-lg);
    box-shadow: var(--tt-shadow-lg);
    
    padding: 6px;
    
    /* Animation */
    animation: slash-in 0.2s var(--tt-ease-spring);
}

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

.slash-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    
    padding: 10px 12px;
    border-radius: var(--tt-radius);
    
    cursor: pointer;
    transition: background 0.1s var(--tt-ease);
}

.slash-menu-item:hover,
.slash-menu-item.selected {
    background: var(--tt-bg-muted);
}

.slash-menu-item.selected {
    background: var(--tt-accent-soft);
}

.slash-menu-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    
    width: 36px;
    height: 36px;
    
    background: var(--tt-bg-muted);
    border-radius: var(--tt-radius);
    
    color: var(--tt-text-soft);
    font-size: 18px;
    
    flex-shrink: 0;
}

.slash-menu-item.selected .slash-menu-icon {
    background: var(--tt-accent);
    color: white;
}

.slash-menu-content {
    flex: 1;
    min-width: 0;
}

.slash-menu-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--tt-text);
}

.slash-menu-description {
    font-size: 12px;
    color: var(--tt-text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ===== TOOLBAR (Modern) ===== */

.pm-toolbar,
.tiptap-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    
    background: var(--tt-bg-subtle);
    border: 1px solid var(--tt-border);
    border-bottom: none;
    border-radius: var(--tt-radius-lg) var(--tt-radius-lg) 0 0;
}

.pm-toolbar-button {
    display: flex;
    align-items: center;
    justify-content: center;
    
    width: 32px;
    height: 32px;
    
    background: transparent;
    border: none;
    border-radius: 6px;
    
    color: var(--tt-text-soft);
    font-size: 16px;
    
    cursor: pointer;
    transition: all 0.15s var(--tt-ease);
}

.pm-toolbar-button:hover {
    background: var(--tt-bg-muted);
    color: var(--tt-text);
}

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

.pm-toolbar-separator {
    width: 1px;
    height: 20px;
    background: var(--tt-border);
    margin: 0 6px;
}


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

.streaming-generation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    
    background: var(--tt-bg);
    border-bottom: 1px solid var(--tt-border);
    border-radius: var(--tt-radius-lg) var(--tt-radius-lg) 0 0;
    
    padding: 1.5rem;
    
    animation: slide-down 0.3s var(--tt-ease-spring);
}

@keyframes slide-down {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.streaming-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    
    font-size: 15px;
    font-weight: 600;
    color: var(--tt-text);
}

.streaming-header i {
    font-size: 20px;
    color: var(--tt-accent);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.1); }
}

.streaming-progress-bar {
    height: 4px;
    background: var(--tt-bg-muted);
    border-radius: 2px;
    overflow: hidden;
}

.streaming-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--tt-accent) 0%, #10b981 100%);
    border-radius: 2px;
    transition: width 0.3s var(--tt-ease);
}


/* ===== CLINICAL SECTIONS (Visual Markers) ===== */

.ProseMirror h2[data-section="hpi"]::before { background: var(--tt-section-hpi); }
.ProseMirror h2[data-section="pe"]::before { background: var(--tt-section-pe); }
.ProseMirror h2[data-section="assessment"]::before { background: var(--tt-section-assessment); }
.ProseMirror h2[data-section="plan"]::before { background: var(--tt-section-plan); }


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

.suggestion.insert {
    background: rgba(16, 185, 129, 0.15);
    border-bottom: 2px solid #10b981;
    padding: 1px 2px;
    border-radius: 2px;
}

.suggestion.delete {
    background: rgba(239, 68, 68, 0.15);
    text-decoration: line-through;
    text-decoration-color: #ef4444;
    opacity: 0.8;
}


/* ===== PROVENANCE HIGHLIGHTING ===== */

.provenance-carried_forward {
    background: rgba(156, 163, 175, 0.1);
    border-left: 2px solid #9ca3af;
    padding-left: 4px;
}

.provenance-today_evidence {
    background: rgba(16, 185, 129, 0.1);
    border-left: 2px solid #10b981;
    padding-left: 4px;
}

.provenance-merged {
    background: rgba(59, 130, 246, 0.1);
    border-left: 2px solid #3b82f6;
    padding-left: 4px;
}


/* ===== SCROLLBAR ===== */

.ProseMirror::-webkit-scrollbar {
    width: 8px;
}

.ProseMirror::-webkit-scrollbar-track {
    background: transparent;
}

.ProseMirror::-webkit-scrollbar-thumb {
    background: var(--tt-border);
    border-radius: 4px;
}

.ProseMirror::-webkit-scrollbar-thumb:hover {
    background: var(--tt-text-muted);
}


/* ===== FOCUS MODE ===== */

.ProseMirror.focus-mode {
    max-width: 720px;
    margin: 0 auto;
    padding: 3rem;
}

.ProseMirror.focus-mode::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--tt-bg);
    z-index: -1;
}


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

@media (max-width: 768px) {
    .ProseMirror {
        padding: 1.25rem;
        font-size: 15px;
    }
    
    .tiptap-slash-menu {
        width: 240px;
        left: 16px !important;
        right: 16px !important;
    }
    
    .pm-toolbar {
        padding: 6px 8px;
        gap: 2px;
    }
    
    .pm-toolbar-button {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}


/* ===== SLASH MENU EMPTY STATE ===== */

.slash-menu-empty {
    padding: 16px;
    text-align: center;
    color: var(--tt-text-muted);
    font-size: 13px;
}


/* ===== STREAMING PROGRESS ===== */

.streaming-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--tt-accent) 0%, #10b981 100%);
    border-radius: 2px;
    transition: width 0.3s var(--tt-ease);
    animation: shimmer 2s linear infinite;
    background-size: 200% 100%;
}

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

.streaming-generation-overlay.fade-out {
    animation: fade-out 0.3s var(--tt-ease) forwards;
}

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


/* ===== PRINT ===== */

@media print {
    .tiptap-bubble-menu,
    .tiptap-slash-menu,
    .pm-toolbar,
    .streaming-generation-overlay {
        display: none !important;
    }
    
    .ProseMirror {
        border: none;
        padding: 0;
        font-size: 11pt;
    }
}


/* ===== REDUCED MOTION ===== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
