/* Cells Shared Styles */

/* Design System Variables */
:root {
    /* Primary brand colors (aligned with apps/shared/icon.svg) */
    --color-primary: #0a9208;
    --color-secondary: #5cb85a;
    --color-primary-hover: #087a06;
    --color-primary-active: #066505;

    /* Neutral palette */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f8f9fa;
    --color-bg-hover: #e9ecef;
    --color-bg-active: #dee2e6;
    --color-bg-input: #ffffff;
    --color-border: #dee2e6;
    --color-separator: #e9ecef;
    --color-border-hover: #adb5bd;
    --color-text-primary: #212529;
    --color-text-secondary: #495057;
    --color-text-muted: #6c757d;
    --color-text-placeholder: #adb5bd;

    /* Semantic colors */
    --color-danger: #dc3545;
    --color-danger-bg: #fff5f5;
    --color-danger-border: #f5c6cb;
    --color-warning: #f59e0b;
    --color-warning-hover: #d97706;

    /* Shadows */
    --color-shadow: rgba(0, 0, 0, 0.12);
    --color-shadow-lg: rgba(0, 0, 0, 0.15);

    /* Scrollbar */
    --color-scrollbar-thumb: #c4c4c4;
    --color-scrollbar-thumb-hover: #a8a8a8;
    --color-scrollbar-thumb-active: #8c8c8c;

    /* Grid (canvas) colors */
    --grid-line: #f0f0f0;
    --grid-cell-bg: #ffffff;
    --grid-cell-text: #212529;
    --grid-header-bg: #f8f9fa;
    --grid-header-border: #dee2e6;
    --grid-header-separator: rgba(0, 0, 0, 0.06);
    --grid-header-text: #495057;
    --grid-corner-bg: #e9ecef;

    /* Spacing scale */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;

    /* Border radius */
    --border-radius: 6px;
    --border-radius-top: 6px 6px 0 0;
    --border-radius-smaller: 5px;

    /* Typography */
    --font-size-xs: 11px;
    --font-size-sm: 12px;
    --font-size-md: 13px;
    --font-size-lg: 14px;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-mono: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;

    /* Script editor colors (light theme) */
    --script-bg: #ffffff;
    --script-bg-gutter: #f5f5f5;
    --script-bg-footer: #f0f0f0;
    --script-text: #1e1e1e;
    --script-text-muted: #6e7681;
    --script-border: #d0d7de;
    --script-caret: #1e1e1e;
    --script-token-keyword: #cf222e;
    --script-token-string: #0a3069;
    --script-token-number: #0550ae;
    --script-token-comment: #6e7681;
    --script-token-name: #953800;
    --script-token-operator: #1e1e1e;
    --script-token-error: #cf222e;
    --script-status-success: #1a7f37;
    --script-status-error: #cf222e;

    /* Toolbar/Bar design tokens */
    --bar-height: 36px;
    --bar-padding-x: var(--spacing-sm);
    --bar-padding-y: var(--spacing-sm);
    --bar-gap: var(--spacing-sm);
    --bar-bg: var(--color-bg-secondary);

    /* Control heights (buttons, inputs, badges) */
    --control-height: 28px;
    --control-padding-x: var(--spacing-md);
    --control-font-size: var(--font-size-sm);

    /* Transitions */
    --transition-fast: 0.15s ease;
}

/* Dark Theme Override */
[data-theme="dark"] {
    /* Script editor colors (dark theme) */
    --script-bg: #1e1e1e;
    --script-bg-gutter: #1e1e1e;
    --script-bg-footer: #252526;
    --script-text: #d4d4d4;
    --script-text-muted: #5a5a5a;
    --script-border: #333333;
    --script-caret: #d4d4d4;
    --script-token-keyword: #569cd6;
    --script-token-string: #ce9178;
    --script-token-number: #b5cea8;
    --script-token-comment: #6a9955;
    --script-token-name: #9cdcfe;
    --script-token-operator: #d4d4d4;
    --script-token-error: #f44747;
    --script-status-success: #4ec9b0;
    --script-status-error: #f48771;

    --color-primary: #4ade80;
    --color-secondary: #22c55e;
    --color-primary-hover: #22c55e;
    --color-primary-active: #16a34a;

    --color-bg-primary: #1a1a1a;
    --color-bg-secondary: #252525;
    --color-bg-hover: #333333;
    --color-bg-active: #404040;
    --color-bg-input: #2d2d2d;
    --color-border: #404040;
    --color-separator: #333333;
    --color-border-hover: #525252;
    --color-text-primary: #e4e4e4;
    --color-text-secondary: #a0a0a0;
    --color-text-muted: #737373;
    --color-text-placeholder: #525252;

    --color-danger: #f87171;
    --color-danger-bg: #3f1d1d;
    --color-danger-border: #7f1d1d;
    --color-warning: #fbbf24;
    --color-warning-hover: #f59e0b;

    --color-shadow: rgba(0, 0, 0, 0.4);
    --color-shadow-lg: rgba(0, 0, 0, 0.5);

    --color-scrollbar-thumb: #555555;
    --color-scrollbar-thumb-hover: #666666;
    --color-scrollbar-thumb-active: #777777;

    /* Grid (canvas) colors - dark */
    --grid-line: #333333;
    --grid-cell-bg: #1a1a1a;
    --grid-cell-text: #e4e4e4;
    --grid-header-bg: #252525;
    --grid-header-border: #404040;
    --grid-header-separator: rgba(255, 255, 255, 0.06);
    --grid-header-text: #a0a0a0;
    --grid-corner-bg: #2d2d2d;

    --bar-bg: var(--color-bg-secondary);
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    color-scheme: light dark;
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
        sans-serif;
}

html[data-theme="light"] {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
}

/* Container */
#container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--color-bg-primary);
}

/* Header */
#header {
    min-height: var(--bar-height);
    padding: var(--bar-padding-x) var(--bar-padding-x) var(--spacing-xs);
    background: var(--bar-bg);
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Header left group (logo + buttons) */
#header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

#header-logo {
    height: 22px;
    width: 22px;
    flex-shrink: 0;
    color: var(--color-primary);
}

/* Workbook Title - centered between left and right groups */
#workbook-title-container {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

#workbook-title {
    height: var(--control-height);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    padding: 0 var(--spacing-sm);
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    outline: none;
    cursor: text;
    min-width: 40px;
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: calc(var(--control-height) - 2px);
    transition:
        border-color var(--transition-fast),
        background-color var(--transition-fast);
}

#workbook-title:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border);
}

#workbook-title:focus {
    background: var(--color-bg-input);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.1);
}

