/* ============================================================
   ChETL Component Styles
   ============================================================
   Config Panel, Blackboard, Theory, Appearance, Chat.
   Must load AFTER layout.css.
   ============================================================ */

/* ===========================================
   Config Panel — 2-Column Engineering Form
   =========================================== */
.config-panel {
    background: var(--surface-subtle);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    padding: 12px;
}

/* 2-column form grid */
.config-row {
    display: grid;
    grid-template-columns: 45% 55%;
    align-items: center;
    column-gap: 12px;
    margin-bottom: 8px;
    width: 100%;
}

.config-label {
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.3;
    min-width: 0;
}

.config-field {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Equal-expansion for paired inputs inside a config-field row */
.config-field > * {
    flex: 1 1 0;
    min-width: 0;
}

/* Section title (stacked, uppercase, accent) */
.config-section-title {
    font-weight: 600;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Force Quasar fields to fill grid column */
.config-panel .q-field {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
}

/* White input fields inside config panel */
.config-panel .q-field__control {
    background: var(--surface-elevated) !important;
    width: 100% !important;
    min-width: 0 !important;
    border-radius: 6px !important;
}

.config-panel .q-field--focused .q-field__control {
    border-color: var(--accent-primary) !important;
}

.config-panel .q-field--disabled .q-field__control {
    background: var(--surface-subtle) !important;
    opacity: 0.75;
}

/* Remove unused validation gutter */
.config-panel .q-field__bottom {
    display: none !important;
}

/* Add real breathing room from panel border */
.config-panel .config-field {
    padding-right: 10px;
}

/* ===========================================
   CONFIG PANEL — ULTRA COMPACT FIELD MODE
   =========================================== */

/* Remove inner vertical inflation */
.config-panel .q-field__inner {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

/* Tighten control container */
.config-panel .q-field__control-container {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

/* Compact line-height for density (font-size -> ui_typography.css) */
.config-panel .q-field__native,
.config-panel .q-field__input {
    line-height: 1.2 !important;
}

/* Reduce min-height slightly further */
.config-panel .q-field,
.config-panel .q-field__control {
    min-height: 34px !important;
}

/* Responsive: collapse to single column on narrow panels */
@media (max-width: 900px) {
    .config-row {
        grid-template-columns: 1fr;
    }
}

/* =============================================
   4.4 Blackboard Styling
   ============================================= */
.blackboard-container {
    background: var(--surface-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-4);
    padding: 24px;
    min-height: 400px;
    writing-mode: horizontal-tb !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    width: 100% !important;
    min-width: 0 !important;
}

.blackboard-container .bb-section-title {
    color: var(--text-primary);
    font-weight: 700;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.blackboard-container .bb-step-title {
    color: var(--accent-primary);
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.blackboard-container .bb-content {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-left: 1rem;
    margin-bottom: 0.25rem;
}

.blackboard-container .bb-equation {
    color: var(--accent-primary);
    text-align: center;
    margin: 0.75rem 1rem;
}

.blackboard-container .bb-note {
    color: var(--text-secondary);
    background: var(--note-surface);
    border-left: 3px solid var(--note);
    line-height: 1.55;
    font-size: 0.95em;
    margin: 0.5rem 1rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-2);
}

.blackboard-container * {
    writing-mode: horizontal-tb !important;
    text-orientation: mixed !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
}

.blackboard-container div, .blackboard-container span, .blackboard-container p {
    writing-mode: horizontal-tb !important;
    white-space: normal !important;
    word-break: normal !important;
}

/* Legacy blackboard class (placeholder panels) */
.blackboard {
    background: var(--surface-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-4);
    writing-mode: horizontal-tb !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    width: 100% !important;
    min-width: 0 !important;
}

.blackboard-title {
    color: var(--text-primary);
    font-weight: bold;
    border-bottom: 2px solid var(--border-muted);
    padding-bottom: 8px;
    margin-bottom: 16px;
    writing-mode: horizontal-tb !important;
    white-space: normal !important;
}

/* =============================================
   4.5 Theory Styling
   ============================================= */
.theory-content {
    line-height: 1.7;
    color: var(--text-secondary);
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.theory-content p {
    margin-bottom: 1rem;
    max-width: 100%;
}

/* Display equations only: allow a horizontal scrollbar to appear ONLY when the
   equation is genuinely wider than the reading column (jax-agnostic — works for
   the SVG build). Inline math must never be clipped or gain a scrollbar, which
   is what previously made single symbols look boxed / broken onto their own
   line. */
mjx-container[display="true"] {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}
mjx-container:not([display="true"]) {
    max-width: none;
    overflow: visible;
}

/* ROOT CAUSE of "inline symbols render on their own line":
   NiceGUI/Quasar bundle a Tailwind-style reset (`svg { display: block }`),
   which overrides MathJax's inline SVG. A block-level <svg> makes its inline
   container span the full column width, dropping every inline symbol ($V$,
   $Z$, $V^{ig}$ …) onto its own line. Restore inline-block flow for MathJax's
   own SVG; MathJax's inline `vertical-align` style still controls the baseline. */
mjx-container > svg {
    display: inline-block;
}

.scroll-mt-4 { scroll-margin-top: 1rem; }

/* Learning Outcomes */
.learning-outcome {
    display: block;
    text-indent: -1.5em;
    padding-left: 1.5em;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.outcome-number {
    font-weight: 600;
    color: var(--accent-primary);
    display: inline;
    min-width: 1.2em;
}
.learning-outcome-intro {
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

/* --- Symbols table --- */
.symbols-table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    overflow-x: hidden;
}
.symbols-table th {
    background: var(--surface-subtle);
    font-weight: 600;
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 2px solid var(--border-muted);
    color: var(--text-secondary);
}
.symbols-table td {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-muted);
    vertical-align: top;
    word-wrap: break-word;
    color: var(--text-primary);
}
.symbols-table tr:hover {
    background: var(--surface-subtle);
}
.symbols-table .symbol-col {
    width: 15%;
}
.symbols-table .desc-col { width: 60%; }
.symbols-table .units-col {
    width: 25%;
    font-family: var(--font-mono);
}

/* --- Theory inline tables (EOS parameters, etc.) --- */
.theory-table {
    width: auto;
    border-collapse: collapse;
    margin: 1rem 0;
}
.theory-table th {
    background: var(--surface-subtle);
    font-weight: 600;
    text-align: center;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-muted);
    color: var(--text-secondary);
}
.theory-table td {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border-muted);
    text-align: center;
    vertical-align: middle;
}
.theory-table tr:hover {
    background: var(--surface-subtle);
}

/* --- Theory figures (![alt](path) markdown images) --- */
.theory-figure {
    margin: 1.75rem auto;
    text-align: center;
    max-width: 100%;
}
.theory-figure img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    /* White canvas keeps dark-stroke SVG flowcharts and PNG plots legible
       regardless of the active (light/dark) theme. */
    background: #ffffff;
    padding: 0.75rem;
    border: 1px solid var(--border-muted);
    border-radius: 6px;
    box-sizing: border-box;
}
.theory-figure figcaption {
    margin-top: 0.6rem;
    font-size: 0.85em;
    font-style: italic;
    color: var(--text-secondary);
    text-align: center;
}

/* Theory section divider */
.theory-divider {
    border: none;
    border-top: 2px solid var(--border-muted);
    margin: 1rem 0 1.5rem 0;
    width: 100%;
}

/* --- Appearance controls (theory reading panel) --- */
.appearance-label {
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
    margin-top: 0;
}
.appearance-label.mt-2 {
    margin-top: 0.5rem;
}
.appearance-group {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.appearance-option {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.125rem 0;
    color: var(--text-secondary);
    cursor: pointer;
}
.appearance-option input[type="radio"] {
    width: 12px;
    height: 12px;
    accent-color: var(--accent-primary);
    margin: 0;
}
.appearance-option:hover {
    color: var(--accent-primary);
}

/* Contents link styling */
.contents-link { text-decoration: none !important; }
.contents-link:hover { text-decoration: none !important; }

/* Theory body styling */
.theory-body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}


/* ===========================================
   CONTENT COLOR HIERARCHY (Symmetry System)
   =========================================== */

/* All content section titles — text-primary in both themes */
.section-heading,
.card-title,
.theory-title {
    color: var(--text-primary) !important;
}

/* Reading and body content — text-secondary */
.theory-content,
.learning-outcome,
.learning-outcome-intro,
.contents-title,
.appearance-option,
.info-panel-body {
    color: var(--text-secondary) !important;
}

/* Hover state for navigational items — accent only on interaction */
.contents-link:hover .contents-title {
    color: var(--accent-primary) !important;
}

/* =============================================
   4.6 Typography Scaling -> assets/styles/ui_typography.css
   ============================================= */

/* Line spacing (not font-size — these stay here) */
.theory-line-normal { line-height: 1.65 !important; }
.theory-line-relaxed { line-height: 1.9 !important; }

.theory-line-normal .theory-content,
.theory-line-normal .theory-content p,
.theory-line-normal .theory-content div { line-height: 1.65 !important; }
.theory-line-relaxed .theory-content,
.theory-line-relaxed .theory-content p,
.theory-line-relaxed .theory-content div { line-height: 1.9 !important; }

.theory-line-normal .learning-outcome,
.theory-line-normal .learning-outcome-intro,
.theory-line-normal .contents-title { line-height: 1.65 !important; }
.theory-line-relaxed .learning-outcome,
.theory-line-relaxed .learning-outcome-intro,
.theory-line-relaxed .contents-title { line-height: 1.9 !important; }

.theory-line-normal .symbols-table td,
.theory-line-normal .theory-table td,
.theory-line-normal .info-table td { line-height: 1.5 !important; }
.theory-line-relaxed .symbols-table td,
.theory-line-relaxed .theory-table td,
.theory-line-relaxed .info-table td { line-height: 1.7 !important; }

/* =============================================
   4.7 Chat UI
   ============================================= */
/* Ask AI — a context-aware assistant, styled from the system palette
   (not a generic "AI = purple gradient" bubble). */
.ai-message {
    background: var(--accent-soft);
    color: var(--text-primary);
    border: 1px solid var(--border-muted);
    border-left: 3px solid var(--accent-primary);
    padding: 12px 16px;
    border-radius: var(--radius-2) var(--radius-5) var(--radius-5) var(--radius-2);
    margin: 8px;
    max-width: 85%;
}

.user-message {
    background: var(--surface-subtle);
    color: var(--text-primary);
    border: 1px solid var(--border-muted);
    padding: 12px 16px;
    border-radius: var(--radius-5) var(--radius-5) var(--radius-2) var(--radius-5);
    margin: 8px;
    max-width: 85%;
    margin-left: auto;
}
