/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: Arial, sans-serif;
    font-size: 14px;
    background: #f4f6f8;
    color: #222;
    min-height: 100vh;
}

a { color: #1a73e8; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Navbar */
.navbar {
    background: #1e3a5f;
    color: #fff;
    padding: 0 1.5rem;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand { font-size: 1.1rem; font-weight: bold; letter-spacing: 0.5px; }
.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a { color: #cde; font-size: 0.9rem; }
.nav-links a:hover { color: #fff; text-decoration: none; }
.nav-user { color: #aac; font-size: 0.85rem; }

/* Container */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* Flash messages */
.flash-messages { margin-bottom: 1rem; }
.alert {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}
.alert-success { background: #d4edda; border: 1px solid #c3e6cb; color: #155724; }
.alert-error   { background: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; }
.alert-warning { background: #fff3cd; border: 1px solid #ffeeba; color: #856404; }
.alert-info    { background: #d1ecf1; border: 1px solid #bee5eb; color: #0c5460; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.45rem 1rem;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    white-space: nowrap;
    transition: background 0.15s;
    text-decoration: none;
    box-sizing: border-box;
    font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: #1e3a5f; color: #fff; border-color: #1e3a5f; }
.btn-primary:hover { background: #14294a; }
.btn-secondary { background: #fff; color: #333; border-color: #ccc; }
.btn-secondary:hover { background: #f0f0f0; }
.btn-danger    { background: #dc3545; color: #fff; border-color: #dc3545; }
.btn-danger:hover { background: #c82333; }
.btn-warning   { background: #f0a500; color: #fff; border-color: #f0a500; }
.btn-warning:hover { background: #d4920a; }
.btn-sm        { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-block     { width: 100%; text-align: center; display: block; }

/* Page header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-header h1 { font-size: 1.4rem; color: #1e3a5f; }
.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.project-meta { font-size: 0.85rem; color: #666; margin-top: 0.25rem; }
.sep { margin: 0 0.25rem; color: #bbb; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-submittal { background: #cfe2ff; color: #084298; }
.badge-revision  { background: #fff3cd; color: #664d03; }
.badge-asbuilt   { background: #d1e7dd; color: #0a3622; }

/* Cards */
.form-card {
    background: #fff;
    border: 1px solid #dde2e8;
    border-radius: 6px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}
.section-card {
    background: #fff;
    border: 1px solid #dde2e8;
    border-radius: 6px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.section-header h2 { font-size: 1rem; color: #1e3a5f; }
.section-hint { font-size: 0.85rem; color: #666; margin-top: 0.25rem; }
.section-actions { display: flex; gap: 0.5rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: #333;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.875rem;
    background: #fff;
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: #1e3a5f; }
.form-group-check { background: #f8f9ff; border: 1px solid #dde2e8; border-radius: 4px; padding: 0.6rem 0.75rem; }
.check-label { display: flex !important; align-items: center; gap: 0.5rem; font-weight: 600 !important; cursor: pointer; margin-bottom: 0 !important; }
.check-label input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }
.form-group-wide { flex: 2; }
.form-group-sm   { flex: 0 0 80px; }
.form-group-btn  { flex: 0 0 auto; }
.form-row        { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; }
.form-actions    { display: flex; gap: 0.75rem; margin-top: 1.25rem; align-items: center; }
.form-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 0.5px;
    margin: 1.25rem 0 0.75rem;
    border-top: 1px solid #eee;
    padding-top: 1rem;
}
.field-hint { font-size: 0.78rem; color: #888; display: block; margin-top: 0.2rem; }
.field-optional { font-size: 0.72rem; font-weight: 400; color: #9ca3af; text-transform: uppercase; letter-spacing: 0.04em; margin-left: 0.3rem; }
.required { color: #dc3545; }

/* Auth card */
.auth-card {
    max-width: 400px;
    margin: 4rem auto;
    background: #fff;
    border: 1px solid #dde2e8;
    border-radius: 8px;
    padding: 2rem;
}
.auth-card h1 { font-size: 1.3rem; color: #1e3a5f; margin-bottom: 0.25rem; }
.auth-card h2 { font-size: 1rem; color: #555; margin-bottom: 1.5rem; }
.auth-link { margin-top: 1rem; font-size: 0.85rem; color: #666; text-align: center; }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.data-table th {
    background: #f0f3f7;
    padding: 0.5rem 0.6rem;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #dde2e8;
    white-space: nowrap;
}
.data-table td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8f9ff; }
.data-table-sm td, .data-table-sm th { padding: 0.35rem 0.5rem; }
.td-actions { text-align: center; padding: 0 4px !important; white-space: nowrap; }
.split-btn { display: inline-flex; vertical-align: middle; }
.split-main {
    display: inline-flex; align-items: center;
    padding: 0.25rem 0.6rem; font-size: 0.8rem; font-family: inherit; font-weight: 500;
    line-height: 1.5; box-sizing: border-box;
    border: 1px solid; border-right: none;
    border-radius: 4px 0 0 4px;
    text-decoration: none; cursor: pointer; white-space: nowrap;
    transition: background 0.15s;
}
.split-main.btn-secondary { background: #fff; color: #333; border-color: #ccc; }
.split-main.btn-secondary:hover { background: #f0f0f0; }
.split-main.btn-warning { background: #f0a500; color: #fff; border-color: #f0a500; }
.split-main.btn-warning:hover { background: #d4920a; }
.split-signoff {
    display: inline-flex; align-items: center;
    padding: 0.25rem 0.5rem; font-size: 0.8rem; font-family: inherit; font-weight: 500;
    line-height: 1.5; box-sizing: border-box;
    border: 1px solid #f0a500; border-left: 1px solid rgba(255,255,255,0.45);
    border-radius: 0 4px 4px 0;
    cursor: pointer; white-space: nowrap;
    background: #f0a500; color: #fff;
    transition: background 0.15s;
}
.split-signoff:hover { background: #d4920a; border-color: #d4920a; border-left-color: rgba(255,255,255,0.45); }
.split-signoff.signed { background: #28a745; border-color: #28a745; border-left-color: rgba(255,255,255,0.45); }
.split-signoff.signed:hover { background: #218838; }
.schedule-table thead th:first-child,
.schedule-table tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: inherit; /* overridden explicitly below for each row context */
}
/* Group-header first cell: same shade as the named group cells */
.schedule-table thead tr.col-group-header th:first-child {
    background: #e5eaf2;
}
/* Column-header first cell: match regular header background */
.schedule-table thead tr:not(.col-group-header) th:first-child {
    background: #f0f3f7;
}
.td-office { max-width: 220px; font-size: 0.8rem; color: #555; }
.td-partnumber { max-width: 200px; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-datasheet  { width: 1px; min-width: 1px; max-width: 2rem; text-align: center; white-space: nowrap; overflow: hidden; }
.td-empty { text-align: center; color: #aaa; padding: 2rem; }
.td-total { text-align: right; background: #f0f3f7; }
.td-desc { font-size: 0.78rem; color: #555; max-width: 300px; }

/* Schedule table */
.schedule-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 220px);
    border: 1px solid #dde2e8;
    border-radius: 6px;
}
.schedule-table { min-width: 900px; }

/* Condensed fixed-width columns */
.td-item-num  { width: 2rem;   min-width: 2rem;   max-width: 2rem; }
.td-pipe-sz   { width: 3.5rem; min-width: 3.5rem; max-width: 3.5rem; }
.td-body-type { width: 3.5rem; min-width: 3.5rem; max-width: 3.5rem; }
.td-close-off { width: 4rem;   min-width: 4rem;   max-width: 4rem; }
.td-qty       { width: 2.5rem; min-width: 2.5rem; max-width: 2.5rem; }
.schedule-table thead th,
.schedule-table tbody td { text-align: center; }
.schedule-table tbody td.td-note { text-align: left; }
.schedule-table thead th {
    position: sticky;
    top: 0;           /* group-header row sticks at very top */
    z-index: 2;
    background: #f0f3f7;
    border-bottom: none;  /* border-collapse paints borders at table layer — use box-shadow instead */
    box-shadow: 0 2px 0 #dde2e8; /* travels with the sticky cell, not the table */
}
/* Column-header row: CSS fallback offset — JS (fixStickyHeaderOffset on window load)
   overwrites this with the exact measured height of the group-header row. */
.schedule-table thead tr:not(.col-group-header) th {
    top: 22px;
}
/* Corner cells — must sit above both sticky header rows and the sticky first column */
.schedule-table thead th:first-child {
    z-index: 3;
}
/* First column body cells need an opaque background so scrolled content doesn't show through */
.schedule-table tbody td:first-child {
    background: #fff;
}
.schedule-table tbody tr:hover td:first-child {
    background: #f8f9ff; /* match .data-table tbody tr:hover */
}
/* Actuator Config column — sized for worst-case "Modulating (4-20mA)" */
.schedule-table .th-control-failure {
    min-width: 10rem;
}
/* Fail-safe failure mode / valve setup label — bold red in both views */
.body-conn-stack .conn-sub.fail-safe-lbl {
    font-weight: 700;
    color: #dc3545;
}
/* Valve setup select — red border when a fail-safe position is chosen */
select#valve_setup.setup-failsafe {
    border-color: #dc3545;
    color: #dc3545;
    font-weight: 700;
}
.row-warning td   { background: #fff8e1 !important; }
.row-override td  { background: #f0f7ff !important; }
.row-isolation td { background: #f3f0ff !important; }
.row-unconfigured td { background: #eef6ff !important; border-left: 3px solid #93c5fd; }
.iso-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    background: #7c3aed;
    color: #fff;
    padding: 0 4px;
    border-radius: 3px;
    margin-left: 4px;
    vertical-align: middle;
}
.td-sm { font-size: 0.78rem; max-width: 120px; }
.cv-ok  { color: #155724; font-weight: 600; }
.cv-low { color: #856404; }
/* Authority tier badges */
.auth-ok         { color: #155724; font-weight: 600; }  /* legacy */
.auth-warn       { color: #dc3545; font-weight: 700; }  /* legacy */
.auth-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.auth-invalid    { background: #f8d7da; color: #58151c; }
.auth-oversized  { background: #f8d7da; color: #58151c; }   /* red  — valve undersized, exceeds spec ΔP */
.auth-ideal      { background: #d1e7dd; color: #0a3622; }
.auth-acceptable { background: #cfe2ff; color: #052c65; }
.auth-poor       { background: #fff3cd; color: #664d03; }   /* yellow — significantly oversized valve */
/* Legacy aliases kept for any cached pages */
.auth-high       { background: #fff3cd; color: #664d03; }
.auth-good       { background: #d1e7dd; color: #0a3622; }
.auth-marginal   { background: #e9ecef; color: #343a40; }

/* Cv ratio tier badges */
.cvr-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.cvr-ideal      { background: #d1e7dd; color: #0a3622; }
.cvr-acceptable { background: #cfe2ff; color: #052c65; }
.cvr-oversized  { background: #fff3cd; color: #664d03; }
.cvr-undersized { background: #f8d7da; color: #58151c; }

/* Selection score badges */
.score-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    min-width: 2.2rem;
    text-align: center;
}
.score-excellent { background: #d1e7dd; color: #0a3622; }
.score-good      { background: #cfe2ff; color: #052c65; }
.score-fair      { background: #fff3cd; color: #664d03; }
.score-poor      { background: #f8d7da; color: #58151c; }

/* Stacked metric cells — number on top, word badge below, same tier color */
.stacked-metric {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.08rem;
    line-height: 1.15;
    padding: 0.15rem 0.45rem;
}
.stacked-num {
    font-size: 0.78rem;
    font-weight: 700;
}
.stacked-lbl {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.85;
}

/* Pipe size ratio check — Fit column */
.psr-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.psr-ok         { background: #d1e7dd; color: #0a3622; }   /* green  — isolation 1:1 */
.psr-good       { background: #d1e7dd; color: #0a3622; }   /* green  — ideal range */
.psr-acceptable { background: #e9ecef; color: #343a40; }   /* gray   — fine */
.psr-oversized  { background: #fff3cd; color: #664d03; }   /* amber  — same as pipe */
.psr-undersized { background: #f8d7da; color: #58151c; }   /* red    — below Belimo min */
.psr-invalid    { background: #f8d7da; color: #58151c; }   /* red    — valve > pipe */
.psr-mismatch   { background: #f8d7da; color: #58151c; }   /* red    — isolation mismatch */

/* Workflow steps */
.workflow-steps {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 1rem 1.5rem;
    background: #fff;
    border: 1px solid #dde2e8;
    border-radius: 6px;
}
.step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    background: #f0f3f7;
    color: #888;
}
.step-num {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: #ccc;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
}
.step-active .step-num { background: #1e3a5f; }
.step-active { color: #1e3a5f; font-weight: 600; }
.step-done .step-num { background: #198754; }
.step-done { color: #198754; }
.step-arrow { color: #bbb; font-size: 1.1rem; }
.step-label { font-size: 0.85rem; }

/* Batch layout */
.batch-layout { display: grid; grid-template-columns: 1fr 320px; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .batch-layout { grid-template-columns: 1fr; } }

/* Catalog match counter */
.match-count { font-size: 0.8rem; font-weight: 600; padding: 0.2rem 0.6rem; border-radius: 10px; margin-left: 0.5rem; }
.match-ok   { background: #d4edda; color: #155724; }
.match-few  { background: #fff3cd; color: #856404; }
.match-none { background: #f8d7da; color: #721c24; }

/* Disabled option styling hint */
select option:disabled { color: #bbb; font-style: italic; }

.config-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #1E3A5F;
    border-bottom: 2px solid #1E3A5F;
    padding-bottom: 0.2rem;
    margin-bottom: 0.6rem;
}
.equip-group-parent { border-bottom: 1px solid #dde2e8; padding-bottom: 0.4rem; margin-bottom: 0.4rem; }
.equip-group-parent:last-child { border-bottom: none; margin-bottom: 0; }
.equip-group-parent-header { font-weight: 600; font-size: 0.88rem; color: #1e3a5f; padding: 0.4rem 0 0.2rem; }
.equip-group { padding: 0.35rem 0; border-bottom: 1px solid #f0f0f0; }
.equip-group:last-child { border-bottom: none; }
.equip-group-sub { padding-left: 0.75rem; }
.equip-group-header { display: flex; justify-content: space-between; align-items: center; }
.equip-group-status { font-size: 0.8rem; color: #666; margin-top: 0.2rem; }
.equip-group-clickable { cursor: pointer; border-radius: 5px; transition: background 0.15s, border-left-color 0.15s; padding-left: 0.5rem; border-left: 3px solid transparent; }
.equip-group-sized        { border-left-color: #198754; }
.equip-group-partial      { border-left-color: #f0a500; }
.equip-group-unconfigured { border-left-color: #adb5bd; }
.equip-group-clickable:hover { background: #f0f4ff; }
.equip-warning { font-size: 0.78rem; color: #856404; margin-top: 0.15rem; }
.svc-label { font-size: 0.82rem; color: #444; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.status-green  { background: #198754; }
.status-yellow { background: #f0a500; }
.status-grey   { background: #bbb; }

/* Batch valve selection */
.valve-select-controls { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.valve-type-filter { font-size: 0.8rem; padding: 0.2rem 0.4rem; border: 1px solid #c8d0db; border-radius: 4px; }

/* Shared grid: checkbox | equip tag | valve tag+badge | calc cv | sized */
.valve-check-header,
.valve-check-item {
    display: grid;
    grid-template-columns: 1.4rem minmax(60px,150px) minmax(120px,220px) 6.5rem 4rem;
    align-items: center;
    gap: 0 0.4rem;
}
.valve-check-header {
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.05em; color: #6b7280;
    padding: 0.25rem 0.6rem 0.25rem 0.5rem;
    border-bottom: 1px solid #dde2e8;
    margin-bottom: 0.1rem;
}
.valve-checkbox-list { display: flex; flex-direction: column; max-height: 14rem; overflow-y: auto;
    border: 1px solid #dde2e8; border-radius: 0 0 6px 6px; padding: 0.25rem 0.4rem;
    background: #fafbfc; }
.valve-check-header + .valve-checkbox-list {
    border-top: none; border-radius: 0 0 6px 6px;
}
/* Wrap header + list together with a shared border */
#valve-selection-panel .valve-check-header {
    border: 1px solid #dde2e8; border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: #f4f6f9;
}
.valve-check-item { font-size: 0.85rem; padding: 0.2rem 0.25rem; border-radius: 4px; cursor: pointer; }
.valve-check-item:hover { background: #f0f4ff; }
.valve-check-item input[type=checkbox] { justify-self: center; }
.valve-check-tag-cell { display: flex; align-items: center; gap: 0.35rem; min-width: 0; }
.valve-check-tag   { font-weight: 600; color: #1e3a5f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.valve-check-type  { font-size: 0.72rem; font-weight: 700; color: #fff; background: #4a7ab5;
    padding: 0.05rem 0.35rem; border-radius: 3px; flex-shrink: 0; }
.valve-check-equip { color: #6c757d; font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.valve-check-cv    { font-size: 0.72rem; font-weight: 600; color: #1e40af; background: #dbeafe;
                     padding: 0.1rem 0.4rem; border-radius: 3px; white-space: nowrap; justify-self: start; }
.valve-check-sized { font-size: 0.72rem; color: #198754; font-weight: 600; justify-self: end; }

/* Valve tag token builder */
.token-builder { display: flex; flex-wrap: wrap; gap: .4rem; min-height: 2.2rem;
    padding: .35rem .4rem; border: 1px solid #dde2e8; border-radius: 6px; background: #fafbfc;
    margin-bottom: .4rem; }
.token-chip { display: flex; align-items: center; gap: .3rem; background: #1e3a5f; color: #fff;
    padding: .25rem .55rem; border-radius: 20px; font-size: .8rem; font-weight: 600;
    cursor: grab; user-select: none; transition: opacity .15s; }
.token-chip.dragging  { opacity: .4; }
.token-chip.drag-over { outline: 2px dashed #93c5fd; }
.token-grip  { font-size: .85rem; opacity: .6; cursor: grab; }
.token-remove { background: none; border: none; color: rgba(255,255,255,.7); font-size: 1rem;
    cursor: pointer; padding: 0 0 0 .15rem; line-height: 1; }
.token-remove:hover { color: #fff; }
.token-add-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-top: .25rem; }
.token-add-bar .btn:disabled { opacity: .35; cursor: not-allowed; }
.token-text-add { display: flex; align-items: center; gap: .3rem; margin-left: .25rem; border-left: 1px solid #dde2e8; padding-left: .5rem; }
.token-text-input { font-size: .8rem; padding: .25rem .45rem; border: 1px solid #ccc; border-radius: 4px; width: 9rem; }
.token-text-label { font-style: italic; opacity: .9; }
.valve-check-new { background: #eef6ff; }
.valve-check-new:hover { background: #dbeafe; }
.valve-check-section-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em;
    text-transform: uppercase; padding: 0.3rem 0.25rem 0.1rem; margin-top: 0.15rem; }
.valve-check-section-new  { color: #1d4ed8; border-top: 1px solid #bfdbfe; }
.valve-check-section-new:first-child { border-top: none; margin-top: 0; }
.valve-check-section-done { color: #6b7280; border-top: 1px solid #e5e7eb; }

/* Override layout */
.override-layout { display: grid; grid-template-columns: 340px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .override-layout { grid-template-columns: 1fr; } }
.override-col1 { display: flex; flex-direction: column; gap: 1.25rem; }
.neighbor-panel-card { padding: 0.75rem 1rem; }
.neighbor-panel-card .neighbor-panel-label { margin-bottom: 0.6rem; }
.info-table { width: 100%; font-size: 0.85rem; }
.info-table th { width: 130px; color: #555; font-weight: 600; padding: 0.3rem 0.5rem 0.3rem 0; }
.info-table td { padding: 0.3rem 0; }
.cv-basis { font-size: 0.72rem; font-weight: 400; color: #888; }

/* Override page catalog search filters */
.override-search-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}
.override-search-filters .form-group {
    flex: 1 1 140px;
    min-width: 120px;
    margin: 0;
}
.override-search-filters label {
    font-size: 0.72rem;
}

/* Candidates table */
.candidate-row { cursor: pointer; }
.candidate-row:hover td { background: #e8f0fe; }
.candidate-current td { background: #e8f0fe; }
.candidate-selected td { background: #c8e6c9 !important; }

/* Neighbor comparison panel */
.neighbor-panel {
    margin: 0.75rem 0;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #f8f9fa;
    padding: 0.6rem 0.75rem;
}
.neighbor-panel-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #6c757d;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}
.neighbor-cards {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
}
.neighbor-card {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 0.5rem 0.6rem;
    cursor: pointer;
    transition: box-shadow 0.15s;
}
.neighbor-card:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.12); }
.neighbor-center {
    border-color: #0d6efd;
    background: #f0f5ff;
}
.neighbor-empty {
    background: #f8f9fa;
    cursor: default;
    opacity: 0.5;
}
.neighbor-empty:hover { box-shadow: none; }
.neighbor-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #6c757d;
    margin-bottom: 0.25rem;
}
.neighbor-center .neighbor-label { color: #0d6efd; }
.neighbor-selectable { cursor: pointer; }
.neighbor-applied { border-color: #198754; background: #f0faf4; }
.neighbor-applied .neighbor-label { color: #198754; }
.neighbor-select-hint { font-weight: 400; text-transform: none; color: #adb5bd; font-size: 0.65rem; }
.neighbor-part {
    font-size: 0.8rem;
    font-weight: 600;
    color: #1e3a5f;
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.neighbor-cv {
    font-size: 0.75rem;
    color: #495057;
    margin-bottom: 0.35rem;
}
.neighbor-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.25rem;
    margin-top: 0.25rem;
}
.neighbor-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}
.neighbor-metric-lbl {
    font-size: 0.60rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9aa5b1;
}
.neighbor-metric-na {
    font-size: 0.75rem;
    color: #bbb;
}
.neighbor-none {
    font-size: 0.85rem;
    color: #adb5bd;
    text-align: center;
    padding: 0.5rem 0;
}

/* Selection impact preview */
.impact-preview {
    display: flex;
    align-items: center;
    background: #f0f4ff;
    border: 1px solid #c5d2f0;
    border-radius: 6px;
    padding: 0.6rem 1rem;
    margin-bottom: 0.75rem;
}
.impact-grid {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}
.impact-item {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.impact-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #666;
    font-weight: 600;
}
.impact-value {
    font-size: 1rem;
    font-weight: 700;
    color: #1E3A5F;
}

/* Inline form in details/summary */
.add-row-form summary { cursor: pointer; }
.add-row-form summary::-webkit-details-marker { display: none; }
.inline-form { margin-top: 1rem; padding: 1rem; background: #f8f9ff; border-radius: 4px; }
.inline-input { width: 100%; padding: 0.3rem 0.4rem; border: 1px solid #ccc; border-radius: 3px; font-size: 0.85rem; }

/* Empty state */
.empty-state { text-align: center; padding: 3rem; color: #888; }
.empty-state p { margin-bottom: 1rem; }

/* Column group dividers */
th.col-div, td.col-div {
    border-left: 2px solid #c8d0da !important;
}

/* Column group spanning header row */
tr.col-group-header th {
    font-size: 0.70rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #5a6782;
    background: #e5eaf2;
    text-align: center;
    padding: 0.2rem 0.5rem;
    border-bottom: none;
    box-shadow: 0 2px 0 #c8d0da; /* box-shadow instead of border-bottom — stays with sticky cell */
}
tr.col-group-header th.col-div {
    border-left: 2px solid #c8d0da !important;
}

/* Legend */
.legend { display: flex; gap: 1rem; margin-top: 0.75rem; font-size: 0.8rem; color: #666; flex-wrap: wrap; align-items: center; }
.legend-item { display: flex; align-items: center; gap: 0.4rem; }
.legend-sep { width: 1px; height: 14px; background: #dde2e8; }
.legend-help-hint { cursor: pointer; color: #0d6efd; text-decoration: underline dotted; }
.legend-help-hint:hover { color: #0a58ca; }
.row-warning-swatch { display: inline-block; width: 14px; height: 14px; background: #fff8e1; border: 1px solid #ffeeba; border-radius: 2px; }
.row-override-swatch { display: inline-block; width: 14px; height: 14px; background: #f0f7ff; border: 1px solid #b8d4f0; border-radius: 2px; }
.row-override-signed td  { background: #f0fff4 !important; }
.row-override-signed-swatch { display: inline-block; width: 14px; height: 14px; background: #f0fff4; border: 1px solid #a3d9b1; border-radius: 2px; }
.row-steam-warn-swatch { display: inline-block; width: 14px; height: 14px; background: #fff0e0; border: 1px solid #f5c89a; border-radius: 2px; }

.legend-icon { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 22px; border-radius: 4px; border: 1px solid transparent; font-size: 0.8rem; font-weight: 500; }
.btn-secondary-swatch { background: #fff; color: #333; border-color: #ccc; }
.btn-warning-swatch   { background: #f0a500; color: #fff; border-color: #f0a500; }
.btn-signoff-swatch   { background: #f0a500; color: #fff; border-color: #f0a500; }
.btn-signoff-signed-swatch { background: #28a745; color: #fff; border-color: #28a745; }

/* ── Rated GPM badge (PIQCV Act Cv cell) ───────────────────────────────── */
.rated-gpm {
    font-size: 0.78rem;
    font-weight: 600;
    color: #1a73e8;
    background: #e8f0fe;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    white-space: nowrap;
}

/* ── Schedule tab bar ────────────────────────────────────────────────────── */
.schedule-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    border-bottom: 2px solid #dde2e8;
}
.schedule-tab {
    padding: 0.55rem 1.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #555;
    background: #f4f6f8;
    border: 1px solid #dde2e8;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    margin-right: 4px;
    position: relative;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.schedule-tab:hover { background: #eef1f5; color: #1e3a5f; }
.schedule-tab.active {
    background: #fff;
    color: #1e3a5f;
    border-bottom: 2px solid #fff;
    margin-bottom: -2px;
    z-index: 1;
}
.tab-count {
    font-size: 0.72rem;
    font-weight: 700;
    background: #dde2e8;
    color: #444;
    border-radius: 10px;
    padding: 0.05rem 0.45rem;
}
.schedule-tab.active .tab-count { background: #1e3a5f; color: #fff; }
.tab-warn-dot {
    width: 7px; height: 7px;
    background: #e6920a;
    border-radius: 50%;
    display: inline-block;
}

/* ── Steam limits banner (top of steam table) ───────────────────────────── */
.steam-limits-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    background: #fff8f0;
    border: 1px solid #f5d9b0;
    border-radius: 4px;
    padding: 0.55rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: #6b4100;
}
.steam-limits-label { color: #6b4100; }
.steam-limits-sep   { color: #c89a50; font-weight: bold; }

/* ── Steam ΔP status colors ─────────────────────────────────────────────── */
.steam-dp-ok   { color: #1a7a3a; font-weight: 600; }
.steam-dp-over { color: #c0392b; font-weight: 600; }
.row-steam-warn td       { background: #fff0e0 !important; }
.row-steam-warn:hover td { background: #ffe5cc !important; }
.td-dp-target  { font-size: 0.78rem; color: #666; white-space: nowrap; }

/* ── Mode badge (Modulating / Two-Position) ─────────────────────────────── */
.mode-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 3px;
    white-space: nowrap;
    letter-spacing: 0.02em;
}
.mode-mod  { background: #e3f0ff; color: #1a5fa8; }
.mode-2pos { background: #eef6ec; color: #2a7a2a; }

/* ── Steam ΔP info panel (override page) ────────────────────────────────── */
.steam-dp-panel {
    margin-top: 1rem;
    background: #fff8f0;
    border: 1px solid #f5d9b0;
    border-radius: 6px;
    padding: 0.85rem 1rem;
}
.steam-dp-panel-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #8a5a00;
    margin-bottom: 0.65rem;
}
.steam-dp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.6rem 1.2rem;
}
.steam-dp-item { display: flex; flex-direction: column; gap: 0.1rem; }
.steam-dp-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #888;
    font-weight: 600;
}
.steam-dp-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: #1e3a5f;
}

/* ── Candidates scroll container (override page) ───────────────────────── */
.candidates-scroll {
    max-height: 420px;
    overflow-y: scroll;
    overflow-x: auto;
    border: 1px solid #dde2e8;
    border-radius: 4px;
    margin-top: 0.5rem;
    display: block;
}
.candidates-scroll .candidates-table {
    width: 100%;
}
.candidates-scroll .candidates-table thead th,
.candidates-scroll .candidates-table tbody td {
    text-align: center;
}

/* Part number / price stacked cell */
.part-price-stack { display: inline-flex; flex-direction: column; align-items: center; gap: 0.1rem; }
.part-price-stack .pp-num { font-size: 0.8rem; font-weight: 600; }
.part-price-stack .pp-sub { font-size: 0.72rem; color: #6c757d; }

/* Body/Fit + Connection stacked cell */
.body-conn-stack { display: inline-flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.body-conn-stack .conn-sub { font-size: 0.72rem; color: #6c757d; }
.body-conn-stack .calc-sub { font-size: 0.72rem; font-weight: 600; color: #495057; }
/* Design conditions cell (GPM + Calc Cv / lbs/hr + Calc Cv) */
.design-cond-line { font-size: 0.8rem; white-space: nowrap; }
.design-lbl { font-size: 0.7rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.02em; margin-right: 0.2rem; }
.stacked-prefix { font-size: 0.68rem; font-weight: 600; opacity: 0.65; text-transform: uppercase; letter-spacing: 0.02em; margin-right: 0.2rem; }
.no-match-badge { display: inline-block; font-size: 0.7rem; font-weight: 600; color: #92400e; background: #fef3c7; border: 1px solid #f59e0b; border-radius: 3px; padding: 0.1rem 0.4rem; white-space: nowrap; }

/* ── Estimated authority marker ──────────────────────────────────────────── */
.auth-est-marker { font-size: 0.6rem; font-weight: 500; opacity: 0.75; font-style: italic; margin-left: 0.15rem; }
.auth-estimated { border-style: dashed; }

/* ── Sortable column headers ─────────────────────────────────────────────── */
.schedule-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.schedule-table thead th.sortable:hover { background: #e4e8ef; }
.schedule-table thead th.sortable::after {
    content: ' ⇅';
    font-size: 0.65rem;
    opacity: 0.35;
    display: inline-block;
    margin-left: 0.2rem;
}
.schedule-table thead th.sort-asc::after  { content: ' ▲'; opacity: 0.8; }
.schedule-table thead th.sort-desc::after { content: ' ▼'; opacity: 0.8; }
.candidates-scroll .candidates-table thead th {
    position: sticky;
    top: 0;        /* group-header row; column-header row overridden below */
    z-index: 2;
    background: #f0f3f7;
    border-bottom: none;                /* border-collapse paints borders at table layer — use box-shadow */
    box-shadow: 0 2px 0 #dde2e8;
}
/* Column-header row: CSS fallback offset — JS (fixCandidatesHeaderOffset) refines this */
.candidates-scroll .candidates-table thead tr:not(.col-group-header) th {
    top: 22px;
}

/* ── Filter match count row (override catalog search) ──────────────────── */
.filter-match-row {
    display: flex;
    justify-content: flex-end;
    margin: 0.35rem 0 0.5rem;
    min-height: 1.2rem;
}

/* ── Steam hint box (batch config) ─────────────────────────────────────── */
.steam-hint-box {
    background: #f0f7ff;
    border: 1px solid #b8d4f0;
    border-radius: 4px;
    padding: 0.65rem 0.9rem;
    font-size: 0.83rem;
    color: #1a3a5f;
    line-height: 1.5;
    margin-top: 0.5rem;
}

/* ── MFT steam mode toggle ──────────────────────────────────────────────── */
.steam-mode-toggle {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.25rem;
}
.steam-mode-opt {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #dde2e8;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}
.steam-mode-opt:hover { background: #f4f6f8; }
.steam-mode-opt input[type="radio"] { margin-top: 2px; flex-shrink: 0; }
.steam-mode-opt span:first-of-type { font-weight: 600; font-size: 0.88rem; white-space: nowrap; }

/* ── Help Modal ─────────────────────────────────────────────────────────── */
.help-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.help-modal-overlay.open { display: flex; }

.help-modal {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    max-width: 700px;
    width: 92%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
}
.help-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e9f0;
    flex-shrink: 0;
}
.help-modal-header h2 { margin: 0; font-size: 1.1rem; color: #1e3a5f; }
.help-modal-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: #888;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    line-height: 1;
}
.help-modal-close:hover { background: #f0f2f5; color: #333; }

.help-modal-body {
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.help-section {
    padding: 1rem 0;
    border-bottom: 1px solid #f0f2f5;
}
.help-section:last-child { border-bottom: none; }
.help-section h3 {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #1e3a5f;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.help-desc {
    margin: 0 0 0.6rem 0;
    font-size: 0.85rem;
    color: #444;
    line-height: 1.5;
}
.help-formula {
    font-family: monospace;
    font-size: 0.9rem;
    background: #f4f6f8;
    border-left: 3px solid #0d6efd;
    padding: 0.35rem 0.75rem;
    border-radius: 0 4px 4px 0;
    margin: 0 0 0.75rem 0;
    color: #1e3a5f;
}
.help-note {
    margin: 0.5rem 0 0 0;
    font-size: 0.78rem;
    color: #666;
    font-style: italic;
}
.help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    margin-bottom: 0.25rem;
}
.help-table th {
    text-align: left;
    padding: 0.3rem 0.5rem;
    background: #f4f6f8;
    color: #555;
    font-weight: 600;
    border-bottom: 1px solid #e5e9f0;
}
.help-table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid #f0f2f5;
    vertical-align: middle;
}
.help-table tr:last-child td { border-bottom: none; }
.help-table td:first-child { white-space: nowrap; min-width: 110px; }

/* Row color swatches inside the modal */
.help-swatch {
    display: inline-block;
    width: 22px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid transparent;
}
.swatch-warning    { background: #fff8e1; border-color: #ffeeba; }
.swatch-steam-warn { background: #fff0e0; border-color: #f5c89a; }
.swatch-override   { background: #f0f7ff; border-color: #b8d4f0; }
.swatch-signed     { background: #f0fff4; border-color: #a3d9b1; }
.steam-mode-opt .field-hint { font-size: 0.78rem; color: #666; margin-top: 0; margin-left: 0.25rem; }

/* Required Cv range panel — batch config */
.cv-range-panel {
    background: #f0f7ff;
    border: 1px solid #bfdbfe;
    border-radius: 5px;
    padding: 0.55rem 0.9rem;
    margin: 0.25rem 0 0.75rem;
}
.cv-range-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #1e40af;
    margin-bottom: 0.3rem;
}
.cv-range-values {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
    font-size: 0.875rem;
    color: #1e3a5f;
}
.cv-sep  { color: #93c5fd; font-weight: 400; }
.cv-note { font-size: 0.78rem; color: #6b7280; }
.cv-warn { font-size: 0.78rem; color: #b45309; font-weight: 500; }

/* ── Custom body-type select with Cv range chips ── */
.cbs-wrap     { position: relative; }
.cbs-trigger  {
    display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
    padding: 0.35rem 0.55rem;
    border: 1px solid #ccc; border-radius: 4px;
    background: #fff; cursor: pointer; font-size: 0.875rem;
    min-height: 34px; user-select: none;
}
.cbs-trigger:hover              { border-color: #999; }
.cbs-wrap.cbs-open .cbs-trigger { border-color: #1e3a5f; box-shadow: 0 0 0 2px rgba(30,58,95,0.15); }
.cbs-trigger:not(.has-value)    { color: #888; }
.cbs-name    { font-weight: 500; color: #1e3a5f; }

.cbs-dropdown {
    display: none;
    position: absolute; top: calc(100% + 2px); left: 0; right: 0;
    background: #fff; border: 1px solid #ccc; border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.13);
    z-index: 200; max-height: 300px; overflow-y: auto;
}
.cbs-option {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.45rem 0.75rem; cursor: pointer; font-size: 0.875rem;
}
.cbs-option:hover:not(.cbs-disabled):not(.cbs-placeholder) { background: #f0f7ff; }
.cbs-placeholder { color: #888; }
.cbs-disabled    { color: #ccc; cursor: not-allowed; }
.cbs-disabled .body-range-chip { opacity: 0.45; }

.body-range-chip {
    font-size: 0.68rem; font-weight: 600;
    background: #dbeafe; color: #1e40af;
    padding: 0.1rem 0.45rem; border-radius: 3px;
    white-space: nowrap;
}

.cbs-note {
    font-size: 0.75rem; color: #92400e;
    background: #fffbeb; border-top: 1px solid #fde68a;
    padding: 0.45rem 0.75rem; line-height: 1.4;
}
.cbs-flash-warn {
    background: #fee2e2 !important;
    transition: background 0.1s;
}

/* ── PDF upload progress bar ──────────────────────────────────────────────── */
.upload-status-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 0.5rem;
}
.upload-progress-track {
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}
.upload-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #1e3a5f, #3b82f6);
    border-radius: 4px;
    transition: width 0.6s ease;
}
.upload-status-hint {
    font-size: 0.78rem;
    color: #64748b;
}