#workbook-title:empty::before {
    content: "Untitled";
    color: var(--color-text-placeholder);
}

/* Toolbar - right group */
#toolbar {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* Theme Toggle Button */
#theme-toggle {
    padding: 0 var(--spacing-sm);
}

#theme-toggle svg {
    display: none;
    color: var(--color-text-secondary);
}

#theme-toggle svg.active {
    display: block;
}

/* Specific icon colors for visibility */
#theme-icon-light {
    color: #f59e0b; /* Sun - amber */
}

#theme-icon-dark {
    color: #6366f1; /* Moon - indigo */
}

/* Collaboration UI Container */
#collab-ui-container {
    display: flex;
    gap: var(--bar-gap);
    align-items: center;
}

/* Buttons - Unified System */
.btn {
    height: var(--control-height);
    padding: 0 var(--control-padding-x);
    font-size: var(--control-font-size);
    font-weight: var(--font-weight-medium);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: calc(var(--control-height) - 2px);
    white-space: nowrap;
}

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

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

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

.btn:focus {
    outline: none;
}

.btn:focus-visible {
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.2);
}

/* No focus ring for formatting toolbar buttons */
#formatting-toolbar .btn:focus,
#formatting-toolbar .btn:focus-visible {
    box-shadow: none;
}

/* Primary variant */
.btn.btn-primary {
    background: var(--color-primary);
    color: var(--color-bg-primary);
    border-color: var(--color-primary);
}

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

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

/* Danger variant */
.btn.btn-danger {
    color: var(--color-danger);
    border-color: var(--color-danger-border);
}

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

/* Size modifiers */
.btn.btn-sm {
    height: 24px;
    padding: 0 var(--spacing-sm);
    font-size: var(--font-size-xs);
    line-height: 22px;
}

.btn.btn-lg {
    height: 36px;
    padding: 0 var(--spacing-lg);
    font-size: var(--font-size-lg);
    line-height: 34px;
    border-radius: var(--border-radius);
}

/* Layout modifiers */
.btn.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.btn.btn-icon .btn-icon-svg {
    flex-shrink: 0;
}

.btn.btn-block {
    width: 100%;
}

/* Responsive: icon-only buttons on narrow screens */
@media (max-width: 600px) {
    .btn.btn-icon .btn-label {
        display: none;
    }

    .btn.btn-icon {
        padding: 0 var(--spacing-sm);
    }

    #workbook-title {
        max-width: 120px;
    }

    #header-left {
        gap: var(--spacing-xs);
    }
}

/* Canvas Container */
#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    outline: none; /* Hide focus ring - we have our own selection highlight */
}

/* Loading State */
#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: var(--color-text-muted);
    display: none;
    background: var(--color-bg-primary);
    padding: 12px 20px;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 8px var(--color-shadow-lg);
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #dee2e6;
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* Error State */
#error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: var(--color-danger);
    text-align: center;
    display: none;
}

/* Drop Zone Overlay */
#drop-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 134, 1, 0.1);
    border: 3px dashed var(--color-primary);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    pointer-events: none;
}

#drop-zone.visible {
    display: flex;
    pointer-events: auto;
}

/* Top-left: open as new document (same as Open button) */
#drop-zone-new-doc {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 168px;
    padding: 12px 14px;
    background: var(--color-bg-primary);
    border: 2px dashed var(--color-text-muted);
    border-radius: var(--border-radius);
    box-shadow: 0 2px 12px var(--color-shadow);
    text-align: left;
    pointer-events: none;
    transition: border-color 0.15s, background 0.15s;
}

#drop-zone-new-doc.drop-target-active {
    border-color: var(--color-primary);
    background: rgba(5, 134, 1, 0.12);
}

#drop-zone-new-doc strong {
    display: block;
    font-size: 13px;
    color: var(--color-text-primary);
}

#drop-zone-new-doc #drop-zone-new-doc-hint:not([hidden]) {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    line-height: 1.35;
    color: var(--color-text-muted);
    font-weight: normal;
}

#drop-zone-content {
    text-align: center;
    padding: 40px;
    background: var(--color-bg-primary);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 20px var(--color-shadow-lg);
}

#drop-zone-content h2 {
    font-size: 18px;
    color: var(--color-primary);
    margin: 0;
}

/* Empty State */
#empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

#empty-state.hidden {
    display: none;
}

#empty-state h2 {
    font-size: 20px;
    color: var(--color-text-primary);
    margin-bottom: 12px;
}

#empty-state p {
    font-size: 14px;
    color: var(--color-text-muted);
    margin-bottom: 20px;
}

#empty-state .file-types {
    font-size: 12px;
    color: var(--color-text-placeholder);
    margin-top: 12px;
}

/* File Input (hidden) */
#file-input {
    display: none;
}

/* Formatting Toolbar - blocks layout */
#formatting-toolbar {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    padding: var(--spacing-xs) var(--bar-padding-x);
    background: var(--bar-bg);
    gap: var(--spacing-md);
}

/* Thin separators between toolbar blocks */
.toolbar-block:not(:last-child) {
    padding-right: var(--spacing-md);
    border-right: 1px solid var(--color-separator);
}

/* Toolbar block - each block is a 2-row column */
.toolbar-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Toolbar block row - horizontal row within a block */
.toolbar-block-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    height: 24px;
}

/* Style controls block - first row has flexible elements */
#style-controls.toolbar-block .toolbar-block-row:first-child {
    min-width: 0;
}

#style-controls.toolbar-block #font-family-dropdown {
    flex: 1;
    min-width: 60px;
}

/* Format controls block - first row has flexible element */
#format-controls.toolbar-block .toolbar-block-row:first-child #format-dropdown {
    flex: 1;
    min-width: 70px;
}

#format-controls.toolbar-block #format-dropdown-btn {
    width: 100%;
    justify-content: space-between;
}

/* Remove borders from all buttons in formatting toolbar */
#formatting-toolbar .btn {
    border: none;
    background: transparent;
}

#formatting-toolbar .btn:hover {
    background: var(--color-bg-hover);
}

#formatting-toolbar .btn:active,
#formatting-toolbar .btn.active {
    background: var(--color-bg-active);
}

#formatting-toolbar.hidden {
    display: none;
}

/* Formula Bar - Single row layout */
#formula-bar {
    position: relative; /* For autocomplete popup positioning */
    height: 36px;
    display: flex;
    align-items: center;
    padding: var(--spacing-xs) var(--bar-padding-x) var(--bar-padding-x);
    background: var(--bar-bg);
    border-bottom: none;
    gap: var(--bar-gap);
}

