/* ============================================================
   Safety24 QMS — design system
   ============================================================ */
:root {
    color-scheme: light;   /* render native controls (date picker, calendar icon, scrollbars) light */
    --bg: #f6f8fb;
    --surface: #ffffff;
    --ink: #18212f;
    --ink-soft: #4d5867;
    --muted: #8a94a3;
    --line: #e7eaf0;
    --line-soft: #eef1f5;
    --brand: #103a5e;
    --brand-2: #2f6db5;
    --brand-tint: #eaf2fb;
    --ok-bg: #e7f5ec; --ok-ink: #1c7d43; --ok-line: #c5e7d2;
    --warn-bg: #fff3e0; --warn-ink: #98660b; --warn-line: #f3e1b8;
    --err-bg: #fdebec; --err-ink: #b32531; --err-line: #f4cace;
    --sb-w: 250px;
    --tb-h: 60px;
    --radius: 11px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
    --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.05);
    --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    /* surfaces that were previously hard-coded light — themed via tokens so dark mode is a token swap */
    --topbar-bg: rgba(255,255,255,.85);
    --input-bg: #f4f6f9;
    --field-bg: #ffffff;
    --pop-bg: #ffffff;
    --thead-bg: #fafbfc;
    --row-hover: #f9fbfd;
    --row-density: 12px;   /* td vertical padding; compact mode shrinks it */
    --chip-bg: #eef1f6; --chip-ink: #50596a; --chip-line: #dde3ec;
}

/* ============================================================ Dark theme */
html.theme-dark {
    color-scheme: dark;    /* the browser now draws the native date-picker popup + calendar icon dark too */
    --bg: #0e1620; --surface: #161f2b; --ink: #e7edf5; --ink-soft: #aeb9c7; --muted: #79859a;
    --line: #283441; --line-soft: #1d2733; --brand: #7eb1e8; --brand-2: #4f8fd4; --brand-tint: #18293b;
    --ok-bg: #13301f; --ok-ink: #5fd093; --ok-line: #21492f;
    --warn-bg: #34280f; --warn-ink: #e2b65f; --warn-line: #4a3a16;
    --err-bg: #3a1a1d; --err-ink: #f1939a; --err-line: #54222a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
    --shadow-lg: 0 12px 34px rgba(0,0,0,.6);
    --topbar-bg: rgba(16,23,32,.85); --input-bg: #1d2733; --field-bg: #1b2530; --pop-bg: #1b2530;
    --thead-bg: #131c26; --row-hover: #1a2532;
    --chip-bg: #232f3d; --chip-ink: #aeb9c7; --chip-line: #303d4d;
}
html.theme-dark .thumb, html.theme-dark .thumb-empty { background: #1b2530; }
html.theme-dark .esign-statement { background: #2a2410; }
html.theme-dark .login-card { background: var(--surface); }
html.theme-dark img.thumb-img { background: #1b2530; }

/* ============================================================ Compact density */
html.density-compact { --row-density: 6px; }
html.density-compact .nav-item { padding-top: 7px; padding-bottom: 7px; }
html.density-compact .card { padding: 13px 15px; }
html.density-compact .panel { padding: 13px 15px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.5; font-size: 14px; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin: 0; }
h2 { font-weight: 600; }

/* ============================================================ Sidebar */
.sidebar {
    position: fixed; top: 0; left: 0; width: var(--sb-w); height: 100vh; z-index: 30;
    background: var(--surface); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; padding-bottom: 16px;
    transition: width .18s ease;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 17px 20px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
    font-weight: 700; font-size: 12.5px; letter-spacing: .3px;
}
.brand-text { font-size: 15.5px; color: var(--ink); }
.brand-text strong { color: var(--brand); }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 12px; }
/* Sidebar menu search */
.nav-search { position: relative; margin: 2px 0 8px; }
.nav-search-ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px;
    fill: none; stroke: var(--muted); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.nav-search-input { width: 100%; box-sizing: border-box; padding: 7px 10px 7px 31px; border-radius: 8px;
    border: 1px solid var(--line); background: var(--field-bg); color: var(--ink); font: inherit; font-size: 13px;
    outline: none; transition: border-color .12s, box-shadow .12s; }
.nav-search-input::placeholder { color: var(--muted); }
.nav-search-input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
html.sb-collapsed .nav-search { display: none; }
.nav-group { margin-top: 14px; }
.nav-label {
    font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    color: var(--muted); padding: 6px 12px 4px;
}
/* Collapsible group headers (click to fold a section; state persists per user) */
button.nav-label {
    display: flex; align-items: center; gap: 6px; width: 100%;
    background: none; border: 0; margin: 0; cursor: pointer; font-family: inherit;
}
button.nav-label:hover { color: var(--ink-soft); }
.nav-label-chev {
    width: 13px; height: 13px; margin-left: auto; stroke: currentColor; stroke-width: 2.4;
    fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: .5; transition: transform .15s ease;
}
html:not(.sb-collapsed) .nav-group--collapsed > a.nav-item { display: none; }
.nav-group--collapsed > .nav-label .nav-label-chev { transform: rotate(-90deg); }
html.sb-collapsed .nav-label-chev { display: none; }

/* Pinned favourites: star any item to add it to a quick-access section at the top */
.nav-pin {
    position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
    width: 20px; height: 20px; display: grid; place-items: center; border-radius: 5px;
    font-size: 13px; line-height: 1; color: var(--muted); opacity: 0; cursor: pointer;
    transition: opacity .12s, color .12s, background .12s;
}
.nav-item:hover .nav-pin { opacity: .5; }
.nav-pin:hover { opacity: 1; background: var(--line-soft); color: #f59e0b; }
.nav-pin.pinned { opacity: 1; color: #f59e0b; }
html.sb-collapsed .nav-pin { display: none; }
.nav-pinned .nav-label { color: #b45309; }
.nav-pinned-list:empty { display: none; }

/* Sortable table headers */
th > a.sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
th > a.sort:hover { color: var(--brand); }
.sort-ind { font-size: 9px; opacity: .3; transition: opacity .12s, color .12s; }
th > a.sort:hover .sort-ind { opacity: .65; }
.sort-ind.on { opacity: 1; color: var(--brand); }

/* Part-type icon gallery (choose a built-in image) */
.icon-gallery { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.icon-choice { width: 52px; height: 52px; padding: 7px; border: 1px solid var(--line); border-radius: 10px;
    background: var(--surface); cursor: pointer; display: grid; place-items: center; transition: border-color .12s, box-shadow .12s; }
.icon-choice:hover { border-color: var(--brand); }
.icon-choice img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.icon-choice.sel { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-tint); }
.nav-item {
    display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--ink-soft); font-size: 13.5px; font-weight: 500; line-height: 1; position: relative;
}
.nav-item:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.nav-count { margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    background: var(--brand-2); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 18px; text-align: center; }
.nav-item.active { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.nav-item.active::before {
    content: ""; position: absolute; left: -12px; top: 6px; bottom: 6px; width: 3px;
    border-radius: 0 3px 3px 0; background: var(--brand-2);
}
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9;
    stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
/* Inline line-icon used in button/link/cell text in place of emoji glyphs. */
.ico-inline { width: 1.05em; height: 1.05em; vertical-align: -0.16em; margin-right: .12em; opacity: .85; }

/* ============================================================ Topbar */
.topbar {
    position: fixed; top: 0; left: var(--sb-w); right: 0; height: var(--tb-h); z-index: 20;
    background: var(--topbar-bg); backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 0 24px;
    transition: left .18s ease;
}
.sb-toggle { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 9px;
    border: 1px solid var(--line); background: var(--field-bg); cursor: pointer; color: var(--ink-soft); flex: none; padding: 0; }
.sb-toggle:hover { background: var(--line-soft); color: var(--ink); }
.sb-toggle-ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.search { position: relative; flex: 1; max-width: 520px; }
.search-ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px;
    fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.search input {
    width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 9px; background: var(--input-bg);
    padding: 0 14px 0 38px; font-size: 13.5px; font-family: inherit; color: var(--ink); outline: none;
}
.search input:focus { background: var(--field-bg); border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.search-suggest { position: absolute; top: 46px; left: 0; right: 0; z-index: 40; }
.suggest-panel { background: var(--pop-bg); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); overflow: hidden; max-height: 70vh; overflow-y: auto; padding-bottom: 4px; }
.suggest-group-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); padding: 10px 14px 4px; }
.suggest-item { display: flex; align-items: center; gap: 10px; padding: 8px 14px; color: var(--ink); }
.suggest-item:hover { background: var(--brand-tint); text-decoration: none; }
.suggest-item .s-title { font-weight: 600; font-size: 13px; }
.suggest-item .s-sub { color: var(--muted); font-size: 12px; }
.suggest-empty { padding: 14px; color: var(--muted); font-size: 13px; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.mywork-btn { position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px;
    border-radius: 9px; color: var(--ink-soft); }
.mywork-btn:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.mywork-ico { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.mywork-badge { position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 999px; background: var(--brand-2); color: #fff; font-size: 10.5px; font-weight: 700;
    line-height: 16px; text-align: center; }

/* Contextual page-help "?" button + modal */
.help-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 9px;
    border: 0; background: transparent; color: var(--ink-soft); cursor: pointer; }
.help-btn:hover { background: var(--line-soft); color: var(--ink); }
.help-ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.help-dialog { width: min(560px, 94vw); max-height: 88vh; padding: 0; border: 1px solid var(--line);
    border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
.help-dialog:not([open]) { display: none; }
.help-dialog[open] { display: flex; flex-direction: column; }
.help-dialog::backdrop { background: rgba(6,10,16,.55); }
.help-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 15px 18px; border-bottom: 1px solid var(--line); }
.help-head h2 { margin: 0; font-size: 1.05rem; }
.help-close { border: 0; background: transparent; color: var(--muted); font-size: 17px; cursor: pointer;
    width: 30px; height: 30px; border-radius: 8px; }
.help-close:hover { background: var(--line-soft); color: var(--ink); }
.help-body { padding: 16px 18px; overflow: auto; }
.help-summary { margin: 0 0 6px; color: var(--ink-soft); line-height: 1.5; }
.help-body h3 { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 6px; }
.help-steps, .help-tips { margin: 0; padding-left: 20px; }
.help-steps li { margin: 6px 0; line-height: 1.45; }
.help-tips li { margin: 6px 0; line-height: 1.45; color: var(--ink-soft); }
.help-foot { display: flex; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }
.help-link { color: var(--accent); font-weight: 600; text-decoration: none; border-bottom: 1px solid transparent; }
.help-link:hover { border-bottom-color: currentColor; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; display: flex; align-items: center; gap: 9px; cursor: pointer;
    padding: 5px 8px 5px 5px; border-radius: 9px; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: var(--line-soft); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; flex: none;
    display: inline-grid; place-items: center; font-size: 11.5px; font-weight: 700; text-transform: uppercase; overflow: hidden; }
.uname { font-size: 13.5px; font-weight: 550; color: var(--ink); }
.chev { width: 15px; height: 15px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.usermenu-pop {
    position: absolute; right: 0; top: 44px; min-width: 190px; background: var(--pop-bg); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 40;
}
.usermenu-pop a, .usermenu-pop button {
    display: block; width: 100%; text-align: left; padding: 9px 11px; border-radius: var(--radius-sm);
    font-size: 13.5px; color: var(--ink); background: none; border: none; cursor: pointer; font-family: inherit;
}
.usermenu-pop a:hover, .usermenu-pop button:hover { background: var(--line-soft); text-decoration: none; }
.usermenu-pop form { margin: 0; }
.usermenu-sep { height: 1px; background: var(--line); margin: 5px 4px; }

/* ============================================================ Command palette (⌘K) */
.cmdk { position: fixed; inset: 0; z-index: 200; background: rgba(8,14,22,.5); display: flex;
    align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; }
.cmdk-box { width: 100%; max-width: 580px; background: var(--pop-bg); border: 1px solid var(--line);
    border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.cmdk-input { width: 100%; border: none; border-bottom: 1px solid var(--line); padding: 16px 18px;
    font-size: 15px; font-family: inherit; color: var(--ink); background: transparent; outline: none; }
.cmdk-list { max-height: 52vh; overflow: auto; padding: 6px; }
.cmdk-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 12px;
    border-radius: 8px; cursor: pointer; font-size: 13.6px; color: var(--ink); }
.cmdk-item.active { background: var(--brand-tint); }
.cmdk-hint { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; flex: none; }
.cmdk-empty { padding: 18px; color: var(--muted); text-align: center; }
.cmdk-foot { display: flex; gap: 16px; padding: 9px 16px; border-top: 1px solid var(--line);
    font-size: 11.5px; color: var(--muted); }
.kbd { display: inline-block; min-width: 18px; text-align: center; padding: 1px 5px; border: 1px solid var(--line);
    border-bottom-width: 2px; border-radius: 5px; background: var(--input-bg); font-size: 11px; font-family: var(--font); color: var(--ink-soft); }
.search-kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }
/* Shortcuts help */
.help-modal { position: fixed; inset: 0; z-index: 200; background: rgba(8,14,22,.5); display: flex;
    align-items: center; justify-content: center; padding: 16px; }
.help-card { background: var(--pop-bg); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg);
    width: 100%; max-width: 420px; padding: 20px 22px; }
.help-card h3 { margin: 0 0 14px; font-size: 15px; }
.help-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; font-size: 13.5px; border-bottom: 1px solid var(--line-soft); }
.help-row:last-child { border-bottom: none; }

/* ============================================================ Content */
.content { margin-left: var(--sb-w); padding: calc(var(--tb-h) + 24px) 32px 64px; max-width: 1260px; transition: margin-left .18s ease; }
.content-narrow { max-width: 780px; }
.messages:empty { display: none; }
.page-head { margin-bottom: 20px; }
.page-head h1 { margin-bottom: 3px; }
.page-head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; align-items: center; }

/* ============================================================ Cards */
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow-sm); color: var(--ink); transition: transform .1s, box-shadow .1s, border-color .1s; }
.card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: #d4dbe6; }
.card-metric { float: right; text-align: right; line-height: 1.05; }
.card-metric span { font-size: 27px; font-weight: 700; color: var(--brand-2); letter-spacing: -.02em; }
.card-metric small { display: block; font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.card-title { font-weight: 650; font-size: 15.5px; margin-bottom: 5px; color: var(--brand); }
.card-desc { font-size: 13px; color: var(--ink-soft); }
.status-strip { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 10px; }
.pill { font-size: 12px; padding: 5px 11px; border-radius: 999px; background: var(--chip-bg); color: var(--ink-soft); border: 1px solid var(--line); }
.pill-ok { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-line); }

