:root {
    --bg: #fafafa;
    --fg: #111;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #009D3E;       /* amitia logo green */
    --primary-dark: #007a30;
    --primary-bg: #e8f7ee;
    --grid-head: #f3f4f6;
    --error: #b91c1c;
    --error-bg: #fee2e2;
}

* { box-sizing: border-box; }
/* Always reserve the vertical scrollbar gutter so toggling tall content (e.g.
   the Gantt side panel on click) doesn't add/remove the scrollbar and shift the
   whole page sideways by its width. */
html { scrollbar-gutter: stable; }
html, body { margin: 0; padding: 0; }
body {
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--fg);
    background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "Cascadia Code", Menlo, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.ts { white-space: nowrap; font-variant-numeric: tabular-nums; }

.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 8px 16px;
    background: white; border-bottom: 2px solid var(--primary);
    position: sticky; top: 0; z-index: 10;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}
.topbar .brand { display: inline-flex; align-items: center; gap: 10px;
    font-weight: 600; color: var(--fg); }
.topbar .brand:hover { text-decoration: none; }
.topbar .brand .brand-logo { height: 24px; width: auto; display: block; }
.topbar .brand .brand-name { font-size: 15px; letter-spacing: .2px; color: var(--fg);
    padding-left: 11px; border-left: 1px solid var(--border); }
.topbar .crumbs { color: var(--muted); }
.topbar .crumbs a { color: var(--muted); }
.topbar .crumbs a:hover { color: var(--fg); }
.topbar .crumbs span { color: var(--fg); }
.topbar .base-dataset { font-size: 12px; color: var(--fg); padding: 2px 8px;
    background: var(--grid-head); border-radius: 4px; white-space: nowrap; }
.topbar .base-dataset code { font-size: 11.5px; }
.topbar .base-dataset .muted { color: var(--muted); }
.topbar .topbar-plan { display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; white-space: nowrap; }
.topbar .topbar-plan select { font-size: 12px; min-width: 240px; max-width: 440px; }
.topbar .topbar-plan .btn { padding: 1px 6px; line-height: 1.4; }
.topbar .version-tag { margin-left: auto; padding: 2px 8px; font-family: ui-monospace, Menlo, monospace;
    font-size: 11px; color: var(--muted); background: var(--grid-head); border-radius: 4px; }
code.flag { display: inline-block; margin-right: 4px; padding: 1px 6px; background: var(--primary-bg);
    color: var(--primary); border-radius: 3px; font-size: 11.5px; }