#formula-bar.hidden {
    display: none;
}

/* Formula bar button - match height of other elements */
#formula-bar .btn {
    height: 28px;
}

/* Format buttons styling */
#formatting-toolbar .btn.btn-sm {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
}

/* Currency button - center the $ sign, match dropdown width feel */
#format-currency-btn {
    justify-content: center;
    text-align: center;
    min-width: 36px;
}

/* Format decimal and percent buttons */
#format-decimal-decrease,
#format-decimal-increase,
#format-percent-btn {
    justify-content: center;
}

/* Active state for percent button */
#format-percent-btn.active {
    background: var(--color-bg-active);
    font-weight: var(--font-weight-bold);
}

#format-percent-btn.active:hover {
    background: var(--color-bg-active);
}

#format-dropdown {
    position: relative;
}

#format-dropdown-btn {
    min-width: 80px;
    justify-content: space-between;
    border: 1px solid var(--color-border) !important;
}

#format-dropdown-label {
    flex: 1;
    text-align: left;
}

.dropdown-arrow {
    flex-shrink: 0;
    opacity: 0.5;
    transition: transform var(--transition-fast);
}

#format-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.format-dropdown-menu {
    left: 0;
    right: auto;
    min-width: 140px;
}

/* Currency dropdown */
#currency-dropdown {
    position: relative;
}

#currency-dropdown-btn {
    min-width: 36px;
    justify-content: center;
    gap: 3px;
}

/* Show arrow and adjust layout only when currency format is active */
#currency-dropdown.active #currency-dropdown-btn {
    min-width: 36px;
}

/* Hide dropdown arrow when not in currency format */
#currency-dropdown-arrow {
    display: none;
}

#currency-dropdown.active #currency-dropdown-arrow {
    display: block;
}

#currency-dropdown-label {
    font-weight: var(--font-weight-medium);
}

#currency-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.currency-dropdown-menu {
    left: 0;
    right: auto;
    min-width: 80px;
}

/* Active state for currency dropdown */
#currency-dropdown.active #currency-dropdown-btn {
    background: var(--color-bg-active);
    font-weight: var(--font-weight-bold);
}

#currency-dropdown.active #currency-dropdown-btn:hover {
    background: var(--color-bg-active);
}

/* Checkmark for active format in dropdown */
.dropdown-item.active {
    color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
}

.dropdown-item.active::before {
    content: "";
    display: inline-block;
    width: 4px;
    height: 4px;
    background: var(--color-primary);
    border-radius: 50%;
    margin-right: var(--spacing-sm);
}

/* Dropdown separator */
.dropdown-separator {
    height: 1px;
    background: var(--color-border);
    margin: var(--spacing-xs) 0;
}

/* Custom format panel */
#custom-format-panel {
    position: absolute;
    top: 100%;
    right: 0; /* Open to the left since dropdown is on right side of screen */
    margin-top: var(--spacing-xs);
    padding: var(--spacing-sm);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 16px var(--color-shadow);
    min-width: 260px;
    z-index: 1000; /* Same as .dropdown-menu */
}

#custom-format-panel.hidden {
    display: none !important;
}

.custom-format-header {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--spacing-sm);
}

#custom-format-input {
    width: 100%;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-sm);
    font-family: var(--font-mono);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-input);
    color: var(--color-text-primary);
    box-sizing: border-box;
}

#custom-format-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.1);
}

#custom-format-preview {
    margin-top: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    background: var(--color-bg-secondary);
    border-radius: var(--border-radius);
    font-family: var(--font-mono);
}

#custom-format-error {
    margin-top: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-sm);
    color: var(--color-error);
    background: rgba(244, 67, 54, 0.1);
    border-radius: var(--border-radius);
}

#custom-format-error.hidden {
    display: none;
}

.custom-format-templates {
    margin-top: var(--spacing-sm);
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
    align-items: center;
}

.template-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    margin-right: var(--spacing-xs);
}

.template-btn {
    padding: 2px 6px;
    font-size: var(--font-size-xs);
    font-family: var(--font-mono);
    color: var(--color-text-secondary);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.template-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
    border-color: var(--color-primary);
}

.custom-format-actions {
    margin-top: var(--spacing-sm);
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-xs);
}

/* Cell reference wrapper with dropdown functionality */
#cell-ref-wrapper {
    position: relative;
    height: 28px;
    padding: 0 var(--control-padding-x);
    font-size: var(--control-font-size);
    font-weight: var(--font-weight-medium);
    font-family: var(--font-mono);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-input);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 70px;
    max-width: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

#cell-ref-wrapper:hover {
    border-color: var(--color-border-hover);
    background: var(--color-bg-hover);
}

#cell-ref-wrapper.active {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.1);
}

#cell-reference {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-ref-dropdown-arrow {
    flex-shrink: 0;
    opacity: 0.5;
    transition: transform var(--transition-fast);
}

#cell-ref-wrapper.active .cell-ref-dropdown-arrow {
    transform: rotate(180deg);
}

/* Named Ranges Dropdown - extends .dropdown-frame */
.named-ranges-dropdown {
    min-width: 200px;
    max-width: 300px;
    max-height: 300px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0; /* Override dropdown-frame padding for custom layout */
}

.named-ranges-header {
    padding: 8px 12px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.named-ranges-list {
    overflow-y: auto;
    max-height: 250px;
}

.named-range-item {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.named-range-item:hover,
.named-range-item.selected {
    background: var(--color-bg-hover);
}

.named-range-name {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.named-range-scope {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.named-ranges-empty {
    padding: 16px 12px;
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* Formula Input Container - wrapper for contenteditable and hidden input */
#formula-input-container {
    flex: 1;
    height: 28px;
    position: relative;
    display: flex;
    align-items: center;
    background: var(--color-bg-input);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
}

#formula-input-container:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.1);
}

/* Script mode styling - when formula starts with '/' */
#formula-input-container.script-mode {
    background: var(--color-bg-secondary);
    border-color: var(--color-text-secondary);
}

#formula-input-container.script-mode:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.15);
}

#formula-input-container.script-mode #formula-display {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
}

/* Hidden input for form submission and IME support */
#formula-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 100%;
    height: 100%;
}

/* Contenteditable for colored formula display */
#formula-display {
    flex: 1;
    height: 100%;
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
        sans-serif;
    font-size: var(--font-size-md);
    color: var(--color-text-primary);
    background: transparent;
    border: none;
    padding: 0 var(--spacing-sm);
    outline: none;
    white-space: pre;
    overflow: hidden;
    line-height: 26px; /* Match container height minus border */
}

