/* Ensure root wrapper fits viewport exactly */
body {
    display: flex;
    background: radial-gradient(circle at 50% 50%, #1e293b 0%, #0f172a 100%);
}

html, body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden; /* Prevents whole-page scrollbars */
    box-sizing: border-box;
}

/* Toolbar Row Layout */
.sheets-toolbar {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 15px auto;
    display: flex !important;
    flex-direction: row !important; /* Forces side-by-side layout */
    align-items: center;
    gap: 12px;
}
.formula-bar-wrapper {
    flex: 1;
    height: 42px; /* Matches tool button height */
    background: linear-gradient(180deg, rgba(255,255,255,0.8) 0%, rgba(240,249,255,0.6) 100%);
    border: 2px solid rgba(255,255,255,0.9);
    border-radius: 10px;
    display: flex;
    align-items: center;
    padding: 0 14px;
    box-shadow: 0 4px 15px rgba(107, 199, 2, 0.15), inset 0 1px 2px #fff;
    backdrop-filter: blur(10px);
}
.formula-badge {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 800;
    color: #5fa700;
    margin-right: 12px;
    padding-right: 12px;
    border-right: 2px solid rgba(43, 77, 0, 0.2);
}
#formula-input {
    border: none;
    background: transparent;
    outline: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    width: 100%;
    color: #334155;
}
#spreadsheet-container {
    flex: 1;
    width: 100%;
    height: calc(100% - 70px);
    max-width: 900px;
    margin: 0 auto;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(240, 249, 255, 0.9) 100%);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    box-shadow: 0 15px 45px rgba(0,0,0,0.25), inset 0 1px 2px #fff;
    overflow: auto; /* Scrollbars appear inside grid when needed */
    backdrop-filter: blur(12px);
}
#aero-grid-table {
    border-collapse: collapse;
    width: 100%;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
}
#aero-grid-table th, #aero-grid-table td {
    border: 1px solid rgba(203, 213, 225, 0.7);
    padding: 10px 14px;
    text-align: left;
    min-width: 110px;
}
#aero-grid-table th {
    background: linear-gradient(180deg, #9bf838 0%, #6bc702 100%);
    color: #ffffff;
    font-weight: 800;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 10;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.4);
}
.corner-header {
    background: linear-gradient(180deg, #64c702 0%, #62a103 100%) !important;
}
.row-header {
    background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
    color: #67a103;
    font-weight: 800;
    text-align: center;
    width: 60px;
    position: sticky;
    left: 0;
    z-index: 5;
}
.sheet-cell {
    outline: none;
    background: rgba(255, 255, 255, 0.6);
    color: #1e293b;
    cursor: cell;
    transition: background 0.15s ease;
}
.sheet-cell:hover {
    background: rgba(149, 248, 56, 0.08);
}
.sheet-cell:focus {
    background: rgba(120, 248, 56, 0.2);
    box-shadow: inset 0 0 0 2px #68c702;
}

/* --- 3D Glass Side Navigation Panel --- */
.aero-sidebar {
    width: 260px;
    min-width: 260px;
    height: 100vh;
    flex-shrink: 0;
    box-sizing: border-box;
    background: linear-gradient(90deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0.05) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 2px solid rgba(255,255,255,0.2);
    display: flex;
    flex-direction: column;
    padding: 25px 15px;
    position: relative;
    transition: transform 0.3s cubic-bezier(0.1, 0.9, 0.2, 1);
    z-index: 50;
    box-shadow: 5px 0 25px rgba(0,0,0,0.15);
}
.sidebar-brand h2 {
    color: #fff;
    font-size: 1.5rem;
    font-weight: 900;
    text-shadow: 0 0 10px rgba(120, 248, 56, 0.6);
    margin-bottom: 30px;
    padding-left: 10px;
    font-family: 'Jetbrains Mono', 'Courier New', Courier, monospace;
}

.pad-selection-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ========================================================
   SIDEBAR BUTTON MECHANICS & GLOW STYLES
   ======================================================== */
.pad-toggle-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    padding: 12px 16px;
    font-weight: bold;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    font-family: 'Jetbrains Mono', 'Courier New', Courier, monospace;
}

.pad-toggle-btn:hover {
    background: linear-gradient(180deg, #98f838 0%, #54c702 100%);
    border-color: #b2fc7d;
    box-shadow: 0 4px 12px rgba(104, 199, 2, 0.35), inset 0 1px 2px #fff;
    transform: translateY(-1px);
    color: #ffffff;
}

.pad-toggle-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 6px rgba(104, 199, 2, 0.2);
}

.sidebar-footer-controls {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-action-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.15);
    color: #cbd5e1;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    font-family: 'Jetbrains Mono', 'Courier New', Courier, monospace;
}
.sidebar-action-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-color: rgba(255,255,255,0.4);
}

