:root {
    --primary-color: #1a73e8;
    --google-blue: #1a73e8;
    --border-color: #dfe1e5;
    --header-bg: #f8f9fa;
    --active-header-bg: #e8eaed;
    --text-color: #3c4043;
    --grid-bg: #ffffff;
    --selection-bg: rgba(26, 115, 232, 0.1);
}

th:hover .header-tools, .row-header:hover .header-tools-row {
    display: none;
}

.btn-grid-tool {
    background: #f1f3f4;
    border: 1px solid #dfe1e5;
    border-radius: 2px;
    padding: 0 4px;
    font-size: 9px;
    line-height: 14px;
    height: 16px;
    min-width: 16px;
    color: #5f6368;
    cursor: pointer;
    font-weight: bold;
}

.btn-grid-tool:hover {
    background-color: var(--active-header-bg);
    color: var(--google-blue);
    border-color: var(--google-blue);
}

.btn-ins-col, .btn-ins-row {
    background-color: #e6f4ea;
    color: #137333;
}

.btn-res-l { font-weight: 900; }
.btn-res-s { font-weight: 400; }

.col-label {
    flex: 1;
    text-align: center;
}

/* ... existing body styles ... */

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
}

.dropdown:hover .dropdown-content {
    display: block;
}

/* Formula & Feature Section */
.formula-section {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

#formula-bar {
    padding: 2px 0;
}

#feature-bar-container {
    padding: 2px 0;
    border-top: 1px solid #f1f3f4;
}

/* Feature Bar Styles */


/* Column Control Popup */
.column-control-popup {
    position: absolute;
    background: white;
    border: 1px solid #dadce0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: 8px;
    padding: 4px;
    display: flex;
    gap: 4px;
    z-index: 2500;
    animation: fadeIn 0.2s ease-out;
}

.size-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #dadce0;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    color: #5f6368;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.size-btn:hover {
    background: #f1f3f4;
    border-color: #1a73e8;
    color: #1a73e8;
}

.size-btn.large {
    background: #f8f9fa;
    font-size: 16px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Existing Palette Refinement */
.char-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 8px;
}
.char-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: white;
}

.char-btn:hover {
    background: var(--active-header-bg);
    border-color: var(--google-blue);
}

.eq-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px;
    margin-bottom: 4px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 4px;
}

.eq-btn:hover {
    background: var(--active-header-bg);
    border-color: var(--google-blue);
}

.menu-btn {
    font-weight: 500;
}

.menu-btn:after {
    content: ' ▾';
    font-size: 10px;
    color: #5f6368;
}

.dropdown-content button:hover {
    background-color: var(--active-header-bg);
}

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

body {
    font-family: 'Roboto', 'Arial', sans-serif;
    color: var(--text-color);
    background-color: #f1f3f4;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Toolbar */
header#toolbar-container {
    background: #fff;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
}

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

button {
    background: transparent;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-color);
    transition: background 0.2s;
}

button:hover {
    background: var(--header-bg);
}

button.active {
    background: var(--active-header-bg);
    color: var(--primary-color);
}

/* Formula Bar */
#formula-bar {
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 4px 16px;
    height: 40px;
}

.formula-bar-label {
    width: 60px;
    font-weight: 500;
    text-align: center;
    border-right: 1px solid var(--border-color);
    padding-right: 8px;
}

.formula-bar-fx {
    padding: 0 12px;
    color: #5f6368;
    font-style: italic;
    font-family: 'serif';
    font-size: 18px;
}

#formula-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    height: 100%;
}

/* Grid */
main#grid-container {
    flex: 1;
    overflow: auto;
    position: relative;
    background: #fff;
    min-height: 0; /* Important for flex child to be scrollable */
}

.spreadsheet-grid {
    border-collapse: collapse;
    table-layout: fixed;
    background: #fff;
}

.spreadsheet-grid th, .spreadsheet-grid td {
    border: 1px solid var(--border-color);
    width: 100px;
    height: 25px;
    position: relative;
}

.spreadsheet-grid th {
    background: var(--header-bg);
    font-weight: normal;
    font-size: 12px;
    color: #5f6368;
    text-align: center;
    user-select: none;
}

.spreadsheet-grid th.active-header {
    background: var(--active-header-bg);
    color: var(--primary-color);
    font-weight: bold;
}

.row-header {
    width: 40px !important;
    background: var(--header-bg);
    text-align: center;
}

.spreadsheet-grid td input {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    padding: 0 4px;
    font-size: 13px;
    background: transparent;
}

.active-cell {
    outline: 2px solid var(--primary-color);
    z-index: 10;
}

.locked-cell {
    background-color: #f1f3f4 !important;
}

.locked-cell::after {
    content: '🔒';
    position: absolute;
    right: 2px;
    top: 2px;
    font-size: 8px;
    opacity: 0.5;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 300px;
}

.modal-header {
    font-size: 18px;
    margin-bottom: 16px;
    font-weight: 500;
}

