/* --- 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; }

/*******************************/
/* STEP-PRINTER STEP TITLES    */
/*******************************/
/* MC_API stepprinter.py tags the opening prose line of each step with .mc-step-title
   plus its depth (l1 = numbered outer list, l2 = lettered sub-list). Lines carrying
   display math are left untagged by the printer, so nothing here lands on a formula.

   Duplicated verbatim in assets/css/sccss.css: dashboard.php loads THIS file and
   dark-theme.css only, the legacy calculator pages load sccss.css. Same split that
   already forces .header_highlight to be defined in both. Edit both together.

   inline-block is load-bearing: these are <p>/<h3> inside an <li>, and as blocks they
   paint their background across the whole column instead of hugging their text. */
.mc-step-title {
    display: inline-block;
    max-width: 100%;
}
/* Top level: a soft chip sized to its own text. */
.mc-step-title-l1 {
    background-color: #eef6ef;
    border-left: 3px solid #81c784;
    padding: 3px 10px;
    border-radius: 3px;
    font-weight: 700;
}
h3.mc-step-title-l1 { font-size: 1.12em; }

/* Second level: weight only -- no fill, no colour. With no chip it doesn't need
   inline-block; plain inline lets the parent <li>'s A./B. marker rest on the
   first-line text baseline instead of floating above it. */
.mc-step-title-l2 {
    font-weight: 600;
    display: inline;
    vertical-align: baseline;
}

/* Dashboard highlights */
.header_highlight {
    margin-left: 20px;
    background-color: #e8f5e9; /* light green */
    color: #000000; /* dark text for contrast */
    padding: 10px;
    font-weight: bold;
    font-size: 1.0em;
    width: fit-content; /* Only highlight the text width */
}

.par_highlight {
    margin-left: 20px;
    background-color: #e8f5e9; /* light green */
    color: #000000; /* dark text for contrast */
    padding: 10px;
}

/* Template blocks wrapped by the `_openclosediv_highlight` key suffix (TemplateCreator emits
   <div class='highlight'>), e.g. the inequality narrator's "Solution to the Inequality" box.
   On the dashboard these are INTERMEDIATE results: the dict emits its own green
   .one_line_answer "Final Result" card right after, so this is deliberately a quiet
   sub-conclusion (neutral tint, no border) rather than the bordered card sccss.css draws
   on legacy pages -- two green cards back to back compete for the same "answer" signal. */
.highlight,
.highlight-explanation {
    border-radius: 8px;
    background-color: rgba(0, 0, 0, 0.04);
    padding: 10px 15px;
    margin-top: 5px;
    margin-bottom: 5px;
}

/* Friendly "we can't solve this, here's what to do" card. Deliberately NOT a red error box:
   a non-math question or a coverage gap is a normal outcome, not a failure, and the copy invites
   the student to the mathpad instead of dead-ending them. Replaces the old inline red
   "Request not understood." / "no calculator matches" boxes. Theme-aware. */
.mc-nudge {
    background-color: #eef4ff;
    color: #1e3a5f;
    border: 1px solid #cfe0ff;
    border-left: 4px solid #4a7bd0;
    border-radius: 10px;
    padding: 16px 18px;
    margin: 16px 0;
    line-height: 1.5;
    font-size: 1.02em;
}
[data-theme="dark"] .mc-nudge {
    background-color: #16263a;
    color: #cfe0ff;
    border-color: #2c4a6e;
    border-left-color: #5a8ad6;
}
.mc-nudge-link { font-weight: 600; color: #2b579a; text-decoration: underline; }
[data-theme="dark"] .mc-nudge-link { color: #8fb6ec; }

/* AI Assisted Answer block. Distinct violet accent so it never reads as a calculator solution;
   the badge + disclaimer make its unverified status explicit. Theme-aware. */
.ai-answer {
    background-color: #faf7ff;
    color: #1f1633;
    border: 1px solid #d9c9f0;
    border-left: 4px solid #7c53c3;
    border-radius: 10px;
    padding: 16px 18px;
    margin: 16px 0;
}
.ai-answer-header {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.ai-answer-badge {
    display: inline-block; background: #7c53c3; color: #fff; font-weight: 600;
    font-size: 0.8em; letter-spacing: 0.02em; padding: 3px 10px; border-radius: 999px;
}
.ai-answer-note { color: #6b5b8a; font-size: 0.85em; }
.ai-answer-body { line-height: 1.6; }
.ai-answer-body .one_line_answer { font-weight: 700; margin-top: 12px; }
[data-theme="dark"] .ai-answer { background-color: #1d1630; color: #e7defb; border-color: #3d2f57; border-left-color: #9b78d9; }
[data-theme="dark"] .ai-answer-badge { background: #9b78d9; color: #1d1630; }
[data-theme="dark"] .ai-answer-note { color: #b7a7d6; }
