@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Merriweather:ital,wght@0,300;0,400;0,700;1,400&family=Azeret+Mono:wght@300;400;500;600&display=swap');

:root {
    /* Semantic design tokens - default to Modern Deep Dark (Dark Mode) */
    --bg-base: #121214;
    --bg-surface: #1a1a1e;
    --text-main: #ffffff;
    --text-muted: #a1a1aa;
    --accent: #00ff99;
    --accent-glow: rgba(0, 255, 153, 0.3);
    --border: rgba(255, 255, 255, 0.05);

    /* Legacy mapping for backwards compatibility */
    --nexus-neon: var(--accent);
    --nexus-neon-glow: var(--accent-glow);
    --nexus-bg: var(--bg-base);
    --nexus-card: var(--bg-surface);
    --nexus-text: var(--text-main);
    --nexus-paper: #F9F9F9;
    --nexus-font-sans: 'Inter', sans-serif;
    --nexus-font-serif: 'Merriweather', serif;
    --nexus-font-mono: 'Azeret Mono', monospace;

    /* Global Selection Style Override */
    --nexus-selection: rgba(0, 255, 153, 0.25);
    --nexus-accent: var(--accent);

    /* Graph Nodes Theme Custom Properties (Dark Mode) */
    --nexus-graph-bg: radial-gradient(circle, #1a1a1a 0%, #121212 100%);
    --nexus-graph-link-secondary: rgba(255, 255, 255, 0.2);
    --nexus-graph-link-default: rgba(255, 255, 255, 0.1);
    
    --nexus-node-pill-bg: rgba(20, 20, 20, 0.95);
    
    --nexus-node-rule: #ff4646;
    --nexus-node-rule-bg: rgba(255, 70, 70, 0.1);
    --nexus-node-rule-text: #ff8b8b;
    
    --nexus-node-definition: #ffb03a;
    --nexus-node-definition-bg: rgba(255, 176, 58, 0.1);
    --nexus-node-definition-text: #ffd18c;
    
    --nexus-node-table: #d946ef;
    --nexus-node-table-bg: rgba(217, 70, 239, 0.1);
    --nexus-node-table-text: #f5d0fe;
    
    --nexus-node-section: #3b82f6;
    --nexus-node-section-bg: rgba(59, 130, 246, 0.1);
    --nexus-node-section-text: #93c5fd;
    
    --nexus-node-bridge: #06b6d4;
    --nexus-node-bridge-bg: rgba(6, 182, 212, 0.1);
    --nexus-node-bridge-text: #67e8f9;
    
    --nexus-node-current: var(--nexus-neon);
    --nexus-node-current-bg: rgba(0, 255, 153, 0.15);
    --nexus-node-current-text: #ffffff;
    
    --nexus-node-concept: #00d2c4;
    --nexus-node-concept-bg: rgba(0, 210, 196, 0.05);
    --nexus-node-concept-text: #e0e0e0;
}

::selection,
.ProseMirror ::selection,
.ProseMirror::selection,
.ProseMirror *::selection {
    background-color: var(--nexus-selection) !important;
    color: inherit !important;
}


/* Global Semantic Theme Mapping */
:root {
    --nexus-primary: var(--nexus-neon);
    --nexus-primary-glow: var(--nexus-neon-glow);
    --nexus-primary-hover: #00e688;

    /* Standard Layout Tokens */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Safe Area Insets with fallbacks */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);

    /* Transitions */
    --nexus-transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Glassmorphism with Fallback */
.glass-panel {
    background: rgba(20, 20, 20, 0.85);
    /* Darker fallback for readability */
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@supports (backdrop-filter: blur(10px)) {
    .glass-panel {
        background: rgba(255, 255, 255, 0.03);
        backdrop-filter: blur(10px);
    }
}

/* Unified Enterprise Component Constraints */
.btn-nexus {
    font-family: var(--nexus-font-sans);
    font-weight: 600;
    border-radius: var(--radius-md);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    text-decoration: none;
}

.btn-nexus-primary {
    background: var(--nexus-neon);
    color: #000000;
}

.btn-nexus-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.btn-nexus:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn-nexus-primary:hover {
    box-shadow: 0 4px 15px var(--nexus-primary-glow);
}

.btn-nexus-secondary:hover {
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.05);
}


.theme-dark {
    /* Semantic design tokens - Modern Deep Dark */
    --bg-base: #121214;
    --bg-surface: #1a1a1e;
    --text-main: #ffffff;
    --text-muted: #a1a1aa;
    --accent: #00ff99;
    --accent-glow: rgba(0, 255, 153, 0.3);
    --border: rgba(255, 255, 255, 0.05);

    /* Legacy mapping for backwards compatibility */
    --nexus-bg: var(--bg-base);
    --nexus-card: var(--bg-surface);
    --nexus-text: var(--text-main);
    --nexus-selection: rgba(0, 255, 153, 0.25);
    --nexus-accent: var(--accent);
}

.theme-light {
    /* Semantic design tokens - Warm Paper / Soft Sepia */
    --bg-base: #f4f1ea;
    --bg-surface: #ffffff;
    --text-main: #2d2a26;
    --text-muted: #78716c;
    --accent: #10b981;
    --accent-glow: rgba(16, 185, 129, 0.2);
    --border: rgba(0, 0, 0, 0.08);

    /* Legacy mapping for backwards compatibility */
    --nexus-bg: var(--bg-base);
    --nexus-card: var(--bg-surface);
    --nexus-text: var(--text-main);
    --nexus-selection: rgba(16, 185, 129, 0.18);
    --nexus-accent: var(--accent);

    /* Graph Nodes Theme Custom Properties (Light Mode) */
    --nexus-graph-bg: radial-gradient(circle, #ffffff 0%, #e8e4da 100%);
    --nexus-graph-link-secondary: rgba(0, 0, 0, 0.15);
    --nexus-graph-link-default: rgba(0, 0, 0, 0.08);
    
    --nexus-node-pill-bg: #fbfafa;
    
    --nexus-node-rule: #dc2626;
    --nexus-node-rule-bg: rgba(220, 38, 38, 0.05);
    --nexus-node-rule-text: #991b1b;
    
    --nexus-node-definition: #d97706;
    --nexus-node-definition-bg: rgba(217, 119, 6, 0.05);
    --nexus-node-definition-text: #92400e;
    
    --nexus-node-table: #c084fc;
    --nexus-node-table-bg: rgba(192, 132, 252, 0.05);
    --nexus-node-table-text: #6b21a8;
    
    --nexus-node-section: #2563eb;
    --nexus-node-section-bg: rgba(37, 99, 235, 0.05);
    --nexus-node-section-text: #1e3a8a;
    
    --nexus-node-bridge: #0891b2;
    --nexus-node-bridge-bg: rgba(8, 145, 178, 0.05);
    --nexus-node-bridge-text: #155e75;
    
    --nexus-node-current: #10b981;
    --nexus-node-current-bg: rgba(16, 185, 129, 0.08);
    --nexus-node-current-text: #064e3b;
    
    --nexus-node-concept: #0d9488;
    --nexus-node-concept-bg: rgba(13, 148, 136, 0.03);
    --nexus-node-concept-text: #115e59;
    
    --nexus-accent: #10b981;
}
.theme-light .knowledge-graph-container svg {
    background: radial-gradient(circle, #ffffff 0%, #e8e4da 100%) !important;
}

.theme-light .graph-controls {
    background: rgba(254, 254, 253, 0.4) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.04) !important;
}

.theme-light .zoom-btn {
    background: rgba(0, 0, 0, 0.02) !important;
    border: 1px solid rgba(0, 0, 0, 0.06) !important;
    color: #78716c !important;
}

.theme-light .zoom-btn:hover {
    background: rgba(16, 185, 129, 0.05) !important;
    color: #10b981 !important;
    border-color: #10b981 !important;
}

.theme-light .loading-state {
    color: #292524 !important;
    background: rgba(254, 254, 254, 0.85) !important;
    border: 1px solid rgba(0, 0, 0, 0.05) !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.05) !important;
}

.theme-light .neon-pulse {
    color: #10b981 !important;
    filter: none !important;
    animation: robot-pulse-light 2s infinite ease-in-out !important;
}

.theme-light .scan-line {
    background: #10b981 !important;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5) !important;
}

.theme-light .nexus-node-active {
    stroke: #10b981 !important;
    filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.2)) !important;
}