/* Collapse Bouncer Toggle Latch Handle */
.latch-toggle-strip {
    position: absolute;
    top: 50%;
    right: -26px;
    width: 24px;
    height: 60px;
    background: linear-gradient(90deg, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0.05) 100%);
    border: 2px solid rgba(255,255,255,0.2);
    border-left: none;
    border-radius: 0 8px 8px 0;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    box-shadow: 4px 0 10px rgba(0,0,0,0.1);
}

/* Main workspace fills remaining space without overflowing */
.workspace-viewport-wrapper {
    flex: 1;
    height: 100vh;
    padding: 20px 30px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Keeps toolbar fixed at top */
}

/* --- Color Picker Toolbar Tool Button --- */
.color-picker-container {
    position: relative;
    display: flex;
    align-items: center;
}
/* Fix 3: Center the palette icon inside the button */
.style-tool-btn {
    background: linear-gradient(180deg, rgba(255,255,255,0.9) 0%, rgba(224,242,254,0.7) 100%);
    border: 2px solid rgba(255,255,255,0.9);
    border-radius: 10px;
    width: 42px;
    height: 42px;
    padding: 0; /* Clears default button padding */
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2e6f00;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(81, 199, 2, 0.15), inset 0 1px 2px #fff;
    transition: all 0.2s ease;
}
.style-tool-btn svg {
    display: block;
    margin: auto;
}

.style-tool-btn:hover {
    background: linear-gradient(180deg, #a2f838 0%, #78c702 100%);
    color: #ffffff;
}

/* --- Floating Aero Glass Popup Palette --- */
.aero-palette-menu {
    position: absolute;
    top: 48px;
    left: 0;
    width: 220px;
    background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(240,249,255,0.9) 100%);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.25), inset 0 1px 1px #fff;
    backdrop-filter: blur(12px);
    padding: 12px;
    display: none;
    flex-direction: column;
    gap: 10px;
    z-index: 100;
}
.aero-palette-menu.show {
    display: flex;
}
.palette-header {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 800;
    color: #5ec702;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 4px;
    text-transform: uppercase;
}
.palette-section label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    display: block;
    margin-bottom: 4px;
}
.preset-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.2);
    cursor: pointer;
    box-shadow: inset 0 1px 2px rgba(255,255,255,0.8), 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.1s ease;
}
.color-swatch:hover {
    transform: scale(1.15);
}
.custom-color-input {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    background: transparent;
    padding: 0;
}
.custom-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color-input::-webkit-color-swatch { border: 1px solid #cbd5e1; border-radius: 50%; }

.palette-footer {
    border-top: 1px solid #cbd5e1;
    padding-top: 6px;
    display: flex;
    justify-content: flex-end;
}
.reset-style-btn {
    background: linear-gradient(180deg, #f1f5f9 0%, #cbd5e1 100%);
    border: 1px solid #94a3b8;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 800;
    color: #334155;
    padding: 3px 8px;
    cursor: pointer;
}
/* --- Custom Picker Icon Button Overrides --- */
.custom-picker-wrapper {
    position: relative;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
    border: 1px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #72c702;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.1s ease;
}
.custom-picker-wrapper:hover {
    transform: scale(1.15);
}
.custom-picker-wrapper input[type="color"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}
.dialog-header {
    font-family: 'JetBrains Mono', monospace;
}

/* --- 3D Glass Chart Pod Component --- */
.aero-chart-card {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 15px auto;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(237, 254, 224, 0.7) 100%);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 14px;
    padding: 12px 18px;
    box-shadow: 0 10px 25px rgba(100, 199, 2, 0.2), inset 0 1px 2px #fff;
    backdrop-filter: blur(10px);
}
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 800;
    color: #57c702;
    border-bottom: 1px solid rgba(94, 199, 2, 0.2);
    padding-bottom: 6px;
    margin-bottom: 12px;
}
.chart-close-orb {
    background: linear-gradient(180deg, #fca5a5 0%, #ef4444 100%);
    border: 1px solid #f87171;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    color: #fff;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chart-bars-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    height: 120px;
    padding: 10px 0;
}
.chart-bar-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}
.chart-bar-fill {
    width: 100%;
    max-width: 40px;
    background: linear-gradient(180deg, #95f838 0%, #5bc702 100%);
    border: 1px solid #c9fc7d;
    border-radius: 6px 6px 0 0;
    box-shadow: 0 4px 10px rgba(107, 199, 2, 0.3), inset 0 1px 1px #fff;
    transition: height 0.4s cubic-bezier(0.1, 0.9, 0.2, 1);
}
.chart-bar-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: bold;
    color: #576947;
    margin-top: 6px;
}
/* --- Dynamic Chart Controls & Bar Badging --- */
.chart-nav-cluster {
    display: flex;
    align-items: center;
    gap: 10px;
}
.chart-nav-btn {
    background: linear-gradient(180deg, #ffffff 0%, #e2e8f0 100%);
    border: 1px solid #a7b894;
    border-radius: 6px;
    width: 24px;
    height: 22px;
    color: #6ec702;
    font-size: 14px;
    font-weight: 900;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1), inset 0 1px 0 #fff;
    transition: transform 0.05s ease;
}
.chart-nav-btn:active {
    transform: scale(0.92);
}