/* ============================================================ Data grid */
.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.grid thead th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
    color: var(--muted); background: var(--thead-bg); padding: 11px 15px; border-bottom: 1px solid var(--line); font-weight: 650; }
.grid tbody td { padding: var(--row-density) 15px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; vertical-align: middle; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr:hover { background: var(--row-hover); }
.grid .empty { text-align: center; color: var(--muted); padding: 44px 20px; }
.grid td.empty::before { content: ""; display: block; width: 40px; height: 40px; margin: 0 auto 12px; opacity: .55;
    background: no-repeat center / contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 12h-6l-2 3h-4l-2-3H2'/%3E%3Cpath d='M5.45 5.11L2 12v6a2 2 0 002 2h16a2 2 0 002-2v-6l-3.45-6.89A2 2 0 0016.76 4H7.24a2 2 0 00-1.79 1.11z'/%3E%3C/svg%3E"); }

/* ============================================================ Badges */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
    vertical-align: middle; white-space: nowrap; background: var(--chip-bg); color: var(--chip-ink); border: 1px solid var(--chip-line); }
.badge-draft, .badge-initiated, .badge-open, .badge-new, .badge-planned { background: var(--chip-bg); color: var(--chip-ink); border-color: var(--chip-line); }
.badge-in_review, .badge-under_review, .badge-investigation, .badge-action_plan, .badge-implementation,
.badge-effectiveness_check, .badge-dispositioned, .badge-in_production, .badge-printing, .badge-washing,
.badge-post_curing, .badge-inspection, .badge-issued, .badge-ready, .badge-partially_received, .badge-shipped, .badge-invoiced {
    background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.badge-effective, .badge-closed, .badge-completed, .badge-received, .badge-qc_released, .badge-paid { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-line); }
.badge-obsolete, .badge-cancelled, .badge-failed { background: var(--line-soft); color: var(--muted); border-color: var(--line); }
.badge-obsolete { text-decoration: line-through; }
.badge-rejected, .badge-critical { background: var(--err-bg); color: var(--err-ink); border-color: var(--err-line); }
.badge-rev { background: var(--brand-tint); color: var(--brand); border-color: var(--chip-line); }
.badge-state { background: var(--chip-bg); color: var(--chip-ink); border-color: var(--chip-line); }
.badge-minor { background: var(--chip-bg); color: var(--chip-ink); border-color: var(--chip-line); }
.badge-major { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
/* material lot statuses */
.badge-in_quarantine { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.badge-released { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-line); }
.badge-in_use { background: var(--brand-tint); color: var(--brand); border-color: var(--chip-line); }
.badge-consumed, .badge-disposed { background: var(--line-soft); color: var(--muted); border-color: var(--line); }
.badge-disposed { text-decoration: line-through; }
.expired { color: var(--err-ink); font-weight: 600; }

/* ============================================================ Panels / detail */
.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 17px 19px; box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 0 0 12px; font-weight: 650; }
.panel-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head-row .panel-title { margin: 0; }
.empty-cta { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 28px 16px; }
/* Reusable empty-state block (fragments/ui :: emptyState / emptyStateCta). */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; gap: 8px; padding: 40px 20px; color: var(--muted); }
.empty-state-ico { width: 40px; height: 40px; opacity: .55; margin-bottom: 4px; }
.empty-state-title { margin: 0; font-size: 14.5px; font-weight: 600; color: var(--ink-soft); }
.empty-state-hint { margin: 0; font-size: 13px; max-width: 380px; }
.empty-state .btn { margin-top: 8px; }
.doc-title { font-size: 15px; color: var(--ink-soft); margin: 5px 0 0; }
.meta { display: grid; grid-template-columns: 140px 1fr; gap: 9px 14px; margin: 0; }
.meta dt { color: var(--muted); font-size: 13px; }
.meta dd { margin: 0; font-size: 13.5px; }
/* Document/SOP content reads like a document (proportional type); JS reflows
   plain-text paragraphs into <p> so seeded hard-wrapped text isn't ragged. */
.doc-content { white-space: pre-wrap; word-wrap: break-word; font-family: var(--font);
    font-size: 14px; line-height: 1.7; color: var(--ink); background: var(--field-bg); border: 1px solid var(--line);
    border-radius: var(--radius-sm); padding: 20px 22px; margin: 0; max-height: 540px; overflow: auto;
    background: var(--surface); }
.doc-content.reflowed { white-space: normal; }
.doc-content p { margin: 0 0 12px; }
.doc-content p:last-child { margin-bottom: 0; }
.doc-content p.doc-h { font-weight: 700; color: var(--brand); margin-top: 4px; }
.doc-content p.doc-li, .learn-body p.doc-li { padding-left: 14px; text-indent: -10px; margin: 0 0 4px; }
.learn-body p { margin: 0 0 12px; }
.learn-body p.doc-h { font-weight: 700; color: var(--brand); }
.learn-body.reflowed { white-space: normal; }

/* Horizontal-scroll wrapper for wide tables on small screens */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Catch-all: no table grows the page unbounded — tall tables scroll within a cap, header stays. */
.table-wrap { max-height: 72vh; overflow-y: auto; }
.table-wrap > table.grid > thead th { position: sticky; top: 0; z-index: 2;
    background: var(--thead-bg); }

/* Dismissible flash messages */
.alert { position: relative; padding-right: 36px; transition: opacity .4s ease; }
.alert.fade { opacity: 0; }
.alert-x { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); width: 22px; height: 22px;
    border: none; background: none; cursor: pointer; font-size: 18px; line-height: 1; color: inherit; opacity: .5; border-radius: 5px; }
.alert-x:hover { opacity: 1; background: rgba(0,0,0,.06); }

/* Breadcrumbs */
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 9px; display: flex; align-items: center; gap: 7px; }
.crumbs a { color: var(--ink-soft); }
.crumbs a:hover { color: var(--brand-2); text-decoration: none; }
.crumb-sep { color: #c7cdd8; }
.crumb-cur { color: var(--ink-soft); font-weight: 600; }

.actionbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 20px; }
.inline { display: inline; margin: 0; }
.reason-form { display: inline-flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.reason-form input, .reason-form select { border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 8px 10px; font-size: 13px; font-family: inherit; background: var(--field-bg); color: var(--ink); }
.reason-form input::placeholder { color: var(--muted); }
.reason-form input:focus, .reason-form select:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.reason-form input[type=text] { min-width: 220px; }

/* File inputs — the native "Choose File" button is OS-white and ignores the
   theme, so re-skin it (and the "no file chosen" label) with theme tokens. */
input[type=file] { color: var(--ink-soft); font-size: 13px; max-width: 100%; }
input[type=file]::file-selector-button {
    margin-right: 12px; padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 600;
    color: var(--ink); background: var(--input-bg); border: 1px solid var(--line);
    border-radius: var(--radius-sm); cursor: pointer; transition: background .12s, border-color .12s, color .12s; }
input[type=file]::file-selector-button:hover {
    background: var(--brand-tint); border-color: var(--brand-2); color: var(--brand); }
/* The bordered drop area some uploaders wrap the input in. */
.file-field { display: block; padding: 14px; border: 1px dashed var(--line); border-radius: var(--radius-sm);
    background: var(--field-bg); }

/* Audit-trail panel header + "Full audit trail" modal (native <dialog>). */
.audit-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.audit-head .panel-title { margin: 0; }
dialog.modal { width: min(1120px, 95vw); max-width: 95vw; max-height: 90vh; padding: 0;
    border: 1px solid var(--line); border-radius: 12px;
    background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px rgba(0,0,0,.45); overflow: hidden; }
/* A closed <dialog> must stay hidden — our display:flex would otherwise override the
   UA `dialog:not([open]){display:none}`, leaking the modal inline onto the page. */
dialog.modal:not([open]) { display: none; }
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal::backdrop { background: rgba(6,10,16,.55); }
.modal-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 13px 18px; border-bottom: 1px solid var(--line); background: var(--thead-bg); }
.modal-title { margin: 0; font-size: 15px; }
.modal-actions { display: flex; align-items: center; gap: 6px; }
.modal-close-form { display: inline; margin: 0; padding: 0; border: 0; background: none; }
.modal-body { flex: 1 1 auto; overflow: auto; padding: 16px 18px; }
.modal-body .table-wrap { max-height: none; overflow: visible; }

