/* ─── Job history (js/modules/jobs/) ─────────────────────────────────────────
   The jobs list, one job's page, the machine page's Jobs panel and the Recent
   jobs / Material used widgets. Built on the rbac-view shell, table and card
   (rbac.css); status pills come from status.css. */

.jobs-view .jobs-shell {
    overflow-y: auto;
}

/* .btn sets a display, which would otherwise beat the hidden attribute. */
.jobs-shell [hidden],
.device-viewer-jobs [hidden],
.device-viewer-jobs-btn[hidden] {
    display: none !important;
}

/* Download everything: how far Fleet has got building the zip. */
.job-export {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs) var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
}

.job-export-label {
    color: var(--text-primary);
    font-weight: 600;
}

.job-export-count,
.job-export-pct {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.job-export .job-export-bar {
    flex: 1 1 160px;
    min-width: 120px;
    height: 6px;
    margin: 0;
}

.job-export--failed {
    border-color: var(--danger-border);
}

.job-export--failed .job-export-label {
    color: var(--color-error);
}

.jobs-shell > * {
    flex-shrink: 0;
}

.job-crumbs {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-bottom: 4px;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.job-crumbs a,
.job-facts a {
    color: var(--primary-light);
    text-decoration: none;
}

.job-crumbs a:hover,
.job-facts a:hover {
    text-decoration: underline;
}

.job-muted {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.job-num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ─── List ───────────────────────────────────────────────────────────────── */

.jobs-toolbar .jobs-search {
    flex: 1 1 220px;
}

.jobs-toolbar .jobs-search input {
    width: 100%;
}

.jobs-toolbar .form-group input[type="date"] {
    min-width: 150px;
}

.jobs-table tbody tr {
    cursor: pointer;
}

.jobs-table th[data-sort-key]:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
}

.jobs-name-cell a {
    color: var(--text-primary);
    font-weight: 600;
    text-decoration: none;
}

.jobs-name-cell a:hover {
    text-decoration: underline;
}

.jobs-alarm-count {
    margin-left: var(--space-xs);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-error-light);
    white-space: nowrap;
}

.jobs-nowrap {
    white-space: nowrap;
}

.jobs-more {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

/* ─── Job page: header and KPIs ──────────────────────────────────────────── */

.job-head-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.job-head-text {
    flex: 1 1 320px;
    min-width: 0;
}

.job-title {
    margin: 0 0 4px;
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.job-download-all {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    min-height: var(--control-height);
}

.job-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-sm);
}

.job-kpi {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--space-sm) var(--space-md);
    background: var(--grad-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    min-width: 0;
}

.job-kpi-label {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.job-kpi-value {
    font-family: var(--font-mono);
    font-size: var(--font-size-xl);
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.job-kpi-sub {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    min-height: 1em;
}

.job-kpi--warn .job-kpi-value {
    color: var(--color-warning-light);
}

.job-kpi--alarm {
    border-color: rgba(var(--error-rgb), 0.5);
}

.job-kpi--alarm .job-kpi-value {
    color: var(--color-error-light);
}

/* ─── Charts ─────────────────────────────────────────────────────────────── */

.job-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.job-section-title {
    margin: 0 0 var(--space-sm);
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-primary);
}

.job-charts-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-md);
    min-height: var(--control-height);
}

.job-hint {
    margin-left: auto;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.job-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
    gap: var(--space-sm);
}

.job-chart {
    background: var(--grad-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-sm) var(--space-md) var(--space-xs);
    min-width: 0;
}

.job-chart-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-sm);
}

