:root {
    --bg: #0f1216;
    --panel: #161a21;
    --panel-2: #1d222b;
    --border: #2a313d;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --accent: #3b82f6;
    --ok: #22c55e;
    --warn: #f59e0b;
    --err: #ef4444;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.error {
    background: rgba(239, 68, 68, 0.1); color: var(--err);
    border: 1px solid var(--err); border-radius: 4px;
    padding: 8px 12px; margin: 0 0 16px; font-size: 13px;
}

.topbar {
    display: flex; align-items: center; gap: 24px;
    padding: 10px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.topbar .brand a { color: var(--text); font-weight: 600; }
.topbar .links { display: flex; gap: 16px; flex: 1; }
.topbar .logout { display: flex; align-items: center; gap: 10px; margin: 0; }
.topbar .who { color: var(--muted); font-size: 13px; }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

button {
    background: var(--accent); color: white; border: 0;
    padding: 8px 14px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
button:hover { filter: brightness(1.1); }
button.secondary { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
button.danger { background: var(--err); }
button.small { padding: 4px 8px; font-size: 12px; }

input, select, textarea {
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 8px 10px; font: inherit; width: 100%;
}
label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
form.inline { display: inline; margin: 0; }
form.inline label { display: inline-flex; }
form.row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
form.narrow { max-width: 480px; }
.secondary-link { margin-left: 12px; color: var(--muted); }

.auth-card {
    max-width: 360px; margin: 80px auto; padding: 28px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-card .hint { color: var(--muted); margin: 0 0 20px; }
.auth-card button { width: 100%; padding: 10px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 8px; padding: 16px;
}
.printer-card.offline { opacity: 0.6; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.card-header .name { font-size: 16px; font-weight: 600; }
.cam-link { font-size: 13px; color: var(--muted); margin-left: 8px; }
.cam-link:hover { color: var(--accent); }

.ready-pill {
    font-size: 12px; padding: 4px 10px; border-radius: 999px;
    font-weight: 600; letter-spacing: 0.02em; cursor: pointer;
    border: 1px solid; line-height: 1;
}
.ready-pill.is-ready {
    background: rgba(34, 197, 94, 0.12); color: var(--ok); border-color: var(--ok);
}
.ready-pill.is-ready:hover { background: rgba(34, 197, 94, 0.2); }
.ready-pill.not-ready {
    background: var(--warn); color: #1a1a1a; border-color: var(--warn);
    animation: pulse-warn 2s ease-in-out infinite;
}
.ready-pill.not-ready:hover { filter: brightness(1.1); }
@keyframes pulse-warn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5); }
    50%      { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}
.printer-card.not-ready { border-color: var(--warn); }

/* LED toggle — pill-sized to sit alongside .ready-pill in the state-row,
   styled as an iOS-style sliding switch. */
.light-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent; border: 1px solid transparent;
    padding: 3px 8px; border-radius: 999px;
    cursor: pointer; line-height: 1;
    font-size: 12px;
}
.light-toggle-icon { font-size: 12px; line-height: 1; }
.light-toggle-track {
    position: relative;
    display: inline-block;
    width: 26px; height: 14px;
    background: rgba(120, 120, 120, 0.45);
    border-radius: 999px;
    transition: background 0.18s ease;
}
.light-toggle-thumb {
    position: absolute;
    top: 1px; left: 1px;
    width: 12px; height: 12px;
    background: #e5e7eb;
    border-radius: 50%;
    transition: left 0.18s ease, background 0.18s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.light-toggle.is-on .light-toggle-track { background: rgba(250, 204, 21, 0.6); }
.light-toggle.is-on .light-toggle-thumb { left: 13px; background: #facc15; }
.light-toggle:hover .light-toggle-track { filter: brightness(1.15); }
.light-toggle.is-off .light-toggle-icon { filter: grayscale(0.9) opacity(0.7); }

.summary-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; padding: 16px; background: var(--panel); border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 24px;
}
.summary-grid .swatch {
    display: inline-block; width: 12px; height: 12px; border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.2); vertical-align: middle; margin-right: 4px;
}

.cam { background: #000; border-radius: 6px; overflow: hidden; margin: -4px 0 12px; aspect-ratio: 4/3; position: relative; }
.cam video { width: 100%; height: 100%; display: block; object-fit: cover; background: #000; }
.cam .cam-img { width: 100%; height: 100%; display: block; object-fit: cover; background: #000; }
.cam video[data-status="connecting"]::before,
.cam video[data-status="error"]::before { content: ""; }
.cam::after {
    content: attr(data-empty);
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 12px; pointer-events: none;
}
/* Connecting / retrying overlay (visible until the first video frame). */
.cam video[data-status="connecting"] + .cam-fullscreen::before,
.cam video[data-status="retrying"]   + .cam-fullscreen::before { content: ""; }
.cam:has(video[data-status="connecting"])::after { content: "Connecting…"; color: var(--muted); }
.cam:has(video[data-status="retrying"])::after  { content: "Retrying…"; color: var(--warn); }
/* Permanently failed camera — give up gracefully so the rest of the dashboard isn't slowed by retries. */
.cam:has(video[data-status="unavailable"])::after {
    content: "📷 Camera unavailable · click to retry";
    color: var(--warn); font-weight: 600;
    background: rgba(0, 0, 0, 0.6); cursor: pointer; pointer-events: auto;
}
.cam[data-status="unavailable"] video { opacity: 0.3; }

.state-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.state {
    font-size: 11px; padding: 2px 8px; border-radius: 999px;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.05em;
}
.state-printing { color: var(--accent); border-color: var(--accent); }
.state-complete { color: var(--ok); border-color: var(--ok); }
.state-error    { color: var(--err); border-color: var(--err); }
.state-paused   { color: var(--warn); border-color: var(--warn); }
.state-preheating {
    color: var(--warn); border-color: var(--warn);
    background: rgba(245, 158, 11, 0.1);
    animation: pulse-warm 1.6s ease-in-out infinite;
}
@keyframes pulse-warm {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
    50%      { box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.25); }
}

.material-pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; padding: 2px 8px; border-radius: 999px;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
}
.material-pill .swatch {
    width: 12px; height: 12px; border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.2);
}
/* Per-nozzle (Left/Right) label badge inside a filament pill on dual-nozzle printers. */
.material-pill .noz-label {
    font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
    padding: 0 5px; border-radius: 999px; color: var(--muted);
    background: rgba(255,255,255,0.07); border: 1px solid var(--border);
}

.temps {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    column-gap: 10px;
    row-gap: 2px;
    margin: 0 0 12px;
    padding: 8px 10px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.temp-row { display: contents; }
.temp-row > * { padding: 2px 0; }
.temp-ic { color: var(--muted); display: inline-flex; align-items: center; }
.temp-label { color: var(--muted); }
.temp-cur { text-align: right; font-weight: 500; }
.temp-tgt { text-align: left; }
.temp-row.lifetime .temp-cur, .temp-row.lifetime .temp-label { color: var(--muted); font-weight: normal; }

.progress-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; font-size: 12px; }

.progress-pct { font-weight: 600; color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums; }

.time-table {
    width: 100%; margin-top: 8px;
    border-collapse: separate; border-spacing: 0;
    background: var(--panel-2);
    border: 1px solid var(--border); border-radius: 6px;
    overflow: hidden;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    table-layout: fixed;
}
.time-table th,
.time-table td { padding: 6px 8px; text-align: center; white-space: nowrap; }
.time-table th {
    font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    background: rgba(59, 130, 246, 0.08);
    border-bottom: 1px solid var(--border);
}
.time-table td { font-weight: 600; color: var(--text); }
.time-table th + th,
.time-table td + td { border-left: 1px solid var(--border); }
.finish-inline {
    color: var(--text); font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.small { font-size: 12px; }

.active { padding: 12px; background: var(--panel-2); border-radius: 6px; margin-bottom: 12px; }
.thumb { float: right; margin: 0 0 8px 12px; width: 90px; height: 90px; background: #000; border-radius: 4px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.active::after { content: ""; display: block; clear: both; }
.active .job-title { font-weight: 500; margin-bottom: 4px; }
.active .status-line { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.active .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.active .actions form { margin: 0; }
.idle { padding: 24px 0; text-align: center; }

.progress { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin: 6px 0 4px; }
.progress .bar { height: 100%; background: var(--accent); transition: width 0.4s ease; }

.queue-header { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.queue-list { margin: 0; padding-left: 20px; }
.queue-list li { padding: 4px 0; display: flex; align-items: center; gap: 8px; }
.queue-list li form { margin: 0 0 0 auto; }

.warn-tag { background: rgba(245, 158, 11, 0.15); color: var(--warn); border: 1px solid var(--warn); padding: 1px 6px; border-radius: 4px; font-size: 11px; }

.failures {
    margin-top: 12px; padding: 8px 10px;
    background: rgba(239, 68, 68, 0.08); border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 6px;
}
.failures .queue-header { color: var(--err); }
.failure { padding: 6px 0; border-top: 1px solid rgba(239, 68, 68, 0.2); }
.failure:first-of-type { border-top: 0; }
.failure-msg { font-family: ui-monospace, "Consolas", monospace; word-break: break-word; margin: 2px 0; }
.failure-actions { display: flex; gap: 6px; margin-top: 4px; }
.failure-actions form { margin: 0; }

.parts-table { width: 100%; border-collapse: collapse; }
.parts-table th, .parts-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.parts-table tr.row-latest { background: rgba(59, 130, 246, 0.06); }
.preheat-matrix th.num, .preheat-matrix td.num { min-width: 110px; }
.preheat-matrix td strong { font-size: 14px; }
.latest-star { color: var(--accent); font-size: 14px; margin-right: 4px; }

.file-slots { min-width: 400px; }
/* Three columns: label · button cluster · filename.
   Buttons sit immediately after the label so their horizontal position is
   independent of however long the filename is — keeps everything aligned
   across all three slot rows. The filename gets the remaining space and
   truncates with an ellipsis. */
.slot {
    display: grid; grid-template-columns: 56px auto minmax(0, 1fr);
    align-items: center; gap: 10px; padding: 3px 0;
    font-size: 12px;
}
.slot-label {
    color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
    font-size: 10px; font-weight: 600;
}
.slot.empty .slot-label { opacity: 0.5; }
.slot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-form { margin: 0; }
/* Two fixed grid columns — Open and Replace (or placeholder + Upload on
   empty slots). Each row's buttons align column-wise regardless of which
   ones are visible. Filename column to the right stretches into the space
   that used to belong to the Clear button. */
.slot-actions {
    display: inline-grid;
    grid-template-columns: repeat(2, 92px);
    gap: 6px; align-items: center;
}
/* The inline form that wraps the upload label has no layout purpose — make
   it vanish so its child button sits directly in the grid cell. */
.slot-actions .slot-form { display: contents; }
.slot-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 4px;
    height: 26px; width: 100%;
    padding: 0 6px; border-radius: 4px;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    cursor: pointer; font-size: 12px; line-height: 1; font-weight: 500;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    white-space: nowrap; box-sizing: border-box;
}
.slot-btn:hover:not(:disabled) { filter: brightness(1.12); }
.slot-btn:disabled { opacity: 0.5; cursor: progress; }
.slot-btn input[type="file"] { display: none; }
.slot-btn-icon { font-size: 14px; line-height: 1; }
.slot-btn-label { letter-spacing: 0.02em; }

/* Invisible placeholder that occupies a grid cell so the Open/Replace/Clear
   columns stay aligned across rows even when one of the buttons isn't
   rendered (e.g. an empty CAD slot has no Open/Clear). */
.slot-btn-placeholder {
    display: block;
    height: 26px;
    visibility: hidden;
}

/* Per-action accents so the three buttons are visually distinct.
   Override button.danger background (set globally elsewhere) for slot-btn
   so the Clear button isn't always-red — only on hover. */
.slot-btn.slot-btn-open    { color: var(--accent); border-color: var(--accent); }
.slot-btn.slot-btn-open:hover    { background: var(--accent); color: #fff; }
.slot-btn.slot-btn-replace { color: var(--muted); }
.slot-btn.slot-btn-replace:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
button.slot-btn.slot-btn-clear   { background: var(--panel-2); color: var(--err); border-color: var(--err); }
button.slot-btn.slot-btn-clear:hover { background: var(--err); color: #fff; }

/* Qty per plate input — keep input + save button on the same row, with the
   save button immediately to the right of the input. The cell is text-align
   right ("num") so we re-align the form's contents to the left so they don't
   pile up on the right edge. */
.qty-form {
    display: inline-flex; gap: 4px; align-items: center; margin: 0;
}
.qty-form input[type="number"] {
    width: 60px; padding: 4px 6px; font-size: 12px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
}
.qty-save {
    background: var(--panel-2); color: var(--muted);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 4px 8px; font-size: 13px; line-height: 1; cursor: pointer;
}
.qty-save:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.parts-table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.parts-table td form select { width: auto; min-width: 80px; display: inline-block; margin-right: 6px; }

section { margin-top: 24px; }
.desc { color: var(--muted); margin: 0 0 16px; }

/* Kind-aware form sections — show only when relevant. */
fieldset.kind-only {
    border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px;
    margin: 12px 0; background: var(--panel-2);
}
fieldset.kind-only legend { padding: 0 8px; color: var(--muted); font-size: 12px; }
/* Assemblies don't take direct cost/weight or supplier info — those roll up. */
body[data-part-kind="assembly"] .kind-non-printed,
body[data-part-kind="assembly"] .kind-buyable { display: none; }
/* Custom parts can derive cost from a gcode revision OR be entered manually,
   but they're never bought from a supplier — hide that fieldset. */
body[data-part-kind="custom"] .kind-buyable { display: none; }

/* BoM table tweaks. */
.bom-table { width: 100%; border-collapse: collapse; }
.bom-table th, .bom-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.bom-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.bom-table .num, .bom-table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bom-table tr.has-newer-rev { background: rgba(245, 158, 11, 0.05); }
.bom-table .qty-inline input { width: 90px; padding: 4px 6px; }
.bom-table .rev-pin {
    background: rgba(168, 85, 247, 0.15); color: #c084fc;
    border: 1px solid #a855f7; padding: 1px 6px; border-radius: 4px; font-size: 11px;
}
.bom-table .rev-stale {
    background: rgba(245, 158, 11, 0.15); color: var(--warn);
    border: 1px solid var(--warn); padding: 1px 6px; border-radius: 4px; font-size: 11px;
}
.kind-pill {
    display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.05em; border: 1px solid var(--border);
    background: var(--panel-2); color: var(--muted);
}
.kind-pill.kind-custom      { color: var(--accent); border-color: var(--accent); }
.kind-pill.kind-proprietary { color: var(--warn);   border-color: var(--warn); }
.kind-pill.kind-assembly    { color: var(--ok);     border-color: var(--ok); }
a.kind-pill { text-decoration: none; }
a.kind-pill:hover { filter: brightness(1.2); }
a.kind-pill.active { background: var(--accent); color: white; border-color: var(--accent); }
.parts-filter { display: flex; gap: 8px; align-items: center; margin: 12px 0 16px; flex-wrap: wrap; }
.parts-filter-form {
    display: flex; gap: 8px; align-items: center; margin: 12px 0 8px;
    flex-wrap: wrap;
}
.parts-filter-form select,
.parts-filter-form input[type="text"] {
    padding: 6px 9px; font-size: 13px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
}
.parts-filter-form .parts-search { min-width: 320px; flex: 1; max-width: 520px; }

.rollup-summary {
    display: flex; gap: 24px; padding: 12px 16px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
    margin-bottom: 16px;
}
.rollup-summary .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.rollup-summary .value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rollup-summary .value.warn { color: var(--warn); font-size: 13px; }

.part-edit { margin: 16px 0; padding: 8px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; }
.part-edit summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.part-edit summary:hover { color: var(--text); }
.part-edit form { padding-top: 12px; }

.source-list { list-style: none; padding: 0; margin: 8px 0; }
.source-list li { padding: 4px 0; }

.cad-hero {
    float: right; max-width: 320px; margin: 0 0 12px 16px;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px; text-align: center;
}
.cad-hero img {
    max-width: 100%; max-height: 280px; display: block; margin: 0 auto;
    background: white; border-radius: 4px;
}
.cad-hero-meta { margin-top: 6px; }

/* Schedule timeline */
.schedule {
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    padding: 12px; margin-top: 16px; overflow: hidden;
}
.sched-header { display: flex; align-items: stretch; margin-bottom: 8px; }
.sched-printer-col { width: 130px; flex-shrink: 0; padding-right: 12px; }
.sched-printer-name { font-weight: 600; }
.sched-track {
    flex: 1; position: relative; height: 56px;
    background: var(--panel-2); border-radius: 4px;
    border: 1px solid var(--border);
}
.sched-day-strip { height: 28px; background: transparent; border: 0; }
.day-marker {
    position: absolute; top: 0; bottom: 0;
    border-left: 1px solid var(--border);
}
.day-marker .day-label {
    position: absolute; top: 2px; left: 4px;
    font-size: 11px; color: var(--muted); white-space: nowrap;
}
.now-marker {
    position: absolute; top: 0; bottom: 0; width: 2px;
    background: var(--accent);
}
.sched-row { display: flex; align-items: stretch; margin-bottom: 8px; }
.sched-row:last-child { margin-bottom: 0; }
.sched-slot {
    position: absolute; top: 4px; bottom: 4px;
    background: rgba(59, 130, 246, 0.18);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 4px 8px;
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
    cursor: default;
    /* Short prints (e.g. 2h on a 7-day horizon = 1.2% = ~16px) get a minimum
       visible footprint so they never disappear behind a neighbour. */
    min-width: 14px;
}
.sched-slot.active {
    background: rgba(34, 197, 94, 0.25);
    border-color: var(--ok);
}
.sched-slot.offhours-finish {
    border-color: var(--warn);
    border-width: 2px;
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35) inset;
}
.sched-slot.offhours-finish::after {
    content: "⏰";
    position: absolute; top: 2px; right: 4px;
    font-size: 10px;
}
.offhours-band {
    position: absolute; top: 0; bottom: 0; pointer-events: none;
    background: repeating-linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.025) 0,
        rgba(255, 255, 255, 0.025) 6px,
        rgba(255, 255, 255, 0.06) 6px,
        rgba(255, 255, 255, 0.06) 12px
    );
}
.work-mark {
    position: absolute; top: 0; bottom: 0; width: 1px;
    pointer-events: none;
}
.work-mark-08 { background: rgba(34, 197, 94, 0.55); }   /* day starts */
.work-mark-18 { background: rgba(245, 158, 11, 0.55); }  /* day ends */
.work-mark::after {
    content: attr(title);
    position: absolute; top: -14px; transform: translateX(-50%);
    font-size: 9px; color: var(--muted); white-space: nowrap;
}
.sched-day-strip .day-marker { border-left-color: rgba(255,255,255,0.18); }

.sched-slot.pinned {
    background: rgba(168, 85, 247, 0.18);
    border-color: #a855f7;
}
.sched-slot.external {
    background: repeating-linear-gradient(
        45deg,
        rgba(152, 162, 179, 0.15) 0,
        rgba(152, 162, 179, 0.15) 4px,
        rgba(152, 162, 179, 0.05) 4px,
        rgba(152, 162, 179, 0.05) 8px
    );
    border-color: var(--muted);
    border-style: dashed;
    color: var(--muted);
}
.sched-slot.pinned::before {
    content: "📌"; position: absolute; top: 2px; left: 4px; font-size: 10px;
}
.pinned-tag { background: rgba(168, 85, 247, 0.15); color: #c084fc; border-color: #a855f7; }

.sched-slot.draggable {
    cursor: grab; user-select: none;
    -webkit-user-drag: none;
}
.sched-slot.draggable a { -webkit-user-drag: none; user-drag: none; pointer-events: none; }
.sched-slot.draggable a:hover { text-decoration: none; }
.sched-slot.dragging { cursor: grabbing; opacity: 0.85; box-shadow: 0 4px 12px rgba(0,0,0,0.4); z-index: 10; }
.sched-track.drop-target { box-shadow: inset 0 0 0 2px var(--accent); }
/* Vertical insertion line on the left edge of the slot we'll drop *before*. */
.sched-slot.slot-drop-before {
    box-shadow: -4px 0 0 0 var(--ok), 0 0 0 2px var(--ok);
    z-index: 5;
}
/* Dragged slot lights up green while a reorder is staged. */
.sched-slot.dragging.will-reorder {
    box-shadow: 0 0 0 2px var(--ok), 0 4px 12px rgba(0,0,0,0.4);
}

.dnd-tooltip {
    position: fixed; display: none; z-index: 1100;
    background: var(--panel); border: 1px solid var(--accent); border-radius: 6px;
    padding: 6px 10px; font-size: 12px; line-height: 1.4;
    box-shadow: 0 4px 14px rgba(0,0,0,0.45);
    pointer-events: none; white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.dnd-tooltip strong { color: var(--text); }
.dnd-tooltip .muted { color: var(--muted); }

/* Modal */
.modal-backdrop {
    display: none; position: fixed; inset: 0; z-index: 1000;
    background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px);
    align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    max-width: 460px; width: 92%; padding: 20px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.modal-body { color: var(--muted); margin-bottom: 16px; }
.modal-body strong { color: var(--text); }
.modal-body p { margin: 0 0 8px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.reorder-cell { display: flex; flex-direction: column; gap: 2px; padding: 2px 4px !important; }
.reorder-cell form { margin: 0; }
.reorder-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 22px; padding: 0; line-height: 1;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 3px; font-size: 14px; cursor: pointer;
}
.reorder-btn:hover { background: var(--accent); border-color: var(--accent); color: white; }
.drag-handle { cursor: grab; position: relative; }
.drag-handle::before {
    content: "⋮⋮"; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
    color: var(--muted); font-size: 14px; letter-spacing: -2px; line-height: 1;
}

tr.queue-row { cursor: grab; transition: background 0.1s; user-select: none; }
tr.queue-row.row-dragging { opacity: 0.45; cursor: grabbing; }
/* Insertion-point indicators — strong, full-width, can't be missed during drag. */
tr.queue-row.drop-above td:first-child { box-shadow: inset 4px 3px 0 -1px var(--accent); }
tr.queue-row.drop-above td { box-shadow: inset 0 3px 0 -1px var(--accent); }
tr.queue-row.drop-above td:last-child { box-shadow: inset -4px 3px 0 -1px var(--accent); }
tr.queue-row.drop-below td:first-child { box-shadow: inset 4px -3px 0 -1px var(--accent); }
tr.queue-row.drop-below td { box-shadow: inset 0 -3px 0 -1px var(--accent); }
tr.queue-row.drop-below td:last-child { box-shadow: inset -4px -3px 0 -1px var(--accent); }

.schedule-form {
    display: flex; gap: 6px; align-items: end; margin: 0;
}
.schedule-form label {
    margin: 0; font-size: 11px;
}
.schedule-form input[type="datetime-local"] {
    width: 165px; padding: 4px 6px; font-size: 12px;
}
.slot-text { font-size: 12px; }
.slot-text a { color: var(--text); }
.sched-overflow {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: var(--panel); padding: 2px 6px; border-radius: 4px;
}

/* Printer card drag-and-drop reordering on the dashboard. */
.printer-card .card-header[data-drag-handle] { cursor: grab; }
.printer-card .card-header[data-drag-handle]:active { cursor: grabbing; }
.printer-card .drag-grip {
    color: var(--muted); margin-right: 6px; font-size: 14px;
    letter-spacing: -2px; user-select: none;
}
.printer-card.dragging {
    opacity: 0.92; box-shadow: 0 12px 32px rgba(0,0,0,0.6);
    transform: rotate(0.5deg);
}
.printer-card-placeholder {
    border: 2px dashed var(--border);
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.06);
}

/* Fullscreen toggle on camera tiles. */
.cam-fullscreen {
    position: absolute; top: 8px; right: 8px;
    background: rgba(0,0,0,0.65); color: #fff;
    border: 1px solid rgba(255,255,255,0.25); border-radius: 4px;
    width: 32px; height: 32px; padding: 0;
    font-size: 16px; line-height: 1; cursor: pointer;
    opacity: 0.65; transition: opacity 0.15s, background 0.15s;
    z-index: 5;
}
.cam:hover .cam-fullscreen,
.cam:focus-within .cam-fullscreen { opacity: 1; }
.cam-fullscreen:hover { background: rgba(0,0,0,0.95); opacity: 1; }
.cam:fullscreen { aspect-ratio: auto; width: 100vw; height: 100vh; }
.cam:fullscreen video { object-fit: contain; }
.cam:fullscreen .cam-fullscreen { opacity: 1; }

/* Stacked form (used by Add/Edit printer pages). */
.stacked-form {
    display: flex; flex-direction: column; gap: 14px;
    max-width: 520px; background: var(--panel); padding: 18px;
    border: 1px solid var(--border); border-radius: 6px;
}
.stacked-form label {
    display: flex; flex-direction: column; gap: 4px; margin: 0;
}
.stacked-form label > span:first-child { font-weight: 600; font-size: 13px; }
.stacked-form input[type="text"],
.stacked-form input[type="url"] {
    width: 100%; padding: 7px 9px; font-size: 13px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
}
.stacked-form.inline-edit { max-width: 640px; }

/* Spool selector dropdown on the dashboard card. */
.spool-row { margin: 0 0 8px; }
.spool-select { position: relative; display: inline-block; }
.spool-select > summary {
    list-style: none; cursor: pointer; user-select: none;
    display: inline-block;
}
.spool-select > summary::-webkit-details-marker { display: none; }
.spool-popup {
    position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
    min-width: 260px; max-height: 320px; overflow-y: auto;
    background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    padding: 4px; display: flex; flex-direction: column; gap: 2px;
}
.spool-popup-row {
    background: transparent; color: var(--text); border: 0;
    padding: 6px 10px; border-radius: 4px; text-align: left;
    font-size: 13px; cursor: pointer; width: 100%;
    display: flex; align-items: center; gap: 6px; font-weight: 400;
}
.spool-popup-row:hover { background: var(--panel-2); }
.spool-popup-row.current { background: rgba(59, 130, 246, 0.15); }
.spool-popup-row.unload { color: var(--muted); font-style: italic; }
.spool-popup-link {
    text-decoration: none; color: var(--accent);
    border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px;
}

/* No-spool-loaded warning on the dashboard. */
.material-pill.warn-pill {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warn);
    border: 1px solid var(--warn);
    text-decoration: none;
}
.material-pill.warn-pill:hover { filter: brightness(1.2); text-decoration: none; }

/* Compact metric cells (est. weight / est. time / energy on the revisions
   table). One bold headline number per cell, optional secondary "plate" or
   breakdown line in muted small. Cells aren't full-width — keep numbers
   easy to scan vertically across rows. */
.metric-headline { font-weight: 600; font-size: 13px; white-space: nowrap; }
.metric-suffix { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: 1px; }
.metric-sub { color: var(--muted); font-size: 11px; line-height: 1.4; margin-top: 1px; }

/* Print column on parts/detail.html — stack Queue print + the check
   popovers vertically, all left-aligned in a single column so they sit
   directly beneath the dropdown rather than wrapping around it. */
.print-cell { vertical-align: top; }
.print-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.print-checks {
    display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
    margin-top: 4px;
}
.print-checks .check-popover { margin-left: 0; }

/* Home page — tile grid linking to major sections with one-glance stats. */
.home-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-top: 8px;
}
.home-tile {
    display: flex; flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px 22px;
    text-decoration: none;
    color: var(--text);
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
    min-height: 140px;
}
.home-tile:hover {
    background: var(--panel-2);
    border-color: var(--accent);
    text-decoration: none;
    transform: translateY(-1px);
}
.home-tile-icon { font-size: 36px; line-height: 1; margin-bottom: 8px; }
.home-tile-title {
    font-size: 13px; font-weight: 600;
    color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em;
}
.home-tile-stat {
    font-size: 26px; font-weight: 600; margin: 4px 0;
}
.home-tile-sub {
    font-size: 12px; color: var(--muted); line-height: 1.4;
}
.home-tile-alert {
    border-color: var(--warn);
    background: rgba(245, 158, 11, 0.08);
}
.home-tile-alert .home-tile-stat { color: var(--warn); }

/* Tool tiles (Diagnostics / Settings) — visually subordinate to the main
   work-area tiles since they're not where the user spends most of their
   time, but reachable from home without hunting through sub-navs. */
.home-tile-tool {
    background: transparent;
    min-height: 100px;
}
.home-tile-tool .home-tile-icon { font-size: 28px; }

/* Dev-server launcher tiles on /home. */
.dev-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 8px;
}
.dev-tile {
    display: flex; flex-direction: column; gap: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
}
.dev-tile-running { border-color: var(--ok); background: rgba(34, 197, 94, 0.04); }
.dev-tile-head { display: flex; gap: 12px; align-items: flex-start; }
.dev-tile-icon { font-size: 28px; line-height: 1; }
.dev-tile-name { font-weight: 600; font-size: 14px; }
.dev-tile-desc { line-height: 1.3; margin-top: 2px; }
.dev-tile-meta { display: flex; gap: 10px; align-items: center; }
.dev-status.running { color: var(--ok); font-weight: 600; }
.dev-status.stopped { color: var(--muted); }
.dev-tile-actions { display: flex; gap: 8px; align-items: center; }

/* Dashboard sub-nav — Schedule / Diagnostics / Settings demoted from the
   topbar to a quieter row inside the dashboard's page header. */
.dashboard-subnav {
    display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
    font-size: 13px;
}

/* Z-offset audit pill on each revision row. */
.z-audit {
    display: inline-block;
    margin-top: 4px;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px; font-weight: 600;
    letter-spacing: 0.04em;
    border: 1px solid currentColor;
}
.z-audit.ok { color: var(--ok); background: rgba(34, 197, 94, 0.08); }
.z-audit.warn { color: var(--warn); background: rgba(245, 158, 11, 0.10); }

/* Stock + buildable summary on parts/detail.html. */
.stock-bar {
    display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
    margin: 14px 0 18px; padding: 12px 16px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
}
.stock-block { min-width: 160px; }
.stock-qty { font-size: 20px; font-weight: 600; }
.stock-adjust {
    display: inline-flex; gap: 8px; align-items: end; flex-wrap: wrap;
    background: var(--panel-2); padding: 8px 10px; border-radius: 6px;
    border: 1px solid var(--border);
}
.stock-adjust label {
    display: inline-flex; flex-direction: column; gap: 2px; margin: 0;
    font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.stock-adjust input, .stock-adjust select {
    background: var(--panel); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 5px 7px; font-size: 13px;
}
.stock-adjust input[name="delta"] { width: 110px; }
.stock-adjust input[name="notes"] { width: 180px; }
/* State pills already styled — add the WO-specific colours. */
.state-planned   { color: var(--muted); border-color: var(--muted); }
.state-issued    { color: var(--accent); border-color: var(--accent); }
.state-completed { color: var(--ok); border-color: var(--ok); }
.state-cancelled { color: var(--muted); border-color: var(--muted); opacity: 0.7; }

/* Pre-flight popover for the overhang/wall check buttons. Lets the user
   tweak thresholds before kicking off a long-running analysis. */
.check-popover { display: inline-block; position: relative; margin-left: 6px; vertical-align: top; }
.check-popover > summary {
    list-style: none; cursor: pointer; user-select: none;
    display: inline-block; padding: 1px 0;
}
.check-popover > summary::-webkit-details-marker { display: none; }
.check-popover[open] > summary { color: var(--accent); }
.check-popover .check-form {
    position: absolute; top: calc(100% + 4px); left: 0; z-index: 60;
    min-width: 280px;
    display: flex; flex-direction: column; gap: 8px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    padding: 12px;
}
.check-popover .check-form label {
    display: flex; flex-direction: column; gap: 3px; margin: 0; font-size: 12px;
}
.check-popover .check-form input[type="number"] {
    width: 90px; padding: 5px 7px; font-size: 13px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
}
.check-popover .check-form p { margin: 0; }
.check-popover .check-form button { align-self: flex-start; }

/* Overhang report visualisations. */
.overhang-img {
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #000;
    image-rendering: pixelated;   /* keep red orphan cells crisp at zoom */
}
.overhang-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 10px;
}
.overhang-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    display: flex; flex-direction: column; gap: 6px;
}
.overhang-card img {
    max-width: 100%;
    border-radius: 4px;
    background: #000;
    image-rendering: pixelated;
}
.overhang-card-meta { font-size: 13px; }

.z-chart {
    display: flex; flex-direction: column; gap: 2px;
    max-height: 360px; overflow-y: auto;
    background: var(--panel);
    padding: 8px; border-radius: 6px; border: 1px solid var(--border);
}
.z-row { display: grid; grid-template-columns: 70px 1fr 70px; gap: 8px; align-items: center; font-size: 11px; }
.z-row .z-label { color: var(--muted); font-family: monospace; }
.z-row .z-bar {
    height: 10px;
    background: linear-gradient(to right, var(--warn), var(--err));
    border-radius: 2px; min-width: 1px;
}
.z-row .z-num { color: var(--text); font-family: monospace; text-align: right; }

/* Per-job post-print notes inline in the parts/print-history table. */
.job-notes { max-width: 320px; }
.job-notes > summary {
    list-style: none; cursor: pointer;
    padding: 2px 6px; border-radius: 4px;
}
.job-notes > summary::-webkit-details-marker { display: none; }
.job-notes > summary:hover { background: var(--panel-2); }
.job-notes-form {
    margin-top: 6px; display: flex; flex-direction: column; gap: 6px;
}
.job-notes-form textarea {
    width: 100%; min-width: 280px; padding: 6px 8px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
    font: inherit; resize: vertical;
}
.job-notes-actions { display: flex; gap: 6px; }

/* "Last time this part took..." line on the dashboard. */
.prev-actual { margin-top: 4px; }
.prev-actual .ok { color: var(--ok); }
.prev-actual .warn { color: var(--warn); }
.ok { color: var(--ok); }