/* Textarea "Maximize" affordance + large editor modal */
.ta-max-wrap { position: relative; display: block; }
.ta-max-wrap > textarea { width: 100%; box-sizing: border-box; }
.ta-max-btn { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; display: grid; place-items: center;
    padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink-soft);
    cursor: pointer; opacity: .5; transition: opacity .12s, color .12s, border-color .12s; }
.ta-max-wrap:hover .ta-max-btn, .ta-max-btn:focus-visible { opacity: 1; }
.ta-max-btn:hover { color: var(--brand-2); border-color: var(--brand-2); }
.ta-max-btn .ico { width: 15px; height: 15px; }
/* Inline maximize icon-button (same affordance as .ta-max-btn, used in panel headers e.g. Document content). */
.btn-maximize { display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0; flex: none;
    border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink-soft);
    cursor: pointer; transition: color .12s, border-color .12s, background .12s; }
.btn-maximize:hover { color: var(--brand-2); border-color: var(--brand-2); background: var(--brand-tint); }
.btn-maximize .ico { width: 15px; height: 15px; }
.ta-modal-text { width: 100%; box-sizing: border-box; min-height: 62vh; resize: vertical; font: inherit;
    background: var(--field-bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
    padding: 12px; line-height: 1.5; }
.ta-modal-foot { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 8px;
    padding: 10px 18px 14px; border-top: 1px solid var(--line); }
.ta-head-btns { display: flex; align-items: center; gap: 8px; }
.ta-ai-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px;
    border: 1px solid var(--chip-line, var(--brand-2)); background: var(--brand-tint); color: var(--brand);
    font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: filter .12s, background .12s, color .12s; }
