/* ==========================================================================
   EngMan 2.0 - design system
   Local-only, no external fonts or CDNs (uses the system font stack).
   ========================================================================== */

:root {
    /* Neutrals (slate) */
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-soft: #334155;
    --muted: #64748b;

    /* Brand (indigo) */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --primary-border: #c7d2fe;

    /* Accents on the dark shell */
    --shell: #0f172a;
    --shell-2: #1e293b;
    --shell-fg: #e2e8f0;
    --shell-muted: #94a3b8;

    /* Semantic */
    --green: #15803d;
    --green-bg: #dcfce7;
    --amber: #b45309;
    --amber-bg: #fef3c7;
    --red: #b91c1c;
    --red-bg: #fee2e2;
    --blue: #1d4ed8;
    --blue-bg: #dbeafe;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-pill: 999px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .08);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .10);
    --ring: 0 0 0 3px rgba(79, 70, 229, .25);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text-soft);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    color: var(--text);
    letter-spacing: -0.01em;
}

h1 { font-size: 26px; }
h2 { font-size: 19px; }

a {
    color: var(--primary);
}

/* ---- Top shell ---------------------------------------------------------- */

.topbar {
    min-height: 60px;
    padding: 0 24px;
    background: var(--shell);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 28px;
}

.brand a {
    color: #fff;
    text-decoration: none;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 9px;
}

.brand a::before {
    content: "";
    width: 11px;
    height: 11px;
    border-radius: 3px;
    background: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .25);
}

.main-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
}

.main-nav a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--shell-fg);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: background .15s, color .15s;
}

.main-nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.main-nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
}

.main-nav a.active {
    color: #fff;
    background: var(--primary);
}

.user-area {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    color: var(--shell-fg);
    font-size: 14px;
}

.logout-form {
    display: inline;
}

/* ---- Project context bar ----------------------------------------------- */

.project-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 8px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.project-nav-title {
    color: var(--primary);
    font-weight: 700;
    font-size: 14px;
    margin-right: 12px;
    padding: 4px 10px;
    background: var(--primary-soft);
    border-radius: var(--radius-pill);
    white-space: nowrap;
}

.project-nav a {
    color: var(--text-soft);
    text-decoration: none;
    font-size: 14px;
    padding: 7px 9px;
    border-radius: var(--radius-pill);
    transition: background .15s, color .15s;
    white-space: nowrap;
}

.project-nav a:hover {
    background: var(--surface-2);
    color: var(--text);
}

.project-nav a.active {
    background: var(--primary);
    color: #fff;
}

/* ---- Layout ------------------------------------------------------------- */

.page-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.page-header h1 { margin: 0; }
.page-header h2 { margin: 0; }
.page-header p { margin: 4px 0 0; }

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin-top: 0;
}

/* ---- Stat cards --------------------------------------------------------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

.stat-title {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-number {
    font-size: 30px;
    font-weight: 700;
    color: var(--text);
}

.card-attention {
    border-left: 4px solid var(--amber);
}

/* Coloured stat cards (import preview) */
.stat-green { color: var(--green); }
.stat-blue { color: var(--blue); }
.stat-orange { color: var(--amber); }
.stat-red { color: var(--red); }

.stat-accent-green { border-top: 3px solid var(--green); }
.stat-accent-blue { border-top: 3px solid var(--blue); }
.stat-accent-orange { border-top: 3px solid var(--amber); }
.stat-accent-red { border-top: 3px solid var(--red); }

/* ---- Tables ------------------------------------------------------------- */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 14px;
}

th, td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    background: var(--surface-2);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-strong);
}

tbody tr {
    transition: background .12s;
}

tbody tr:hover td {
    background: var(--primary-soft);
}

td a {
    font-weight: 600;
    text-decoration: none;
}

td a:hover {
    text-decoration: underline;
}

/* ---- Buttons ------------------------------------------------------------ */

.button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    padding: 9px 15px;
    text-decoration: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: background .15s, box-shadow .15s, border-color .15s,
        transform .05s;
}

.button:hover {
    background: var(--surface-2);
    border-color: var(--muted);
}

.button:active {
    transform: translateY(1px);
}

.button-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 1px 2px rgba(79, 70, 229, .3);
}

.button-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #fff;
}

.button-danger {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
}

.button-danger:hover {
    background: #991b1b;
    border-color: #991b1b;
    color: #fff;
}

.button-small {
    padding: 5px 11px;
    font-size: 12px;
}

/* ---- Icon buttons ------------------------------------------------------- */

.actions-col {
    white-space: nowrap;
    width: 1%;
    text-align: right;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-soft);
    text-decoration: none;
    padding: 5px 9px;
    font-size: 15px;
    line-height: 1;
    transition: background .15s, border-color .15s, color .15s;
}

.icon-button:hover {
    background: var(--primary-soft);
    border-color: var(--primary-border);
    color: var(--primary);
}

.icon-danger {
    color: var(--red);
    border-color: #fecaca;
}

.icon-danger:hover {
    background: var(--red-bg);
    border-color: #fca5a5;
    color: var(--red);
}

/* ---- Forms -------------------------------------------------------------- */

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-soft);
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}

textarea {
    min-height: 120px;
}

.form-field {
    margin-bottom: 16px;
    max-width: 640px;
}

.form-actions {
    margin-top: 22px;
    display: flex;
    gap: 10px;
}

.search-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.search-form input,
.search-form select {
    max-width: 280px;
    width: auto;
    flex: 1 1 180px;
}

/* ---- Badges ------------------------------------------------------------- */

.badge {
    display: inline-block;
    border-radius: var(--radius-pill);
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    background: #e2e8f0;
    color: var(--text-soft);
    white-space: nowrap;
}

/* semantic status badges */
.badge-approved, .badge-green {
    background: var(--green-bg);
    color: var(--green);
}

.badge-review {
    background: var(--amber-bg);
    color: var(--amber);
}

.badge-blocked {
    background: var(--red-bg);
    color: var(--red);
}

.badge-info {
    background: var(--blue-bg);
    color: var(--blue);
}

.badge-draft {
    background: var(--primary-soft);
    color: var(--primary-hover);
}

.badge-neutral {
    background: #e2e8f0;
    color: var(--muted);
}

/* ---- Alerts ------------------------------------------------------------- */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 14px;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--green-bg);
    color: #166534;
    border-color: #bbf7d0;
}

.alert-danger, .alert-error {
    background: var(--red-bg);
    color: #991b1b;
    border-color: #fecaca;
}

.alert-warning {
    background: var(--amber-bg);
    color: #92400e;
    border-color: #fde68a;
}

/* ---- Login -------------------------------------------------------------- */

.login-card {
    max-width: 400px;
    margin: 72px auto;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.login-card h1 {
    margin-top: 0;
    margin-bottom: 4px;
}

.login-card label {
    margin-top: 14px;
}

.login-card input {
    margin-bottom: 4px;
}

.login-card .button {
    width: 100%;
    justify-content: center;
    margin-top: 22px;
    padding: 11px;
}

/* ---- Detail grids ------------------------------------------------------- */

.detail-grid {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 12px 16px;
}

.detail-label {
    font-weight: 600;
    color: var(--muted);
}

.muted {
    color: var(--muted);
}

.cell-error {
    color: var(--red);
    font-size: 12px;
    margin-top: 4px;
    white-space: normal;
}

/* Register bar: filters, or the bulk actions while rows are ticked, plus
   the Columns button on the right (one row above the table). */
.register-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
    transition: background .15s, border-color .15s;
}