code.flag.flag-replaced { background: #fdecea; color: #b52b27; }
code.flag.flag-skipped { background: #fff4e5; color: #8a5a00; }
a.notif-dot { color: #d9534f; font-size: 15px; line-height: 1; text-decoration: none; }
a.notif-dot:hover { color: #b52b27; }
/* Cap identifier/marker cells in every grid table (link cells and the explicit
   .cell-trunc spans) so long orig_ids / custom markers can never blow out the
   layout. The full value is shown on hover via a title set by sections.js when
   the text is actually truncated. inline-block + max-width is reliable in auto
   table layout, unlike td-level wrapping. */
.cell-trunc, table.grid td a { display: inline-block; max-width: 420px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    vertical-align: bottom; }

.content { padding: 16px 24px 48px; max-width: min(1800px, 96vw); margin: 0 auto; }

h1 { font-size: 20px; margin: 8px 0 16px; }
h2 { font-size: 16px; margin: 24px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }

section + section { margin-top: 8px; }
.collapsible-section .section-head { display: flex; align-items: center; gap: 12px;
    cursor: pointer; padding: 2px 0; }
.collapsible-section .section-head h2 { border-bottom: none; margin: 0; }
.collapsible-section .section-head .section-summary { color: var(--muted); font-size: 13px; }
.collapsible-section .section-head .spacer { flex: 1; }
.collapsible-section .section-filter { padding: 3px 6px; border: 1px solid var(--border);
    border-radius: 4px; width: 200px; }
.collapsible-section .section-toggle { padding: 2px 8px; }
.collapsible-section .section-body[hidden] { display: none; }

.actions { margin: 16px 0; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.btn {
    display: inline-block; padding: 4px 10px; border: 1px solid var(--border);
    border-radius: 6px; background: white; color: var(--fg); font-size: 12.5px;
}
.btn:hover { text-decoration: none; background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: white; }
.btn.danger { color: var(--error); border-color: #f3c0c0; }
.btn.danger:hover { background: var(--error-bg); border-color: var(--error); color: var(--error); }
.btn.disabled { opacity: 0.45; pointer-events: none; cursor: not-allowed; }

dl.kv { display: grid; grid-template-columns: minmax(160px, max-content) 1fr; gap: 4px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

table.grid { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.grid th, table.grid td {
    padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left;
    white-space: nowrap;
}
table.grid td.wrap, table.grid th.wrap {
    white-space: normal;
    word-break: normal;
    overflow-wrap: anywhere;
    width: 40%;
    max-width: 0;     /* trick that forces the td to honour width on auto-layout tables */
}
/* io-grid: fixed layout + shared <colgroup> widths so the Inputs and Outputs
   tables compute identical column widths and line up vertically. */
table.grid.io-grid { table-layout: fixed; }
table.grid.io-grid td { overflow: hidden; text-overflow: ellipsis; }
table.grid th { background: var(--grid-head); font-weight: 600; }
table.grid tbody tr:hover { background: var(--primary-bg); }

/* Production-operation status row tints (text stays the default dark --fg). */
table.grid tbody tr.po-replaced { background: #fbdedd; }
table.grid tbody tr.po-replaced:hover { background: #f6cbc9; }
table.grid tbody tr.po-skipped { background: #ffe8cf; }
table.grid tbody tr.po-skipped:hover { background: #ffdab4; }

/* Data-set status row tints (locked = light blue, protected = light green). */
table.grid tbody tr.ds-locked { background: #e6effb; }
table.grid tbody tr.ds-locked:hover { background: #d3e3f7; }
table.grid tbody tr.ds-protected { background: #e6f6ec; }
table.grid tbody tr.ds-protected:hover { background: #d2eedd; }
/* A data set whose async deletion is in flight: greyed out and non-interactive. */
table.grid tbody tr.ds-deleting { background: #f0f0f0; color: var(--muted); opacity: .75; }
table.grid tbody tr.ds-deleting:hover { background: #ececec; }
table.grid tbody tr.ds-delete-error { background: #fbeaea; }
table.grid tbody tr.ds-delete-error:hover { background: #f6dada; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.badge.deleting { background: #eceff3; color: #5a6b7b; border: 1px solid #d4dbe3; }
.badge.error { background: var(--error-bg); color: var(--error); border: 1px solid #f3c0c0; }

ul.errors { background: var(--error-bg); border-left: 4px solid var(--error); padding: 10px 16px 10px 28px; }

.pager { display: flex; align-items: center; gap: 12px; margin: 8px 0; padding: 6px 8px;
    background: white; border: 1px solid var(--border); border-radius: 6px; }
.pager .spacer { flex: 1; }
.pager .pager-nav { display: inline-flex; align-items: center; gap: 6px; }
.pager .btn.disabled { opacity: 0.4; pointer-events: none; }
.pager form.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.pager select { padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px; background: white; }

/* Gantt page */
.gantt-toolbar {
    display: flex; flex-wrap: nowrap; overflow-x: auto;
    align-items: center; gap: 8px 12px; margin: 4px 0 8px;
    padding: 6px 8px; background: white; border: 1px solid var(--border); border-radius: 6px;
}
.gantt-toolbar > * { flex: 0 0 auto; }
.gantt-toolbar #gantt-status {
    flex: 0 0 320px;
    min-width: 320px;
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
}
.gantt-toolbar .spacer { flex: 1; }
.gantt-toolbar #visible-range { font-size: 12px; }
.filter-banner { padding: 6px 10px; margin: 0 0 8px; background: #fef3c7; border: 1px solid #f59e0b;
    border-radius: 6px; font-size: 13px; }
.gantt-toolbar .preset-group { display: inline-flex; gap: 2px; }
.gantt-toolbar .preset-group .btn { padding: 4px 8px; border-radius: 0; border-right-width: 0; }
.gantt-toolbar .preset-group .btn:first-child { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.gantt-toolbar .preset-group .btn:last-child  { border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-right-width: 1px; }
.gantt-toolbar .preset-group .btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.gantt-wrap { position: relative; }
.gantt-canvas {
    width: 100%; height: calc(100vh - 220px); min-height: 480px;
    border: 1px solid var(--border); border-radius: 6px; background: white;
}
.gantt-loader {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; background: rgba(255,255,255,0.78);
    border: 1px solid var(--border); border-radius: 6px;
    z-index: 40; cursor: progress;
}
.gantt-loader[hidden] { display: none; }
.gantt-loader .text { font-size: 13px; color: var(--muted); }
.gantt-loader .spinner {
    width: 36px; height: 36px; border: 4px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.gantt-side {
    margin-top: 12px; padding: 12px; background: white;
    border: 1px solid var(--border); border-radius: 6px; min-height: 60px;
}
.gantt-side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.gantt-side h3, .gantt-side h4 { margin: 0 0 6px; font-size: 14px; }
#gantt-side-close { padding: 0 8px; font-size: 16px; line-height: 1.2; }

#page-spinner {
    position: fixed; inset: 0; z-index: 1000;
    display: none; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.55);
    cursor: progress;
}
#page-spinner.active { display: flex; }
#page-spinner .spinner {
    width: 48px; height: 48px; border: 5px solid var(--border);
    border-top-color: var(--primary, #2563eb); border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

/* Login page */
.login-card { max-width: 340px; margin: 72px auto; padding: 28px 28px 24px;
    background: white; border: 1px solid var(--border);
    border-top: 3px solid var(--primary); border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .07); }
.login-card .login-logo { display: block; width: 200px; max-width: 100%; margin: 4px auto 10px; }
.login-card h1 { font-size: 14px; font-weight: 500; text-align: center;
    color: var(--muted); margin: 0 0 20px; letter-spacing: .4px; }
.login-form label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.login-form input { display: block; width: 100%; box-sizing: border-box;
    margin-top: 5px; padding: 8px 10px; font-size: 14px;
    border: 1px solid var(--border); border-radius: 6px; }
.login-form input:focus { outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg); }
.login-form .btn { margin-top: 8px; width: 100%; padding: 9px; font-size: 14px; }
.login-error { background: var(--error-bg); color: var(--error);
    border: 1px solid #f3c0c0; border-radius: 6px; padding: 8px 10px;
    font-size: 13px; margin-bottom: 16px; text-align: center; }
.topbar .auth-box { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.topbar .auth-user { color: var(--muted, #5a6b7b); }
.topbar .auth-box a { color: var(--muted); }
.topbar .auth-box a:hover { color: var(--fg); }
.topbar .auth-box .logout-form { margin: 0; display: flex; }

/* Empty / message states (e.g. dataset with no production plan) */
.empty-state { max-width: 560px; margin: 56px auto; text-align: center; }
.empty-state h1 { font-size: 20px; margin: 0 0 12px; }
.empty-state p { margin: 0 0 16px; }

/* Long PO/JC/variant names: ellipsis in tables, wrap in detail lists */
.gantt-side .trunc { display: inline-block; max-width: 260px; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.gantt-side .kv dd { overflow-wrap: anywhere; }
/* JCs-in-view panel filter + pager */
.jc-list-controls { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; flex-wrap: wrap; }
.jc-list-controls input[type="search"] { padding: 4px 8px; border: 1px solid var(--border);
    border-radius: 6px; width: 200px; font-size: 13px; }
.jc-list-controls .pager-info { color: var(--muted); font-size: 12.5px; }

/* Datasets list: expandable per-plan rows */
.plans-cell { white-space: nowrap; }
.plan-toggle { background: none; border: none; cursor: pointer; padding: 0;
    font: inherit; color: var(--primary); }
.plan-toggle:hover { text-decoration: underline; }
.plan-count-static { color: var(--fg); }
.plan-count-static.muted { color: var(--muted); }
/* Fixed-width caret slot (empty for single/zero-plan rows) keeps every count
   digit at the same x, so the column lines up whether or not it can expand. */
.plans-cell .caret { display: inline-block; width: 1.1em; text-align: center; color: var(--muted); }
tr.plan-subrow > td { background: var(--grid-head); padding: 8px 12px 10px; }
.plan-subtable { width: auto; min-width: 50%; margin: 0; }
.plan-subtable th, .plan-subtable td { background: white; }
.badge.latest { background: var(--primary-bg); color: var(--primary-dark); border: 1px solid #bfe6cc; }

/* src/plain_console/static/style.css — utilization heatmap */
.util-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.util-toolbar .preset-group { display: inline-flex; gap: 2px; }
.util-toolbar .preset-group .btn { padding: 4px 8px; border-radius: 0; border-right-width: 0; }
.util-toolbar .preset-group .btn:first-child { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.util-toolbar .preset-group .btn:last-child { border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-right-width: 1px; }
.util-toolbar .preset-group .btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.util-toolbar .preset-group .btn:disabled { opacity: .45; cursor: not-allowed; }
/* Segmented flags control inside a filter (.pager) row, e.g. Plan steps. */
.pager .preset-group { display: inline-flex; gap: 2px; vertical-align: middle; }
.pager .preset-group .btn { padding: 4px 8px; border-radius: 0; border-right-width: 0; }
.pager .preset-group .btn:first-child { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.pager .preset-group .btn:last-child { border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-right-width: 1px; }
.pager .preset-group .btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.util-range-label { font-variant-numeric: tabular-nums; }
/* The grid wrapper shrink-wraps to its content, so scrollbars appear only when
   the grid genuinely exceeds the viewport (not when it would fit). The area is
   a positioned block so the loader overlay has a region to center in even
   before any rows exist (first load). */
.util-grid-area { position: relative; min-height: 200px; }
.util-grid-wrap { display: inline-block; max-width: 100%; overflow: auto; max-height: calc(100vh - 210px); vertical-align: top; }
table.grid.util-grid { border-collapse: collapse; }
table.grid.util-grid th, table.grid.util-grid td { border: 1px solid #ddd; font-size: 11px; }
table.grid.util-grid thead th { position: sticky; top: 0; background: #fafafa; z-index: 2; white-space: nowrap; padding: 3px 6px; text-align: center; }
.util-yearhead { background: #f0f0f0; font-weight: 600; }
.util-cell { min-width: 36px; height: 20px; padding: 0; text-align: center; color: #fff; font-variant-numeric: tabular-nums; text-shadow: 0 0 2px rgba(0, 0, 0, .4); }
.util-cell-link { display: block; padding: 0 2px; line-height: 20px; color: inherit; text-decoration: none; cursor: pointer; }
.util-cell-link:hover { text-decoration: underline; }
.util-rowhead { position: sticky; left: 0; background: #fafafa; z-index: 1; white-space: nowrap; padding: 2px 8px; text-align: left; min-width: 150px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.util-resname { color: #2563eb; }
.util-rowhead:hover .util-resname { text-decoration: underline; }
table.grid.util-grid thead th.util-rowhead { z-index: 4; text-align: left; vertical-align: middle; }
/* The Σ column stays visible on the right, mirroring the sticky resource column;
   header and body share width + alignment so the sticky column lines up. */
.util-summary { position: sticky; right: 0; background: #fafafa; z-index: 1; font-weight: 600; text-align: right; padding: 0 8px; min-width: 52px; font-variant-numeric: tabular-nums; }
table.grid.util-grid thead th.util-sumhead { position: sticky; right: 0; top: 0; background: #fafafa; z-index: 4; text-align: right; vertical-align: middle; min-width: 52px; padding: 0 8px; }
/* Deep-linked resource: spotlight it by fading the OTHER rows; the target row
   keeps its exact colours and values. A light accent on the (non-data) name
   cell anchors the row while scrolling. */
.util-grid.util-spotlight tbody tr:not(.util-row-hi) { opacity: .3; }
.util-grid.util-spotlight tbody tr:not(.util-row-hi):hover { opacity: 1; }
.util-row-hi .util-rowhead { background: #fff3cd; box-shadow: inset 3px 0 0 #f59e0b; font-weight: 600; }
/* Reuses the shared .spinner ring (also used by the Gantt and #page-spinner). */
.util-loader { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: rgba(255, 255, 255, .78); z-index: 40; cursor: progress; }
.util-loader[hidden] { display: none; }
.util-loader .text { font-size: 13px; color: var(--muted); }
.util-loader .spinner { width: 36px; height: 36px; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.9s linear infinite; }

/* ---- Nesting placement visualization (inline SVG + hover) ---- */
.nesting-holder { overflow-x: auto; padding: 6px 0; }
.nesting-holder svg { max-width: 100%; height: auto; }
/* Hover behaviour: dim the unrelated pieces, accent the ones from the same JobCard. */
.nesting-holder [data-piece-orig-id] { transition: opacity .08s ease; }
.nesting-holder .nesting-dim { opacity: .25; }
.nesting-holder .nesting-active { stroke: var(--fg); stroke-width: 1.2; }
.nesting-tip {
    /* Above the lightbox overlay (z 100) so the hover tip shows on the enlarged SVG too. */
    position: absolute; z-index: 2000; pointer-events: none;
    background: #111; color: #fff; padding: 6px 8px; border-radius: 4px;
    font-size: 12px; line-height: 1.35; max-width: 320px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}
.nesting-tip[hidden] { display: none; }

/* Nesting: enlarged lightbox + Outputs-row highlight on piece hover. */
.nesting-holder { cursor: zoom-in; }
.nesting-row-hi { outline: 2px solid rgba(0, 0, 0, .15); }
.nesting-lightbox {
    position: fixed; inset: 0; z-index: 100; display: flex;
    align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .6); padding: 24px;
}
.nesting-lightbox-inner {
    position: relative; background: #fff; border-radius: 6px; padding: 16px;
    max-width: 96vw; max-height: 92vh; overflow: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .4);
}
.nesting-lightbox-close { position: sticky; top: 0; float: right; margin-left: 8px; }

/* Nesting: DXF-on-click panel inside the enlarged lightbox (2D items). */
.nesting-dxf-panel { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.nesting-dxf-cap { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.nesting-dxf-img svg { max-width: 90vw; max-height: 50vh; height: auto; }

/* Caption under the full-page spinner (slow async actions, e.g. PDF generation). */
#page-spinner { flex-direction: column; gap: 14px; }
.spinner-label { font-size: 14px; color: var(--fg); background: rgba(255,255,255,.85); padding: 4px 10px; border-radius: 4px; }
