/* public/typography.css */
@import url('https://rsms.me/inter/inter.css');
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Fuzzy+Bubbles:wght@400;700&display=swap');

/* Lab Mono Font */
@font-face {
    font-family: 'Lab Mono';
    src: url('./lib/fonts/custom-fonts/LabMono-Regular.woff2') format('woff2'),
         url('./lib/fonts/custom-fonts/LabMono-Regular.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* Typography Theme - SUPRB Sans Typography System */

/* ========== CRISP FONT RENDERING ========== */
/* Apply font smoothing only to text elements to avoid canvas interference */
body, 
.text-item, 
.document-editor-content, 
.toolbar, 
.help-modal-content,
.selection-toolbar,
h1, h2, h3, h4, h5, h6,
button, 
input, 
select, 
textarea {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.2;
}

/* Optimize text rendering for different zoom levels */
html {
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
}

/* Force subpixel positioning for maximum sharpness - only for text elements */
.text-item .rich-text-editor,
.document-editor-content {
    transform: translateZ(0);
    will-change: transform;
}

/* ========== TYPOGRAPHY OVERRIDES ========== */
:root {
    /* Override main font */
    --font-main: 'InterVariable', 'Inter', sans-serif;
 

    
    /* Fine-tune font weights to match SUPRB Sans */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;
    --font-black: 900;
    
    /* Keep book weight for backwards compatibility */
    --font-book: 400;
    --font-light: 400; /* Use regular as lightest */
    
    /* Font sizes - multiplier-based system using existing variable names */
    --font-size-base: 16px; /* Base font size */
    --font-size-scale: 1.125; /* Perfect fourth scale (1.125) */
    /*
      - 1.125 = Perfect fourth (current)
      - 1.2 = Minor third
      - 1.333 = Perfect fourth
      - 1.414 = Augmented fourth
      - 1.5 = Perfect fifth
      - 1.618 = Golden ratio
    */
    
    /* Override existing styles.css variables with calculated values */
    --text-xs: calc(var(--font-size-base) * 0.714); /* ~10px */
    --text-sm: calc(var(--font-size-base) * 0.857); /* ~12px */
    --text-base: var(--font-size-base); /* 14px */
    --text-md: calc(var(--font-size-base) * 1.143); /* ~16px */
    --text-lg: calc(var(--font-size-base) * 1.429); /* ~20px */
    --text-xl: calc(var(--font-size-base) * var(--font-size-scale) * 3); /* ~48px */
    
    /* Extended sizes for better hierarchy */
    --text-2xl: calc(var(--font-size-base) * var(--font-size-scale) * 2); /* ~32px */
    --text-3xl: calc(var(--font-size-base) * var(--font-size-scale) * 1.75); /* ~28px */
    --text-4xl: calc(var(--font-size-base) * var(--font-size-scale) * 1.5); /* ~24px */
    
    /* Enable ss03 stylistic set */
     /*--font-features: "ss03" 1, "cv11" 1, "dlig" 1, "tnum" 1, "zero" 1;*/

}

/** {
    font-family: var(--font-main) !important;
    font-weight: var(--font-normal);
    font-size: var(--text-base) !important;
    font-feature-settings: var(--font-features) !important;

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-variant-ligatures: common-ligatures;
    font-kerning: auto;
    font-optical-sizing: auto;
}*/

/* ========== GLOBAL FONT APPLICATION ========== */
body {
    font-family: var(--font-main);
    font-weight: var(--font-normal);
    font-size: var(--text-base);
    font-feature-settings: var(--font-features);

    text-rendering: optimizeLegibility;
    font-variant-ligatures: common-ligatures;
    font-kerning: normal;
    
    /* Enhanced font rendering for crisp text */
   /* -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-variant-ligatures: common-ligatures;
    font-kerning: auto;
    font-optical-sizing: auto;*/
    /*letter-spacing: -0.01em;*/
}

/* Text items */
.text-item .rich-text-editor,
.text-item .rich-text-editor * {
    font-family: var(--font-main);
    font-size: var(--text-base);
    font-feature-settings: var(--font-features);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Document modal */
.document-editor-content,
.document-editor-content * {
    font-family: var(--font-main);
    /*font-size: var(--text-base);*/
    font-feature-settings: var(--font-features);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-main);
    font-feature-settings: var(--font-features);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1 {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
}

h2 {
    font-size: var(--text-2xl);
    font-weight: var(--font-semibold);
}

h3 {
    font-size: var(--text-3xl);
    font-weight: var(--font-medium);
}

h4 {
    font-size: var(--text-4xl);
    font-weight: var(--font-medium);
}

h5 {
    font-size: var(--text-lg);
    font-weight: var(--font-medium);
}

h6 {
    font-size: var(--text-md);
    font-weight: var(--font-medium);
}

/* Toolbar and UI elements */
.toolbar,
.tool-btn,
.tool-select,
button,
input,
select,
textarea {
    font-family: var(--font-main);
    font-size: var(--text-base);
    font-feature-settings: var(--font-features);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Text size controls */
.text-size-s { 
    font-weight: var(--font-light);
    font-size: var(--text-sm);
}
.text-size-m { 
    font-weight: var(--font-normal);
    font-size: var(--text-base);
}
.text-size-l { 
    font-weight: var(--font-medium);
    font-size: var(--text-md);
}

/* Logic nodes */
.logic-node,
.logic-node * {
    font-family: var(--font-main);
    font-size: var(--text-sm);
    font-feature-settings: var(--font-features);
}

/* Help modal */
.help-modal-content,
.help-modal-content * {
    font-family: var(--font-main);
    font-size: var(--text-base);
    font-feature-settings: var(--font-features);
}

/* Selection toolbar */
.selection-toolbar,
.selection-toolbar * {
    font-family: var(--font-main);
    font-size: var(--text-sm);
    font-feature-settings: var(--font-features);
}

/* Make light text more readable */
.text-item .rich-text-editor p {
    font-weight: var(--font-book);
}

/* Stronger emphasis for important UI elements */
.toolbar .tool-btn {
    font-weight: var(--font-medium);
}

.help-modal-content h2 {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
}

.help-modal-content h3 {
    font-size: var(--text-3xl);
    font-weight: var(--font-semibold);
}

/* Fine-tune document editor typography */
.document-editor-content p {
    font-weight: var(--font-book);
}

.document-editor-content h1 {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
}

.document-editor-content h2 {
    font-size: var(--text-2xl);
    font-weight: var(--font-semibold);
}

.document-editor-content h3 {
    font-size: var(--text-3xl);
    font-weight: var(--font-medium);
}

.document-editor-content strong {
    font-weight: var(--font-bold);
}

.document-editor-content em {
    font-style: italic;
}

/* Improve readability for smaller text */
.storage-indicator,
.zoom-indicator,
.position-indicators {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}




.notion-editor-container h1, 
h1.editor-block, 
.notion-editor-container h1.editor-block,
.notion-editor-container h2, 
h2.editor-block, 
.notion-editor-container h2.editor-block,
.notion-editor-container h3, 
h3.editor-block, 
.notion-editor-container h3.editor-block {
    margin: 0 !important;
    padding: 0 !important;
}

/* ========== CUSTOM FONT CLASSES ========== */
/* Font family classes for text items */
.text-item.font-inter .rich-text-editor,
.text-item.font-inter .rich-text-editor *,
.text-item.font-inter .notion-editor-container,
.text-item.font-inter .notion-editor-container *,
.text-item.font-inter .editor-block {
    font-family: 'InterVariable', 'Inter', sans-serif !important;
}

.text-item.font-source-serif .rich-text-editor,
.text-item.font-source-serif .rich-text-editor *,
.text-item.font-source-serif .notion-editor-container,
.text-item.font-source-serif .notion-editor-container *,
.text-item.font-source-serif .editor-block {
    font-family: 'Source Serif 4', serif !important;
}

.text-item.font-fuzzy-bubbles .rich-text-editor,
.text-item.font-fuzzy-bubbles .rich-text-editor *,
.text-item.font-fuzzy-bubbles .notion-editor-container,
.text-item.font-fuzzy-bubbles .notion-editor-container *,
.text-item.font-fuzzy-bubbles .editor-block {
    font-family: 'Fuzzy Bubbles', cursive !important;
}

.text-item.font-lab-mono .rich-text-editor,
.text-item.font-lab-mono .rich-text-editor *,
.text-item.font-lab-mono .notion-editor-container,
.text-item.font-lab-mono .notion-editor-container *,
.text-item.font-lab-mono .editor-block {
    font-family: 'Lab Mono', monospace !important;
}

/* public/styles.css */
/* Electron draggable title bar */
.electron-drag-region {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 32px;
    -webkit-app-region: drag;
    z-index: 9999;
    pointer-events: none;
    background: transparent;
}

/* Make buttons and interactive elements non-draggable within the drag region */
.electron-drag-region * {
    -webkit-app-region: no-drag;
    pointer-events: auto;
}

/* Adjust body padding for transparent title bar */
body.electron-app {
    padding-top: 32px;
}

:root {
    /* ========== TYPOGRAPHY ========== */
   
    /* Font weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Line heights */
    --leading-tight: 1.2;
    --leading-normal: 1.4;  /* Main text line height */
    --leading-relaxed: 1.8;

 
     /* ========== GRID SYSTEM ========== */
    /* Base grid unit derived from text line height */
    --text-line-height: calc(var(--text-base) * var(--leading-normal)); /* 14px * 1.4 = 19.6px */
    --grid-base-unit: 24px; /* Slightly larger than one line for good spacing */

    /* ========== SPACING ========== */
    --space-xs: calc(var(--grid-base-unit) * 0.5);
    --space-sm: calc(var(--grid-base-unit) * 0.75);
    --space-md: var(--grid-base-unit); /* 24px - now grid-aligned */
    --space-lg: calc(var(--grid-base-unit) * 1.5); /* 36px */
    --space-xl: calc(var(--grid-base-unit) * 2); /* 48px */


    /* ========== COLORS ========== */
    /* Base colors - Light mode */
    --color-bw: #ffffff;
    --color-bg: #f5f5f5;
    --color-fg: #111111;
    --color-muted: #666666;
    --color-border: #e0e0e0;
    --color-accent: #0066cc;
    --color-danger: #dc2626;
    --color-grid: rgba(0,0,0, 0.2);
    
    /* Surface hierarchy - Light mode */
    --color-surface-1: #f5f5f5;  /* viewport bg */
    --color-surface-2: #eeeeee;  /* link item bg */
    --color-surface-3: #23241f;  /* code item bg - stays dark */
    --color-surface-4: #000000;  /* embed item bg - stays dark */
    
    /* Text hierarchy - Light mode */
    --color-text-primary: #111111;
    --color-text-secondary: #666666;
    --color-text-muted: #999999;
    
    /* Interactive states - Light mode */
    --color-hover: rgba(0, 0, 0, 0.05);
    --color-active: rgba(0, 0, 0, 0.1);
    --color-selected: rgba(0,0,0, 0.1);
    --color-multi-selected: rgba(0, 102, 204, 0.8);

/* ========== UNIFIED DROPDOWN MENU SYSTEM ========== */
/* Unified hover states for all dropdown/menu items */
.logic-node-option:hover,
.context-menu-item:hover,
.slash-menu-item:hover,
.slash-menu-item.selected,
.prisma-slash-menu-item:hover,
.prisma-slash-menu-item.selected {
    background-color: var(--color-hover) !important;
    border: none !important;
    box-shadow: none !important;
    transform: none !important;
    opacity: 1 !important;
    color: inherit !important;
}

/* Reset any existing transforms/effects */
.context-menu-item:hover {
    transform: none !important;
}

.prisma-slash-menu-item:hover {
    transform: none !important;
}

.slash-menu-item:hover,
.slash-menu-item.selected {
    opacity: 1 !important;
}

.logic-node-option:hover {
    opacity: 1 !important;
}

/* NotionStyleEditor padding fix */
.notion-editor-container .notion-editor-container {
    padding: 0;
}

    /* ========== LAYOUT ========== */
    /* Component sizes */
    --toolbar-height: 48px;
    --canvas-size: 5000px;
    --viewport-top: var(--toolbar-height);
    
    /* Item dimensions */
    --item-min-width: 50px;
    --item-min-height: 50px;
    --text-item-min-width: 100px;
    --code-item-min-width: 300px;
    --item-padding: var(--space-md);
    
    /* Interactive elements */
    --btn-height: 36px;
    --btn-padding-x: var(--space-md);
    --btn-padding-y: var(--space-sm);
    --toolbar-btn-size: 28px;
    --delete-btn-size: 20px;
    --resize-handle-size: 16px;
    
    /* ========== BORDERS & RADIUS ========== */
    --border-width: 1px;
    --border-style: solid;
    --border: var(--border-width) var(--border-style) var(--color-border);
    
    /* Border radius */
    --radius-sm: 3px;
    --radius-md: 6px;
    --radius-lg: 12px;
    --radius-item: 12px;
    --radius-full: 50%;
    
    /* ========== EFFECTS ========== */
    /* Opacity states */
    --opacity-hover: 1;
    --opacity-dragging: 0.8;
    --opacity-disabled: 0.5;
    --opacity-muted: 0.5;
    
    /* Z-index layers */
    --z-base: 1;
    --z-overlay: 2;
    --z-selected: 100;
    --z-dragging: 101;
    --z-toolbar: 1000;
    --z-dropdown: 1001;
    
    /* Transitions */
    --transition-fast: 0ms ease;
    --transition-normal: 0ms ease;
    
    /* Code editor colors - constant in both themes */
    --code-bg: #23241f;
    --code-text: #d4d4d4;
    --code-keyword: #569cd6;
    --code-string: #ce9178;
    --code-comment: #6a9955;
    --code-number: #b5cea8;
    --code-function: #dcdcaa;

      
    /* ========== LAYOUT ========== */
    
    /* Item dimensions - grid-aligned */
    --item-min-width: calc(var(--grid-base-unit) * 4); /* 96px */
    --item-min-height: calc(var(--grid-base-unit) * 2); /* 48px */
    --text-item-min-width: calc(var(--grid-base-unit) * 2); /* 192px */
    --code-item-min-width: calc(var(--grid-base-unit) * 12); /* 288px */
    --item-padding: calc(var(--grid-base-unit) * 0.75); /* 18px - close to 16px but grid-aligned */

    --color-bg-tertiary: rgba(255,255,255,0.05);
}


/* Dark mode - Perfectly inverted with same contrast ratios */
body.dark-theme {
    /* Inverted base colors */
    --color-bw: #000000;
    --color-bg: #111111;
    --color-fg: #ffffff;
    --color-muted: #999999;
    --color-border: #2a2a2a;
    --color-accent: #4d94ff;
    --color-danger: #ef4444;
    --color-grid: rgba(255,255,255, 0.1);
    
    /* Inverted surface hierarchy */
    --color-surface-1: #0a0a0a;
    --color-surface-2: #1a1a1a;
    /* --color-surface-3 and --color-surface-4 stay the same */
    
    /* Inverted text hierarchy */
    --color-text-primary: #ffffff;
    --color-text-secondary: #999999;
    --color-text-muted: #666666;
    
    /* Inverted interactive states */
    --color-hover: rgba(255, 255, 255, 0.05);
    --color-active: rgba(255, 255, 255, 0.1);
    --color-selected: rgba(255,255,255, 0.25);
    --color-multi-selected: rgba(77, 148, 255, 0.8);

    --border: var(--border-width) var(--border-style) var(--color-border);
}

/* ========== GLOBAL STYLES ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}



/* Global performance optimizations */
html {
    /* Optimize font rendering */
 /*   -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeSpeed;*/
}

body {
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
    font: var(--text-base)/var(--leading-normal) var(--font-main);
    background: var(--color-bg);
    color: var(--color-fg);
    overflow: hidden;
    transition: background-color var(--transition-normal), 
                color var(--transition-normal);
}

* {
    cursor: url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" width="22" height="22" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.50001 4.07491C0.897091 2.46714 2.46715 0.897094 4.07491 1.50001L21.2155 7.92774C23.1217 8.64256 22.8657 11.4162 20.8609 11.77L13.1336 13.1336L11.77 20.8609C11.4162 22.8657 8.64255 23.1217 7.92774 21.2155L1.50001 4.07491ZM3.37267 3.37267L9.8004 20.5133L11.164 12.786C11.3101 11.9582 11.9582 11.3101 12.786 11.164L20.5133 9.8004L3.37267 3.37267Z" fill="%230F0F0F"/><path d="M3.37267 3.37267L9.8004 20.5133L11.164 12.786C11.3101 11.9582 11.9582 11.3101 12.786 11.164L20.5133 9.8004L3.37267 3.37267Z" fill="white"/></svg>') 1 1, auto !important;
}
/* Cursor handled by blur-cursor.js */

/* ========== TOOLBAR ========== */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--toolbar-height);
    background: var(--color-bg);
    border-bottom: var(--border);
    display: flex;
    align-items: center;
    padding: 0 var(--space-md);
    gap: var(--space-sm);
    z-index: var(--z-toolbar);
    transition: background-color var(--transition-normal),
                border-color var(--transition-normal);
    /* Safe GPU acceleration for toolbar */
    will-change: background-color, border-color;
    transform: translateZ(0);
}

/* Toolbar buttons */
.tool-btn,
.tool-select {
    height: var(--btn-height);
    padding: var(--btn-padding-y) var(--btn-padding-x);
    background: transparent;
    color: var(--color-fg);
    border: var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font: inherit;
    transition: all var(--transition-fast);
}

.tool-btn:hover,
.tool-select:hover {
    background: var(--color-hover);
    border-color: var(--color-muted);
}

.tool-btn:active {
    background: var(--color-muted);
}

.tool-btn.danger {
    color: var(--color-danger);
}

.tool-btn.danger:hover {
    background: var(--color-danger);
    color: white;
    border-color: var(--color-danger);
}

/* Drawing mode styles */
.tool-btn.active {
    /*background: var(--color-accent);*/
    color:  var(--color-accent);
    
}

/* Tool drag preview */
.tool-drag-preview {
    position: absolute;
    border: 2px dashed var(--color-accent);
    background: rgba(0, 102, 204, 0.1);
    pointer-events: none;
    z-index: 1000;
    border-radius: var(--radius-lg);
}

.line-item {
    pointer-events: none !important; /* Disable all pointer events on container */
    background: transparent !important; /* Force transparent background */
    border: none !important; /* Remove any inherited borders */
}

/* Disable pointer events on SVG container but enable on paths */
.line-item svg {
    pointer-events: none !important;
    cursor: default;
    overflow: visible !important;
}

.line-item svg path {
    pointer-events: auto !important;
    cursor: move;
}

/* Disable drag overlay for line items completely */
.line-item .drag-overlay {
    pointer-events: none !important;
    display: none !important;
}

/* Ensure all other children of line-item are not clickable */
.line-item * {
    pointer-events: none !important;
}

/* Re-enable pointer events only for path elements */
.line-item svg path {
    pointer-events: auto !important;
}



.line-item.selected svg,
.line-item.selected .drag-overlay,
.line-item.selected * {
    pointer-events: auto !important;
}






/* Keep delete button clickable */
.line-item .delete-btn {
    pointer-events: auto !important;
    cursor: pointer;
}

.line-selection-overlay {
    background: transparent;
    pointer-events: all;
    border-radius: var(--radius-md);
}

/* Override selection styling for line items */
.line-item.selected,    
.line-item.multi-selected  {
    border-color: transparent !important; /* Remove container border */
    background: transparent !important; /* Remove container background */
}

/*.line-item.selected svg path {
    filter: drop-shadow(0 0 calc(1px / var(--zoom-scale, 0.5)) var(--color-accent)) drop-shadow(0 0 calc(1px / var(--zoom-scale, 0.5)) var(--color-accent));
    stroke-width: calc(var(--stroke-width, 6) + 1) !important;
}

.line-item.multi-selected svg path {
    filter: drop-shadow(0 0 calc(1px / var(--zoom-scale, 0.5)) var(--color-multi-selected)) drop-shadow(0 0 calc(1px / var(--zoom-scale, 0.5)) var(--color-multi-selected));
    stroke-width: calc(var(--stroke-width, 6) + 1) !important;
}*/


/*.canvas-item:hover:not(.section-container) {
    border-color: transparent !important;
    box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) var(--color-selected) !important;
}*/

/* Disable hover effects during drawing mode */
.drawing-mode-active .canvas-item:hover {
    transform: none !important;
    box-shadow: none !important;
    background: transparent !important;
    border-color: transparent !important;
}

/* Specifically disable hover border for line items during drawing mode */
.drawing-mode-active .canvas-item.line-item:hover:not(.section-container) {
    border-color: transparent !important;
}

/* Hide line selection overlay only while actively drawing */
body.actively-drawing .line-selection-overlay {
    pointer-events: none !important;
    opacity: 0 !important;
    display: none !important;
}

/* Hide hover effects on line items only while actively drawing */
body.actively-drawing .canvas-item.line-item:hover {
    box-shadow: none !important;
}

.drawing-mode-active .delete-btn {
    opacity: 0 !important;
}

.drawing-mode-active .resize-handle {
    opacity: 0 !important;
}

/* Disable connection and port hover effects during drawing mode */
.drawing-mode-active .canvas-item:hover .connection-port,
.drawing-mode-active .section-container > .canvas-item:hover .connection-port,
.drawing-mode-active .logic-item:hover .connection-port {
    opacity: 0 !important;
}

.drawing-mode-active .connection-port:hover {
    opacity: 0 !important;
    transform: none !important;
}

.drawing-mode-active .connection-line:hover {
    stroke-width: inherit !important;
    opacity: inherit !important;
}

.drawing-mode-active .connection-port.port-hover-valid .port-dot,
.drawing-mode-active .connection-port.port-hover-invalid .port-dot {
    transform: none !important;
    background: inherit !important;
    box-shadow: none !important;
}

/* Drawing controls styling */
.drawing-controls {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.opacity-slider {
    width: 80px;
    height: 20px;
    background: #ddd;
    outline: none;
    border-radius: 10px;
    -webkit-appearance: none;
}

.opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-accent);
    cursor: pointer;
}

.opacity-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-accent);
    cursor: pointer;
    border: none;
}

.opacity-label {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    min-width: 35px;
    text-align: center;
}

#themeToggle {
    width: var(--btn-height);
    /*padding: var(--btn-padding-y);*/
    font-size: 18px;
}

.zoom-level {
    margin-left: auto;
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
}

.tool-btn .item-counter {
    position: absolute;
    /*top: -8px;*/
    left: 19px;
    color: var(--color-danger);
   
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    display: none;
}

.tool-btn .item-counter:not(:empty) {
    display: block;
}

.tool-btn.danger {
    position: relative;
    width: auto;
    min-width: 32px;
}

/* ========== VIEWPORT & CANVAS ========== */
#viewport {
    position: fixed;
    top: var(--viewport-top);
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-surface-1);
    cursor: grab;
    overflow: hidden;
    transition: background-color var(--transition-normal);
    overscroll-behavior: none;
    touch-action: none; /* This prevents all default touch behaviors */
    /* Safe GPU acceleration for viewport */
    will-change: scroll-position;
    transform: translateZ(0);
}

#viewport.grabbing {
    cursor: grabbing;
}

#canvas {
    width: var(--canvas-size);
    height: var(--canvas-size);
    background: var(--color-bg);
    transform-origin: 0 0;
    position: relative;
    transition: background-color var(--transition-normal);
    /* Safe GPU acceleration for canvas */
    will-change: transform;
    transform: translateZ(0);
}

/* ========== CANVAS ITEMS - Base ========== */
.canvas-item {
    position: absolute;
    background: var(--color-bg);
    border: var(--border);
    border-radius: var(--radius-lg);
    padding: var(--item-padding);
    /*cursor: move;*/
    user-select: none;
    min-width: var(--item-min-width);
    min-height: var(--item-min-height);
    transition: border-color 0s,
                background-color var(--transition-normal);
    border-width: calc(1px / var(--zoom-scale, 1));
    /* Safe GPU acceleration for canvas items */
    will-change: transform, opacity;
    transform: translateZ(0);
}

/* Only apply hover styles to items on canvas, not when hovering section containers */
/* DISABLED: These were causing items to move on hover
.canvas-item:hover:not(.section-container) {
    border-color: var(--color-text-secondary);
}

/* For section containers, only apply hover to direct children */
/* .section-container > .canvas-item:hover {
    border-color: var(--color-text-secondary);
} */

/* Canvas item states */
.canvas-item.selected {
    border-color: var(--color-accent);
    /*background: var(--color-selected);*/
    /* z-index handled by JavaScript */
    /*border-width: calc(1px / var(--zoom-scale, 1));*/
}

/* Hide individual selection styling when unified selection is active */
.canvas-item.multi-selected {
    /* Remove individual selection styling for cleaner unified selection */
}

.canvas-item.dragging {
    opacity: var(--opacity-dragging);
    /* z-index handled by JavaScript */
    transition: none;
    /* GPU acceleration for dragging */
}

.canvas-item.dragging,
.canvas-item.dragging *,
.canvas-item.selected.dragging,
.canvas-item.selected.dragging *,
body.dragging-multiple .canvas-item,
body.dragging-multiple .canvas-item * {
    transition: none !important;
    animation: none !important;
}

.canvas-item.preparing-drag {
    animation: pulse 0.3s ease-in-out;
}

.canvas-item.drag-ready {
    opacity: var(--opacity-dragging);
}

/* Canvas item overlays */
.shift-hover-overlay,
.multi-select-overlay {
    position: absolute;
    inset: 0;
    z-index: var(--z-overlay);
    /*cursor: pointer;*/
    background: transparent;
}

.multi-select-overlay {
    /*cursor: move;*/
}

/* Image item specific multi-select */
.image-item.multi-selected {
    /*position: relative;*/
}

.image-item .multi-select-overlay {
    border-radius: var(--radius-lg); /* Match the image border radius */
    /*background: var(--color-selected);*/
}

/* Ensure overlay works with padding: 0 items */
.image-item .multi-select-overlay,
.embed-item .multi-select-overlay,
.link-item .multi-select-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-overlay);
}

body.shift-held .canvas-item:hover .shift-hover-overlay {
    pointer-events: all;
}



/* Disable interactivity when multi-selected */
.canvas-item.multi-selected iframe,
.canvas-item.multi-selected [contenteditable],
.canvas-item.multi-selected a,
.canvas-item.multi-selected .rich-text-editor,
.canvas-item.multi-selected .ql-editor {
    pointer-events: none !important;
    user-select: none;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: var(--resize-handle-size);
    height: var(--resize-handle-size);
    cursor: nwse-resize;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 1000000000000;
    transform: scale(calc(1 / var(--zoom-scale, 1)));
    will-change: transform, opacity;
    transform: scale(calc(1 / var(--zoom-scale, 1))) translateZ(0);
}

/* Disabled: Only show resize handles when item-active, not on hover */
/* .canvas-item:hover:not(.section-container) .resize-handle {
    opacity: var(--opacity-hover);
} */

/* .section-container > .canvas-item:hover .resize-handle {
    opacity: var(--opacity-hover);
} */

.resize-handle::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 0 6px 6px;
    border-color: transparent transparent var(--color-text-secondary) transparent;
    opacity: 0.3;
}

/* Remove the triangle from directional resize handles */
.resize-handle-n::before,
.resize-handle-s::before,
.resize-handle-e::before,
.resize-handle-w::before,
.resize-handle-nw::before,
.resize-handle-ne::before,
.resize-handle-sw::before,
.resize-handle-se::before {
    display: none;
}

/* Delete Button */
.delete-btn {
    position: absolute;
    top: calc(var(--delete-btn-size) / -2);
    right: calc((var(--delete-btn-size) / -2) - 1px);
    width: var(--delete-btn-size);
    height: var(--delete-btn-size);
    background: var(--color-bg);
    color: var(--color-accent);
    border: var(--border);
    border-radius: var(--radius-full);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font: bold var(--text-xs)/1 var(--font-main);
    transition: all var(--transition-fast);
    transform: scale(calc(1 / var(--zoom-scale, 1)));
    z-index: 1000000000002;
    /* Safe GPU acceleration for delete button */
    will-change: transform, opacity;
    transform: scale(calc(1 / var(--zoom-scale, 1))) translateZ(0);
}

/* Only show delete buttons when hovering direct items, not section containers */
.canvas-item:hover:not(.section-container) .delete-btn {
    display: flex;
}

.section-container > .canvas-item:hover .delete-btn {
    display: flex;
}
/* ========== TEXT ITEM ========== */
.text-item {
    min-width: var(--text-item-min-width);
    min-height: calc(var(--grid-base-unit) * 1); /* Exactly 2 grid units = 48px */
    width: calc(var(--grid-base-unit) * 12); /* 288px - grid-aligned default width */
    height: auto;/*calc(var(--grid-base-unit) * 2);*/
    /*padding: 12px !important; /* Adjusted padding for better grid fit */
    /*padding: var(--space-xs) var(--space-sm);*/
    padding: 0;
    transition: none;
    animation: none;
    /* GPU acceleration for text items */
}



.rich-text-editor {
    width: 100%;
    height: 23px;
    min-height: 23px;
    border: none !important;
    outline: none !important;
    /* GPU acceleration for text editor */
    font: inherit;
    color: var(--color-fg);
    background: transparent;
    overflow-y: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
    cursor: text;
    padding: 0; /* Remove any padding from editor itself */
    margin: 0; /* Remove any margin from editor itself */
    line-height: 1.0 !important; /* Consistent line height */
    font-size: var(--text-base); /* Consistent font size */
    padding-right: var(--space-sm);
}

.rich-text-editor:empty:before {
    content: '';
    color: var(--color-text-secondary);
    line-height: 1.0; /* Match editor line height */
}

.rich-text-editor ul { 
    margin: 0; /* Remove margins */
    padding-left: var(--space-lg); 
    line-height: 1.4; /* Match editor line height */
}

.rich-text-editor li {
    margin: 0; /* Remove margins */
    padding: 0; /* Remove padding */
    line-height: 1.4; /* Match editor line height */
}
.delete-btn:hover {
    background: var(--color-danger);
    color: white;
    border-color: var(--color-danger);
}