#formula-display:empty::before {
    content: attr(data-placeholder);
    color: var(--color-text-placeholder);
}

/* Spilled cell formula display - grayed out and non-editable */
#formula-display.spilled-cell {
    color: var(--color-text-disabled);
    cursor: default;
    pointer-events: none;
}

/* Formula reference colors in text */
#formula-display .formula-ref,
#cell-display .formula-ref {
    font-weight: var(--font-weight-semibold);
    transition: text-shadow 0.15s ease;
    cursor: default;
}

/* Hover effect when mouse is over formula text (or corresponding grid highlight) */
#formula-display .formula-ref:hover,
#formula-display .formula-ref-hovered,
#cell-display .formula-ref:hover,
#cell-display .formula-ref-hovered {
    text-shadow: 0 0 2px currentColor;
}

/* Cell Editor Container - wrapper for contenteditable and hidden input */
#cell-editor-container {
    position: absolute;
    display: none;
    border: 1px solid var(--color-primary);
    background: var(--color-bg-input);
    box-sizing: border-box;
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.1);
    z-index: 100;
}

/* Hidden input for cell editor */
#cell-editor {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 100%;
    height: 100%;
}

/* Contenteditable for colored cell formula display */
#cell-display {
    width: 100%;
    height: 100%;
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 13px;
    color: var(--color-text-primary);
    background: transparent;
    padding: 2px 4px;
    outline: none;
    white-space: pre;
    overflow: hidden;
    box-sizing: border-box;
}

/* Column Header Editor */
#column-header-editor {
    position: absolute;
    display: none;
    border: 2px solid var(--color-primary);
    background: var(--color-bg-input);
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 12px;
    font-weight: 500;
    padding: 2px 4px;
    outline: none;
    box-sizing: border-box;
    z-index: 100;
    text-align: center;
    color: var(--color-text-primary);
}

#column-header-editor::placeholder {
    color: var(--color-text-placeholder);
    opacity: 1;
}

/* Export Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}

/* Dropdown arrow animation */
.dropdown .btn .arrow {
    font-size: 8px;
    transition: transform 0.15s ease;
}

.dropdown.open .btn .arrow {
    transform: rotate(180deg);
}

/* =============================================================================
 * Dropdown Frame (shared container for all dropdowns)
 * =============================================================================
 * Used by DropdownFrame class for consistent dropdown styling.
 * Uses fixed positioning - the positionDropdown() utility handles placement.
 */
.dropdown-frame {
    position: fixed;
    min-width: 120px;
    padding: var(--spacing-xs);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 16px var(--color-shadow);
    z-index: 1000;
}

.dropdown-frame.hidden {
    display: none;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--spacing-xs);
    min-width: 120px;
    padding: var(--spacing-xs);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 16px var(--color-shadow);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition:
        opacity var(--transition-fast),
        transform var(--transition-fast),
        visibility var(--transition-fast);
}

.dropdown.open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-normal);
    color: var(--color-text-primary);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s ease;
    border-radius: var(--border-radius-smaller);
}

.dropdown-item:hover {
    background: var(--color-bg-secondary);
}

.dropdown-item:active {
    background: var(--color-bg-hover);
}

.dropdown-item:disabled {
    color: var(--color-text-placeholder);
    cursor: not-allowed;
}

.dropdown-item:disabled:hover {
    background: none;
}

/* Bottom Bar (contains sheet tabs) */
#bottom-bar {
    display: flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bar-bg);
    border-top: 1px solid var(--color-border);
    min-height: 32px;
    gap: 2px;
}

#bottom-bar.hidden {
    display: none;
}

/* Sheet Tabs Container */
#sheet-tabs-container {
    display: flex;
    align-items: center;
    gap: 2px;
    overflow-x: auto;
}

/* Hide scrollbar but keep functionality */
#sheet-tabs-container::-webkit-scrollbar {
    display: none;
}

#sheet-tabs-container {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.sheet-tab {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--border-radius-top);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    position: relative;
    user-select: none;
}

.sheet-tab:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-secondary);
}

.sheet-tab.active {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    border-color: var(--color-border);
    border-bottom: none;
}

.sheet-tab.dragging {
    opacity: 0.5;
}

.sheet-tab-add {
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 16px;
    font-weight: var(--font-weight-normal);
    line-height: 22px;
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sheet-tab-add:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-secondary);
    border-color: var(--color-border);
}

.sheet-tab-add:active {
    background: var(--color-bg-active);
}

/* Sheet Tab Context Menu */
.sheet-tab-context-menu {
    position: fixed;
    min-width: 120px;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px var(--color-shadow-lg);
    z-index: 2000;
    padding: var(--spacing-xs);
}

.sheet-tab-context-menu-item {
    display: block;
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-normal);
    color: var(--color-text-primary);
    background: none;
    border: none;
    border-radius: var(--border-radius-smaller);
    text-align: left;
    cursor: pointer;
    transition: background 0.1s ease;
}

.sheet-tab-context-menu-item:hover {
    background: var(--color-bg-secondary);
}

.sheet-tab-context-menu-item:active {
    background: var(--color-bg-hover);
}

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

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

/* Sheet Tab Inline Editor */
.sheet-tab-editor {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    background: var(--color-bg-input);
    border: 2px solid var(--color-primary);
    border-radius: var(--border-radius);
    outline: none;
    min-width: 60px;
    max-width: 200px;
}

/* ============================================================================
   Bottom bar spacer and zoom controls
   ============================================================================ */

/* Spacer to push zoom controls to the right in bottom bar */
.bottom-bar-spacer {
    flex: 1;
}

/* Zoom controls in bottom bar - positioned at far right */
#zoom-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-left: 1px solid var(--color-border);
}

#zoom-level {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    min-width: 36px;
    text-align: center;
    user-select: none;
}

.zoom-btn {
    padding: 2px 4px;
}

.zoom-btn svg {
    display: block;
}

/* Zoom slider styling */
#zoom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

#zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: background var(--transition-fast);
}

#zoom-slider::-webkit-slider-thumb:hover {
    background: var(--color-primary-hover);
}

#zoom-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--color-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background var(--transition-fast);
}

#zoom-slider::-moz-range-thumb:hover {
    background: var(--color-primary-hover);
}

#zoom-slider::-moz-range-track {
    background: var(--color-border);
    border-radius: 2px;
    height: 4px;
}

