/* --- Base & App Layout --- */
html, body {
    margin: 0; padding: 0; height: 100%; overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f8f9fa;
}

/* --- Header Styles --- */
#app-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1001;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 15px; height: 60px; background-color: #000000;
    border-bottom: 1px solid #343a40; box-sizing: border-box;
}
#app-header .branding img { height: 40px; vertical-align: middle; }
.header-right { display: flex; align-items: center; gap: 15px; }

/* --- Desktop Dropdown Menu Styles --- */
.dropdown { position: relative; }
.dropdown-toggle { display: flex; align-items: center; gap: 8px; background: none; border: none; cursor: pointer; color: #d5dee7; font-weight: 500; font-size: 15px; padding: 8px 12px; border-radius: 6px; transition: background-color 0.2s, color 0.2s; }
.dropdown-toggle:hover { background-color: #343a40; color: #ffffff; }
.dropdown-toggle .icon { width: 20px; height: 20px; stroke: currentColor; }
.dropdown-menu { display: none; position: absolute; top: calc(100% + 5px); right: 0; background-color: #ffffff; border: 1px solid #dee2e6; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); min-width: 240px; z-index: 1000; padding: 5px 0; list-style: none; margin: 0; }
.dropdown-menu.show { display: block; }
.dropdown-menu a { display: block; padding: 10px 20px; text-decoration: none; color: #212529; font-size: 14px; white-space: nowrap; }
.dropdown-menu a:hover { background-color: #f8f9fa; }

/* --- Hamburger & Mobile Nav Styles --- */
#hamburger-btn { background: none; border: none; cursor: pointer; padding: 5px; }
#hamburger-btn .icon { width: 28px; height: 28px; stroke: #d5dee7; }
#mobile-nav { position: fixed; top: 0; right: -100%; width: 280px; height: 100%; background-color: #111; box-shadow: -5px 0 15px rgba(0,0,0,0.2); z-index: 2000; transition: right 0.3s ease-in-out; display: flex; flex-direction: column; padding-top: 60px; }
#mobile-nav.open { right: 0; }
#close-nav-btn { position: absolute; top: 10px; right: 15px; background: none; border: none; color: #aaa; font-size: 36px; cursor: pointer; }
#mobile-nav a { padding: 15px 25px; text-decoration: none; font-size: 16px; color: #d5dee7; border-bottom: 1px solid #333; }
#mobile-nav a:hover { background-color: #333; }

/* --- Responsive Visibility Classes --- */
.mobile-only { display: none !important; }

@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }
}

/* --- App Container --- */
#app-container { 
    display: flex; 
    position: absolute; top: 60px; bottom: 0; left: 0; right: 0;
}

/* --- DESKTOP LAYOUT --- */
#expressions-panel { 
    width: 530px; min-width: 350px; background-color: #f8f9fa; 
    display: flex; flex-direction: column; flex-shrink: 0; 
}
#graph-panel { flex-grow: 1; height: 100%; min-width: 0; position: relative; }
#expressions-header { padding: 8px; border-bottom: 1px solid #dee2e6; background-color: #e9ecef; flex-shrink: 0; }
#expressions-list { flex-grow: 1; overflow-y: auto; padding: 8px; min-height: 0; }
#resizer { width: 5px; background: #dee2e6; cursor: col-resize; flex-shrink: 0; transition: background-color 0.2s; }
#resizer:hover { background: #007bff; }

/* --- MOBILE LAYOUT OVERRIDE (PURE CSS) --- */
@media (max-width: 768px) {
    #app-container {
        flex-direction: column;
        height: calc(100% - 25vh); 
    }
    
    #graph-panel {
        order: 1;
        height: 50%;
        flex-shrink: 0;
    }
    #expressions-panel {
        order: 2;
        width: 100%;
        height: 50%;
        display: flex;
        flex-direction: column-reverse; 
    }
    #resizer { display: none; }

    #expressions-list {
        flex-grow: 1;
        min-height: 0;
    }
    #expressions-header {
        flex-shrink: 0;
        border-top: 1px solid #dee2e6;
        border-bottom: none;
    }

    #keyboard-fab {display: none !important; }
    #stroke-width-slider-container {display: none !important; }
}