.text-item.text-style-h1,
.text-item.text-style-h2 {
    /*padding: 10px !important;*/
}

/* Text item style classes - support both old and new editors */
.text-item.text-style-h1 .rich-text-editor,
.text-item.text-style-h1 .rich-text-editor *,
.text-item.text-style-h1 .notion-editor-container,
.text-item.text-style-h1 .notion-editor-container * {
    font-size: var(--text-xl) !important;
    /*font-weight: var(--font-bold) !important;*/
    line-height: 0.99 !important;
}

.text-item.text-style-h2 .rich-text-editor,
.text-item.text-style-h2 .rich-text-editor *,
.text-item.text-style-h2 .notion-editor-container,
.text-item.text-style-h2 .notion-editor-container * {
    font-size: var(--text-lg) !important;
    /*font-weight: var(--font-semibold) !important;*/
    line-height: 1.2 !important;
}

.text-item.text-style-h3 .rich-text-editor,
.text-item.text-style-h3 .rich-text-editor *,
.text-item.text-style-h3 .notion-editor-container,
.text-item.text-style-h3 .notion-editor-container * {
    font-size: var(--text-md) !important;
    /*font-weight: var(--font-semibold) !important;*/
    line-height: 1.2 !important;
}

.text-item.text-style-p .rich-text-editor,
.text-item.text-style-p .rich-text-editor *,
.text-item.text-style-p .notion-editor-container,
.text-item.text-style-p .notion-editor-container * {
    font-size: var(--text-base) !important;
    /*font-weight: var(--font-normal) !important;*/
    line-height: 1.4 !important;
    color: var(--color-fg);
}

/* Text alignment classes */
.text-item.text-align-left .editor-block,
.text-item.text-align-left .prisma-editor-block,
.text-item.text-align-left .rich-text-editor,
.text-item.text-align-left .notion-editor-container {
    text-align: left !important;
}

.text-item.text-align-center .editor-block,
.text-item.text-align-center .prisma-editor-block,
.text-item.text-align-center .rich-text-editor,
.text-item.text-align-center .notion-editor-container {
    text-align: center !important;
}

.text-item.text-align-right .editor-block,
.text-item.text-align-right .prisma-editor-block,
.text-item.text-align-right .rich-text-editor,
.text-item.text-align-right .notion-editor-container {
    text-align: right !important;
}

.text-item.text-align-justify .editor-block,
.text-item.text-align-justify .prisma-editor-block,
.text-item.text-align-justify .rich-text-editor,
.text-item.text-align-justify .notion-editor-container {
    text-align: justify !important;
}

/* Vertical alignment for text items */
.text-item {
    display: flex;
    flex-direction: column;
}

.text-item.text-valign-top {
    justify-content: flex-start;
}

.text-item.text-valign-middle {
    justify-content: center;
}

.text-item.text-valign-bottom {
    justify-content: flex-end;
}

.document-editor-content h1:empty:before {
  content: attr(data-placeholder);
  color: var(--color-fg);
  opacity: 0.1;
  pointer-events: none;
}


/* Checkboxes */
.checkbox-wrapper {
    display: flex;
    gap: var(--space-sm);
    /*margin: var(--space-xs) 0;*/
}

.checkbox-wrapper input {
    margin-top: 2px;
    accent-color: var(--color-accent);
}

.checkbox-wrapper.checked .checkbox-content {
    text-decoration: line-through;
    opacity: var(--opacity-muted);
}

/* ========== CODE ITEM ========== */
.code-item {
    background: var(--code-bg);
    padding: 0 !important;
    min-width: var(--code-item-min-width);
    min-height: 64px;
    position: relative;
    /* GPU acceleration for code items */
}

.file-type-indicator {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-family: var(--font-code);
    opacity: 0.7;
    z-index: 10;
    pointer-events: none;
}

.quill-code-container {
    width: 100%;
    height: calc(100% - 4px); /* Account for border/padding */
    position: relative;
    box-sizing: border-box;
    /* GPU acceleration for code container */
}

.code-item .ql-container {
    font-family: var(--font-code);
    font-size: var(--text-sm);
    border: none;
    height: 100%;
    padding: var(--space-xs) var(--space-sm);
    background: transparent;
    box-sizing: border-box;
    position: relative;
}

.code-item .ql-editor {
    padding: 0;
    color: var(--code-text);
}

.code-item .ql-toolbar {
    display: none;
}

/* Quill specific */
.code-item .ql-clipboard,
.code-item .ql-tooltip {
    display: none !important;
}

.ql-snow .ql-editor pre,
.ql-snow .ql-editor pre.ql-syntax {
    padding: 0;
    background: transparent;
}

/* Syntax highlighting */
.code-item .hljs-keyword { color: var(--code-keyword); }
.code-item .hljs-string { color: var(--code-string); }
.code-item .hljs-comment { color: var(--code-comment); }
.code-item .hljs-number { color: var(--code-number); }
.code-item .hljs-function { color: var(--code-function); }

/* ========== IMAGE ITEM ========== */
.image-item {
    padding: 0 !important;
    background: transparent !important;
    border: calc(1px / var(--zoom-scale, 1)) solid white;
    /* GPU acceleration for image items */
}

.image-item img {
    display: block;
    width: 100%;
    height: 100%;
   /* object-fit: contain;
    border-radius: var(--radius-item);
   */ /* GPU acceleration for images */
}

/* ========== EMBED ITEM ========== */
.embed-item {
    padding: 0 !important;
    background: var(--color-surface-4);
    /* GPU acceleration for embed items */
}

.iframe-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-item);
    overflow: hidden;
    /* GPU acceleration for iframe wrapper */
}

.iframe-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.drag-overlay {
    position: absolute;
    inset: 0;
    z-index: var(--z-base);
}

/* ========== LINK ITEM ========== */
.link-item {
    background: var(--color-surface-2);
    min-width: 280px;
    max-width: 400px;
    overflow: hidden;
    /* GPU acceleration for link items */
}

/* Link item states */
.link-item.link-loading {
    padding: var(--space-lg) !important;
    min-height: 80px;
}

.link-item.link-simple {
    min-width: 300px;
}

/* ========== SIZE VARIANTS ========== */
/* Small size - Compact single line */
.link-item.link-small {
    min-width: 200px;
    max-width: 400px;
    min-height: 60px;
    height: 60px !important;
    max-height: 60px !important;
}

/* Medium size - Standard with side image */
.link-item.link-medium {
    min-width: 300px;
    max-width: 400px;
    min-height: 100px;
    max-height: 140px !important;
}

/* Large size - Card with top image */
.link-item.link-large {
    min-width: 350px;
    max-width: 400px;
    min-height: 200px;
    max-height: 900px !important;
}

/* ========== LINK WRAPPER ========== */
.link-wrapper {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    width: 100%;
    height: 100%;
    /* GPU acceleration for link wrapper */
}

.link-wrapper.no-image {
    padding: 0;
}

.link-wrapper.with-image {
    padding: 0;
}

/* ========== LAYOUT VARIATIONS ========== */
/* Small layout */
.link-small .link-wrapper {
    /*padding: var(--space-sm) var(--space-md);*/
}

.link-small .link-image {
    display: none;
}

.link-small .link-description {
    display: none;
}

.link-small .link-details {
    flex-direction: row;
    align-items: center;
    gap: var(--space-sm);
    padding-top: 0;
}

.link-small .link-header {
    margin: 0;
}

.link-small .link-title {
    font-size: var(--text-sm);
    -webkit-line-clamp: 1;
}

/* Medium layout */
.link-medium .link-wrapper {
    padding: 0;
}

.link-medium .link-image {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    overflow: hidden;
    background: var(--color-surface-1);
    order: 2;
}

.link-medium .link-title {
    padding-right: 20px;
}

.link-medium .link-details {
    order: 1;
    padding-top: 0;
}

.link-medium .link-description {
    display: none;
}

/* Large layout */
.link-large .link-wrapper {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
}

.link-large .link-image {
    width: 100%;
    height: auto; /* Changed from fixed 180px to auto */
    order: 1;
    flex-shrink: 0;
    display: flex; /* Add flex to contain the image properly */
    justify-content: center;
    background: var(--color-surface-1);
}

.link-large .link-details {
    /*padding: var(--space-md);*/
    order: 2;
}

.link-large .link-title {
    font-size: var(--text-md);
    -webkit-line-clamp: 2;
}

.link-large .link-description {
    -webkit-line-clamp: 3;
}

.link-large .link-image img {
    width: 100%;
    height: auto; /* Let height be determined by aspect ratio */
    object-fit: contain; /* Changed from cover to contain to show full image */
    display: block;
    border-radius: var(--radius-md);
    overflow: hidden;
    /* max-height: 300px; Optional: set a max height to prevent extremely tall images */
}

/* Iframe layout */
.link-iframe {
    /* No size constraints - completely free resizing! */
    min-width: unset;
    min-height: unset;
    max-width: unset;  
    max-height: unset;
}

.link-iframe .link-wrapper {
    padding: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.link-iframe .link-image,
.link-iframe .link-details,
.link-iframe .link-description {
    display: none; /* Hide all metadata in iframe mode */
}

.link-iframe .link-iframe-container {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--color-surface-1);
    position: relative;
}

.link-iframe .link-iframe-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius-md);
}

/* ========== LINK IMAGE ========== */
.link-image {
    flex-shrink: 0;
    width: 120px;
    height: 120px;
    overflow: hidden;
    background: var(--color-surface-1);
}

.link-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* ========== LINK DETAILS ========== */
.link-details {
    flex: 1;
    padding-top: var(--space-md);
    
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
    min-width: 0;
}

.link-wrapper.no-image .link-details {
    padding: 0;
}

/* ========== LINK HEADER ========== */
.link-header {
    display: flex;
    align-items: center;
    gap: calc(var(--space-xs) * 0.5);
    margin-bottom: calc(var(--space-xs) * 0.5);
}

.link-favicon {
    width: 14px;
    height: 14px;
    object-fit: contain;
    flex-shrink: 0;
}

.link-domain {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========== LINK CONTENT ========== */
.link-title {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    color: var(--color-fg);
    line-height: 1.3;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.link-description {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    line-height: 1.4;
    margin: var(--space-xs) 0 0 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.link-url {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    margin: var(--space-xs) 0 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========== LINK ICON (Fallback) ========== */
.link-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    margin-right: var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.link-favicon-large {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.link-icon-fallback {
    width: 48px;
    height: 48px;
    background: var(--color-surface-1);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
}

/* ========== LOADING STATE ========== */
.link-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

.link-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: var(--space-sm);
    /* Safe GPU acceleration for spinner */
    will-change: transform;
    transform: translateZ(0);
}

.link-loading-text {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
}

/* ========== DRAG PREVENTION ========== */
.link-item,
.link-item *,
.link-wrapper,
.link-wrapper *,
.link-title,
.link-description,
.link-domain,
.link-url {
    -webkit-user-drag: none;
    user-drag: none;
}

.link-title,
.link-description,
.link-domain,
.link-url {
    user-select: text;
}

/* ========== SELECTION BOX ========== */
.selection-box {
    position: absolute;
    border: 2px solid var(--color-accent);
    background: var(--color-selected);
    opacity: 0.3;
    pointer-events: none;
    z-index: var(--z-toolbar);
    border-radius: var(--radius-sm);
    /* Safe GPU acceleration for selection box */
    will-change: transform, opacity;
    transform: translateZ(0);
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

/* ========== ANIMATIONS ========== */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.98); }
    100% { transform: scale(1); }
}

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

/* ========== FOCUS STATES ========== */
:focus-visible {
    outline: 0px solid var(--color-accent);
    outline-offset: 0px;
}

/* ========== VIDEO ITEM ========== */
.video-item {
    padding: 0 !important;
    background: var(--color-surface-4);
    min-width: 200px;
    min-height: 150px;
    /* GPU acceleration for video items */
}

.video-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: #000;
    /* GPU acceleration for video wrapper */
}

.video-wrapper video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: #000;
}

.video-wrapper .drag-overlay {
    position: absolute;
    inset: 0;
    z-index: var(--z-base);
    /*cursor: move;*/
}

/* Hide overlay when not dragging to allow video controls */
.video-item:not(.dragging) .drag-overlay {
    pointer-events: none;
}

/* Show overlay on hover for drag indication */
.video-item.preparing-drag .drag-overlay,
.video-item.drag-ready .drag-overlay,
.video-item.dragging .drag-overlay {
    pointer-events: all;
}


/* ========== SECTION CONTAINER ========== */
.section-container {
    position: absolute;
    background: var(--color-surface-1);
    /*border: 1px dashed var(--color-border);*/
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    min-width: 200px;
    min-height: 150px;
    transition: all var(--transition-fast);
    overflow: visible;
}

.section-container:hover {
    border-color: var(--color-text-secondary);
    background: var(--color-hover);
}

.section-container.selected {
    border-style: solid;
    border-color: var(--color-accent);
    /*background: var(--color-selected);*/
}

.section-container.drag-over {
    border-color: var(--color-accent);
    /*background: var(--color-selected);*/
    border-width: 3px;
}

/* Section presentation mode */
.section-container.presentation-mode {
    border-style: solid;
    border-color: #9333ea;
    box-shadow: 0 0 0 1px #9333ea;
    overflow: hidden; /* Clip content to section boundaries */
}

/* Hide resize handles for the section itself in presentation mode (not items inside) */
.section-container.presentation-mode > .resize-handle,
.section-container.presentation-mode > .resize-handle-nw,
.section-container.presentation-mode > .resize-handle-ne,
.section-container.presentation-mode > .resize-handle-sw,
.section-container.presentation-mode > .resize-handle-se,
.section-container.presentation-mode > .resize-handle-n,
.section-container.presentation-mode > .resize-handle-s,
.section-container.presentation-mode > .resize-handle-e,
.section-container.presentation-mode > .resize-handle-w {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

.section-container .section-header {
    position: absolute;
    top: calc(var(--space-lg) * -1);
    left: 0;
    right: 0;
    height: var(--space-lg);
    display: flex;
    align-items: center;
    padding: 0;
}

/* Position header inside presentation mode sections */
.section-container.presentation-mode .section-header {
    top: 0;
    z-index: 1000;
    /*background: rgba(255, 255, 255, 0.9);*/
    backdrop-filter: blur(5px);
    padding: 0 5px;
}

/* Hide section header in fullscreen presentation mode */
:fullscreen .section-container.presentation-mode .section-header,
.section-container.presentation-mode.fullscreen .section-header {
    display: none !important;
}

/* Ensure proper stacking */
/* Section z-index handled by JavaScript */

/* Items inside sections - use auto to avoid creating new stacking context */
.section-container .canvas-item:not(.selected) {
    z-index: auto;
}

.section-container .section-title {
    color: var(--color-text-secondary);
    /* font-weight: var(--font-medium); */
    opacity: 1;
    transition: opacity var(--transition-fast), font-size 0.1s ease;
    cursor: move;
    /* padding: 2px 6px; */
    border-radius: var(--radius-sm);
    /* min-width: calc(60px / var(--zoom-scale, 1)); */
    white-space: nowrap;
    pointer-events: all;
    font-size: var(--font-main);
    padding: 2px 5px;
    background: var(--color-bw);
}

.section-container .section-title.editing {
    opacity: 1;
    background: var(--color-bg);
    border: calc(1px / var(--zoom-scale, 1)) solid var(--color-accent);
    outline: none;
    color: var(--color-fg);
    cursor: text;
    pointer-events: all;
}

.section-container:hover .section-title,
.section-container.selected .section-title {
    opacity: 1;
}

/* Section controls */
.section-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.2s ease, gap 0.1s ease;
}

.section-container:hover .section-controls,
.section-container.selected .section-controls {
    opacity: 1;
}

.section-color-btn {
    border:0; 
    border-radius: calc(var(--radius-md) / var(--zoom-scale, 1));
    width: calc(20px / var(--zoom-scale, 1));
    height: calc(20px / var(--zoom-scale, 1));
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0s ease;
    /*transform: scale(calc(1 / var(--zoom-scale, 1))) !important;*/
    box-sizing:content-box;
    padding: calc(var(--space-xs) * 0.25);
}




.section-share-btn,
.section-mode-btn,
.section-present-btn {
    border:0; 
    border-radius: calc(var(--radius-md) / var(--zoom-scale, 1));
    width: calc(20px / var(--zoom-scale, 1));
    height: calc(20px / var(--zoom-scale, 1));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0s ease;  
    box-sizing:content-box;
    padding: calc(var(--space-xs) * 0.25);
    /*background: rgba(255,255,255, 0.5);*/
}
.section-color-btn:hover
.section-share-btn:hover,
.section-mode-btn:hover,
.section-present-btn:hover {
    background: var(--color-bw);
}

.section-color-btn svg,
.section-share-btn svg,
.section-mode-btn svg,
.section-present-btn svg {
    background: var(--color-fg);
    background: transparent;
}

.section-color-btn:hover svg,
.section-share-btn:hover svg,
.section-mode-btn:hover svg,
.section-present-btn:hover svg {
    /*background: var(--color-fg);*/
}


/* Presentation mode specific button color */
/*.presentation-mode .section-mode-btn {
    background: rgba(147, 51, 234, 0.2);
}

.presentation-mode .section-mode-btn:hover {
    background: rgba(147, 51, 234, 0.3);
}

.presentation-mode .section-mode-btn svg {
    color: #9333ea;
}*/

/* Presentation connection ports */
.presentation-port {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #9333ea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: crosshair;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 100;
    pointer-events: all;
    user-select: none;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.presentation-port:hover {
    cursor: crosshair;
}

.presentation-port:active {
    cursor: crosshair;
}

/* Hide ports by default, show only on section hover */
.section-container.presentation-mode .presentation-port {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.section-container.presentation-mode:hover .presentation-port {
    opacity: 1;
}

/* Move ports inside the section border */
.presentation-port-next {
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
}

.presentation-port-next:hover {
    transform: translateY(-50%) scale(1.1);
}

.presentation-port-prev {
    left: 5px;
    top: 50%;
    transform: translateY(-50%);
}

.presentation-port-prev:hover {
    transform: translateY(-50%) scale(1.1);
}

/* Presentation connection visual states */
.presentation-port-next.connecting {
    opacity: 1 !important;
    transform: translateY(-50%) scale(1.2);
    box-shadow: 0 0 20px rgba(147, 51, 234, 0.6);
}

.presentation-port-prev.connecting {
    opacity: 1 !important;
    transform: translateY(-50%) scale(1.2);
    box-shadow: 0 0 20px rgba(147, 51, 234, 0.6);
}

.section-container.connecting-from {
    box-shadow: 0 0 0 2px rgba(147, 51, 234, 0.6);
}

.presentation-port-next.valid-drop-target {
    opacity: 1 !important;
    transform: translateY(-50%) scale(1.3);
    background: #16a34a;
    animation: pulse-presentation 1s infinite;
}

.presentation-port-prev.valid-drop-target {
    opacity: 1 !important;
    transform: translateY(-50%) scale(1.3);
    background: #16a34a;
    animation: pulse-presentation 1s infinite;
}

.section-container.valid-drop-target {
    box-shadow: 0 0 0 3px #16a34a;
}

@keyframes pulse-presentation {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(22, 163, 74, 0.6);
    }
    50% { 
        box-shadow: 0 0 30px rgba(22, 163, 74, 0.8);
    }
}

/* Presentation connection lines */
.presentation-connection-line {
    filter: drop-shadow(0 2px 4px rgba(147, 51, 234, 0.3));
}

.presentation-connection-line.temp-connection {
    filter: drop-shadow(0 2px 8px rgba(147, 51, 234, 0.5));
}

/* ========== MISC ========== */
.hidden {
    display: none !important;
}

/* Disable transitions during grid operations */
.canvas-item.grid-snapping {
    transition: none !important;
}

.canvas-item.grid-snapping * {
    transition: none !important;
}

.viewport.drag-over {
    background-color: rgba(0, 123, 255, 0.05);
    border: 2px dashed #007bff;
}

.viewport.drag-over::after {
    content: 'Drop here';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #007bff;
    pointer-events: none;
}

/* .section-container:hover .canvas-item .delete-btn {
    display: none;
} */

/* Don't hide resize handles on section hover - let item-specific rules handle them */
/* .section-container:hover .canvas-item .resize-handle {
    display: none;
} */

/* Show advanced resize handles for sections on hover */
.section-container:hover > .resize-handle-nw,
.section-container:hover > .resize-handle-ne,
.section-container:hover > .resize-handle-sw,
.section-container:hover > .resize-handle-se,
.section-container:hover > .resize-handle-n,
.section-container:hover > .resize-handle-s,
.section-container:hover > .resize-handle-e,
.section-container:hover > .resize-handle-w {
    opacity: 1 !important;
    display: block !important;
}

/* Show resize handles for active (selected) items inside sections */
.section-container .canvas-item.item-active .resize-handle,
.section-container .canvas-item.item-active .resize-handle-nw,
.section-container .canvas-item.item-active .resize-handle-ne,
.section-container .canvas-item.item-active .resize-handle-sw,
.section-container .canvas-item.item-active .resize-handle-se,
.section-container .canvas-item.item-active .resize-handle-n,
.section-container .canvas-item.item-active .resize-handle-s,
.section-container .canvas-item.item-active .resize-handle-e,
.section-container .canvas-item.item-active .resize-handle-w {
    display: flex !important;
    opacity: var(--opacity-hover) !important;
    pointer-events: all !important;
    z-index: 1000000000001 !important;
    cursor: nwse-resize !important;
}

/* Hide delete button on selected items to avoid conflict with resize handles */
.canvas-item.item-active .delete-btn,
.section-container .canvas-item.item-active .delete-btn {
    display: none !important;
}

/* Disabled: Don't show resize handles on hover, only when selected/active */
/* .section-container .canvas-item:hover .resize-handle,
.section-container .canvas-item:hover .resize-handle-nw,
.section-container .canvas-item:hover .resize-handle-ne,
.section-container .canvas-item:hover .resize-handle-sw,
.section-container .canvas-item:hover .resize-handle-se,
.section-container .canvas-item:hover .resize-handle-n,
.section-container .canvas-item:hover .resize-handle-s,
.section-container .canvas-item:hover .resize-handle-e,
.section-container .canvas-item:hover .resize-handle-w {
    display: flex !important;
    opacity: var(--opacity-hover) !important;
    pointer-events: all !important;
} */

/* But show them when hovering the items directly */
.section-container .canvas-item:hover > .delete-btn {
    display: flex;
    z-index: 1000000000002 !important;
}
/* .section-container .canvas-item:hover > .resize-handle {
    display: flex;
} */

/* Embed active state */
.embed-item.embed-active .drag-overlay,
.video-item.embed-active .drag-overlay {
    background: transparent !important;
    pointer-events: none !important;
    cursor: default !important;
}

.embed-item.embed-active,
.video-item.embed-active {
    /*box-shadow: 0 0 0 3px var(--color-accent);*/
}

/* Show a subtle indicator when hovering inactive overlay */
.embed-item:not(.embed-active) .drag-overlay:hover,
.video-item:not(.embed-active) .drag-overlay:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Dark theme version */
body.dark-theme .embed-item:not(.embed-active) .drag-overlay:hover,
body.dark-theme .video-item:not(.embed-active) .drag-overlay:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Ensure overlays are always visible when not active */
.embed-item:not(.embed-active) .drag-overlay,
.video-item:not(.embed-active) .drag-overlay {
    pointer-events: all !important;
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-bg-modal);
    color: var(--color-fg);
    padding: var(--space-xs);
    border-radius: var(--radius-lg);
    border: var(--border);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    /* Safe GPU acceleration for toast notifications */
    will-change: transform, opacity;
    transform: translateX(-50%) translateY(100px) translateZ(0);
}

.toast-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Modal overlay */
.toast-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    /* GPU acceleration for overlay */
}

.toast-overlay.show {
    opacity: 1;
    pointer-events: all;
}

/* Modal-style toast */
.toast-notification.modal {
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%) scale(0.9);
    min-width: 300px;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.toast-notification.modal.show {
    transform: translate(-50%, -50%) scale(1);
}

/* Keep your existing button styles... */
.toast-notification.has-buttons {
    padding: 16px 20px;
    max-width: 400px;
}

.toast-message {
    /*margin-bottom: 12px;*/
}

.toast-buttons {
    display: flex;
    gap: 8px;
    justify-content:flex-wrap;
    font-weight: bold;
}

/* Full width buttons for board selection modal */
.toast-notification.modal .toast-buttons {
    /*flex-direction: column;*/
    align-items: stretch;
}

.toast-notification.modal .toast-button {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
}

.toast-button {
    padding: 12px 16px;
    border: none;
    border-radius: 2px;
    background: var(--color-hover);
    color: var(--color-fg);
    cursor: pointer;
    /*font-size: 14px;*/
    transition: all 0.2s;
    margin-top: 20px;
    text-align: center !important;
}

.toast-button:hover {
    /*background: rgba(255, 255, 255, 0.3);*/
    opacity: 0.95;
}

.toast-button.primary {
    background: var(--color-fg);
    color: var(--color-bg);
}

.toast-button.primary:hover {
    background: var(--color-fg);
    color: var(--color-bg);
}

body.dark-theme .toast-notification {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

body.dark-theme .toast-overlay {
    background: rgba(0, 0, 0, 0.7);
}


/* Board Switcher */
.board-switcher {
    display: flex;
    align-items: center;
    gap: var(--space-xs);

}

.board-switcher .tool-select {
    border-radius: var(--radius-sm);
}

.board-switcher .tool-btn {
    padding: var(--space-xs);
    width: 32px;
    height: 32px;
}

/* Storage Indicator */
.storage-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-right: var(--space-md);
}

.storage-bar {
    width: 100px;
    height: 6px;
    background: var(--color-surface-2);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.storage-fill {
    height: 100%;
    background: var(--color-accent);
    transition: width 0.3s ease, background-color 0.3s ease;
}

.storage-text {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .board-switcher .tool-select {
        /*min-width: 100px;*/
    }
    
    .storage-indicator {
        display: none;
    }
}

/* Custom ChatGPT-style Tooltips */
.custom-tooltip {
    position: fixed;
    background: var(--color-bw);
    color: var(--color-fg);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: var(--text-sm);
    font-weight: 400;
    white-space: nowrap;
    z-index: 100000000000;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0s ease, transform 0.2s ease;
    /* Safe GPU acceleration for tooltips */
    will-change: transform, opacity;
    transform: translateY(4px) translateZ(0);
}

.custom-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

/* Dark theme tooltip (lighter background) */
body.dark-theme .custom-tooltip {
}

/* Ghost copy preview */
/* Ghost copy preview */
.ghost-copy {
    opacity: 0.7 !important;
    pointer-events: none !important;
    border: 2px dashed var(--color-accent) !important;
    background: rgba(0, 102, 204, 0.05) !important;
}

.ghost-copy * {
    pointer-events: none !important;
}

/* Hide all interactive elements in ghosts */
.ghost-copy .delete-btn,
.ghost-copy .resize-handle,
.ghost-copy .link-toggle,
.ghost-copy button {
    display: none !important;
    visibility: hidden !important;
}

/* Long press visual feedback */
.long-press-ripple {
    position: fixed;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--color-accent);
    opacity: 0.2;
    pointer-events: none;
    z-index: 10000;
    animation: ripple 0.5s ease-out;
    /* GPU acceleration for ripple */
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 0.4;
    }
    100% {
        transform: scale(1);
        opacity: 0.2;
    }
}

/* Position indicators */
.position-indicators {
    pointer-events: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    /* GPU acceleration for position indicators */
}

.position-indicator {
    position: absolute;
    background: rgba(0, 0, 0, 0.0);
    transition: opacity 0.2s ease;
}

body.dark-theme .position-indicator {
    background: rgba(255, 255, 255, 0.0);
}

/* Horizontal indicator (bottom) */
.position-indicator.horizontal {
    bottom: 6px;
    left: 6px;
    right: 6px;
    height: 2px;
    border-radius: 2px;
}

/* Vertical indicator (right side) */
.position-indicator.vertical {
    right: 6px;
    top: 6px; /* Account for toolbar */
    bottom: 6px;
    width: 2px;
    border-radius: 2px;
}

/* The moving dot */
.position-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--color-fg);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: opacity 0.1s ease-out;
    opacity: 0;
}

/* Position dot in center of track */
.horizontal .position-dot {
    top: 50%;
    transform: translateY(-50%);
}

.vertical .position-dot {
    left: 50%;
    transform: translateX(-50%);
}

/* Hide when zoomed out too far */
.position-dot {
    
}

.position-dot.hidden {
    opacity: 0;
}


body.canvas-panning .position-dot {
    opacity: 0.2;
}

/* Canvas panning cursors */
body.canvas-panning {
    cursor: grabbing !important;
}

body.canvas-panning *:not(.rich-text-editor):not(.ql-editor) {
    cursor: grabbing !important;
}

/* Higher priority for when actively click-panning */
body.canvas-panning.space-pressed {
    cursor: grabbing !important;
}

body.canvas-panning.space-pressed *:not(.rich-text-editor):not(.ql-editor) {
    cursor: grabbing !important;
}

/* Space key pressed - ready to pan */
body.space-pressed {
    cursor: grab !important;
}

body.space-pressed * {
    cursor: grab !important;
}

/* Override text selection cursors during panning states */
body.canvas-panning .rich-text-editor,
body.canvas-panning .ql-editor,
body.space-pressed .rich-text-editor,
body.space-pressed .ql-editor {
    cursor: inherit !important;
}

/* ========== STEP 1: PERFORMANCE OPTIMIZATIONS ========== */

/* Performance optimizations during panning */
body.canvas-panning .canvas-item {
    /* Disable expensive CSS during interactions */
    transition: none !important;
    animation: none !important;
    /* Use GPU layer for smooth transforms */
    will-change: transform;
    /* Prevent text selection during pan */
    user-select: none;
    pointer-events: none;
}

