/* MAF Studio: a simple, readable desktop layout. Meaning is never carried by color alone (texts and icons say it too). */
:root {
    --bg: #f7f8fa;
    --panel: #ffffff;
    --text: #1b1f24;
    --muted: #5a6270;
    --accent: #1f4e79;
    --accent-soft: #e6eef6;
    --border: #d6dbe1;
    --danger: #a4262c;
    --danger-soft: #fbeaea;
    --ok: #1e6b36;
    --ok-soft: #e7f4ea;
    --focus: #f0a202;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

body { margin: 0; }

a { color: var(--accent); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--panel); padding: 0.5rem 1rem; z-index: 10; }
.skip-link:focus { left: 1rem; }

.shell {
    display: grid;
    grid-template-columns: 15rem 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}

.topbar {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1.5rem;
    background: var(--accent);
    color: #fff;
}

.topbar a, .topbar .link-button { color: #fff; }
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; }
.account { display: flex; gap: 1rem; align-items: center; }

.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 1rem 0.75rem; }
.nav, .nav ul { list-style: none; margin: 0; padding: 0; }
.nav ul { padding-left: 1rem; }
.nav a { display: block; padding: 0.3rem 0.6rem; border-radius: 4px; text-decoration: none; color: var(--text); }
.nav a:hover { background: var(--accent-soft); }
.nav a.active { background: var(--accent-soft); font-weight: 700; border-left: 4px solid var(--accent); }
.nav-group { display: block; padding: 0.5rem 0.6rem 0.2rem; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }

.content { padding: 1.5rem 2rem; max-width: 60rem; }
.content-narrow { max-width: 28rem; margin: 3rem auto; padding: 0 1rem; }

h1 { font-size: 1.6rem; margin-top: 0; }

.notice { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 0.75rem 1rem; }
.error-box { background: var(--danger-soft); border-left: 4px solid var(--danger); padding: 0.75rem 1rem; margin-bottom: 1rem; }
.error-box ul { margin: 0.25rem 0 0; }
.success-box { background: var(--ok-soft); border-left: 4px solid var(--ok); padding: 0.75rem 1rem; margin-bottom: 1rem; }

.form { display: flex; flex-direction: column; gap: 0.9rem; max-width: 32rem; }
.form label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; }
.form input[type=text], .form input[type=email], .form input[type=password], .form textarea {
    font: inherit; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 4px; font-weight: 400;
}
.form textarea { min-height: 8rem; }
.form .hint { font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.form .check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 400; }

button, .button {
    font: inherit; padding: 0.45rem 1rem; border-radius: 4px; border: 1px solid var(--accent);
    background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; display: inline-block;
}
button.secondary, .button.secondary { background: var(--panel); color: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); }
.link-button { background: none; border: none; padding: 0; text-decoration: underline; cursor: pointer; font: inherit; }
.inline-form { display: inline; margin: 0; }
.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; margin: 1rem 0; }

table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--accent-soft); }

.status { display: inline-block; padding: 0 0.4rem; border-radius: 3px; border: 1px solid var(--border); font-size: 0.9rem; }
.status-blocked { border-color: var(--danger); color: var(--danger); }
.status-active { border-color: var(--ok); color: var(--ok); }

.note-text { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel); border: 1px solid var(--border); padding: 1rem; }
.secret-link { font-family: ui-monospace, monospace; overflow-wrap: anywhere; background: var(--panel); border: 1px dashed var(--accent); padding: 0.5rem; }
.muted { color: var(--muted); }
code { font-family: ui-monospace, monospace; }