@keyframes robot-pulse-light {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.theme-light ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

.theme-light ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

.theme-light .glass-panel {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

@supports (backdrop-filter: blur(10px)) {
    .theme-light .glass-panel {
        background: rgba(255, 255, 255, 0.7);
        backdrop-filter: blur(10px);
    }
}

.theme-light .btn-nexus-secondary {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.08);
    color: #292524;
}

.theme-light .btn-nexus-secondary:hover {
    background: rgba(0, 0, 0, 0.08);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}



* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--nexus-bg);
    color: var(--nexus-text);
    font-family: var(--nexus-font-sans);
    margin: 0;
    padding: 0;

    /* Handle Notches */
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);

    min-height: 100vh;
    overflow-x: hidden;
}

body, .reader-canvas, .reader-flow-container, .nexus-mobile-reader-header, .nexus-mobile-chapter-title, .nexus-mobile-escape-btn {
    transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
}

/* Modern Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}


/* Platform Specific Tweaks */
.platform-mobile .nexus-btn {
    min-height: var(--touch-target-size);
    min-width: var(--touch-target-size);
    font-size: 1.1rem;
    padding: 12px 24px;
}

.platform-desktop .nexus-btn {
    min-height: 36px;
    font-size: 0.9rem;
    padding: 8px 16px;
}