/* Re-enable interactions for specific elements */
body.canvas-panning .canvas-item .rich-text-editor,
body.canvas-panning .canvas-item .ql-editor {
    pointer-events: auto;
    user-select: text;
}

/* Optimize images during panning for better performance */
body.canvas-panning .canvas-item img {
    /* Use faster, lower-quality rendering during movement */
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    /* Enable GPU acceleration */
    will-change: transform;
    /* Disable transitions on images */
    transition: none !important;
}

/* Optimize videos during panning */
body.canvas-panning .canvas-item video {
    /* Use GPU acceleration */
    will-change: transform;
    /* Disable transitions */
    transition: none !important;
}

/* ========== VIEWPORT CULLING FADE ANIMATIONS ========== */
/* Smooth fade transitions for items entering/leaving viewport */
.canvas-item {
    transition: opacity 0.4s ease-in-out !important;
}

/* More specific rule to ensure opacity transition works */
.canvas-item:not(.no-fade-transition) {
    transition: opacity 0.4s ease-in-out !important;
}

/* Even more specific for image items */
.canvas-item.image-item {
    transition: opacity 0.4s ease-in-out !important;
}

/* Disable fade transitions during interactions for performance */
body.canvas-panning .canvas-item {
    transition: none !important;
}



/* API Settings Modal */
.api-settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0s ease;
    /* GPU acceleration for modal */
}

.api-settings-content {
    background: var(--color-bg);
    /*border: 1px solid rgba(255, 255, 255, 0.1);*/
    border-radius: var(--radius-lg);
    width: 600px;
    max-width: 90vw;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.2s ease;
    /* GPU acceleration for modal content */
}

/* Light mode */
body:not(.dark-theme) .api-settings-content {
    background: #ffffff;
    border: px solid rgba(0, 0, 0, 0.1);
}

/* Header */
.api-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    /*border-bottom: 1px solid rgba(255, 255, 255, 0.1);*/
}

body:not(.dark-theme) .api-settings-header {
    /*border-bottom: 1px solid rgba(0, 0, 0, 0.1);*/
}

.api-settings-header h2 {
    margin: 0;
    color: #ffffff;
}

body:not(.dark-theme) .api-settings-header h2 {
    color: #000000;
}

.api-close-btn {
    background: none;
    border: none;
    color: #959595;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: none;
}

.api-close-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

body:not(.dark-theme) .api-close-btn:hover {
    color: #000000;
    background: rgba(0, 0, 0, 0.05);
}

/* Body */
.api-settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* Setting Row */
.api-setting-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body:not(.dark-theme) .api-setting-row {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.api-setting-row:last-child {
    border-bottom: none;
}

.api-setting-info {
    flex: 1;
    margin-right: 24px;
}

.api-setting-label {
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    margin-bottom: 4px;
}

body:not(.dark-theme) .api-setting-label {
    color: #000000;
}

.api-setting-description {
    font-size: var(--text-sm);
    color: #959595;
    line-height: 1.5;
}

/* API Key Input Group */
.api-setting-control {
    width: 300px;
}

.api-key-wrapper {
    position: relative;
    width: 100%;
}

.api-key-input {
    width: 100%;
    padding: 8px 40px 8px 12px;
    background: var(--color-surface-2);
    border: 0px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #ffffff;
    font-family: monospace;
    font-size: var(--text-sm);
    transition: all 0.2s ease;
}

body:not(.dark-theme) .api-key-input {
    /*background: var(--color-fg);*/
    border: 0px solid rgba(0, 0, 0, 0.1);
    color: #000000;
}

.api-key-input:focus {
    outline: none;
    border-color: #0066cc;
}

.api-key-input::placeholder {
    color: #666666;
}

.api-key-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #959595;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.api-key-toggle:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

body:not(.dark-theme) .api-key-toggle:hover {
    color: #000000;
    background: rgba(0, 0, 0, 0.05);
}

.api-key-link {
    display: inline-block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--color-accent);
    text-decoration: none;
}

.api-key-link:hover {
    text-decoration: underline;
}

/* Footer */
.api-settings-footer {
    padding: 20px 24px;
    /*border-top: 0px solid rgba(255, 255, 255, 0.1);*/
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

body:not(.dark-theme) .api-settings-footer {
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

/* Buttons */
.api-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.api-btn.secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

body:not(.dark-theme) .api-btn.secondary {
    border: 1px solid rgba(0, 0, 0, 0.2);
    color: #000000;
}

.api-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.05);
}

body:not(.dark-theme) .api-btn.secondary:hover {
    background: rgba(0, 0, 0, 0.05);
}

.api-btn.primary {
    background: var(--color-accent);
    color: var(--color-fg);
    border: none;
}

.api-btn.primary:hover {
    opacity: 0.5;
}

/* Warning Box */
.api-settings-note {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255, 193, 7, 0.1);
    /*border: 1px solid rgba(255, 193, 7, 0.2);*/
    border-radius: 6px;
    margin: 0 0 24px 0;
    font-size: var(--text-sm);
    color: #ffc107;
}

body:not(.dark-theme) .api-settings-note {
    background: rgba(255, 193, 7, 0.05);
    color: #f57c00;
}

.api-settings-note svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* Result Messages */
.api-test-result {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: var(--text-sm);
    display: none;
    align-items: center;
    gap: 8px;
}

.api-test-result.success {
    background: rgba(52, 211, 153, 0.1);
    color: #34d399;
}

.api-test-result.error {
    background: rgba(248, 113, 113, 0.1);
    color: #f87171;
}

/* Scrollbar */
.api-settings-body::-webkit-scrollbar {
    width: 8px;
}

.api-settings-body::-webkit-scrollbar-track {
    background: transparent;
}

.api-settings-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

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









/* ========== INSTRUCTION ITEM - MINIMAL CHAT STYLE ========== */
.instruction-item {
    border: none !important;
    background: var(--color-surface-2) !important;
    min-width: 280px;
    /*min-height: auto;*/
    padding: 0 !important;
    /*border-radius: 24px !important;*/
    box-shadow: none;
}

.instruction-item.selected, .instruction-item.multi-selected {
    border: 1px solid rgba(0,0,0, 0.2) !important;
    box-sizing: border-box;
    /*background: rgba(0, 0, 0, 0.08) !important;*/
}

body.dark-theme .instruction-item {
    background: rgba(255, 255, 255, 0.08) !important;
}

body.dark-theme .instruction-item.selected, .instruction-item.multi-selected {
    /*border: 1px solid rgba(255, 255, 255, 0.2) !important;*/
}

.instruction-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    /*padding: 16px 20px 14px 20px;*/
    padding: var(--space-sm);
    justify-content: space-between;
    /*gap: 12px;*/
}

.instruction-input {
    width: 100%;
    border: none;
    background: transparent;
    font-family: var(--font-main);
    font-size: var(--text-base);
    color: var(--color-fg);
    resize: none;
    outline: none;
    padding: 0;
    margin: 0;
    min-height: 24px;
    line-height: 1.5;
}


.instruction-input::placeholder {
    content: "Set instruction..."; /* ignored, not how it works */
    color: var(--color-text-secondary);
    opacity: 0.6;
}

.instruction-footer {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-top: 0px;
    padding-bottom: 0px;
    position: relative;
}

.instruction-footer .ai-provider-selector {
    display: flex;
    gap: 5px;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    margin: -4px -8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    opacity:1;
    width: auto;
}

.model-selector:hover {
    background: rgba(0, 0, 0, 0.05);
    opacity: 1;
}
body.dark-theme .model-selector:hover {
    background: rgba(255, 255, 255, 0.05);
}

.model-label {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-icon {
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border-radius: 4px;
    font-size: 9px;
}

.model-icon.claude {
    background: #D97706;
    color: white;
}

.model-icon.openai {
    background: #10B981;
    color: white;
}

.model-icon.gemini {
    background: #4285F4;
    color: white;
}

.model-icon.local {
    background: #8B5CF6;
    color: white;
}

.model-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 4px;
    background: #2a2a2a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px;
    min-width: 120px;
    display: none;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

body.dark-theme .model-dropdown {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    /*background: #eee;*/
}

.model-dropdown.show {
    display: block;
}

.model-option {
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    color: #aaa;
}

.model-option:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}
body.dark-theme .model-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.model-option.selected {
    color: #7C3AED;
    font-weight: 500;
}
.model-option.selected:hover {
    color: #8B5CF6;
}

/* Contextual menu styles for AI provider selector */
.provider-context-menu.context-menu {
    min-width: 240px;
    max-width: 320px;
}

.output-type-context-menu.context-menu {
    min-width: 240px;
    max-width: 320px;
}

/* Make sure model-option items inherit context-menu-item styling */
.provider-context-menu .model-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: var(--text-base);
    color: var(--color-fg);
    transition: background-color 0.15s ease;
}

.provider-context-menu .model-option:hover {
    background: var(--color-hover) !important;
}

.provider-context-menu .model-option.selected {
    background: var(--color-selected);
    color: var(--color-accent);
}

/* Output type menu items already use .context-menu-item so they inherit the base styles */
.output-type-context-menu .context-menu-item.selected {
    background: var(--color-selected);
    color: var(--color-accent);
}

/* Provider icon styling */
.provider-context-menu .model-icon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: var(--font-bold);
    color: white;
}

.provider-context-menu .model-icon.anthropic {
    background: #d97706;
}

.provider-context-menu .model-icon.openai {
    background: #10b981;
}

.provider-context-menu .model-icon.gemini {
    background: #3b82f6;
}

.provider-context-menu .model-icon.local {
    background: #6b7280;
}

.instruction-run-btn {
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.1);
    color: var(--color-fg);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
    margin-left: 2px;
}

body.dark-theme .instruction-run-btn {
    background: rgba(255, 255, 255, 0.1);
}

.instruction-run-btn:hover {
    background: rgba(0, 0, 0, 0.15);
    transform: scale(1.05);
}

body.dark-theme .instruction-run-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.instruction-run-btn:active {
    transform: scale(0.95);
}

.instruction-run-btn svg {
    width: 18px;
    height: 18px;
    margin-left: 2px;
}

.instruction-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.instruction-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(124, 58, 237, 0.2);
    border-top-color: #7C3AED;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.instruction-item.instruction-processing {
    /*background: rgba(124, 58, 237, 0.1) !important;*/
    /*box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.3);*/
}

.instruction-item.pending-execution {
    animation: pendingGlow 0.6s ease-out;
    background: rgba(16, 185, 129, 0.1) !important;
}

@keyframes pendingGlow {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 0 12px rgba(16, 185, 129, 0);
        transform: scale(1.02);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
        transform: scale(1);
    }
}

.instruction-context-indicator {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 16px;
    height: 16px;
    background: #3B82F6;
    border: 2px solid var(--color-bg);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: white;
    font-weight: bold;
}

.instruction-item.has-context .instruction-context-indicator {
    display: flex;
}

.instruction-error {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: #EF4444;
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    margin-bottom: 8px;
    animation: slideUp 0.3s ease-out;
}

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

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== CONNECTION PORTS ========== */
.connection-port {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: crosshair;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 10;
    transform: translateY(-50%) scale(calc(1 / var(--zoom-scale, 1)));
}

/* Only show connection ports when hovering direct items, not section containers */
.canvas-item:hover:not(.section-container) .connection-port {
    opacity: 0.7;
}

.section-container > .canvas-item:hover .connection-port {
    opacity: 0.7;
}

/* Show connection ports on area boundaries */
.area-boundary:hover .connection-port {
    opacity: 0.7;
}

.connection-port:hover {
    opacity: 1 !important;
}

.input-port {
    left: -13px;
    z-index: 1000;
}

.output-port {
    right: -13px;
    z-index: 1000;
}

.port-dot {
    width: 20px;
    height: 20px;
    background: #7C3AED;
    border: 10px solid var(--color-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
}

.port-dot svg {
    color: black;
}

.dark-theme .port-dot svg {
    color: white
}

.dark-theme .port-dot {
    border: 10px solid var(--color-bg);
}

.output-port .port-dot {
    background: #3B82F6;
}

.port-dot span {
    color: white;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-port .port-dot span {
    display: none;
}

/*.connection-port.connecting .port-dot {
    transform: scale(1.3);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.2);
}

.connection-port.port-hover-valid .port-dot {
    transform: scale(1.4);
    background: #10B981 !important;
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.3);
}

.connection-port.port-hover-invalid .port-dot {
    transform: scale(0.8);
    background: #EF4444 !important;
    opacity: 0.5;
}*/



.connection-preview {
    pointer-events: none;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

body:has(.connection-port.connecting) .canvas-item .connection-port {
    opacity: 1;
}

.instruction-item .input-port .port-dot {
    background: #7C3AED;
}

.instruction-item .output-port .port-dot {
    background: #10B981;
}

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

.connection-port.connecting .port-dot {
    animation: pulse-port 1s ease-in-out infinite;
}

/* ========== CONNECTIONS SVG ========== */
.connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    /* Width and height are set dynamically in JS to match canvas */
    pointer-events: none;
    z-index: 10000 !important;

    /*z-index: -100000 !important;*/
}

.connection-line {
    pointer-events: stroke;
    cursor: pointer;
    transition: stroke-width 0.2s ease, opacity 0.2s ease;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: calc(1px / var(--zoom-scale, 1)); /* Maintains 2px visual thickness */
    opacity: 0.5;
    /* Solid lines by default - only animate when active */
}

.connection-line:hover {
    stroke-width: 4;
    opacity: 1;
    stroke-width: calc(4px / var(--zoom-scale, 1));
}

.connection-line.delete-hover {
    stroke: #EF4444 !important;
    stroke-width: 4;
    stroke-width: calc(4px / var(--zoom-scale, 1));
}

@keyframes flow {
    0% {
        stroke-dashoffset: 0;
    }
    100% {
        stroke-dashoffset: -30;
    }
}

.connection-line.active {
    stroke-dasharray: calc(6px / var(--zoom-scale, 1)) calc(12px / var(--zoom-scale, 1));
    animation: flow 0.8s linear infinite;
    opacity: 1 !important;
    stroke-width: calc(3px / var(--zoom-scale, 1)) !important;
}

/* ========== CONNECTED ITEMS STYLING ========== */
.canvas-item[data-connection-type="source"] {
    border: 1px solid #ccc !important;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

.canvas-item[data-connection-type="output"] {
    border: 1px solid var(--color-hover) !important; /* #10B981 */
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.canvas-item[data-connection-type="instruction"] {
    border: 1px solid transparent !important;
    box-shadow: 0 0 0 10px rgba(124, 58, 237, 0.3);
}

/*body.dark-theme .canvas-item[data-connection-type="source"] {
    border-color: var(--color-hover) !important;
    box-shadow: 0 0 10px rgba(96, 165, 250, 0.3);
}

body.dark-theme .canvas-item[data-connection-type="output"] {
    border-color: #34D399 !important;
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.3);
}

body.dark-theme .canvas-item[data-connection-type="instruction"] {
    border-color: #A78BFA !important;
    box-shadow: 0 0 10px rgba(167, 139, 250, 0.3);
}
*/
@keyframes pulse-glow {
    0%, 100% { 
        box-shadow: 0 0 10px rgba(var(--glow-color), 0.3);
    }
    50% { 
        box-shadow: 0 0 20px rgba(var(--glow-color), 0.5);
    }
}

.canvas-item[data-connection-type="source"] {
    --glow-color: 59, 130, 246;
    animation: pulse-glow 3s ease-in-out infinite;
}

.canvas-item[data-connection-type="output"] {
    --glow-color: 16, 185, 129;
    animation: pulse-glow 3s ease-in-out infinite;
}

.canvas-item[data-connection-type="instruction"] {
    --glow-color: 124, 58, 237;
    animation: pulse-glow 3s ease-in-out infinite;
}

.item-run-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    background: #7C3AED;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s ease;
}

/* Only show run buttons when hovering direct items, not section containers */
.canvas-item:hover:not(.section-container) .item-run-btn {
    display: flex;
}

.section-container > .canvas-item:hover .item-run-btn {
    display: flex;
}

.item-run-btn:hover {
    background: #6D28D9;
    transform: scale(1.1);
}

@keyframes updateFlash {
    0% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0.4); }
    50% { box-shadow: 0 0 20px 10px rgba(124, 58, 237, 0); }
    100% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0); }
}

.canvas-item.updated {
    animation: updateFlash 0.5s ease-out;
}



/* Image model dropdown */
/* Image Model Selector - matching model-selector style */


.image-model-selector {
    display: flex
;
    align-items: center;
    gap: 4px;
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    margin: -4px -8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    
}

.image-model-button {
   /* display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: var(--text-sm);
    color: #999;
    background: transparent;*/
}

.image-model-selector:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ccc;
}

.image-model-label {
    font-size: var(--text-sm);
    font-weight: 500;
}

.image-model-dropdown-menu {
    position: absolute;
    bottom: 100%;
    right: 50px;
    margin-bottom: 4px;
    background: #2a2a2a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px;
    min-width: 120px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.image-model-dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    /*transform: translateY(0);*/
}

.image-model-option {
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 12px;
    color: #999;
}

.image-model-option:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.image-model-option.selected {
    background: rgba(124, 58, 237, 0.2);
    color: #A78BFA;
}

/* Status feedback */
.instruction-status {
    padding: 6px 12px;
    font-size: 10px;
    margin: 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #888;
    transition: all 0.2s;
    position: absolute;
    box-sizing: border-box;
    bottom: -44px;
    right: 0;
    left: 0;
}

.instruction-status.info {
    color: #64B5F6;
    background: rgba(33, 150, 243, 0.1);
}

.instruction-status.success {
    color: #81C784;
    background: rgba(76, 175, 80, 0.1);
}

.instruction-status.error {
    color: #E57373;
    background: rgba(244, 67, 54, 0.1);
}

/* Make sure resize handle is visible */
.instruction-item .resize-handle {
    opacity: 0;
    transition: opacity 0.2s;
}

/* .instruction-item:hover .resize-handle {
    opacity: 1;
} */

/* ========== AI BADGE ========== */
.ai-generated-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #7C3AED;
    color: white;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: var(--font-semibold);
    animation: fadeIn 0.3s ease-out;
    z-index: 10;
}

.ai-generated-badge.fade-out {
    animation: fadeOut 0.5s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

/* ========== ERROR FLASH ========== */
.canvas-item.error-flash {
    animation: errorFlash 0.5s ease-in-out 2;
}

@keyframes errorFlash {
    0%, 100% { 
        border-color: #EF4444;
        box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
    }
    50% { 
        border-color: #DC2626;
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.8);
    }
}

/* Add to instruction item CSS */
.instruction-item .resize-handle {
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* .instruction-item:hover .resize-handle {
    opacity: 0.5;
} */

/* Ensure instruction container doesn't block resize handle */
.instruction-container {
    pointer-events: none;
}

.instruction-container * {
    pointer-events: auto;
}

/* ========== DRAWING CONTROLS CONTAINER ========== */
.drawing-tool-container {
    position: relative;
    display: inline-block;
}

.drawing-controls-container {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: var(--color-bw);
    border-radius: var(--radius-lg);
    padding: var(--space-sm);
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.95);
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
    pointer-events: none;
    min-width: 200px;
}

.drawing-controls-container.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.drawing-controls-compact {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.tool-select-compact {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    min-width: 40px;
}

.tool-btn-compact {
    width: 28px;
    height: 28px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tool-btn-compact:hover {
    background: var(--color-hover);
    border-color: var(--color-accent);
}

.color-preview {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    background: #000000;
    border: 1px solid rgba(0,0,0,0.1);
}

.opacity-control-compact {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 80px;
}

.opacity-slider-compact {
    -webkit-appearance: none;
    width: 60px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    outline: none;
}

.opacity-slider-compact::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--color-accent);
    border-radius: 50%;
    cursor: pointer;
}

.opacity-slider-compact::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--color-accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.opacity-label-compact {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    min-width: 24px;
    text-align: right;
}

/* Active flow animation for connections */
.connection-line.active-flow {
    stroke: #00ff88 !important; /* Bright green color for active state */
    stroke-dasharray: calc(8px / var(--zoom-scale, 1)) calc(4px / var(--zoom-scale, 1)) !important;
    animation: flowActive 0.6s linear infinite !important;
    /* Removed: drop-shadow, stroke-width changes */
}

@keyframes flowActive {
    0% {
        stroke-dashoffset: 0;
    }
    100% {
        stroke-dashoffset: -15;
    }
}

/* More obvious execution pulse for items */
.instruction-item.instruction-processing {
    /*animation: processingPulse 0.8s ease-in-out infinite !important;
    background: rgba(124, 58, 237, 0.15) !important;
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.4) !important;*/
}

@keyframes processingPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(124, 58, 237, 0.4);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 0 30px rgba(124, 58, 237, 0.6);
    }
}

/* Output update animation */
.canvas-item.output-updating {
    animation: outputPulse 0.6s ease-out;
}

@keyframes outputPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}


/* Markdown-specific styles */
.markdown-code-block {
    background: var(--color-surface-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: var(--text-sm);
    line-height: 1.5;
    margin: 8px 0;
}

.markdown-inline-code {
    background: var(--color-surface-secondary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
}

.markdown-quote {
    border-left: 3px solid var(--color-primary);
    padding-left: 16px;
    margin: 8px 0;
    color: var(--color-text-secondary);
    font-style: italic;
}

/* Better list styling in text items */
/*.rich-text-editor ul,
.rich-text-editor ol {
    margin: 8px 0;
    padding-left: 24px;
}

.rich-text-editor li {
    margin: 4px 0;
}

.rich-text-editor h1 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 12px 0 8px 0;
}

.rich-text-editor h2 {
    font-size: 1.3em;
    font-weight: 600;
    margin: 10px 0 6px 0;
}

.rich-text-editor h3 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 8px 0 4px 0;
}*/


/* Grid overlay */



.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
    background-image: radial-gradient(
        circle at center,
        var(--color-grid) 0,
        var(--color-grid) calc(1.25px / var(--zoom-scale, 1)), /* Scales inversely */
        transparent calc(0.5px / var(--zoom-scale, 1)),
        transparent 100%
    );
    background-size: calc(max(var(--grid-base-unit), var(--grid-base-unit) / var(--zoom-scale, 1))) calc(max(var(--grid-base-unit), var(--grid-base-unit) / var(--zoom-scale, 1))); /* Scale grid spacing with zoom, but not smaller than base unit */
    background-position: calc(max(var(--grid-base-unit), var(--grid-base-unit) / var(--zoom-scale, 1)) / 2) calc(max(var(--grid-base-unit), var(--grid-base-unit) / var(--zoom-scale, 1)) / 2); /* Center grid dots on snap points */
}

.grid-overlay.visible {
    opacity: 1;
}

/* Hide grid when zoomed out too far for performance */
@supports (zoom: 1) {
    .grid-overlay.visible {
        opacity: calc(clamp(0, var(--zoom-scale, 1) - 0.2, 1));
    }
}

/* Grid toggle button */
#toggleGrid {
    /*background: none;*/
    border: none;
    padding: 8px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    color: var(--color-fg);
}

#toggleGrid:hover {
    opacity: 1;
}

#toggleGrid.active {
    opacity: 1;
    color: var(--color-accent);
}







/* WEB ELEMENTS */

/* Web Element Item Styles */
.web-element-item {
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-width: 200px;
    min-height: 150px;
}

.web-element-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: white;
}

.web-element-iframe {
    background: white;
}

.web-element-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.web-element-item:hover .web-element-controls {
    opacity: 1;
}

.web-element-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--color-surface);
    border: 0px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: rgba(0,0,0, 0.6);
}

.web-element-btn:hover {
    background: rgba(255,255,255, 0.6);
    color: black;
    border-color: var(--color-primary);
}

.dark-theme .web-element-btn {
    color: rgba(255,255,255, 0.6);
    background: rgba(0,0,0, 0.8);
}

/* Active state */
.web-element-item.web-element-active {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-alpha);
}

/* Expanded state */
.web-element-btn.expand-btn.expanded {
    background: var(--color-primary);
    color: white;
}

/* Editor Modal */
.web-element-editor-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.web-element-editor-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.web-element-editor-content {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 800px;
    height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.web-element-editor-header {
    padding: 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.web-element-editor-header h3 {
    margin: 0;
    font-size: 18px;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.close-btn:hover {
    opacity: 1;
}

.web-element-editor-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.editor-tabs {
    display: flex;
    gap: 0;
    padding: 0 20px;
    border-bottom: 1px solid var(--color-border);
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--color-text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--color-text);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.editor-panels {
    flex: 1;
    position: relative;
    min-height: 0;
}

.editor-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 20px;
    display: none;
}

.editor-panel.active {
    display: block;
}

.code-editor {
    width: 100%;
    height: 100%;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: var(--text-sm);
    line-height: 1.5;
    padding: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-background);
    resize: none;
}

.web-element-editor-footer {
    padding: 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.save-btn, .cancel-btn {
    padding: 8px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.save-btn {
    background: var(--color-primary);
    color: white;
}

.save-btn:hover {
    background: var(--color-primary-dark);
}

.cancel-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.cancel-btn:hover {
    background: var(--color-background);
}

/* Fullscreen View */
.web-element-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-background);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s;
}

.web-element-fullscreen.show {
    opacity: 1;
}

.fullscreen-header {
    padding: 16px;
    display: flex;
    justify-content: flex-end;
    position: fixed;
    top: 0;
    /*background: var(--color-surface);*/
    /*border-bottom: 1px solid var(--color-border);*/
}

.close-fullscreen-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 0px solid var(--color-border);
    background: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: fixed;
    right: 20px;
}

.dark-theme .close-fullscreen-btn {
    background: rgba(255,255,255,0.2);
}

.close-fullscreen-btn:hover {
    background: var(--color-background);
}

.dark-theme .close-fullscreen-btn:hover {
    background: rgba(255,255,255,0.5);
}


.fullscreen-iframe {
    flex: 1;
    border: none;
    background: white;
}

/* Dark theme adjustments */
.dark-theme .web-element-container,
.dark-theme .web-element-iframe,
.dark-theme .fullscreen-iframe {
    background: #1a1a1a;
}




/* Conversation */
/* ========== CONVERSATIONAL INSTRUCTIONS - ULTRA MINIMAL ========== */
.instruction-item {
    transition: all 0s ease !important;
}

.instruction-item.conversation-mode {
    min-height: 400px;
}

/* Hide initial input when in conversation mode */
.instruction-item.conversation-mode .instruction-input {
    display: none;
}

/* Keep footer visible in conversation mode but hide some elements */
.instruction-item.conversation-mode .instruction-footer {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding-top: 8px;
    border-top: 0px solid rgba(0, 0, 0, 0.06);
}

/* Hide run button and loading in conversation mode */
/*.instruction-item.conversation-mode .instruction-run-btn,*/
.instruction-item.conversation-mode .instruction-loading {
    display: none !important;
}

/* Show conversation toggle */
.instruction-item.has-output .conversation-toggle,
.instruction-item.conversation-mode .conversation-toggle {
    display: flex !important;
}

.conversation-view {
    display: none;
    flex-direction: column;
    height: 100%;
    min-height: 200px;
    padding: 0;
}

.instruction-item.conversation-mode .conversation-view {
    display: flex;
}

.conversation-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: transparent;
    margin-bottom: 8px;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
}

/* Ultra minimal speech bubbles */
.conversation-message {
    padding: 8px 12px;
    border-radius: 16px;
    font-size: var(--text-base);
    line-height: 1.5;
    font-family: var(--font-sans);
    color: var(--color-fg);
    max-width: 80%;
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
}

.conversation-message.user {
    align-self: flex-end;
    background: rgba(0, 0, 0, 0.04);
    margin-left: 20%;
}

.conversation-message.assistant {
    align-self: flex-start;
    /*background: rgba(124, 58, 237, 0.08);*/
    margin-right: 20%;
    padding: 0;
}

body.dark-theme .conversation-message.user {
    background: rgba(255, 255, 255, 0.06);
}

body.dark-theme .conversation-message.assistant {
    /*background: rgba(0, 0, 0, 0.2);*/
}

.conversation-message.assistant.clarification {
    background: rgba(255, 193, 7, 0.08);
}

/* Single input area at bottom - minimal style */
.conversation-input-footer {
    display: flex;
    gap: 6px;
    align-items: flex-end;
    padding: 0;
}

.conversation-input {
    flex: 1;
    min-height: 32px;
    max-height: 80px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    font-size: var(--text-base);
    font-family: var(--font-sans);
    resize: none;
    outline: none;
    color: var(--color-fg);
    transition: all 0 ease;
}

body.dark-theme .conversation-input {
    background: rgba(255, 255, 255, 0.04);
}

.conversation-input:focus {
    background: rgba(0, 0, 0, 0.04);
}

body.dark-theme .conversation-input:focus {
    background: rgba(255, 255, 255, 0.1);
}

/* Minimal send button */

.conversation-input-footer .instruction-run-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 16px;
    opacity: 0.6;
    transition: all 0s ease;
}

.conversation-input-footer .instruction-run-btn:hover {
    opacity: 1;
    background: rgba(124, 58, 237, 0.08);
}

/* Output history indicator - more subtle */
.output-history-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 10px;
    color: var(--color-text-secondary);
    opacity: 0.4;
    display: none;
}

.instruction-item.has-history .output-history-indicator {
    display: none;
}

.output-history-nav {
    display: flex;
    gap: 2px;
    align-items: center;
}

.history-btn {
    width: 16px;
    height: 16px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--color-text-secondary);
    opacity: 0.6;
}

.history-btn:hover:not(:disabled) {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}

.history-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
}

/* System messages - very subtle */
.conversation-message.system {
    align-self: center;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 11px;
    opacity: 0.5;
    margin: 0;
    padding: 4px 8px;
    max-width: none;
}

/* Conversation input port - follows same pattern as connection ports */
.conversation-input-port {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    /*width: 16px;*/
    height: 16px;
    /*background: #F59E0B;*/
    border: 0px solid var(--color-bg);
    border-radius: 50%;
    cursor: crosshair;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
    top: auto;
}

/* Show conversation input port on hover like other connection ports */
.canvas-item:hover:not(.section-container) .conversation-input-port {
    opacity: 0.7;
}