.ta-ai-btn[hidden] { display: none; }
.ta-ai-btn:hover { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.ta-ai-btn .ico { width: 15px; height: 15px; flex: none; }

/* ============================================================ Field-assist (inline AI on form fields) */
.fa-wrap { position: relative; display: block; }
.fa-wrap > textarea { width: 100%; box-sizing: border-box; }
.fa-btn { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; display: grid; place-items: center;
    padding: 0; border: 1px solid var(--brand-tint); border-radius: 6px; background: var(--surface); color: var(--brand-2);
    cursor: pointer; opacity: .6; transition: opacity .12s, color .12s, background .12s, border-color .12s; }
.fa-wrap:hover .fa-btn, .ta-max-wrap:hover .fa-btn, .fa-btn:focus-visible { opacity: 1; }
.fa-btn:hover { color: #fff; background: var(--brand-2); border-color: var(--brand-2); }
.fa-btn .ico { width: 15px; height: 15px; }

/* Field-assist modal (override dialog.modal's wide default with a higher-specificity selector). */
dialog.fa-modal { width: min(600px, 94vw); max-width: 94vw; max-height: 88vh; }
.fa-head { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 15px 18px;
    border-bottom: 1px solid var(--line); background: linear-gradient(115deg, var(--brand-tint), transparent 72%); }
.fa-head-badge { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 10px;
    background: linear-gradient(135deg, var(--brand-2), var(--brand)); box-shadow: 0 5px 14px rgba(16,58,94,.28); }
.fa-head-badge .ico { width: 19px; height: 19px; stroke: #fff; }
.fa-head-titles { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.fa-head-title { font-weight: 700; font-size: 14.5px; color: var(--ink); line-height: 1.2; }
.fa-head-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fa-head-btns { display: flex; align-items: center; gap: 4px; flex: none; }
.fa-x, .fa-max { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px;
    background: transparent; color: var(--muted); cursor: pointer; }
.fa-x:hover, .fa-max:hover { background: rgba(0,0,0,.07); color: var(--ink); }
.fa-x .ico { width: 17px; height: 17px; }
.fa-max .ico { width: 16px; height: 16px; }
/* Maximized: fill the viewport and let the suggestion editor grow. Higher specificity beats dialog.fa-modal. */
dialog.fa-modal.fa-modal--max { width: 96vw; max-width: 96vw; height: 94vh; max-height: 94vh; }
.fa-modal--max .fa-body { flex: 1 1 auto; }
.fa-modal--max .fa-result { flex: 1 1 auto; }
.fa-modal--max .fa-empty { flex: 1 1 auto; }
.fa-modal--max .fa-preview-wrap:not([hidden]) { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.fa-modal--max .fa-preview { flex: 1 1 auto; min-height: 0; resize: none; }
.fa-body { flex: 1 1 auto; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 13px; }
.fa-hint { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 9px;
    background: var(--brand-tint); color: var(--brand); font-size: 12.5px; }
.fa-hint[hidden] { display: none; }
.fa-hint .ico { width: 15px; height: 15px; flex: none; }
.fa-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.fa-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px 7px 11px; border-radius: 9px;
    border: 1px solid var(--line); background: var(--field-bg); color: var(--ink-soft); font: inherit; font-size: 12.5px;
    font-weight: 600; cursor: pointer; transition: border-color .12s, background .12s, color .12s; }
.fa-chip .ico { width: 14px; height: 14px; flex: none; opacity: .85; }
.fa-chip:hover { border-color: var(--brand-2); color: var(--brand); background: var(--brand-tint); }
.fa-chip[data-action="improve"] { border-color: var(--chip-line, var(--brand-2)); color: var(--brand); background: var(--brand-tint); }
.fa-chip:disabled { opacity: .5; cursor: default; }
.fa-custom { position: relative; display: flex; gap: 8px; align-items: center; }
.fa-custom > .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px;
    color: var(--brand-2); pointer-events: none; }
.fa-instruction { flex: 1 1 auto; height: 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--input-bg);
    padding: 0 12px 0 34px; font: inherit; font-size: 13px; color: var(--ink); outline: none; }
.fa-instruction:focus { background: var(--field-bg); border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.fa-run { flex: none; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--brand-2);
    background: var(--brand-2); color: #fff; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.fa-run:hover { filter: brightness(1.07); }
.fa-run:disabled { opacity: .5; cursor: default; }
.fa-result { position: relative; display: flex; flex-direction: column; min-height: 168px; }
.fa-empty { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 11px;
    padding: 24px 22px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; }
.fa-empty[hidden] { display: none; }
.fa-empty-ico { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: var(--brand-tint); }
.fa-empty-ico .ico { width: 21px; height: 21px; color: var(--brand-2); }
.fa-empty p { margin: 0; font-size: 12.5px; max-width: 330px; line-height: 1.5; }
/* Generating: dim the current content (preview/empty) and overlay a pulsing icon in the centre. */
.fa-result.is-loading > :not(.fa-loading) { opacity: .35; filter: blur(.4px); pointer-events: none; transition: opacity .2s; }
.fa-loading { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }
.fa-result.is-loading .fa-loading { display: flex; }
.fa-loading-ico { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%;
    background: var(--brand-tint); color: var(--brand-2); animation: fa-pulse 1.2s ease-in-out infinite; }
.fa-loading-ico .ico { width: 26px; height: 26px; animation: fa-rotate 2.6s linear infinite; }
@keyframes fa-pulse { 0%, 100% { transform: scale(.9); opacity: .65; } 50% { transform: scale(1.07); opacity: 1; } }
@keyframes fa-rotate { to { transform: rotate(360deg); } }
.fa-error { background: var(--err-bg); color: var(--err-ink); border: 1px solid var(--err-line);
    border-radius: 9px; padding: 9px 12px; font-size: 13px; }
.fa-preview-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.fa-preview-head > span:first-child { font-weight: 650; font-size: 13px; color: var(--ink); }
.fa-edit-note { margin-left: auto; }
.fa-preview { width: 100%; box-sizing: border-box; resize: vertical; min-height: 170px; font: inherit; font-size: 13.5px;
    line-height: 1.6; background: var(--field-bg); color: var(--ink); border: 1px solid var(--brand-2);
    border-radius: 10px; padding: 12px; box-shadow: 0 0 0 3px var(--brand-tint); }
.fa-foot { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 12px 18px 14px; border-top: 1px solid var(--line); }
.fa-foot-right { display: flex; gap: 8px; }

/* Floating AI assistant widget */
.ai-asst { position: fixed; right: 20px; bottom: 20px; z-index: 1200; }
.ai-asst-fab { width: 52px; height: 52px; border-radius: 50%; border: none; cursor: pointer;
    background: var(--brand-2); color: #fff; display: grid; place-items: center;
    box-shadow: 0 6px 20px rgba(6,10,16,.28); transition: transform .12s, box-shadow .12s; }
.ai-asst-fab:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(6,10,16,.34); }
.ai-asst-fab .ico { width: 24px; height: 24px; stroke: #fff; opacity: 1; }
.ai-asst.is-open .ai-asst-fab { display: none; }
.ai-asst-panel { position: absolute; right: 0; bottom: 0; width: min(380px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 110px)); background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(6,10,16,.30);
    display: flex; flex-direction: column; overflow: hidden; }
.ai-asst-panel[hidden] { display: none; }
/* Maximize: a larger chat window (toggled by the header button; chat is preserved). */
.ai-asst--max .ai-asst-panel { width: min(960px, calc(100vw - 40px)); height: min(88vh, calc(100vh - 40px)); }
.ai-asst-head { flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
    padding: 10px 12px 10px 14px; border-bottom: 1px solid var(--line); }
.ai-asst-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none;
    background: var(--field-bg); border: 1px solid var(--line); }
.ai-asst-id { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.ai-asst-title { font-weight: 600; font-size: 14px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-asst-spec { border: none; background: none; padding: 0; margin: 1px 0 0; cursor: pointer;
    display: flex; align-items: center; gap: 3px; color: var(--muted); font-size: 11.5px; max-width: 100%; }
.ai-asst-spec span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-asst-spec .ico { width: 13px; height: 13px; flex: none; transition: transform .15s; }
.ai-asst-spec[aria-expanded="true"] .ico { transform: rotate(180deg); }
.ai-asst-model { display: flex; align-items: center; gap: 3px; margin: 1px 0 0; max-width: 100%;
    color: var(--muted); font-size: 11px; opacity: .85; }
.ai-asst-model .ico { width: 12px; height: 12px; flex: none; }
.ai-asst-model span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-asst-desc { flex: 0 0 auto; padding: 9px 14px; border-bottom: 1px solid var(--line);
    color: var(--ink-soft); font-size: 12.5px; line-height: 1.5; }
.ai-asst-head-btns { display: flex; align-items: center; gap: 2px; }

/* ============================================================ Eligium model picker (plugin page) */
.ai-pick-label { display: block; font-size: 11.5px; font-weight: 650; text-transform: uppercase;
    letter-spacing: .4px; color: var(--muted); margin: 12px 0 7px; }
.ai-bubble-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.ai-bubble { position: relative; display: flex; flex-direction: column; gap: 2px; flex: 1 1 132px;
    min-width: 132px; max-width: 190px; padding: 10px 12px; text-align: left; cursor: pointer;
    border: 1.5px solid var(--line); border-radius: 12px; background: var(--field-bg);
    transition: border-color .12s, background .12s, box-shadow .12s; font: inherit; }
.ai-bubble:hover { border-color: var(--brand-2); }
.ai-bubble.is-sel { border-color: var(--brand-2); background: var(--brand-tint); box-shadow: 0 0 0 3px var(--brand-tint); }
.ai-bubble.is-off { opacity: .5; }
.ai-bubble-name { display: flex; align-items: center; gap: 7px; font-weight: 650; font-size: 13.5px;
    color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-bubble-name .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--ok-ink); }
.ai-bubble.is-off .ai-bubble-name .dot { background: var(--muted); }
.ai-bubble-sub { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-bubble-check { position: absolute; top: 8px; right: 9px; width: 15px; height: 15px; fill: none;
    stroke: var(--brand-2); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity .12s; }
.ai-bubble.is-sel .ai-bubble-check { opacity: 1; }
.ai-chip-search { position: relative; margin: 0 0 8px; }
.ai-chip-search-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px;
    fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.ai-chip-search input { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 9px;
    background: var(--input-bg); padding: 0 12px 0 37px; font: inherit; font-size: 13px; color: var(--ink); outline: none; }
.ai-chip-search input:focus { background: var(--field-bg); border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.ai-chip-wrap { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; max-height: 196px; overflow-y: auto;
    padding: 9px; border: 1px solid var(--line); border-radius: 11px; background: var(--input-bg); }
.ai-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; cursor: pointer; font: inherit;
    font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; border: 1.5px solid var(--line);
    border-radius: 999px; background: var(--field-bg); transition: border-color .1s, background .1s, color .1s; }
.ai-chip:hover { border-color: var(--brand-2); color: var(--ink); }
.ai-chip.is-sel { background: var(--brand-2); border-color: var(--brand-2); color: #fff; font-weight: 600; }
.ai-chip-def { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 1px 5px;
    border-radius: 6px; background: var(--brand-tint); color: var(--brand); }
.ai-chip.is-sel .ai-chip-def { background: rgba(255,255,255,.24); color: #fff; }
.ai-chip-empty { color: var(--muted); font-size: 12px; padding: 6px 4px; }
.ai-asst-max, .ai-asst-min, .ai-asst-x { border: none; background: none; cursor: pointer; color: var(--muted);
    display: grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; line-height: 1; }
.ai-asst-max:hover, .ai-asst-min:hover, .ai-asst-x:hover { color: var(--ink); background: var(--field-bg); }
.ai-asst-x { font-size: 15px; }
.ai-asst-max .ico, .ai-asst-min .ico { width: 16px; height: 16px; }
.ai-asst-log { flex: 1 1 auto; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.ai-asst-msg { max-width: 85%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.5;
    white-space: pre-wrap; word-wrap: break-word; }
.ai-asst-bot { align-self: flex-start; background: var(--field-bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
/* Markdown rendered inside an agent answer */
.ai-asst-bot p { margin: 0 0 6px; }
.ai-asst-bot p:last-child { margin-bottom: 0; }
.ai-asst-bot ul, .ai-asst-bot ol { margin: 4px 0 6px; padding-left: 20px; }
.ai-asst-bot li { margin: 2px 0; }
.ai-asst-bot code { background: var(--line-soft); padding: 1px 5px; border-radius: 4px; font-size: 12.5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ai-asst-bot pre { background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
    padding: 8px 10px; margin: 4px 0; overflow-x: auto; }
.ai-asst-bot pre code { background: none; padding: 0; font-size: 12px; }
.ai-asst-bot a { color: var(--brand-2); }
.ai-asst-me { align-self: flex-end; background: var(--brand-2); color: #fff; border-bottom-right-radius: 4px; }
.ai-asst-pending { color: var(--muted); }
.ai-asst-err { color: var(--err-ink); border-color: var(--err-line); }
/* Composer: one rounded box (border + focus ring), borderless textarea on top, an action bar below. */
.ai-asst-form { flex: 0 0 auto; margin: 10px 12px 12px; display: flex; flex-direction: column;
    border: 1px solid var(--line); border-radius: 14px; background: var(--field-bg);
    transition: border-color .15s, box-shadow .15s; }
.ai-asst-form:focus-within { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.ai-asst-form textarea { border: none; outline: none; background: transparent; color: var(--ink);
    resize: none; font: inherit; line-height: 1.45; padding: 10px 12px 2px; min-height: 22px; max-height: 120px;
    overflow-y: auto; }
.ai-asst-form textarea::placeholder { color: var(--muted); }
.ai-asst-form-bar { display: flex; align-items: center; gap: 8px; padding: 4px 8px 8px; }
.ai-asst-form-bar #aiAsstSend { margin-left: auto; height: 32px; padding: 0 16px; border-radius: 9px; }
.ai-asst-mic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer;
    transition: color .12s, border-color .12s, background .12s; }
.ai-asst-mic .ico { width: 17px; height: 17px; }
.ai-asst-mic:hover { color: var(--brand-2); border-color: var(--brand-2); background: var(--brand-tint); }
.ai-asst-mic.recording { color: #fff; background: var(--err-ink); border-color: var(--err-ink);
    animation: aiMicPulse 1.25s infinite; }
.ai-asst-mic-busy { opacity: .55; cursor: default; }
@keyframes aiMicPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(200, 40, 40, .45); }
    50% { box-shadow: 0 0 0 5px rgba(200, 40, 40, 0); }
}
.audit-modal-meta { margin: 0 0 10px; }

/* Per-column filter row (data-colfilter) — a control under each header. */
tr.filter-row th { padding: 5px 6px; background: var(--thead-bg); position: static; top: auto;
    border-bottom: 1px solid var(--line); }
.colf-input, .colf-select { width: 100%; box-sizing: border-box; font-size: 12px; padding: 4px 7px;
    border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--field-bg); color: var(--ink);
    font-family: inherit; }
.colf-input::placeholder { color: var(--muted); }
.colf-input:focus, .colf-select:focus { outline: none; border-color: var(--brand-2);
    box-shadow: 0 0 0 2px var(--brand-tint); }

.sig-list, .audit-list, .rev-list { list-style: none; margin: 0; padding: 0; }
.sig-list li { padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; }
.sig-list li:last-child { border-bottom: none; }
.sig-meaning { display: inline-block; font-size: 11px; font-weight: 600; color: var(--brand); background: var(--brand-tint);
    border-radius: 999px; padding: 2px 8px; margin-right: 4px; }
.audit-list li { padding: 11px 0; border-bottom: 1px dashed var(--line); }
.audit-list li:last-child { border-bottom: none; }
.audit-list .why { margin-top: 3px; color: var(--ink-soft); font-style: italic; }
.audit-changes { list-style: none; margin: 6px 0 0; padding: 7px 10px; background: var(--input-bg);
    border: 1px solid var(--line); border-radius: var(--radius-sm); display: flex; flex-direction: column; gap: 3px; }
.audit-changes li { font-size: 12.5px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.audit-changes .ac-field { font-weight: 600; color: var(--ink-soft); }
.audit-changes .ac-old { color: var(--err-ink); text-decoration: line-through; }
.audit-changes .ac-arrow { color: var(--muted); }
.audit-changes .ac-new { color: var(--ok-ink); font-weight: 600; }
.rev-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; }

/* ============================================================ Forms */
.form { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm); }
.form label { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 13px 0 5px; }
.form label:first-of-type { margin-top: 0; }
/* Required-field marker: a red asterisk on any label immediately followed by a required
   control. Progressive enhancement (:has) — purely visual; the `required` attribute already
   conveys the requirement to assistive tech. Optional fields stay unmarked. */
.form label:has(+ input:required)::after,
.form label:has(+ select:required)::after,
.form label:has(+ textarea:required)::after { content: " *"; color: var(--err-ink); font-weight: 700; }
.form input, .form select, .form textarea { border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 10px 12px; font-size: 14px; font-family: inherit; color: var(--ink); background: var(--field-bg); }
.form textarea { resize: vertical; line-height: 1.5; }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
/* Stack label + field even when the form's fields are nested inside panels (e.g. management review,
   build inspection). Without this, nested label/textarea flow inline and scatter. Checkboxes/radios
   and .check labels keep their inline layout. */
.form label:not(.check) { display: block; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea { display: block; width: 100%; box-sizing: border-box; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.field-error { color: var(--err-ink); font-size: 12.5px; margin-top: 4px; }

/* Part-type picker — trigger + popup of image "bubbles" (build planner) */
.pt-field { position: relative; }
.pt-trigger { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
    border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--field-bg);
    color: var(--ink); padding: 7px 12px; font: inherit; cursor: pointer; min-height: 44px; }
.pt-trigger:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.pt-trigger.is-empty .pt-trigger-label { color: var(--muted); }
.pt-trigger.is-invalid { border-color: var(--err-ink, #c0392b); box-shadow: 0 0 0 3px rgba(192,57,43,.15); }
.pt-trigger-media { flex: none; width: 30px; height: 30px; border-radius: 8px; overflow: hidden;
    background: var(--brand-tint); display: flex; align-items: center; justify-content: center; }
.pt-trigger.is-empty .pt-trigger-media { display: none; }
.pt-trigger-media img { width: 100%; height: 100%; object-fit: contain; padding: 3px; box-sizing: border-box; }
.pt-trigger-media .pt-bubble-fallback { font-size: 13px; }
.pt-trigger-label { flex: 1 1 auto; }
.pt-trigger-chev { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--muted);
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.pt-popup { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50;
    background: var(--pop-bg); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 8px; max-height: 360px; overflow-y: auto; }
.pt-group-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); padding: 8px 6px 6px; }
/* Type-to-filter box for long bubble pickers (e.g. 10+ resin tanks). Sticky so it stays while scrolling. */
.pt-search { position: sticky; top: -8px; z-index: 2; box-sizing: border-box; width: 100%; margin: -2px 0 8px;
    padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--field-bg);
    color: var(--ink); font-size: 13px; }
.pt-search:focus { outline: none; border-color: var(--accent); }
.pt-bubbles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px; padding: 0 2px 6px; }
.pt-bubble { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 11px 8px;
    border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink);
    cursor: pointer; font: inherit; transition: border-color .1s, box-shadow .1s, transform .1s; }
.pt-bubble:hover { border-color: var(--brand-2); transform: translateY(-1px); }
.pt-bubble:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.pt-bubble.sel { border-color: var(--brand-2); box-shadow: 0 0 0 2px var(--brand-tint); }
.pt-bubble-media { width: 54px; height: 54px; border-radius: 50%; overflow: hidden; background: var(--brand-tint);
    display: flex; align-items: center; justify-content: center; }
.pt-bubble-media img { width: 100%; height: 100%; object-fit: contain; padding: 7px; box-sizing: border-box; }
.pt-bubble-fallback { font-size: 20px; font-weight: 700; color: var(--brand-2); text-transform: uppercase; }
.pt-bubble-name { font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.25; overflow-wrap: anywhere; }
/* Thin top progress bar shown while an htmx request is in flight (wired in ui.js). */
.htmx-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 2000;
    background: linear-gradient(90deg, var(--brand-2), var(--brand)); opacity: 0;
    transition: width .2s ease, opacity .2s ease; pointer-events: none; }
.htmx-progress.is-active { width: 85%; opacity: 1; transition: width 8s cubic-bezier(.1,.7,.1,1), opacity .2s ease; }
/* Subtle dimming of an element that triggered an in-flight htmx request. */
.htmx-request { opacity: .6; transition: opacity .15s ease; }

.pt-bubble-sub { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.2; overflow-wrap: anywhere; }
/* FEFO shelf-life cue on lot pickers: amber for expiring-soon, red for already expired. */
.pt-bubble-sub.pt-exp-warn { color: var(--warn-ink); font-weight: 600; }
.pt-bubble-sub.pt-exp-bad { color: var(--err-ink); font-weight: 600; }
.pt-empty { padding: 14px; color: var(--muted); font-size: 13px; }
/* "List rows" variant (icon left, title over description, check on the selected row) */
.pt-bubbles--rows { grid-template-columns: 1fr; }
.pt-bubbles--rows .pt-bubble { display: grid; grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto; column-gap: 12px; align-items: center; text-align: left; padding: 10px 12px; }
.pt-bubbles--rows .pt-bubble:hover { transform: none; }
.pt-bubbles--rows .pt-bubble-media { grid-row: 1 / 3; grid-column: 1; width: 36px; height: 36px; }
.pt-bubbles--rows .pt-bubble-media .thumb-ico { width: 18px; height: 18px; }
.pt-bubbles--rows .pt-bubble-name { grid-column: 2; text-align: left; align-self: end; }
.pt-bubbles--rows .pt-bubble-sub { grid-column: 2; text-align: left; align-self: start; }
.pt-bubbles--rows .pt-bubble::after { content: ''; grid-column: 3; grid-row: 1 / 3; width: 16px;
    color: var(--brand-2); font-weight: 800; font-size: 15px; text-align: center; }
.pt-bubbles--rows .pt-bubble.sel { background: var(--brand-tint); box-shadow: none; }
.pt-bubbles--rows .pt-bubble.sel::after { content: '\2713'; }
/* "Insert template" dropdown */
.tplfill { position: relative; display: inline-block; margin: 0 0 8px; }
.tplfill-menu { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 240px; max-width: 360px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(16,24,40,.12); padding: 6px; }
.tplfill-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: none;
    background: none; border-radius: 7px; font: inherit; color: var(--ink); cursor: pointer; }
.tplfill-item:hover { background: var(--brand-tint); color: var(--brand-2); }
/* Template editor: two-column layout with a Variables palette on the right */
.tpl-edit-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.tpl-edit-grid > .form { min-width: 0; }
@media (max-width: 900px) { .tpl-edit-grid { grid-template-columns: 1fr; } }
.varlist-panel { border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
    padding: 14px; position: sticky; top: 16px; max-height: calc(100vh - 90px); overflow: auto; }
.varlist-head { margin-bottom: 6px; }
.varlist-title { font-size: 14px; font-weight: 800; margin: 0 0 4px; }
.varlist-group-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); margin: 12px 0 6px; }
.var-bubble { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
    padding: 8px 9px; margin: 0 0 6px; border: 1px solid var(--line); border-radius: 10px;
    background: var(--field-bg); color: var(--ink); cursor: pointer; font: inherit; transition: all .12s; }