/* Collaboration Status Badge */
.collab-status-badge {
    height: var(--control-height);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 var(--control-padding-x);
    font-size: var(--control-font-size);
    font-weight: var(--font-weight-medium);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.collab-status-badge:hover {
    background: var(--color-bg-secondary);
    border-color: var(--color-border-hover);
}

.collab-status-badge .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.collab-status-badge .status-text {
    color: var(--color-text-secondary);
}

/* Status states */
.collab-status-badge.offline .status-dot {
    background: #6c757d;
}

.collab-status-badge.offline .status-text {
    color: #6c757d;
}

.collab-status-badge.connecting .status-dot {
    background: #ffc107;
    animation: pulse 1.5s ease-in-out infinite;
}

.collab-status-badge.connecting .status-text {
    color: #856404;
}

.collab-status-badge.syncing .status-dot {
    background: #17a2b8;
    animation: pulse 1s ease-in-out infinite;
}

.collab-status-badge.syncing .status-text {
    color: #0c5460;
}

.collab-status-badge.online .status-dot {
    background: #28a745;
}

.collab-status-badge.online .status-text {
    color: #155724;
}

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

/* Connection details popup
   Spacing rhythm: panel 12px padding; section dividers 12px;
   rows 6px vertical; footer block 12px gap. */
.collab-status-details {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--spacing-xs);
    width: 240px;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 16px var(--color-shadow);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition:
        opacity 0.15s ease,
        transform 0.15s ease,
        visibility 0.15s ease;
    padding: 12px;
}

.collab-status-badge.show-details .collab-status-details {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.collab-status-details-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--color-text-secondary);
    padding: 6px 0;
}

.collab-status-details-row .label {
    color: var(--color-text-muted);
}

.collab-status-details-row .value {
    font-weight: 500;
    color: var(--color-text-primary);
}

.collab-status-details-peers {
    margin-top: 0;
}

.collab-status-details-peers .peer-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 4px 0;
    font-size: 12px;
}

.collab-status-details-peers .peer-color {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.collab-status-details-peers .peer-name {
    color: var(--color-text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Collaborate button - extends .btn.btn-icon */
.collab-collaborate-btn {
    position: relative;
}

/* Status dot inside collaborate button */
.collab-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6c757d;
    flex-shrink: 0;
}

.collab-status-dot.offline {
    background: #6c757d;
}

.collab-status-dot.connecting {
    background: #ffc107;
    animation: pulse 1.5s ease-in-out infinite;
}

.collab-status-dot.syncing {
    background: var(--color-secondary);
    animation: pulse 1s ease-in-out infinite;
}

.collab-status-dot.online {
    background: #198754;
}

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

/* Show details panel from collaborate button */
.collab-collaborate-btn.show-details .collab-status-details {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Share section */
.collab-status-share-section {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* Centered footer block: skill link + debug + version */
.collab-status-details-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

/* Skill/CLI install — underlined external link */
.collab-skill-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 12px;
    line-height: 1.3;
    color: var(--color-text-muted);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color var(--transition-fast);
}

.collab-skill-link:hover {
    color: var(--color-primary);
}

.collab-skill-link-icon {
    flex-shrink: 0;
    opacity: 0.85;
}

/* Divider */
.collab-status-details-divider {
    height: 1px;
    background: var(--color-border);
    margin: 12px 0;
}

/* Name / nickname row */
.collab-status-details-row.name-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 0;
}

.collab-status-details-row.name-row .label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

/* Inline name input */
.collab-name-edit-inline {
    width: 100%;
}

.collab-name-edit-inline input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--color-text-primary);
    background: var(--color-bg-input);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    outline: none;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.collab-name-edit-inline input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.1);
}

.collab-name-edit-inline input::placeholder {
    color: var(--color-text-placeholder);
}

/* Version footer — quiet, minimal footprint */
.collab-status-details-version {
    margin: 0;
    padding: 0;
    border-top: none;
    text-align: center;
    font-size: 10px;
    line-height: 1;
    color: var(--color-text-placeholder);
    opacity: 0.7;
    letter-spacing: 0.01em;
    user-select: none;
    pointer-events: none;
}

/* Share tooltip */
.collab-share-tooltip {
    position: fixed;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 12px;
    font-weight: 500;
    color: #fff;
    background: #212529;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.2s ease,
        visibility 0.2s ease;
    pointer-events: none;
}

.collab-share-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

.collab-share-tooltip::after {
    content: "";
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 6px 6px 6px;
    border-style: solid;
    border-color: transparent transparent #212529 transparent;
}

/* Debug section — centered with skill link + version */
.collab-status-details-debug {
    margin: 0;
    padding: 0;
    border-top: none;
    width: 100%;
}

.collab-status-details-debug .debug-toggle {
    display: flex;
    justify-content: center;
}

.collab-status-details-debug .debug-toggle label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    color: var(--color-text-placeholder);
    cursor: pointer;
}

.collab-status-details-debug .debug-toggle label:hover {
    color: var(--color-text-muted);
}

.collab-status-details-debug .debug-toggle input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    opacity: 0.6;
}

.collab-status-details-debug .debug-toggle input[type="checkbox"]:checked {
    opacity: 1;
}

.collab-status-details-debug .debug-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
    width: 100%;
}

.collab-status-details-debug .debug-actions .collab-status-details-row {
    padding: 0;
}

.collab-status-details-debug .debug-actions .value.poor {
    color: var(--color-danger);
    font-weight: 600;
}

/* Debug buttons use .btn.btn-sm.btn-block (and .btn-danger for danger variant) */

/* ============================================================================
   AST Debug Panel (for formula parser visualization)
   ============================================================================ */

#ast-debug-panel {
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace;
    font-size: 12px;
    max-height: 300px;
    overflow: auto;
    border-bottom: 1px solid #333;
}

#ast-debug-panel.hidden {
    display: none;
}

#ast-debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #252526;
    border-bottom: 1px solid #333;
    color: #cccccc;
    font-size: 11px;
}

#ast-debug-toggle {
    color: #808080;
}

#ast-debug-content {
    padding: 12px;
    overflow: auto;
    max-height: 250px;
}

#ast-errors {
    color: #f48771;
    margin-bottom: 8px;
}

#ast-errors:empty {
    display: none;
}

#ast-tree {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.4;
}

/* Syntax highlighting for AST JSON */
#ast-tree .ast-type {
    color: #4ec9b0;
    font-weight: 600;
}

#ast-tree .ast-key {
    color: #9cdcfe;
}

#ast-tree .ast-string {
    color: #ce9178;
}

#ast-tree .ast-number {
    color: #b5cea8;
}

#ast-tree .ast-boolean {
    color: #569cd6;
}

#ast-tree .ast-null {
    color: #569cd6;
}

/* ============================================================================
   Script Panel (Luau scripting interface)
   ============================================================================ */