.register-bar .search-form {
    flex: 1;
}

.bulk-actions {
    display: none;
    flex: 1;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.bulk-actions select {
    width: auto;
    min-width: 170px;
}

.bulk-count {
    color: var(--primary);
    margin-right: 4px;
}

.register-bar.has-selection {
    background: var(--primary-soft);
    border-color: var(--primary-border);
}

.register-bar.has-selection .bulk-actions {
    display: flex;
}

.register-bar.has-selection .search-form {
    display: none;
}

.check-col {
    width: 1%;
    text-align: center;
    white-space: nowrap;
}

.check-col input {
    width: auto;
    cursor: pointer;
}

/* ---- Wide registers ----------------------------------------------------- */

/* Registers show every field of the item, so they use the full window
   width and scroll horizontally inside the card. Header row, row checkbox
   and tag column stay pinned while scrolling. */
.page-wide {
    max-width: none;
}

.register-scroll {
    padding: 0;
    overflow: auto;
    max-height: calc(100vh - 260px);
    min-height: 240px;
}

/* Register pages are exactly one window tall: title, filters and toolbar
   stay put and the table fills the rest, so the table is the only thing
   that scrolls (one vertical scrollbar, horizontal one always in view).
   Short or narrow windows fall back to normal page scrolling below. */
body.register-page {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.register-page .page-container {
    flex: 1;
    min-height: 0;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding-top: 20px;
    padding-bottom: 16px;
}

body.register-page .page-container > form[method="post"] {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

body.register-page .page-header {
    margin-bottom: 14px;
}

body.register-page .card,
body.register-page .register-bar,
body.register-page .alert {
    margin-bottom: 12px;
}

body.register-page .register-scroll {
    flex: 1;
    min-height: 0;
    max-height: none;
    margin-bottom: 0;
}

@media (max-width: 980px), (max-height: 560px) {
    body.register-page {
        height: auto;
        overflow: visible;
        display: block;
    }

    body.register-page .register-scroll {
        max-height: calc(100vh - 120px);
        min-height: 240px;
    }
}

.register-table {
    font-size: 13px;
}

.register-table th,
.register-table td {
    padding: 8px 10px;
    white-space: nowrap;
}

.register-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.register-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.register-table .wrap {
    white-space: normal;
    min-width: 180px;
    max-width: 360px;
}

.register-table .sticky-col,
.register-table .sticky-col-2 {
    position: sticky;
    z-index: 1;
    background: var(--surface);
}

.register-table .sticky-col {
    left: 0;
    width: 40px;
    min-width: 40px;
}

.register-table .sticky-col-2 {
    left: 40px;
    box-shadow: inset -1px 0 0 var(--border-strong);
}

/* Actions stay visible at the right edge (edit/delete, inline Save). */
.register-table .actions-col {
    position: sticky;
    right: 0;
    z-index: 1;
    background: var(--surface);
    box-shadow: inset 1px 0 0 var(--border-strong);
}

.register-table thead .actions-col {
    z-index: 3;
    background: var(--surface-2);
}

.register-table tbody tr:hover .actions-col,
.register-table tbody tr:hover .sticky-col,
.register-table tbody tr:hover .sticky-col-2 {
    background: var(--primary-soft);
}

.register-table thead .sticky-col,
.register-table thead .sticky-col-2,
.register-table thead .sticky-col-first {
    z-index: 3;
    background: var(--surface-2);
}

.register-table .unit {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}

/* Column picker (register_columns.js), right end of the bulk toolbar. */
.column-picker {
    position: relative;
    margin-left: auto;
}

.column-picker:empty {
    display: none;
}

.column-picker-button::after {
    content: "";
    width: 6px;
    height: 6px;
    margin-left: 2px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
}

.column-picker-button.is-filtered {
    border-color: var(--primary-border);
    background: var(--primary-soft);
    color: var(--primary);
}

.column-picker-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 20;
    width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .15);
}

.column-picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}

.column-picker-list {
    max-height: 340px;
    overflow-y: auto;
    padding: 6px;
}

.column-picker-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
}

.column-picker-list label:hover {
    background: var(--surface-2);
}

.column-picker-list input {
    width: auto;
    margin: 0;
    accent-color: var(--primary);
}

.link-button {
    border: 0;
    background: none;
    padding: 0;
    color: var(--primary);
    font: inherit;
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
}

.link-button:hover {
    text-decoration: underline;
}

/* Inline row edit (register_inline.js). */
.register-table tr.row-editing td {
    background: var(--primary-soft);
    border-top: 1px solid var(--primary-border);
    border-bottom: 1px solid var(--primary-border);
    vertical-align: top;
}

.register-table tr.row-editing input,
.register-table tr.row-editing select {
    min-width: 110px;
    padding: 5px 8px;
    font-size: 13px;
}

.register-table tr.row-editing .cell-pair > select,
.register-table tr.row-editing .cell-pair > input {
    display: inline-block;
    width: auto;
}

.register-table tr.row-editing .num input {
    min-width: 70px;
    text-align: right;
}

.register-table tr.row-editing .wrap input {
    min-width: 200px;
}

.register-table tr.row-editing .cell-error {
    max-width: 220px;
}

.register-table tr.row-editing .actions-col .button + .button {
    margin-left: 4px;
}

.register-table tr.row-saved td {
    animation: row-saved 1.8s ease-out;
}

@keyframes row-saved {
    from { background: var(--green-bg); }
    to { background: var(--surface); }
}

/* ---- Responsive --------------------------------------------------------- */

@media (max-width: 980px) {
    .topbar {
        flex-wrap: wrap;
        gap: 12px;
        padding: 12px 16px;
    }

    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .page-container {
        padding: 18px 16px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 600px) {
    .card-grid {
        grid-template-columns: 1fr;
    }

    .search-form {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form input,
    .search-form select {
        flex: 0 0 auto;  /* the 180px basis would become the height */
        max-width: none;
    }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 4px 0;
    }

    .detail-label {
        margin-top: 10px;
    }
}

/* ==========================================================
   MODERN DASHBOARD
   ========================================================== */

.dashboard-hero {
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 30px;
    padding: 38px 42px;
    margin-bottom: 22px;
    border-radius: 16px;
    color: #ffffff;
    background:
        radial-gradient(circle at 88% 15%, rgba(74, 144, 226, 0.35), transparent 27%),
        radial-gradient(circle at 70% 100%, rgba(66, 153, 225, 0.18), transparent 33%),
        linear-gradient(125deg, #111c31 0%, #1a3359 55%, #1b4c75 100%);
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
}

.dashboard-hero::after {
    content: "";
    position: absolute;
    width: 290px;
    height: 290px;
    right: -110px;
    top: -145px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 50%;
    box-shadow:
        0 0 0 30px rgba(255, 255, 255, 0.025),
        0 0 0 60px rgba(255, 255, 255, 0.02);
}

.dashboard-hero-content,
.dashboard-hero-actions {
    position: relative;
    z-index: 1;
}

.dashboard-hero h1 {
    margin: 8px 0 10px;
    font-size: 32px;
    letter-spacing: -0.7px;
    color: #ffffff;
}

.dashboard-hero p {
    max-width: 610px;
    margin: 0;
    color: rgba(255, 255, 255, 0.76);
    font-size: 15px;
    line-height: 1.6;
}

.eyebrow {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #a8d5ff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.3px;
}

.eyebrow-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #50d890;
    box-shadow: 0 0 0 5px rgba(80, 216, 144, 0.14);
}

.dashboard-hero-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.button-hero-primary,
.button-hero-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 17px;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.button-hero-primary {
    color: #10233d;
    border-color: #ffffff;
    background: #ffffff;
}

.button-hero-primary:hover {
    color: #10233d;
    background: #e8f4ff;
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.15);
}