.var-bubble:hover { border-color: var(--brand-2); background: var(--brand-tint); }
.var-ico { flex: none; width: 30px; height: 30px; display: grid; place-items: center;
    border-radius: 8px; background: var(--line-soft); color: var(--ink-soft); }
.var-ico .ico { width: 18px; height: 18px; }
.var-bubble:hover .var-ico { background: var(--surface); color: var(--brand-2); }
.var-main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.var-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.var-name { font-weight: 700; font-size: 13px; }
.var-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px;
    color: var(--brand-2); background: var(--brand-tint); border-radius: 5px; padding: 0 5px; }
.var-desc { font-size: 11.5px; color: var(--muted); }
/* Breadcrumbs — clickable navigation trail at the top of each page */
.breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
    font-size: 12.5px; margin: 0 0 14px; color: var(--muted); }
.breadcrumbs a { color: var(--muted); text-decoration: none; padding: 2px 4px; border-radius: 6px; }
.breadcrumbs a:hover { color: var(--brand-2); background: var(--brand-tint); text-decoration: none; }
.breadcrumbs span[aria-current] { color: var(--ink); font-weight: 600; padding: 2px 4px; }
.crumb-sep { width: 14px; height: 14px; flex: none; fill: none; stroke: var(--muted);
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: .6; }
/* Small count badge in the sidebar nav (e.g. pending registrations) */
.nav-badge { margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--brand-2); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px;
    text-align: center; flex: none; }
/* Reuse the type-aware media thumb (image or default icon) inside picker bubbles/trigger */
.pt-bubble-media .thumb { width: 100%; height: 100%; background: transparent; border-radius: 50%; }
.pt-bubble-media .thumb-img { width: 100%; height: 100%; border-radius: 50%; }
.pt-bubble-media .thumb-ico { width: 26px; height: 26px; stroke: var(--brand-2); }
.pt-trigger-media .thumb { width: 100%; height: 100%; background: transparent; }
.pt-trigger-media .thumb-img { width: 100%; height: 100%; border-radius: 8px; }
.pt-trigger-media .thumb-ico { width: 18px; height: 18px; stroke: var(--brand-2); }
/* Lot picker: let the popup be wider than the trigger so lot labels fit */
.pt-popup--wide { right: auto; min-width: 320px; }

/* Two-column labelled field grid — reuses .form input/label tokens (theme-aware) */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; margin-top: 4px; }
.field-grid .field { display: flex; flex-direction: column; min-width: 0; }
.field-grid label { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 12px 0 5px; }
.field-grid input { width: 100%; box-sizing: border-box; border: 1px solid var(--line);
    border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; font-family: inherit;
    color: var(--ink); background: var(--field-bg); }
.field-grid input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.field-grid .field-group { grid-column: 1 / -1; font-size: 11px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--muted); margin: 16px 0 2px; }
.field-grid .field-group:first-child { margin-top: 6px; }
.checks { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }
.check { display: flex; align-items: baseline; gap: 8px; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; margin: 0; }
.check input { margin: 0; position: relative; top: 1px; }
.check small { font-weight: 400; }
.reject-form { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 14px; }

/* ============================================================ Buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: 9px 15px; font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit; transition: background .1s, box-shadow .1s; }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-primary { background: var(--brand-2); color: #fff; }
.btn-primary:hover { background: var(--brand); text-decoration: none; box-shadow: var(--shadow); }
.btn-primary:disabled:hover, .btn-primary[disabled]:hover { background: var(--brand-2); box-shadow: none; }
.btn-ghost { background: var(--field-bg); border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--line-soft); text-decoration: none; }

/* ============================================================ Alerts */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; }
.alert-error { background: var(--err-bg); color: var(--err-ink); border: 1px solid var(--err-line); }
.alert-ok { background: var(--ok-bg); color: var(--ok-ink); border: 1px solid var(--ok-line); }

/* ============================================================ E-signature */
.esign-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 4px 0 0; }
.esign-statement { background: #fff8ec; border: 1px solid var(--warn-line); border-radius: var(--radius-sm);
    margin: 16px; padding: 13px 15px; font-size: 13px; color: var(--warn-ink); }
/* Color-only urgency token used across lists (shelf-life, reorder, overdue analytics). */
.text-danger { color: var(--err-ink); }
/* A button rendered in its "disabled" state (e.g. "Send test" when mail is off) must also be inert. */
.btn.is-disabled, button.is-disabled { opacity: .5; pointer-events: none; cursor: not-allowed; }