.section-container > .canvas-item:hover .conversation-input-port {
    opacity: 0.7;
}

.conversation-input-port:hover {
    opacity: 1 !important;
}

/* Show when connecting */
body:has(.connection-port.connecting) .canvas-item .conversation-input-port {
    opacity: 1;
}

/* Hide during drawing mode like other ports */
.drawing-mode-active .canvas-item:hover .conversation-input-port,
.drawing-mode-active .section-container > .canvas-item:hover .conversation-input-port {
    opacity: 0 !important;
}

.drawing-mode-active .conversation-input-port:hover {
    opacity: 0 !important;
    transform: none !important;
}

/* Animation for conversation flow */
.conversation-connection {
    stroke: #F59E0B !important;
    stroke-dasharray: 5, 3;
    animation: conversation-flow 1s linear infinite;
}

@keyframes conversation-flow {
    to {
        stroke-dashoffset: -8;
    }
}

/* Piped input flash effect - more subtle */
@keyframes piped-flash {
    0%, 100% { 
        background: rgba(0, 0, 0, 0.02);
    }
    50% { 
        background: rgba(245, 158, 11, 0.08);
    }
}

.instruction-footer-actions {
    display: flex;
    gap: 0px;
}
.conversation-toggle.btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 16px;
    opacity: 0.6;
    transition: all 0.2s ease;
    cursor: pointer;
}

.conversation-toggle.btn:hover {
    opacity: 1;
}


body.dark-theme .conversation-toggle.btn {
    color: white;
}

.schema-toggle.btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 16px;
    opacity: 0.6;
    transition: all 0.2s ease;
    cursor: pointer;
}

.schema-toggle.btn:hover {
    opacity: 1;
}

body.dark-theme .schema-toggle.btn {
    color: var(--color-fg);
    margin-right: -5px;
}

/* Expand conversation area when item is not active */
.instruction-item.conversation-mode:not(.item-active) .conversation-view {
    height: calc(100% + 120px);
}

.instruction-item.conversation-mode:not(.item-active) .conversation-messages {
    max-height: calc(100vh - 200px);
}



/* OUTPUT SELECTOR */

.output-type-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    margin: -4px -8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.output-type-selector:hover {
    background: rgba(0, 0, 0, 0.05);
}
body.dark-theme .output-type-selector:hover {
    background: rgba(255, 255, 255, 0.05);
}

.output-type-button {
    display: flex;
    align-items: center;
    gap: 4px;
}

.output-type-label {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.output-type-dropdown-menu {
    position: absolute;
    bottom: 100%;
    left: 60px;
    margin-bottom: 4px;
    background: #2a2a2a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px;
    min-width: 140px;
    display: none;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.output-type-dropdown-menu.show {
    display: block;
}

.output-type-option {
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    color: #aaa;
}

.output-type-option:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}
body.dark-theme .output-type-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.output-type-option.selected {
    color: #7C3AED;
    font-weight: 500;
}
.output-type-option.selected:hover {
    color: #8B5CF6;
}










/* Make sure these styles are in your CSS */
.canvas-item.item-active .drag-overlay {
    pointer-events: none !important;
}

/* Keep line selection overlay interactive when item is active */
.canvas-item.item-active .line-selection-overlay {
    pointer-events: all !important;
}

.canvas-item.item-active {
    /*box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);*/
}

/* Ensure interactive elements work when activated */
.canvas-item.item-active .rich-text-editor,
.canvas-item.item-active .ql-editor,
.canvas-item.item-active a,
.canvas-item.item-active button,
.canvas-item.item-active input,
.canvas-item.item-active iframe,
.canvas-item.item-active video {
    pointer-events: all !important;
}



/* Alignment guide lines */

.alignment-guide {
    position: absolute;
    background: var(--color-muted);
    opacity: 0.4;
    pointer-events: none;
    z-index: 999999999;
    box-shadow: 0 0 calc(2px / var(--zoom-scale, 0.5)) var(--color-muted);
}

/* Section center alignment guides have a dashed pattern */
.alignment-guide.section-center {
    background: transparent;
    background-image: repeating-linear-gradient(
        0deg,
        var(--color-muted),
        var(--color-muted) 4px,
        transparent 4px,
        transparent 8px
    );
    opacity: 0.6;
}

.alignment-guide.section-center.horizontal {
    background-image: repeating-linear-gradient(
        90deg,
        var(--color-muted),
        var(--color-muted) 4px,
        transparent 4px,
        transparent 8px
    );
}

.alignment-guide.horizontal {
    height: calc(0.5px / var(--zoom-scale, 1));
    width: 100%;
}

.alignment-guide.vertical {
    width: calc(0.5px / var(--zoom-scale, 1));
    height: 100%;
}

/* Highlight for aligned items */
.canvas-item.alignment-highlight {
    /*opacity: 0.4;*/
    border: 1px solid transparent !important;
    box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) var(--color-selected) !important;
    /* z-index: 999 !important; */ /* Removed to prevent z-index jumping */
}

/*.canvas-item.snapping {
    transition: left 0.15s ease-out, top 0.15s ease-out, width 0.15s ease-out, height 0.15s ease-out !important;
}
.canvas-item.snapping * {
    transition: none !important;
}*/


.back-to-content-btn {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    
    display: none; /* Hidden by default */
    align-items: center;
    gap: 8px;
    
    padding: 12px 20px;
    background: var(--color-bw);
    border: 0px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    font-size: 14px;
    font-weight: 500;
    
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(8px);
    
    cursor: pointer;
    transition: all 0.2s ease;
}

.back-to-content-btn:hover {
    background: var(--color-bg-tertiary);
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.back-to-content-btn.show {
    display: flex;
    animation: slideInDown 0.3s ease;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.back-to-content-btn svg {
    flex-shrink: 0;
}




/* select layout */

.floating-sort-selector {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-sm);
    /*color: var(--color-text);*/
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s ease;
    background: var(--color-bw);
    border: 1px solid var(--color-border);
    /*min-width: 120px;*/
}

.floating-sort-selector:hover {
    background: var(--color-bg-tertiary);
}

.sort-selector-button {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    justify-content: space-between;
}

.sort-selector-label {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    flex: 1;
    white-space: nowrap;
}

.dropdown-arrow {
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.floating-sort-selector.open .dropdown-arrow {
    transform: rotate(180deg);
}

.sort-dropdown-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: 4px;
    background: var(--color-bw);
    border: 0px solid var(--color-border);
    border-radius: 8px;
    padding: 2px;
    min-width: 140px;
    display: none;
    transform: translateY(10px);
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

.sort-dropdown-menu.show {
    display: block;
    transform: translateY(0);
}

.sort-option {
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: var(--text-sm);
    transition: background 0.2s ease;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.sort-option:hover {
    background: var(--color-bg-tertiary);
}

.sort-option.selected {
    color: var(--color-accent);
    font-weight: 500;
    background: var(--color-bg-tertiary);
}

/* Dark theme specific adjustments */
body.dark-theme .sort-dropdown-menu {
    background: #2a2a2a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

body.dark-theme .sort-option {
    color: #aaa;
}

body.dark-theme .sort-option.selected {
    color: #7C3AED;
}



/* Add this to your main CSS file */
.context-menu {
    position: fixed;
    background: var(--color-bw);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 4px 0;
    min-width: 160px;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: transform 0.15s ease, margin-top 0.15s ease;
    backdrop-filter: blur(10px);
    margin-top: 10px;
}

.context-menu.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
    margin-top: 0;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: var(--text-base);
    color: var(--color-fg);
    transition: background-color 0.15s ease;
}

.context-menu-item:hover {
   background-color: var(--color-hover);
   color: var(--color-muted);
}

.context-menu-item.danger {
    color: var(--color-error);
}

.context-menu-item.danger:hover {
    background: var(--color-error-bg);
}

.context-menu-item svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.context-menu-divider {
    height: 1px;
    background: var(--color-muted);
    margin: 4px 0;
    opacity: 0.25;
}

/* Locked item styling */
.canvas-item.locked {
    position: absolute;
}

.canvas-item.locked::after {
    content: '';
    position: absolute;
    top: calc(4px / var(--zoom-scale, 1));
    right: calc(4px / var(--zoom-scale, 1));
    width: calc(16px / var(--zoom-scale, 1));
    height: calc(16px / var(--zoom-scale, 1));
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2' ry='2'/%3E%3Ccircle cx='12' cy='16' r='1'/%3E%3Cpath d='M7 11V7a5 5 0 1 1 10 0v4'/%3E%3C/svg%3E") no-repeat center;
    background-size: calc(12px / var(--zoom-scale, 1)) calc(12px / var(--zoom-scale, 1));
    transition: all 0.1s ease;
    z-index: 10;
    pointer-events: none;
}

/* Prevent dragging of locked items */
.canvas-item.locked .drag-overlay {
    cursor: not-allowed !important;
}


/* Add this to your context menu CSS */
.context-menu-item.has-submenu {
    position: relative;
}

.submenu-arrow {
    margin-left: auto;
    opacity: 0.5;
}

.context-submenu {
    position: absolute;
    left: 100%;
    top: 0;
    background: var(--color-bw);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 4px 0;
    min-width: 140px;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-8px);
    transition: all 0.15s ease;
    z-index: 10001;
    backdrop-filter: blur(10px);
}

.context-menu-item.has-submenu:hover .context-submenu,
.context-submenu:hover {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.context-submenu-item:hover {
   color: var(--color-muted);
}

.context-menu-item.ai-action {
    /*color: #7C3AED;*/
}

.context-menu-divider.ai-divider {
    /*background: linear-gradient(90deg, #7C3AED, transparent);*/
}







/*** BEGIN LOGIC NODES ITEMS ***/

/* Base Logic Item */
.logic-item {
    border: none !important;
    background: var(--color-bw) !important;
    width: 120px;
    max-width: 200px;
    min-width: 200px;
    height: 80px;
    padding: var(--space-sm) !important;
    border-radius: 24px !important;
}

/* Output Target Node - Small Circle */
.logic-item.logic-output-target {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    border-radius: 50% !important;
    padding: 8px !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logic-item.logic-output-target .logic-content {
    height: 100% !important;
    padding: 0;
    margin: 0;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.logic-item.logic-output-target .logic-label {
    display: none;
}

.logic-item.logic-output-target .logic-config {
    display: none;
}

.logic-item.logic-output-target .logic-icon {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin: 0 !important;
    color: var(--color-fg) !important;
}

.logic-item.logic-output-target .logic-icon svg {
    width: 20px !important;
    height: 20px !important;
    color: inherit;
}

/* Ensure output-target items are visible during sorting/selection */
.logic-item.logic-output-target.multi-selected,
.logic-item.logic-output-target:hover {
    transform: scale(1.1);
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
}

/* Trigger Node - Same Size as Output Target */
.logic-item.logic-trigger {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    min-height: 48px !important;
    border-radius: 50% !important;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute !important;
}

.logic-item.logic-trigger .logic-content {
    height: 100% !important;
    padding: 0;
    margin: 0;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.logic-item.logic-trigger .trigger-run-btn {
   /* width: 100% !important;
    height: 100% !important;
    border-radius: 50% !important;
    border: none !important;
    background: transparent !important;
    color: var(--color-fg) !important;
    font-size: 14px !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    text-align: center !important;*/
}

.logic-item.selected {
    border: 1px solid rgba(0,0,0, 0.02) !important;
    box-sizing: border-box;
    background: var(--color-bw) !important;
}

/* Hide individual logic item selection styling for multi-select */
.logic-item.multi-selected {
    /* Individual styling removed for cleaner unified selection */
}

body.dark-theme .logic-item {
    background: var(--color-bw) !important;
}

body.dark-theme .logic-item.selected {
    border: 1px solid rgba(255, 255, 255, 0.02) !important;
}

body.dark-theme .logic-item.multi-selected {
    /* Individual styling removed for cleaner unified selection */
}

/* Logic Content */
.logic-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.logic-icon {
    display: none !important;
}

.logic-label {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    color: var(--color-fg);
    margin-bottom: 4px;
    letter-spacing: 0.01em;
    opacity: 0.9;
}

.logic-config {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    background: rgba(0, 0, 0, 0.03);
    padding: 12px;
    border-radius: 12px;
    margin-top: 4px;
    transition: all 0.2s ease;
    font-weight: 500;
    line-height: 1.4;
    max-width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.logic-config svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.logic-config:hover svg {
    opacity: 1;
}

body.dark-theme .logic-config {
    background: rgba(255, 255, 255, 0.05);
}

.logic-config:hover {
    color: var(--color-text-primary);
    background: rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

body.dark-theme .logic-config:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Special styling for different logic node types */
.logic-delay .logic-config {
    background: rgba(245, 158, 11, 0.1);
    color: #F59E0B;
}

.logic-queue .logic-config {
    background: rgba(59, 130, 246, 0.1);
    color: #3B82F6;
}

.logic-merger .logic-config {
    background: rgba(16, 185, 129, 0.1);
    color: #10B981;
}

.logic-trigger .logic-config {
    display: none; /* Already hidden for trigger */
}

.logic-scheduler .logic-config {
    background: rgba(99, 102, 241, 0.1);
    color: #6366F1;
}

.logic-api .logic-config {
    background: rgba(236, 72, 153, 0.1);
    color: #EC4899;
}

.logic-filter .logic-config {
    background: rgba(168, 85, 247, 0.1);
    color: #A855F7;
}

.logic-output .logic-config {
    background: rgba(20, 184, 166, 0.1);
    color: #14B8A6;
}

/* Connection Ports - Properly Scaled */
.logic-item .connection-port {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: crosshair;
    opacity: 0;
    transition: opacity 0s ease;
    z-index: 10;
    transform: translateY(-50%) scale(calc(1 / var(--zoom-scale, 1)));
}

.logic-item:hover .connection-port {
    opacity: 1;
}

.connection-port:hover {
    opacity: 1 !important;
}

.logic-item .input-port {
    left: -13px;
}

.logic-item .output-port {
    right: -13px;
}


.logic-item .port-dot {
    width: 20px;
    height: 20px;
    background: #7C3AED;
    border: 10px solid var(--color-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
}

.logic-item .port-dot svg {
    color: black;
}

.dark-theme .logic-item .port-dot svg {
    color: white;
}

.dark-theme .logic-item .port-dot {
    border: 10px solid var(--color-bg);
}

.logic-item .output-port .port-dot {
    background: #3B82F6;
}

.logic-item .port-dot span {
    color: white;
    font-size: var(--text-md);
    /*font-weight: bold;*/
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logic-item .input-port .port-dot span {
    display: none;
}

/* Logic Item States */
.logic-item.delay-active {
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}

.logic-item .logic-config.delay-showing {
    color: #F59E0B;
    font-weight: 500;
}

.logic-item.queue-has-items {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.logic-item.queue-full {
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
}

.logic-item.merger-partial {
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}

.logic-item.merger-complete {
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
}

/* Action Buttons */
.queue-release-btn,
.merger-reset-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(calc(1 / var(--zoom-scale, 1)));
    z-index: 10000000000000;
}

.queue-release-btn {
    background: #F59E0B;
    color: white;
}

.merger-reset-btn {
    background: var(--color-text-secondary);
    color: white;
}

/* Config Modal - Fixed Size Structure */
.logic-config-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.logic-config-content {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    width: 480px;
    height: 520px;
    max-width: 90vw;
    max-height: 90vh;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

body.dark-theme .logic-config-content {
    background: #1a1a1a;
}

.logic-config-content h3 {
    margin: 0;
    padding: 24px 24px 20px 24px;
    font-size: 18px;
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    border-bottom: 1px solid var(--color-border);
}

.config-field {
    margin-bottom: 16px;
}

.config-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: var(--font-medium);
    color: var(--color-text-primary);
}

.config-field input,
.config-field select {
    width: 100%;
    padding: var(--item-padding);
    border: 0px solid var(--color-muted);
    border-radius: var(--radius-lg);
    font-size: var(--text-base);
    background: rgba(0, 0, 0, 0.05) !important;
    color: var(--color-text-primary);
    font-family: var(--font-main);
    margin-bottom: 2px;
}
.config-field input[type='checkbox'] {
    width: auto;
}

body.dark-theme .config-field input,
body.dark-theme .config-field select {
    background: rgba(255,255,255, 0.05) !important;
    border-color: var(--color-muted);
    color: #fff;
}

.config-field input:focus,
.config-field select:focus {
    outline: none;
    border-color: var(--color-accent);
}

.config-field small {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    line-height: 1.4;
}

/* Modal Body - Scrollable Content Area */
.logic-config-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: 100px; /* Extra padding for fixed footer */
    max-height: calc(520px - 140px); /* Total height minus header and footer */
}

/* For modals without logic-config-body wrapper - temporary fix */
.logic-config-content > .config-tabs,
.logic-config-content > .config-tab-content,
.logic-config-content > .config-field {
    position: relative;
}

/* Scrollable content area for modals without proper wrapper */
.logic-config-content {
    position: relative;
}

.logic-config-content > *:not(h3):not(.config-buttons):not(.config-tabs) {
    max-height: calc(520px - 240px);
    overflow-y: auto;
    padding: 0 24px 20px 24px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.logic-config-content > *:not(h3):not(.config-buttons):not(.config-tabs)::-webkit-scrollbar {
    width: 8px;
}

.logic-config-content > *:not(h3):not(.config-buttons):not(.config-tabs)::-webkit-scrollbar-track {
    background: transparent;
}

.logic-config-content > *:not(h3):not(.config-buttons):not(.config-tabs)::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
}

.logic-config-content > *:not(h3):not(.config-buttons):not(.config-tabs)::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

/* Config Tabs - Styled Like Output Type Selector */
.config-tabs {
    display: flex;
    gap: 8px;
    margin: 0 24px 20px 24px;
    padding: 4px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    align-items: center;
}

body.dark-theme .config-tabs {
    background: rgba(255, 255, 255, 0.05);
}

.config-tab-btn {
    flex: 1;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-family: var(--font-main);
}

.config-tab-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.dark-theme .config-tab-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.config-tab-btn.active {
    background: var(--color-bg);
    color: var(--color-text-primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body.dark-theme .config-tab-btn.active {
    background: var(--color-surface-2);
}

/* Tab Content */
.config-tab-content,
.api-tab-content {
    display: none;
}

.config-tab-content.active,
.api-tab-content.active {
    display: block;
}

/* Fixed Footer Buttons */
.config-buttons {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 20px 24px;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
}

.config-buttons button {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: var(--font-medium);
    cursor: pointer;
    border: none;
    font-family: var(--font-main);
    transition: all 0.2s ease;
}

.config-buttons .cancel-btn {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-text-primary);
}

body.dark-theme .config-buttons .cancel-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.config-buttons .cancel-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

body.dark-theme .config-buttons .cancel-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.config-buttons .save-btn {
    background: var(--color-accent);
    color: white;
}

.config-buttons .save-btn:hover {
    background: #0052a3;
    transform: translateY(-1px);
}

/* API Config Modal - Same Fixed Size */
.api-config-modal .logic-config-content,
.output-config-modal .logic-config-content,
.data-source-config-modal .logic-config-content,
.browser-config-modal .logic-config-content,
.scheduler-config-modal .logic-config-content {
    /* All modals use same size */
}

.api-config-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--color-border);
}

body.dark-theme .api-config-tabs {
    border-bottom-color: var(--color-muted);
}

.api-tab-btn {
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    color: var(--color-text-secondary);
    transition: all 0.2s ease;
    font-family: var(--font-main);
}

.api-tab-btn.active {
    border-bottom-color: var(--color-accent);
    background: var(--color-surface-1);
    color: var(--color-text-primary);
}

.api-tab-btn:hover {
    color: var(--color-text-primary);
}

/* Header Management */
.header-item {
    display: flex;
    gap: 8px;
    margin: 5px 0;
    align-items: center;
}

.header-item input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--color-muted);
    border-radius: 4px;
    font-size: 12px;
    background: var(--color-surface-2);
    color: var(--color-text-primary);
    font-family: var(--font-main);
}

body.dark-theme .header-item input {
    background: var(--color-surface-2);
    border-color: var(--color-muted);
    color: #fff;
}

.header-item input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.remove-header-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: var(--color-danger);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.remove-header-btn:hover {
    opacity: 0.8;
}

.add-header-btn {
    padding: 6px 12px;
    border: 1px solid var(--color-muted);
    background: var(--color-surface-1);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: var(--color-text-primary);
    font-family: var(--font-main);
    transition: all 0.2s ease;
}

body.dark-theme .add-header-btn {
    background: var(--color-surface-2);
    border-color: var(--color-muted);
    color: #fff;
}

.add-header-btn:hover {
    background: var(--color-hover);
}

/* Body Input */
.body-input {
    width: 100%;
    font-family: var(--font-code);
    font-size: 12px;
    padding: 8px;
    border: 1px solid var(--color-muted);
    border-radius: 4px;
    resize: vertical;
    background: var(--color-surface-2);
    color: var(--color-text-primary);
    min-height: 120px;
}

body.dark-theme .body-input {
    background: var(--color-surface-2);
    border-color: var(--color-muted);
    color: #fff;
}

.body-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* Test Button */
.test-btn {
    background: #10B981;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: var(--font-medium);
    font-family: var(--font-main);
    transition: all 0.2s ease;
}

.test-btn:hover {
    opacity: 0.9;
}

.test-btn:disabled {
    background: var(--color-text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Switch specific styles */
.conditions-container h4 {
    margin: 16px 0 12px 0;
    font-size: 16px;
    font-weight: var(--font-medium);
    color: var(--color-text-primary);
}

.condition-item {
    margin: 12px 0;
    padding: 16px;
    border: 0px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface-1);
}

body.dark-theme .condition-item {
    background: #252525;
    border-color: #444;
}

.condition-header {
    font-size: 14px;
    font-weight: var(--font-medium);
    color: var(--color-text-primary);
    margin-bottom: 8px;
}

.condition-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.condition-row input,
.condition-row select {
    padding: 6px 10px;
    border: 0px solid var(--color-muted);
    border-radius: 4px;
    font-size: var(--text-base);
    background: var(--color-surface-2);
    color: var(--color-text-primary);
    min-width: 80px;
    font-family: var(--font-main);
}

body.dark-theme .condition-row input,
body.dark-theme .condition-row select {
    background: var(--color-surface-2);
    border-color: var(--color-muted);
    color: #fff;
}

/* Trigger Button */
/*.trigger-run-btn {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    background: #10B981;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-weight: var(--font-bold);
    cursor: pointer;
    font-size: 11px;
    font-family: var(--font-main);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}
*/
.trigger-run-btn {
    position: absolute;
    /*bottom: 10px;*/
    /*right: 10px;*/
    width: 36px;
    height: 36px;
    background: transparent;
    color: var(--color-fg);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
   /* padding: 0
    padding-left: 3px;
    padding-top: 1px;*/
    flex-shrink: 1;
    line-height: 32px;
    font-size: 20px;
    text-indent: 2px;
   
}

.trigger-run-btn:hover {
    background: #059669;
    transform: scale(1.05);
}

.trigger-run-btn:active {
    transform: scale(0.95);
}


/* Scheduler Toggle Button - Same styling as trigger button */
.scheduler-toggle-btn, .logic-send .trigger-run-btn {
    position: absolute;
    bottom: 10px;
    /* transform: translateX(-50%); */
    left: 78%;
    width: 32px;
    height: 32px;
    background: var(--color-active);
    color: var(--color-fg);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex !important
;
    /* align-items: center; */
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    /* padding-left: 3px; */
    /* padding-top: 1px; */
    flex-shrink: 1;
    line-height: 32px;
    font-size: 14px;
    text-indent: 3px;
}

.scheduler-toggle-btn:hover,
.logic-send .trigger-run-btn:hover {
    background: #059669;
    transform: scale(1.05);
}

.scheduler-toggle-btn:active {
    transform: translateX(-50%) scale(0.95);
}

/* Trigger Active State */
.logic-item.trigger-active {
    border-color: #10B981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3) !important;
    animation: trigger-pulse 0.3s ease-out;
}

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

/* Trigger Node Height */
.logic-item.logic-trigger {
    min-height: 80px;
}

/* Custom Payload Field */
.custom-payload-field {
    margin-top: 10px;
}

.custom-payload-input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--color-muted);
    border-radius: 4px;
    font-family: var(--font-code);
    font-size: 12px;
    resize: vertical;
    background: var(--color-surface-2);
    color: var(--color-text-primary);
    min-height: 60px;
}

body.dark-theme .custom-payload-input {
    background: var(--color-surface-2);
    border-color: var(--color-muted);
    color: #fff;
}

.custom-payload-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* Test Trigger Button */
.test-trigger-btn {
    background: #F59E0B;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: var(--font-medium);
    font-family: var(--font-main);
    transition: all 0.2s ease;
}

.test-trigger-btn:hover {
    opacity: 0.9;
}

.test-trigger-btn:disabled {
    background: var(--color-text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

.logic-item.api-loading {
    border-color: #F59E0B;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.logic-item.api-loading .logic-config {
    color: #F59E0B;
    font-weight: bold;
}

/*** END LOGIC NODES ITEMS ***/




/* OVERRIDES */

.item-style-toolbar {
    top: -100000px;
    left: -100000px;
}

.canvas-item {
    border-radius: var(--radius-item) !important;
    border: 1px solid transparent !important;
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) transparent !important;*/
}

.canvas-item:hover:not(.section-container) {
    /*border-color: transparent !important;*/
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) var(--color-selected) !important;*/
}

.canvas-item.line-item:hover {
    border-color: transparent !important;
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) transparent !important;*/
}
.canvas-item.line-item.selected:hover {
    border-color: transparent !important;
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) transparent !important;*/
}

.canvas-item.line-item {
    overflow: visible !important;
    box-sizing: border-box;
    /* Remove minimum width constraint that causes small lines to rescale */
    min-width: 0 !important;
    min-height: 0 !important;
    border: none !important;
}

.canvas-item.line-item.selected,
.canvas-item.line-item.active {
    border-color: transparent !important;
    box-sizing: border-box;
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) transparent !important;*/
}

.canvas-item:hover:has(body.drawing-mode-active) {
   
}

.section-container > .canvas-item:hover {
    border-color: transparent !important;
    box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) var(--color-selected) !important;
}


.canvas-item.selected {
    /*border: 1px solid transparent !important;*/
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.5)) var(--color-selected) !important;*/
     /* Visible in Windows high-contrast themes */
   /* outline-color: var(--color-selected);
    outline-width: 1px;
    outline-style: solid;*/
}
.canvas-item.multi-selected {
    /*border: 1px solid transparent !important;*/
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.15)) var(--color-accent) !important;*/
   
   /* outline-color: var(--color-multi-selected);
    outline-width: 1px;
    outline-style: solid;*/
}

.canvas-item.item-active {
    /*border: 1px solid transparent !important;*/
    /*box-shadow: 0px 0px 0px calc(2px / var(--zoom-scale, 0.5)) var(--color-accent) !important;*/
   

     /* Visible in Windows high-contrast themes */
  /*  outline-color: var(--color-selected);
    outline-width: 2px;
    outline-style: solid;*/
}


.ql-container.ql-snow {
    border: 0;
}

.canvas-item:hover,
.line-item.multi-selected,
.line-item.item-active {
    border: 1px solid transparent !important;
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.15)) red !important;*/
}

.section-container.drag-over{
    border-color: transparent !important;
    /*box-shadow: 0px 0px 0px calc(2px / var(--zoom-scale, 0.5)) var(--color-accent) !important;*/
}
.section-container.selected, .section-container.multi-selected, .code-item.selected,  .code-item.item-active{
    /*box-shadow: 0px 0px 0px calc(2px / var(--zoom-scale, 0.5)) var(--color-accent) !important;*/
}
.connection-line {
    z-index: 9999999999 !important;
}


body.drawing-mode-active .canvas-item:hover {
    /*box-shadow: 0px 0px 0px calc(0px / var(--zoom-scale, 0.5)) var(--color-selected) !important;*/
}


/* Override selection styling for line items */

.canvas-item:hover, .line-item.multi-selected, .line-item.item-active {
    /*box-shadow: 0px 0px 0px calc(1px / var(--zoom-scale, 0.15)) transparent !important;*/
}

.canvas-item.line-item > .delete-btn {
    display: none !important;
}



/* THEME OVERRIDES */

/* ========== TOOLBAR ========== */
.toolbar {
    background: transparent;
    border: none;
    padding: 20px;
    padding-left: 10px;
    /*backdrop-filter: blur(10px);*/
    /*-webkit-backdrop-filter: blur(10px);*/
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toolbar-group {
    display: flex;
    gap: 2px;
}

/* Left toolbar-group (first one) styling */
.toolbar-group:first-child {
   /* background: var(--color-bw);
    border: 1px solid var(--color-border);*/
    border-radius: var(--radius-lg);
    padding: var(--space-xs);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 12px;
    opacity: 0.6;
}

.toolbar-spacer {
    flex: 1;
}

/* Centered Board Picker */
.board-switcher-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

/* Right Menu */
.right-menu-container {
    position: relative;

}

.right-menu-container:hover .right-menu {
    display: flex;
}

.right-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: calc(var(--space-xs) * -1);
    background: var(--color-bw);
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-xs);
    z-index: 1000;
    gap: 2px;
    flex-direction: column;
    animation: floatInMenu 0.2s ease forwards;
}

.right-menu .tool-btn {
    justify-content: center;
    width: 36px;
    height: 36px;
    position: relative;
}

/* Remove tooltip from menu toggle button */
#menuToggle {
    pointer-events: auto;
}

#menuToggle::before,
#menuToggle::after {
    display: none !important;
}