#script-panel {
    background: var(--script-bg);
    color: var(--script-text);
    font-family: var(--font-mono);
    font-size: 13px;
    min-height: 150px;
    max-height: 50vh;
    height: 200px;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--script-border);
    position: relative;
}

#script-panel.hidden {
    display: none;
}

#script-panel-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

#script-line-numbers {
    width: 40px;
    padding: 12px 8px 12px 0;
    background: var(--script-bg-gutter);
    color: var(--script-text-muted);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    text-align: right;
    user-select: none;
    overflow: hidden;
    white-space: pre-line;
    border-right: 1px solid var(--script-border);
    flex-shrink: 0;
}

#script-editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#script-editor-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 12px;
    background: var(--script-bg);
    overflow: auto;
    pointer-events: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    tab-size: 2;
}

#script-editor-highlight {
    display: block;
    color: var(--script-text);
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

#script-editor {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    padding: 12px;
    background: transparent;
    color: transparent;
    caret-color: var(--script-caret);
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    tab-size: 2;
    overflow: auto;
}

#script-editor::placeholder {
    color: var(--script-text-muted);
}

/* Luau syntax highlighting tokens */
.luau-keyword {
    color: var(--script-token-keyword);
}

.luau-string {
    color: var(--script-token-string);
}

.luau-number {
    color: var(--script-token-number);
}

.luau-comment {
    color: var(--script-token-comment);
}

.luau-name {
    color: var(--script-token-name);
}

.luau-operator {
    color: var(--script-token-operator);
}

.luau-error {
    color: var(--script-token-error);
    text-decoration: wavy underline var(--script-token-error);
}

#script-panel-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 8px 12px;
    background: var(--script-bg-footer);
    border-top: 1px solid var(--script-border);
    flex-shrink: 0;
}

#script-status {
    font-size: 11px;
    color: var(--script-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#script-status.success {
    color: var(--script-status-success);
}

#script-status.error {
    color: var(--script-status-error);
}

#script-run-btn {
    flex-shrink: 0;
}

#script-run-btn .btn-shortcut {
    margin-left: var(--spacing-sm);
    opacity: 0.4;
}

/* Resize handle */
#script-panel-resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    cursor: ns-resize;
    background: transparent;
}

#script-panel-resize-handle:hover {
    background: var(--script-border);
}

#script-panel-resize-handle:active {
    background: var(--color-primary);
}

/* Script panel button active state */
#script-panel-btn.active {
    background: var(--color-bg-active);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* Console Panel (inside script panel) */
#script-console {
    display: flex;
    flex-direction: column;
    min-width: 150px;
    max-width: 50%;
    width: 250px;
    background: var(--script-bg);
    border-left: 1px solid var(--script-border);
    flex-shrink: 0;
}

#script-console.hidden {
    display: none;
}

#script-console-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    background: var(--script-bg-gutter);
    border-bottom: 1px solid var(--script-border);
    flex-shrink: 0;
}

#script-console-title {
    font-size: 11px;
    font-weight: 500;
    color: var(--script-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#script-console-actions {
    display: flex;
    gap: 4px;
}

.script-console-btn {
    width: 20px;
    height: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 3px;
    color: var(--script-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.script-console-btn:hover {
    background: var(--color-bg-hover);
    color: var(--script-text);
}

.script-console-btn:active {
    background: var(--color-bg-active);
}

#script-console-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--script-text);
    white-space: pre-wrap;
    word-break: break-word;
}

#script-console-content:empty::before {
    content: "Console output will appear here...";
    color: var(--script-text-muted);
    font-style: italic;
}

/* Console output lines */
.console-line {
    padding: 2px 0;
}

/* Horizontal resize handle between editor and console */
#script-console-resize-handle {
    width: 4px;
    cursor: ew-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background var(--transition-fast);
}

#script-console-resize-handle.hidden {
    display: none;
}

#script-console-resize-handle:hover {
    background: var(--script-border);
}

#script-console-resize-handle:active,
#script-console-resize-handle.dragging {
    background: var(--color-primary);
}

/* ============================================================================
   Custom Scrollbars (virtual scrolling)
   ============================================================================ */

/* Vertical scrollbar track */
.scrollbar-track-vertical {
    position: absolute;
    top: 0;
    right: 0;
    width: 12px;
    bottom: 12px; /* Leave space for corner */
    background: var(--color-bg-secondary);
    border-left: 1px solid var(--color-border);
    z-index: 50;
}

.scrollbar-track-vertical.hidden {
    display: none;
}

.scrollbar-track-vertical.active {
    background: var(--color-bg-hover);
}

/* Horizontal scrollbar track */
.scrollbar-track-horizontal {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 12px;
    right: 12px; /* Leave space for corner */
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
    z-index: 50;
}

.scrollbar-track-horizontal.hidden {
    display: none;
}

.scrollbar-track-horizontal.active {
    background: var(--color-bg-hover);
}

/* Scrollbar thumbs */
.scrollbar-thumb {
    position: absolute;
    background: var(--color-scrollbar-thumb);
    border-radius: var(--border-radius);
    transition: background 0.15s ease;
    cursor: pointer;
}

.scrollbar-thumb:hover {
    background: var(--color-scrollbar-thumb-hover);
}

.scrollbar-thumb:active,
.scrollbar-track-vertical.active .scrollbar-thumb,
.scrollbar-track-horizontal.active .scrollbar-thumb {
    background: var(--color-scrollbar-thumb-active);
}

.scrollbar-thumb-vertical {
    left: 2px;
    right: 2px;
    min-height: 30px;
}

.scrollbar-thumb-horizontal {
    top: 2px;
    bottom: 2px;
    min-width: 30px;
}

/* Corner where scrollbars meet */
.scrollbar-corner {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 12px;
    height: 12px;
    background: var(--color-bg-secondary);
    border-left: 1px solid var(--color-border);
    border-top: 1px solid var(--color-border);
    z-index: 50;
}

/* ============================================================================
   Context Menu (right-click menu)
   ============================================================================ */

.context-menu {
    position: fixed;
    min-width: 160px;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow:
        0 4px 16px var(--color-shadow),
        0 1px 3px var(--color-shadow);
    z-index: 2000;
    padding: var(--spacing-xs);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px) scale(0.98);
    transition:
        opacity var(--transition-fast),
        transform var(--transition-fast),
        visibility var(--transition-fast);
}

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

.context-menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-normal);
    color: var(--color-text-primary);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s ease;
    gap: var(--spacing-sm);
    border-radius: var(--border-radius-smaller);
}

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

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

.context-menu-item.disabled {
    color: var(--color-text-placeholder);
    cursor: not-allowed;
}

