/* 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;
    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;
    align-items: center;
    gap: 12px;
}
.formula-bar-wrapper {
    flex: 1;
    height: 42px;
    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: var(--aero-primary, #9D84FF);
    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;
    backdrop-filter: blur(12px);
}

/* --- 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(157, 132, 255, 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;
}

.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, var(--aero-primary, #9D84FF) 0%, #7b5ce6 100%);
    border-color: #bfaeff;
    box-shadow: 0 4px 12px rgba(157, 132, 255, 0.35), inset 0 1px 2px #fff;
    transform: translateY(-1px);
    color: #ffffff;
}

.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);
}

.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);
}

.workspace-viewport-wrapper {
    flex: 1;
    height: 100vh;
    padding: 20px 30px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sidebar.collapsed {
    transform: translateX(-260px);
}
#sidebar.collapsed .latch-toggle-strip {
    right: -26px;
}
#sidebar.collapsed #toggle-icon {
    transform: rotate(180deg);
}
.toolbar-tools-dock {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
/* Chip Select: the choices are glossy Bubble Chips you tap! */
.fm-chip-row { display: flex; flex-wrap: wrap; gap: 9px; padding: 2px 0; }
.fm-chip.gel-bubble-chip {
    gap: 7px;
    padding: 5px 13px 5px 8px;
    border-radius: 999px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    cursor: pointer;
    opacity: 0.55;
    filter: saturate(0.5);
    transition: opacity 0.2s ease, filter 0.2s ease, transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1), box-shadow 0.2s ease;
}
.fm-chip:hover:not(:disabled) { opacity: 0.9; filter: none; transform: translateY(-2px); }
.fm-chip.is-on { opacity: 1; filter: none; box-shadow: 0 5px 12px rgba(0, 0, 0, 0.14), inset 0 1px 1px rgba(255, 255, 255, 0.6), 0 0 0 3px rgba(255, 255, 255, 0.95); }
.fm-chip:disabled { cursor: default; }
.fm-chip:focus-visible { outline: 3px solid #7c4ff0; outline-offset: 3px; }
/* the little dot fills in with a check when the chip is picked */
.fm-chip-dot {
    position: relative;
    flex: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid currentColor;
    background: rgba(255, 255, 255, 0.7);
    box-sizing: border-box;
}
.fm-chip.is-on .fm-chip-dot { background: currentColor; }
.fm-chip.is-on .fm-chip-dot::after {
    content: "";
    position: absolute;
    left: 3px; top: 0.5px;
    width: 3px; height: 6px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.fm-chip.fm-pop { animation: fmChipPop 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes fmChipPop { 0% { transform: scale(0.88); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .fm-chip, .fm-chip.fm-pop { transition: none; animation: none; } }

/* the Keydown Guide dialog */
.fm-kd-guide { max-height: 60vh; overflow-y: auto; padding-right: 6px; }
.fm-kd-guide .kd-guide-note { font-size: 13px; color: #5b4b8a; margin-bottom: 6px; }
.fm-kd-guide .kd-guide-title { font-weight: 800; margin: 14px 0 6px; color: #7c4ff0; }
.fm-kd-guide .kd-guide-row { display: flex; gap: 12px; align-items: center; padding: 4px 0; border-bottom: 1px solid #ece7fb; font-size: 13px; }
.fm-kd-guide .kd-guide-row code { flex: 0 0 42%; font: 12px 'JetBrains Mono', monospace; color: #475569; word-break: break-all; }

/* Option Row: a centered row of buttons; the picked one lights up violet */
.fm-optrow { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 4px 0; }
.fm-opt {
    position: relative;
    overflow: hidden;
    min-width: 64px;
    padding: 9px 18px;
    border-radius: 10px;
    border: 2px solid #c4b5fd;
    background: linear-gradient(180deg, #ffffff 0%, #f3efff 100%);
    color: #5b3fd0;
    font: 700 0.88rem 'JetBrains Mono', monospace;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(124, 79, 240, 0.12), inset 0 1px 1px #fff;
    transition: transform 0.2s cubic-bezier(0.3, 1.6, 0.5, 1), border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.fm-opt:hover:not(:disabled) { border-color: #8b5cf6; transform: translateY(-2px); box-shadow: 0 5px 12px rgba(124, 79, 240, 0.2), inset 0 1px 1px #fff; }
.fm-opt.is-on {
    border-color: #6d3fe0;
    background: linear-gradient(180deg, #a78bfa 0%, #7c4ff0 100%);
    color: #fff;
    text-shadow: 0 1px 1px rgba(46, 16, 101, 0.4);
    box-shadow: 0 5px 14px rgba(124, 79, 240, 0.38), inset 0 1px 1px rgba(255, 255, 255, 0.5);
}
/* a glossy shine across the top half of the picked button */
.fm-opt.is-on::before {
    content: "";
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.08) 100%);
    pointer-events: none;
}
.fm-opt:disabled { cursor: default; }
.fm-opt:focus-visible { outline: 3px solid #7c4ff0; outline-offset: 3px; }
.fm-opt.fm-pop { animation: fmChipPop 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }
@media (prefers-reduced-motion: reduce) { .fm-opt, .fm-opt.fm-pop { transition: none; animation: none; } }

/* the builder's "Buttons: − 4 +" stepper */
.fm-count { display: flex; align-items: center; gap: 8px; font: 700 0.8rem 'JetBrains Mono', monospace; color: #475569; }
.fm-count button {
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 1px solid #c4b5fd;
    background: linear-gradient(180deg, #fff 0%, #ede9fe 100%);
    color: #6d3fe0;
    font: 800 1rem/1 'JetBrains Mono', monospace;
    cursor: pointer;
}
.fm-count button:disabled { opacity: 0.4; cursor: default; }
.fm-count button:focus-visible { outline: 3px solid #7c4ff0; outline-offset: 2px; }
.fm-count output { min-width: 1.5em; text-align: center; color: #1e293b; }

/* a view-only (.kfv) form: no live sharing, since that could edit it */
body.fm-locked .rc-share { display: none !important; }