/* Animation for appearance */
@keyframes floatInMenu {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


/* Tooltip styles are handled by the existing .custom-tooltip class */

/* Bottom Left Indicators */
.bottom-left-indicators {
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    z-index: 100;
    background: var(--color-bg);
    padding: 6px;
    border-radius: var(--radius-md);
    border: var(--border);
    box-shadow: var(--shadow-sm);
}

/* Minimal buttons */
.tool-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    color: var(--color-text);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.tool-btn:hover {
    background: var(--color-hover);
    color: var(--color-fg);
}

.tool-btn:active {
    transform: scale(0.96);
}

.tool-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

.tool-btn.danger:hover {
    color: #ff3b30;
    background: rgba(255, 59, 48, 0.1);
}

/* Minimal select */
.tool-select {
    background: transparent;
    color: var(--color-fg);
    border: 0px solid var(--color-border);
    border-radius: var(--radius-sm) !important;
    font-size: var(--text-base);
    
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-repeat: no-repeat;
    background-position: right 8px center;
    
    /* Auto width with constraints */
    width: auto;
    max-width: 200px; /* Maximum width (optional) */
    text-align: center !important;
}
.tool-select:hover {
    background: var(--color-hover);
}

.tool-select:focus {
    outline: none;
}

/* Zoom indicator */
.zoom-indicator {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text);
    padding: 0 8px;
    opacity: 0.3;
    transition: opacity 0.2s ease;
}

.zoom-indicator.zoom-active {
    opacity: 1;
}

/* Zoom-scale utility classes - scale elements inversely with zoom level */
/* NOTE: Only use these for elements OUTSIDE the canvas. Canvas elements are already scaled by parent transform */

.zoom-scale {
    --zoom-scale: 1;
    transform: scale(calc(1 / var(--zoom-scale)));
    transform-origin: center;
    transition: transform 0.1s ease;
}

/* For canvas elements, use CSS properties with calc() instead of transform classes */
.zoom-scale-border {
    --zoom-scale: 1;
    border-width: calc(1px / var(--zoom-scale));
    transition: border-width 0.1s ease;
}

.zoom-scale-shadow {
    --zoom-scale: 1;
    box-shadow: 0px 0px 0px calc(2px / var(--zoom-scale)) var(--color-accent);
    transition: box-shadow 0.1s ease;
}

/* Theme toggle icons */
#themeToggle .sun-icon {
    display: block;
}

#themeToggle .moon-icon {
    display: none;
}

body.dark-theme #themeToggle .sun-icon {
    display: none;
}

body.dark-theme #themeToggle .moon-icon {
    display: block;
}

/* ========== VIEWPORT ========== */
#viewport {
    background: black;
    top: 0px;
}

/* ========== CANVAS ============ */

#canvas {
/*    border: 10px solid black;
    box-sizing: border-box;
*/}


/* ========== CANVAS ITEMS ========== */
.canvas-item {
    background: var(--color-surface);
    border: 1px solid transparent;
    border-radius: var(--radius);
    box-shadow: none;
    transition: var(--transition);
}

.canvas-item:not(.selected):hover {
    border-color: rgba(0, 0, 0, 0.1);
}

body.dark-theme .canvas-item:not(.selected):hover {
    /*border-color: rgba(255, 255, 255, 0.1);*/
}

.canvas-item.selected {
    border-color: var(--color-accent);
}

/* Minimal delete button */
/*.delete-btn {
    width: 24px;
    height: 24px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    font-size: 16px;
    opacity: 0;
    transition: var(--transition);
    z-index: 10;
    position: absolute;
}*/

/* Only show delete buttons when hovering direct items, not section containers */
.canvas-item:hover:not(.section-container) .delete-btn {
    opacity: 1;
}

.section-container > .canvas-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: #ff3b30;
    border-color: #ff3b30;
    color: white;
}

.resize-handle {
    z-index: 10;
    position: absolute;
}

/* Resize handle */
.resize-handle::before {
    border-color: transparent transparent var(--color-text) transparent;
    opacity: 0.3;
}

/* Remove the triangle from directional resize handles */
.resize-handle-n::before,
.resize-handle-s::before,
.resize-handle-e::before,
.resize-handle-w::before,
.resize-handle-nw::before,
.resize-handle-ne::before,
.resize-handle-sw::before,
.resize-handle-se::before {
    display: none;
    z-index: 100000000000;
}

/* Disabled: Only show resize handle hover when hovering direct items, not section containers */
/* .canvas-item:hover:not(.section-container) .resize-handle::before {
    opacity: 0.6;
} */

/* .section-container > .canvas-item:hover .resize-handle::before {
    opacity: 0.6;
} */

/* Text items */
.text-item {
    background: transparent;
    /*background: var(--color-surface);*/
}

/*.rich-text-editor {
    font-size: 14px;
    line-height: 1.6;
    color: var(--color-fg);
}

.rich-text-editor:empty:before {
    color: var(--color-text);
}
*/
/* Code items */
.code-item {
    background: #1a1a1a !important;
}

.code-item pre {
     font-family: var(--font-code-main) !important;
}

/* Link items */
.link-item {
    background: var(--color-surface);
}

.link-title {
    /*font-weight: 500;*/
}

/* Image items */
.image-item {
    /*border: none;*/
    /*background: transparent !important;*/
}

/* ========== GREENISH MULTI-SELECT ========== */

/* Multi-selected items */
.canvas-item.multi-selected {
    border-color: var(--color-accent);
    border-width: 2px;
    /*box-sizing: border-box;*/
    background: var(--backgroundcolor-accent);
    /*background: rgba(16, 163, 127, 0.03);*/
    /*animation: multiSelectPulse 300ms cubic-bezier(0.4, 0, 0.2, 1);*/
}

@keyframes multiSelectPulse {
    0% {
        transform: scale(0.98);
        border-color: rgba(16, 163, 127, 0.5);
    }
    50% {
        transform: scale(1.01);
        border-color: rgba(16, 163, 127, 1);
    }
    100% {
        transform: scale(1);
        border-color: var(--color-accent);
    }
}

/* Multi-select overlay */
.multi-select-overlay {
    /*background: linear-gradient(135deg, 
        rgba(16, 163, 127, 0.05) 0%, 
        rgba(16, 163, 127, 0.02) 100%);*/
    border-radius: var(--radius);
    animation: overlayFadeIn 200ms ease-out;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Selection box */
.selection-box {
    border: 1px solid var(--color-accent);
    background: var(--backgroundcolor-accent);
    animation: selectionGrow 100ms ease-out;
}

@keyframes selectionGrow {
    from {
        opacity: 0.5;
    }
    to {
        opacity: 1;
    }
}

/* Shift-hover overlay */
.shift-hover-overlay {
    background: transparent;
    transition: background 150ms ease;
}

body.shift-held .canvas-item:hover .shift-hover-overlay {
    /*background: rgba(16, 163, 127, 0.08);*/
    cursor: pointer;
}

/* Multiple items selected - stronger visual feedback */
.canvas-item.multi-selected:nth-child(odd) {
    animation-delay: 50ms;
}

.canvas-item.multi-selected:nth-child(even) {
    animation-delay: 100ms;
}

/* Dark theme multi-select adjustments */
body.dark-theme .canvas-item.multi-selected {
    border-color: var(--color-accent);
    /*background: rgba(25, 195, 125, 0.05);*/
}

body.dark-theme .selection-box {
    border-color: var(--color-accent);
    background: rgba(25, 195, 125, 0.1);
}

body.dark-theme .multi-select-overlay {
  /*  background: linear-gradient(135deg, 
        rgba(25, 195, 125, 0.08) 0%, 
        rgba(25, 195, 125, 0.03) 100%);*/
}

/* ========== SELECTION TOOLBAR ========== */
.selection-toolbar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body.dark-theme .selection-toolbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.selection-toolbar button {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: var(--text-base);
}

.selection-toolbar button:hover {
    background: var(--color-hover);
}

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

.toolbar-separator {
    background: var(--color-border);
    opacity: 0.5;
}

/* ========== HELP MODAL ========== */
.help-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

body.dark-theme .help-modal {
    background: rgba(0, 0, 0, 0.6);
}

.help-modal.show {
    display: flex;
}

.help-modal-content {
    background: var(--color-surface);
    border-radius: 16px;
    max-width: 480px;
    width: 100%;
    max-height: 70vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
    animation: modalSlideIn 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

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

.help-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--color-surface-2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-fg);
    /* Safe GPU acceleration for close button */
    will-change: transform, opacity;
    transform: translateZ(0);
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.help-modal-close:hover {
    background: var(--color-hover);
    transform: scale(1.05) rotate(90deg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.help-modal-close svg {
    width: 20px;
    height: 20px;
}

.help-modal h2 {
    margin: 0 0 20px 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.help-section {
    margin-bottom: 20px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
}

.help-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-section li {
    padding: 6px 0;
    font-size: var(--text-base);
    color: var(--color-text);
    line-height: 1.5;
}

.help-section strong {
    color: var(--color-fg);
    font-weight: 500;
}

/* ========== MINIMAL SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 10px;
}

/* Modal scrollbar */
.help-modal-content::-webkit-scrollbar {
    width: 6px;
}

/* ========== ABOUT MODAL ========== */
.about-header {
    text-align: center;
    margin-top: var(--space-xs);
    margin-bottom: var(--space-xs);
}

.about-logo {
    margin-bottom: 0px;
}

.about-logo svg {
    color: #000000; /* Pure black */
}

/* White logo in dark mode */
body.dark-theme .about-logo svg {
    color: #ffffff; /* Pure white */
}

.about-title {
    margin: 0;
    color: var(--color-fg);
    letter-spacing: -0.01em;
}

.about-content {
    text-align: center;
    color: var(--color-fg);
    max-width: 330px;
    margin-left: auto;
    margin-right: auto;
}

.about-content p {
    margin: 0 0 16px 0;
    opacity: 0.8;
}

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

.about-footer {
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
    opacity: 0.5;
}

.about-footer p {
    margin: 2px 0;
    font-size: var(--text-xs);
    color: var(--color-fg);
}

.version-info {
    opacity: 0.7;
}

.copyright {
    opacity: 0.6;
}

/* ========== DOCUMENT MODAL ========== */
.document-modal {
    position: fixed;
    inset: 0;
    /*background: rgba(0, 0, 0, 0.025);*/
    /*background: var(--color-bg);*/
    /*background: rgba(240,240,240, 0.9);*/
    /*backdrop-filter: blur(0px);*/
    z-index: 2000;
    padding: 0px;
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
    transition: background 0.15s ease, backdrop-filter 0.15s ease, visibility 0.15s ease, opacity 0.15s ease;
    overflow-y: auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding-top: 0vh;
    padding-bottom: 5vh;
    pointer-events: none;
    /* Safe GPU acceleration for document modal */
    will-change: opacity, visibility;
    transform: translateZ(0);
}

body.dark-theme .document-modal.show {
    /*background: var(--color-bg);*/
}

.document-modal-spacer {
    width: 10px;
}

.document-modal.show {
     /*background: var(--color-bg);*/
    /*backdrop-filter: blur(100px);*/
    pointer-events: none;
    visibility: visible;
    opacity: 1;
}

.document-modal::-webkit-scrollbar {
    width: 12px;
}

.document-modal::-webkit-scrollbar-track {
    background: transparent;
}

.document-modal::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 6px;
}

.document-modal::-webkit-scrollbar-thumb:hover {
    background: var(--color-muted);
}

.document-modal-content {
    background: var(--color-bg);
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Transition controlled by JavaScript */
    border-radius: var(--radius-item) !important;
    min-height: 70vh;
    border-radius: var(--radius-item);
    box-shadow: rgba(0, 0, 0, 0.05) 0px 25px 50px !important;
    overflow: visible;
    pointer-events: auto;
    /* Safe GPU acceleration for modal content */
    will-change: transform, opacity;
    transform: translate(-50%, -50%) translateZ(0);
}

.document-modal-close {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--color-surface-2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2001;
    color: var(--color-fg);
    /* Safe GPU acceleration for close button */
    will-change: transform, opacity;
    transform: translateZ(0);
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.document-modal-close:hover {
    background: var(--color-hover);
    transform: scale(1.05) rotate(90deg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.document-modal-close svg {
    width: 20px;
    height: 20px;
}

.document-editor-content {
    padding: 30px;
    border: none;
    outline: none;
    /*font-family: var(--font-main);*/
    /*font-family: -apple-system-ui-serif, serif;*/
    color: var(--color-fg);
    background: var(--color-surface);
    resize: none;
    box-sizing: border-box;
    min-height: calc(70vh - 120px);
}

.document-editor-content:empty::before {
    content: attr(placeholder);
    color: var(--color-muted);
    font-style: italic;
}

/* Document title */
.document-title {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 24px 0;
    padding: 8px 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--color-fg);
    width: 100%;
    min-height: 40px;
}

.document-title:empty::before {
    content: 'Untitled';
    color: var(--color-muted);
    font-style: normal;
}

/* Quill editor styling */
.document-editor-content .ql-editor {
    font-size: 16px;
    line-height: 1.4;
    color: var(--color-fg);
    padding: 0;
    border: none;
    outline: none;
}

.document-editor-content .ql-editor.ql-blank::before {
    color: var(--color-muted);
    font-style: italic;
}

.document-editor-content .ql-editor p {
    margin: 0;
    padding: 4px 0;
    min-height: 20px;
}

/* Prisma Block Editor Styles - Unique class names to avoid conflicts */
.prisma-block-editor {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    font-family: var(--font-main);
    background: transparent !important;
    border: none !important;
    outline: none !important;
    color: var(--color-text-primary) !important;
}

.prisma-editor-block {
    padding: 4px 2px;
    position: relative;
    transition: margin-left 0.2s ease;
    color: var(--color-text-primary);
    line-height: 1.5;
    min-height: 1.5em;
    font-size: 16px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
}

.prisma-editor-block:hover {
    background-color: var(--color-hover);
}

.prisma-editor-block:focus {
    outline: none;
}

.prisma-editor-block[contenteditable="true"]:empty:focus:before,
.prisma-todo-content[contenteditable="true"]:empty:focus:before {
    content: attr(data-placeholder);
    color: var(--color-text-muted);
    cursor: text;
    font-style: italic;
}

.prisma-single-selected-block {
    background-color: var(--color-selected);
}

.prisma-multi-selected-block {
    background-color: rgba(0, 102, 204, 0.1); /* Use design system blue */
}

/* Todo block styles */
.prisma-editor-block[data-block-type="todo"] {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.prisma-todo-checkbox {
    margin-top: 2px;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
}

.prisma-todo-content {
    flex: 1;
    outline: none;
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    font-size: 16px;
    line-height: 1.5;
    min-height: 1.5em;
}

.prisma-todo-content.line-through {
    text-decoration: line-through;
    opacity: 0.6;
}

/* Heading styles */
.prisma-editor-block[data-block-type="h1"] {
    font-size: 2em;
    font-weight: var(--font-semibold);
    margin: 0.67em 0;
}

.prisma-editor-block[data-block-type="h2"] {
    font-size: 1.5em;
    font-weight: var(--font-semibold);
    margin: 0.83em 0;
}

.prisma-editor-block[data-block-type="h3"] {
    font-size: 1.17em;
    font-weight: var(--font-semibold);
    margin: 1em 0;
}

/* List styles */
.prisma-editor-block[data-block-type="ul"] {
    list-style-type: disc;
    margin-left: 1.5rem;
}

.prisma-editor-block[data-block-type="ol"] {
    list-style-type: decimal;
    margin-left: 1.5rem;
}

/* Slash menu */
.prisma-slash-menu {
    position: fixed !important;
    background: var(--color-bw);
    border: var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: var(--space-sm);
    width: 250px;
    z-index: 10000 !important;
    display: none;
}

body.dark-theme .prisma-slash-menu {
    background: var(--color-surface-2);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.prisma-slash-menu-item {
    display: flex;
    align-items: center;
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text-primary);
    gap: 8px;
}

.prisma-slash-menu-item:hover,
.prisma-slash-menu-item.prisma-slash-selected {
    background-color: var(--color-hover);
}

.prisma-slash-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-medium);
    color: var(--color-text-secondary);
}

/* Custom toolbar */
.prisma-custom-toolbar {
    position: absolute;
    background: var(--color-surface-3);
    color: var(--color-bw);
    border-radius: var(--radius-md);
    padding: 4px 8px;
    display: none;
    z-index: 20;
    gap: 8px;
}

.prisma-toolbar-btn {
    background: none;
    border: none;
    color: var(--color-bw);
    padding: 4px 8px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-weight: var(--font-medium);
}

.prisma-toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.document-editor-content .ql-container,
.document-editor-content .ql-container.ql-snow {
    border: none !important;
    font-family: var(--font-main);
}

/* Bullet lists - only target non-checkbox lists */
.document-editor-content .ql-editor ul {
    padding-left: 20px;
    margin: 0;
}

.document-editor-content .ql-editor ul:not([data-checked]) li {
    list-style-type: disc;
    padding: 4px 0;
}

/* Checkbox lists - remove default bullet styling */
.document-editor-content .ql-editor ul[data-checked] li {
    list-style-type: none;
    padding: 4px 0;
}

/* Strike-through */
.document-editor-content .ql-editor s {
    text-decoration: line-through;
    color: var(--color-muted);
}






/* Focus indicator */
.document-editor-content > *:focus {
 /*   outline: none;
    background-color: #ffffff;*/
}

body.dark-theme .document-editor-content > *:focus {
    /*background-color: rgba(255, 255, 255, 0.02);*/
}

/* Simple contenteditable editor styles */
.document-editor-content.simple-editor {
    color: var(--color-fg);
    background: white;
    padding: 60px;
    min-height: calc(70vh - 120px);
    border: none;
    outline: none;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Block-like styling for all direct children */
.document-editor-content.simple-editor > * {
    position: relative;
    margin: 0;
    padding: 0;
    border-radius: 6px;
    transition: all 0.15s ease;
}

/* Hover effect for blocks */
.document-editor-content.simple-editor > *:hover,
.document-editor-content.simple-editor > *:active,
.document-editor-content.simple-editor > *.simulated-hover {
    /*background: rgba(0, 0, 0, 0.03);*/
}

/* Active/focused block */
.document-editor-content.simple-editor > *:focus,
.document-editor-content.simple-editor > *:focus-within,
.document-editor-content.simple-editor > *.slash-menu-active {
/*    background: rgba(59, 130, 246, 0.08);
    box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.3);*/
    outline: none;
}

/* Dark theme block hover/focus */
body.dark-theme .document-editor-content.simple-editor > *:hover,
body.dark-theme .document-editor-content.simple-editor > *.simulated-hover {
    /*background: rgba(255, 255, 255, 0.03);*/
}

body.dark-theme .document-editor-content.simple-editor > *:focus,
body.dark-theme .document-editor-content.simple-editor > *:focus-within,
body.dark-theme .document-editor-content.simple-editor > *.slash-menu-active {
  /*  background: rgba(59, 130, 246, 0.15);
    box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.5);*/
}


/* Empty blocks placeholder using data attribute */
.document-editor-content.simple-editor > .show-placeholder:focus::before {
    content: attr(data-placeholder);
    color: #9ca3af;
    opacity: 0.5;
    pointer-events: none;
    position: absolute;
    left: 0;
}

body.dark-theme .document-editor-content.simple-editor,
body.dark-theme .document-modal-content {
    background: black;
}

.document-editor-content.simple-editor h1 {
    font-size: 2.5em;
    font-weight: 700;
    margin: 0;
    color: var(--color-fg);
}

.document-editor-content.simple-editor h2 {
    font-size: 2em;
    font-weight: 600;
    margin: 0;
    color: var(--color-fg);
}

.document-editor-content.simple-editor h3 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 0;
    color: var(--color-fg);
}

.document-editor-content.simple-editor p {
    margin: 0;
}

.document-editor-content.simple-editor ul {
    padding-left: 20px;
    margin: 0;
}

.document-editor-content.simple-editor ul li {
    list-style-type: disc;
    padding: 0;
}

/* Simple checkbox styling for both old and new structures */
.document-editor-content.simple-editor .checkbox-wrapper,
.document-editor-content.simple-editor div:has(> input[type="checkbox"]) {
    display: block;
    margin: 0;
}

.document-editor-content.simple-editor .checkbox-wrapper input[type="checkbox"],
.document-editor-content.simple-editor div > input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
    vertical-align: middle;
}

.document-editor-content.simple-editor .checkbox-content {
    cursor: text;
    display: inline;
    outline: none;
}

.document-editor-content.simple-editor strong {
    font-weight: 700;
}

.document-editor-content.simple-editor em {
    font-style: italic;
}

.document-editor-content.simple-editor u {
    text-decoration: underline;
}

.document-editor-content.simple-editor s {
    text-decoration: line-through;
    color: var(--color-muted);
}

.document-editor-content.simple-editor br {
}

/* Placeholder for empty simple editor */
.document-editor-content.simple-editor:empty::before {
    content: 'Start writing...';
    color: var(--color-muted);
    font-style: italic;
    pointer-events: none;
}

/* Tab indentation levels */
.document-editor-content [data-indent="1"] {
    margin-left: 24px;
}
.document-editor-content [data-indent="2"] {
    margin-left: 48px;
}
.document-editor-content [data-indent="3"] {
    margin-left: 72px;
}
.document-editor-content [data-indent="4"] {
    margin-left: 96px;
}
.document-editor-content [data-indent="5"] {
    margin-left: 120px;
}

/* Visual indicator for indented blocks */
.document-editor-content [data-indent]:not([data-indent="0"]) {
    border-left: 2px solid rgba(0, 0, 0, 0.1);
    padding-left: 8px;
}

/* Dark theme support for indented blocks */
body.dark-theme .document-editor-content [data-indent]:not([data-indent="0"]) {
    border-left-color: rgba(255, 255, 255, 0.15);
}

/* Focus styles for simple editor */

/* Guard element at the end of editor to prevent content escaping */
.editor-end-guard {
    opacity: 0;
    pointer-events: none;
    user-select: none;
    min-height: 1.5em;
    margin: 0;
    padding: 0;
}

.editor-end-guard:empty::before {
    content: '\00a0'; /* Non-breaking space */
}

/* Editable heading with placeholder */
.editable-heading {
    position: relative;
    min-height: 1.2em; 
    margin-bottom: 32px;
}

.editable-heading:empty::before {
    content: attr(data-placeholder);
    color: var(--color-muted);
    opacity: 0.5;
    pointer-events: none;
}
.editable-heading.heading-empty::before {
    content: attr(data-placeholder);
    color: var(--color-fg);
    opacity: 0.1;
    pointer-events: none;
    position: absolute;
    left: 0;
    top: 0;
}

/* Document item canvas styles */
.document-item {
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    background: transparent !important;
}
.document-item.selected,
.document-item.item-active {
    background: transparent !important;
    border: 0;
    border-color: transparent;
    box-shadow: 0 32px 72px rgba(0, 17, 68, 0.18);
}

.document-item:hover {
    /*transform: translateY(-2px);*/
    /*box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);*/
}

.document-preview {
    padding: 0;
    height: 100%;
    position: relative;
    /*box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);*/
    overflow: hidden;
    border:0;
}

.document-miniature {
    background: var(--color-bw);
    border-radius: calc(var(--radius-item) + 0px);
    width: 140px;
    height: 196px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-main);
    font-size: 3px;
    line-height: 1.4;
    color: var(--color-text-primary);
    /*padding: 10px;*/
    box-sizing: border-box;
    overflow: hidden;
    pointer-events: none;
    border: 0px solid rgba(0, 0, 0, 0.1);
}
.document-miniature::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 80px;
    background: linear-gradient(to top, var(--color-bw), transparent);
    pointer-events: none;
}
.document-miniature-content {
    padding: 10px;
    height: 100%;
    box-sizing: border-box;
}

/* Miniature list styling */
.document-miniature-content ul {
    margin: 0;
}

.document-miniature-content h1 {
    margin-bottom: 10px !important;
}

/* Regular bullet lists in miniature */
.document-miniature-content ul:not([data-checked]) {
    padding-left: 1.5em;
}

.document-miniature-content ul:not([data-checked]) li {
    list-style-type: disc;
    font-size: 10px;
    line-height: 1.3;
}

/* Checkboxes in miniature - remove bullets and add checkbox symbols */
.document-miniature-content ul[data-checked] {
    padding-left: 0;
}

.document-miniature-content ul[data-checked] li {
    list-style-type: none !important;
    font-size: 10px;
    line-height: 1.3;
    position: relative;
    padding-left: 1.2em;
}

/* Add checkbox symbols */
.document-miniature-content ul[data-checked="false"] li::before {
    content: "☐";
    position: absolute;
    left: 0;
    top: 0;
    font-size: 10px;
    color: #666;
}

.document-miniature-content ul[data-checked="true"] li::before {
    content: "☑";
    position: absolute;
    left: 0;
    top: 0;
    font-size: 10px;
    color: #333;
}

/* Make sure no bullets appear for any checkbox list */
.document-miniature-content ul[data-checked] {
    list-style: none !important;
}


/* Keep original styles for other contexts */
.document-miniature h1 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 2px 0;
    line-height: 1.2;
}

.document-miniature h2 {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 2px 0;
    line-height: 1.2;
}

.document-miniature h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 1px 0;
    line-height: 1.2;
}

.document-miniature p,
.document-miniature div {
    margin: 0 0 1px 0;
    font-size: 10px;
    line-height: 1.3;
}

.document-miniature:empty::before {
    content: 'Title';
    color: var(--color-muted);
    font-style: italic;
}


/* Remove all unnecessary shadows */
* {
    box-shadow: none !important;
}

/* Only allow specific shadows */
.selection-toolbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

body.dark-theme .selection-toolbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.delete-btn {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
}

/* Focus states */
:focus {
    outline: none;
}

/* Drag states */
.canvas-item.dragging {
    opacity: 0.8;
}

/* Checkboxes */
.checkbox-wrapper input[type="checkbox"] {
    accent-color: var(--color-accent);
}

/* Preparing to drag - subtle pulse */
.canvas-item.preparing-drag {
    animation: holdPulse 0.4s ease-in-out;
}

@keyframes holdPulse {
    0% {
        transform: scale(1);
        border-color: var(--color-border);
    }
    50% {
        transform: scale(0.95);
        border-color: var(--color-accent);
    }
    100% {
        transform: scale(1);
        border-color: var(--color-accent);
    }
}

/* Ready to drag - visual feedback */
.canvas-item.drag-ready {
    border-color: var(--color-accent);
    /*background: rgba(16, 163, 127, 0.02);*/
    /*transform: scale(0.98);*/
    transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dragging state */
.canvas-item.dragging {
    opacity: 0.85;
    /*transform: scale(0.98);*/
    transition: opacity 150ms ease;
    cursor: grabbing !important;
}

/* Release animation - snap back */
.canvas-item:not(.dragging):not(.preparing-drag):not(.drag-ready) {
    transition: transform 20ms cubic-bezier(0.4, 0, 0.2, 1),
                border-color 200ms ease,
                background 10s0ms ease;
}

/* Dark theme adjustments */
body.dark-theme .canvas-item.drag-ready {
    background: rgba(25, 195, 125, 0.03);
}

/* Prevent animation conflicts with multi-select */
.canvas-item.multi-selected.preparing-drag {
    animation: none;
}

.canvas-item.multi-selected.drag-ready {
    /*transform: scale(0.98);*/
}

/* Smooth cursor transitions */
.canvas-item {
    /*cursor: move;*/
}

.canvas-item.preparing-drag,
.canvas-item.drag-ready {
    cursor: grab;
}

.canvas-item.dragging {
    cursor: grabbing !important;
}


.embed-item .iframe-wrapper {
    /*position: relative;*/
    /* pointer-events: none; Disable iframe interaction by default */
}

.embed-item iframe {
    /* pointer-events: none; Disable iframe interaction by default */
}

/* Enable iframe interaction only when not hovering controls */
.embed-item:not(:hover) .iframe-wrapper,
.embed-item:not(:hover) iframe {
    /*pointer-events: auto;*/
}

/* Ensure controls are always interactive */
.embed-item .delete-btn,
.embed-item .resize-handle {
    /*pointer-events: auto !important;*/
}

/* Optional: Add a subtle overlay on hover to make controls more visible */
/*.embed-item:hover .iframe-wrapper::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.05);
    pointer-events: none;
    border-radius: var(--radius);
}*/

body.dark-theme .embed-item:hover .iframe-wrapper::after {
    background: rgba(255, 255, 255, 0.05);
}


.model-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    padding: 12px;
    text-align: center;
}

.model-dropdown:empty::after {
    content: 'No API keys configured';
    padding: 12px;
    color: #666;
    display: block;
    text-align: center;
}

/* Scheduler Node Styles */
.logic-item.scheduler-active {
    border-color: #10B981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3) !important;
}

.logic-item.scheduler-paused {
    border-color: #F59E0B !important;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3) !important;
}

.logic-item.scheduler-error {
    border-color: #EF4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.4) !important;
    animation: scheduler-error-pulse 0.6s ease-out;
}

.logic-item.trigger-active {
    animation: scheduler-trigger-pulse 0.3s ease-out;
}

@keyframes scheduler-error-pulse {
    0% { 
        transform: scale(1);
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.4);
    }
    50% { 
        transform: scale(1.02);
        box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.6);
    }
    100% { 
        transform: scale(1);
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.4);
    }
}

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

.scheduler-start-btn,
.scheduler-pause-btn,
.scheduler-stop-btn {
    background: none;
    border: 1px solid var(--color-muted);
    color: var(--color-text);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.scheduler-start-btn:hover {
    background: rgba(16, 185, 129, 0.1);
    border-color: #10B981;
    color: #10B981;
}

.scheduler-pause-btn:hover {
    background: rgba(245, 158, 11, 0.1);
    border-color: #F59E0B;
    color: #F59E0B;
}

.scheduler-stop-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #EF4444;
    color: #EF4444;
}

/* ========== THEME STYLES (moved from theme.css) ========== */


:root {
    /*--font-main: -apple-system, BlinkMacSystemFont, sans-serif;*/
    --font-code-main: ui-monospace, monospace;
    
    /* Minimal palette */
    --color-bg: #f5f5f5;
    --color-bg-modal: #e5e5e5;
    --color-fg: #000;
    --color-border: #f0f0f0;
    --color-accent: rgba(50,120,255,1.0);
    --backgroundcolor-accent: rgba(50,120,255,0.1);
    /*--color-selected: rgba(50,120,255,0.1);*/
    
    --color-surface: #fff;
    --color-text: #666;
    --color-hover: rgba(0, 0, 0, 0.03);
    
    /*--radius: 12px;*/
    --transition: all 0s cubic-bezier(0.4, 0, 0.2, 1), width 0s, height 0s, top 0s, bottom 0s, right 0s, left 0s;
    --selectBorder: 3px;
}