/* Stage 2: agents, chat, inspector, teaching panel, tokenization, course. */
.hint { font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.form-wide { max-width: 48rem; }
.form select, .form input[type=number], .block-label select, .block-label textarea {
    font: inherit; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-weight: 400;
}
.form fieldset, .session-toggle { border: 1px solid var(--border); border-radius: 4px; padding: 0.5rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.field-error { color: var(--danger); font-weight: 600; display: flex; flex-direction: column; }
.validation-message { color: var(--danger); font-weight: 600; }
table.compact th, table.compact td { padding: 0.25rem 0.5rem; }
table caption { text-align: left; font-weight: 600; padding: 0.25rem 0; }
.block-label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; margin: 0.75rem 0; }
.block-label textarea { min-height: 5rem; }
.session-toggle { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 1rem; margin: 0.75rem 0; }
.session-toggle .hint { flex-basis: 100%; margin: 0; }
.banner { margin-top: 0; }

.statusbar { display: flex; gap: 1.25rem; font-size: 0.9rem; }

.chat-turns, .messages, .timeline, .lessons { list-style: none; padding: 0; margin: 0; }
.chat-turn { border: 1px solid var(--border); background: var(--panel); border-radius: 4px; padding: 0.6rem 0.9rem; margin-bottom: 0.75rem; }
.chat-role { font-weight: 700; }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-user { margin-bottom: 0.4rem; }
.chat-assistant { border-left: 4px solid var(--accent); padding-left: 0.6rem; }
.chat-reasoning { margin: 0.4rem 0; border-left: 4px dashed var(--muted); padding-left: 0.6rem; color: var(--muted); }
.chat-meta { font-size: 0.9rem; margin-top: 0.3rem; }
.chat-status { min-height: 1.5rem; }

.card { border: 1px solid var(--border); background: var(--panel); border-radius: 4px; padding: 0.75rem 1rem; margin-bottom: 1rem; }
.card h3 { margin-top: 0; font-size: 1.1rem; }
.card h4 { margin-bottom: 0.25rem; }
.anatomy-bar { width: 100%; height: 1.75rem; border: 1px solid var(--text); display: block; margin: 0.5rem 0; }
.anatomy-bar rect { stroke: #fff; stroke-width: 2; }
.swatch { display: inline-block; width: 0.9rem; height: 0.9rem; border: 1px solid var(--text); vertical-align: middle; }
.part-instructions { fill: #1f4e79; background: #1f4e79; }
.part-history { fill: #8a5a00; background: #8a5a00; }
.part-usermessage { fill: #1e6b36; background: #1e6b36; }
.part-toolschemas { fill: #6b2d8a; background: #6b2d8a; }
.part-toolresults { fill: #a4262c; background: #a4262c; }
.part-providercontext { fill: #00707a; background: #00707a; }
.part-templateoverhead { fill: #9aa3ad; background: #9aa3ad; }
meter { width: 12rem; vertical-align: middle; }

.message { border-left: 4px solid var(--border); background: var(--panel); padding: 0.4rem 0.8rem; margin-bottom: 0.5rem; }
.message-role { font-weight: 700; font-size: 0.9rem; }
.message-user { border-left-color: var(--ok); }
.message-assistant { border-left-color: var(--accent); }
.message-system { border-left-color: var(--muted); border-left-style: dashed; }
.message-reasoning { border-left-color: var(--muted); border-left-style: dotted; color: var(--muted); }

.timeline-item { display: grid; grid-template-columns: 6rem 16rem 1fr auto; gap: 0.75rem; padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.timeline-offset { font-family: ui-monospace, monospace; color: var(--muted); }
.timeline-summary { overflow-wrap: anywhere; }
.timeline-code { white-space: nowrap; }

.teaching-explanation { background: var(--panel); border: 1px solid var(--border); padding: 0.75rem 1rem; }
.snippet { margin: 1rem 0; }
.snippet figcaption { font-size: 0.9rem; margin-bottom: 0.25rem; }
ol.code { font-family: ui-monospace, monospace; font-size: 0.85rem; background: #f0f2f5; border: 1px solid var(--border); padding: 0.5rem 0.5rem 0.5rem 4rem; margin: 0; overflow-x: auto; }
ol.code li { white-space: pre; }
ol.code li::marker { color: var(--muted); }

.tokens { background: var(--panel); border: 1px solid var(--border); padding: 0.75rem; line-height: 2.2; overflow-wrap: anywhere; }
.tok { border: 1px solid var(--text); border-radius: 3px; padding: 0.1rem 0.05rem; margin-right: 1px; white-space: pre-wrap; }
.tok-0 { background: #dbe9f6; }
.tok-1 { background: #fbe3c4; }
.tok-2 { background: #d9f0dc; }
.tok-3 { background: #eadcf3; }

.lesson-question { font-size: 1.05rem; }
.lessons li { margin-bottom: 0.6rem; }
.lesson-task { background: var(--panel); border: 1px solid var(--border); padding: 0.75rem 1rem; }
.markdown { background: var(--panel); border: 1px solid var(--border); padding: 0.25rem 1rem; }
.markdown pre { background: #f0f2f5; padding: 0.5rem; overflow-x: auto; }

#blazor-error-ui {
    background: #ffffe0; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); display: none;
    left: 0; padding: 0.6rem 1.25rem 0.7rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; background: none; border: none; color: var(--text); }

/* Stage 3: tools, approvals, middleware, structured output. */
.badge { display: inline-block; padding: 0 0.4rem; border-radius: 3px; border: 1px solid var(--border); font-size: 0.85rem; background: var(--bg); }
.badge-sensitive { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.picker { list-style: none; padding: 0; margin: 0 0 1rem; }
.picker-item { border: 1px solid var(--border); border-radius: 4px; padding: 0.5rem 0.75rem; margin-bottom: 0.5rem; background: var(--panel); }
.picker-item .hint { margin: 0.25rem 0; }
.picker-settings { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; align-items: flex-end; }
.picker-settings label { font-size: 0.9rem; }
.picker-settings input[type=number] { width: 6rem; }
.inline-fieldset { border: 1px dashed var(--border); padding: 0.25rem 0.75rem; }
.teacher-note { border-left: 3px solid var(--focus); padding-left: 0.5rem; }
pre.json, .tool-card pre, .structured-output pre { background: #f0f2f5; padding: 0.5rem; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 24rem; }
.tool-steps { padding-left: 1.25rem; }
.tool-steps > li { margin-bottom: 0.5rem; }
.chat-tools { margin: 0.25rem 0; }
.tool-card-compact { border: 1px solid var(--border); border-radius: 4px; padding: 0.25rem 0.75rem; margin-bottom: 0.35rem; background: var(--panel); }
.approval-card { border: 2px solid var(--focus); }
.onion, .onion-root { list-style: none; padding-left: 1.25rem; border-left: 2px solid var(--border); margin: 0.25rem 0; }
.onion-root { padding-left: 0.5rem; }
.onion-node { margin: 0.25rem 0; }
.onion-step { font-family: ui-monospace, monospace; font-size: 0.85rem; color: var(--muted); margin-right: 0.35rem; }
.onion-modelcall, .onion-toolcall { color: var(--muted); }
.structured-output { border: 1px solid var(--border); border-radius: 4px; padding: 0.5rem 0.75rem; margin: 0.35rem 0; background: var(--panel); }
.tool-steps strong, .tool-steps .status, .tool-steps .badge { margin-right: 0.35rem; }
.tool-steps a, .onion-node .timeline-code { margin-left: 0.5rem; }

/* Stage 4: session, history, context providers, compaction, long-term memory. */
.call-context { border-left: 4px solid #00707a; padding-left: 0.75rem; margin: 0.5rem 0 1rem; }
.call-context h5, .compaction h5 { margin: 0.75rem 0 0.25rem; font-size: 1rem; }
.context-kinds td, .context-kinds th { font-size: 0.92rem; }
.compaction { border: 1px solid var(--border); border-radius: 4px; padding: 0.5rem 0.75rem; background: var(--bg); }
.compaction-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.compaction-saved { color: var(--ok); }
.compaction-grew { color: var(--danger); }
.history-preview { list-style: decimal; padding-left: 1.75rem; margin: 0; font-size: 0.9rem; }
.history-item { border-bottom: 1px solid var(--border); padding: 0.15rem 0; }
.history-summary { background: var(--accent-soft); border-left: 4px solid var(--accent); padding-left: 0.4rem; }
.history-tokens { font-family: ui-monospace, monospace; color: var(--muted); margin: 0 0.35rem; }
.score-bar { width: 8rem; height: 0.9rem; vertical-align: middle; }
.score-track { fill: var(--bg); stroke: var(--border); }
.score-hit { fill: #1e6b36; }
.score-miss { fill: #9aa3ad; }
.score-threshold { stroke: var(--text); stroke-width: 2; }
.score-value { font-family: ui-monospace, monospace; margin: 0 0.35rem; }
.memory-hits, .memory-misses { margin: 0.5rem 0; }
.embedding-line { font-size: 0.9rem; }
.provider-list > li { margin-bottom: 0.5rem; }
.chat-banner { margin: 0.75rem 0; }
.chat-memory-kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.chat-memory-kinds > section { border: 1px solid var(--border); border-radius: 4px; padding: 0.25rem 0.75rem; background: var(--panel); }
.chat-memory-kinds h3 { font-size: 1rem; margin: 0.4rem 0; }
@media (max-width: 50rem) { .compaction-columns, .chat-memory-kinds { grid-template-columns: 1fr; } }
.pipeline-steps { list-style: none; padding: 0; margin: 0.5rem 0; }
.pipeline-step { border: 1px solid var(--border); border-left: 4px solid var(--accent); background: var(--panel); border-radius: 4px; padding: 0.4rem 0.9rem; margin-bottom: 0.6rem; }
.pipeline-step h4 { margin: 0.3rem 0; }
.pipeline-step pre, pre.context-text { background: #f0f2f5; padding: 0.5rem; overflow-x: auto; max-height: 24rem; font-family: ui-monospace, monospace; font-size: 0.85rem; }
.pipeline-code { margin: 0.3rem 0; font-size: 0.9rem; }
.histogram-bar { width: 12rem; height: 0.8rem; vertical-align: middle; }
.knowledge-hits { margin: 0.5rem 0; }
.knowledge-search { border: 1px solid var(--border); background: var(--panel); border-radius: 4px; padding: 0.25rem 0.9rem; margin: 0.5rem 0; }
.chat-sources { font-size: 0.9rem; margin-top: 0.4rem; border-left: 4px solid var(--ok); padding-left: 0.6rem; }
.chat-sources ul { margin: 0.2rem 0; }
.source-link { margin-left: 0.25rem; overflow-wrap: anywhere; }