/* --- Common Component Styles --- */
#add-expression-btn { background-color: #28a745; color: white; border: none; border-radius: 5px; font-size: 20px; font-weight: bold; width: 32px; height: 32px; cursor: pointer; transition: background-color 0.2s; }
#add-expression-btn:hover { background-color: #218838; }
#stroke-width-slider-container { position: absolute; top: 15px; right: 15px; z-index: 10; background-color: rgba(248, 249, 250, 0.9); padding: 8px 12px; border-radius: 6px; box-shadow: 0 2px 5px rgba(0,0,0,0.15); display: flex; align-items: center; gap: 8px; }
#stroke-width-slider-container label { font-size: 14px; color: #495057; }
#stroke-width-slider { cursor: pointer; }
.expression-box { display: flex; align-items: stretch; margin-bottom: 8px; border: 1px solid #ced4da; border-radius: 4px; background-color: white; transition: border-color 0.2s; overflow: hidden; position: relative; }
.expression-box.is-active { border-color: #80bdff; box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25); }
.color-indicator { width: 6px; flex-shrink: 0; }
.line-prefix { display: flex; align-items: center; justify-content: center; width: 36px; flex-shrink: 0; }
.main-content-area { flex-grow: 1; display: flex; flex-direction: column; border-left: 1px solid #e9ecef; }
.main-input-wrapper { display: flex; align-items: stretch; border-bottom: 1px solid #e9ecef; }
.expression-number { color: #adb5bd; font-size: 11px; }
.warning-icon svg, .fraction-icon svg, .plot-toggle-icon svg { width: 24px; height: 24px; }
.warning-icon svg { fill: #e67e22; }
.fraction-icon, .plot-toggle-icon { cursor: pointer; }
.fraction-icon svg .icon-path { fill: #868e96; }
.fraction-icon svg .icon-circle { fill: transparent; } 
.fraction-icon.fraction-mode svg .icon-path { fill: white; }
.fraction-icon.fraction-mode svg .icon-circle { fill: #007bff; }
.plot-toggle-icon .icon-circle { transition: fill 0.2s ease-in-out, stroke 0.2s ease-in-out; }
.plot-toggle-icon .icon-parabola { transition: stroke 0.2s ease-in-out; }
math-field { flex-grow: 1; padding: 5px 10px; font-size: 18px; border: none; --caret-color: #007bff; --selection-background-color: rgba(0, 123, 255, 0.2); }
math-field:focus-within { outline: none; }
.delete-btn { background: none; border: none; color: #adb5bd; font-size: 24px; font-weight: bold; cursor: pointer; padding: 0 12px; display: flex; align-items: center; }
.delete-btn:hover { color: #dc3545; }
.result-display { display: none; padding: 4px 12px; min-height: 25px; color: #868e96; font-size: 16px; --container-background: white; --bezel-color: transparent; justify-content: flex-end; align-items: center; }
#keyboard-fab { position: fixed; bottom: 20px; left: 20px; width: 56px; height: 56px; background-color: #007bff; color: white; border: none; border-radius: 50%; box-shadow: 0 4px 8px rgba(0,0,0,0.2); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 1200; transition: background-color 0.2s, transform 0.2s; }
#keyboard-fab:hover { background-color: #0056b3; transform: scale(1.05); }
#keyboard-fab svg { width: 28px; height: 28px; }
body.is-resizing { cursor: col-resize !important; user-select: none; }
body.is-resizing * { pointer-events: none; }
.jxgbox {border-radius: 0 !important; }

body { --keycap-height: 38px; --keycap-font-size: 14px; --keycap-shift-font-size: 9px; --keycap-small-font-size: 9px; --keycap-extra-small-font-size: 9px; --keyboard-toolbar-font-size: 12px; --keycap-gap: 2px; }
.ML__keyboard { padding: 5px 3px !important; }
.ML__keyboard-row { gap: 4px !important; margin-bottom: 4px !important; }
.ML__keyboard .ML__keycap { height: 38px !important; font-size: 14px !important; }
.ML__keyboard .ML__keycap .strut { height: 30px !important; }
math-field::part(virtual-keyboard-toggle) { display: none; }
math-field::part(menu-toggle) { display: none; }
