:root {
    --bg: #f7f8fa;
    --panel: #ffffff;
    --border: #e3e6eb;
    --text: #1f2329;
    --muted: #6a7280;
    --accent: #2563eb;
    --accent-soft: #dbeafe;
    --highlight: #f59e0b;
    --highlight-soft: #fef3c7;
    --error: #b91c1c;
    --error-soft: #fee2e2;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    --node-stroke: #d1d5db;
    --node-service-fill: #fff7ed;
    --node-service-stroke: #ea580c;
    --node-network-fill: #eff6ff;
    --node-network-stroke: #2563eb;
    --node-queue-fill: #f5f3ff;
    --node-queue-stroke: #7c3aed;
    --node-cache-fill: #ecfdf5;
    --node-cache-stroke: #059669;
    --node-storage-fill: #eef2ff;
    --node-storage-stroke: #4f46e5;
    --node-index-fill: #eef2ff;
    --node-index-stroke: #4f46e5;
    --node-database-fill: #eef2ff;
    --node-database-stroke: #4f46e5;
    --node-orchestrator-fill: #fffbeb;
    --node-orchestrator-stroke: #d97706;
    --node-model-fill: #fdf4ff;
    --node-model-stroke: #c026d3;
    --node-external-fill: #fef2f2;
    --node-external-stroke: #dc2626;
    --node-observability-fill: #f0fdfa;
    --node-observability-stroke: #0f766e;
    --node-actor-fill: #f8fafc;
    --node-actor-stroke: #64748b;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar h1 {
    margin: 0;
    font-weight: 600;
}

/* Interview icon in the header; shown only when one is defined and loads. */
.dataset-icon {
    width: 64px;
    height: 64px;
    object-fit: contain;
    flex: none;
}

.dataset-icon[hidden] {
    display: none;
}


.muted {
    color: var(--muted);
    font-size: 13px;
}

select,
button {
    font: inherit;
    color: inherit;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: #f1f4f9;
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    height: calc(100vh - 60px);
}

.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.nav-list {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    padding: 8px 0 16px;
}

/* Settings: pinned below the nav groups; pushed to the bottom when the list is
   short, otherwise it just follows the last group at the end of the scroll. */