/* D3.js Touch Optimization */
svg {
    touch-action: none;
}

h1:focus {
    outline: none;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
    margin: 1rem;
    border-radius: 8px;
}

/* Preloader Styles */
#app-preloader,
.app-preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #1a1a1a 0%, var(--nexus-bg) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.8s ease, visibility 0.8s;
}

#app-preloader.loaded {
    opacity: 0;
    visibility: hidden;
}

.preloader-spinner {
    width: 80px;
    height: 80px;
    border: 3px solid rgba(0, 255, 153, 0.1);
    border-top: 3px solid var(--nexus-neon);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    filter: drop-shadow(0 0 10px var(--nexus-neon));
    margin-bottom: 20px;
}

.preloader-text {
    color: var(--nexus-neon);
    font-family: var(--nexus-font-sans);
    letter-spacing: 4px;
    text-transform: uppercase;
    font-size: 0.8rem;
    font-weight: 500;
    animation: pulse 2s infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.95);
    }
}

/* ==========================================================================
   Selection Pop-up Menu & Crepe Toolbar Unification (SelectionAiPanel Style)
   ========================================================================== */

/* 1. Pop-up Containers (Glassmorphism Capsule) */
.milkdown-popover,
.popover,
.prosemirror-bubble-menu,
.milkdown .popover,
.milkdown-popover.popover,
.milkdown-toolbar {
    background: rgba(24, 24, 28, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-radius: 8px !important;
    padding: 4px 6px !important;
    margin: 0 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 28px rgba(0, 0, 0, 0.4) !important;
    display: inline-flex; /* Removed !important to allow Tippy.js to hide popovers via inline style */
    align-items: center !important;
    gap: 4px !important;
    z-index: 10000 !important;
    box-sizing: border-box !important;
    animation: fadeInScaleGlobal 0.18s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

/* Light Theme (Warm Paper) Overrides for Container */
.theme-light .milkdown-popover,
.theme-light .popover,
.theme-light .prosemirror-bubble-menu,
.theme-light .milkdown .popover,
.theme-light .milkdown-popover.popover,
.theme-light .milkdown-toolbar {
    background: rgba(254, 254, 254, 0.95) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05), 0 10px 30px rgba(0, 0, 0, 0.04) !important;
}

/* 2. Button & Item Formatting (Reader Selection Toolbar Style) */
.milkdown-popover button,
.popover button,
.prosemirror-bubble-menu button,
.milkdown .popover button,
.milkdown-toolbar button {
    text-transform: none !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    color: #e4e4e7 !important; /* zinc-200 */
    background: transparent !important;
    border: none !important;
    padding: 6px 12px !important;
    margin: 0 !important;
    border-radius: 6px !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    gap: 6px !important;
}

/* Crepe's Specific Square Icon-Only Toolbar Items */
.milkdown-toolbar .toolbar-item {
    text-transform: none !important;
    color: #e4e4e7 !important; /* zinc-200 */
    background: transparent !important;
    border: none !important;
    margin: 0 !important;
    border-radius: 6px !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    cursor: pointer !important;
    width: 28px !important;
    height: 28px !important;
    padding: 6px !important;
    display: inline-flex !important;
    justify-content: center !important;
    align-items: center !important;
    box-sizing: border-box !important;
}

/* Icon overrides inside buttons */
.milkdown-popover button svg,
.popover button svg,
.prosemirror-bubble-menu button svg,
.milkdown .popover button svg,
.milkdown-popover button i,
.popover button i,
.prosemirror-bubble-menu button i,
.milkdown .popover button i,
.milkdown-toolbar button svg,
.milkdown-toolbar .toolbar-item svg,
.milkdown-toolbar button i,
.milkdown-toolbar .toolbar-item i {
    color: currentColor !important;
    fill: currentColor !important;
    width: 14px !important;
    height: 14px !important;
}

/* Hover effects (zinc-200 / zinc-100 highlight) */
.milkdown-popover button:hover:not(.active),
.popover button:hover:not(.active),
.prosemirror-bubble-menu button:hover:not(.active),
.milkdown-toolbar button:hover:not(.active),
.milkdown-toolbar .toolbar-item:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
}

