: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; }
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: 200px;
    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; }