.nav-settings {
    margin-top: auto;
    margin-bottom: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.setting-field {
    padding: 4px 18px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.setting-select {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

.setting-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.setting-hint {
    font-size: 11px;
    line-height: 1.35;
}

.nav-group {
    padding: 10px 18px 4px;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: black;
}

.nav-items {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
}

.nav-items li {
    padding: 8px 18px;
    cursor: pointer;
    border-left: 3px solid transparent;
    font-size: 14px;
    color: var(--text);
    line-height: 1.35;
}

.nav-items li:hover {
    background: #f1f4f9;
}

.nav-items li.active {
    background: var(--accent-soft);
    border-left-color: var(--accent);
    font-weight: 600;
}

.nav-items li.nav-item-child {
    padding-left: 36px;
    font-size: 13px;
    color: #4b5563;
}

.nav-items li.nav-item-child::before {
    content: "↳ ";
    color: var(--muted);
}

.content {
    padding: 20px 28px 64px;
    overflow-y: auto;
}

.step-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.step-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.step-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.step-description {
    color: #333a44;
}

.step-text-section {
    box-sizing: border-box;
    max-width: 100%;
    margin: 8px 0 12px;
}

h3 {
    color: darkblue;
}

.step-text-section h3,
.step-concepts h3 {
    margin: 0 0 6px;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Step text-section title rendered with an icon (Design Rationale, Why Now,
   Decision Point). */
.step-text-section > .section-heading {
    margin-bottom: 6px;
}

.step-text-section > .section-heading h3 {
    margin-bottom: 0;
}

.step-text-body {
    max-width: 74ch;
}

.step-text-body p,
.step-text-body ul {
    margin: 0;
}

.step-text-body ul {
    padding-left: 18px;
}

.step-text-body li {
    margin: 4px 0;
}

.step-concepts {
    margin: 22px 0 12px;
}

.concept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
}

.concept-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 12px;
    border-left-width: 3px;
    border-left-color: lightgrey;
}

/* Trade-off cards reuse the concept-card box; the accent edge marks them as
   decision content rather than vocabulary. */
.concept-card.tradeoff-card {
    border-left-color: var(--accent);
}

.concept-card h4 {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 600;
}

.concept-card p {
    margin: 0;
    font-size: 13px;
    line-height: 1.4;
}

.concept-card p + p {
    margin-top: 5px;
}

.concept-card .step-chips {
    margin-top: 8px;
    white-space: nowrap;
    overflow: hidden;
}

.concept-line strong {
    font-weight: 600;
    margin-top: 12px;
}

.asset-heading {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.asset-heading h4,
.asset-heading .pattern-name {
    min-width: 0;
}

.asset-icon {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    padding: 3px;
}

.concept-card .asset-heading {
    margin-bottom: 4px;
}

.concept-card .asset-heading h4 {
    margin-bottom: 0;
}

.diagram-view-tabs,
.option-tabs {
    display: flex;
    gap: 4px;
    margin-top: 12px;
    border-bottom: 1px solid var(--border);
}

.diagram-view-tabs + .option-tabs {
    margin-top: 0;
}

.diagram-view-tab,
.option-tab {
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: -1px;
    cursor: pointer;
}

.diagram-view-tab:hover,
.option-tab:hover {
    color: var(--text);
    background: #f1f4f9;
}

.diagram-view-tab.active,
.option-tab.active {
    background: var(--panel);
    border-color: var(--border);
    color: var(--accent);
    font-weight: 600;
}

/* Diagram <-> AI Visual toggle: a small pill segmented control above the
   diagram (and inside the intro visual-switcher). */
.visual-tabs {
    display: flex;
    gap: 2px;
    margin: 0;
    padding: 0;
}

.visual-tabs[hidden] {
    display: none;
}

.visual-tab {
    background: var(--panel);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 11px;
    color: var(--muted);
    cursor: pointer;
}

.visual-tab:hover {
    color: var(--text);
}

.visual-tab.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

/* Two-column layout for step / final-design diagrams: the diagram fills the
   left, interactive controls in a fixed-width right column. */
.diagram-layout {
    display: flex;
    align-items: stretch;
    gap: 12px;
    margin-top: 12px;
}

/* Right column: a TB/LR layout switch on top, then a vertical list of node
   on/off toggles. `order: 1` places it after the diagram regardless of DOM
   order. */
.diagram-controls {
    order: 1;
    flex: 0 0 200px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 8px;
    align-self: flex-start;
}

.diagram-controls[hidden] {
    display: none;
}

.diagram-control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* The TB/LR buttons sit side by side under their label. */
.diagram-direction {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
}

.diagram-control-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.diagram-direction .diagram-control-label {
    flex-basis: 100%;
}

.diagram-dir-btn {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
}

.diagram-dir-btn:hover {
    color: var(--text);
}

.diagram-dir-btn.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

/* Node toggles as a vertical list. */
.diagram-node-toggles {
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
}

.diagram-node-toggle {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.diagram-node-toggle input {
    cursor: pointer;
    margin: 0;
    flex: 0 0 auto;
}

/* A toggled-off node reads as muted in the list. */
.diagram-node-toggle:has(input:not(:checked)) {
    color: var(--muted);
    text-decoration: line-through;
}

/* "Download SVG" action under the node list. */
.diagram-download {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.diagram-download-btn {
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--accent);
    cursor: pointer;
}

.diagram-download-btn:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.diagram-container {
    flex: 1 1 auto;
    min-width: 0;
    margin-top: 0;
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 0 8px 8px 8px;
    overflow-x: auto;
    min-height: 200px;
}

/* Narrow screens: stack the diagram and controls vertically (controls below,
   per their order). */
@media (max-width: 720px) {
    .diagram-layout {
        flex-direction: column;
    }
    .diagram-controls {
        flex-basis: auto;
    }
}

/* Highlight legend: sits at the bottom of the controls column with a top
   divider and a "Legend" label header, matching the Layout/Nodes groups. */
.diagram-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    font-size: 12px;
    color: var(--muted, #6a7280);
}

.diagram-legend[hidden] {
    display: none;
}

.diagram-legend-row {
    display: flex;
    align-items: center;
    gap: 7px;
}

.diagram-legend-swatch {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid crimson;
    flex: none;
}

/* The diagram lives in the right column of #diagram-layout. Its default
   border-radius (0 8px 8px 8px) connects it to the tabs above the layout row;
   with no tabs at all it's a fully rounded standalone panel. */
.option-tabs[hidden] + .diagram-layout .diagram-container {
    border-radius: 8px;
}

.diagram-block.has-diagram-view-tabs .option-tabs[hidden] + .diagram-layout .diagram-container {
    border-radius: 0 8px 8px 8px;
}

/* Short "what this alternative is" line for the selected option, shown below
   the diagram and just above its pros/cons. */
.option-description {
    margin: 12px 4px 0;
    font-size: 14px;
    color: #333a44;
}

.option-description[hidden] {
    display: none;
}

/* When the description sits directly above the pros/cons, keep them close so
   the line reads as a lead-in to the columns. */
.option-description:not([hidden]) + .option-proscons {
    margin-top: 8px;
}

.option-proscons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 12px;
}

.option-proscons .proscons-col {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
}

.option-proscons h3 {
    margin: 0 0 6px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.option-proscons .pros h3 {
}

.option-proscons .cons h3 {
}

/* Single-column fallback for options authored with a flat `tradeoffs` list
   (no split pros/cons): span the full width instead of leaving a gap. */
.option-proscons .tradeoffs {
    grid-column: 1 / -1;
}

.option-proscons ul {
    margin: 0;
    padding-left: 18px;
}

.option-proscons li {
    margin: 3px 0;
    font-size: 14px;
}

.mermaid {
    font-family: inherit;
}

/* Subgraph (group) background: softer than Mermaid's default lavender so the
   nodes stay the focus. Targets the rendered cluster rect in both the main
   diagram and the makeMermaidEl flow/deep-dive diagrams. */
.mermaid .cluster > rect,
.overview-diagram .cluster > rect {
    fill: #fafbfc !important;
    stroke: var(--border) !important;
    stroke-width: 1px !important;
}

.mermaid .node-label-stack {
    display: inline-block;
    text-align: center;
    white-space: nowrap;
    line-height: 1.12;
}

.mermaid .node-type-caption {
    display: block;
    margin: 0 0 1px;
    color: var(--muted);
    font-size: 10px;
    line-height: 1;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.mermaid .node-label-top-spacer {
    display: block;
    height: 1em;
    line-height: 1em;
}

.mermaid .node-main-label {
    display: block;
    line-height: 1;
}

.mermaid .node-annotation {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 9px;
    line-height: 1.1;
    font-weight: 400;
}

.mermaid .sequence-node-type-caption {
    fill: var(--muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.mermaid .sequence-node-main-label {
    font-size: 15px;
    line-height: 1.1;
}

/* Highlight for new/changed Mermaid nodes.
   Flowcharts use Mermaid's classDef/class to apply 'newNode'.
   Sequence diagrams reject that syntax, so app.js patches the rendered SVG
   directly: it adds `.newNode` to the participant <rect> and its <text>.
   Highlight is an outline so type color remains visible. */
.node.newNode > rect,
.node.newNode > polygon,
.node.newNode > circle,
.node.newNode > ellipse,
.node.newNode > path,
rect.newNode,
.actor.newNode,
rect.actor.newNode,
.actor-top.newNode,
.actor-bottom.newNode {
    stroke: crimson !important;
    stroke-width: 3.6px !important;
}

.node.newNode .label,
text.newNode,
.actor.newNode + text,
text.actor.newNode {
    font-weight: 600;
}

.error-banner {
    margin-top: 16px;
    padding: 10px 14px;
    background: var(--error-soft);
    color: var(--error);
    border: 1px solid #fca5a5;
    border-radius: 6px;
    font-size: 14px;
    white-space: pre-wrap;
}

/* ---------- Step extras (deep dives / bottlenecks / talking points) ---------- */

.step-extras {
    margin-top: 4px;
}

.extras-section {
    margin-top: 22px;
}

/* Separate each "probe further" section from the previous one with a thin
   rule (acts like an <hr> between sections, without a leading divider). */
.extras-section + .extras-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.extras-section > h3,
.extras-section > .section-heading h3 {
    margin: 0 0 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Section title rendered with an icon (e.g. Talking points). */
.extras-section > .section-heading {
    margin-bottom: 8px;
}

.extras-section > .section-heading h3 {
    margin-bottom: 0;
}

.education-card,
.failure-drill-card,
.signal-col,
.recap-grid .labeled-text {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    border-left-width: 3px;
    border-left-color: lightgrey;
}

.education-card {
    border-left-width: 3px;
    border-left-color: lightgrey;
}

.decision-prompt {
    border-left-width: 3px;
    border-left-color: lightgrey;
}

.education-card p,
.education-card ul,
.labeled-text p,
.failure-drill-card p,
.signal-col ul {
    margin: 0;
}

.education-card ul,
.signal-col ul {
    padding-left: 18px;
}

.education-card li,
.signal-col li {
    margin: 3px 0;
}

.recap-grid,
.failure-drill-list,
.signal-columns {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.failure-drill-list,
.signal-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.labeled-text h4,
.failure-drill-card h4,
.signal-col h4 {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
}

.labeled-text p {
    font-size: 14px;
    line-height: 1.45;
    margin-bottom: 12px;
}

.failure-drill-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.failure-drill-card > h4 {
    font-size: 15px;
}

.signal-col.strong {
    border-top: 3px solid #047857;
}

.signal-col.weak {
    border-top: 3px solid var(--error);
}

.flow-tabs-wrap {
    display: flex;
    flex-direction: column;
}

.flow-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--border);
}

.flow-tab {
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: -1px;
    cursor: pointer;
}

.flow-tab:hover {
    color: var(--text);
    background: #f1f4f9;
}

.flow-tab.active {
    background: var(--panel);
    border-color: var(--border);
    color: var(--accent);
    font-weight: 600;
}

.flow-body {
    background: var(--panel);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 6px 6px 6px;
    padding: 10px 14px;
}

.flow-note {
    margin: 0 0 6px;
    font-size: 13px;
}

.overview-diagram.flow-diagram {
    margin: 6px 0 0;
    padding: 8px;
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.deepdive-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.deepdive-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    border-left-width: 3px;
    border-left-color: lightgrey;
}

.deepdive-card h4 {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
}

.deepdive-card .asset-heading {
    margin-bottom: 6px;
}

.deepdive-card .asset-heading h4 {
    margin-bottom: 0;
}

.deepdive-card ul {
    margin: 0;
    padding-left: 20px;
}

.deepdive-card li {
    margin: 3px 0;
}

.bottleneck-list {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    border-left-width: 3px;
    border-left-color: lightgrey;
}

.bottleneck-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
}

/* Rows that lead with a mitigations icon get an auto column for it. */
.bottleneck-row:has(> .asset-icon) {
    grid-template-columns: auto 1fr 1fr;
    align-items: center;
}

.bottleneck-row:first-child {
    border-top: none;
}

.bottleneck-issue::before {
    content: "Issue: ";
    font-weight: 600;
    color: var(--error);
}

.bottleneck-mitigation::before {
    content: "Mitigation: ";
    font-weight: 600;
    color: #047857;
}

.extras-section.talking ul,
.extras-section.followups ul {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px 10px 32px;
    margin: 0;
    border-left-width: 3px;
    border-left-color: lightgrey;
}

.extras-section.talking li,
.extras-section.followups li {
    margin: 3px 0;
}

/* ---------- Intro block (Requirements / Capacity / API / Data Model / Follow-ups) ---------- */

.intro-block {
    margin-top: 8px;
}

.dataset-description {
    max-width: 980px;
    margin: 0 0 14px;
    padding-left: 20px;
    font-size: 16px;
    line-height: 1.45;
}

.dataset-description li {
    margin: 3px 0;
    font-size: 16px;
    color: black;
}

/* Optional Mermaid visuals rendered above (or inside) intro sections. */
.overview-diagram {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 16px;
    overflow-x: auto;
}

/* Requirements & capacity diagrams: uniform very-light-grey node fill (these
   are conceptual diagrams, not the typed architecture, so all nodes look the
   same rather than carrying node-type colors). */
.overview-diagram.requirements-diagram .node > rect,
.overview-diagram.requirements-diagram .node > polygon,
.overview-diagram.requirements-diagram .node > circle,
.overview-diagram.requirements-diagram .node > ellipse,
.overview-diagram.requirements-diagram .node > path,
.overview-diagram.capacity-diagram .node > rect,
.overview-diagram.capacity-diagram .node > polygon,
.overview-diagram.capacity-diagram .node > circle,
.overview-diagram.capacity-diagram .node > ellipse,
.overview-diagram.capacity-diagram .node > path {
    fill: #f3f4f6 !important;
    stroke: var(--border) !important;
}

.overview-diagram .mermaid {
    text-align: center;
}

.overview-diagram.api-diagram {
    margin-top: 4px;
    margin-bottom: 0;
    padding: 10px;
    background: #fbfcfe;
}

/* Decision-tree map: the Wrap-up "Steps Overview" entry — the whole journey of
   steps -> chosen option -> final design, with alternatives as side branches.
   Auto-generated; nodes are clickable and jump to the matching entry. */

/* Heading + description above the diagram on the Final Design entry
   ("High-Level Architecture"), shown above the diagram. */
.diagram-heading {
    margin: 0 0 8px;
}

.diagram-description {
    margin: 0 0 12px;
}

.decision-tree-intro {
    margin: 0 0 12px;
}

.overview-diagram.decision-tree-diagram {
    background: #fbfcfe;
}

/* Clicking a node navigates to that step / alternative / final design. */
.overview-diagram.decision-tree-diagram .node.dt-clickable {
    cursor: pointer;
}

.overview-diagram.decision-tree-diagram .node.dt-clickable:hover > rect,
.overview-diagram.decision-tree-diagram .node.dt-clickable:hover > polygon,
.overview-diagram.decision-tree-diagram .node.dt-clickable:hover > path {
    stroke: var(--accent) !important;
    stroke-width: 2px !important;
}

/* Optional diagram inside a deep-dive card: sits flush in the card, no nested panel. */
.overview-diagram.deepdive-diagram {
    margin-top: 8px;
    margin-bottom: 0;
    padding: 8px;
    background: transparent;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
}

/* AI-generated visual shown in the diagram area when toggled on, and the
   standalone visual under requirements/capacity. */
.diagram-image {
    display: block;
    width: 100%;
    max-height: 560px;
    object-fit: contain;
    border-radius: 4px;
    background: #fff;
}

.diagram-image[hidden] {
    display: none;
}

/* Intro (requirements/capacity) AI visual sits in the same panel as the
   overview diagram. */
.overview-diagram .diagram-image.intro-ai-visual {
    margin: 0;
}

.diagram-image.standalone {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 16px;
}

/* The intro Diagram/AI-Visual switcher wraps the overview diagram + its image. */
.visual-switcher {
    margin-bottom: 16px;
}

.diagram-inline-error {
    margin-top: 6px;
    padding: 6px 10px;
    background: var(--error-soft);
    color: var(--error);
    border: 1px solid #fca5a5;
    border-radius: 4px;
    font-size: 12px;
    white-space: pre-wrap;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco,
    Consolas, "Liberation Mono", monospace;
    font-size: 13px;
}

/* Requirements: two columns */
.req-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.req-col {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
}

.req-col h3 {
    margin: 0 0 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.req-col ul {
    margin: 0;
    padding-left: 20px;
}

.req-col li {
    margin: 4px 0;
}

/* Capacity table */
.capacity-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.capacity-table th,
.capacity-table td {
    text-align: left;
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    vertical-align: top;
}

.capacity-table thead th {
    background: #f3f5f9;
    border-top: none;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
}

/* API design */
.api-list {
    display: grid;
    gap: 10px;
}

.api-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
}

.api-head {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

/* Collapsible endpoint: the method+path line is the clickable summary. */
details.api-card > summary.api-head {
    cursor: pointer;
    list-style: none;          /* hide the default disclosure triangle … */
    user-select: none;
}

details.api-card > summary.api-head::-webkit-details-marker {
    display: none;             /* … including the WebKit/Safari variant */
}

/* Custom chevron rendered before the method chip; rotates when open. */
details.api-card > summary.api-head::before {
    content: "";
    flex: 0 0 auto;
    width: 6px;
    height: 6px;
    margin-right: 2px;
    border-right: 2px solid var(--muted, #6b7280);
    border-bottom: 2px solid var(--muted, #6b7280);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
}

details.api-card[open] > summary.api-head::before {
    transform: rotate(45deg);
}

details.api-card > summary.api-head:hover::before {
    border-color: var(--accent, #2563eb);
}

.api-method {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #fff;
    background: #6b7280;
}

.api-method.method-get {
    background: #2563eb;
}

.api-method.method-post {
    background: #047857;
}

.api-method.method-put {
    background: #b45309;
}

.api-method.method-delete {
    background: #b91c1c;
}

.api-method.method-patch {
    background: #7c3aed;
}

.api-path {
    font-size: 14px;
}

.api-desc {
    margin: 6px 0 4px;
    color: #333a44;
}

.api-label {
    margin-top: 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.api-flow-placeholder {
    margin: 4px 0 0;
    padding: 8px 10px;
    background: #f3f5f9;
    border: 1px dashed var(--border);
    border-radius: 4px;
    font-style: italic;
}

.api-code {
    margin: 4px 0 0;
    padding: 8px 10px;
    background: #f3f5f9;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Data model */
.schema-list {
    display: grid;
    gap: 12px;
}

.schema-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
}

.schema-card h3,
.schema-card > .schema-head {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Collapsible table: the table name is the clickable summary. */
details.schema-card > summary.schema-head {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    list-style: none;          /* hide the default disclosure triangle … */
    user-select: none;
}

details.schema-card > summary.schema-head::-webkit-details-marker {
    display: none;             /* … including the WebKit/Safari variant */
}

/* Custom chevron rendered before the table name; rotates when open. */
details.schema-card > summary.schema-head::before {
    content: "";
    flex: 0 0 auto;
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
}

details.schema-card[open] > summary.schema-head::before {
    transform: rotate(45deg);
}

details.schema-card > summary.schema-head:hover::before {
    border-color: var(--accent);
}

/* When collapsed, drop the name's bottom margin so the summary sits flush. */
details.schema-card:not([open]) > summary.schema-head {
    margin-bottom: 0;
}

.schema-note {
    margin: 0 0 8px;
}

.schema-table {
    width: 100%;
    border-collapse: collapse;
}

.schema-table th,
.schema-table td {
    text-align: left;
    padding: 5px 8px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    vertical-align: top;
}

.schema-table thead th {
    border-top: none;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
}

/* Design vs. Requirements */
.satisfies-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.satisfies-col h3 {
    margin: 0 0 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.satisfies-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 10px;
}

.satisfies-req {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
}

.satisfies-how {
    margin: 0 0 8px;
    color: #333a44;
}

.satisfies-visual-link {
    display: block;
    margin: 8px 0;
}

.satisfies-visual-img {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.step-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.step-chip {
    font: inherit;
    font-size: 12px;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid #c7dafe;
    border-radius: 999px;
    padding: 2px 10px;
    cursor: pointer;
}

.step-chip:hover {
    background: #c7dafe;
}

.step-chip-missing {
    color: var(--muted);
    background: #f3f5f9;
    border-color: var(--border);
    cursor: default;
}

/* Wrap-up > Technology Choices: one card per architecture concern, with
   self-hosted vs cloud-native (AWS/GCP/Azure) options, a trade-off line, and a
   "what this makes irrelevant" note. */
.tech-choices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(800px, 1fr));
    gap: 12px;
}

.tech-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    border-left-width: 3px;
    border-left-color: lightgrey;
    padding: 12px 14px;
}

.tech-head {
    display: block;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 10px;
    margin-bottom: 28px;
}

.tech-concern {
    font-size: 30px;
    margin-bottom: 12px;
    margin-top: 0;
    font-weight: 500;
}

.tech-section-label {
    margin: 10px 0 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.tech-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    margin: 4px 0;
}

.tech-row-label {
    flex: 0 0 72px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.tech-cloud-row .tech-row-label {
    flex-basis: 52px;
}

.tech-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1 1 0;
    min-width: 0;
}

.tech-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #334155;
    background: #f1f4f9;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 12px 3px 3px;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.tech-chip:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.tech-chip-icon {
    width: 30px;
    height: 30px;
    object-fit: contain;
    flex: none;
    border-radius: 50%;
    border: 2px solid lightgrey;
}

.tech-note-label {
    margin: 12px 0 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.tech-tradeoff,
.tech-irrelevant {
    margin: 0;
    font-size: 14px;
    line-height: 1.45;
    color: #3f3a14;
    background: #f0f0f0;
    border-radius: 6px;
    padding: 8px 10px 8px 28px;
    border: 1px solid lightgrey;
}

.tech-tradeoff li,
.tech-irrelevant li {
    margin: 2px 0;
}

.tech-tradeoff li:first-child,
.tech-irrelevant li:first-child {
    margin-top: 0;
}

/* Explainer comic (Wrap-up) */
.explainer-comic {
    margin: 4px 0;
}

.explainer-comic-link {
    display: inline-block;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.explainer-comic-img {
    display: block;
    max-width: 100%;
    height: auto;
}

.explainer-comic-caption {
    margin-top: 8px;
}

/* Follow-ups */
.followups-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px 12px 32px;
}

.followups-card ul {
    margin: 0;
    padding-left: 0;
}

.followups-card li {
    margin: 4px 0;
}

/* To Probe Further */
.probe-further {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.probe-group-title {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}

.probe-group-description {
    margin: 0 0 10px;
}

.probe-links {
    margin: 0;
    padding: 4px 32px;
    border-left: 3px lightgrey solid;
    background-color: white;
}

.probe-link-item {
    margin: 9px 0;
    padding-left: 2px;
}

.probe-link-title {
    color: var(--accent);
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
}

a.probe-link-title:hover {
    text-decoration: underline;
}

.probe-link-meta {
    color: var(--muted);
    font-size: 11px;
}

.probe-link-why {
    margin: 3px 0 0;
    color: #333a44;
}

@media (max-width: 720px) {
    .layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 200px;
    }

    .recap-grid,
    .failure-drill-list,
    .signal-columns {
        grid-template-columns: 1fr;
    }
}

/* ---------- Overview page (index.html) ---------- */

.overview {
    max-width: 1120px;
    margin: 0 auto;
    padding: 24px;
}

/* "← All interviews" link in the interview-page topbar. */
.overview-link {
    display: inline-block;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
}

.overview-link:hover {
    text-decoration: underline;
}

.overview-search {
    margin-bottom: 24px;
}

.overview-search-input {
    width: 100%;
    max-width: 420px;
    padding: 10px 14px;
    font: inherit;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.overview-search-input::placeholder {
    color: var(--muted);
}

.overview-search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

#overview-search-empty {
    margin: 12px 0 0;
}

.group-section {
    margin-bottom: 32px;
}

.group-title {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.interview-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 16px;
    box-shadow: var(--shadow);
    transition: border-color 0.12s ease, box-shadow 0.12s ease,
    transform 0.12s ease;
}

.interview-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12);
    transform: translateY(-2px);
}

.interview-icon {
    width: 132px;
    height: 132px;
    object-fit: contain;
}

.interview-name {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
}

@media (max-width: 720px) {
    .overview {
        padding: 16px;
    }

    .overview-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }

    .interview-icon {
        width: 56px;
        height: 56px;
    }
}

/* ---------- Book features: patterns, interview script, levels, traps ---------- */

/* Overview > Patterns */
.patterns-list {
    display: grid;
    /* auto-fit (not auto-fill) so cards stretch to fill the row — a lone card
       spans the full width, matching .concept-grid. */
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
}

.intro-grouped-list,
.overview-concepts {
    display: block;
}

.intro-item-group {
    margin: 0 0 20px;
}

.intro-item-group:last-child {
    margin-bottom: 0;
}

/* Pattern cards share the concept-card box styling (background, border,
   radius, left accent, padding). */
.pattern-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 12px;
    border-left-width: 3px;
    border-left-color: lightgrey;
}

.pattern-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.pattern-heading {
    margin-bottom: 4px;
}

.pattern-heading .pattern-name {
    margin-bottom: 0;
}

.pattern-what {
    margin: 0 0 6px;
    color: #333a44;
    font-size: 13px;
    line-height: 1.4;
}

.pattern-when {
    margin: 0 0 8px;
    font-style: italic;
    font-size: 13px;
    line-height: 1.4;
}

.pattern-tradeoffs {
    margin: 0 0 8px;
    color: #333a44;
    font-size: 13px;
    line-height: 1.4;
}

/* Overview grouped headings */
.catalog-category,
.intro-item-group-title,
.step-concepts .intro-item-group-title {
    margin: 20px 0 10px;
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}

.catalog-category:first-child,
.intro-item-group:first-child .intro-item-group-title,
.step-concepts .intro-item-group:first-child .intro-item-group-title {
    margin-top: 0;
}

/* Per-step pattern tags (non-clickable chips) */
.pattern-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.pattern-tag {
    font-size: 12px;
    color: var(--node-queue-stroke);
    background: var(--node-queue-fill);
    border: 1px solid #ddd6fe;
    border-radius: 999px;
    padding: 2px 10px;
}

/* usedBy chips that link to a case study */
a.pattern-tag {
    text-decoration: none;
}

a.pattern-tag:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Pattern relationships: aliases, pairs-with, confused-with rows */
.pattern-rel {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
    margin: 0 0 8px;
    font-size: 12px;
    line-height: 1.5;
}

.pattern-rel-label {
    font-size: 12px;
}

.pattern-alias,
.pattern-rel-chip {
    font-size: 12px;
    border-radius: 999px;
    padding: 1px 9px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: #333a44;
}

.pattern-alias {
    font-style: italic;
}

/* Overview > Interview Script */
.script-timeline {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.script-phase {
    background: var(--panel);
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-left-color: lightgrey;
    border-radius: 6px;
    padding: 10px 14px;
}

.script-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.script-phase-name {
    font-weight: 600;
    font-size: 15px;
    color: darkblue;
}

.script-time {
    font-size: 12px;
    color: var(--muted);
}

/* Wrap-up > By Level */
.level-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.level-col h3 {
    margin: 0 0 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Per-step Common traps */
.trap-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.trap-card {
    border: 1px solid lightgrey;
    border-radius: 6px;
    padding: 10px 14px;
    background-color: white;
    border-left-width: 3px;
    border-left-color: lightgrey;
}

.trap-card h4 {
    margin: 0 0 6px;
    font-size: 15px;
}

.trap-card .asset-heading {
    margin-bottom: 4px;
}

.trap-card .asset-heading h4 {
    margin-bottom: 0;
}

/* Recap (Before/After/New risk) and failure-drill headings carry an icon via
   .asset-heading; keep the label tight against the icon. */
.recap-grid .labeled-text .asset-heading,
.failure-drill-card .asset-heading {
    margin-bottom: 4px;
}

.recap-grid .labeled-text .asset-heading h4,
.failure-drill-card .asset-heading h4 {
    margin-bottom: 0;
    font-size: 14px;
}

@media (max-width: 720px) {
    .patterns-list,
    .level-columns {
        grid-template-columns: 1fr;
    }
}
