/* ==========================================================================
   Table to Excel - World-Class Premium Editor Styles
   ========================================================================== */

:root {
    /* Brand Colors */
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.4);
    --secondary: #8b5cf6;
    --secondary-glow: rgba(139, 92, 246, 0.4);

    /* Backgrounds & Surfaces */
    --bg-base: #06090f;
    /* Extremely deep blue/black */
    --surface-glass: rgba(15, 23, 42, 0.6);
    --surface-glass-hover: rgba(30, 41, 59, 0.8);
    --surface-solid: #0f172a;
    --surface-raised: #1e293b;

    /* Borders & Lines */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.2);

    /* Typography */
    --text-pure: #ffffff;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Jspreadsheet Specific Overrides */
    --js-cell-bg: #090e17;
    --js-header-bg: #0e1522;
    --js-border: rgba(255, 255, 255, 0.05);
    /* Very subtle grid lines */
    --js-selection: rgba(59, 130, 246, 0.15);
    /* Soft blue fill for selection */

    /* Effects */
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.7);
    --blur-md: blur(12px);
    --blur-lg: blur(24px);

    font-family: 'Inter', -apple-system, sans-serif;
}

/* Base Body Setup */
body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-base);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Ambient Background Glows --- */
.bg-glow {
    position: absolute;
    width: 600px;
    height: 600px;
    filter: blur(100px);
    border-radius: 50%;
    z-index: 0;
    opacity: 0.15;
    pointer-events: none;
    animation: float 20s ease-in-out infinite alternate;
}

.bg-glow-blue {
    background: var(--primary);
    top: -200px;
    left: -100px;
}

.bg-glow-purple {
    background: var(--secondary);
    bottom: -200px;
    right: -100px;
    animation-delay: -10s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(50px, 50px) scale(1.1);
    }
}

/* --- App Layout shell --- */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    z-index: 10;
}

.navbar {
    height: 64px;
    background: var(--surface-glass);
    backdrop-filter: var(--blur-lg);
    -webkit-backdrop-filter: var(--blur-lg);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    flex-shrink: 0;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 1000;
}

.nav-left,
.nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-pure);
    letter-spacing: -0.02em;
}

.logo img {
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.gradient-text {
    background: linear-gradient(135deg, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-divider {
    width: 1px;
    height: 24px;
    background: var(--border-light);
    margin: 0 8px;
}

/* Editor Navigation Links */
.editor-nav {
    display: flex;
    align-items: center;
    gap: 24px;
}

.editor-nav a {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s ease;
}

.editor-nav a:hover {
    color: var(--text-pure);
}

@media (max-width: 900px) {
    .editor-nav {
        display: none;
    }
}

/* Document Title Input */
.document-title-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 12px;
    transition: all 0.2s ease;
}

.document-title-wrapper:hover:not(:has(input:disabled)) {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-light);
}

.document-title-wrapper:focus-within {
    background: var(--surface-glass);
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.sheet-title-input {
    background: transparent;
    border: none;
    color: var(--text-pure);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    padding: 8px 0;
    width: 200px;
    outline: none;
}

.sheet-title-input:disabled {
    color: var(--text-muted);
}

.sheet-title-icon {
    color: var(--text-muted);
    margin-left: 8px;
    display: flex;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
    outline: none;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 10px var(--primary-glow);
}

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:not(:disabled):active {
    transform: translateY(0);
}

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

.btn-ghost:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-pure);
}

.btn-outline {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.btn-outline:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-muted);
}

.export-group {
    display: flex;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
}

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

.dropdown-toggle .chevron {
    transition: transform 0.2s;
}

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

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: max-content;
    min-width: 240px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: var(--blur-lg);
    -webkit-backdrop-filter: var(--blur-lg);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    padding: 8px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.dropdown.open .dropdown-menu {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    color: var(--text-primary);
    font-family: inherit;
}

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