.chart-bar-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}

/* Numeric Value Badge Above Bar */
.chart-value-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 800;
    color: #6bc702;
    margin-bottom: 4px;
}

/* Cell ID Label Below Bar */
.chart-bar-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: bold;
    color: #64748b;
    margin-top: 4px;
}
/* Sidebar Collapsed State */
#sidebar.collapsed {
    transform: translateX(-260px); /* Slides sidebar off-screen */
}

/* Adjust toggle latch position so it stays visible when collapsed */
#sidebar.collapsed .latch-toggle-strip {
    right: -26px;
}

/* Rotate toggle arrow icon when collapsed */
#sidebar.collapsed #toggle-icon {
    transform: rotate(180deg);
}
/* Keeps tool buttons grouped horizontally */
.toolbar-tools-dock {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* --- Writeout Format Ribbon Integration --- */
.aero-format-ribbon {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(200, 230, 255, 0.7) 100%);
    border: 2px solid rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 8px 14px;
    box-shadow: 0 8px 25px rgba(14, 165, 233, 0.2), inset 0 1px 2px #fff;
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: 10px;
}

.aero-format-ribbon .format-control,
.aero-format-ribbon .color-picker-label {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(224, 242, 254, 0.85) 100%) !important;
    border: 1px solid #7dd3fc !important;
    border-radius: 8px !important;
    color: #0369a1 !important;
    padding: 6px 10px !important;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 13px !important;
    box-shadow: 0 2px 5px rgba(14, 165, 233, 0.15), inset 0 1px 1px #fff !important;
    cursor: pointer;
}

.aero-format-ribbon .format-control:hover,
.aero-format-ribbon .color-picker-label:hover {
    background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%) !important;
    color: #ffffff !important;
    border-color: #0284c7 !important;
}

.aero-format-ribbon .ribbon-separator {
    width: 1px;
    height: 22px;
    background: rgba(0, 0, 0, 0.15);
    margin: 0 2px;
}

.aero-format-ribbon input[type="color"] {
    border: none;
    width: 20px;
    height: 20px;
    cursor: pointer;
    background: none;
}

/* Container Reference for Positioning */
.workspace-viewport-wrapper, #spreadsheet-container {
    position: relative !important;
}

/* Floating Glass Bar Styling */
#aero-selection-toolbar.aero-floating-bar {
    position: absolute !important;
    display: none;
    align-items: center;
    gap: 4px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(240, 249, 255, 0.8) 100%);
    border: 2px solid rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 4px 8px;
    box-shadow: 0 10px 25px rgba(2, 132, 199, 0.25), inset 0 1px 0 #fff;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
}

.style-bar-btn {
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: bold;
    color: #334155;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05), inset 0 1px 0 #fff;
}

.style-bar-btn:hover {
    background: #e2e8f0;
    color: #0284c7;
}

.style-bar-divider {
    width: 1px;
    height: 18px;
    background: #cbd5e1;
    margin: 0 4px;
}

/* Grid Menu Trays */
.aero-dropdown {
    position: relative;
    display: inline-block;
}

.highlight-grid-menu {
    display: none;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 6px;
    padding: 8px !important;
    background: linear-gradient(180deg, #e2e8f0 0%, #cbd5e1 100%) !important;
    border: 2px solid #94a3b8 !important;
    border-radius: 10px !important;
    box-shadow: 0 8px 20px rgba(0,0,0,0.2), inset 0 1px 0 #fff !important;
    min-width: 150px !important;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1005;
}

.aero-dropdown.active .highlight-grid-menu {
    display: grid !important;
}

.chip-grid-menu {
    grid-template-columns: repeat(4, 1fr) !important;
    min-width: 180px !important;
}

.color-swatch-item, .chip-swatch-item {
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease;
}

.color-swatch-item:hover, .chip-swatch-item:hover {
    transform: scale(1.12);
}

/* Ensure the wrapper serves as the relative positioning boundary */
.workspace-viewport-wrapper {
    position: relative !important;
    overflow: visible !important;
}

/* Force high z-index and absolute positioning for the selection bar */
#aero-selection-toolbar.aero-floating-bar {
    position: absolute !important;
    z-index: 9999 !important;
    pointer-events: auto !important;
}

/* Glass selection highlight for multi-tile selection */
.sheet-cell.selected-tile {
    background: rgba(120, 248, 56, 0.2) !important;
    outline-offset: -2px;
    box-shadow: inset 0 0 0 2px #68c702 !important;
}