body.dark-theme {   
    --color-bg: #111;
    --color-bg-modal: #151515;
    --color-fg: #fff;
    --color-border: #222;
    --color-accent: rgba(222,100,100,1.0); 
    --backgroundcolor-accent: rgba(222,100,100,0.1);

  
    --color-surface: #1a1a1a;
    --color-text: #999;
    --color-hover: rgba(255, 255, 255, 0.1);
}


body {
    background: var(--color-bg);
    color: var(--color-fg);
}

/* ========== TOOLBAR ========== */
.toolbar {
    background: transparent;
    border: none;
    padding: 20px;
    padding-left: 10px;
    /*backdrop-filter: blur(10px);*/
    /*-webkit-backdrop-filter: blur(10px);*/
}

.toolbar-group {
    display: flex;
    gap: 2px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 12px;
    opacity: 0.6;
}

.toolbar-spacer {
    flex: 1;
}

/* Minimal buttons */
.tool-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    color: var(--color-text);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.tool-btn:hover {
    background: var(--color-hover);
    color: var(--color-fg);
}

.tool-btn:active {
    transform: scale(0.96);
}

.tool-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

.tool-btn.danger:hover {
    color: #ff3b30;
    background: rgba(255, 59, 48, 0.1);
}

/* Minimal select */
.tool-select {
    padding: 0 10px;
    background: transparent;
    color: var(--color-fg);
    border: 0px solid var(--color-border);
    border-radius: var(--radius);
    appearance: none;
    background-repeat: no-repeat;
    background-position: right 8px center;
    
    /* Auto width with constraints */
}
.tool-select:hover {
    background: var(--color-hover);
}

.tool-select:focus {
    outline: none;
}

/* Zoom indicator */
.zoom-indicator {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text);
    padding: 0 8px;
}

/* Theme toggle icons */
#themeToggle .sun-icon {
    display: block;
}

#themeToggle .moon-icon {
    display: none;
}

body.dark-theme #themeToggle .sun-icon {
    display: none;
}

body.dark-theme #themeToggle .moon-icon {
    display: block;
}

/* ========== VIEWPORT ========== */
#viewport {
    background: black;
    top: 0px;
}

/* ========== CANVAS ============ */

#canvas {
/*    border: 10px solid black;
    box-sizing: border-box;
*/}


/* ========== CANVAS ITEMS ========== */
.canvas-item {
    background: var(--color-surface);
    border: 1px solid transparent;
    border-radius: var(--radius);
    box-shadow: none;
    transition: var(--transition);
}

.canvas-item:not(.selected):hover {
    border-color: rgba(0, 0, 0, 0.1);
}

body.dark-theme .canvas-item:not(.selected):hover {
    border-color: rgba(255, 255, 255, 0.1);
}

.canvas-item.selected {
    border-color: var(--color-accent);
}

/* Minimal delete button */
/*.delete-btn {
    width: 24px;
    height: 24px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    font-size: 16px;
    opacity: 0;
    transition: var(--transition);
    z-index: 10;
    position: absolute;
}*/

.canvas-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: #ff3b30;
    border-color: #ff3b30;
    color: white;
}

.resize-handle {
    z-index: 10;
    position: absolute;
}

/* Resize handle */
.resize-handle::before {
    border-color: transparent transparent var(--color-text) transparent;
    opacity: 0.3;
}

/* Remove the triangle from directional resize handles */
.resize-handle-n::before,
.resize-handle-s::before,
.resize-handle-e::before,
.resize-handle-w::before,
.resize-handle-nw::before,
.resize-handle-ne::before,
.resize-handle-sw::before,
.resize-handle-se::before {
    display: none;
}

/* .canvas-item:hover .resize-handle::before {
    opacity: 0.6;
} */

/* Text items */
.text-item {
    background: transparent;
    /*background: var(--color-surface);*/
}

/*.rich-text-editor {
    font-size: 14px;
    line-height: 1.6;
    color: var(--color-fg);
}

.rich-text-editor:empty:before {
    color: var(--color-text);
}
*/
/* Code items */
.code-item {
    background: #1a1a1a !important;
}

.code-item pre {
     font-family: var(--font-code-main) !important;
}

/* Link items */
.link-item {
    background: var(--color-surface);
}

.link-title {
    /*font-weight: 500;*/
}

/* Image items */
.image-item {
    /*border: none;*/
    /*background: transparent !important;*/
}

/* ========== GREENISH MULTI-SELECT ========== */

/* Multi-selected items */
.canvas-item.multi-selected {
    border-color: var(--color-accent);
   /* border-width: 2px;
    box-sizing: border-box;
   */ background: var(--backgroundcolor-accent);
    /*background: rgba(16, 163, 127, 0.03);*/
    /*animation: multiSelectPulse 300ms cubic-bezier(0.4, 0, 0.2, 1);*/
}

@keyframes multiSelectPulse {
    0% {
        transform: scale(0.98);
        border-color: rgba(16, 163, 127, 0.5);
    }
    50% {
        transform: scale(1.01);
        border-color: rgba(16, 163, 127, 1);
    }
    100% {
        transform: scale(1);
        border-color: var(--color-accent);
    }
}

/* Multi-select overlay */
.multi-select-overlay {
    /*background: linear-gradient(135deg, 
        rgba(16, 163, 127, 0.05) 0%, 
        rgba(16, 163, 127, 0.02) 100%);*/
    border-radius: var(--radius);
    animation: overlayFadeIn 200ms ease-out;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Selection box */
.selection-box {
    border: 1px solid var(--color-accent);
    background: var(--backgroundcolor-accent);
    animation: selectionGrow 100ms ease-out;
}

@keyframes selectionGrow {
    from {
        opacity: 0.5;
    }
    to {
        opacity: 1;
    }
}

/* Shift-hover overlay */
.shift-hover-overlay {
    background: transparent;
    transition: background 150ms ease;
}

body.shift-held .canvas-item:hover .shift-hover-overlay {
    /*background: rgba(16, 163, 127, 0.08);*/
    cursor: pointer;
}

/* Multiple items selected - stronger visual feedback */
.canvas-item.multi-selected:nth-child(odd) {
    animation-delay: 50ms;
}

.canvas-item.multi-selected:nth-child(even) {
    animation-delay: 100ms;
}

/* Dark theme multi-select adjustments */
body.dark-theme .canvas-item.multi-selected {
    border-color: var(--color-accent);
    /*background: rgba(25, 195, 125, 0.05);*/
}

body.dark-theme .selection-box {
    border-color: var(--color-accent);
    /*background: rgba(25, 195, 125, 0.1);*/
}

body.dark-theme .multi-select-overlay {
  /*  background: linear-gradient(135deg, 
        rgba(25, 195, 125, 0.08) 0%, 
        rgba(25, 195, 125, 0.03) 100%);*/
}

/* ========== SELECTION TOOLBAR ========== */
.selection-toolbar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body.dark-theme .selection-toolbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.selection-toolbar button {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 13px;
}

.selection-toolbar button:hover {
    background: var(--color-hover);
}

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

.toolbar-separator {
    background: var(--color-border);
    opacity: 0.5;
}

/* ========== HELP MODAL ========== */
.help-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

body.dark-theme .help-modal {
    background: rgba(0, 0, 0, 0.6);
}

.help-modal.show {
    display: flex;
}

.help-modal-content {
    background: var(--color-surface);
    border-radius: 16px;
    max-width: 480px;
    width: 100%;
    max-height: 70vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
    animation: modalSlideIn 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

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

.help-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--color-surface-2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-fg);
    /* Safe GPU acceleration for close button */
    will-change: transform, opacity;
    transform: translateZ(0);
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.help-modal-close:hover {
    background: var(--color-hover);
    transform: scale(1.05) rotate(90deg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.help-modal-close svg {
    width: 20px;
    height: 20px;
}

.help-modal h2 {
    margin: 0 0 20px 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.help-section {
    margin-bottom: 20px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
}

.help-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-section li {
    padding: 6px 0;
    font-size: 13px;
    color: var(--color-text);
    line-height: 1.5;
}

.help-section strong {
    color: var(--color-fg);
    font-weight: 500;
}

/* ========== MINIMAL SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 10px;
}

/* Modal scrollbar */
.help-modal-content::-webkit-scrollbar {
    width: 6px;
}

/* Remove all unnecessary shadows */
* {
    box-shadow: none !important;
}

/* Only allow specific shadows */
.selection-toolbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

body.dark-theme .selection-toolbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.delete-btn {
    /*box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;*/
    transform: scale(calc(1 / var(--zoom-scale, 1))) !important;
}

/* Focus states */
:focus {
    outline: none;
}

/* Drag states */
.canvas-item.dragging {
    opacity: 0.8;
}

/* Checkboxes */
.checkbox-wrapper input[type="checkbox"] {
    accent-color: var(--color-accent);
}

/* Preparing to drag - subtle pulse */
.canvas-item.preparing-drag {
    animation: holdPulse 0.4s ease-in-out;
}

@keyframes holdPulse {
    0% {
        transform: scale(1);
        border-color: var(--color-border);
    }
    50% {
        transform: scale(0.95);
        border-color: var(--color-accent);
    }
    100% {
        transform: scale(1);
        border-color: var(--color-accent);
    }
}

/* Ready to drag - visual feedback */
.canvas-item.drag-ready {
    border-color: var(--color-accent);
    /*background: rgba(16, 163, 127, 0.02);*/
    /*transform: scale(0.98);*/
    transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dragging state */
.canvas-item.dragging {
    opacity: 0.85;
    /*transform: scale(0.98);*/
    transition: opacity 150ms ease;
    cursor: grabbing !important;
}

/* Release animation - snap back */
.canvas-item:not(.dragging):not(.preparing-drag):not(.drag-ready) {
    transition: transform 20ms cubic-bezier(0.4, 0, 0.2, 1),
                border-color 200ms ease,
                background 10s0ms ease;
}

/* Dark theme adjustments */
body.dark-theme .canvas-item.drag-ready {
    background: rgba(25, 195, 125, 0.03);
}

/* Prevent animation conflicts with multi-select */
.canvas-item.multi-selected.preparing-drag {
    animation: none;
}

.canvas-item.multi-selected.drag-ready {
    transform: scale(0.98);
}

/* Smooth cursor transitions */
.canvas-item {
    /*cursor: move;*/
}

.canvas-item.preparing-drag,
.canvas-item.drag-ready {
    cursor: grab;
}

.canvas-item.dragging {
    cursor: grabbing !important;
}


.embed-item .iframe-wrapper {
    /*position: relative;*/
    /* pointer-events: none; Disable iframe interaction by default */
}

.embed-item iframe {
    /* pointer-events: none; Disable iframe interaction by default */
}

/* Enable iframe interaction only when not hovering controls */
.embed-item:not(:hover) .iframe-wrapper,
.embed-item:not(:hover) iframe {
    /*pointer-events: auto;*/
}

/* Ensure controls are always interactive */
.embed-item .delete-btn,
.embed-item .resize-handle {
    /*pointer-events: auto !important;*/
}

/* Optional: Add a subtle overlay on hover to make controls more visible */
/*.embed-item:hover .iframe-wrapper::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.05);
    pointer-events: none;
    border-radius: var(--radius);
}*/

body.dark-theme .embed-item:hover .iframe-wrapper::after {
    background: rgba(255, 255, 255, 0.05);
}


.model-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    padding: 12px;
    text-align: center;
}

.model-dropdown:empty::after {
    content: 'No API keys configured';
    padding: 12px;
    color: #666;
    display: block;
    text-align: center;
}

/* ========== CONVERSATION MODE TOGGLE ========== */

.conversation-input-footer {
    display: flex !important;
    gap: 8px;
}

.conversation-input-container {
    position: relative;
    flex: 1;
}

.conversation-input {
    width: 100%;
    padding-right: 50px; /* Make space for toggle */
}

.conversation-mode-toggle {
    position: absolute;
    bottom: 12px;
    right: 6px;
    display: flex;
    /*background: rgba(0, 0, 0, 0.4);*/
    border-radius: 10px;
    padding: 1px;
    z-index: 10;
}

.mode-btn {
    padding: 2px 6px;
    border: none;
    border-radius: 2px;
    background: transparent;
    color: var(--color-fg);
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.1s ease;
    white-space: nowrap;
    opacity: 0.4;
}

.mode-btn.active {
    opacity: 1;
    color: var(--color-fg);
    background: var(--color-surface)
}

/* Reference image toggle styling */
.reference-image-toggle {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin-top: 8px;
    background: var(--color-surface-hover);
    border-radius: 6px;
    border: 1px solid var(--color-border);
}

.reference-toggle-label {
    font-size: var(--text-sm);
    color: var(--color-fg-secondary);
    font-weight: 500;
}

.reference-toggle-buttons {
    display: flex;
    background: var(--color-surface);
    border-radius: 4px;
    padding: 1px;
    border: 1px solid var(--color-border);
}

.reference-btn {
    padding: 3px 8px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--color-fg-secondary);
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.1s ease;
    white-space: nowrap;
    opacity: 0.6;
    min-width: 28px;
}

.reference-btn.active {
    opacity: 1;
    color: var(--color-fg);
    background: var(--color-accent);
    color: white;
}

/* ========== REMOTE IMAGE DOWNLOAD BUTTON ========== */
/* Show download button on hover for remote images */
.canvas-item.has-download-btn:hover .remote-image-download-btn {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: scale(1) !important;
}

/* Spinning animation for loading state */
.spinning {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.reference-btn:hover:not(.active) {
    opacity: 0.8;
    background: var(--color-surface-hover);
}

.mode-btn:hover:not(.active) {
    
    background: rgba(0,0,0, 0.3);
}

/* ========== PLACEHOLDER HANDLING WITH HIDDEN CHARACTER ========== */

/* When textarea only contains the hidden character, make text invisible and show placeholder */
.instruction-input {
    position: relative;
}

/* Container for textarea and custom placeholder */
.instruction-input-container {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* Custom placeholder overlay - real DOM element */
.custom-placeholder {
    position: absolute;
    left: 0;
    top: 1px;
    right: 0;
    bottom: 0;
    padding: inherit;
    border: inherit;
    font: inherit;
    color: var(--color-text-secondary);
    opacity: 0.6;
    pointer-events: none;
    white-space: pre-wrap;
    overflow: hidden;
    display: none;
    z-index: 1;
    background: transparent;
    resize: none;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

/* Show custom placeholder when only hidden character is present and textarea not focused */
.instruction-input-container[data-has-hidden-char="true"] .custom-placeholder {
    display: block;
}

.instruction-input-container[data-has-hidden-char="true"] .instruction-input:not(:focus) {
    color: transparent;
}

.instruction-input-container[data-has-hidden-char="true"] .instruction-input:focus + .custom-placeholder {
    display: none;
}

/* ========== ADAPTIVE ITEM SIZING ========== */

/* Use visibility instead of opacity for hidden elements so they don't take up space - ONLY in conversation mode */
.instruction-item.conversation-mode:not(.item-active) .conversation-input-footer,
.instruction-item.conversation-mode:not(.item-active) .instruction-footer,
.instruction-item.conversation-mode:not(.item-active) .instruction-input,
.instruction-item.conversation-mode:not(.item-active) .instruction-run-btn,
.instruction-item.conversation-mode:not(.item-active) .instruction-loading {
    opacity: 0;
    visibility: hidden;
    height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease, height 0.2s ease, margin 0.2s ease, padding 0.2s ease;
}

.instruction-item.conversation-mode.item-active .conversation-input-footer,
.instruction-item.conversation-mode.item-active .instruction-footer,
.instruction-item.conversation-mode.item-active .instruction-input,
.instruction-item.conversation-mode.item-active .instruction-run-btn,
.instruction-item.conversation-mode.item-active .instruction-loading {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0.2s ease, height 0.2s ease, margin 0.2s ease, padding 0.2s ease;
}

/* Expand conversation area when item is not active to use the freed space */
.instruction-item.conversation-mode:not(.item-active) .conversation-view {
    height: calc(100% + 120px);
}

.instruction-item.conversation-mode:not(.item-active) .conversation-messages {
    max-height: calc(100vh - 200px);
}

/* ============================================ */
/* AI Writing Assistant Styles                 */
/* ============================================ */

/* AI Prompt Modal in Document Editor */
.ai-prompt-modal {
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    box-shadow: 0 2px 8px var(--shadow-sm);
}

.ai-prompt-modal input {
    color: var(--color-text) !important;
    background: transparent !important;
}

.ai-prompt-modal input::placeholder {
    color: var(--color-text-secondary);
    opacity: 0.6;
}

/* Document Modal AI Toolbar */
.doc-modal-ai-toolbar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 8px;
    background: var(--color-surface-2);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    z-index: 100001;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

body:not(.dark-theme) .doc-modal-ai-toolbar {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.doc-modal-ai-button {
    padding: 8px 16px;
    background: var(--color-surface-3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #ffffff;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

body:not(.dark-theme) .doc-modal-ai-button {
    background: var(--color-surface-2);
    border-color: rgba(0, 0, 0, 0.1);
    color: #000000;
}

.doc-modal-ai-button:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.doc-modal-ai-button:active {
    transform: translateY(0);
}

.doc-modal-ai-button.loading {
    opacity: 0.7;
    cursor: wait;
}

.doc-modal-ai-button.loading::after {
    content: '...';
    animation: ellipsis 1.5s infinite;
}

@keyframes ellipsis {
    0% { content: '.'; }
    33% { content: '..'; }
    66% { content: '...'; }
}

/* Document Modal AI Provider Selector */
.doc-modal-ai-toolbar .ai-provider-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.doc-modal-ai-toolbar .model-selector {
    font-size: var(--text-sm);
    padding: 6px 12px;
}

.doc-modal-ai-toolbar .model-dropdown {
    bottom: 100%;
    top: auto;
    margin-bottom: 8px;
    max-height: 300px;
    overflow-y: auto;
}

/* Inline AI Prompt */
.inline-ai-wrapper {
    margin: 8px 0;
}

.inline-ai-prompt {
    background: var(--color-surface-2);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    animation: promptSlideIn 0.2s ease-out;
    width: 100%;
    max-width: 600px;
}

body:not(.dark-theme) .inline-ai-prompt {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(0, 0, 0, 0.15);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

@keyframes promptSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.inline-ai-input {
    width: 100%;
    background: var(--color-surface-1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 10px 14px;
    color: #ffffff;
    font-size: var(--text-base);
    font-family: inherit;
    resize: none;
    min-height: 40px;
    max-height: 200px;
    overflow-y: auto;
    outline: none;
    transition: all 0.2s ease;
}

body:not(.dark-theme) .inline-ai-input {
    background: var(--color-surface-0);
    border-color: rgba(0, 0, 0, 0.1);
    color: #000000;
}

.inline-ai-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.2);
}

.inline-ai-input::placeholder {
    color: #666666;
    opacity: 1;
}

.inline-ai-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.inline-provider-selector {
    flex: 1;
    display: flex;
    gap: 8px;
}

.inline-provider-selector .model-selector {
    font-size: var(--text-sm);
    padding: 6px 12px;
    height: 36px;
}

.inline-provider-selector .model-dropdown {
    font-size: var(--text-sm);
    bottom: 100%;
    top: auto;
    margin-bottom: 4px;
}

.inline-ai-generate {
    padding: 8px 20px;
    background: var(--color-accent);
    border: none;
    border-radius: 6px;
    color: #ffffff;
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 90px;
}

.inline-ai-generate:hover:not(:disabled) {
    background: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.inline-ai-generate:active:not(:disabled) {
    transform: translateY(0);
}

.inline-ai-generate:disabled {
    opacity: 0.9;
    cursor: wait;
}

/* AI Generation Loading States */
.generating-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
}

.generating-text {
    font-weight: 500;
}

.generating-dots {
    display: inline-block;
    min-width: 20px;
    text-align: left;
    font-weight: bold;
    animation: pulse 1.5s ease-in-out infinite;
}

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

/* Typewriter cursor effect (optional) */
.ai-typing-cursor {
    display: inline-block;
    background-color: currentColor;
    width: 2px;
    height: 1.2em;
    margin-left: 2px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.inline-ai-cancel {
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #959595;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

body:not(.dark-theme) .inline-ai-cancel {
    border-color: rgba(0, 0, 0, 0.1);
    color: #666666;
}

.inline-ai-cancel:hover {
    background: var(--color-surface-3);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.2);
}

body:not(.dark-theme) .inline-ai-cancel:hover {
    background: var(--color-surface-2);
    color: #000000;
}

/* AI Writing Menu */
.ai-writing-menu {
    position: absolute;
    background: var(--color-surface-2);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    min-width: 200px;
    padding: 8px;
    backdrop-filter: blur(10px);
    animation: menuFadeIn 0.15s ease-out;
}

body:not(.dark-theme) .ai-writing-menu {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(0, 0, 0, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

@keyframes menuFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ai-writing-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: var(--text-sm);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    width: 100%;
    text-align: left;
}

body:not(.dark-theme) .ai-writing-option {
    color: #000000;
}

.ai-writing-option:hover {
    background: var(--color-surface-3);
    transform: translateX(2px);
}

body:not(.dark-theme) .ai-writing-option:hover {
    background: var(--color-surface-2);
}

.ai-option-icon {
    font-size: 14px;
    width: 16px;
    text-align: center;
}

.ai-option-label {
    font-weight: 500;
}

/* Text Selection Toolbar */
.text-selection-toolbar {
    position: fixed;
    background: var(--color-surface-2);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    padding: 6px;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 4px;
    animation: toolbarSlideIn 0.2s ease-out;
}

body:not(.dark-theme) .text-selection-toolbar {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(0, 0, 0, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

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

.text-selection-toolbar button {
    padding: 6px 8px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #ffffff;
    font-size: var(--text-xs);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

body:not(.dark-theme) .text-selection-toolbar button {
    border-color: rgba(0, 0, 0, 0.1);
    color: #000000;
}

.text-selection-toolbar button:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #ffffff;
    transform: translateY(-1px);
}

.text-selection-toolbar .ai-button {
    background: linear-gradient(135deg, var(--color-accent), #8b5cf6);
    border-color: var(--color-accent);
    color: #ffffff;
    font-weight: 500;
}

.text-selection-toolbar .ai-button:hover {
    background: linear-gradient(135deg, #0056b3, #7c3aed);
    transform: translateY(-1px);
}

/* AI Provider Selector in Document Items */
.document-item .ai-provider-selector {
    margin-top: 4px;
}

.document-item .ai-provider-selector .model-selector {
    font-size: var(--text-xs);
    padding: 4px 8px;
}

.document-item .ai-provider-selector .model-dropdown {
    font-size: var(--text-xs);
}

/* Loading states for AI operations */
.ai-writing-loading {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--color-surface-3);
    border-radius: 4px;
    font-size: var(--text-xs);
    color: #959595;
    animation: pulse 1.5s ease-in-out infinite;
}

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

.ai-writing-loading::before {
    content: "⟳";
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* NotionStyleEditor padding fix */
.text-editor-container .notion-editor-container {
    padding: 0 !important;
}

/* ========== STYLE SCHEMA SECTION ========== */

.style-schema-section {
    background: var(--color-bw);
    padding: var(--space-sm);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 0;
    transform: translateY(-10px);
}

.style-schema-section.visible {
    max-height: 800px; /* increased for larger schemas */
    opacity: 1;
    margin-top: 5px;
    transform: translateY(0px);
    overflow: visible; /* ensure content is not clipped */
}

.style-schema-section > * {
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.style-schema-section.visible > * {
    opacity: 1;
    transform: translateY(0px);
}


/* Style Schema Name Display */
.style-schema-name {
    font-size: var(--text-sm);
    color: var(--color-accent);
    margin-bottom: var(--space-sm);
    padding: var(--space-xs) calc(var(--space-lg) + var(--space-sm)) var(--space-xs) var(--space-sm);
    background: rgba(0, 102, 204, 0.1);
    border: var(--border-width) solid rgba(0, 102, 204, 0.2);
    border-radius: var(--radius-xl);
    position: relative;
    display: flex;
    align-items: center;
}

.style-schema-name-text {
    flex: 1;
    min-width: 0;
}

.style-schema-name-clear {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: absolute;
    right: var(--space-sm);
    top: 50%;
    transform: translateY(-50%);
}

.style-schema-name-clear:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--color-text-primary);
}

/* Style Schema Modal */
.style-schema-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0s ease;
    backdrop-filter: blur(10px);
}

.style-schema-modal-content {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    width: 600px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}


.style-schema-modal-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    margin: 0;
    display: none;
}

.style-schema-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.style-schema-modal-close:hover {
    color: var(--color-text-primary);
}

.style-schema-modal-body {
    padding: var(--space-lg);
    flex: 1;
    overflow-y: auto;
}

/* Style Schema Editor */
.style-schema-editor {
   
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    min-height: 200px;
    max-height: 200px;
    overflow-y: auto;
    background: transparent;
    border: 0;
    resize: vertical;
    color: rgba(255, 255, 255, 0.3);
    width: 100%;
    box-sizing: border-box;
    outline: none;
    resize: none;

}

.style-schema-editor:focus {
    border-color: var(--color-hover);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.style-schema-editor::placeholder {
    color: var(--color-muted);
    opacity: 0.5;
}

/* Style Schema Buttons */
.style-schema-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

.style-schema-btn {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-sm);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.style-schema-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.style-schema-btn:active {
    transform: translateY(0);
}

.style-schema-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


.style-schema-btn.danger {
    background: rgba(220, 38, 38, 0.2);
    color: #ff6b6b;
}

.style-schema-btn.danger:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.3);
}

/* Style Schema Status */
.style-schema-status {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-sm);
    display: none;
    margin-bottom: var(--space-sm);
    background: rgba(0, 0, 0, 0.2);
    border: var(--border-width) solid rgba(255, 255, 255, 0.1);
}

.style-schema-status.success {
    display: block;
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.3);
}

.style-schema-status.error {
    display: block;
    background: rgba(239, 68, 68, 0.2);
    color: #ff6b6b;
    border-color: rgba(239, 68, 68, 0.3);
}

.style-schema-status.info {
    display: block;
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.3);
}

/* Schema Editor */





.style-schema-status.success {
    display: block;
    background: rgba(34, 197, 94, 0.1);
    color: rgb(21, 128, 61);
    border-color: rgba(34, 197, 94, 0.2);
}

.style-schema-status.error {
    display: block;
    background: rgba(239, 68, 68, 0.1);
    color: rgb(153, 27, 27);
    border-color: rgba(239, 68, 68, 0.2);
}

.style-schema-status.info {
    display: block;
    background: rgba(59, 130, 246, 0.1);
    color: rgb(29, 78, 216);
    border-color: rgba(59, 130, 246, 0.2);
}

/* Library styles updated for modal */
.style-schema-library-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    overflow-y: auto;
}

.style-schema-library-item {
    padding: var(--space-md);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--color-bw);
    position: relative;
    display: flex;
    gap: var(--space-md);
    align-items: flex-start;
}

.style-schema-library-item-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    background: var(--color-surface-2);
    border: var(--border-width) solid var(--color-border);
}

.style-schema-library-item > *:hover {
    border: 0 !important;
}

.style-schema-library-item-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.style-schema-library-item-content {
    flex: 1;
    min-width: 0;
}

.style-schema-library-item:hover {
    background: var(--color-hover);
}

.style-schema-library-item-name {
    font-weight: var(--font-medium);
    font-size: var(--text-base);
    color: var(--color-text-primary);
    margin-bottom: calc(var(--space-xs) / 2);
    padding-right: var(--space-xl);
}

.style-schema-library-item-meta {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.style-schema-library-item-meta-item {
    display: flex;
    align-items: center;
    gap: calc(var(--space-xs) / 2);
}

.style-schema-library-item-actions {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    display: flex;
    gap: var(--space-xs);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.style-schema-library-item:hover .style-schema-library-item-actions {
    opacity: 1;
}

.style-schema-library-item-delete {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.style-schema-library-item-delete:hover {
    background: var(--color-hover);
    color: var(--color-text-primary);
}

/* Empty state */
.style-schema-empty {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--color-text-secondary);
}

.style-schema-empty-icon {
    width: var(--space-xl);
    height: var(--space-xl);
    margin: 0 auto var(--space-sm);
    opacity: 0.5;
}

.style-schema-empty-text {
    font-size: var(--text-sm);
    margin-bottom: var(--space-sm);
}

.style-schema-empty-hint {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}


.style-schema-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    cursor: pointer;
    border-radius: var(--radius-item) var(--radius-item) 0 0;
    transition: all 0.2s ease;
    user-select: none;
    background: var(--color-surface-2);
    border-bottom: var(--border-width) solid var(--color-border);
}

.style-schema-header:hover {
    background: var(--color-hover);
}

.style-schema-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-text-primary);
}

.style-schema-toggle svg {
    width: var(--space-sm);
    height: var(--space-sm);
    transition: transform 0.3s ease;
    color: var(--color-text-secondary);
}

.style-schema-section.expanded .style-schema-toggle svg {
    transform: rotate(90deg);
}

.style-schema-actions {
    display: flex;
    gap: 5px;
}



.style-schema-btn:hover {
    background: var(--color-hover);
    border-color: var(--color-accent);
    color: var(--color-text-primary);
}

.style-schema-btn:active {
    transform: scale(0.95);
    background: var(--color-active);
}


.style-schema-content {
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
    padding: 0;
}

.style-schema-section.expanded .style-schema-content {
    max-height: 600px;
    padding: var(--space-md);
}



.style-schema-editor:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}



.style-schema-status {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
    border-radius: var(--radius-sm);
    display: none;
    font-weight: var(--font-medium);
    border: 0;
}

.style-schema-status.success {
    display: block;
    background: rgba(34, 197, 94, 0.1);
    color: rgb(21, 128, 61);
    border-color: rgba(34, 197, 94, 0.2);
}

.style-schema-status.error {
    display: block;
    background: rgba(239, 68, 68, 0.1);
    color: rgb(153, 27, 27);
    border-color: rgba(239, 68, 68, 0.2);
}

.style-schema-status.info {
    display: block;
    background: rgba(59, 130, 246, 0.1);
    color: rgb(29, 78, 216);
    border-color: rgba(59, 130, 246, 0.2);
}

.style-schema-badge {
    position: absolute;
    top: var(--space-sm);
    right: calc(var(--space-xl) + var(--space-sm));
    background: var(--color-accent);
    color: white;
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    padding: calc(var(--space-xs) / 2) var(--space-xs);
    border-radius: var(--radius-sm);
    display: none;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.instruction-item.has-schema .style-schema-badge {
    display: block;
}

.style-schema-library {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--color-bw);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 600px;
    width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 10000;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.style-schema-library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: var(--border-width) solid var(--color-border);
}

.style-schema-library-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    margin: 0;
}

.style-schema-library-close {
    background: none;
    border: none;
    font-size: var(--text-lg);
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--btn-height) * 0.8);
    height: calc(var(--btn-height) * 0.8);
}

