/* ================================================================
   DataForge — Design System
   Glassmorphism dark theme with clear visual hierarchy
   ================================================================ */

/* ─── CSS Variables ─── */
:root {
    /* Background */
    --bg-base: #000000;
    --bg-surface: rgba(255, 255, 255, 0.08);
    --bg-surface-hover: rgba(255, 255, 255, 0.15);
    --bg-glass: rgba(10, 10, 10, 0.85);
    --bg-glass-strong: rgba(5, 5, 5, 0.98);

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.1);
    --border-medium: rgba(255, 255, 255, 0.25);
    --border-strong: rgba(255, 255, 255, 0.5);

    /* Text */
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.75);
    --text-tertiary: rgba(255, 255, 255, 0.45);
    --text-inverse: #000000;

    /* Accent */
    --accent: #ffffff;
    --accent-soft: rgba(255, 255, 255, 0.18);
    --accent-medium: rgba(255, 255, 255, 0.45);
    --accent-glow: rgba(255, 255, 255, 0.2);

    /* Functional colors */
    --success: #ffffff;
    --success-soft: rgba(255, 255, 255, 0.1);
    --danger: #ff4757;
    --danger-soft: rgba(255, 71, 87, 0.12);
    --warning: #ffab00;
    --warning-soft: rgba(255, 171, 0, 0.12);

    /* Grid */
    --grid-border: rgba(255, 255, 255, 0.04);
    --grid-header-bg: rgba(255, 255, 255, 0.05);
    --grid-row-alt: rgba(255, 255, 255, 0.015);
    --grid-row-num-bg: rgba(8, 12, 24, 0.95);
    --row-height: 34px;
    --header-height: 36px;
    --row-num-width: 54px;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px rgba(78, 140, 255, 0.15);

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition-fast: 120ms var(--ease-out);
    --transition-base: 200ms var(--ease-out);
    --transition-slow: 350ms var(--ease-out);
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background: var(--accent-medium);
    color: #fff;
}

/* ─── Animated Background Blobs ─── */
.bg-blobs {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    display: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.25;
    will-change: transform;
}

.blob-1 {
    width: 500px;
    height: 500px;
    background: linear-gradient(135deg, #4e8cff, #6c5ce7);
    top: -15%;
    left: -10%;
    animation: blobFloat1 22s infinite ease-in-out;
}

.blob-2 {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, #a855f7, #ec4899);
    bottom: -10%;
    right: -8%;
    animation: blobFloat2 26s infinite ease-in-out;
}

.blob-3 {
    width: 350px;
    height: 350px;
    background: linear-gradient(135deg, #06b6d4, #10b981);
    top: 45%;
    left: 55%;
    animation: blobFloat3 20s infinite ease-in-out;
}

@keyframes blobFloat1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(80px, 60px) scale(1.1); }
    66% { transform: translate(-40px, 100px) scale(0.95); }
}

@keyframes blobFloat2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(-70px, -50px) scale(1.08); }
    66% { transform: translate(50px, -80px) scale(0.92); }
}

@keyframes blobFloat3 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(60px, -70px) scale(1.05); }
    66% { transform: translate(-80px, 30px) scale(0.97); }
}

/* ─── App Layout ─── */
.app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    gap: 0;
}

/* ─── Toolbar ─── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 20;
}

.toolbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 8px;
}

.toolbar-brand svg {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}

.toolbar-brand h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #ffffff;
    white-space: nowrap;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-subtle);
    margin: 0 6px;
}

.toolbar-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.toolbar-actions button:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.toolbar-actions button:active {
    transform: scale(0.92);
}

.toolbar-actions button.danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.toolbar-actions button svg {
    width: 18px;
    height: 18px;
    pointer-events: none;
}

.toolbar-actions button[title]::after {
    content: attr(title);
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-glass-strong);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    z-index: 100;
    backdrop-filter: blur(12px);
}

.toolbar-actions button:hover[title]::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

.toolbar-status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.save-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    transition: all var(--transition-base);
}

.save-indicator.saved {
    color: var(--success);
    border-color: rgba(0, 230, 118, 0.1);
}

.save-indicator.saving {
    color: var(--warning);
    border-color: rgba(255, 171, 0, 0.1);
}

.save-indicator svg {
    width: 14px;
    height: 14px;
}

/* ─── Info Bar (Cell Reference + Preview) ─── */
.info-bar {
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 0 20px;
    height: 34px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 15;
}