/* ============================================================ Login */
.login-body { min-height: 100vh; margin: 0; background: linear-gradient(150deg, #0c2c47 0%, #2f6db5 100%); display: grid; place-items: center; }
.login-shell { width: 100%; max-width: 410px; padding: 24px; }
.login-card { background: var(--surface); border-radius: 16px; padding: 32px 30px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-title { font-size: 18px; }
.login-sub { font-size: 13px; color: var(--muted); }
.login-form { display: flex; flex-direction: column; }
.login-form label { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.login-form input { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 12px; font-size: 14px; margin-bottom: 16px; }
.login-form input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.login-form .btn { margin-top: 4px; justify-content: center; }
.login-foot { margin: 20px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ============================================================ Genealogy chain */
.chain { display: flex; flex-direction: column; align-items: flex-start; max-width: 640px; margin: 0 auto; }
.chain-title a:hover { text-decoration: underline; }
.chain-node { width: 100%; background: var(--field-bg); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 13px 16px; box-shadow: var(--shadow-sm); }
.chain-node.focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.chain-kind { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.chain-title { font-weight: 650; font-size: 15px; margin-top: 2px; }
.chain-title a { color: var(--ink); }
.chain-sub { color: var(--ink-soft); font-size: 13px; margin-top: 3px; }
.chain-arrow { width: 2px; height: 22px; background: #cdd6e2; margin-left: 26px; }
.chain-section { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
    color: var(--muted); margin: 22px 0 10px; }
.chain-branch { border-left: 2px dashed var(--line); margin-left: 26px; padding-left: 18px; margin: 10px 0; }
.chain-branch .chain-node { margin-bottom: 10px; }

/* ============================================================ Collapsed sidebar (manual toggle) */
html.sb-collapsed { --sb-w: 68px; }
html.sb-collapsed .brand { justify-content: center; padding: 16px 0; gap: 0; }
html.sb-collapsed .brand-text { display: none; }
html.sb-collapsed .nav-label { display: none; }
html.sb-collapsed .nav-group { margin-top: 8px; border-top: 1px solid var(--line-soft); padding-top: 8px; }
html.sb-collapsed .nav-item { justify-content: center; padding: 11px 0; }
html.sb-collapsed .nav-item span { display: none; }
html.sb-collapsed .nav-item.active::before { display: none; }

/* Floating label tooltip for collapsed nav icons (appended to <body>) */
.nav-tip { position: fixed; z-index: 100; transform: translateY(-50%);
    background: #1d2735; color: #fff; padding: 6px 11px; border-radius: 8px;
    font-size: 12.5px; font-weight: 500; line-height: 1; white-space: nowrap;
    box-shadow: var(--shadow-lg); pointer-events: none; opacity: 0;
    transition: opacity .1s ease; }
.nav-tip.show { opacity: 1; }
.nav-tip::before { content: ""; position: absolute; left: -3px; top: 50%;
    width: 8px; height: 8px; background: #1d2735; border-radius: 2px;
    transform: translateY(-50%) rotate(45deg); }

/* ============================================================ Responsive */
@media (max-width: 980px) { .detail-grid { grid-template-columns: 1fr; } }
/* Tablet: collapse the sidebar to a 62px icon rail (phones get the off-canvas drawer below). */
@media (min-width: 641px) and (max-width: 860px) {
    :root { --sb-w: 62px; }
    /* button.nav-label (group headers) needs the element-qualified selector to beat its own
       `button.nav-label{display:flex}` rule — otherwise the section labels clip in the 62px rail. */
    .brand-text, .nav-item span, .nav-label, button.nav-label, .uname { display: none; }
    .nav-item { justify-content: center; padding: 11px 0; }
    .nav-item.active::before { display: none; }
    .brand { justify-content: center; padding: 16px 0; }
    .content { padding-left: 16px; padding-right: 16px; }
    .search { max-width: none; }
}

/* Phone (<=640px): the sidebar becomes an off-canvas drawer slid in over a backdrop.
   We override the layout offsets directly (not via --sb-w) so the .sb-toggle that flips
   html.drawer-open wins regardless of any sb-collapsed state carried over from desktop. */
.drawer-backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 22, 30, .45); z-index: 50; }
@media (max-width: 640px) {
    .content { margin-left: 0; padding-left: 16px; padding-right: 16px; }
    .topbar { left: 0; }
    .search { max-width: none; }
    .sidebar {
        width: min(86vw, 290px); z-index: 60;
        transform: translateX(-100%);
        box-shadow: 2px 0 18px rgba(0, 0, 0, .22);
    }
    html.drawer-open .sidebar { transform: translateX(0); }
    html.drawer-open .drawer-backdrop { display: block; }
    /* Stack two-column form/detail grids to a single column for thumb-friendly entry. */
    .field-grid, .detail-grid, .tpl-edit-grid { grid-template-columns: 1fr; }
    .page-head-row { flex-wrap: wrap; gap: 10px; }
    /* Wide data tables scroll horizontally within their panel instead of overflowing the
       page (avoids wrapping all ~117 grids in .table-wrap; same effect, one rule). */
    table.grid { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Order fulfillment progress — segmented pill track */
.order-progress { min-width: 140px; }
.seg { display: flex; gap: 3px; width: 140px; }
.seg span { height: 7px; flex: 1; border-radius: 3px; background: var(--line); cursor: help; }
.seg span:hover { outline: 2px solid var(--brand-tint); outline-offset: 1px; }
.seg span.done { background: var(--ok-ink); }
.seg span.cur { background: var(--brand-2); }
.seg span.cancelled { background: var(--err-line); }
.seg-lab { font-size: 11.5px; color: var(--muted); margin-top: 5px; display: flex; gap: 6px; align-items: baseline; }
.seg-lab .seg-step { color: var(--muted); opacity: .7; font-variant-numeric: tabular-nums; }
.seg-lab.cancelled { color: var(--err-ink); }

/* Reusable "Find code" picker */
.codepick, .recpick { position: relative; }
.recpick-display { background: var(--input-bg); }
.codepick-row { display: flex; gap: 8px; align-items: flex-start; }
.codepick-row .codepick-field { flex: 1; }
.codepick-row .codepick-btn { white-space: nowrap; flex: 0 0 auto; }
.codepick-panel { position: absolute; z-index: 30; top: 100%; left: 0; right: 0; margin-top: 4px;
    background: var(--field-bg); border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 8px 24px rgba(15,23,42,.12); padding: 8px; }
.codepick-panel .codepick-q { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 7px;
    padding: 0 10px; font-size: 13px; font-family: inherit; color: var(--ink); outline: none; }
.codepick-panel .codepick-q:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.codepick-results { max-height: 260px; overflow: auto; margin-top: 6px; }
.codepick-result { padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.codepick-result:hover { background: var(--brand-tint); }
.codepick-result strong { color: var(--brand); }
.codepick-result .cp-label { color: var(--ink-soft); }
.codepick-result .cp-type { color: var(--muted); font-size: 11.5px; float: right; }
.codepick-empty { padding: 8px 9px; color: var(--muted); font-size: 12.5px; }

/* Status badges added with the customers/invoices modules */
.badge-active { background: var(--ok-bg); color: var(--ok-ink); }
.badge-retired, .badge-void { background: var(--line-soft); color: var(--muted); }

/* Quality-module status badges */
.badge-approved { background: var(--ok-bg); color: var(--ok-ink); }
.badge-observation { background: var(--line-soft); color: var(--muted); }

/* Complaint reportability badges */
.badge-reportable { background: var(--err-bg); color: var(--err-ink); }
.badge-not_reportable { background: var(--ok-bg); color: var(--ok-ink); }
.badge-not_assessed { background: var(--line-soft); color: var(--muted); }

/* Design (DHF) phases */
.badge-planning { background: var(--line-soft); color: var(--ink-soft); border-color: var(--line); }
.badge-inputs, .badge-outputs, .badge-verification, .badge-validation, .badge-review {
    background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.badge-transfer { background: var(--brand-tint); color: var(--brand); border-color: var(--chip-line); }
/* Process-validation stages */
.badge-not_started { background: var(--line-soft); color: var(--muted); border-color: var(--line); }
.badge-in_progress { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.badge-passed { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-line); }
/* Change-control implemented */
.badge-implemented { background: var(--brand-tint); color: var(--brand); border-color: var(--chip-line); }

/* Form "same as" toggle */
.is-hidden { display: none; }

/* Structured address input grid */
.addr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 4px; }
.addr-grid .addr-wide { grid-column: 1 / -1; }
.addr-grid input { width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 9px;
    padding: 0 12px; font-size: 13.5px; font-family: inherit; color: var(--ink); background: var(--field-bg); }
.addr-grid input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.logo-preview { max-height: 64px; max-width: 240px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: var(--field-bg); }

/* ============================================================ Image thumbnails */
.thumb { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 9px;
    overflow: hidden; background: var(--field-bg); border: 1px solid var(--line); flex: none; }
.thumb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-empty { background: linear-gradient(145deg, var(--surface), var(--field-bg)); }
.thumb-ico { width: 21px; height: 21px; fill: none; stroke: var(--brand-2); stroke-width: 1.7;
    stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.thumb-lg { width: 84px; height: 84px; border-radius: 13px; }
.thumb-lg .thumb-ico, .thumb.thumb-lg svg { width: 38px; height: 38px; }
/* image + label cell */
.cell-media { display: flex; align-items: center; gap: 11px; min-width: 0; }
.cell-media .cm-text { min-width: 0; }
.cell-media .cm-text strong { display: block; }
/* form image picker */
.imgpick { display: flex; align-items: center; gap: 16px; margin-top: 4px; }
.imgpick .thumb { width: 72px; height: 72px; border-radius: 12px; }
.imgpick .thumb svg { width: 32px; height: 32px; }
.imgpick-controls { display: flex; flex-direction: column; gap: 7px; }
.detail-hero { display: flex; gap: 16px; align-items: flex-start; }
.detail-hero > .thumb { width: 84px; height: 84px; border-radius: 13px; }
.detail-hero > .thumb svg { width: 38px; height: 38px; }

/* ============================================================ Training */
.learn-body { white-space: pre-wrap; word-wrap: break-word; font-size: 13.7px; line-height: 1.62;
    color: var(--ink); max-height: 520px; overflow: auto; }
.video-embed { position: relative; width: 100%; padding-top: 56.25%; border-radius: var(--radius-sm);
    overflow: hidden; border: 1px solid var(--line); background: #000; }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
/* course questions (answer-key view) */
.qlist { margin: 0; padding-left: 18px; }
.qlist > li { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.qlist > li:last-child { border-bottom: none; }
.q-prompt { font-weight: 600; margin-bottom: 6px; }
.q-opts { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.q-opts li { font-size: 13px; color: var(--ink-soft); padding: 3px 8px; border-radius: 6px; }
.q-opts li.q-correct { background: var(--ok-bg); color: var(--ok-ink); font-weight: 600; }
.qopt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qopt-grid label { margin-top: 0; }
/* quiz-taking */
.quiz { margin: 0; padding-left: 20px; display: grid; gap: 18px; }
/* Each question is a <fieldset>/<legend> for screen-reader grouping; strip the native
   chrome so it looks identical to the previous div-based layout. */
.quiz-fs { border: 0; padding: 0; margin: 0; min-inline-size: 0; }
.quiz-fs > legend.q-prompt { display: block; width: 100%; padding: 0; }
.quiz-q .q-prompt { margin-bottom: 9px; }
.quiz-opt { display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px; border: 1px solid var(--line);
    border-radius: var(--radius-sm); margin-bottom: 7px; cursor: pointer; font-weight: 400; font-size: 13.7px; }
.quiz-opt:hover { background: var(--brand-tint); border-color: #cfe0f3; }
.quiz-opt input { margin: 2px 0 0; }
.quiz-opt input:checked ~ span { font-weight: 600; }

/* ============================================================ Table toolbar + sorting */
.table-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.page-head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
/* Sensor trend tabs + inline SVG charts. */
.sensor-tabs .tab-labels { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 12px; }
.sensor-tabs .tab-label { border: 1px solid var(--line); background: var(--field-bg); color: var(--ink-soft);
    border-radius: 7px; padding: 5px 11px; font: inherit; font-size: 12.5px; cursor: pointer; }
.sensor-tabs .tab-label.active { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.sensor-tabs .tab-panel { display: none; }
.sensor-tabs .tab-panel.active { display: block; }
.req { color: #e06464; font-weight: 700; }

.spark { position: relative; }
.spark-svg { width: 100%; height: 200px; display: block; touch-action: none; cursor: crosshair; }
.spark-line { fill: none; stroke: var(--brand-2); stroke-width: 2; vector-effect: non-scaling-stroke;
  stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: var(--brand-tint); stroke: none; opacity: .55; }
.spark-grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; opacity: .55; }
.spark-ref { fill: none; stroke-width: 1.4; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; opacity: .85; }
.spark-ref-max { stroke: var(--warn-ink); }
.spark-ref-min { stroke: var(--ok-ink); }
.spark-ref-lab { font-size: 10px; font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.spark-ref-lab.max { fill: var(--warn-ink); }
.spark-ref-lab.min { fill: var(--ok-ink); }
.spark-ax { fill: var(--muted); font-size: 10px; }
.spark-ax-y { text-anchor: end; }
.spark-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; opacity: .8; }
.spark-dot { fill: var(--brand-2); stroke: var(--surface); stroke-width: 2; }
.spark-tip { position: absolute; pointer-events: none; z-index: 5; background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; font-size: 12px; color: var(--ink);
  box-shadow: 0 6px 18px rgba(0,0,0,.28); white-space: nowrap; }
.spark-tip b { font-size: 13px; }
.spark-tip-t { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.spark-meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
/* Collapsible panel via native <details> (CSP-safe, no JS). */
.collapse-panel > summary { cursor: pointer; user-select: none; }
/* Inline "what does this field mean?" chevron, sits next to form fields. */
.field-help { margin: 4px 0 12px; }
.field-help > summary { cursor: pointer; user-select: none; color: var(--brand-2); font-size: 13px; font-weight: 600; }
.field-help > summary::marker { color: var(--muted); }
.field-help ul { margin: 8px 0 2px; padding-left: 18px; color: var(--ink-soft); font-size: 13px; line-height: 1.55; }
.field-help li { margin: 0 0 4px; }
.collapse-panel > summary.panel-title { margin: 0 0 12px; }
.collapse-panel:not([open]) > summary.panel-title { margin-bottom: 0; }
.collapse-panel > summary::marker { color: var(--muted); }
.table-filter-wrap { position: relative; display: inline-flex; align-items: center; }
.table-filter-input { height: 36px; min-width: 240px; max-width: 340px; border: 1px solid var(--line);
    border-radius: 9px; background: var(--field-bg); padding: 0 13px; font-size: 13.5px; font-family: inherit; color: var(--ink); outline: none; }
.table-filter-input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
/* Active (incl. restored) filter: highlight + room for the ✕ clear button. */
.table-filter-input.is-active { border-color: var(--brand-2); padding-right: 34px; }
.table-filter-clear { position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
    width: 21px; height: 21px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
    border: none; border-radius: 50%; background: var(--line); color: var(--ink); cursor: pointer;
    font-size: 11px; line-height: 1; }
.table-filter-clear:hover { background: var(--brand-2); color: #fff; }
.table-filter-clear:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 1px; }
/* The native search-input clear "X" is redundant now — hide it (WebKit). */
.table-filter-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.table-count { margin-left: auto; }
.table-pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }
.table-pager .btn[disabled] { opacity: .45; cursor: default; pointer-events: none; }

/* Callout / info box (theme-aware) */
.callout { border: 1px solid var(--line); border-left: 3px solid var(--brand-2); background: var(--input-bg);
    border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; }
.callout strong { color: var(--ink); }
.callout-info { border-left-color: var(--brand-2); }
.callout-ok { border-left-color: var(--ok-ink); background: var(--ok-bg); }
.callout-warn { border-left-color: #e0903a; }

/* "Action required" callout (read-and-understood) — amber so it stands out from plain panels. */
.action-required { display: flex; align-items: center; gap: 13px; flex-wrap: wrap;
    background: var(--warn-bg); border: 1px solid var(--warn-line); border-left: 4px solid var(--warn-ink); }
.action-required-ico { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--warn-ink);
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.action-required-text { flex: 1; min-width: 200px; color: var(--ink); }
.action-required-text strong { color: var(--warn-ink); }

/* Maximized document reader: the content fills the dialog (drop the inner 540px clamp + border). */
.doc-modal .modal-body { padding: 0; }
.doc-modal .doc-content { max-height: none; border: none; border-radius: 0; padding: 22px 24px; }
.callout-err { border-left-color: var(--err-ink); background: var(--err-bg); }
.table-tools { display: flex; gap: 7px; position: relative; }
.btn-xs { padding: 6px 10px; font-size: 12px; }
.cols-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; background: var(--pop-bg);
    border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 8px; min-width: 180px; max-height: 320px; overflow: auto; }
.cols-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; font-size: 13px; color: var(--ink); cursor: pointer; }
.cols-item:hover { background: var(--row-hover); }
.grid thead th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.grid thead th.th-sort:hover { color: var(--ink); }
.grid thead th.th-sort::after { content: "⇅"; opacity: .35; margin-left: 5px; font-size: 10px; }
.grid thead th.sorted-asc::after { content: "↑"; opacity: .9; }
.grid thead th.sorted-desc::after { content: "↓"; opacity: .9; }
.grid thead th.th-sort a { color: inherit; text-decoration: none; }
/* Cell helpers for dense log/audit tables. */
.grid td.nowrap, .grid th.nowrap { white-space: nowrap; }
.grid .mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.grid td.ai-prompt { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================ Server filter bar + pager */
.filter-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-input { height: 38px; min-width: 260px; flex: 0 1 320px; border: 1px solid var(--line); border-radius: 9px;
    background: var(--field-bg); padding: 0 13px; font-size: 13.5px; font-family: inherit; color: var(--ink); outline: none; }
.filter-input:focus, .filter-select:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); outline: none; }
.filter-select { height: 38px; border: 1px solid var(--line); border-radius: 9px; background: var(--field-bg);
    padding: 0 30px 0 12px; font-size: 13.5px; font-family: inherit; color: var(--ink); }
.filter-meta { margin-left: auto; }      /* count sits after the inputs, pushed right */
.filter-actions { margin-left: 12px; }   /* …then Filter/Clear pinned to the far right */
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }
.pager .is-disabled { opacity: .45; pointer-events: none; }

/* ============================================================ Dashboard attention */
.attention { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow-sm); margin-bottom: 20px; }
.attention-head { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.attention-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 0; font-weight: 700; }
.att-ico { width: 17px; height: 17px; fill: none; stroke: var(--warn-ink); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.attention-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.att-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 13px; border-radius: 999px;
    font-size: 13px; font-weight: 500; border: 1px solid var(--line); background: var(--field-bg); color: var(--ink); }
.att-chip:hover { text-decoration: none; box-shadow: var(--shadow); transform: translateY(-1px); }
.att-chip b { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.att-chip.att-err { background: var(--err-bg); border-color: var(--err-line); color: var(--err-ink); }
.att-chip.att-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.att-chip.att-ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.card-metric .metric-bad { color: var(--err-ink); }
.onboard-steps { margin: 8px 0 10px; padding-left: 20px; display: grid; gap: 7px; font-size: 13.7px; }
.onboard-steps li { color: var(--ink-soft); }
/* Management-review live snapshot tiles */
.snapshot { display: grid; grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); gap: 10px; margin-bottom: 8px; }
.snap { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 8px;
    border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink-soft); }
.snap:hover { border-color: var(--brand-2); text-decoration: none; box-shadow: var(--shadow-sm); }
.snap b { font-size: 20px; color: var(--brand-2); font-variant-numeric: tabular-nums; }
.snap span { font-size: 11px; text-align: center; }
/* Non-clickable snapshot tile (viewer lacks access to that module). */
.snap-static { cursor: default; }
.snap-static:hover { border-color: var(--line); box-shadow: none; }
.snap-static b { color: var(--muted); }

/* ============================================================ Attachments */
.att-list { list-style: none; margin: 0 0 12px; padding: 0; }
.att-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.att-list li:last-child { border-bottom: none; }
.att-ico { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--brand-2); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.att-main { flex: 1; min-width: 0; }
.att-main > a { font-weight: 600; word-break: break-all; }
.att-meta { display: block; font-size: 12px; color: var(--muted); }
.att-desc { color: var(--ink-soft); }
.att-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 17px; line-height: 1; padding: 2px 7px; border-radius: 6px; }
.att-del:hover { background: var(--err-bg); color: var(--err-ink); }
.att-upload { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; border-top: 1px dashed var(--line); padding-top: 12px; }
.att-descin { flex: 1; min-width: 150px; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 11px;
    font-size: 13px; font-family: inherit; background: var(--field-bg); color: var(--ink); }
.att-descin:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }

/* ---- Controlled distribution (read & understood) ---- */
.distribute-form { border-top: 1px dashed var(--line); padding-top: 14px; margin-top: 4px; }
.distribute-label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.distribute-quick { display: flex; gap: 6px; margin-bottom: 7px; }
.distribute-select { width: 100%; box-sizing: border-box; border: 1px solid var(--line);
    border-radius: var(--radius-sm); background: var(--field-bg); color: var(--ink);
    font-size: 13.5px; font-family: inherit; padding: 5px; }
.distribute-select:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.distribute-select option { padding: 6px 9px; border-radius: 6px; }
.distribute-select option:checked { background: var(--brand-tint); color: var(--brand-2); font-weight: 600; }
.distribute-hint { margin: 7px 0 13px; }
.distribute-hint kbd { font: inherit; font-size: 11px; background: var(--field-bg); border: 1px solid var(--line);
    border-radius: 5px; padding: 1px 5px; color: var(--ink-soft); }
.distribute-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.distribute-due { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.distribute-due input[type=date] { height: 36px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 0 11px; font-size: 13px; font-family: inherit; background: var(--field-bg); color: var(--ink); }
.distribute-due input[type=date]:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }

/* ---- CAPA action items + effectiveness verification ---- */
.btn-sm { height: 30px; padding: 0 11px; font-size: 12px; }
.actions-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 4px 0 12px; }
.actions-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px;
    text-transform: uppercase; letter-spacing: .04em; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.actions-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.actions-table tr.row-overdue td { background: var(--err-bg); }
/* Overdue date cell (e.g. the per-course trainee roster). */
.cell-overdue { color: var(--err-ink); font-weight: 600; }
/* Compact inline form control used in table cells (audit checklist/findings, action tables…). Theme-aware. */
.mini-input { height: 32px; border: 1px solid var(--line); border-radius: 7px; padding: 0 9px;
    font-size: 12px; font-family: inherit; background: var(--field-bg); color: var(--ink);
    min-width: 110px; max-width: 100%; box-sizing: border-box; vertical-align: middle; }
.mini-input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
/* Inline form inside a table cell — controls + Save line up and wrap gracefully. */
.cell-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; }
.action-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
    border-top: 1px dashed var(--line); padding-top: 12px; }
.action-add input[type=text], .action-add input[type=date] { height: 34px; border: 1px solid var(--line);
    border-radius: 8px; padding: 0 11px; font-size: 13px; font-family: inherit; background: var(--field-bg); color: var(--ink); }
.action-add select { height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px;
    font-size: 13px; font-family: inherit; background: var(--field-bg); color: var(--ink); }
.action-add input[name=description] { flex: 1; min-width: 180px; }
.radio-row { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px; }
.radio-row .radio { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.radio-row .radio input { width: auto; margin: 0; }
.score-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.score-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600;
    color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.score-row input { width: 70px; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px;
    font-size: 15px; font-family: inherit; background: var(--field-bg); color: var(--ink); text-align: center; }
.score-row input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.finding-actions { display: flex; flex-direction: column; gap: 6px; }
.finding-actions .mini-input { min-width: 120px; }
.snap-warn { border-color: var(--err-line, #e7c3c3); background: var(--err-bg); }
.snap-warn b { color: var(--err-ink); }

/* ---- Workflow form-builder (Variant A) ---- */
.wf-builder { display: flex; flex-direction: column; gap: 18px; margin: 6px 0 4px; }
.wf-section { display: flex; flex-direction: column; gap: 8px; }
.wf-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
    border-top: 1px solid var(--line-soft); padding-top: 14px; }
.wf-section-head .panel-title { margin: 0; }
.wf-section > .wf-initial { max-width: 260px; }
.wf-row.wf-state-row { display: flex; align-items: center; gap: 9px; }
.wf-row.wf-state-row .wf-state { flex: 1; max-width: 360px; }
.wf-iconbtn { flex: none; border: 0; background: transparent; cursor: pointer; color: var(--muted);
    font-size: 14px; line-height: 1; padding: 6px 8px; border-radius: 6px; transition: color .12s, background .12s; }
.wf-iconbtn:hover { color: var(--err-ink); background: var(--err-bg); }
.wf-trans-table { table-layout: auto; }
.wf-trans-table th { white-space: nowrap; }
.wf-trans-table td { vertical-align: middle; }
.wf-trans-table select, .wf-trans-table input[type="text"] { width: 100%; min-width: 92px; margin: 0; }
.wf-trans-table .wf-label { min-width: 110px; }
.wf-trans-table .wf-esign { width: 18px; height: 18px; margin: 0; }
.wf-trans-table td:last-child { width: 1%; white-space: nowrap; }
.wf-advanced { margin-top: 2px; }
.wf-advanced > summary { cursor: pointer; font-size: 13px; color: var(--brand-2); font-weight: 600;
    padding: 4px 0; user-select: none; }
.wf-advanced[open] > summary { margin-bottom: 8px; }
.wf-validation { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 2px; }
.wf-msg { font-size: 13px; padding: 8px 12px; border-radius: 8px; border: 1px solid transparent; }
.wf-msg-error { background: var(--err-bg); color: var(--err-ink); border-color: var(--err-line); }
.wf-msg-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }

/* ---- Workflow template gallery ---- */
.wf-templates { margin: 2px 0 8px; }
.wf-tpl-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.wf-tpl-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.wf-tpl-sub { font-size: 12px; color: var(--muted); }
.wf-tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 10px; }
.wf-tpl-card { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
    padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--field-bg);
    cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .12s; }
.wf-tpl-card:hover { border-color: var(--brand-2); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.wf-tpl-card.is-active { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.wf-tpl-name { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.wf-tpl-desc { font-size: 12px; color: var(--muted); line-height: 1.45; }
.wf-tpl-blank { border-style: dashed; }

/* ---- Authority picker (custom popup) ---- */
.authpick { position: relative; }
.authpick-trigger { display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; min-width: 96px; padding: 6px 10px; font: inherit; font-size: 13px; cursor: pointer;
    border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--field-bg); color: var(--ink); }
.authpick-trigger:hover { border-color: var(--brand-2); }
.authpick-trigger:focus-visible { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.authpick-label { display: flex; align-items: center; min-width: 0; overflow: hidden; }
.authpick-anylabel { color: var(--muted); white-space: nowrap; }
.authpick-idbadge { font-size: 11px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.authpick-chev { color: var(--muted); font-size: 11px; flex: none; }
.authpick-menu { position: fixed; z-index: 1000; display: flex; flex-direction: column; max-height: 320px;
    padding: 6px; background: var(--pop-bg); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); }
.authpick-menu[hidden] { display: none; }
.authpick-search { margin: 2px 2px 6px; padding: 7px 9px; font-size: 13px; color: var(--ink);
    background: var(--input-bg); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.authpick-search:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.authpick-list { overflow-y: auto; }
.authpick-opt { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
    padding: 7px 9px; border: 0; background: transparent; cursor: pointer; border-radius: var(--radius-sm); }
.authpick-opt:hover { background: var(--line-soft); }
.authpick-opt.is-sel { background: var(--brand-tint); }
.authpick-id { flex: none; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px;
    font-weight: 600; color: var(--chip-ink); background: var(--chip-bg); border: 1px solid var(--chip-line);
    border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.authpick-any { font-weight: 600; color: var(--ink); }
.authpick-desc { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.authpick-empty { padding: 10px 9px; color: var(--muted); font-size: 13px; }

/* ---- Highlighted JSON editor (Advanced) ---- */
.json-editor { position: relative; margin-top: 4px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--input-bg); overflow: hidden; }
.json-hl, .json-ta { margin: 0; padding: 12px 14px; box-sizing: border-box; border: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; line-height: 1.6;
    white-space: pre; tab-size: 2; -moz-tab-size: 2; }
.json-ta { position: relative; z-index: 1; display: block; width: 100%; min-height: 320px; resize: vertical;
    background: transparent; color: transparent; caret-color: var(--ink); overflow: auto; }
.json-ta:focus { outline: none; }
.json-hl { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; color: var(--ink); }
.json-editor:focus-within { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.json-hl .tok-key { color: var(--brand-2); }
.json-hl .tok-str { color: var(--ok-ink); }
.json-hl .tok-num { color: var(--warn-ink); }
.json-hl .tok-bool { color: var(--err-ink); font-weight: 600; }
.json-hl .tok-null { color: var(--muted); }

/* Inline AI drafting assistant (document editor) */
.ai-assist { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 4px 0 10px;
  background: var(--brand-tint, var(--row-hover)); }
.ai-assist-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ai-assist-title { font-weight: 600; color: var(--brand-2); white-space: nowrap; }
.ai-assist-result { margin-top: 10px; }
.ai-assist-result.is-hidden { display: none; }
.ai-assist-status { margin-bottom: 6px; }
.ai-assist-result textarea { width: 100%; box-sizing: border-box; background: var(--field-bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-family: inherit; }
.ai-assist-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* Inline AI "suggest" control (CAPA / complaint forms) */
.ai-suggest { margin: 0 0 8px; }
.ai-suggest-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-suggest-status.ai-suggest-error { color: var(--err-ink); font-weight: 600; }
.ai-suggest-result { margin-top: 8px; }
.ai-suggest-result.is-hidden { display: none; }
.ai-suggest-text { width: 100%; box-sizing: border-box; background: var(--field-bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-family: inherit; }
.ai-suggest-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }

/* ---- STL 3D viewer: per-unit thumbnail + interactive model dialog ---- */
.stl-cell { width: 96px; text-align: center; vertical-align: middle; }
.stl-thumb { display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--field-bg); overflow: hidden; font-size: 18px; line-height: 1; color: var(--muted); }
.stl-thumb.stl-clickable { cursor: pointer; transition: border-color .12s ease, box-shadow .12s ease; }
.stl-thumb.stl-clickable:hover { border-color: var(--brand-2); box-shadow: 0 0 0 2px var(--brand-tint); }
.stl-thumb-canvas { display: block; width: 46px; height: 46px; }
.stl-thumb.is-fail { font-size: 20px; }
.stl-up { margin: 4px 0 0; }
/* Clearly-clickable upload affordance (the bare "+STL" chip was too easy to miss). */
.stl-add { display: inline-block; cursor: pointer; font-size: 11.5px; font-weight: 600; line-height: 1;
  padding: 5px 9px; border: 1px solid var(--brand-2); border-radius: 7px; color: var(--brand-2);
  background: var(--brand-tint); white-space: nowrap; transition: background .12s ease, color .12s ease; }
.stl-add:hover { background: var(--brand-2); color: #fff; }
.stl-add.stl-add-replace { font-weight: 500; color: var(--muted); border-color: var(--line);
  background: var(--field-bg); padding: 3px 7px; }
.stl-add.stl-add-replace:hover { border-color: var(--brand-2); color: var(--ink); background: var(--field-bg); }
.stl-none { color: var(--muted); }

dialog.stl-modal { width: min(900px, 96vw); }
.stl-modal-body { padding: 0; display: flex; flex-direction: column; }
.stl-canvas { display: block; width: 100%; height: min(68vh, 620px);
  background: radial-gradient(circle at 50% 38%, #20262f 0%, #11151b 100%);
  touch-action: none; cursor: grab; }
.stl-canvas:active { cursor: grabbing; }
.stl-status { margin: 0; padding: 9px 16px; border-top: 1px solid var(--line);
  background: var(--thead-bg); text-align: center; }

/* ============================================================ Print
   A clean print/Save-as-PDF view for any record page: drop the app chrome
   (sidebar, topbar, search, action buttons, AI assistant, modals) and let the
   content flow full-width on white. The dedicated /print and /pdf documents
   render standalone and are unaffected. Add .no-print to hide anything else. */
@media print {
    :root { --sb-w: 0px; --tb-h: 0px; }
    .sidebar, .topbar, .nav-search, .ai-asst, .htmx-progress,
    .palette, .palette-backdrop, .page-head-actions, .no-print,
    .att-upload, .att-del, .alert-x, .panel-x { display: none !important; }
    /* Buttons and form controls are interactive chrome — omit from the printout. */
    .btn, button, .reason-form input, .detail-actions, .form-actions { display: none !important; }
    body { background: #fff; color: #000; font-size: 12px; }
    .content { margin: 0 !important; padding: 0 !important; max-width: none !important; }
    .panel, .grid, .esign-card { box-shadow: none !important; border-color: #ccc !important;
        break-inside: avoid; }
    a { color: #000; text-decoration: none; }
    thead { display: table-header-group; }   /* repeat table headers across printed pages */
    tr, img { break-inside: avoid; }
}

/* ============================================================ Document WYSIWYG editor (2.3) */
/* Shared rendering for the editable surface and the read-only .doc-html (detail / modal / print),
   so what you author is exactly what the controlled record shows. */
.doc-html, .doc-wysiwyg { font-size: 14px; line-height: 1.65; color: var(--ink); }
.doc-html h1, .doc-wysiwyg h1 { font-size: 20px; }
.doc-html h2, .doc-wysiwyg h2 { font-size: 17px; }
.doc-html h3, .doc-wysiwyg h3 { font-size: 15px; }
.doc-html h1, .doc-html h2, .doc-html h3,
.doc-wysiwyg h1, .doc-wysiwyg h2, .doc-wysiwyg h3 {
    color: var(--brand); font-weight: 700; margin: 14px 0 6px; line-height: 1.3; }
.doc-html p, .doc-html div, .doc-wysiwyg p, .doc-wysiwyg div { margin: 0 0 10px; }
.doc-html ul, .doc-html ol, .doc-wysiwyg ul, .doc-wysiwyg ol { margin: 0 0 10px; padding-left: 24px; }
.doc-html li, .doc-wysiwyg li { margin: 0 0 4px; }
.doc-html blockquote, .doc-wysiwyg blockquote {
    margin: 0 0 10px; padding: 4px 0 4px 14px; border-left: 3px solid var(--line); color: var(--ink-soft); }
.doc-html a, .doc-wysiwyg a { color: var(--brand-2); }
.doc-html pre, .doc-wysiwyg pre {
    white-space: pre-wrap; background: var(--input-bg); padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.doc-html code, .doc-wysiwyg code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; }
.doc-html > :first-child, .doc-wysiwyg > :first-child { margin-top: 0; }
.doc-html > :last-child, .doc-wysiwyg > :last-child { margin-bottom: 0; }

.doc-wysiwyg-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
    border: 1px solid var(--line); border-bottom: none; border-radius: 10px 10px 0 0;
    padding: 6px 8px; background: var(--input-bg); }
.doc-tbtn { font: inherit; font-size: 13px; line-height: 1; cursor: pointer;
    padding: 6px 9px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ink); }
.doc-tbtn:hover { background: var(--surface); border-color: var(--line); }
.doc-tbtn.is-active { background: var(--brand-tint); border-color: var(--brand-2); color: var(--brand); }
.doc-tbtn.tb-b { font-weight: 800; }
.doc-tbtn.tb-i { font-style: italic; }
.doc-tbtn.tb-u { text-decoration: underline; }
.doc-tbtn-ai { display: inline-flex; align-items: center; gap: 4px; color: var(--brand-2); font-weight: 600; margin-left: auto; }
.doc-tbtn-ai svg { width: 15px; height: 15px; }
.doc-wysiwyg-sep { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }
.doc-wysiwyg { border: 1px solid var(--line); border-radius: 0 0 10px 10px;
    padding: 14px 16px; min-height: 320px; background: var(--field-bg); outline: none; overflow-wrap: anywhere; }
.doc-wysiwyg:focus { box-shadow: inset 0 0 0 2px var(--brand-tint); }

/* ============================================================ Rich <select> (bubble + description) */
.richsel { position: relative; }
.richsel-trigger { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; font: inherit;
    padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--field-bg); color: var(--ink); cursor: pointer; }
.richsel-trigger:focus-visible { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-tint); }
.richsel-trigger-label { flex: 1 1 auto; }
.richsel-trigger-chev { color: var(--muted); display: flex; flex: none; }
.richsel-trigger-chev svg, .richsel-opt-chev svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.richsel-bubble { flex: none; display: inline-block; min-width: 40px; text-align: center; padding: 2px 8px;
    border-radius: 999px; background: var(--chip-bg); color: var(--chip-ink); border: 1px solid var(--chip-line);
    font-size: 11px; font-weight: 700; letter-spacing: .4px; }
.richsel-pop { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--pop-bg); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 6px; max-height: 360px; overflow-y: auto; }
.richsel-pop[hidden] { display: none; }
.richsel-opt { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit;
    padding: 9px 10px; border: none; background: none; color: var(--ink); cursor: pointer; border-radius: 8px; }
.richsel-opt:hover, .richsel-opt:focus-visible { background: var(--row-hover); outline: none; }
.richsel-opt[aria-selected="true"] { background: var(--brand-tint); }
.richsel-opt-text { flex: 1 1 auto; min-width: 0; }
.richsel-opt-label { display: block; font-weight: 600; }
.richsel-opt-desc { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 1px; }
.richsel-opt-chev { color: var(--muted); display: flex; flex: none; }