.modal-body {
    margin-bottom: 24px;
}

.modal-body input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    outline: none;
}

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

.btn-primary {
    background: var(--primary-color);
    color: #fff;
}

.btn-primary:hover {
    background: #1557b0;
}

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

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #fff;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 100;
    border-radius: 4px;
    padding: 4px 0;
}

.dropdown-content button {
    width: 100%;
    text-align: left;
    padding: 8px 16px;
    border-radius: 0;
}



/* Resize Handles */
.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    width: 4px;
    height: 100%;
    cursor: col-resize;
    z-index: 5;
}

.col-resize-handle:hover {
    background-color: var(--google-blue);
}

.row-resize-handle {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 4px;
    cursor: row-resize;
    z-index: 5;
}

.row-resize-handle:hover {
    background-color: var(--google-blue);
}

/* Tooltip */
.cell-tooltip {
    display: none;
    position: fixed;
    background-color: #333;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    max-width: 300px;
    word-wrap: break-word;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Grid Layout Upgrades */
.cell {
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cell.formatting-underline { text-decoration: underline; }
.cell.formatting-strikethrough { text-decoration: line-through; }

/* Sheet Tabs */
#sheet-tabs-container {
    background: #f8f9fa;
    border-top: 1px solid var(--border-color);
    padding: 0 16px;
    height: 32px;
    display: flex;
    align-items: center;
}

.sheet-tabs {
    display: flex;
    align-items: center;
    gap: 0;
    height: 100%;
}

.sheet-tab {
    padding: 0 16px;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #5f6368;
    background: transparent;
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    position: relative;
    border-bottom: 2px solid transparent;
}

.sheet-tab:hover {
    background: #e8eaed;
}

.sheet-tab.active {
    background: white;
    color: var(--primary-color);
    font-weight: 500;
    border-bottom-color: var(--primary-color);
}

.sheet-delete {
    font-size: 16px;
    font-weight: bold;
    padding: 2px;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
}

.sheet-tab:hover .sheet-delete {
    visibility: visible;
}

.sheet-delete:hover {
    background: rgba(0,0,0,0.1);
    color: #d93025;
}

.btn-add-sheet {
    background: none;
    border: none;
    padding: 0 12px;
    font-size: 20px;
    color: #5f6368;
    cursor: pointer;
    line-height: 24px;
}

.btn-add-sheet:hover {
    color: var(--primary-color);
}

/* Chart Modal */
.chart-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 1100;
    width: 600px;
    max-width: 90vw;
}

.chart-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.chart-modal-header span {
    font-weight: 500;
    color: var(--text-color);
}

.chart-container {
    position: relative;
    height: 350px;
}

/* Formula & Feature Section */
.formula-section {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

#formula-bar {
    padding: 2px 0;
}

#feature-bar-container {
    padding: 2px 0;
    border-top: 1px solid #f1f3f4;
}

/* Feature Bar Styles */
.feature-bar {
    display: flex;
    gap: 16px;
    padding: 4px 16px;
    overflow: visible; /* FIXED: Removed overflow-x: auto to prevent clipping */
    font-size: 12px;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
}

.feature-category {
    position: relative;
    cursor: pointer;
}

.feature-cat-btn {
    border: none;
    background: none;
    color: #3c4043;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 4px;
    transition: all 0.2s;
    cursor: pointer;
    font-size: 13px;
}

.feature-cat-btn:hover {
    background: #e8eaed;
    color: #1a73e8;
}

/* Feature List (Dropdown) */
.feature-list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #dfe1e5;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 9999;
    min-width: 180px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px 0;
    border-radius: 4px;
}

.feature-category:hover .feature-list {
    display: block;
}

.feature-item {
    padding: 8px 14px;
    color: #3c4043;
    font-size: 12px;
    transition: background 0.2s;
    cursor: pointer;
}

.feature-item:hover {
    background: #f1f3f4;
    color: #1a73e8;
}

/* Column Control Popup */
.column-control-popup {
    position: absolute;
    background: white;
    border: 1px solid #dadce0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: 8px;
    padding: 4px;
    display: flex;
    gap: 4px;
    z-index: 1001;
    animation: fadeIn 0.15s ease-out;
}

.size-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #dadce0;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    color: #5f6368;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.size-btn:hover {
    background: #f1f3f4;
    border-color: #1a73e8;
    color: #1a73e8;
}

.size-btn.large {
    background: #f8f9fa;
    font-size: 16px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.char-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 8px;
}
.char-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 16px;
}

/* Superior Layering for Popups */
.column-control-popup { z-index: 9999 !important; }
.feature-list { z-index: 9999 !important; }
.cell-tooltip { z-index: 9997 !important; }

/* Modals & Overlays */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    min-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    animation: modalPop 0.2s ease-out;
}

@keyframes modalPop {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1a73e8;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.btn-primary {
    background: #1a73e8 !important;
    color: white !important;
}

.chart-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    z-index: 11000;
    width: 700px;
}