.job-chart-title {
    margin: 0;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.job-chart-note {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    white-space: nowrap;
}

.job-chart-canvas {
    position: relative;
    height: 260px;
    touch-action: pan-y;
    cursor: crosshair;
}

.job-chart-select {
    position: absolute;
    background: rgba(var(--primary-light-rgb), 0.16);
    border-left: 1px solid var(--primary-light);
    border-right: 1px solid var(--primary-light);
    pointer-events: none;
}

/* ─── Timelapse and events ───────────────────────────────────────────────── */

.job-grid {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: var(--space-sm);
}

.job-timelapse-head,
.job-events-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.job-inline-field {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.job-timelapse-frame {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.job-timelapse-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.job-timelapse-controls {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

.job-timelapse-controls input[type="range"] {
    flex: 1;
    min-width: 80px;
    accent-color: var(--primary-light);
}

.job-timelapse-time {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    white-space: pre;
}

.job-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.job-chip {
    padding: 4px 10px;
    min-height: 32px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--font-size-xs);
    cursor: pointer;
}

.job-chip[aria-pressed="true"] {
    background: var(--bg-selected);
    border-color: var(--primary);
    color: var(--text-primary);
}

.job-events {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 420px;
    overflow-y: auto;
}

/* A machine's calibrations on its jobs page (jobs-list.js) */
.jobs-cals {
    margin-bottom: var(--space-md);
}

.jobs-cals > summary {
    cursor: pointer;
    width: fit-content;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.jobs-cals > summary:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* An event Bob can explain: its Ask Bob sits beside it, the answer beneath */
.job-event-item {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
}

.job-event-item > .job-event {
    flex: 1 1 0;
    min-width: 0;
}

.job-event-ask {
    margin: 6px var(--space-xs) 0;
}

.job-event-item > .bob-inline {
    flex: 1 0 100%;
    margin: 0 var(--space-xs) var(--space-sm);
}

.job-kpi-ask {
    align-self: flex-start;
}

.job-event {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    grid-template-areas: "time title" "time detail";
    column-gap: var(--space-sm);
    width: 100%;
    padding: 6px var(--space-xs);
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    border-bottom: 1px solid var(--border);
    color: var(--text-body);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.job-event:hover {
    background: var(--bg-hover);
}

.job-event:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
}

.job-event--alarm {
    border-left-color: var(--color-error);
}

.job-event--state {
    border-left-color: var(--primary);
}

.job-event-time {
    grid-area: time;
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.job-event-time small {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.job-event-title {
    grid-area: title;
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.job-event--alarm .job-event-title {
    color: var(--color-error-light);
}

.job-event-detail {
    grid-area: detail;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.job-event-empty {
    padding: var(--space-sm) 0;
}

.job-layer-canvas {
    position: relative;
    height: 200px;
}

.job-file-name {
    font-weight: 600;
    overflow-wrap: anywhere;
}

/* ─── Recent jobs (machine page panel, third-party view, widget) ─────────── */

.recent-jobs {
    list-style: none;
    margin: 0;
    padding: 0;
}

.recent-job + .recent-job {
    border-top: 1px solid var(--border);
}

.recent-job-link {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--space-xs) 4px;
    color: var(--text-body);
    text-decoration: none;
    border-radius: var(--radius-sm);
}

.recent-job-link:hover {
    background: var(--bg-hover);
}

.recent-job-link:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
}

.recent-job-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-xs);
}

.recent-job-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-job-facts {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.recent-job .dash-heater-progress {
    width: 100%;
    margin: 2px 0 0;
}

.recent-jobs-all {
    display: inline-block;
    margin-top: var(--space-xs);
    font-size: var(--font-size-sm);
}

/* The machine page's Jobs button and panel (device-viewer.js). */
.device-viewer-jobs-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    margin-right: var(--space-xs);
    padding: 4px 10px;
    min-height: 32px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--font-size-sm);
    cursor: pointer;
}

.device-viewer-jobs-btn:hover,
.device-viewer-jobs-btn[aria-expanded="true"] {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* The panel hangs from the toolbar, over the machine's screen. */
.device-viewer-toolbar {
    position: relative;
}

.device-viewer-jobs {
    position: absolute;
    top: calc(100% + 4px);
    right: var(--space-xs);
    z-index: var(--z-sticky);
    width: min(380px, calc(100% - 2 * var(--space-xs)));
    max-height: min(560px, 70vh);
    overflow-y: auto;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
}

.device-viewer-jobs h3 {
    margin: 0 0 var(--space-xs);
    font-size: var(--font-size-md);
    font-weight: 600;
}

/* ─── Widgets ────────────────────────────────────────────────────────────── */

.fw-recent-jobs {
    overflow-y: auto;
    min-height: 0;
}

/* A fit body gives every child an equal share; the totals line takes only its own height. */
.fw-body--fit > .fw-material-total {
    flex: 0 0 auto;
    margin-bottom: var(--space-xs);
}

.fw-material-total {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.fw-material-total strong {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
}

/* ─── Narrow screens ─────────────────────────────────────────────────────── */

@media (max-width: 900px) {
    .job-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .job-charts {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 600px) {
    .job-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .job-hint {
        display: none;
    }

    .job-event {
        grid-template-columns: 88px minmax(0, 1fr);
    }
}

/* --- Bob's insights (jobs/bob-findings.js): jobs list, job page, widget --- */

.bob-insights {
    background: var(--grad-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.bob-insights--widget {
    background: none;
    border: 0;
    padding: 0;
    margin: 0;
    height: 100%;
    overflow-y: auto;
}

.bob-insights-head {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.bob-insights-orb {
    flex-shrink: 0;
    line-height: 0;
}

.bob-insights-headtext {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.bob-insights-title {
    margin: 0;
    font-size: var(--font-size-md);
    color: var(--text-primary);
}

.bob-insights-sub,
.bob-insights-totals,
.bob-insights-empty {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin: 0;
}

.bob-insights-totals {
    font-family: var(--font-mono);
}

.bob-findings {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.bob-finding {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border: 1px solid var(--border);
    border-left: 3px solid var(--color-info);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
}

.bob-finding--critical { border-left-color: var(--color-error); }
.bob-finding--warning { border-left-color: var(--color-warning); }
.bob-finding--good { border-left-color: var(--color-success); }

.bob-finding-icon {
    flex-shrink: 0;
    line-height: 0;
    padding-top: 2px;
    color: var(--color-info);
}

.bob-finding--critical .bob-finding-icon { color: var(--color-error-light); }
.bob-finding--warning .bob-finding-icon { color: var(--color-warning-light); }
.bob-finding--good .bob-finding-icon { color: var(--color-success-light); }

.bob-finding-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bob-finding-title {
    margin: 0;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.bob-finding-detail,
.bob-finding-action {
    margin: 0;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    line-height: 1.45;
}

.bob-finding-action {
    color: var(--text-body);
}

.bob-finding-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    align-items: center;
    margin-top: 2px;
}

.bob-finding-link,
.bob-finding-ask {
    font-size: var(--font-size-xs);
    color: var(--primary-light);
    background: none;
    border: 0;
    padding: 2px 0;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.bob-finding-link:hover,
.bob-finding-ask:hover {
    color: var(--text-primary);
}

.bob-finding-link:focus-visible,
.bob-finding-ask:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.bob-review-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    flex-wrap: wrap;
    margin-bottom: var(--space-sm);
}

.bob-review-head .job-section-title {
    margin: 0;
}

@media (max-width: 600px) {
    .bob-insights-head {
        flex-wrap: wrap;
    }

    .bob-insights-ask {
        width: 100%;
    }
}

/* --- Traceability (jobs/job-trace.js): job page and QA passport --- */

.job-trace [hidden] {
    display: none !important;
}

.job-trace {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.job-trace-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.job-trace-head .job-section-title {
    margin: 0;
}

.job-trace-head--sub {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border);
}

.job-trace-subtitle,
.job-trace-formtitle {
    margin: 0;
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-primary);
}

.job-trace-formtitle {
    margin-bottom: var(--space-xs);
}

.job-trace-facts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-sm) var(--space-md);
    margin: 0;
}

.job-trace-facts dt {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.job-trace-facts dd {
    margin: 2px 0 0;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.job-trace-wide {
    grid-column: 1 / -1;
}

/* Keeps the table's screen-reader-only text inside its scroll box. */
.job-trace .rbac-table-wrap {
    position: relative;
}

.job-trace-serials {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.job-trace-serials li {
    padding: 2px 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-pill);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
}

.job-trace-notes {
    white-space: pre-wrap;
}

.job-trace-changed,
.job-trace-status {
    margin: 0;
}

.job-trace-status {
    min-height: 1em;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.job-trace-form {
    padding-top: var(--space-xs);
}

.job-trace-row {
    flex-wrap: wrap;
}

.job-trace-row > * {
    flex: 1 1 180px;
}

.job-trace-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

/* A calibration's status when the job started: text and colour both say it. */
.job-cal-status {
    display: inline-block;
    padding: 2px 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-secondary);
}

.job-cal-status--ok {
    color: var(--color-success-light);
    border-color: rgba(var(--success-rgb), 0.5);
}

.job-cal-status--warn {
    color: var(--color-warning-light);
    border-color: rgba(var(--warning-rgb), 0.5);
}

.job-cal-status--bad {
    color: var(--color-error-light);
    border-color: rgba(var(--error-rgb), 0.6);
    background: rgba(var(--error-rgb), 0.12);
}