.style-schema-library-close:hover {
    background: var(--color-hover);
    color: var(--color-text-primary);
}

.style-schema-library-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.style-schema-library-item {
    padding: var(--space-md);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--color-surface-2);
}

.style-schema-library-item:hover {
    background: var(--color-hover);
}

.style-schema-library-item > * {

}

.style-schema-library-item-name {
    font-weight: var(--font-medium);
    font-size: var(--text-base);
    color: var(--color-text-primary);
    margin-bottom: calc(var(--space-xs) / 2);
     pointer-events: none !important;
}

.style-schema-library-item-meta {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
     pointer-events: none !important;
}

.style-schema-library-item-meta-item {
    display: flex;
    align-items: center;
    gap: calc(var(--space-xs) / 2);
     pointer-events: none !important;
}

/* Schema generation loading state */
.style-schema-generating {
    opacity: 0.7;
    pointer-events: none;
}

.style-schema-generating .style-schema-btn {
    opacity: 0.5;
}

/* Empty state */
.style-schema-empty {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--color-text-secondary);
}

.style-schema-empty-icon {
    width: var(--space-xl);
    height: var(--space-xl);
    margin: 0 auto var(--space-sm);
    opacity: 0.5;
}

.style-schema-empty-text {
    font-size: var(--text-sm);
    margin-bottom: var(--space-sm);
}

.style-schema-empty-hint {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}
/* PERMANENT: Line items should NEVER have resize handles - they use path resizing */
.canvas-item.line-item .resize-handle,
.canvas-item.line-item .resize-handle-nw,
.canvas-item.line-item .resize-handle-ne,
.canvas-item.line-item .resize-handle-sw,
.canvas-item.line-item .resize-handle-se,
.canvas-item.line-item .resize-handle-n,
.canvas-item.line-item .resize-handle-s,
.canvas-item.line-item .resize-handle-e,
.canvas-item.line-item .resize-handle-w,
.line-item.selected .resize-handle-nw,
.line-item.selected .resize-handle-ne,
.line-item.selected .resize-handle-sw,
.line-item.selected .resize-handle-se,
.line-item.item-active .resize-handle-nw,
.line-item.item-active .resize-handle-ne,
.line-item.item-active .resize-handle-sw,
.line-item.item-active .resize-handle-se {
    /*display: none !important;*/
    /*visibility: hidden !important;*/
    /*pointer-events: none !important;*/
    /*opacity: 0 !important;*/
    display: block !important;
}

/* ========== PERFORMANCE: DISABLE TRANSITIONS DURING DRAG ========== */
/* This MUST be at the end to override all other transition rules */
.canvas-item.dragging,
.canvas-item.dragging *,
.canvas-item.selected.dragging,
.canvas-item.selected.dragging *,
.canvas-item.multiselect-drag,
.canvas-item.multiselect-drag *,
body.multiselect-dragging .canvas-item.selected,
body.multiselect-dragging .canvas-item.selected *,
body.multiselect-dragging .canvas-item,
body.multiselect-dragging .canvas-item *,
body.multiselect-dragging .unified-selection-bounds,
body.dragging-multiple .unified-selection-bounds {
    transition: none !important;
    animation: none !important;
    will-change: transform !important;
}

/* ========== TEXT ITEM EDIT MODE STYLES ========== */
/* Hide UI chrome when text items are in edit mode */
.text-item.item-active .connection-port {
    opacity: 0 !important;
    visibility: hidden !important;
}

.text-item.item-active .resize-handle-nw,
.text-item.item-active .resize-handle-ne,
.text-item.item-active .resize-handle-sw,
.text-item.item-active .resize-handle-se,
.text-item.item-active .resize-handle-n,
.text-item.item-active .resize-handle-s,
.text-item.item-active .resize-handle-e,
.text-item.item-active .resize-handle-w {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Hide selection border/box-shadow for text items in edit mode */
.text-item.item-active {
    border-color: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    cursor: text !important;
}

/* Also hide selection styles even if item is also selected */
.text-item.item-active.selected {
    border-color: transparent !important;
    box-shadow: none !important;
    outline: none !important;
}

/* Hide hover selection styles for text items in edit mode */
.text-item.item-active:hover,
.canvas-item.text-item.item-active:hover:not(.section-container),
.section-container > .canvas-item.text-item.item-active:hover {
    border-color: transparent !important;
    box-shadow: none !important;
    outline: none !important;
}

/* ========== RESIZE HANDLE TOUCH AREA IMPROVEMENTS ========== */
/* Make the actual resize handle elements larger for bigger touch areas */
.resize-handle-nw,
.resize-handle-ne,
.resize-handle-sw,
.resize-handle-se {
    /* Increase the actual clickable area */
    width: 32px !important;
    height: 32px !important;
    /* Override original background to be transparent */
    background: transparent !important;
    border: none !important;
    z-index: 10000000000;
}

/* Create the small visual indicator perfectly centered within the larger clickable area */
.resize-handle-nw::after,
.resize-handle-ne::after,
.resize-handle-sw::after,
.resize-handle-se::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--color-active);
    border: 1px solid var(--color-bw);
    pointer-events: none; /* Let clicks pass through to parent */
}

/* Adjust positioning to keep handles in same visual location */
.resize-handle-nw {
    top: -16px !important;
    left: -16px !important;
}

.resize-handle-ne {
    top: -16px !important;
    right: -16px !important;
}

.resize-handle-sw {
    bottom: -16px !important;
    left: -16px !important;
}

.resize-handle-se {
    bottom: -16px !important;
    right: -16px !important;
}

.resize-handle-n,
.resize-handle-s {
    /* Reduce height for better precision */
    height: 16px !important;
    width: 100%;
}

.resize-handle-n {
    top: -8px !important;
}

.resize-handle-s {
    bottom: -8px !important;
}

.resize-handle-e,
.resize-handle-w {
    /* Reduce width for better precision */  
    width: 16px !important;
    height: 100%;
}

.resize-handle-e {
    right: -8px !important;
}

.resize-handle-w {
    left: -8px !important;
}

/* ========== RESIZE HANDLE CURSOR OVERRIDES ========== */
/* Ensure native resize cursors override any custom cursor */
.resize-handle-nw,
.resize-handle-nw * {
    cursor: nw-resize !important;
}

.resize-handle-ne,
.resize-handle-ne * {
    cursor: ne-resize !important;
}

.resize-handle-sw,
.resize-handle-sw * {
    cursor: sw-resize !important;
}

.resize-handle-se,
.resize-handle-se * {
    cursor: se-resize !important;
}

.resize-handle-n,
.resize-handle-n * {
    /*cursor: ns-resize !important;*/

    cursor: ns-resize !important;
    width: calc(100% - 32px) !important;
    left: 50%;
    transform: translateX(-50%);
    height: calc(16px / var(--zoom-scale)) !important;
}

.resize-handle-s,
.resize-handle-s * {
    cursor: ns-resize !important;
    width: calc(100% - 32px) !important;
    left: 50%;
    transform: translateX(-50%);
    height: calc(16px / var(--zoom-scale)) !important;
}

.resize-handle-e,
.resize-handle-e * {
    cursor: ew-resize !important;

    height: calc(100% - 32px) !important;
    top: 50%;
    transform: translateY(-50%);
    width: calc(16px / var(--zoom-scale)) !important;
}

.resize-handle-w,
.resize-handle-w * {
    cursor: ew-resize !important;

    height: calc(100% - 32px) !important;
    top: 50%;
    transform: translateY(-50%);
    width: calc(16px / var(--zoom-scale)) !important;
}



/* ========== SECTION CONTAINER SELECTION FIXES ========== */
/* Prevent items inside selected section-containers from showing selection styles */
.section-container.selected .canvas-item,
.section-container.item-active .canvas-item,
.section-container.multi-selected .canvas-item {
    border-color: transparent !important;
    box-shadow: none !important;
    outline: none !important;
}

/* Also hide resize handles and connection ports on items inside selected sections */
.section-container.selected .canvas-item .resize-handle-nw,
.section-container.selected .canvas-item .resize-handle-ne,
.section-container.selected .canvas-item .resize-handle-sw,
.section-container.selected .canvas-item .resize-handle-se,
.section-container.selected .canvas-item .resize-handle-n,
.section-container.selected .canvas-item .resize-handle-s,
.section-container.selected .canvas-item .resize-handle-e,
.section-container.selected .canvas-item .resize-handle-w,
.section-container.selected .canvas-item .connection-port {
    opacity: 0 !important;
    visibility: hidden !important;
}


.instruction-item.item-active .resize-handle-nw,
.instruction-item.item-active .resize-handle-ne,
.instruction-item.item-active .resize-handle-sw,
.instruction-item.item-active .resize-handle-se,
.instruction-item.item-active .resize-handle-n,
.instruction-item.item-active .resize-handle-s,
.instruction-item.item-active .resize-handle-e,
.instruction-item.item-active .resize-handle-w {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* ========== AREA STYLES ========== */
.area-title-container {
    top: calc(-25px / var(--zoom-scale, 1));
    gap: 4px;
    transform: scale(calc(1 / var(--zoom-scale, 1)));
    transform-origin: left top;
}

.area-title {
    font-size: var(--text-sm);
    background-color: var(--color-bw);
    padding: 1px 6px;
    border-radius: 4px;
    cursor: move;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.area-title:hover {
    background-color: var(--color-hover);
}

.area-menu-btn {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: none;
    background-color: var(--color-bw) !important;
    color: var(--color-fg);
    cursor: pointer;
    padding: 0;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    opacity: 1;
    transition: opacity 0.2s ease, background-color 0.2s ease;
}

.area-title-container:hover .area-menu-btn {
    opacity: 1;
}

.area-menu-btn:hover {
    background-color: var(--color-hover);
}

.area-menu-btn:active {
    background-color: var(--color-bw);
}

.area-color-btn {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--color-bw);
    cursor: pointer;
    padding: 0;
    pointer-events: auto;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.area-color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.area-color-btn:active {
    transform: scale(0.95);
}

/* Hidden color input for area color picker */
.area-color-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
}

/* Area scaling mode selector */
.area-scaling-select {
    font-size: 11px;
    padding: 2px 4px;
    margin-right: 4px;
    border: 1px solid var(--color-bw);
    border-radius: 4px;
    background: var(--color-bg);
    color: var(--color-text);
    cursor: pointer;
    pointer-events: auto;
    transition: background 0.2s ease;
}

.area-scaling-select:hover {
    background: var(--color-bg-hover);
}

.area-scaling-select:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* Area share URL display */
.area-url-container {
    bottom: calc(-20px / var(--zoom-scale, 1));
    gap: 4px;
}

.area-url-text {
    font-size: calc(var(--text-xs) / var(--zoom-scale, 1));
    color: #999;
    background-color: var(--color-bw);
    padding: 1px 6px;
    border-radius: 4px;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    transition: color 0.2s ease;
}

.area-url-container:hover .area-url-text {
    color: var(--color-accent);
}

/* Locked area styling */
.area-boundary.area-locked {
    opacity: 0.7;
}

.area-boundary.area-locked .area-title {
    cursor: not-allowed !important;
    opacity: 0.7;
}

.area-boundary.area-locked .area-color-btn {
    cursor: not-allowed !important;
    opacity: 0.7;
    pointer-events: none !important;
}

/* Lock icon for locked areas */
.area-boundary.area-locked::after {
    content: '';
    position: absolute;
    top: calc(4px / var(--zoom-scale, 1));
    right: calc(4px / var(--zoom-scale, 1));
    width: calc(16px / var(--zoom-scale, 1));
    height: calc(16px / var(--zoom-scale, 1));
    background: url(data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2' ry='2'/%3E%3Ccircle cx='12' cy='16' r='1'/%3E%3Cpath d='M7 11V7a5 5 0 1 1 10 0v4'/%3E%3C/svg%3E) no-repeat center;
    background-size: calc(12px / var(--zoom-scale, 1)) calc(12px / var(--zoom-scale, 1));
    transition: all 0.1s ease;
    z-index: 10;
    pointer-events: none;
}

/* ========== PERFORMANCE OPTIMIZATIONS ========== */

/* Temporal sampling keyframes for frame-skipping during interactions */
@keyframes temporalSample2x {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0.99; }
}

@keyframes temporalSample3x {
    0%, 33.33% { opacity: 1; }
    33.34%, 66.66% { opacity: 0.99; }
    66.67%, 100% { opacity: 0.98; }
}

@keyframes temporalSample4x {
    0%, 25% { opacity: 1; }
    25.01%, 50% { opacity: 0.99; }
    50.01%, 75% { opacity: 0.98; }
    75.01%, 100% { opacity: 0.97; }
}

/* Base performance optimizations for canvas items */
.canvas-item {
    /* Modern performance features */
    /*content-visibility: auto;
    contain-intrinsic-size: 300px 200px;
    contain: layout style paint;
    */
    /* GPU acceleration preparation */
    will-change: auto;
    backface-visibility: hidden;
    
    /* Transition optimization */
    transition: transform 0.1s ease-out, opacity 0.15s ease-out;
}

/* During zoom/pan interactions - reduce quality for performance */
.canvas-item.interacting {
    /* GPU acceleration during interactions */
    will-change: transform, opacity;
    transform: translateZ(0); /* Force GPU layer */
    
    /* Quality reduction for all content types */
    /*filter: blur(0.5px);*/
    
    /* Disable expensive effects during interaction */
    box-shadow: none !important;
    text-shadow: none !important;
}

/* Image-specific optimizations during interaction */
.canvas-item.interacting img {
    image-rendering: pixelated;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    /*filter: blur(1px);*/
}

/* Iframe-specific optimizations during interaction */
.canvas-item.interacting iframe {
    /*filter: blur(2px) grayscale(0.3);*/
    pointer-events: none;
}

/* Video-specific optimizations during interaction */
.canvas-item.interacting video {
    /*filter: blur(1.5px) grayscale(0.2);*/
    image-rendering: pixelated;
}

/* Heavy zoom interactions - more aggressive optimizations */
.canvas-item.heavy-interaction {
    /* Maximum performance mode */
    will-change: transform;
    transform: translateZ(0) scale3d(1, 1, 1);
    
    /* NO EXPENSIVE FILTERS in placeholder mode */
    filter: none !important;
    opacity: 1;
    
    /* Disable all expensive rendering */
    box-shadow: none !important;
    text-shadow: none !important;
    /*border-radius: 0 !important;*/
}

/* Heavy interaction - DISABLED hiding of content during pan/zoom
.canvas-item.heavy-interaction iframe,
.canvas-item.heavy-interaction video,
.canvas-item.heavy-interaction canvas,
.canvas-item.heavy-interaction .rich-text-editor {
    display: none !important;
}
*/

/* Scale-based quality reduction for images */

/* Quality Level 1: 100%-75% scale (minimal reduction) */
.canvas-item.heavy-interaction.quality-1 img {
    display: block !important;
    image-rendering: pixelated;
    image-rendering: -webkit-optimize-contrast;
    transition: none !important;
}

/* Quality Level 2: 75%-50% scale (moderate reduction) */
.canvas-item.heavy-interaction.quality-2 img {
    display: block !important;
    image-rendering: pixelated;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: -moz-crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
    transition: none !important;
    width: 10% !important;
    height: 10% !important;
    transform: scale(10) translateZ(0) !important;
    transform-origin: top left !important;
    will-change: transform !important;
    backface-visibility: hidden !important;
    contain: layout style paint !important;
    filter: none !important;
    /* Temporal sampling - skip every 2nd frame */
    animation: temporalSample2x 0.033s steps(2) infinite !important;
}

/* Quality Level 3: 50%-25% scale (strong reduction) */
.canvas-item.heavy-interaction.quality-3 img {
    display: block !important;
    image-rendering: pixelated;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: -moz-crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
    transition: none !important;
    width: 10% !important;
    height: 10% !important;
    transform: scale(10) translateZ(0) !important;
    transform-origin: top left !important;
    will-change: transform !important;
    backface-visibility: hidden !important;
    contain: layout style paint !important;
    filter: none !important;
    /* Temporal sampling - skip every 3rd frame */
    animation: temporalSample3x 0.05s steps(3) infinite !important;
}

/* Quality Level 4: 25%-0% scale (maximum reduction) */
.canvas-item.heavy-interaction.quality-4 img {
    display: block !important;
    image-rendering: pixelated;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: -moz-crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
    transition: none !important;
    width: 10% !important;
    height: 10% !important;
    transform: scale(10) translateZ(0) !important;
    transform-origin: top left !important;
    will-change: transform !important;
    backface-visibility: hidden !important;
    contain: layout style paint !important;
    filter: none !important;
    /* Temporal sampling - skip every 4th frame */
    animation: temporalSample4x 0.066s steps(4) infinite !important;
}


/* DISABLED - Show simplified placeholder during heavy interactions
.canvas-item.heavy-interaction::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f0f0f0;
    border: 1px solid #ddd;
    z-index: 1;
}
*/

/* Hide placeholder background for image items (show low-quality image instead) */
.canvas-item.heavy-interaction.image-item::before {
    display: none;
}

/* DISABLED - Scale-based placeholder simplification for non-image items
.canvas-item.heavy-interaction.quality-1::before,
.canvas-item.heavy-interaction.quality-2::before {
    background: #f0f0f0;
    border: 1px solid #ddd;
}

.canvas-item.heavy-interaction.quality-3::before {
    background: #f5f5f5;
    border: 1px solid #e5e5e5;
}

.canvas-item.heavy-interaction.quality-4::before {
    background: #fafafa;
    border: none;
}
*/

/* Scale emoji size based on quality level */
.canvas-item.heavy-interaction.quality-1.embed-item::after,
.canvas-item.heavy-interaction.quality-1.text-item::after {
    font-size: 20px;
}

.canvas-item.heavy-interaction.quality-2.embed-item::after,
.canvas-item.heavy-interaction.quality-2.text-item::after {
    font-size: 18px;
}

.canvas-item.heavy-interaction.quality-3.embed-item::after,
.canvas-item.heavy-interaction.quality-3.text-item::after {
    font-size: 16px;
}

.canvas-item.heavy-interaction.quality-4.embed-item::after,
.canvas-item.heavy-interaction.quality-4.text-item::after {
    font-size: 12px;
    opacity: 0.7;
}

/* DISABLED - Content type indicators for heavy interaction placeholders
.canvas-item.heavy-interaction.image-item::after {
    display: none;
}

.canvas-item.heavy-interaction.embed-item::after {
    content: '🌐';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 20px;
    z-index: 2;
    line-height: 1;
}

.canvas-item.heavy-interaction.text-item::after {
    content: '📝';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 20px;
    z-index: 2;
    line-height: 1;
}
*/

/* Cleanup after interactions */
.canvas-item:not(.interacting):not(.heavy-interaction) {
    will-change: auto;
    filter: none;
    opacity: 1;
    visibility: visible;
}

/* Smooth restoration after interaction */
.canvas-item:not(.interacting):not(.heavy-interaction) img,
.canvas-item:not(.interacting):not(.heavy-interaction) iframe,
.canvas-item:not(.interacting):not(.heavy-interaction) video {
    image-rendering: auto;
    filter: none;
    pointer-events: auto;
    visibility: visible;
}




/* Hide performance controls */
.fps-monitor,
.test-controls,
[class*="performance-"],
[id*="performance-"],
[class*="fps-"],
[id*="fps-"] {
    display: none !important;
}


/* Saving progress visual feedback */
.canvas-item.saving-in-progress {
    opacity: 0.5 !important;
    position: relative;
}

.canvas-item.saving-in-progress::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255,255,255,0.8);
    border-radius: 50%;
    border-top: 2px solid var(--color-accent);
    animation: spin 1s linear infinite;
    z-index: 10;
    pointer-events: none;
}

/* public/theme.css */
/* Minimal Cupertino-inspired theme
   Crisp neutrals, precise typography, and restrained motion */

:root {
    --color-bg: #f5f5f7;
    --color-surface-1: #ffffff;
    --color-surface-2: #f2f2f5;
    --color-surface-3: #1f2023;
    --color-surface-4: #0d0d10;
    --color-fg: #1d1d1f;
    --color-muted: #6e6e73;
    --color-accent: #0071e3;
    --color-border: rgba(17, 17, 17, 0.08);
    --color-divider: rgba(17, 17, 17, 0.12);
    --color-hover: rgba(0, 17, 68, 0.06);
    --color-selected-background: rgba(0, 17, 68, 0.08);
    --color-selected: rgba(0, 17, 68, 0.14);
    --color-active: rgba(0, 113, 227, 0.24);
    --color-selected-line: #0071e3;
    --color-bw: #ffffff;

    --shadow-card: 0 24px 48px rgba(17, 17, 17, 0.08);
    --shadow-up: 0 28px 60px rgba(17, 17, 17, 0.08);
    --shadow-down: 0 16px 36px rgba(17, 17, 17, 0.1);
    --shadow-doc: 0 32px 70px rgba(17, 17, 17, 0.16);
    --shadow-port: 0 0 0 1px rgba(17, 17, 17, 0.08);

    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-item: 18px;
    --item-scale-down: 0.98;
    --toolbar-hint-height: 44px;

    --anim-micro: 120ms;
    --anim-quick: 200ms;
    --anim-butter: cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark-theme {
    --color-bg: #0b0b0f;
    --color-surface-1: #141416;
    --color-surface-2: #1c1c1f;
    --color-surface-3: #1c1c1e;
    --color-surface-4: #050506;
    --color-fg: #f5f5f7;
    --color-muted: #9a9aa2;
    --color-accent: #0a84ff;
    --color-border: rgba(245, 245, 247, 0.08);
    --color-divider: rgba(245, 245, 247, 0.14);
    --color-hover: rgba(10, 132, 255, 0.12);
    --color-selected-background: rgba(10, 132, 255, 0.1);
    --color-selected: rgba(10, 132, 255, 0.18);
    --color-active: rgba(10, 132, 255, 0.26);
    --color-selected-line: #0a84ff;
    --color-bw: #141416;

    --shadow-card: 0 24px 48px rgba(0, 0, 0, 0.45);
    --shadow-up: 0 28px 60px rgba(0, 0, 0, 0.55);
    --shadow-down: 0 18px 42px rgba(0, 0, 0, 0.6);
    --shadow-doc: 0 36px 80px rgba(0, 0, 0, 0.7);
    --shadow-port: 0 0 0 1px rgba(245, 245, 247, 0.12);
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

html, body {
    background: var(--color-bg) !important;
    color: var(--color-fg) !important;
}

body {
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    letter-spacing: -0.01em;
}

::selection {
    background: var(--color-active);
    color: var(--color-surface-1);
}

/* Core canvas surfaces */
.item,
.canvas-item,
[data-item-type],
.text-item,
.code-item,
.section-item,
.document-item,
.link-item,
.image-item,
.video-item,
.instruction-item,
.section-container,
div[class*="section-container"] {
    background: var(--color-surface-1) !important;
    border: none;
    border-radius: var(--radius-item);
    box-shadow: var(--shadow-card);
    transition: background var(--anim-micro) var(--anim-butter), color var(--anim-micro) var(--anim-butter) !important;
}

.text-item {
    background: transparent !important;
    border-radius: 0 !important;
}

.image-item  {
    border-radius: 0 !important
}

.item:hover,
.canvas-item:hover,
[data-item-type]:hover,
.section-container:hover {
    border-color: rgba(0, 113, 227, 0.25);
    box-shadow: 0 30px 60px rgba(0, 17, 68, 0.14); 
    transition: transform var(--anim-quick) var(--anim-butter), opacity calc(var(--anim-quick) * 0.5) var(--anim-butter) !important;
}

.item:active,
.canvas-item:active,
[data-item-type]:active,
.section-container:active {
    transform: scale(0.98) !important;
    box-shadow: 0 16px 28px rgba(0, 17, 68, 0.18);
    opacity: 0.8!important;
    transition: transform var(--anim-quick) var(--anim-butter), opacity calc(var(--anim-quick) * 0.5) var(--anim-butter) !important;
}

/* Ensure mouse-out transition works */
.item:not(:hover):not(:active),
.canvas-item:not(:hover):not(:active),
[data-item-type]:not(:hover):not(:active),
.section-container:not(:hover):not(:active) {
    transition: transform var(--anim-quick) var(--anim-butter), opacity calc(var(--anim-quick) * 0.5) var(--anim-butter) !important;
}

/* Prevent z-index jumping during snapping operations - removed since we fixed it in styles.css */

.text-item.selected,
.instruction-item.selected,
.section-container.selected,
/*.document-item.selected,*/
.item.multi-selected,
.canvas-item.multi-selected {
    background: var(--color-selected-background) !important;
    border-color: transparent;
    box-shadow: 0 32px 72px rgba(0, 17, 68, 0.18);
}

body.dark-theme .item:hover,
body.dark-theme .canvas-item:hover,
body.dark-theme [data-item-type]:hover,
body.dark-theme .section-container:hover {
    border-color: rgba(10, 132, 255, 0.35);
    box-shadow: 0 30px 60px rgba(4, 31, 63, 0.5);
}

body.dark-theme .instruction-item.selected,
body.dark-theme .section-container.selected,
body.dark-theme .document-item.selected,
body.dark-theme .item.multi-selected,
body.dark-theme .canvas-item.multi-selected {
    box-shadow: 0 32px 72px rgba(10, 132, 255, 0.28);
}


.video-item video {
    border-radius: calc(var(--radius-item) - 0px);
    object-fit: cover !important;
}
.image-item img {
    object-fit: cover !important;
}

.code-item,
.code-item.selected,
.code-item.multi-selected,
.code-item.item-active {
    background: var(--color-surface-3) !important;
    color: #f5f5f7;
    border: none;
    box-shadow: var(--shadow-card);
}

body.dark-theme .code-item,
body.dark-theme .code-item.selected,
body.dark-theme .code-item.multi-selected,
body.dark-theme .code-item.item-active {
    background: var(--color-surface-3) !important;
    color: #f5f5f7;
}

.line-item,
.line-item:hover,
.line-item:active,
.line-item.selected,
.line-item.multi-selected,
.canvas-item.line-item,
.canvas-item.line-item:hover,
.canvas-item.line-item:active,
.canvas-item.line-item.selected,
.canvas-item.line-item.multi-selected {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.line-item svg path[stroke="transparent"] {
    pointer-events: none !important;
}

.line-item:hover svg path[stroke="transparent"],
.line-item.selected svg path[stroke="transparent"],
.line-item.multi-selected svg path[stroke="transparent"] {
    stroke: var(--color-selected-line);
    stroke-width: calc(1px / var(--zoom-scale, 1));
    stroke-opacity: 1;
}



/* Floating interface elements */
.sort-dropdown-menu,
.contextual-menu,
.context-menu,
.dropdown-menu {
    background: var(--color-surface-1) !important;
    border: none !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-up) !important;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    transition: box-shadow var(--anim-quick) var(--anim-butter),
                transform var(--anim-micro) var(--anim-butter);
}

.selection-box {
    background: rgba(0, 113, 227, 0.12) !important;
    border: calc(1px / var(--zoom-scale, 1)) solid rgba(0, 113, 227, 0.45) !important;
    border-radius: var(--radius-xs) !important;
}

body.dark-theme .selection-box {
    background: rgba(10, 132, 255, 0.16) !important;
    border-color: rgba(10, 132, 255, 0.5) !important;
}

.unified-selection-bounds {
    border: calc(1px / var(--zoom-scale, 1)) solid var(--color-selected-line) !important;
    border-radius: var(--radius-item) !important;
    background: transparent !important;
    box-shadow: inset 0 0 0 calc(1px / var(--zoom-scale, 1)) rgba(0, 113, 227, 0.08);
    transition: none !important; /* Prevent lag during dragging */
}

/* EXACT right-menu tool button styling applied to ALL tool buttons */
.tool-btn,
.tool-select,
.item-style-toolbar button,
.floating-toolbar .tool-btn,
.selection-toolbar button,
.toolbar-group .tool-btn,
.drawing-controls-container button {
    justify-content: center;
    width: 36px;
    height: 36px;
    position: relative;
    background: transparent !important;
    border-radius: var(--radius-sm);
    color: var(--color-fg);
    padding: 6px;
    border: none;
    display: flex;
    align-items: center;
    gap: 2px;
    transition: background var(--anim-micro) var(--anim-butter),
                color var(--anim-micro) var(--anim-butter),
                scale var(--anim-micro) var(--anim-butter);
}

/* EXACT right-menu hover effect applied to ALL tool buttons */
.tool-btn:hover,
.tool-select:hover,
.item-style-toolbar button:hover,
.floating-toolbar .tool-btn:hover,
.selection-toolbar button:hover,
.toolbar-group .tool-btn:hover,
.drawing-controls-container button:hover {
    background: rgba(0, 0, 0, 0.08) !important;
    scale: 1.15;
}

/* EXACT right-menu active state applied to ALL tool buttons */
.tool-btn:active,
.tool-select:active,
.item-style-toolbar button:active,
.floating-toolbar .tool-btn:active,
.selection-toolbar button:active,
.toolbar-group .tool-btn:active,
.drawing-controls-container button:active {
    transform: scale(var(--item-scale-down));
    scale: 0.95;
}

.tool-select {
    width: auto !important;
    min-width: auto !important;
    text-align: left !important;
}

/* Board picker positioned on left */
.board-picker-left {
    position: absolute;
    top: 20px;
    left: 20px;
    /*background: var(--color-bw);*/
    border: 0;
    border-radius: var(--radius-lg);
    /*box-shadow: var(--shadow-up) !important;*/
    padding: var(--space-xs);
    gap: 2px;
    display: flex;
    align-items: center;
    z-index: 1000;
    /*backdrop-filter: saturate(180%) blur(20px);*/
    /*-webkit-backdrop-filter: saturate(180%) blur(20px);*/
}

/* Tools positioned in center */
.tools-center {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-bw);
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-up) !important;
    padding: var(--space-xs);
    gap: 2px;
    display: flex;
    align-items: center;
    z-index: 1000;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
}