.button-hero-secondary {
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.08);
}

.button-hero-secondary:hover {
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.65);
    background: rgba(255, 255, 255, 0.16);
}

.button-icon {
    font-size: 20px;
    font-weight: 400;
    line-height: 12px;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #35b46b;
    box-shadow: 0 0 0 4px rgba(53, 180, 107, 0.12);
}

/* Project cards */

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(355px, 1fr));
    gap: 20px;
}

.project-card {
    overflow: hidden;
    border: 1px solid #e1e7ef;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 7px 22px rgba(15, 23, 42, 0.055);
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease,
        border-color 0.2s ease;
}

.project-card:hover {
    border-color: #b7c9df;
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.11);
    transform: translateY(-4px);
}

.project-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 22px 22px 18px;
}

.project-identity {
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
}

.project-icon {
    display: flex;
    width: 43px;
    height: 43px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 11px;
    color: #2d6da3;
    background: linear-gradient(145deg, #e5f3ff, #d8ebfa);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.4px;
}

/* the badge shows the full project number, so it needs to grow */
.project-icon-number {
    width: auto;
    min-width: 43px;
    padding: 0 12px;
    font-size: 15px;
    letter-spacing: 0.3px;
}

.project-card h2 {
    overflow: hidden;
    max-width: 250px;
    margin: 0;
    color: #17263c;
    font-size: 17px;
    letter-spacing: -0.15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-open-icon {
    display: flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border: 1px solid #e1e8f0;
    border-radius: 9px;
    color: #5c728b;
    background: #f8fafc;
    font-size: 21px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.project-open-icon:hover {
    border-color: #2b78b5;
    color: #ffffff;
    background: #2b78b5;
}

.project-client {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 22px 20px;
}

.client-label {
    color: #98a5b5;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.8px;
}

.client-name {
    overflow: hidden;
    color: #53647a;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    margin: 0 22px;
    padding: 15px 0;
    border-top: 1px solid #e9edf2;
    border-bottom: 1px solid #e9edf2;
}

.metric {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-left: 15px;
    border-left: 1px solid #e9edf2;
}

.metric:first-child {
    padding-left: 0;
    border-left: none;
}

.metric-value {
    color: #1f334c;
    font-size: 22px;
    font-weight: 700;
}

.metric-label {
    color: #8190a3;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

/* ---- Project classification chips ---- */

.project-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 22px 14px;
}

.chip {
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    color: var(--primary-hover);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .2px;
    white-space: nowrap;
}

.chip-scope { background: #0f172a; color: #fff; }
.chip-plant { background: #e2e8f0; color: #334155; }
.chip-tech { background: var(--amber-bg); color: var(--amber); }
.chip-product { background: var(--blue-bg); color: var(--blue); }

/* ---- Capacity + open-changes (two identical labelled columns) ---- */

.project-metrics-2 { grid-template-columns: repeat(2, 1fr); }

.project-attention {
    min-height: 83px;
    padding: 18px 22px;
}

.attention-title {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 10px;
    color: #66788e;
    font-size: 12px;
    font-weight: 700;
}

.attention-icon {
    display: inline-flex;
    width: 16px;
    height: 16px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #ffffff;
    background: #8090a3;
    font-size: 11px;
    font-weight: 800;
}

.attention-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.modern-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 650;
}

.modern-badge-warning {
    color: #a45b05;
    background: #fff4df;
}

.modern-badge-success {
    color: #22794b;
    background: #e6f7ed;
}

.badge-check {
    margin-right: 5px;
    font-weight: 900;
}

.project-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 22px;
    border-top: 1px solid #e9edf2;
    background: #fbfcfe;
}

.project-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #648096;
    font-size: 12px;
    font-weight: 650;
}

.project-open-button {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: #236ca6;
    font-size: 13px;
    font-weight: 750;
    text-decoration: none;
}

.project-open-button:hover {
    color: #164d7a;
}

.project-open-button span {
    font-size: 17px;
    transition: transform 0.2s ease;
}

.project-open-button:hover span {
    transform: translateX(3px);
}

/* Empty dashboard */

.empty-projects {
    max-width: 720px;
    margin: 55px auto;
    padding: 48px 35px;
    border: 1px solid #e2e9f1;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.05);
    text-align: center;
}

.empty-project-icon {
    display: flex;
    width: 58px;
    height: 58px;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
    border-radius: 16px;
    color: #3776a9;
    background: #e8f3fc;
    font-size: 28px;
    font-weight: bold;
}

.empty-projects h2 {
    margin: 0 0 10px;
    color: #1c2d44;
    font-size: 22px;
}

.empty-projects p {
    max-width: 510px;
    margin: 0 auto 24px;
    color: #6f8094;
    line-height: 1.6;
}

.empty-project-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.empty-projects .button-hero-primary {
    color: #ffffff;
    border-color: #2563eb;
    background: #2563eb;
}

.empty-projects .button-hero-primary:hover {
    color: #ffffff;
    background: #1d4ed8;
}

/* Responsive dashboard */

@media (max-width: 850px) {
    .dashboard-hero {
        align-items: flex-start;
        flex-direction: column;
        padding: 30px;
    }

    .dashboard-hero-actions {
        width: 100%;
    }

    .dashboard-hero-actions .button {
        flex: 1;
    }
}

@media (max-width: 560px) {
    .dashboard-hero {
        padding: 24px;
    }

    .dashboard-hero h1 {
        font-size: 27px;
    }

    .dashboard-hero-actions,
    .empty-project-actions {
        flex-direction: column;
    }

    .dashboard-hero-actions .button,
    .empty-project-actions .button {
        width: 100%;
    }

    .project-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   Mass & heat balance - stream cards
   ========================================================================== */

.stream-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.stream-card {
    --accent: #64748b;
    --accent-soft: #f1f5f9;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    scroll-margin-top: 16px;
}

.stream-card:target {
    box-shadow: var(--ring), var(--shadow-md);
}

/* Stream medium groups: red = vapour/steam, blue = brine/slurry,
   green = make-up/cooling/sealing/wash water, slate = other. */
.accent-red    { --accent: #dc2626; --accent-soft: #fef2f2; }
.accent-blue   { --accent: #2563eb; --accent-soft: #eff6ff; }
.accent-green  { --accent: #16a34a; --accent-soft: #f0fdf4; }
.accent-slate  { --accent: #64748b; --accent-soft: #f1f5f9; }

/* Excluded from print: faded on screen, hidden in print. */
.stream-card.is-no-print {
    opacity: .6;
    border-left-style: dashed;
}

/* ---- Header ---- */

.stream-head {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px 24px;
    align-items: center;
    padding: 16px 20px 12px;
    background: linear-gradient(to right, var(--accent-soft), var(--surface) 60%);
    border-bottom: 1px solid var(--border);
}

.stream-id {
    display: flex;
    align-items: center;
    gap: 12px;
}

.stream-no {
    font-size: 26px;
    font-weight: 800;
    line-height: 1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    min-width: 56px;
}

.stream-id-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.medium-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.medium-pill b {
    font-weight: 800;
    margin-right: 3px;
}

.stream-chip {
    display: inline-block;
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    margin-right: 4px;
}

.stream-route {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.route-node {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.route-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.route-name {
    font-weight: 600;
    color: var(--text);
}

.route-arrow {
    color: var(--accent);
    font-size: 20px;
    font-weight: 700;
}

.stream-desc {
    grid-column: 1 / -1;
    margin: 0;
    color: var(--text-soft);
}

/* No-print toggle switch */
.stream-print-toggle { margin: 0; }

.print-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--text-soft);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.print-switch:hover { border-color: var(--border-strong); }

.switch-track {
    position: relative;
    width: 30px;
    height: 18px;
    border-radius: var(--radius-pill);
    background: var(--green);
    transition: background .15s;
}

.switch-knob {
    position: absolute;
    top: 2px;
    left: 14px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    transition: left .15s;
}

.print-switch.off { color: var(--red); }
.print-switch.off .switch-track { background: var(--border-strong); }
.print-switch.off .switch-knob { left: 2px; }

/* ---- KPI strip ---- */

.stream-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-bottom: 1px solid var(--border);
}

.kpi {
    display: flex;
    flex-direction: column;
    padding: 10px 20px;
    border-right: 1px solid var(--border);
}

.kpi:last-child { border-right: 0; }

.kpi-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}

.kpi-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.kpi-value small {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

/* ---- Body ---- */

.stream-body {
    display: grid;
    grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.2fr) minmax(0, .8fr);
}

.stream-section {
    padding: 14px 20px 16px;
    border-right: 1px solid var(--border);
}

.stream-section:last-child { border-right: 0; }

.section-title {
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.section-title + table + .section-title,
.props-table + .section-title {
    margin-top: 16px;
}

.phase-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.phase {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.phase-head {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    color: var(--text);
    font-size: 13px;
}

.phase-units {
    font-weight: 500;
    font-size: 11px;
    color: var(--muted);
}

.phase-na {
    border-style: dashed;
    background: var(--surface-2);
}

.phase-na .phase-head {
    color: var(--muted);
    background: transparent;
}

.phase-empty {
    margin: 0;
    padding: 18px 10px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    font-style: italic;
}

/* Compact numeric tables inside the card */
.mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.mini-table th,
.mini-table td {
    padding: 4px 10px;
    border: 0;
    border-bottom: 1px solid var(--surface-2);
    background: none;
    text-align: left;
}

.mini-table th {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: none;
    letter-spacing: 0;
}

.mini-table .num { text-align: right; white-space: nowrap; }
.mini-table .pct { color: var(--muted); width: 1%; }
.mini-table tr.is-zero td { color: var(--muted); }

.mini-table tfoot td {
    border-top: 1px solid var(--border);
    border-bottom: 0;
    font-weight: 700;
    color: var(--text);
    background: var(--surface-2);
}

.props-table td:first-child { color: var(--text-soft); }
.props-table th,
.props-table td { padding-left: 0; }
.props-table .unit { width: 1%; }

.unit {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.na {
    color: #cbd5e1;
    font-style: italic;
    font-weight: 400;
}

.kv-list { margin: 0; }

.kv {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 0;
    border-bottom: 1px solid var(--surface-2);
    font-size: 13px;
}

.kv dt { color: var(--text-soft); }

.kv dd {
    margin: 0;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.kv-na dt,
.kv-na dd { color: #cbd5e1; font-weight: 400; }

.stream-pipe { background: var(--surface-2); }

.soon-badge {
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: var(--radius-pill);
    background: var(--amber-bg);
    color: var(--amber);
    font-size: 10px;
    letter-spacing: .02em;
    text-transform: none;
}

.pipe-hint {
    margin: 10px 0 0;
    font-size: 12px;
    color: var(--muted);
}

.stream-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}

.line-chip {
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    text-decoration: none;
    font-weight: 600;
}

.stream-empty { text-align: center; }

@media (max-width: 1150px) {
    .stream-body { grid-template-columns: 1fr 1fr; }
    .stream-composition {
        grid-column: 1 / -1;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 760px) {
    .stream-head { grid-template-columns: 1fr; }
    .stream-kpis { grid-template-columns: 1fr 1fr; }
    .kpi:nth-child(2) { border-right: 0; }
    .kpi:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
    .stream-body,
    .phase-grid { grid-template-columns: 1fr; }
    .stream-section { border-right: 0; border-bottom: 1px solid var(--border); }
}

/* Print / PDF: only streams without "No print". */
@media print {
    .topbar,
    .project-nav,
    .stream-filters,
    .case-bar,
    .stoff-card,
    .header-actions,
    .stream-print-toggle,
    .alert,
    .stream-card.is-no-print {
        display: none !important;
    }

    body { background: #fff; }
    .page-container { max-width: none; padding: 0; }

    .stream-card {
        box-shadow: none;
        break-inside: avoid;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .stream-body { grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.2fr) minmax(0, .8fr); }
    .stream-composition { grid-column: auto; border-right: 1px solid var(--border); border-bottom: 0; }
}

.chip-row { display: flex; gap: 4px; }
.chip-row .stream-chip { margin-right: 0; }

.button:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Project phase stepper (dashboard card) --------------------------- */

.phase-stepper {
    display: flex;
    align-items: flex-start;
    list-style: none;
    margin: 0;
    padding: 0 22px 16px;
}

.phase-step {
    position: relative;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

/* connector to the previous step */
.phase-step + .phase-step::before {
    content: "";
    position: absolute;
    top: 12px;
    right: calc(50% + 15px);
    left: calc(-50% + 15px);
    height: 2px;
    background: var(--border);
}

.phase-step.phase-done + .phase-step::before { background: var(--green); }

.phase-dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
}

.phase-done .phase-dot { background: var(--green); color: #fff; }

.phase-current .phase-dot {
    background: var(--surface);
    border: 2px solid var(--primary);
    box-shadow: var(--ring);
}

.phase-core {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
}

.phase-next .phase-dot {
    background: var(--surface-2);
    border: 2px solid var(--border-strong);
    color: var(--border-strong);
}

.phase-code {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    color: var(--muted);
}

.phase-done .phase-code { color: var(--green); }
.phase-current .phase-code { color: var(--primary); }

.detail-phase { max-width: 420px; margin: 0 0 16px; }
.detail-phase .phase-stepper { padding: 0; }

.chip-phase { background: var(--primary-soft); color: var(--primary-hover); font-weight: 700; }

/* ---- Recent activity feed ---------------------------------------------- */

.activity-section { margin-top: 24px; }

.activity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.activity-header h2 { margin: 0; }

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

.activity-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 2px;
    border-bottom: 1px solid var(--border);
}

.activity-row:last-child { border-bottom: none; }

.activity-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.activity-dot { background: var(--muted); }
.activity-created, .activity-po-created { background: var(--green); }
.activity-updated { background: var(--blue); }
.activity-deleted, .activity-po-deleted { background: var(--red); }
.activity-imported { background: var(--primary); }
.activity-phase-changed,
.activity-status-changed,
.activity-po-status-changed { background: var(--amber); }

.activity-text a { color: var(--text); font-weight: 600; text-decoration: none; }
.activity-text a:hover { color: var(--primary); }
.activity-text strong { color: var(--text); }

.activity-action {
    color: var(--muted);
    font-size: 12px;
    margin: 0 6px;
}

.activity-meta {
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.activity-empty { padding: 16px 2px; }

/* ---- Change log --------------------------------------------------------- */

/* All filters on one row: the search box takes the spare width, the
   dropdowns share the rest; it only wraps when the window is too narrow. */
.changelog-filters { flex-wrap: wrap; gap: 8px; }
.changelog-filters input,
.changelog-filters select { flex: 1 1 0; min-width: 118px; max-width: 170px; }
.changelog-filters .filter-search { flex: 2 1 0; min-width: 170px; max-width: 320px; }
.changelog-filters .button { flex: none; }
.filter-date { display: inline-flex; flex: none; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.changelog-filters .filter-date input { flex: none; width: 135px; min-width: 0; max-width: none; }

.changelog-table td { vertical-align: top; }

.log-level {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.log-level-high { background: var(--primary-soft); color: var(--primary-hover); }
.log-level-item { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.log-action { font-weight: 600; }
.log-action-created, .log-action-po-created { color: var(--green); }
.log-action-deleted, .log-action-po-deleted { color: var(--red); }

.log-changes { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.log-changes li + li { margin-top: 2px; }
.log-field { color: var(--muted); }
.log-old { color: var(--red); text-decoration: line-through; }
.log-new { color: var(--green); font-weight: 600; }

/* Pager below a register table: total and page x / n, page links, jump. */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 10px;
    font-size: 13px;
}
.pager-info { color: var(--muted); }
.pager-info b { color: var(--text); }
.pager-links { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pager-link {
    min-width: 30px;
    height: 30px;
    padding: 0 8px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-variant-numeric: tabular-nums;
}
a.pager-link:hover { border-color: var(--primary-border); background: var(--primary-soft); }
.pager-link.is-current { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.pager-link.is-disabled { color: var(--border-strong); }
.pager-gap { padding: 0 4px; color: var(--muted); }
.pager-jump label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.pager-jump input { width: 72px; padding: 4px 8px; }
body.register-page .pager { flex: none; }

/* ---- Mass & heat balance import ---- */

.compact-table th,
.compact-table td {
    padding: 6px 10px;
    font-size: 13px;
}

.import-help { margin: 0; padding-left: 18px; }
.import-help li { margin-bottom: 6px; }

.import-stats { grid-template-columns: repeat(5, 1fr); }

.import-table td { vertical-align: top; }
.import-table tr.import-unchanged td { color: var(--muted); }
.import-table tr.import-error td { background: var(--red-bg); }

.import-warning {
    color: var(--amber);
    font-size: 13px;
}

.import-changes summary {
    cursor: pointer;
    color: var(--blue);
    font-size: 13px;
    font-weight: 600;
}

.change-table { margin-top: 4px; width: auto; }

.change-table td {
    padding: 2px 8px 2px 0;
    border: 0;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    background: none;
}

.change-table .old { color: var(--muted); text-decoration: line-through; }
.change-table .new { color: var(--text); font-weight: 600; }

@media (max-width: 760px) {
    .import-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Mass & heat balance cases ---- */

.case-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin: 0 0 14px;
}

.case-bar-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

.case-tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow);
}

.case-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    color: var(--text-soft);
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none;
}

.case-tab:hover { background: var(--surface-2); color: var(--text); }

.case-tab.is-active {
    background: var(--primary);
    color: #fff;
}

.case-count {
    min-width: 22px;
    padding: 0 7px;
    border-radius: var(--radius-pill);
    background: var(--border);
    color: var(--text-soft);
    font-size: 11.5px;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.case-tab.is-active .case-count { background: rgba(255, 255, 255, .22); color: #fff; }

.case-add { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.case-add select { width: auto; padding: 5px 8px; font-size: 13px; }

.case-delete { margin-left: auto; color: var(--red); }

.case-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    vertical-align: middle;
}

/* ---- Stoff codes card (collapsible, inline rows) ---- */

.stoff-card { padding: 0; overflow: hidden; }

.stoff-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.stoff-summary::-webkit-details-marker { display: none; }
.stoff-summary:hover { background: var(--surface-2); }

.stoff-chevron {
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform .15s ease;
}

.stoff-card[open] .stoff-chevron { transform: rotate(45deg); }

.stoff-title { font-weight: 700; color: var(--text); white-space: nowrap; }

.stoff-count {
    padding: 0 8px;
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    line-height: 20px;
}

.stoff-hint { font-size: 13px; }

.stoff-body {
    border-top: 1px solid var(--border);
    padding: 14px 18px 12px;
    background: var(--surface-2);
}

.stoff-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.stoff-upload { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.stoff-upload input[type="file"] { width: auto; font-size: 13px; }

.stoff-scroll {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.stoff-table { min-width: 1100px; margin: 0; }
.stoff-table th,
.stoff-table td { white-space: nowrap; }
.stoff-table .group-start { border-left: 2px solid var(--border-strong); }
.stoff-table td.na { color: #cbd5e1; }
.stoff-table td.js-empty-row { white-space: normal; }

.stoff-table tr.row-editing td {
    background: var(--primary-soft);
    border-top: 1px solid var(--primary-border);
    border-bottom: 1px solid var(--primary-border);
    vertical-align: top;
}

.stoff-table tr.row-editing input,
.stoff-table tr.row-editing select {
    width: 100%;
    min-width: 72px;
    padding: 4px 6px;
    font-size: 12.5px;
}

.stoff-table tr.row-editing td.wide input { min-width: 150px; }

.stoff-table tr.row-editing .actions-col .button + .button { margin-left: 4px; }

.stoff-table tr.row-saved td { animation: row-saved 1.8s ease-out; }

.stoff-note { margin: 8px 0 0; font-size: 12.5px; }


/* ---- Help page --------------------------------------------------------- */

.help-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.help-toc {
    position: sticky;
    top: 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 10px;
    box-shadow: var(--shadow);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.help-toc-title {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 0 10px 8px;
}

.help-toc a {
    color: var(--text-soft);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.help-toc a:hover {
    background: var(--primary-soft);
    color: var(--primary-hover);
}

.help-content { min-width: 0; }

.help-section {
    scroll-margin-top: 20px;
    max-width: 860px;
    font-size: 14.5px;
    line-height: 1.65;
}

.help-section h2 {
    font-size: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}

.help-section h3 {
    font-size: 15px;
    margin: 22px 0 8px;
    color: var(--text);
}

.help-section p { margin: 0 0 12px; }
.help-section ul { margin: 0 0 12px; padding-left: 20px; }
.help-section li { margin-bottom: 6px; }
.help-section .badge { margin: 1px 0; }

.help-section code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 13px;
}

/* numbered steps with round counters */
.help-steps {
    list-style: none;
    counter-reset: step;
    padding: 0;
    margin: 0 0 12px;
}

.help-steps li {
    counter-increment: step;
    position: relative;
    padding-left: 40px;
    margin-bottom: 12px;
    min-height: 26px;
}

.help-steps li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    color: var(--primary-hover);
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-callout {
    background: var(--primary-soft);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin: 14px 0;
}

.help-callout-warn {
    background: var(--amber-bg);
    border-left-color: var(--amber);
}

.help-tip {
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-soft);
}

.help-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 12px;
    margin: 14px 0;
}

.help-feature {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

.help-feature h4 { margin: 0 0 4px; font-size: 14px; }
.help-feature p { margin: 0; font-size: 13.5px; color: var(--text-soft); }

.help-table { margin: 6px 0 14px; }
.help-table td:first-child { white-space: nowrap; width: 1%; }

.help-defs {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 18px;
    margin: 0 0 12px;
}

.help-defs dt { font-weight: 600; color: var(--text); }
.help-defs dd { margin: 0; color: var(--text-soft); }

.help-faq {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    background: var(--surface);
}

.help-faq summary {
    cursor: pointer;
    font-weight: 600;
    padding: 10px 14px;
}

.help-faq summary:hover { color: var(--primary-hover); }
.help-faq[open] summary { border-bottom: 1px solid var(--border); }
.help-faq p { padding: 10px 14px 0; }

.help-footer { margin-top: 18px; }

@media (max-width: 900px) {
    .help-layout { grid-template-columns: 1fr; }
    .help-toc {
        position: static;
        max-height: none;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .help-toc-title { width: 100%; }
    .help-defs { grid-template-columns: 1fr; gap: 2px; }
    .help-defs dd { margin-bottom: 8px; }
}

/* ---- Project register (no row checkbox, so the number sticks at 0) ----- */

.register-table .sticky-col-first {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    box-shadow: inset -1px 0 0 var(--border-strong);
}
.register-table .chip-list { display: flex; flex-wrap: wrap; gap: 4px; }
.register-bar .search-form { flex: 1; }

/* ---- Project overview: status beside the title, one-line counters ----- */

.title-with-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}
.title-with-badge h1 { margin: 0; }

.counter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
}

.counter {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
}
.counter:hover { border-color: var(--primary-border); color: var(--primary); }
.counter-value {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.nowrap { white-space: nowrap; }

/* ---- Procurement ------------------------------------------------------- */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Wide tables scroll inside their card, never the page. */
.table-scroll { overflow-x: auto; }

.card-head-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.card-head-row h2 { margin-bottom: 4px; }

.po-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0 16px;
}
.po-field-wide { grid-column: 1 / -1; }
.po-submit { margin: 0 0 24px; }

/* "Ready to order": tickable tag chips */
.ready-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.ready-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    cursor: pointer;
    font-size: 13px;
    transition: border-color .15s, background .15s;
}
.ready-item:hover { border-color: var(--primary-border); }
.ready-item:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.ready-item input { margin: 0; accent-color: var(--primary); }
.ready-number { font-weight: 600; }

/* Item pickers (static/procurement/po_picker.js) */
.picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 20px;
}

.picker {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.picker-head h3 { margin: 0; font-size: 15px; }

.picker-count {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary-hover);
    background: var(--primary-soft);
    padding: 2px 10px;
    border-radius: var(--radius-pill);
}

.picker-hint { margin: 2px 0 8px; font-size: 13px; }

.picker-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: text;
}
.picker-box:focus-within { border-color: var(--primary); box-shadow: var(--ring); }

.picker-search {
    flex: 1 1 140px;
    min-width: 120px;
    border: 0 !important;
    outline: 0;
    box-shadow: none !important;
    padding: 4px 2px !important;
    background: transparent;
    font: inherit;
}

.chip-picked {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 4px 3px 10px;
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    color: var(--primary-hover);
    font-size: 13px;
    font-weight: 600;
}
.chip-picked.is-new { animation: chip-in .15s ease-out; }

@keyframes chip-in {
    from { transform: scale(.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.chip-pipe { background: var(--blue-bg); border-color: #bfdbfe; color: var(--blue); }

.chip-length {
    width: 64px;
    padding: 1px 4px !important;
    border: 1px solid currentColor !important;
    border-radius: 6px;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    text-align: right;
}
.chip-unit { font-weight: 500; }

.chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}
.chip-remove:hover, .chip-remove:focus-visible { background: rgba(15, 23, 42, .12); }

.picker-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    margin: 10px 0 6px;
}

.picker-filters { display: flex; flex-wrap: wrap; gap: 6px; }

.pill {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--text-soft);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.pill:hover { border-color: var(--primary-border); }
.pill.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pill-count { opacity: .7; margin-left: 2px; }

.picker-add-all {
    border: 0;
    background: none;
    color: var(--primary);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}
.picker-add-all:hover { text-decoration: underline; }

.picker-list {
    list-style: none;
    margin: 0;
    padding: 4px;
    height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.picker-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.picker-option:hover,
.picker-option.is-active { background: var(--surface); box-shadow: var(--shadow); }
.picker-option.is-active { outline: 2px solid var(--primary-border); }

.picker-main { font-weight: 700; color: var(--text); white-space: nowrap; }
.picker-sub {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}
.picker-custom .picker-main { color: var(--primary); }

.picker-type {
    flex-shrink: 0;
    width: 78px;
    padding: 2px 0;
    border-radius: var(--radius-pill);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .03em;
    text-align: center;
    text-transform: uppercase;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
}
.picker-type-equipment { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.picker-type-valve { background: var(--green-bg); color: var(--green); border-color: transparent; }
.picker-type-instrument { background: var(--blue-bg); color: var(--blue); border-color: transparent; }
.picker-type-line { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

.picker-state {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    color: var(--amber);
}
.picker-state-ordered { color: var(--green); }

.picker-empty { padding: 24px 12px; text-align: center; color: var(--muted); font-size: 13px; }

.picker-errors { margin: 6px 0 0 18px; padding: 0; }

@media (max-width: 600px) {
    .picker-grid { grid-template-columns: 1fr; }
    .picker-list { height: 220px; }
}

/* ---- Info cards: label-over-value groups side by side ------------------- */

.info-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px 32px;
}

.info-group,
.info-group dl,
.info-text {
    margin: 0;
}

.info-group-title {
    margin: 0 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.info-group dt,
.info-text dt {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.info-group dd {
    margin: 2px 0 12px;
    overflow-wrap: anywhere;
}
.info-group dd:last-child { margin-bottom: 0; }

.info-text {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.info-text dd { margin: 2px 0 14px; }
.info-text dd:last-child { margin-bottom: 0; }
.info-text dd p:first-child { margin-top: 0; }
.info-text dd p:last-child { margin-bottom: 0; }

.info-wide {
    margin-top: 16px;
}

/* ---- Change request form and affected-tag picker ------------------------ */

.change-form .form-field { max-width: none; }

.form-row {
    display: grid;
    gap: 0 16px;
}
.form-row-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.change-add-submit {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 14px;
}
.change-add-submit .form-field {
    margin-bottom: 0;
    min-width: 240px;
}

/* ---- Equipment specification ------------------------------------------ */

/* Source colours: manual blue, MHB green, calculated violet. */
.spec-src-manual { --spec-bg: var(--blue-bg); --spec-fg: var(--blue); }
.spec-src-mhb { --spec-bg: var(--green-bg); --spec-fg: var(--green); }
.spec-src-calculated { --spec-bg: #f3e8ff; --spec-fg: #7e22ce; }

.spec-chip {
    display: inline-block;
    padding: 0 8px;
    border-radius: var(--radius-pill);
    background: var(--spec-bg, var(--border));
    color: var(--spec-fg, var(--text-soft));
    font-size: 11.5px;
    font-weight: 600;
    line-height: 18px;
}
.spec-legend { margin-left: 8px; display: inline-flex; gap: 6px; align-items: center; }
.spec-req { color: var(--red); margin-left: 2px; }
.spec-calc { color: #7e22ce; margin-left: 3px; font-style: italic; }

.spec-grid .spec-group {
    text-align: center;
    border-bottom: 1px solid var(--border-strong);
}
.spec-grid thead tr:nth-child(2) th { top: 33px; }
.spec-grid .sticky-col-first {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    box-shadow: inset -1px 0 0 var(--border-strong);
}
.spec-grid td.spec-cell { padding: 3px 4px; }
.spec-grid td.spec-cell input,
.spec-grid td.spec-cell select {
    width: 110px;
    padding: 4px 6px;
    font-size: 13px;
    background: var(--spec-bg, var(--surface));
    color: var(--spec-fg, var(--text));
    border: 1px solid var(--border);
    border-radius: 6px;
}
.spec-grid td.spec-cell input.num { text-align: right; }
.spec-grid td.spec-cell input::placeholder { color: var(--muted); font-size: 11.5px; }
.spec-grid td.spec-cell.spec-dirty input,
.spec-grid td.spec-cell.spec-dirty select { border-color: var(--amber); }
.spec-grid td.spec-pending { box-shadow: inset 0 -3px 0 var(--amber); }

.spec-controls { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
.spec-controls .inline-form { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
.spec-controls select { width: auto; }
.spec-controls p { margin: 0; }

.spec-sheet {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 0 18px;
}
.spec-form { width: 100%; }
.spec-form th { text-align: left; font-weight: 500; width: 40%; }
.spec-form td, .spec-form th { padding: 4px 6px; vertical-align: middle; }
.spec-form input, .spec-form select { background: var(--spec-bg, var(--surface)); }
.spec-form input.num { text-align: right; }
.spec-form .unit { color: var(--muted); white-space: nowrap; width: 60px; }
.spec-note { font-size: 12px; }
.spec-warning { color: var(--amber); font-weight: 600; }
.alert .inline-form { display: flex; gap: 8px; align-items: center; margin: 8px 0 0; }
.alert p { margin: 0; }
.spec-form th {
    text-transform: none;
    letter-spacing: normal;
    font-size: 13px;
    color: var(--text-soft);
    background: none;
}
.spec-form input, .spec-form select { width: 100%; max-width: 220px; }

/* Vendor To Advise: exported as "VTA" while empty. */
.spec-vta { --spec-bg: #f1f5f9; --spec-fg: var(--muted); }
.spec-chip.spec-vta { font-size: 10.5px; padding: 0 6px; }
.spec-grid td.spec-vta input::placeholder,
.spec-form input::placeholder { color: var(--muted); font-style: italic; }

.header-actions .js-spec-export { display: inline; margin: 0; }
.spec-grid .sticky-col-first input[type="checkbox"] { margin: 0 6px 0 0; vertical-align: middle; }

/* Project defaults of common fields: inherited values shown in grey. */
.spec-default { --spec-bg: var(--surface-2); --spec-fg: var(--muted); }
.spec-grid td.spec-default input::placeholder { color: var(--text-soft); font-style: normal; }
.spec-form input::placeholder { color: var(--text-soft); }
.spec-defaults summary { cursor: pointer; }
.spec-defaults-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px 16px;
    margin-top: 12px;
}
.spec-default-field { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--text-soft); }
.spec-default-field input, .spec-default-field select { font-size: 13px; padding: 5px 8px; }

/* Grid sections (one at a time) and the vendor-field switch. */
.spec-sections {
    display: flex; flex-wrap: wrap; align-items: center;
    justify-content: space-between; gap: 8px; margin-bottom: 10px;
}
.section-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.section-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border: 1px solid var(--border);
    border-radius: var(--radius-pill); background: var(--surface);
    color: var(--text-soft); font-size: 13px; text-decoration: none;
}
.section-tab:hover { border-color: var(--primary-border); color: var(--primary); }
.section-tab.is-active { background: var(--primary-soft); border-color: var(--primary-border); color: var(--primary); font-weight: 600; }
.vta-switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-soft); text-decoration: none; }
.vta-box {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border: 1px solid var(--border-strong);
    border-radius: 4px; font-size: 11px; background: var(--surface);
}
.vta-switch.is-on .vta-box { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---- Instrument catalog ------------------------------------------------- */
.card td.nowrap { white-space: nowrap; }
.card td.num { text-align: right; white-space: nowrap; }
.header-actions .inline-form,
.actions-col .inline-form,
.catalog-lists .inline-form { display: inline; margin: 0; }
.catalog-detail { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 0 18px; }
.catalog-detail .detail-grid { grid-template-columns: 180px 1fr; }
.catalog-form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 18px; }
.catalog-form-grid .form-field { max-width: none; }
.catalog-form-wide { grid-column: 1 / -1; }
.catalog-form-wide .form-field > div[id] { margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 6px 20px; }
.catalog-form-wide .form-field > div[id] label { font-weight: 400; display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.catalog-lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0 18px; }
.catalog-lists .search-form { margin-bottom: 10px; }
tr.is-selected td { background: var(--primary-soft); }
/* Column header sort + filter row (register_table.py, _register_head.html) */
.sort-link { color: inherit; text-decoration: none; display: inline-flex; gap: 4px; align-items: baseline; white-space: nowrap; }
.sort-link:hover { color: var(--primary); }
.sort-link .sort-mark { font-size: 10px; opacity: .35; }
.sort-link.is-sorted { color: var(--primary); }
.sort-link.is-sorted .sort-mark { opacity: 1; }
thead .filter-row th { padding-top: 0; padding-bottom: 8px; font-weight: 400; text-transform: none; letter-spacing: 0; }
thead .filter-row input,
thead .filter-row select { width: 100%; min-width: 64px; padding: 3px 6px; font-size: 12px; height: auto; margin: 0; }
thead .filter-row .is-active { border-color: var(--primary); background: var(--primary-soft); }
thead .filter-row .link-button { font-size: 12px; }
.catalog-table tr.is-obsolete td { color: var(--muted); }
@media (max-width: 700px) {
    .catalog-detail { grid-template-columns: 1fr; }
    .catalog-detail .detail-grid { grid-template-columns: 1fr; }
}

/* ---- Process data panel + stream links (stream_links.py) ---------------- */
.process-data-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.process-data-head h2 { margin: 0; }
.process-data-head .inline-form { display: inline; margin: 0; }
.process-data-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.process-stream { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.process-stream-title { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.process-route { font-size: 12px; margin: 2px 0 6px; }
.process-stream .mini-table { width: 100%; }
.margin-input { width: 64px; }
.header-actions .inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.add-link { position: relative; }
.add-link summary { list-style: none; cursor: pointer; }
.add-link summary::-webkit-details-marker { display: none; }
.add-link-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; display: grid; gap: 8px; width: 280px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(15, 23, 42, .12); }
.margin-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; }
.register-bar.has-selection .margin-form { display: none; }
.spec-src-motor { --spec-bg: var(--amber-bg); --spec-fg: var(--amber); text-decoration: none; }
.spec-locked { display: inline-block; padding: 4px 6px; color: var(--amber); font-variant-numeric: tabular-nums; }
.register-table td.inherited { color: var(--muted); font-style: italic; }
.register-table select.cell-select { width: auto; min-width: 150px; padding: 3px 6px; font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0 18px; }
.settings-card { display: block; color: inherit; text-decoration: none; }
.settings-card:hover { border-color: var(--primary-border); }
.settings-card h2 { color: var(--primary); }
tr.is-obsolete td { color: var(--muted); }

/* ---- Instrument Schedule: loop page ----------------------------------- */

.loop-add-member {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}
.loop-add-member input[type="text"] { width: 260px; }
.loop-add-member select { width: auto; }
.register-table .loop-role-select { width: auto; }

/* ---- I/O list ------------------------------------------------------------ */

.add-link-panel.io-counts { width: auto; min-width: 380px; }
.io-counts table { margin-bottom: 8px; }
.io-counts td, .io-counts th { padding: 4px 10px; }
.register-bar .io-panel-input { width: 90px; }
.text-warning { color: var(--amber); }

/* ---- Valve catalogue ------------------------------------------------------ */

.add-link-panel.missing-codes { width: 340px; max-height: 60vh; overflow: auto; }
.missing-codes td, .missing-codes th { padding: 3px 8px; }

/* ---- One spec system (PR 5b) ---------------------------------------------- */

/* Spec page menu: item kind first (Equipment / Instruments / Valves),
   then the spec types of that kind as underlined tabs. */
.spec-menu {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}
.spec-kinds {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    padding: 8px 10px;
}
.spec-menu .spec-types { border-top: 1px solid var(--border); }
.spec-kind {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 14px; border-radius: var(--radius-pill);
    color: var(--text-soft); font-size: 14px; font-weight: 600;
    text-decoration: none;
}
.spec-kind:hover { background: var(--surface-2); color: var(--text); }
.spec-kind.is-active { background: var(--primary); color: #fff; }
.spec-kind.is-active .case-count { background: rgba(255, 255, 255, .22); color: #fff; }
.spec-kind-icon { width: 17px; height: 17px; flex: none; }
.spec-kind-unassigned { margin-left: auto; background: var(--amber-bg); color: var(--amber); }
.spec-kind-unassigned:hover { background: var(--amber-bg); color: var(--amber); box-shadow: inset 0 0 0 1px var(--amber); }
.spec-kind-unassigned.is-active { background: var(--amber); }
.spec-types {
    display: flex; flex-wrap: wrap; gap: 0 22px; padding: 0 18px;
}
.spec-type {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 1px 7px; border-bottom: 2px solid transparent;
    color: var(--text-soft); font-size: 13.5px; font-weight: 600;
    text-decoration: none;
}
.spec-type:hover { color: var(--primary); border-bottom-color: var(--primary-border); }
.spec-type.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.spec-type.is-empty { color: var(--muted); font-weight: 400; }
.spec-type-count {
    min-width: 20px; padding: 0 6px; border-radius: var(--radius-pill);
    background: var(--surface-2); color: var(--muted);
    font-size: 11.5px; font-weight: 600; line-height: 17px; text-align: center;
    font-variant-numeric: tabular-nums;
}
.spec-type.is-active .spec-type-count { background: var(--primary-soft); color: var(--primary); }
@media (max-width: 640px) {
    .spec-kinds { gap: 2px; padding: 6px; }
    .spec-kind { gap: 5px; padding: 6px 9px; font-size: 13px; }
    .spec-kind-unassigned { margin-left: 0; }
    .spec-types { gap: 0 14px; padding: 0 12px; }
    .spec-filter { margin-left: 0; flex-wrap: wrap; }
}

/* Summary of the open type and the row filter, above the grid. */
.spec-summary {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px;
    margin: 0 0 10px; font-size: 13px; color: var(--text-soft);
}
.spec-summary strong { color: var(--text); font-variant-numeric: tabular-nums; }
.spec-summary-ok strong { color: var(--green); }
.spec-summary-missing strong { color: var(--amber); }
.spec-summary-pending strong { color: var(--red); }
.spec-filter { margin-left: auto; display: inline-flex; align-items: center; gap: 12px; }
.spec-filter input[type="search"] { width: 200px; padding: 5px 10px; font-size: 13px; }
.spec-filter label { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* Per-item spec status column and the tag description. */
.spec-grid .spec-tag-desc {
    display: block; max-width: 220px; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
    color: var(--muted); font-size: 11.5px; font-weight: 400;
}
.spec-grid td.spec-status { white-space: nowrap; font-size: 12px; }
.spec-progress {
    display: inline-block; width: 56px; height: 6px; margin-right: 6px;
    border-radius: 3px; background: var(--border); overflow: hidden;
    vertical-align: middle;
}
.spec-progress span { display: block; height: 100%; background: var(--amber); }
.spec-status.is-complete .spec-progress span { background: var(--green); }
.spec-status-count { color: var(--text-soft); font-variant-numeric: tabular-nums; margin-right: 4px; }
.spec-flag {
    display: inline-block; margin-left: 3px; padding: 0 6px;
    border-radius: var(--radius-pill); font-size: 11px; font-weight: 600;
    line-height: 17px;
}
.spec-flag-mhb { background: var(--green-bg); color: var(--green); }
.spec-flag-default { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }
.spec-flag-pending { background: var(--red-bg); color: var(--red); }
.spec-catalogue p { margin: 0 0 10px; }
.check-ok { color: var(--green, #15803d); font-weight: 700; }
.check-no { color: var(--red, #b91c1c); font-weight: 700; }

/* ---- Control valve sizing (PR 5c) ------------------------------------------ */

.sizing-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.sizing-figure { display: flex; flex-direction: column; gap: 2px; }
.sizing-figure b { font-size: 22px; }
.sizing-params { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 16px; margin-bottom: 8px; }
.sizing-table th[scope="row"] { text-align: left; white-space: nowrap; }
.sizing-table td { min-width: 150px; }
.sizing-table td input.num { width: 100%; }
.sizing-table td select { margin-top: 4px; width: 100%; }
.sizing-table .sizing-result td, .sizing-table .sizing-result th { background: var(--surface-2); }
.sizing-use label { display: block; font-size: 12px; white-space: nowrap; }
.sizing-calc { margin: 8px 0; }
.sizing-calc summary { cursor: pointer; }
.sizing-steps code { white-space: nowrap; }
.sizing-table td.spec-cell input { background: var(--spec-bg, var(--surface)); color: var(--spec-fg, inherit); }

/* Bulk-edit bar (register_bulk_edit.js): values for the ticked rows. */
.register-table tr.bulk-edit-row td {
    border-bottom: 2px solid var(--primary);
}

.register-table tr.bulk-edit-row .check-col {
    color: var(--primary);
    text-align: center;
}