.dropdown-item:active {
    background: rgba(255, 255, 255, 0.1);
}

.dropdown-item .item-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.dropdown-item .item-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- Main Workspace --- */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: var(--blur-md);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px 16px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.1em;
}

.add-sheet-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    transition: all 0.2s;
}

.add-sheet-btn:hover {
    color: var(--text-pure);
    background: rgba(255, 255, 255, 0.1);
}

/* Sheets List */
.sheets-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sheet-tab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.sheet-tab:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
}

.sheet-tab.active {
    background: var(--surface-raised);
    color: var(--primary);
    border-color: var(--border-light);
    box-shadow: var(--shadow-sm);
}

.sheet-tab-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    padding-right: 8px;
}

.sheet-tab-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s, color 0.2s;
}

.sheet-tab:hover .sheet-tab-delete,
.sheet-tab.active .sheet-tab-delete {
    opacity: 1;
}

.sheet-tab-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    /* Red tint on hover */
    color: #ef4444;
}

/* --- Editor Core State --- */
.editor-core {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--js-cell-bg);
    overflow: hidden;
}

/* Spreadsheet wrapper fills all remaining space */
#spreadsheet {
    flex: 1;
    overflow: auto;
    position: relative;
    min-height: 0;
    /* critical for flex children to scroll */
}

/* jspreadsheet container element fills its parent */
#spreadsheet>div {
    width: 100%;
    height: 100%;
}

/* Override jspreadsheet table so it can scroll inside wrapper */
.jexcel_content {
    overflow: auto !important;
    max-height: calc(100vh - 185px);
}

/* Glass Overlay for Loading/Empty State */
.glass-overlay {
    position: absolute;
    inset: 0;
    background: rgba(6, 9, 15, 0.8);
    backdrop-filter: var(--blur-lg);
    -webkit-backdrop-filter: var(--blur-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.overlay-content {
    text-align: center;
    max-width: 400px;
    padding: 40px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-overlay.active .overlay-content {
    transform: translateY(0);
}

/* Hero Icon Animation */
.hero-icon-wrapper {
    position: relative;
    width: 64px;
    height: 64px;
    margin: 0 auto 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pulse-ring {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    opacity: 0;
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }

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

.hero-icon {
    width: 48px;
    height: 48px;
    position: relative;
    z-index: 2;
}

.overlay-heading {
    margin: 0 0 12px 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-pure);
    letter-spacing: -0.01em;
}

.overlay-subtext {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 0.9375rem;
}

.demo-fallback {
    margin-top: 32px;
    padding-top: 32px;
    border-top: 1px solid var(--border-subtle);
}

/* --- Grid Toolbar --- */
.grid-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--surface-glass);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 10;
}

.grid-toolbar-left {
    display: flex;
    gap: 8px;
}

.grid-toolbar .btn-sm {
    padding: 6px 12px;
    font-size: 0.8125rem;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
}

.grid-toolbar .btn-sm:hover {
    background: rgba(255, 255, 255, 0.08);
}

.grid-toolbar-right .hint-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- Spreadsheet Wrapper --- */
.spreadsheet-wrapper {
    flex: 1;
    overflow: auto;
    position: relative;
}

/* ==========================================================================
   AGRESSIVE JSPREADSHEET CE OVERRIDES
   Transforming a 2010s grid into a 2026 SaaS powerhouse
   ========================================================================== */

/* Main Container */
.jexcel_container {
    width: 100% !important;
    height: 100% !important;
    background: var(--js-cell-bg) !important;
}

.jexcel {
    background: var(--js-cell-bg) !important;
    font-family: 'Inter', sans-serif !important;
    color: var(--text-primary) !important;
}

/* The Grid Cells */
.jexcel>tbody>tr>td {
    background-color: var(--js-cell-bg) !important;
    border-bottom: 1px solid var(--js-border) !important;
    border-right: 1px solid var(--js-border) !important;
    color: var(--text-primary) !important;
    font-size: 14px !important;
    padding: 10px 14px !important;
    transition: background 0.1s;
}

/* Cell Input/Edit Mode */
.jexcel>tbody>tr>td>input,
.jexcel>tbody>tr>td>textarea {
    background-color: var(--surface-glass) !important;
    color: var(--text-pure) !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 14px !important;
    padding: 10px 14px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5) !important;
    border-radius: 4px;
}

