/* ── Workflow buckets (collapsible accordion) ─────────────────────────────────
   Each workflow stage is a foldable "bucket": a clickable header (title + status
   chip + chevron) over a body that shows only when open. Layout/structure only;
   colours come from the shared theme. */
.cnc-bucket {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-card);
    overflow: hidden;
}

.cnc-bucket-head {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    background: none;
    border: none;
    color: var(--text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.cnc-bucket-head:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.03);
}

.cnc-bucket-head:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.cnc-bucket-title {
    font-size: 14px;
    font-weight: 700;
}

.cnc-bucket-status {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    color: var(--text-secondary);
}

.cnc-bucket-status[data-tone="ok"] { color: var(--dev-ok); }
.cnc-bucket-status[data-tone="ready"] { color: var(--accent); }

.cnc-bucket-chevron {
    flex: none;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--text-secondary);
    border-bottom: 2px solid var(--text-secondary);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
}

.cnc-bucket.is-open .cnc-bucket-chevron {
    transform: rotate(45deg);
}

.cnc-bucket-body {
    display: none;
    padding: 12px 14px 14px;
    border-top: 1px solid var(--border);
}

.cnc-bucket.is-open > .cnc-bucket-body {
    display: block;
}

/* The machine-setup body keeps its flex column layout (.setup-body) when open. */
.cnc-bucket.is-open > .setup-body {
    display: flex;
}

/* A stage that is not reachable yet: visible, but its header cannot be opened. */
.cnc-bucket.is-locked > .cnc-bucket-head {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Nested machine-setup bucket sits flush inside the scan panel. */
.cloud-source-panel .cnc-bucket {
    margin-bottom: 14px;
    background: var(--bg-input);
}

/* ── Cloud-source chooser (scan with camera vs import a file) ─────────────── */
.cloud-source-seg {
    display: flex;
    width: 100%;
    margin-bottom: 14px;
}

.cloud-source-seg .seg-btn {
    flex: 1;
}

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

.import-row .import-file {
    flex: 1 1 100%;
}

/* Reverse-engineering review panel: deviation controls and the generated
   CadQuery program. Layout-only; colours come from the shared theme. */

.reverse-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 0.75rem 0;
}

.reverse-controls .stock-input {
    width: 6rem;
}

.reverse-code-wrap {
    margin-top: 1rem;
}

.reverse-block-title {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.reverse-code {
    max-height: 16rem;
    overflow: auto;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.25);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    white-space: pre;
    margin: 0;
}

/* Review diagnostics: per-check gate verdict, worst unresolved region, the
   per-feature fit report and the engineer-nominal suggestions. Layout only;
   colours come from the shared theme. */
.reverse-diag {
    margin-top: 0.9rem;
}

.reverse-gate-list {
    list-style: none;
    margin: 0.3rem 0 0;
    padding: 0;
}

.reverse-gate-list li {
    font-size: 0.82rem;
    padding: 0.15rem 0;
}

.reverse-gate-list li.gate-pass { color: var(--dev-ok); }
.reverse-gate-list li.gate-fail { color: var(--dev-bad); font-weight: 600; }
.reverse-gate-list li.gate-advisory { color: var(--dev-warn); }

.reverse-unresolved-text {
    font-size: 0.82rem;
    margin: 0.3rem 0 0;
    color: var(--text-secondary);
}

.reverse-feature-table,
.reverse-canon-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.4rem;
    font-size: 0.78rem;
}

.reverse-feature-table th,
.reverse-canon-table th {
    text-align: left;
    font-weight: 600;
    padding: 0.25rem 0.4rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.reverse-feature-table td,
.reverse-canon-table td {
    padding: 0.22rem 0.4rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.reverse-feature-table td.feature-ok { color: var(--dev-ok); }
.reverse-feature-table td.feature-bad { color: var(--dev-bad); font-weight: 600; }
.reverse-feature-table td.feature-unjudged { color: var(--text-secondary); }

/* Feature timeline (Fusion-style): a strip of clickable step chips in build
   order; the selected step's code opens beneath. Layout only; colours from
   the shared theme. */
.reverse-timeline-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.4rem;
}

.reverse-timeline-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.6rem;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    color: inherit;
    font-size: 0.78rem;
    line-height: 1.3;
    cursor: pointer;
}

.reverse-timeline-chip:hover {
    background: rgba(255, 255, 255, 0.1);
}

.reverse-timeline-chip.is-active {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.08);
}

.reverse-timeline-idx {
    color: var(--text-secondary);
    font-size: 0.72rem;
}

.reverse-timeline-edited {
    color: var(--dev-warn);
    font-size: 0.72rem;
}

.reverse-timeline-caption {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0.6rem 0 0.3rem;
}

.reverse-timeline-code {
    max-height: 12rem;
}

/* Flip / re-pose capture controls (layout only; colours from the theme). */
.flip-controls {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.flip-active {
    margin-top: 0.6rem;
}

.flip-actions,
.flip-rotate-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.flip-manual {
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px dashed rgba(255, 255, 255, 0.12);
}

/* ---- Build log (debugging trail for a reconstruction run) ---- */
.reverse-log-panel {
    margin-top: 8px;
    border: 1px solid var(--cnc-border, #2a2f3a);
    border-radius: 6px;
    background: var(--cnc-panel-2, #14171e);
    font-size: 12px;
}
.reverse-log-panel summary {
    cursor: pointer;
    padding: 6px 10px;
    color: var(--cnc-text-dim, #9aa4b2);
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
.reverse-log-count { opacity: 0.7; }
.reverse-log-copy {
    margin-left: auto;
    font-size: 11px;
    padding: 2px 8px;
}
.reverse-log {
    margin: 0;
    padding: 8px 10px;
    max-height: 260px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    line-height: 1.5;
    color: var(--cnc-text-dim, #9aa4b2);
    border-top: 1px solid var(--cnc-border, #2a2f3a);
}

/* ---- Live cinematic build overlay ----
   Film-style letterbox over the viewer while a reconstruction runs: a live
   badge and draft counter up top, the engine's narration + fit numbers down
   below. pointer-events: none everywhere so the viewer stays interactive. */
.reverse-cinema {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.reverse-cinema-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
}

.reverse-cinema-top {
    background: linear-gradient(to bottom, rgba(8, 10, 16, 0.82), rgba(8, 10, 16, 0));
    animation: reverse-cinema-drop 0.45s ease-out;
}

.reverse-cinema-bottom {
    background: linear-gradient(to top, rgba(8, 10, 16, 0.88), rgba(8, 10, 16, 0));
    padding-bottom: 16px;
    animation: reverse-cinema-rise 0.45s ease-out;
}

@keyframes reverse-cinema-drop {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

@keyframes reverse-cinema-rise {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

.reverse-cinema-live {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #eaf1ff;
}

.reverse-cinema-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff5f56;
    animation: reverse-cinema-pulse 1.4s ease-in-out infinite;
}

@keyframes reverse-cinema-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(255, 95, 86, 0.55); }
    50%      { opacity: 0.55; box-shadow: 0 0 0 6px rgba(255, 95, 86, 0); }
}

.reverse-cinema-draft {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9fd4ff;
}

.reverse-cinema-caption {
    flex: 1;
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: #eaf1ff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.reverse-cinema-stats {
    flex: none;
    font-size: 12px;
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: #9fd4ff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
