/* ==========================================================================
   Reverse – „Code verstehen“: Codeansicht, Erklärungen, Ablauf, Glossar
   Nutzt ausschließlich Tokens aus variables.css bzw. evidence.css.
   ========================================================================== */

:root {
    --cx-line-height: 20px;
    --cx-sel-bg: rgba(91, 143, 217, 0.16);
    --cx-sel-border: var(--color-accent);
    --cx-range-bg: rgba(154, 143, 214, 0.16);
    --cx-hover-bg: rgba(255, 255, 255, 0.03);
}
:root[data-theme="light"] {
    --cx-sel-bg: rgba(47, 102, 179, 0.12);
    --cx-range-bg: rgba(106, 91, 181, 0.12);
    --cx-hover-bg: rgba(0, 0, 0, 0.03);
}

.cx { display: flex; flex-direction: column; gap: var(--space-4); min-height: 100%; container-type: inline-size; }
.cx-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.cx-toolbar .select { max-width: 340px; }
.cx-grid {
    display: grid;
    grid-template-columns: 230px minmax(0, 1.25fr) minmax(320px, 1fr);
    gap: var(--space-4);
    align-items: stretch;
    min-height: 560px;
}
.cx-grid > .panel { display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - var(--topbar-height) - var(--footer-height) - 170px); min-width: 0; }
.cx-pane-head { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); }
.cx-pane-head h3 { margin: 0; font-size: var(--text-md); }
.cx-scroll { overflow: auto; flex: 1; min-height: 0; }

/* Navigation */
.cx-nav-list { list-style: none; margin: 0; padding: var(--space-2); font-size: var(--text-sm); }
.cx-nav-item {
    display: flex; gap: 6px; align-items: baseline; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
    color: var(--color-text-body); font: inherit; padding: 4px 6px; border-radius: var(--radius-sm);
}
.cx-nav-item:hover { background: var(--color-accent-softer); }
.cx-nav-item[aria-current="true"] { background: var(--color-accent-soft); color: var(--color-text); }
.cx-nav-item:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }
.cx-nav-item .ln { color: var(--color-text-faint); font-family: var(--font-mono); font-size: var(--text-xs); min-width: 2.6em; text-align: right; }
.cx-nav-item .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-nav-item .kind { color: var(--color-text-faint); font-size: var(--text-xs); }

