/* Reset and basic setup */
html {
    height: 100%;
}
body {
    height: 100vh; /* Use viewport height for a reliable container height */
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    
    /* CSS Grid for main layout */
    display: flex;
    flex-direction: column;
    grid-template-rows: auto auto 1fr; 
}

/* Color Palette for Range Chiclets */
:root {
    --range-color-1: #cce5ff; /* Light Blue */
    --range-text-1: #004085;
    --range-color-2: #d4edda; /* Light Green */
    --range-text-2: #155724;
    --range-color-3: #fff3cd; /* Light Yellow */
    --range-text-3: #856404;
    --range-color-4: #e2d9f3; /* Light Purple */
    --range-text-4: #3c2a59;
    --range-color-5: #fde2e2; /* Light Red */
    --range-text-5: #721c24;
    --range-color-6: #d1ecf1; /* Light Cyan */
    --range-text-6: #0c5460;
}


/* Modern Menu Bar */
.menu-bar {
    background-color: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}
.menu-button {
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    border-radius: 4px;
    transition: background-color 0.2s;
}
.menu-button:hover, .menu-button.active {
    background-color: #e5e7eb;
}
.menu-dropdown {
    background-color: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    padding: 4px;
    min-width: 180px;
}
.menu-item {
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 4px;
    color: #374151;
    transition: background-color 0.2s;
    cursor: pointer;
}
.menu-item:hover {
    background-color: #f3f4f6;
}
.menu-separator {
    height: 1px;
    background-color: #e5e7eb;
    margin: 4px 0;
}

/* Modern Formula bar styles */
.formula-bar {
    background-color: #f9fafb;
    padding: 4px 8px;
    border-bottom: 1px solid #e5e7eb;
}
.name-box {
    background-color: white;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}
/* This class now applies to our contenteditable div */
.formula-input {
    background-color: white;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    white-space: nowrap; /* Prevent wrapping inside the formula bar */
    overflow-x: auto; /* Allow horizontal scrolling if content is too long */
    overflow-y: hidden;
    line-height: 1.5; /* Ensure consistent height */
    caret-color: #374151; /* Make the cursor visible */
    align-items: center;
    display: flex;
}
.formula-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4);
}

/* NEW: Style for the range chiclets */
.formula-range {
    border-radius: 4px;
    padding: 1px 4px;
    font-weight: 500;
    /* We'll set the specific colors via inline CSS variables from JS */
    background-color: var(--range-color);
    color: var(--range-text);
}


/* Canvas container and canvas itself */
main {
    background-color: white;
    overflow: hidden; /* Prevent canvas from overflowing its grid area */
    display: grid;
    grid-template-rows: 1fr auto;
    grid-template-columns: 1fr auto;
    flex-grow: 1; 
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: cell;
    touch-action: none;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(17, 24, 39, 0.5); /* gray-900 with 50% opacity */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal-box {
    background-color: white;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 90%;
    max-width: 400px;
}

.disabled-menu {
    color: rgb(140, 140, 140);
}

#main-canvas {
    outline: none;
    touch-action: none;
}

#custom-tooltip {
    position: absolute;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 10px;
    z-index: 100;
    /* pointer-events: none prevents the tooltip from interfering with other mouse events */
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

#custom-tooltip.visible {
    opacity: 0.8;
}

#canvas-container {
    grid-row: 1;
    grid-column: 1;
    overflow: hidden; /* This container clips the canvas */
}

#v-scrollbar-container {
    grid-row: 1;
    grid-column: 2;
    overflow-y: scroll;
    overflow-x: hidden;
}

#h-scrollbar-container {
    grid-row: 2;
    grid-column: 1;
    overflow-x: scroll;
    overflow-y: hidden;
}

#scrollbar-corner {
    grid-row: 2;
    grid-column: 2;
    background-color: #f1f1f1; /* Match track color */
}

#v-scrollbar-sizer { width: 1px; }
#h-scrollbar-sizer { height: 1px; }

/* Style for always-visible scrollbars on desktop (WebKit browsers) */
#v-scrollbar-container::-webkit-scrollbar,
#h-scrollbar-container::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

#v-scrollbar-container::-webkit-scrollbar-track,
#h-scrollbar-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#v-scrollbar-container::-webkit-scrollbar-thumb,
#h-scrollbar-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 6px;
}

#v-scrollbar-container::-webkit-scrollbar-thumb:hover,
#h-scrollbar-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

#gridcontainer {
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* This makes the container grow to fill all available space */
    min-height: 0; /* Prevents flexbox overflow issues */
}