.context-menu-item.disabled:hover {
    background: none;
}

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

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

.context-menu-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.context-menu-label {
    flex: 1;
}

.context-menu-shortcut {
    margin-left: var(--spacing-lg);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
    opacity: 0.8;
}

.context-menu-separator {
    height: 1px;
    background: var(--color-bg-hover);
    margin: var(--spacing-xs) 0;
}

/* ============================================================================
   Modal Dialog
   ============================================================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.15s ease,
        visibility 0.15s ease;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--color-bg-primary);
    border-radius: var(--border-radius);
    box-shadow:
        0 8px 32px var(--color-shadow-lg),
        0 2px 8px var(--color-shadow);
    max-width: 420px;
    width: calc(100% - 32px);
    transform: translateY(-8px) scale(0.98);
    transition: transform 0.15s ease;
}

.modal-overlay.visible .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px 0;
}

.modal-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.modal-icon-warning {
    color: var(--color-warning);
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.modal-body {
    padding: 16px 24px 20px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text-secondary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 24px 20px;
}

.modal-footer-stack {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

/* Full-width stacked actions: avoid .btn fixed height + padding clash */
.modal-footer-stack .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: auto;
    min-height: 36px;
    padding: 10px 16px;
    font-size: 13px;
    line-height: 1.3;
    white-space: normal;
    text-align: center;
    box-sizing: border-box;
}

/* Modal buttons use .btn and .btn.btn-primary with padding/font override */
.modal-footer:not(.modal-footer-stack) .btn {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: var(--border-radius);
}

/* Warning modal variant */
.modal.modal-warning .btn.btn-primary {
    background: var(--color-warning);
    border-color: var(--color-warning);
}

.modal.modal-warning .btn.btn-primary:hover {
    background: var(--color-warning-hover);
    border-color: var(--color-warning-hover);
}

.modal.modal-warning .btn.btn-primary:active {
    background: #b45309;
    border-color: #b45309;
}

.modal.modal-warning .btn:focus {
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

/* ============================================================================
   Autocomplete Popup (script editor) - extends .dropdown-frame
   ============================================================================ */

.autocomplete-popup {
    position: absolute;
    min-width: 200px;
    max-width: 400px;
    max-height: 200px;
    overflow-y: auto;
}

.autocomplete-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    cursor: pointer;
    border-radius: var(--border-radius-smaller);
    transition: background 0.1s ease;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: var(--color-bg-secondary);
}

.autocomplete-item.selected {
    background: var(--color-bg-hover);
}

.autocomplete-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.autocomplete-label {
    flex: 1;
    font-family: var(--font-mono);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.autocomplete-label.deprecated {
    text-decoration: line-through;
    opacity: 0.7;
}

.autocomplete-detail {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-left: auto;
    padding-left: var(--spacing-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.autocomplete-signature {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    margin-left: var(--spacing-xs);
    white-space: nowrap;
}

/* Type correctness indicators */
.autocomplete-item.type-correct {
    background: color-mix(in srgb, var(--color-success) 10%, transparent);
}

.autocomplete-item.type-correct:hover,
.autocomplete-item.type-correct.selected {
    background: color-mix(in srgb, var(--color-success) 20%, transparent);
}

.autocomplete-item.type-correct-fn {
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

.autocomplete-item.type-correct-fn:hover,
.autocomplete-item.type-correct-fn.selected {
    background: color-mix(in srgb, var(--color-primary) 15%, transparent);
}

.autocomplete-type-indicator {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--color-success);
    margin-left: var(--spacing-xs);
}

/* ============================================================================
   Style Controls (text formatting, colors)
   ============================================================================ */

/* Style buttons (B, I, U) */
.style-btn {
    min-width: 24px;
    justify-content: center;
    font-family: inherit;
}

.style-btn strong {
    font-weight: 700;
}

.style-btn em {
    font-style: italic;
}

/* Active state for style buttons (when format is applied) */
.style-btn.active {
    background: var(--color-bg-active);
    font-weight: var(--font-weight-bold);
}

.style-btn.active:hover {
    background: var(--color-bg-active);
}

/* Color picker wrapper (contains button + popup) */
.color-picker-wrapper {
    position: relative;
}

/* Color button - override .btn.btn-icon flex row layout */
.color-btn.btn.btn-icon {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 0 var(--spacing-sm);
    height: 24px;
}

.color-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.color-btn-icon svg {
    width: 14px;
    height: 14px;
    display: block;
}

/* Color swatch under icon */
.color-swatch {
    width: 14px;
    height: 3px;
    border-radius: 1px;
    flex-shrink: 0;
    /* Default state shows a border outline */
    border: 1px solid var(--color-border);
    box-sizing: border-box;
}

/* When a color is set via inline style, the background will show */

/* Color picker popup */
.color-picker-popup {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: var(--spacing-xs);
    padding: var(--spacing-sm);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 16px var(--color-shadow);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition:
        opacity var(--transition-fast),
        transform var(--transition-fast),
        visibility var(--transition-fast);
}

.color-picker-wrapper.open .color-picker-popup {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Color palette grid */
.color-picker-palette {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    margin-bottom: var(--spacing-sm);
}

/* Individual color option */
.color-option {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid var(--color-border);
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
}

.color-option:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px var(--color-shadow);
    z-index: 1;
}

.color-option.selected {
    box-shadow: 0 0 0 2px var(--color-primary);
}

/* No fill option (transparent with diagonal line) */
.color-option.no-color {
    background: linear-gradient(
        to top right,
        var(--color-bg-primary) 45%,
        var(--color-danger) 45%,
        var(--color-danger) 55%,
        var(--color-bg-primary) 55%
    );
}

/* Custom hex input */
.color-picker-custom {
    border-top: 1px solid var(--color-border);
    padding-top: var(--spacing-sm);
}

.color-hex-input {
    width: 100%;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-sm);
    font-family: var(--font-mono);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-input);
    color: var(--color-text-primary);
    text-transform: uppercase;
}

.color-hex-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(5, 134, 1, 0.1);
}

.color-hex-input::placeholder {
    color: var(--color-text-placeholder);
    text-transform: none;
}

/* Theme color label in hex input (read-only when showing theme slot name) */
.color-hex-input.theme-label {
    text-transform: none;
    color: var(--color-text-secondary);
    font-family: var(--font-sans);
    font-style: italic;
    cursor: default;
}

/* Theme color section in color picker */
.color-picker-theme {
    margin-bottom: var(--spacing-xs);
}

.color-picker-theme:empty {
    display: none;
}