.cell-reference {
    width: 80px;
    padding: 0 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    border-right: 1px solid var(--border-subtle);
    text-align: center;
    font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
    flex-shrink: 0;
}

.cell-content-preview {
    flex: 1;
    padding: 0 12px;
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Grid Area ─── */
.grid-area {
    flex: 1;
    padding: 12px 16px;
    overflow: hidden;
    position: relative;
}

.grid-container {
    width: 100%;
    height: 100%;
    position: relative;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.grid-container:focus {
    outline: none;
    border-color: var(--border-medium);
}

/* Scroll wrapper */
.grid-scroll-wrap {
    width: 100%;
    height: 100%;
    overflow: auto;
    position: relative;
}

/* ─── Grid Header ─── */
.grid-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    height: var(--header-height);
    background: var(--bg-glass-strong);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-medium);
    min-width: fit-content;
}

.grid-corner {
    position: sticky;
    left: 0;
    z-index: 12;
    width: var(--row-num-width);
    min-width: var(--row-num-width);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg-glass-strong);
    border-right: 1px solid var(--border-medium);
}

.grid-header-cells {
    display: flex;
    height: 100%;
}

.header-cell {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-right: 1px solid var(--grid-border);
    cursor: default;
    user-select: none;
    flex-shrink: 0;
    transition: background var(--transition-fast);
    overflow: hidden;
}

.header-cell:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.header-cell .header-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-editor {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--accent-soft);
    color: var(--text-primary);
    font-size: 11.5px;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    padding: 0 4px;
    outline: none;
    border-radius: 2px;
}

.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 2;
}

.col-resize-handle:hover,
.col-resize-handle:active {
    background: var(--accent);
    opacity: 0.5;
}

/* ─── Grid Viewport (Virtual Rows) ─── */
.grid-viewport {
    position: relative;
    min-width: fit-content;
}

.grid-row {
    position: absolute;
    left: 0;
    display: flex;
    height: var(--row-height);
    min-width: 100%;
    border-bottom: 1px solid var(--grid-border);
}

.grid-row:nth-child(even) {
    background: var(--grid-row-alt);
}

.grid-row.row-in-sel {
    background: rgba(78, 140, 255, 0.03);
}

.grid-row:hover {
    background: var(--bg-surface);
}

/* Row numbers */
.row-number {
    position: sticky;
    left: 0;
    z-index: 5;
    width: var(--row-num-width);
    min-width: var(--row-num-width);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-tertiary);
    background: var(--grid-row-num-bg);
    border-right: 1px solid var(--border-subtle);
    cursor: pointer;
    user-select: none;
    font-variant-numeric: tabular-nums;
    transition: all var(--transition-fast);
}

.row-number:hover {
    background: var(--bg-surface-hover);
    color: var(--text-secondary);
}

.row-number.rn-sel {
    background: var(--accent-soft);
    color: var(--accent);
}

/* Grid cells */
.grid-cell {
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-primary);
    border-right: 1px solid var(--grid-border);
    cursor: cell;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 0;
}

.grid-cell:hover {
    background: var(--bg-surface);
}

.grid-cell.cell-active {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 2px var(--accent);
    z-index: 3;
    position: relative;
}

.grid-cell.cell-in-range {
    background: var(--accent-soft);
}

/* ─── Cell Editor ─── */
.cell-editor {
    position: absolute;
    z-index: 20;
    border: 2px solid var(--accent);
    background: rgba(15, 22, 42, 0.97);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    padding: 0 10px;
    outline: none;
    box-shadow: var(--shadow-md), 0 0 0 4px rgba(78, 140, 255, 0.15);
    border-radius: 2px;
}

/* ─── Sheet Tabs ─── */
.sheet-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    height: 40px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 15;
}