/* Active formatting state colors (var(--accent, #00ff99)) */
.milkdown-popover button.active,
.popover button.active,
.prosemirror-bubble-menu button.active,
.milkdown-popover button[aria-pressed="true"],
.popover button[aria-pressed="true"],
.prosemirror-bubble-menu button[aria-pressed="true"],
.milkdown-toolbar button.active,
.milkdown-toolbar .toolbar-item.active,
.milkdown-toolbar button[aria-pressed="true"],
.milkdown-toolbar .toolbar-item[aria-pressed="true"] {
    color: var(--accent, #00ff99) !important;
}

.milkdown-popover button.active:hover,
.popover button.active:hover,
.prosemirror-bubble-menu button.active:hover,
.milkdown-popover button[aria-pressed="true"]:hover,
.popover button[aria-pressed="true"]:hover,
.prosemirror-bubble-menu button[aria-pressed="true"]:hover,
.milkdown-toolbar button.active:hover,
.milkdown-toolbar .toolbar-item.active:hover,
.milkdown-toolbar button[aria-pressed="true"]:hover,
.milkdown-toolbar .toolbar-item[aria-pressed="true"]:hover {
    background: rgba(0, 255, 153, 0.08) !important;
    box-shadow: 0 0 12px rgba(0, 255, 153, 0.15) !important;
    color: var(--accent, #00ff99) !important;
}

/* 3. Light Theme Overrides for Buttons */
.theme-light .milkdown-popover button,
.theme-light .popover button,
.theme-light .prosemirror-bubble-menu button,
.theme-light .milkdown-toolbar button,
.theme-light .milkdown-toolbar .toolbar-item {
    color: #57524e !important;
}

.theme-light .milkdown-popover button:hover:not(.active),
.theme-light .popover button:hover:not(.active),
.theme-light .prosemirror-bubble-menu button:hover:not(.active),
.theme-light .milkdown-toolbar button:hover:not(.active),
.theme-light .milkdown-toolbar .toolbar-item:hover:not(.active) {
    background: rgba(0, 0, 0, 0.04) !important;
    color: #1c1917 !important;
}

.theme-light .milkdown-popover button.active,
.theme-light .popover button.active,
.theme-light .prosemirror-bubble-menu button.active,
.theme-light .milkdown-popover button[aria-pressed="true"],
.theme-light .popover button[aria-pressed="true"],
.theme-light .prosemirror-bubble-menu button[aria-pressed="true"],
.theme-light .milkdown-toolbar button.active,
.theme-light .milkdown-toolbar .toolbar-item.active,
.theme-light .milkdown-toolbar button[aria-pressed="true"],
.theme-light .milkdown-toolbar .toolbar-item[aria-pressed="true"] {
    color: #10b981 !important;
}

.theme-light .milkdown-popover button.active:hover,
.theme-light .popover button.active:hover,
.theme-light .prosemirror-bubble-menu button.active:hover,
.theme-light .milkdown-popover button[aria-pressed="true"]:hover,
.theme-light .popover button[aria-pressed="true"]:hover,
.theme-light .prosemirror-bubble-menu button[aria-pressed="true"]:hover,
.theme-light .milkdown-toolbar button.active:hover,
.theme-light .milkdown-toolbar .toolbar-item.active:hover,
.theme-light .milkdown-toolbar button[aria-pressed="true"]:hover,
.theme-light .milkdown-toolbar .toolbar-item[aria-pressed="true"]:hover {
    background: rgba(16, 185, 129, 0.06) !important;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.1) !important;
    color: #10b981 !important;
}

/* 4. Dividers Alignment */
.milkdown-popover .divider,
.popover .divider,
.prosemirror-bubble-menu .divider,
.milkdown .popover .divider,
.milkdown-toolbar .divider {
    width: 1px !important;
    height: 16px !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
    margin: 0 4px !important;
    border: none !important;
}

.theme-light .milkdown-popover .divider,
.theme-light .popover .divider,
.theme-light .prosemirror-bubble-menu .divider,
.theme-light .milkdown-toolbar .divider {
    background-color: rgba(0, 0, 0, 0.08) !important;
}

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ==========================================================================
   Editor Table & General Control Elements Theming (SelectionAiPanel Style)
   ========================================================================== */

/* 1. Cell Drag Handles (Column and Row Drag Handles) */
.milkdown .milkdown-table-block .cell-handle {
    background-color: rgba(24, 24, 28, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    color: #e4e4e7 !important;
    transition: all 0.2s ease !important;
}

.theme-light .milkdown .milkdown-table-block .cell-handle {
    background-color: rgba(254, 254, 254, 0.95) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    color: #57524e !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
}

.milkdown .milkdown-table-block .cell-handle:hover {
    background-color: rgba(255, 255, 255, 0.15) !important;
    color: #ffffff !important;
    border-color: var(--accent) !important;
}

.theme-light .milkdown .milkdown-table-block .cell-handle:hover {
    background-color: rgba(0, 0, 0, 0.08) !important;
    color: #1c1917 !important;
    border-color: #10b981 !important;
}

.milkdown .milkdown-table-block .cell-handle svg {
    fill: currentColor !important;
    color: currentColor !important;
}

/* 2. Drag Handle Options Popup Menu (.button-group) */
.milkdown .milkdown-table-block .cell-handle .button-group {
    background: rgba(24, 24, 28, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 28px rgba(0, 0, 0, 0.4) !important;
    padding: 4px !important;
    gap: 4px !important;
    display: flex; /* Removed !important to allow toggling via data-show attribute */
}

.theme-light .milkdown .milkdown-table-block .cell-handle .button-group {
    background: rgba(254, 254, 254, 0.95) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05), 0 10px 30px rgba(0, 0, 0, 0.04) !important;
}

.milkdown .milkdown-table-block .cell-handle .button-group button {
    background: transparent !important;
    border: none !important;
    margin: 0 !important;
    border-radius: 6px !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    cursor: pointer !important;
    width: 28px !important;
    height: 28px !important;
    padding: 6px !important;
    display: inline-flex !important;
    justify-content: center !important;
    align-items: center !important;
    box-sizing: border-box !important;
    color: #e4e4e7 !important;
}

.theme-light .milkdown .milkdown-table-block .cell-handle .button-group button {
    color: #57524e !important;
}

.milkdown .milkdown-table-block .cell-handle .button-group button:hover {
    background: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
}

.theme-light .milkdown .milkdown-table-block .cell-handle .button-group button:hover {
    background: rgba(0, 0, 0, 0.04) !important;
    color: #1c1917 !important;
}

.milkdown .milkdown-table-block .cell-handle .button-group button:active {
    background: rgba(0, 255, 153, 0.08) !important;
    color: var(--accent, #00ff99) !important;
}

.theme-light .milkdown .milkdown-table-block .cell-handle .button-group button:active {
    background: rgba(16, 185, 129, 0.06) !important;
    color: #10b981 !important;
}

.milkdown .milkdown-table-block .cell-handle .button-group button svg {
    color: currentColor !important;
    fill: currentColor !important;
    width: 14px !important;
    height: 14px !important;
}

/* 3. Table Column/Row Insertion Lines & Add Buttons */
.milkdown .milkdown-table-block .line-handle {
    background-color: var(--accent) !important;
}

.theme-light .milkdown .milkdown-table-block .line-handle {
    background-color: #10b981 !important;
}

.milkdown .milkdown-table-block .line-handle .add-button {
    background-color: rgba(24, 24, 28, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    color: #e4e4e7 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.theme-light .milkdown .milkdown-table-block .line-handle .add-button {
    background-color: rgba(254, 254, 254, 0.95) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    color: #57524e !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
}

.milkdown .milkdown-table-block .line-handle .add-button:hover {
    background-color: rgba(255, 255, 255, 0.15) !important;
    color: #ffffff !important;
    border-color: var(--accent) !important;
}

.theme-light .milkdown .milkdown-table-block .line-handle .add-button:hover {
    background-color: rgba(0, 0, 0, 0.08) !important;
    color: #1c1917 !important;
    border-color: #10b981 !important;
}

.milkdown .milkdown-table-block .line-handle .add-button svg {
    width: 12px !important;
    height: 12px !important;
    color: currentColor !important;
    fill: currentColor !important;
}

/* 4. Paragraph Block Drag Handles */
.milkdown .milkdown-block-handle {
    background-color: rgba(24, 24, 28, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-radius: 6px !important;
    padding: 2px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    display: flex; /* Removed !important to allow toggling */
    gap: 2px !important;
}

.theme-light .milkdown .milkdown-block-handle {
    background-color: rgba(254, 254, 254, 0.95) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
}

.milkdown .milkdown-block-handle .operation-item {
    border-radius: 4px !important;
    width: 24px !important;
    height: 24px !important;
    padding: 4px !important;
    display: inline-flex !important;
    justify-content: center !important;
    align-items: center !important;
    color: #e4e4e7 !important;
    transition: all 0.2s ease !important;
}

.theme-light .milkdown .milkdown-block-handle .operation-item {
    color: #57524e !important;
}

.milkdown .milkdown-block-handle .operation-item:hover {
    background: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
}

.theme-light .milkdown .milkdown-block-handle .operation-item:hover {
    background: rgba(0, 0, 0, 0.04) !important;
    color: #1c1917 !important;
}

.milkdown .milkdown-block-handle .operation-item.active {
    background: rgba(0, 255, 153, 0.08) !important;
    color: var(--accent, #00ff99) !important;
}

.theme-light .milkdown .milkdown-block-handle .operation-item.active {
    background: rgba(16, 185, 129, 0.06) !important;
    color: #10b981 !important;
}

.milkdown .milkdown-block-handle .operation-item svg {
    width: 14px !important;
    height: 14px !important;
    fill: currentColor !important;
    color: currentColor !important;
}

/* 5. Slash Commands Menu */
.milkdown .milkdown-slash-menu {
    background: rgba(24, 24, 28, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 28px rgba(0, 0, 0, 0.4) !important;
    font-family: var(--nexus-font-sans) !important;
    color: #ffffff !important;
}

.theme-light .milkdown .milkdown-slash-menu {
    background: rgba(254, 254, 254, 0.95) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05), 0 10px 30px rgba(0, 0, 0, 0.04) !important;
    color: #2d2a26 !important;
}

.milkdown .milkdown-slash-menu .tab-group ul li {
    color: #a1a1aa !important;
    border-radius: 6px !important;
    transition: all 0.2s ease !important;
}

.theme-light .milkdown .milkdown-slash-menu .tab-group ul li {
    color: #78716c !important;
}

.milkdown .milkdown-slash-menu .tab-group ul li:hover {
    background: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
}

.theme-light .milkdown .milkdown-slash-menu .tab-group ul li:hover {
    background: rgba(0, 0, 0, 0.04) !important;
    color: #1c1917 !important;
}

.milkdown .milkdown-slash-menu .tab-group ul li.selected {
    background: rgba(0, 255, 153, 0.08) !important;
    color: var(--accent) !important;
}

.theme-light .milkdown .milkdown-slash-menu .tab-group ul li.selected {
    background: rgba(16, 185, 129, 0.06) !important;
    color: #10b981 !important;
}

.milkdown .milkdown-slash-menu .menu-groups .menu-group li {
    color: #e4e4e7 !important;
    border-radius: 6px !important;
    transition: all 0.2s ease !important;
}

.theme-light .milkdown .milkdown-slash-menu .menu-groups .menu-group li {
    color: #57524e !important;
}

.milkdown .milkdown-slash-menu .menu-groups .menu-group li svg {
    color: #a1a1aa !important;
    fill: #a1a1aa !important;
}

.theme-light .milkdown .milkdown-slash-menu .menu-groups .menu-group li svg {
    color: #78716c !important;
    fill: #78716c !important;
}

.milkdown .milkdown-slash-menu .menu-groups .menu-group li.hover {
    background: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
}

.theme-light .milkdown .milkdown-slash-menu .menu-groups .menu-group li.hover {
    background: rgba(0, 0, 0, 0.04) !important;
    color: #1c1917 !important;
}

.milkdown .milkdown-slash-menu .menu-groups .menu-group li.active {
    background: rgba(0, 255, 153, 0.08) !important;
    color: var(--accent) !important;
}

.theme-light .milkdown .milkdown-slash-menu .menu-groups .menu-group li.active {
    background: rgba(16, 185, 129, 0.06) !important;
    color: #10b981 !important;
}

.milkdown .milkdown-slash-menu .menu-groups .menu-group li.active svg {
    color: var(--accent) !important;
    fill: var(--accent) !important;
}

.theme-light .milkdown .milkdown-slash-menu .menu-groups .menu-group li.active svg {
    color: #10b981 !important;
    fill: #10b981 !important;
}

/* 6. Explicit Visibility State Overrides */
.milkdown-popover[data-show="false"],
.popover[data-show="false"],
.prosemirror-bubble-menu[data-show="false"],
.milkdown-toolbar[data-show="false"],
.milkdown-slash-menu[data-show="false"],
.milkdown-table-block .cell-handle .button-group[data-show="false"],
.milkdown-link-preview[data-show="false"],
.milkdown-link-edit[data-show="false"] {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* 7. Table Overflow Clipping Fix for Handles */
.milkdown .tableWrapper {
    overflow: visible !important;
}