/* Codeansicht */
.cx-code { font-family: var(--font-mono); font-size: 12.5px; line-height: var(--cx-line-height); background: var(--color-inset); counter-reset: none; outline: none; }
.cx-code:focus-visible { box-shadow: inset 0 0 0 2px var(--color-accent); }
.cx-line { display: flex; min-height: var(--cx-line-height); cursor: pointer; border-left: 3px solid transparent; }
.cx-line:hover { background: var(--cx-hover-bg); }
.cx-line.is-sel { background: var(--cx-sel-bg); border-left-color: var(--cx-sel-border); }
.cx-line.is-range { background: var(--cx-range-bg); border-left-color: var(--ev-derived, #9a8fd6); }
.cx-line.is-flash { animation: cx-flash 900ms ease-out; }
@keyframes cx-flash { from { background: var(--color-accent-soft); } }
@media (prefers-reduced-motion: reduce) { .cx-line.is-flash { animation: none; } }
.cx-ln { flex: none; width: 3.6em; padding-right: 10px; text-align: right; color: var(--color-text-faint); user-select: none; }
.cx-line.is-sel .cx-ln { color: var(--color-accent); font-weight: 700; }
.cx-src { flex: 1; white-space: pre; padding-right: 12px; color: var(--color-text-body); }
.cx-wrap .cx-src { white-space: pre-wrap; word-break: break-all; }
.cx-var { border-bottom: 1px dotted var(--color-text-muted); cursor: help; }
.cx-var:hover, .cx-fn:hover { background: var(--color-accent-soft); border-radius: 2px; }
.cx-fn { text-decoration: underline dotted var(--syntax-function); text-underline-offset: 3px; }
.cx-hl { background: rgba(215, 163, 75, 0.28); border-radius: 2px; }
.cx-error-line { background: var(--color-error-soft) !important; border-left-color: var(--color-error) !important; }

/* Erklärung */
.cx-exp { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.cx-exp h3 { margin: 0; font-size: var(--text-lg); }
.cx-exp h4 { margin: 0 0 var(--space-2); font-size: var(--text-md); color: var(--color-text); }
.cx-exp p { margin: 0; }
.cx-lead { font-size: var(--text-md); line-height: 1.6; color: var(--color-text-body); }
.cx-q { border-left: 3px solid var(--color-border-strong); padding: 2px 0 2px var(--space-3); }
.cx-q dt { font-weight: 700; color: var(--color-text); font-size: var(--text-sm); display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.cx-q dd { margin: 4px 0 0; line-height: 1.55; }
.cx-qa { display: flex; flex-direction: column; gap: var(--space-3); margin: 0; }
.cx-ev { display: inline-flex; gap: 6px; align-items: center; }
.cx-tech { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; }
.cx-tech li { line-height: 1.5; }
.cx-example { background: var(--color-inset); border-radius: var(--radius-sm); padding: var(--space-3); }
.cx-example table { width: auto; }
.cx-nav-btns { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.cx-legend { display: flex; flex-wrap: wrap; gap: var(--space-2); font-size: var(--text-xs); }
.cx-cond { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.cx-cond li code { white-space: pre-wrap; }
.cx-joiner { font-weight: 700; color: var(--color-accent); font-size: var(--text-xs); letter-spacing: 0.5px; }
.cx-children { display: flex; flex-direction: column; gap: 2px; }
.cx-kv-table td:first-child { white-space: nowrap; }

/* Ablauf */
.cx-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; counter-reset: cxstep; }
.cx-step { display: flex; gap: 8px; align-items: flex-start; padding: 5px 8px; border-radius: var(--radius-sm); font-size: var(--text-sm); cursor: pointer; line-height: 1.45; }
.cx-step:hover { background: var(--color-accent-softer); }
.cx-step:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }
.cx-step .no { color: var(--color-text-faint); font-family: var(--font-mono); font-size: var(--text-xs); min-width: 2em; text-align: right; padding-top: 1px; }
.cx-step .kd { flex: none; font-size: var(--text-xs); padding: 1px 6px; border-radius: var(--radius-pill); background: var(--color-inset); color: var(--color-text-muted); }
.cx-step[data-kind="trigger"] .kd, .cx-step[data-kind="register"] .kd { background: var(--color-accent-soft); color: var(--color-accent); }
.cx-step[data-kind="decision"] .kd { background: var(--color-warning-soft); color: var(--color-warning); }
.cx-step[data-kind="network"] .kd, .cx-step[data-kind="async"] .kd { background: var(--ev-derived-soft); color: var(--ev-derived); }
.cx-step[data-kind="output"] .kd { background: var(--color-success-soft); color: var(--color-success); }
.cx-step[data-kind="error"] .kd, .cx-step[data-kind="gap"] .kd { background: var(--color-error-soft); color: var(--color-error); }
.cx-step[data-kind="branch"] { cursor: default; font-weight: 700; color: var(--color-text-muted); }
.cx-step[data-kind="gap"] { border: 1px dashed var(--color-error); }
.cx-step .tx { flex: 1; min-width: 0; }

/* Flussdiagramm */
.cx-fd { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
.cx-fd-node {
    position: relative; margin: 0 auto 18px; width: min(100%, 520px); padding: 8px 12px; border-radius: var(--radius); background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-strong); font-size: var(--text-sm); text-align: center; cursor: pointer; line-height: 1.4;
}
.cx-fd-node::after { content: ""; position: absolute; left: 50%; bottom: -16px; height: 14px; border-left: 2px solid var(--color-border-strong); }
.cx-fd-node:last-child::after { display: none; }
.cx-fd-node[data-kind="decision"] { border-color: var(--color-warning); background: var(--color-warning-soft); }
.cx-fd-node[data-kind="trigger"] { border-color: var(--color-accent); background: var(--color-accent-soft); border-radius: var(--radius-pill); }
.cx-fd-node[data-kind="network"], .cx-fd-node[data-kind="async"] { border-style: dashed; border-color: var(--ev-derived); }
.cx-fd-node[data-kind="gap"] { border: 2px dashed var(--color-error); background: var(--color-error-soft); }
.cx-fd-node[data-kind="end"], .cx-fd-node[data-kind="done"] { border-radius: var(--radius-pill); }
.cx-fd-node:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.cx-fd-branches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin: 0 0 18px; }
.cx-fd-branch { border: 1px dashed var(--color-border-strong); border-radius: var(--radius); padding: 8px 6px 0; min-width: 0; }
.cx-fd-branch > .cx-fd-label { text-align: center; font-size: var(--text-xs); font-weight: 700; color: var(--color-text-muted); margin-bottom: 6px; }
.cx-fd-inner { border-left: 2px solid var(--color-border-strong); margin: 0 0 18px 18px; padding: 8px 0 0 10px; }

/* Funktionen / Variablen */
.cx-card { border: 1px solid var(--color-border-subtle); border-radius: var(--radius); padding: var(--space-3) var(--space-4); }
.cx-risk { border-left: 3px solid var(--color-border-strong); }
.cx-risk[data-cat="error"] { border-left-color: var(--color-error); }
.cx-risk[data-cat="risk"] { border-left-color: var(--color-warning); }
.cx-risk[data-cat="suggestion"] { border-left-color: var(--color-accent); }
.cx-risk dl { margin: var(--space-2) 0 0; }
.cx-diff { font-family: var(--font-mono); font-size: 12px; width: 100%; border-collapse: collapse; }
.cx-diff td { padding: 2px 8px; vertical-align: top; white-space: pre-wrap; word-break: break-all; border-bottom: 1px solid var(--color-border-subtle); }
.cx-diff .del { background: var(--color-error-soft); }
.cx-diff .add { background: var(--color-success-soft); }
.cx-diff .ln { color: var(--color-text-faint); text-align: right; width: 3.5em; }

/* Glossar */
.cx-term { scroll-margin-top: 12px; }
.cx-term pre { margin: var(--space-2) 0 0; }
.cx-term.in-code { border-color: var(--color-accent-soft); }

/* Responsiv */
@container (max-width: 1150px) {
    .cx-grid { grid-template-columns: 200px minmax(0, 1fr); }
    .cx-grid > .cx-explain-pane { grid-column: 1 / -1; max-height: none; }
}
@container (max-width: 760px) {
    .cx-grid { grid-template-columns: minmax(0, 1fr); }
    .cx-grid > .panel { max-height: none; }
    .cx-grid > .cx-nav-pane .cx-scroll { max-height: 220px; }
    .cx-grid > .cx-code-pane .cx-scroll { max-height: 60vh; }
    .cx-fd-branches { grid-template-columns: minmax(0, 1fr); }
    .cx-toolbar .select { max-width: 100%; width: 100%; }
}