.add-sheet-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--border-medium);
    background: transparent;
    color: var(--text-tertiary);
    font-size: 16px;
    font-weight: 300;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.add-sheet-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.tabs-container {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    flex: 1;
    scrollbar-width: none;
}

.tabs-container::-webkit-scrollbar {
    display: none;
}

.sheet-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    position: relative;
}

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

.sheet-tab.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(255, 255, 255, 0.2);
    font-weight: 600;
}

.sheet-tab .tab-close {
    display: none;
    width: 16px;
    height: 16px;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-tertiary);
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.sheet-tab:hover .tab-close {
    display: flex;
}

.sheet-tab .tab-close:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.sheet-tab-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--accent);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    outline: none;
    width: 80px;
    padding: 0;
}

.status-info {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-tertiary);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.status-divider {
    opacity: 0.4;
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

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

.modal {
    width: 480px;
    max-width: 90vw;
    background: var(--bg-glass-strong);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    transform: scale(0.95) translateY(10px);
    transition: transform var(--transition-slow);
    overflow: hidden;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.modal-close {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 18px;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.modal-body {
    padding: 24px;
}

/* ─── Drop Zone ─── */
.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 24px;
    border: 2px dashed var(--border-medium);
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
    transition: all var(--transition-base);
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.drop-zone.drag-over {
    transform: scale(1.01);
}

.drop-zone svg {
    width: 44px;
    height: 44px;
    color: var(--text-tertiary);
    transition: color var(--transition-base);
}

.drop-zone:hover svg,
.drop-zone.drag-over svg {
    color: var(--accent);
}

.drop-zone p {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.drop-zone span {
    font-size: 12px;
    color: var(--text-tertiary);
}

.btn-browse {
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    color: #000000;
    background: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
}

.btn-browse:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 16px rgba(255, 255, 255, 0.2);
}

.btn-browse:active {
    transform: translateY(0);
}

.drop-hint {
    font-size: 11px !important;
    color: var(--text-tertiary) !important;
    margin-top: 4px;
}

/* ─── Context Menu ─── */
.context-menu {
    position: fixed;
    z-index: 200;
    min-width: 200px;
    padding: 6px;
    background: var(--bg-glass-strong);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
}

.context-menu.open {
    display: block;
    animation: ctxFadeIn 150ms var(--ease-out);
}

@keyframes ctxFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.context-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.context-menu button:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.context-menu button.ctx-danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.context-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 4px 8px;
}

/* ─── Empty State ─── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
    text-align: center;
    padding: 40px;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--text-tertiary);
    opacity: 0.5;
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 340px;
    line-height: 1.6;
}

.empty-state-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.btn-primary {
    padding: 10px 24px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    color: #000000;
    background: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: 0 2px 12px rgba(255, 255, 255, 0.1);
}

.btn-primary:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.2);
}

.btn-secondary {
    padding: 10px 24px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
}

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

/* ─── Custom Scrollbars ─── */
.grid-scroll-wrap::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.grid-scroll-wrap::-webkit-scrollbar-track {
    background: transparent;
}

.grid-scroll-wrap::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.grid-scroll-wrap::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

.grid-scroll-wrap::-webkit-scrollbar-corner {
    background: transparent;
}

/* Firefox scrollbars */
.grid-scroll-wrap {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* ─── Utility Animations ─── */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

.saving-pulse {
    animation: pulse 1.5s infinite;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .toolbar {
        padding: 8px 12px;
        gap: 8px;
    }

    .toolbar-brand h1 {
        font-size: 15px;
    }

    .toolbar-group {
        gap: 0;
    }

    .toolbar-actions button {
        width: 30px;
        height: 30px;
    }

    .grid-area {
        padding: 8px;
    }

    .info-bar {
        padding: 0 12px;
    }

    .cell-reference {
        width: 60px;
    }
}

/* ─── Grouping and Filtering UI Elements ─── */

.toolbar-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 4px 0 8px;
    user-select: none;
}

.toolbar-select {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 12px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toolbar-select:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-medium);
}

.toolbar-select option {
    background: var(--bg-base);
    color: var(--text-primary);
}

.col-filter-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-left: auto;
    opacity: 0;
    transition: all var(--transition-fast);
    z-index: 5;
    flex-shrink: 0;
}