/* Define selection colors with alpha for proper transparency */
:root {
    --selection-bg: rgba(0, 113, 227, 0.3); /* color-accent with 30% opacity */
    --selection-bg-active: rgba(0, 113, 227, 0.4); /* color-accent with 40% opacity */
}

body.dark-theme {
    --selection-bg: rgba(10, 132, 255, 0.3); /* dark mode color-accent with 30% opacity */
    --selection-bg-active: rgba(10, 132, 255, 0.4); /* dark mode color-accent with 40% opacity */
}

/* Text selection highlighting in document editor */
.notion-editor-container ::selection {
    background: var(--selection-bg) !important;
    color: var(--color-fg) !important;
}

/* AI selection highlighting in document editor (slightly stronger when AI modal is open) */
.notion-editor-container.ai-selection-active ::selection {
    background: var(--selection-bg-active) !important;
    color: var(--color-fg) !important;
}

/* Board tools toolbar - using opacity for smooth transitions */
.board-picker-left .board-tools-toolbar {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    position: absolute;
    top: calc(100% - 5px); /* Overlap slightly to remove gap */
    left: 0;
    background: var(--color-bw);
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-up) !important;
    padding: var(--space-xs);
    gap: 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    z-index: 1003; /* Higher z-index to ensure it's clickable */
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    transform: translateY(4px);
    transition-delay: 0s; /* Show immediately */
}

/* Create invisible bridge to connect picker and toolbar */
.board-picker-left::before {
    content: '';
    position: absolute;
    top: 95%; /* Start near bottom of picker */
    left: -10px; /* Extend wider than picker */
    right: -10px;
    height: 20px; /* Bridge the gap */
    z-index: 1001; /* Lower than toolbar */
    pointer-events: none; /* Don't block clicks normally */
}

/* Show toolbar on hover */
.board-picker-left:hover .board-tools-toolbar,
.board-picker-left .board-tools-toolbar:hover {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    transform: translateY(0);
    transition-delay: 0s; /* Show immediately */
}

.board-picker-left:hover::before {
    pointer-events: all; /* Enable bridge when hovering */
}

/* Ensure toolbar buttons are always clickable when visible */
.board-picker-left .board-tools-toolbar[style*="opacity: 1"] {
    pointer-events: all !important;
}

.board-picker-left .board-tools-toolbar .tool-btn {
    pointer-events: all !important;
    z-index: 1004; /* Higher than everything */
}

/* Add delay before hiding */
.board-picker-left .board-tools-toolbar {
    transition-delay: 200ms; /* Stay visible for 200ms after mouse leaves */
}

.board-picker-left:hover .board-tools-toolbar,
.board-picker-left .board-tools-toolbar:hover {
    transform: translateY(0);
    transition-delay: 0s; /* But show immediately on hover */
}

/* Prevent button movement/animation on hover */
.board-tools-toolbar .tool-btn {
    transition: none !important;
    transform: none !important;
}

.board-tools-toolbar .tool-btn:hover {
    transform: none !important;
    animation: none !important;
}




/* Hide the old dynamically created board-tools-toolbar */
.board-tools-toolbar:not(.board-picker-left .board-tools-toolbar) {
    display: none !important;
}

/* Right menu positioned on right */
.right-menu-container {
    position: absolute;
    top: 20px;
    right: 20px;
    /*background: var(--color-bw);*/
    border: 0;
    border-radius: var(--radius-lg);
    /*box-shadow: var(--shadow-up) !important;*/
    padding: var(--space-xs);
    gap: 2px;
    display: flex;
    align-items: center;
    z-index: 1000;
    /*backdrop-filter: saturate(180%) blur(20px);*/
    /*-webkit-backdrop-filter: saturate(180%) blur(20px);*/
}

/* Right menu alignment - add space to align with toggle button */
.right-menu-container .right-menu {
    position: absolute;
    top: 100%;
    right: 0;
}

.connection-port {
    transition: opacity var(--anim-quick) var(--anim-butter),
                transform var(--anim-quick) var(--anim-butter),
                background var(--anim-micro) var(--anim-butter),
                color var(--anim-micro) var(--anim-butter);
}

/* Remove old toolbar styling */
.toolbar {
    display: none;
}

/* Removed toolbar hint indicator */

/* Removed toolbar arrow indicator */

/* Removed dark theme toolbar indicators */

.toolbar > * {
    opacity: 1;
    margin-top: 0;
    transition: opacity var(--anim-quick) var(--anim-butter);
}

/* Removed toolbar hover effects - toolbar is always visible */

.toolbar .tool-btn,
.toolbar .tool-select,
.toolbar .item-style-toolbar button {
    transform: translateY(0);
    transition: opacity var(--anim-quick) var(--anim-butter),
                transform var(--anim-quick) var(--anim-butter),
                background var(--anim-micro) var(--anim-butter),
                color var(--anim-micro) var(--anim-butter);
}

.toolbar .tool-btn:hover,
.toolbar .tool-btn:focus-visible {
    transform: translateY(0);
    /*background: rgba(0, 0, 0, 0.08);*/
}

.toolbar .tool-btn:active {
    transform: scale(var(--item-scale-down));
}

.toolbar .tool-btn.active,
.toolbar .tool-btn.selected,
.toolbar .tool-btn[aria-pressed="true"] {
    opacity: 1;
    transform: translateY(0);
}

/* Toolbar group styling is now part of universal tool menu styling above */

/* EXACT right-menu styling applied to all tool menus */
.board-switcher-center,
.floating-toolbar,
.selection-toolbar,
.item-style-toolbar,
.drawing-controls-container {
    background: var(--color-bw);
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-up) !important;
    padding: var(--space-xs);
    gap: 2px;
    display: flex;
    align-items: center;
}

.drawing-controls-container {
    left:50% !important;
    top: 20px !important;
}

/* Keep right-menu separate since it has specific positioning */
.right-menu {
    background: var(--color-bw);
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-up) !important;
    padding: var(--space-xs);
    gap: 2px;
}

/* Mobile styles - toolbar always visible and transparent */
@media (hover: none) {
    .toolbar {
        transform: translateY(0);
        box-shadow: none;
        background: transparent !important;
        border-bottom: none;
    }

    .toolbar > * {
        opacity: 1;
        margin-top: 0;
    }
}

.tool-btn.selected,
.tool-btn.active,
.tool-btn[aria-pressed="true"],
.item-style-toolbar button.active,
.logic-dropdown-btn.selected,
.logic-dropdown-btn.active,
.logic-nodes-dropdown.open .logic-dropdown-btn,
.drawing-mode-active #drawToggle,
#drawToggle.active {
    background: var(--color-selected-background) !important;
    color: var(--color-selected-line) !important;
    box-shadow: none !important;
}

.logic-dropdown-menu {
    background: var(--color-bw);
}

/* DISABLED - Performance degradations for heavy embeds while panning
.canvas-item iframe,
.canvas-item video,
.canvas-item embed,
.canvas-item object {
    transition: opacity var(--anim-quick) var(--anim-butter);
}

body.canvas-panning .canvas-item iframe,
body.canvas-panning .canvas-item video,
body.canvas-panning .canvas-item embed,
body.canvas-panning .canvas-item object {
    opacity: 0;
    pointer-events: none !important;
}
*/

/* LOW-DETAIL MODE DISABLED - These styles are no longer used
body.canvas-low-detail .low-detail-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 999;
}

body.canvas-low-detail .low-detail-placeholder {
    position: absolute;
    border: 1px dashed var(--color-border);
    color: var(--color-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    border-radius: var(--radius-md);
    box-shadow: 0 12px 24px rgba(17, 17, 17, 0.08);
}

body.dark-theme.canvas-low-detail .low-detail-placeholder {
    background: rgba(20, 20, 22, 0.72);
    border-color: rgba(245, 245, 247, 0.16);
    color: rgba(245, 245, 247, 0.72);
}

body.canvas-low-detail .low-detail-placeholder.low-detail-image {
    border: none;
    box-shadow: 0 18px 36px rgba(17, 17, 17, 0.18);
    background: rgba(255, 255, 255, 0.55);
}

body.dark-theme.canvas-low-detail .low-detail-placeholder.low-detail-image {
    background: rgba(20, 20, 22, 0.55);
}

body.canvas-low-detail .low-detail-placeholder.low-detail-image img.low-detail-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: inherit;
    filter: saturate(0.85) contrast(0.95);
    image-rendering: auto;
}

body.canvas-low-detail .low-detail-placeholder.low-detail-image.low-detail-image-fallback img.low-detail-preview {
    filter: blur(1.2px) saturate(0.8);
}
*/

/* Status pills */
.instruction-status {
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    color: var(--color-muted);
    border: none;
    padding: 4px 10px;
}

.instruction-status.success {
    color: #0b8a3c;
}

.instruction-status.error {
    color: #d64545;
}

/* Document surfaces */
.document-modal {
    background: transparent !important;
    /*backdrop-filter: blur(28px);*/
    /*-webkit-backdrop-filter: blur(28px);*/
}

.document-modal-content {
    background: transparent !important;
    box-shadow: none !important;
}

.document-editor-content {
    background: var(--color-surface-1) !important;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-doc) !important;
    border: none;
}

/* Overlays */
.help-modal,
.api-settings-modal,
.logic-config-modal {
    background: rgba(245, 245, 247, 0.6);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
}

body.dark-theme .help-modal,
body.dark-theme .api-settings-modal,
body.dark-theme .logic-config-modal {
    background: rgba(20, 20, 22, 0.7);
}


.logic-config-content {
    background: var(--color-surface-1) !important;
    color: var(--color-fg) !important;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

/* Ports and connectors */
.delete-btn {
    display: none !important;
}

.connection-port .port-dot {
    background: var(--color-surface-1) !important;
    border-radius: 50%;
    box-shadow: var(--shadow-port) !important;
    border: 0;
}

.logic-item .port-dot span {
    color: var(--color-muted) !important;
    font-weight: 500;
}

.connection-port:hover {
    transform: translateY(-50%) scale(calc(1.35 / var(--zoom-scale, 1.35)));
}

.canvas-item[data-connection-type="source"] {
    border: calc(1px / var(--zoom-scale, 1)) solid var(--color-selected-line) !important;
    background: var(--color-selected-background) !important;
}

.single-selected-block,
.multi-selected-block {
    background-color: var(--color-selected-background) !important;
}

/* Toasts and dialogs */
.toast-notification,
.api-test-result,
.zoom-indicator,
.model-dropdown,
.image-model-dropdown-menu,
.output-type-dropdown-menu,
.sort-dropdown-menu {
    border-radius: var(--radius-lg);
    border: none;
    background: var(--color-surface-1);
    box-shadow: var(--shadow-down);
    transition: transform var(--anim-micro) var(--anim-butter),
                opacity var(--anim-quick) var(--anim-butter);
}

.toast-button,
.save-btn,
.cancel-btn,
.api-btn,
.section-color-btn,
.section-share-btn,
.queue-release-btn,
.merger-reset-btn {
    border-radius: var(--radius-sm);
    transition: background var(--anim-micro) var(--anim-butter),
                transform var(--anim-micro) var(--anim-butter);
}

.toast-button:hover,
.save-btn:hover,
.cancel-btn:hover,
.api-btn:hover,
.section-color-btn:hover,
.section-share-btn:hover,
.queue-release-btn:hover,
.merger-reset-btn:hover {
    background: var(--color-hover);
    transform: translateY(-1px);
}

.toast-button:active,
.save-btn:active,
.cancel-btn:active,
.api-btn:active {
    transform: translateY(0);
}

/* Minimal motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark theme hover effects for all tool buttons */
body.dark-theme .tool-btn:hover,
body.dark-theme .tool-select:hover,
body.dark-theme .item-style-toolbar button:hover,
body.dark-theme .floating-toolbar .tool-btn:hover,
body.dark-theme .selection-toolbar button:hover,
body.dark-theme .right-menu .tool-btn:hover,
body.dark-theme .toolbar-group .tool-btn:hover,
body.dark-theme .toolbar .tool-btn:hover,
body.dark-theme .toolbar .tool-btn:focus-visible,
body.dark-theme .drawing-controls-container button:hover {
    background: rgba(255, 255, 255, 0.1) !important;
}


*::selection,
*::-moz-selection,
*::-webkit-selection {
    color: var(--color-fg) !important;
}

/* Drawing mode transitions */
.tools-center {
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform: translateX(-50%);
}

.drawing-mode-active .tools-center {
    transform: translate(-50%, -30px) scale(0.9);
    opacity: 0;
    pointer-events: none;
}

.drawing-controls-container {
    transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
    transform: translate(-50%, 30px) scale(0.9);
    opacity: 0;
    pointer-events: none;
}

.drawing-mode-active .drawing-controls-container.show {
    transform: translate(-50%, 0px) scale(1) !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

#exitDrawingMode svg {
    transition: transform 0.2s ease;
}

#exitDrawingMode:hover svg {
    transform: rotate(90deg);
}


.canvas-item.line-item:active,
.canvas-item.line-item:hover,
.canvas-item.line-item.selected {
     /*border: calc(1px / var(--zoom-scale, 1)) solid var(--color-selected-line) !important;*/
     box-shadow: inset 0 0 0 calc(1px / var(--zoom-scale, 1)) var(--color-selected-line) !important;
}



/* public/floating-toolbars.css */
/* Base floating toolbar */
.floating-toolbar {
    position: fixed;
    background: #FFF;
    /*border: var(--border);*/
    border-radius: var(--radius-lg);
    padding: var(--space-xs);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    /*box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.1);*/
    z-index: var(--z-dropdown);
    opacity: 0;
    transform: translateX(-50%) translateY(8px) scale(0.95);
    transition: all 0.2s ease;
    pointer-events: none;
    left: 50%;
    /* Safe GPU acceleration for floating toolbars */
    will-change: transform, opacity;
    transform: translateX(-50%) translateY(8px) scale(0.95) translateZ(0);
}

/* Stronger shadow in light mode */
body:not(.dark-theme) .floating-toolbar {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.15);
    border-color: var(--color-border);
}

/* Even stronger shadow in dark mode */
body.dark-theme .floating-toolbar {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
    background: #000;
}

.floating-toolbar.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
    pointer-events: all;
    left: 50%;
}

/* Floating toolbar buttons - better contrast */
.floating-toolbar .tool-btn {
    height: 32px;
    width: 32px;
    padding: 6px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--color-fg);
}

.floating-toolbar .tool-btn:hover {
    background: var(--color-hover);
}

/* Light mode specific button styling */
body:not(.dark-theme) .floating-toolbar .tool-btn {
    color: var(--color-fg);
}

body:not(.dark-theme) .floating-toolbar .tool-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* Floating select - better contrast */
.floating-toolbar .tool-select {
    height: 32px;
    padding: 6px 12px;
    font-size: var(--text-base);
    border: var(--border);
    background: #000;
    color: var(--color-fg);
    border-radius: var(--radius-sm);
    border-color: black;
    text-align: center;
}

body:not(.dark-theme) .floating-toolbar .tool-select {
    border-color: white;
    background: white;
}

/* Divider in floating toolbar */
.floating-toolbar .toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 4px;
}

/* Selection toolbar (for sorting) - positioned at bottom center */
.selection-floating-toolbar {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px) scale(0.95);
    top: auto;
}

.selection-floating-toolbar.show {
    transform: translateX(-50%) translateY(0) scale(1);
}


/* Logic nodes dropdown styles */
.logic-nodes-dropdown {
    position: relative;
    display: inline-flex;
}

.logic-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    /*padding: 6px 10px !important;*/
    
   
}

.logic-dropdown-btn .logic-label {
    font-size: var(--text-base);
    font-weight: 400;
}

.logic-dropdown-btn .dropdown-arrow {
    opacity: 0.6;
    transition: transform 0.2s ease;
}

.logic-nodes-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.logic-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: #FFF;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.08);
    padding: 8px 0px;
    min-width: 220px;
    max-height: 400px;
    overflow-y: auto;
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 1000;
}

.logic-nodes-dropdown.open .logic-dropdown-menu {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Dark theme support */
body.dark-theme .logic-dropdown-menu {
    background: var(--color-bw);
    /*border-color: rgba(255, 255, 255, 0.1);*/
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.logic-node-group {
    margin-bottom: 12px;
}

.logic-node-group:last-child {
    margin-bottom: 0;
}

.logic-node-group-title {
    font-size: calc(var(--text-base) * 0.75);
    /*font-weight: 600;*/
    text-transform: uppercase;
    color: #666;
    padding: 4px 12px;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

body.dark-theme .logic-node-group-title {
    color: #999;
}

.logic-node-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: var(--text-base);
    color: var(--color-fg);
    text-align: left;
}

.logic-node-option:hover {
    background: var(--color-hover);
    opacity: 1;
}

body.dark-theme .logic-node-option:hover {
    background: var(--color-hover);
}

.logic-node-option:active {
    transform: scale(0.98);
}

.logic-node-option svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.7;
}

.logic-node-option span {
    flex: 1;
    font-weight: 400;
}

/* Scrollbar styling for dropdown */
.logic-dropdown-menu::-webkit-scrollbar {
    width: 6px;
}

.logic-dropdown-menu::-webkit-scrollbar-track {
    background: transparent;
}

.logic-dropdown-menu::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

body.dark-theme .logic-dropdown-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

/* REMOVED: Long press functionality disabled
.long-press-ripple {
    position: fixed;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--color-accent);
    opacity: 0.3;
    pointer-events: none;
    z-index: 10000;
    animation: ripple 0.5s ease-out;
}

body:not(.dark-theme) .long-press-ripple {
    opacity: 0.4;
    background: var(--color-accent);
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 0.5;
    }
    100% {
        transform: scale(1);
        opacity: 0.3;
    }
}
*/

/* REMOVED: Quick tools functionality disabled
.quick-tools-fade-area {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-dropdown) - 1);
    pointer-events: none;
    opacity: 0;
}

.quick-tools-fade-area.active {
    pointer-events: all;
}
*/

/* Hide main toolbar items when floating versions are shown */
body.floating-ui-active .toolbar .board-switcher .tool-btn:not(#boardSelect),
body.floating-ui-active .toolbar #sortMode,
body.floating-ui-active .toolbar #addText,
body.floating-ui-active .toolbar #addCode,
body.floating-ui-active .toolbar #addSection,
body.floating-ui-active .toolbar #zoomIn,
body.floating-ui-active .toolbar #zoomOut,
body.floating-ui-active .toolbar #homeBtn {
    /*opacity: 0.3;*/
    pointer-events: none;
}

/* Ensure schema toggle buttons remain clickable */
body.floating-ui-active .schema-toggle.btn {
    pointer-events: all !important;
}

/* Animation for appearance */
@keyframes floatIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.floating-toolbar.show {
    /*animation: floatIn 0.2s ease forwards;*/
}

/* Ensure danger buttons are visible */
.floating-toolbar .tool-btn.danger {
    color: var(--color-danger);
}

.floating-toolbar .tool-btn.danger:hover {
    background: var(--color-danger);
    color: white;
}


/* ========== SELECTION TOOLBAR ========== */
.selection-toolbar {
    position: fixed;
    background: #FFF;
    border-radius: var(--radius-lg);
    padding: var(--space-xs);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    z-index: 100000000000;
    min-width: 100px;
    
    /* Smooth animations matching floating toolbar */
    opacity: 0;
    transform: translateY(20px) scale(0.95) translateZ(0);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    will-change: transform, opacity;
}

/* Stronger shadow in light mode - matching floating toolbar */
body:not(.dark-theme) .selection-toolbar {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.15);
    border-color: var(--color-border);
}

/* Even stronger shadow in dark mode - matching floating toolbar */
body.dark-theme .selection-toolbar {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
    background: #000;
}

.selection-toolbar.visible {
    opacity: 1;
    transform: translateY(-10px) scale(1) translateZ(0);
    pointer-events: all;
}

.selection-toolbar button {
    height: 32px;
    width: 32px;
    padding: 6px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--color-fg);
    cursor: pointer;
    font-size: 16px;
    white-space: nowrap;
    
    /* Smooth transitions matching floating toolbar */
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    transform: scale(1);
    opacity: 0.8;
}

.selection-toolbar button:hover {
    background: var(--color-hover);
    opacity: 1;
    /* REMOVED: transform: scale(1.05); - was causing button movement */
}

.selection-toolbar button:active {
    transform: scale(0.95);
    opacity: 0.7;
}

.selection-toolbar button.active {
    background: var(--color-accent);
    color: white;
    transform: scale(1);
    opacity: 1;
    box-shadow: 0 0 0 2px rgba(var(--color-accent-rgb), 0.3);
}

/* Light mode specific button styling - matching floating toolbar */
body:not(.dark-theme) .selection-toolbar button {
    color: var(--color-fg);
}

body:not(.dark-theme) .selection-toolbar button:hover {
    background: rgba(0, 0, 0, 0.06);
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 var(--space-xs);
}








/* Item-level contextual menu */
.item-style-toolbar {
    position: fixed;
    top: calc(100vh - 100px); /* Fixed near bottom without using bottom property */
    left: 50%;
    transform: translateX(-50%) translateY(8px) scale(0.95);
    background: var(--color-bw);
    border: var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-xs);
    display: flex;
    z-index: var(--z-dropdown);
    gap: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: background-color var(--transition-normal);
    min-width: 100px; /* Ensure it's wide enough */
    transition: all 0.2s ease;
    opacity: 0;
    pointer-events: none; /* Prevent interactions when hidden */
}

body.dark-theme .item-style-toolbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.item-style-toolbar.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
    pointer-events: all;
}

.item-style-toolbar button {
    height: 32px;
    width: 32px;
    background: transparent;
    color: var(--color-fg);
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    padding: 6px;
    font-size: var(--text-base);
    white-space: nowrap;
    flex: 1; /* Make buttons equal width */
}

.item-style-toolbar button:hover {
    background: var(--color-hover);
}

.item-style-toolbar button.active {
    background: var(--color-accent);
    color: white;
}

.item-style-toolbar .toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--color-border);
    margin: 4px 4px;
    align-self: center;
}


/* Font selector buttons */
.item-style-toolbar .font-btn {
    height: 32px;
    width: 40px;
    background: transparent;
    color: var(--color-fg);
    border: 0px solid var(--color-border);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    padding: 6px;
    font-size: 18px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.item-style-toolbar .font-btn:hover {
    background: var(--color-hover);
}

.item-style-toolbar .font-btn.active {
    background: var(--color-bw);
    color: white;
}

/* Font-specific styling */
.item-style-toolbar .font-inter-btn {
    font-family: 'Inter', sans-serif;
}

.item-style-toolbar .font-source-serif-btn {
    font-family: 'Source Serif 4', serif;
}

.item-style-toolbar .font-fuzzy-bubbles-btn {
    font-family: 'Fuzzy Bubbles', cursive;
    padding-top: 9px;
}

.item-style-toolbar .font-lab-mono-btn {
    font-family: 'Lab Mono', monospace;
}

/* Hide h1, h2 from text selection toolbar */
.selection-toolbar button[data-command="formatBlock"][data-value="h1"],
.selection-toolbar button[data-command="formatBlock"][data-value="h2"] {
    display: none;
}

.selection-toolbar button[title="Heading 1"],
.selection-toolbar button[title="Heading 2"] {
    display: none !important;
}

/* public/document-windows.css */
/* Document Windows Container */
.document-windows-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2100; /* Higher than modal default */
}

/* Document Window - standalone styling without modal inheritance */
.document-window {
    /* Position is set by JavaScript - don't override it here */
    background: transparent;
    padding: 0;
    overflow: visible;
    border-radius: 0;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    /* z-index is set by JavaScript - don't override it here */
    display: block;
}

.document-window .document-modal-content {
    position: relative !important;
    transform: none !important;
    transition: none !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    min-height: 100% !important;
    overflow: visible !important; /* Changed to visible so AI modals can show */
    display: flex;
    flex-direction: column;
    /* Restore nice drop shadow and styling */
    background: var(--color-bg, #ffffff) !important;
    box-shadow: rgba(0, 0, 0, 0.05) 0px 25px 50px !important;
    border-radius: 0 !important;
    border: none;
}

.document-window.active .document-modal-content {
    box-shadow: 
        0 0 0 1px rgba(0, 0, 0, 0.1),
        0 20px 60px rgba(0, 0, 0, 0.15),
        0 4px 20px rgba(0, 0, 0, 0.1);
}

.document-window.dragging {
    transition: none;
    cursor: move;
}

.document-window.dragging .document-modal-content,
.document-window.resizing .document-modal-content {
    opacity: 0.95;
}

.document-window.resizing {
    user-select: none;
}

/* Draggable area indicator */
.document-window .document-modal-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    cursor: move;
    z-index: 1;
    background: linear-gradient(to bottom, rgba(255,255,255,0.02) 0%, transparent 100%);
}

.document-window.dragging .document-modal-content::before {
    background: linear-gradient(to bottom, rgba(0,0,0,0.05) 0%, transparent 100%);
}

/* Editor Content in Window */
.document-window .document-editor-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 0;
    background: var(--color-surface-1, #ffffff) !important;
    border: none;
    box-shadow: var(--shadow-doc, rgba(0, 0, 0, 0.1) 0px 10px 40px) !important;
    padding: 40px;
    min-height: 0; /* Important for flexbox scrolling */
    position: relative;
    margin: 0;
}

/* Ensure the editor blocks don't create their own scroll containers */
.document-window .document-editor-content .editor-block {
    overflow: visible;
}

.document-window .document-editor-content * {
    overflow-x: visible;
}

/* Close button positioning for windows */
.document-window .document-modal-close {
    z-index: 10;
}

/* Window Resize Handles - Match existing system */
.window-resize-handle {
    position: absolute;
    background: transparent;
    border: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Corner handles - larger touch areas */
.resize-nw, .resize-ne, .resize-sw, .resize-se {
    width: 32px;
    height: 32px;
}

/* Edge handles */
.resize-n, .resize-s {
    height: 16px;
    width: calc(100% - 32px);
    left: 50%;
    transform: translateX(-50%);
}

.resize-e, .resize-w {
    width: 16px;
    height: calc(100% - 32px);
    top: 50%;
    transform: translateY(-50%);
}

/* Positioning */
.resize-nw { top: -16px; left: -16px; cursor: nw-resize !important; }
.resize-ne { top: -16px; right: -16px; cursor: ne-resize !important; }
.resize-sw { bottom: -16px; left: -16px; cursor: sw-resize !important; }
.resize-se { bottom: -16px; right: -16px; cursor: se-resize !important; }
.resize-n { top: -8px; cursor: ns-resize !important; }
.resize-s { bottom: -8px; cursor: ns-resize !important; }
.resize-e { right: -8px; cursor: ew-resize !important; }
.resize-w { left: -8px; cursor: ew-resize !important; }

/* Visual indicators for corner handles - completely transparent */
.resize-nw::after, .resize-ne::after, .resize-sw::after, .resize-se::after {
    display: none;
}

/* Show handles on window hover */
.document-window:hover .window-resize-handle {
    opacity: 1;
}

/* Ensure AI modals appear above document windows */
.ai-prompt-modal,
.ai-writing-menu {
    z-index: 2200 !important; /* Higher than document windows (2100) */
    position: fixed !important;
    visibility: visible !important; /* Ensure modal is visible */
    opacity: 1 !important; /* Ensure modal is opaque */
}

/* Ensure selection toolbar appears above document windows */
.selection-toolbar {
    z-index: 2200 !important; /* Higher than document windows (2100) */
}

/* Dark Theme Support */
body.dark-theme .document-window.active .document-modal-content {
    box-shadow: 
        0 0 0 1px rgba(255, 255, 255, 0.15),
        0 20px 60px rgba(0, 0, 0, 0.7),
        0 4px 20px rgba(0, 0, 0, 0.5);
}

/* Tiling Animation */
.document-window.tiling {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ensure windows are properly visible and positioned */
.document-window {
    z-index: 2100 !important;
}

/* Override any modal hiding styles */
.document-window.document-modal.show {
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* public/guide.css */
.guide-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
}

.guide-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.guide-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.guide-content {
    position: relative;
    width: 90%;
    max-width: 500px;
    max-height: 70vh;
    background: var(--color-bg);
    border-radius: 8px;
    border: 1px solid var(--border-primary);
    overflow: hidden;
}

.guide-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--color-muted);
    cursor: pointer;
}

.guide-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-primary);
}

.guide-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 400;
}

.guide-body {
    padding: 20px;
    overflow-y: auto;
    max-height: 50vh;
}

.guide-body p {
    margin: 0 0 12px 0;
    color: var(--color-muted);
    font-size: 13px;
    line-height: 1.5;
}

.guide-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.guide-step-indicator {
    font-size: 12px;
    color: var(--color-muted);
}

.guide-btn {
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid var(--border-primary);
    background: var(--color-surface-1);
    color: var(--color-fg);
    font-size: 13px;
    cursor: pointer;
}