/* Headers (A, B, C... and 1, 2, 3...) */
.jexcel>thead>tr>td,
.jexcel>tbody>tr>td.jexcel_row {
    background-color: var(--js-header-bg) !important;
    border-bottom: 1px solid var(--border-light) !important;
    border-right: 1px solid var(--border-light) !important;
    color: var(--text-muted) !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px !important;
}

/* Corner Select All Block */
.jexcel>thead>tr>td.jexcel_selectall {
    background-color: var(--js-header-bg) !important;
    border-bottom: 1px solid var(--border-light) !important;
    border-right: 1px solid var(--border-light) !important;
}

/* Smart Highlighting */
/* The selection fill */
.jexcel>tbody>tr>td.highlight {
    background-color: var(--js-selection) !important;
}

/* The crisp selection borders */
.jexcel>tbody>tr>td.highlight-left {
    border-left-color: var(--primary) !important;
}

.jexcel>tbody>tr>td.highlight-right {
    border-right-color: var(--primary) !important;
}

.jexcel>tbody>tr>td.highlight-top {
    border-top-color: var(--primary) !important;
}

.jexcel>tbody>tr>td.highlight-bottom {
    border-bottom-color: var(--primary) !important;
}

/* The little drag-to-copy square */
.jexcel_corner {
    background-color: var(--primary) !important;
    border: 2px solid var(--js-cell-bg) !important;
    border-radius: 50% !important;
    /* Make it a circle */
    width: 6px !important;
    height: 6px !important;
    bottom: -4px !important;
    right: -4px !important;
    box-shadow: 0 0 0 2px var(--primary-glow) !important;
}

/* Context Menu Restyling */
.jcontextmenu {
    border: 1px solid var(--border-light) !important;
    background: rgba(15, 23, 42, 0.95) !important;
    backdrop-filter: var(--blur-lg) !important;
    -webkit-backdrop-filter: var(--blur-lg) !important;
    border-radius: 12px !important;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.05) inset !important;
    padding: 8px !important;
    font-family: 'Inter', sans-serif !important;
}

.jcontextmenu>div {
    border-bottom: 1px solid var(--border-subtle) !important;
}

.jcontextmenu>div:last-child {
    border-bottom: none !important;
}

.jcontextmenu>div>a {
    color: var(--text-primary) !important;
    font-size: 13px !important;
    padding: 8px 12px !important;
    border-radius: 6px !important;
    transition: all 0.15s !important;
}

.jcontextmenu>div>a:hover {
    background-color: var(--primary) !important;
    color: white !important;
}

.jcontextmenu>hr {
    border-color: var(--border-subtle) !important;
    margin: 4px 0 !important;
}

/* Native Search Restyling */
.jexcel_search {
    background: rgba(15, 23, 42, 0.6) !important;
    border: 1px solid var(--border-light) !important;
    color: var(--text-pure) !important;
    border-radius: 8px !important;
    padding: 8px 12px 8px 32px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 13px !important;
    margin-bottom: 12px !important;
    width: 240px !important;
    transition: all 0.2s !important;
    background-image: url('data:image/svg+xml;utf8,<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="%2394a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>') !important;
    background-repeat: no-repeat !important;
    background-position: 10px center !important;
}

.jexcel_search:focus {
    outline: none !important;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px var(--primary-glow) !important;
}

/* Hide Jspreadsheet Toolbar if present by default */
.jexcel_toolbar {
    display: none !important;
}