.header-cell:hover .col-filter-btn,
.col-filter-btn.active {
    opacity: 1;
}

.col-filter-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.col-filter-btn.active {
    color: var(--accent);
    opacity: 1;
}

.col-filter-btn svg {
    width: 12px;
    height: 12px;
    pointer-events: none;
}

.filter-popover {
    position: absolute;
    z-index: 1000;
    width: 220px;
    background: var(--bg-glass-strong);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: slideUp var(--transition-fast);
}

.filter-search-input {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 12px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition-fast);
}

.filter-search-input:focus {
    border-color: var(--accent);
}

.filter-options-list {
    max-height: 160px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px;
}

/* Custom scrollbar for filter list */
.filter-options-list::-webkit-scrollbar {
    width: 4px;
}
.filter-options-list::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 2px;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    user-select: none;
    transition: background var(--transition-fast);
}

.filter-option:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.filter-option input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

.filter-actions {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    border-top: 1px solid var(--border-subtle);
    padding-top: 8px;
    margin-top: 2px;
}

.filter-actions button {
    padding: 5px 10px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.filter-btn-clear {
    background: transparent;
    color: var(--text-secondary);
}

.filter-btn-clear:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
}

.filter-btn-apply {
    background: var(--accent);
    color: var(--text-inverse);
}

.filter-btn-apply:hover {
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.25);
}

/* ─── Group Header Row ─── */
.group-header-row {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.02) 100%) !important;
    border-left: 4px solid var(--accent);
    font-weight: 600;
    cursor: pointer !important;
    display: flex;
    align-items: center;
}

.group-header-toggle {
    color: var(--accent) !important;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-base);
}

.group-header-row.collapsed .group-header-toggle {
    transform: rotate(-90deg);
}

.group-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 14px;
    font-size: 13px;
    color: var(--text-primary);
}

.group-header-count {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    background: var(--bg-surface);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

/* ─── Cell Editor with Hamburger Dropdown ─── */
.cell-editor-container {
    position: absolute;
    z-index: 100;
    display: flex;
    align-items: center;
    background: #000000;
    border: 2px solid #ffffff;
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.25);
}

.cell-editor-input {
    flex: 1;
    height: 100%;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: #ffffff;
    font-size: 13px;
    font-family: inherit;
    padding: 0 8px;
}

.cell-dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
    transition: background var(--transition-fast);
}

.cell-dropdown-trigger:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Hamburger button visible on active cell */
.grid-cell {
    position: relative;
}

.cell-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-quick-btn {
    display: none;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    color: #ffffff;
    font-size: 11px;
    cursor: pointer;
    z-index: 5;
    padding: 0;
    line-height: 1;
}

.grid-cell.cell-active .cell-quick-btn,
.grid-cell:hover .cell-quick-btn {
    display: flex;
}

.cell-quick-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    border-color: #ffffff;
}

/* Dropdown Menu (1 al 4) */
.cell-dropdown-menu {
    position: fixed;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #0d0d0d;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-md);
    padding: 4px;
    min-width: 85px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.9), 0 0 10px rgba(255, 255, 255, 0.1);
    animation: fadeIn 120ms ease-out;
}

.cell-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.cell-dropdown-item:hover {
    background: rgba(255, 255, 255, 0.2);
}

.cell-dropdown-item.item-clear {
    color: #ff4757;
    font-size: 11px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    margin-top: 3px;
    padding-top: 5px;
}

.cell-dropdown-item.item-clear:hover {
    background: rgba(255, 71, 87, 0.2);
    color: #ff6b81;
}