.color-picker-theme-label {
    font-size: 10px;
    color: var(--color-text-secondary);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.color-picker-theme-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
}

.color-picker-theme-grid .color-option {
    width: 18px;
    height: 18px;
    border-radius: 2px;
}

/* Standard colors section */
.color-picker-standard {
    border-top: 1px solid var(--color-border);
    padding-top: var(--spacing-xs);
}

.color-picker-standard-label {
    font-size: 10px;
    color: var(--color-text-secondary);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Mixed state indicator (when selection has different values) */
/* Note: Buttons should look normal (not disabled) when mixed - they're still clickable */
/* The non-highlighted state already indicates the property is not uniformly applied */
.style-btn.mixed,
.color-btn.mixed {
    /* No special styling - button looks like default state */
    /* User can click to apply the property to the entire selection */
}

/* Font dropdowns */
.font-dropdown {
    display: inline-block;
}

#font-family-dropdown {
    flex: 1; /* Expand to fill available space in row */
}

#font-family-btn {
    width: 100%;
    height: 24px; /* Fixed height to prevent layout shifts */
    border: 1px solid var(--color-border) !important;
}

#font-family-label {
    display: inline-block;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    line-height: 1; /* Consistent line height regardless of font */
    vertical-align: middle;
}

#font-size-btn {
    min-width: 40px;
    border: 1px solid var(--color-border) !important;
}

#font-size-label {
    min-width: 16px;
    text-align: center;
}

.font-dropdown-menu {
    left: 0;
    right: auto;
    min-width: 120px;
    max-height: 250px;
    overflow-y: auto;
}

.font-dropdown-menu.font-size-menu {
    min-width: 60px;
}

.font-dropdown-menu .dropdown-item {
    padding: var(--spacing-xs) var(--spacing-sm);
}

.font-dropdown-menu .font-item {
    font-size: var(--font-size-md);
}

/* Font dropdown open state */
.font-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

/* Merge Cells Dropdown */
.merge-dropdown {
    display: inline-flex;
}

.merge-dropdown #merge-btn {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px;
}

.merge-dropdown #merge-btn svg:first-child {
    width: 14px;
    height: 14px;
}

.merge-dropdown-menu {
    left: auto;
    right: 0;
    min-width: 160px;
}

.merge-dropdown-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.merge-dropdown-menu .dropdown-item svg {
    flex-shrink: 0;
}

.merge-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

/* Border Dropdown */
.border-dropdown {
    display: inline-flex;
}

.border-dropdown #border-btn {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px;
}

.border-dropdown #border-btn svg:first-child {
    width: 14px;
    height: 14px;
}

.border-dropdown-menu {
    left: auto;
    right: 0;
    min-width: 160px;
}

.border-dropdown-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.border-dropdown-menu .dropdown-item svg {
    flex-shrink: 0;
}

.border-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

/* Border style selector */
.dropdown-section-label {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.border-style-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: var(--spacing-xs) var(--spacing-sm) var(--spacing-sm);
}

.border-style-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 4px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.border-style-btn:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border-active);
}

.border-style-btn.selected {
    background: var(--color-primary-bg);
    border-color: var(--color-primary);
}

.border-style-btn svg {
    color: var(--color-text-primary);
}

.border-style-btn.selected svg {
    color: var(--color-primary);
}

/* Border color section */
.border-color-section {
    padding: var(--spacing-xs) var(--spacing-sm) var(--spacing-sm);
}

.border-color-palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    margin-bottom: var(--spacing-sm);
}

.border-color-option {
    width: 24px;
    height: 24px;
    border-radius: 3px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
}

.border-color-option:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px var(--color-shadow);
}

.border-color-option.selected {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-bg);
}

.border-color-custom {
    border-top: 1px solid var(--color-border);
    padding-top: var(--spacing-sm);
}

/* Border button style indicator */
.border-btn-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.border-style-indicator {
    margin-top: -2px;
}

/* Alignment button groups */
.align-btn-group {
    display: flex;
    gap: var(--spacing-xs);
}

.align-btn {
    min-width: 22px;
    height: 22px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
}

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

.align-btn.active {
    background: var(--color-bg-active);
    font-weight: var(--font-weight-bold);
}

.align-btn.active:hover {
    background: var(--color-bg-active);
}

.align-btn svg {
    width: 12px;
    height: 12px;
}

/* =============================================================================
   Cell Styles Gallery
   ============================================================================= */

/* Themes / Cell Styles buttons in alignment block */
.toolbar-gallery-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    white-space: nowrap;
}

.toolbar-gallery-label {
    font-size: var(--font-size-xs);
}

/* Gallery dropdown */
.cell-styles-gallery {
    position: fixed;
    width: 340px;
    max-height: 420px;
    overflow-y: auto;
    padding: var(--spacing-sm);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 16px var(--color-shadow);
    z-index: 1000;
}

.cell-styles-gallery.hidden {
    display: none;
}

/* Category header */
.cell-styles-category {
    font-size: 10px;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 8px 0 4px 0;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--color-separator);
}

.cell-styles-category:first-child {
    margin-top: 0;
}

/* Preset grid */
.cell-styles-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    margin-bottom: 4px;
}

/* Individual preset chip */
.cell-style-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    padding: 2px 6px;
    border: 1px solid var(--color-border);
    border-radius: 3px;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: 11px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: box-shadow 0.1s ease;
}

.cell-style-chip:hover {
    box-shadow: 0 0 0 2px var(--color-primary);
}

.cell-style-chip:active {
    opacity: 0.8;
}

/* =============================================================================
   Theme Gallery
   ============================================================================= */

/* Gallery dropdown */
.theme-gallery {
    position: fixed;
    width: 280px;
    max-height: 420px;
    overflow-y: auto;
    padding: var(--spacing-sm);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 16px var(--color-shadow);
    z-index: 1000;
}

.theme-gallery.hidden {
    display: none;
}

/* Category header */
.theme-gallery-category {
    font-size: 10px;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 8px 0 4px 0;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--color-separator);
}

.theme-gallery-category:first-child {
    margin-top: 0;
}

/* Individual theme row */
.theme-gallery-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 5px 8px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--color-text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.1s ease;
    text-align: left;
}

.theme-gallery-row:hover {
    background-color: var(--color-bg-hover);
}

.theme-gallery-row-active {
    background-color: var(--color-bg-selected);
}

/* Checkmark */
.theme-gallery-check {
    width: 14px;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--color-primary);
    text-align: center;
}

/* Theme name */
.theme-gallery-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Accent color swatches */
.theme-gallery-swatches {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.theme-gallery-swatch {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid var(--color-border);
}