/* ─── Light Theme (Blanco y Negro Claro) ─── */
body.light-theme {
    --bg-base: #f7f7f8;
    --bg-surface: rgba(0, 0, 0, 0.05);
    --bg-surface-hover: rgba(0, 0, 0, 0.09);
    --bg-glass: rgba(255, 255, 255, 0.9);
    --bg-glass-strong: #ffffff;

    --border-subtle: rgba(0, 0, 0, 0.1);
    --border-medium: rgba(0, 0, 0, 0.22);
    --border-strong: rgba(0, 0, 0, 0.6);

    --text-primary: #000000;
    --text-secondary: rgba(0, 0, 0, 0.7);
    --text-tertiary: rgba(0, 0, 0, 0.45);
    --text-inverse: #ffffff;

    --accent: #000000;
    --accent-soft: rgba(0, 0, 0, 0.08);
    --accent-medium: rgba(0, 0, 0, 0.2);
    --accent-glow: rgba(0, 0, 0, 0.1);

    --grid-border: rgba(0, 0, 0, 0.12);
    --grid-header-bg: #ececec;
    --grid-row-alt: rgba(0, 0, 0, 0.02);
    --grid-row-num-bg: #f0f0f0;
}

body.light-theme .toolbar-brand h1 {
    color: #000000;
}

body.light-theme .cell-editor-container {
    background: #ffffff;
    border-color: #000000;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

body.light-theme .cell-editor-input {
    color: #000000;
}

body.light-theme .cell-dropdown-trigger {
    background: rgba(0, 0, 0, 0.06);
    border-left-color: rgba(0, 0, 0, 0.15);
    color: #000000;
}

body.light-theme .cell-dropdown-trigger:hover {
    background: rgba(0, 0, 0, 0.14);
}

body.light-theme .cell-quick-btn {
    background: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.2);
    color: #000000;
}

body.light-theme .cell-quick-btn:hover {
    background: rgba(0, 0, 0, 0.2);
    border-color: #000000;
}

body.light-theme .cell-dropdown-menu {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.25);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

body.light-theme .cell-dropdown-item {
    color: #000000;
}

body.light-theme .cell-dropdown-item:hover {
    background: rgba(0, 0, 0, 0.08);
}

body.light-theme .btn-browse,
body.light-theme .btn-primary {
    color: #ffffff;
    background: #000000;
}

body.light-theme .btn-browse:hover,
body.light-theme .btn-primary:hover {
    background: #222222;
}

body.light-theme .filter-popover {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.2);
    color: #000000;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

body.light-theme .filter-search-input {
    background: #f0f0f0;
    color: #000000;
    border-color: rgba(0, 0, 0, 0.15);
}

body.light-theme .filter-btn-apply {
    background: #000000;
    color: #ffffff;
}

body.light-theme .filter-btn-apply:hover {
    background: #222222;
}

body.light-theme .group-header-row {
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.07) 0%, rgba(0, 0, 0, 0.01) 100%) !important;
    border-left: 4px solid #000000;
}

body.light-theme .context-menu {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

body.light-theme .context-menu button {
    color: #333333;
}

body.light-theme .context-menu button:hover {
    background: rgba(0, 0, 0, 0.07);
    color: #000000;
}

/* ─── Mobile Responsiveness (Celulares y Tablets) ─── */
@media (max-width: 768px) {
    .app {
        height: 100dvh;
        width: 100vw;
    }

    .toolbar {
        padding: 6px 8px;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .toolbar::-webkit-scrollbar {
        display: none;
    }

    .toolbar-brand h1 {
        font-size: 15px;
    }

    .toolbar-brand svg {
        width: 22px;
        height: 22px;
    }

    .toolbar-actions {
        gap: 4px;
        flex-shrink: 0;
    }

    .toolbar-group button {
        min-width: 34px;
        height: 34px;
        padding: 6px;
    }

    .toolbar-label {
        display: none;
    }

    .toolbar-select {
        height: 34px;
        font-size: 12px;
        max-width: 110px;
    }

    .toolbar-status {
        display: none;
    }

    .info-bar {
        padding: 4px 8px;
        gap: 8px;
    }

    .cell-reference {
        min-width: 44px;
        font-size: 11px;
    }

    .cell-content-preview {
        font-size: 11px;
    }

    .sheet-tabs {
        padding: 4px 8px;
        height: 38px;
    }

    .status-info {
        display: none;
    }

    .sheet-tab {
        padding: 4px 10px;
        font-size: 11px;
    }

    .modal {
        width: 92%;
        max-width: 360px;
        padding: 16px;
    }
}

