/*
 * ThMed theme, shared by th-manager and th-technician. Palette and proportions taken from
 * docs/app-audit/th-manager-device-mvp-mockups.html so the running app
 * matches the mockups for the device MVP slice.
 *
 * Theming is driven by the `data-th-theme` attribute on <html>, set
 * synchronously by `js/theme-bootstrap.js` before paint (no flash).
 * Effective values are `light` or `dark`; the user's *preference*
 * (System / Light / Dark) lives in localStorage and is resolved against
 * `prefers-color-scheme` at bootstrap and on system changes.
 */

:root {
    --th-bg: #f4efe7;
    --th-paper: #fffaf2;
    --th-surface: #ffffff;
    --th-surface-2: #f7f1e8;
    --th-ink: #26302c;
    --th-muted: #6f7972;
    --th-faint: #9aa49e;
    --th-line: rgba(43, 55, 50, 0.12);
    --th-sidebar: #1f2926;
    --th-sidebar-2: #293833;
    --th-sidebar-text: #ecf1ed;
    --th-sage: #6f8f73;
    --th-sage-soft: #e5eee2;
    --th-teal: #287b75;
    --th-teal-strong: #1f6962;
    --th-teal-soft: #dcefeb;
    --th-amber: #d99732;
    --th-amber-soft: #faedd7;
    --th-red: #b84a3a;
    --th-red-soft: #f7ded9;
    --th-blue: #346b8f;
    --th-blue-soft: #dfebf3;
    --th-shadow: 0 24px 70px rgba(34, 40, 36, 0.14);
    --th-radius: 8px;
    --th-font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
    --th-font-mono: "IBM Plex Mono", Consolas, ui-monospace, monospace;

    /* Shared by our .th-tab strips and Radzen's tabs so every sub-tab reads alike:
       medium weight, sentence case; the active tab is marked by colour + underline.
       Inactive text sits between muted and ink — plain muted fell under AA contrast
       on the tab strip. */
    --th-tab-font-size: 14px;
    --th-tab-font-weight: 500;
    --th-tab-letter-spacing: 0.01em;
    --th-tab-color: color-mix(in srgb, var(--th-ink) 40%, var(--th-muted));

    /* Per-theme tokens consumed in selectors below. Light defaults; the
       dark block re-defines them. Keeps the existing rules unchanged. */
    --th-body-grid-line: rgba(38, 48, 44, 0.045);
    --th-body-glow: rgba(217, 151, 50, 0.18);
    --th-main-bg: #f8f5ef;
    --th-topbar-bg: rgba(255, 255, 255, 0.76);
    --th-tabs-bg: #f4f0e9;
    --th-field-bg: #fffdf8;
    --th-grid-head-bg: #f1eee8;
    --th-grid-row-stripe: #faf6ed;
    --th-grid-row-hover: rgba(217, 151, 50, 0.08);
    --th-badge-green-color: #34734a;
    --th-badge-green-bg: #e6f0e5;
    --th-badge-gray-bg: rgba(43, 55, 50, 0.08);
    --th-sidebar-active: rgba(217, 151, 50, 0.22);
    --th-sidebar-toggle-border: rgba(255, 255, 255, 0.16);
    --th-sidebar-toggle-bg: rgba(255, 255, 255, 0.06);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    max-width: 100%;
    /* clip, not hidden: hidden makes these scroll containers, which disables every position: sticky below. */
    overflow-x: clip;
}

body {
    color: var(--th-ink);
    font-family: var(--th-font-body);
    font-size: 14px;
    line-height: 1.5;
    background: linear-gradient(var(--th-body-grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--th-body-grid-line) 1px, transparent 1px),
    radial-gradient(circle at top left, var(--th-body-glow), transparent 34rem),
    var(--th-bg);
    background-size: 28px 28px, 28px 28px, auto, auto;
    transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    color: var(--th-ink);
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ===== Shell layout ===== */

.th-shell {
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    background: linear-gradient(
        to right,
        var(--th-sidebar) 0,
        var(--th-sidebar) 260px,
        var(--th-main-bg) 260px,
        var(--th-main-bg) 100%
    );
    overflow-x: clip;
}

html[data-th-sidebar-collapsed="true"] .th-shell {
    grid-template-columns: 76px minmax(0, 1fr);
    background: linear-gradient(
        to right,
        var(--th-sidebar) 0,
        var(--th-sidebar) 76px,
        var(--th-main-bg) 76px,
        var(--th-main-bg) 100%
    );
}

.th-sidebar {
    color: var(--th-sidebar-text);
    background: linear-gradient(180deg, rgba(217, 151, 50, 0.08), transparent 34%),
    var(--th-sidebar);
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    position: sticky;
    top: 0;
    align-self: start;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    /* Lift the sidebar's stacking context above the main column so the
       collapsed-nav hover tooltip (a ::after that pokes into the content
       area) renders over the toolbar/filter controls instead of behind
       them. Stays below Radzen popups (z-index ~1000+). */
    z-index: 30;
}

.th-sidebar-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.th-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 6px 0;
    flex: 1;
    min-width: 0;
}

.th-brand-mark {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 9px;
    color: #1f2926;
    background: var(--th-amber);
    font-weight: 800;
}

.th-brand b {
    display: block;
    font-size: 16px;
}

.th-brand small {
    color: rgba(236, 241, 237, 0.64);
    font-size: 12px;
}

.th-nav-group {
    display: grid;
    gap: 6px;
}

.th-nav-label {
    margin: 8px 8px 4px;
    color: rgba(236, 241, 237, 0.54);
    font-family: var(--th-font-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.th-nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 38px;
    padding: 0 10px;
    border-radius: 7px;
    color: rgba(236, 241, 237, 0.82);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.th-nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.th-nav-item .th-nav-left {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    flex: 1;
    min-width: 0;
}

.th-nav-icon {
    display: inline-flex;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: rgba(236, 241, 237, 0.72);
}

.th-nav-icon::before {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    background: currentColor;
    mask-image: var(--th-nav-icon-url);
    mask-position: center;
    mask-repeat: no-repeat;
    mask-size: contain;
    mask-mode: alpha;
    -webkit-mask-image: var(--th-nav-icon-url);
    -webkit-mask-position: center;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: contain;
}

.th-nav-item.active {
    color: #fff;
    background: var(--th-sidebar-active);
    box-shadow: inset 3px 0 0 var(--th-amber);
}

.th-nav-item.active .th-nav-icon {
    color: var(--th-amber);
}

.th-nav-item.dim .th-nav-icon {
    color: rgba(236, 241, 237, 0.38);
}

.th-nav-item.dim {
    color: rgba(236, 241, 237, 0.42);
    cursor: default;
}

.th-nav-item.dim:hover {
    background: transparent;
    color: rgba(236, 241, 237, 0.42);
}

.th-nav-count {
    color: rgba(236, 241, 237, 0.56);
    font-family: var(--th-font-mono);
    font-size: 11px;
}

/* Collapsed sidebar rail, shared by th-manager and th-technician.
   Driven by the `data-th-sidebar-collapsed` attribute on <html>, set before paint
   to avoid a flash (th-manager: `js/sidebar-state-bootstrap.js`, th-technician: `js/boot.js`). */

html[data-th-sidebar-collapsed="true"] .th-sidebar {
    align-items: center;
    gap: 18px;
    padding: 18px 10px;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-sidebar-head {
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding-bottom: 14px;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-brand {
    width: 100%;
    justify-content: center;
    padding: 0;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-brand-text,
html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-label,
html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-text,
html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-count {
    display: none;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-group {
    width: 100%;
    gap: 8px;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-item {
    width: 44px;
    height: 44px;
    min-height: 44px;
    justify-content: center;
    margin: 0 auto;
    padding: 0;
    position: relative;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-item .th-nav-left {
    justify-content: center;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-item.active {
    box-shadow: inset 0 -3px 0 var(--th-amber);
}

/* Fixed (not absolute) so the scrolling sidebar's overflow doesn't clip it; with top unset it keeps
   its static position, which the flex item centres on the icon. */
html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-item::after {
    content: none;
    position: fixed;
    z-index: 4;
    left: 70px;
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 7px;
    color: var(--th-sidebar-text);
    background: var(--th-sidebar-2);
    box-shadow: 0 12px 28px rgba(31, 41, 38, 0.22);
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-item:hover::after {
    content: attr(data-label);
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-nav-icon {
    width: 22px;
    height: 22px;
}

.th-sidebar-toggle {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--th-sidebar-toggle-border);
    border-radius: 7px;
    color: rgba(236, 241, 237, 0.88);
    background: var(--th-sidebar-toggle-bg);
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.th-sidebar-toggle:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.1);
}

.th-sidebar-toggle .th-nav-icon {
    color: inherit;
}

.th-sidebar-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.th-sidebar-toggle-icon-expand {
    display: none;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-sidebar-toggle-icon-collapse {
    display: none;
}

html[data-th-sidebar-collapsed="true"] .th-sidebar .th-sidebar-toggle-icon-expand {
    display: inline-flex;
}

/* ===== Main column ===== */

.th-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--th-main-bg);
    transition: background-color 0.25s ease;
}

.th-topbar {
    min-height: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--th-line);
    background: var(--th-topbar-bg);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 20;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.th-page-header {
    min-width: 0;
}

.th-page-header .th-crumb {
    color: var(--th-muted);
    font-size: 13px;
}

.th-page-header h1 {
    margin-top: 4px;
    font-size: 24px;
    font-weight: 600;
}

.th-top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

/* In the devices toolbar the bar top-aligns its children so the filter labels
   sit on one line, but these actions should line up with the filter *inputs*
   (the bottom row), not the labels above them. */
.th-toolbar .th-top-actions {
    align-self: flex-end;
}

.th-search {
    width: 270px;
    height: 38px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    color: var(--th-muted);
    background: var(--th-surface);
    font-size: 13px;
}

.th-search input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--th-ink);
    font-size: inherit;
    font-family: inherit;
}

.th-search-icon {
    flex: 0 0 auto;
    color: var(--th-muted);
}

.th-avatar {
    width: 38px;
    height: 38px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    color: var(--th-surface);
    background: var(--th-teal);
    font-family: var(--th-font-mono);
    font-size: 13px;
    font-weight: 600;
}

/* ===== User / profile menu =====
   The topbar avatar opens an "identity card" popover: a tinted header with the
   user's name, email and role chips, an Account action, and a sign-out footer.
   Anchored + dismissed with the same click-backdrop model as the columns picker. */

.th-usermenu {
    position: relative;
    display: inline-flex;
}

.th-usermenu__trigger {
    appearance: none;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: box-shadow 0.15s ease;
}

.th-usermenu__trigger:hover {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--th-teal) 16%, transparent);
}

.th-usermenu.open .th-usermenu__trigger {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--th-teal) 24%, transparent);
}

.th-usermenu__trigger:focus-visible {
    outline: 2px solid var(--th-teal);
    outline-offset: 2px;
}

.th-usermenu__backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 40;
}

.th-usermenu__panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 50;
    width: 296px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
    box-shadow: 0 16px 42px rgba(34, 40, 36, 0.20);
    overflow: hidden;
}

.th-usermenu__head {
    padding: 15px 16px;
    border-bottom: 1px solid var(--th-line);
    background: var(--th-teal-soft);
}

.th-usermenu__id {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.th-usermenu__avatar-lg {
    width: 46px;
    height: 46px;
    flex: none;
    font-size: 16px;
}

.th-usermenu__id-text {
    min-width: 0;
}

.th-usermenu__name {
    font-size: 15.5px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--th-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.th-usermenu__email {
    margin-top: 2px;
    color: var(--th-muted);
    font-size: 12.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.th-usermenu__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.th-usermenu__chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--th-surface);
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}

.th-usermenu__chip-dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: currentColor;
}

.th-usermenu__chip.admin {
    color: var(--th-teal-strong);
}

.th-usermenu__chip.mgr {
    color: var(--th-badge-green-color);
}

.th-usermenu__chip.tech {
    color: var(--th-blue);
}

.th-usermenu__chip.cust {
    color: var(--th-muted);
}

.th-usermenu__section {
    padding: 12px 14px 5px;
    font-family: var(--th-font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--th-faint);
}

.th-usermenu__item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 14px;
    border: none;
    background: transparent;
    color: var(--th-ink);
    font: inherit;
    font-size: 13.5px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease;
}

.th-usermenu__item:hover {
    background: var(--th-surface-2);
}

.th-usermenu__ico {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    color: var(--th-muted);
}

.th-usermenu__item:hover .th-usermenu__ico {
    color: var(--th-ink);
}

.th-usermenu__item-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.th-usermenu__item-title {
    color: inherit;
}

.th-usermenu__item-hint {
    margin-top: 1px;
    font-size: 11.5px;
    color: var(--th-faint);
}

.th-usermenu__foot {
    border-top: 1px solid var(--th-line);
}

.th-usermenu__foot form {
    margin: 0;
}

.th-usermenu__item--danger {
    padding: 12px 14px;
    color: var(--th-red);
}

.th-usermenu__item--danger .th-usermenu__ico,
.th-usermenu__item--danger:hover .th-usermenu__ico {
    color: var(--th-red);
}

.th-usermenu__item--danger:hover {
    background: var(--th-red-soft);
}

.th-content {
    min-width: 0;
    padding: 24px;
    display: grid;
    gap: 16px;
}

/* ===== Toolbar ===== */

.th-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
    padding: 14px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
}

/* ===== Filter bar =====
   Labelled filter fields above a non-grid list (admin audit) and the labelled search box. */

/* Quick-search rendered with a label so it stacks like a filter field and
   shares the row's baseline with the labelled facets next to it. */
.th-search-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.th-filter-bar {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    gap: 10px 12px;
    align-items: flex-end;
    min-width: 0;
}

/* Hairline divider between the quick-search and the faceted filters when they
   share the toolbar's left cluster, so the two groups read as distinct.
   Scoped to the catalog combo (search + bar); the Devices/Customers bar lives
   directly in the toolbar and is unaffected. */

.th-filter-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
    flex: 0 1 200px;
}

.th-filter-field__label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    font-family: var(--th-font-mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--th-muted);
}

.th-filter-daterange {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* A date-range field holds two pickers + a separator, so it needs roughly
   twice the room of a single-control field; otherwise each picker shrinks
   below the width of a `dd.MM.yyyy` value and crowds its calendar icon. */
.th-filter-field:has(.th-filter-daterange) {
    min-width: 264px;
    flex-basis: 284px;
}

.th-filter-daterange__sep {
    color: var(--th-muted);
}

/* Radzen controls inside the bar: compact font + height so the filters read
   as toolbar chrome rather than form fields, and let multi-select chips wrap
   instead of overflowing past the trigger. Target text elements only — never
   blanket `*`, which would also shrink the chevron/clear icon fonts. */
.th-filter-bar .rz-dropdown,
.th-filter-bar .rz-dropdown-label,
.th-filter-bar .rz-textbox,
.th-filter-bar .rz-inputtext,
.th-filter-bar .rz-datepicker,
.th-filter-bar .rz-datepicker input,
.th-filter-bar .rz-chip,
.th-filter-bar .rz-chip-text {
    font-size: 12px;
}

/* Keep the dropdown chevron at a usable size (the rules above must not touch
   the icon font). */
.th-filter-bar .rz-dropdown-trigger-icon {
    font-size: 1.25rem;
}

.th-filter-bar .rz-dropdown,
.th-filter-bar .rz-textbox,
.th-filter-bar .rz-datepicker {
    min-height: 34px;
    height: auto;
}

/* Dropdowns land at 40px (their label adds padding); match it so a text filter
   lines up with its neighbours in the bottom-aligned bar. */
.th-filter-bar .rz-textbox {
    min-height: 40px;
}

/* Multi-select chips: tight padding, wrap within the trigger. */
.th-filter-bar .rz-chip,
.th-filter-bar .rz-multiselect-chip {
    padding: 1px 4px 1px 6px;
    margin: 2px;
}

.th-filter-bar .rz-dropdown .rz-dropdown-label,
.th-filter-bar .rz-dropdown .rz-inputtext {
    white-space: normal;
    padding-top: 3px;
    padding-bottom: 3px;
}

.th-filter-daterange .rz-datepicker {
    flex: 1 1 0;
    min-width: 0;
}

/* Dropdown popups render at the document root (outside their trigger's
   container), so item sizing is global and can't be scoped per call site.
   Kept at the body font size: these are the same popups the form dropdowns
   (company, model, linked user, …) open, where 12px read as cramped. The
   filter bar still gets compact *triggers* (sized above) — only the open
   list is sized here, so toolbar density is unaffected. */
.rz-dropdown-panel .rz-dropdown-item,
.rz-dropdown-panel .rz-multiselect-item {
    font-size: 14px;
    padding-top: 7px;
    padding-bottom: 7px;
}

.rz-dropdown-panel .rz-dropdown-filter-container .rz-inputtext {
    font-size: 14px;
}

/* ===== Buttons =====
   Sentence-case IBM Plex Sans: the earlier mono uppercase labels read poorly.
   Radzen's Material buttons get the same treatment so both kinds match. */

.rz-button,
.rz-button-xs,
.rz-button-sm,
.rz-button-md,
.rz-button-lg {
    font-family: var(--th-font-body);
    font-weight: 500;
    letter-spacing: normal;
    text-transform: none;
}

.rz-button,
.rz-button-sm,
.rz-button-xs {
    font-size: 13px;
}

.th-button {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 0 15px;
    color: var(--th-surface);
    background: var(--th-teal);
    font-family: var(--th-font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    text-decoration: none;
}

.th-button:hover {
    background: var(--th-teal-strong);
}

.th-button.secondary {
    color: var(--th-ink);
    border-color: var(--th-line);
    background: var(--th-surface-2);
}

.th-button.secondary:hover {
    background: var(--th-paper);
}

/* ===== Columns picker ===== */

.th-columns-menu {
    position: relative;
    display: inline-block;
}

.th-columns-menu__backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 40;
}

.th-columns-menu__panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 50;
    min-width: 240px;
    padding: 8px 0;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
}

.th-columns-menu__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px 10px;
    border-bottom: 1px solid var(--th-line);
    color: var(--th-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.th-columns-menu__reset {
    border: none;
    background: transparent;
    padding: 2px 4px;
    color: var(--th-teal);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.th-columns-menu__reset:hover {
    text-decoration: underline;
}

.th-columns-menu__list {
    margin: 0;
    padding: 4px 0;
    list-style: none;
    /* Sized to comfortably fit every device column without scrolling on a
       standard laptop viewport; falls back to a visible scrollbar on very
       short windows so no entry is silently clipped. */
    max-height: min(70vh, 560px);
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.th-columns-menu__row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 14px 0 6px;
}

.th-columns-menu__row:hover {
    background: var(--th-surface-2);
}

.th-columns-menu__row.is-dragging {
    opacity: 0.45;
}

.th-columns-menu__row.is-drag-over {
    /* Insertion indicator: the dragged column will land at this row. */
    box-shadow: inset 0 2px 0 var(--th-teal);
}

.th-columns-menu__drag-handle {
    flex: 0 0 auto;
    padding: 8px 2px;
    color: var(--th-muted);
    font-size: 11px;
    letter-spacing: -2px;
    line-height: 1;
    cursor: grab;
    user-select: none;
}

.th-columns-menu__row:active .th-columns-menu__drag-handle {
    cursor: grabbing;
}

.th-columns-menu__item {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    color: var(--th-ink);
    font-size: 13px;
    cursor: pointer;
}

.th-columns-menu__item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--th-teal);
    cursor: pointer;
}

.th-columns-menu__item.is-locked {
    color: var(--th-muted);
    cursor: not-allowed;
}

.th-columns-menu__item.is-locked input[type="checkbox"] {
    cursor: not-allowed;
}

/* ===== Grid export menu (shares the columns-picker popover) ===== */

.th-export-menu__trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.th-export-menu__trigger svg {
    flex: none;
}

.th-export-menu__panel {
    min-width: 180px;
    padding: 4px 0;
}

/* Full-width menu rows; reset Radzen's uppercase, bold button type to match the columns menu. */
.th-export-menu__panel .th-export-menu__item.rz-button.rz-variant-text {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: flex-start;
    padding: 8px 14px;
    border-radius: 0;
    color: var(--th-ink);
    font-family: inherit;
    font-size: 13px;
    font-weight: 400;
    letter-spacing: normal;
    text-transform: none;
}

.th-export-menu__panel .th-export-menu__item.rz-button svg {
    flex: none;
    color: var(--th-muted);
}

/* ===== Cards ===== */

.th-card {
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
    overflow: hidden;
}

/* hidden makes the card a scroll container, which would stop an open inline editor's actions from sticking. */
.th-card:has(.th-section-edit) {
    overflow: clip;
}

.th-panel {
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
    padding: 16px;
}

.th-panel h4 {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 600;
}

/* ===== Badges ===== */

.th-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.th-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: currentColor;
}

.th-badge.green {
    color: var(--th-badge-green-color);
    background: var(--th-badge-green-bg);
}

.th-badge.amber {
    color: #a16411;
    background: var(--th-amber-soft);
}

.th-badge.red {
    color: var(--th-red);
    background: var(--th-red-soft);
}

.th-badge.blue {
    color: var(--th-blue);
    background: var(--th-blue-soft);
}

.th-badge.gray {
    color: var(--th-muted);
    background: var(--th-badge-gray-bg);
}

/* ===== Detail page ===== */

.th-detail-toolbar {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
}

.th-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) 340px;
    gap: 16px;
}

.th-detail-title {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: start;
    padding: 18px;
    border-bottom: 1px solid var(--th-line);
}

.th-detail-title h2 {
    font-size: 28px;
    font-weight: 600;
}

.th-badge-row {
    display: inline-flex;
    gap: 8px;
    align-items: center;
}

.th-detail-meta {
    margin-top: 8px;
    color: var(--th-muted);
    font-size: 14px;
}

.th-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--th-line);
    background: var(--th-tabs-bg);
}

.th-tab {
    padding: 12px 16px;
    color: var(--th-tab-color);
    border-right: 1px solid var(--th-line);
    /* Tabs are <button>s, which don't inherit the page font (they fell back to Arial). */
    font-family: inherit;
    font-size: var(--th-tab-font-size);
    font-weight: var(--th-tab-font-weight);
    letter-spacing: var(--th-tab-letter-spacing);
    cursor: pointer;
    background: transparent;
    border-top: none;
    border-left: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}

.th-tab.active {
    color: var(--th-teal);
    background: var(--th-surface);
    border-bottom-color: var(--th-teal);
}

.th-detail-section {
    border-bottom: 1px solid var(--th-line);
}

.th-detail-section:last-child {
    border-bottom: none;
}

.th-detail-section > header {
    padding: 16px 18px 0;
    color: var(--th-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.th-detail-section > .th-caption {
    padding: 10px 18px 18px;
}

/* Empty-state line inside a detail card (sits below the .th-detail-title divider). */
.th-card > .th-caption {
    padding: 16px 18px;
}

.th-detail-notes {
    margin: 0;
    padding: 10px 18px 18px;
    white-space: pre-wrap;
}

.th-field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 18px;
}

.th-field {
    padding: 12px;
    border: 1px solid var(--th-line);
    border-radius: 7px;
    background: var(--th-field-bg);
}

.th-field small {
    display: block;
    color: var(--th-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.th-field strong {
    display: block;
    margin-top: 5px;
    overflow-wrap: break-word;
    font-weight: 600;
}

.th-side-stack {
    display: grid;
    gap: 12px;
    align-content: start;
}

.th-timeline {
    display: grid;
    gap: 10px;
}

.th-timeline-item {
    padding-left: 14px;
    border-left: 3px solid var(--th-sage);
}

.th-timeline-item strong {
    font-size: 13px;
    font-weight: 600;
}

.th-timeline-item small {
    color: var(--th-muted);
    font-size: 12px;
}

/* ===== Radzen DataGrid theme overrides ===== */

/* The grid card is the horizontal-scroll container. Without this, the sum of
   the column widths can exceed the available main-column width and the
   overflow escapes to <body>, which is what dragged the sticky topbar
   sideways and showed an empty strip past the right edge of the page. */
.th-grid {
    min-width: 0;
    overflow-x: auto;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
}

.th-grid .rz-data-grid {
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 220px);
    max-height: calc(100dvh - 220px);
}

/* Keep long result sets in the grid's flexible middle section. Radzen puts the
   table (including its thead) here and the pager after it, so only the rows
   scroll while the column labels and paging controls remain visible. */
.th-grid .rz-data-grid-data {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.th-grid .rz-grid-table thead th {
    color: var(--th-muted);
    background: var(--th-grid-head-bg);
    font-size: 12px;
    font-weight: 600;
    border-bottom: 1px solid var(--th-line);
    padding: 6px 8px;
    position: sticky;
    top: 0;
    z-index: 2;
    box-shadow: 0 1px 0 var(--th-line);
}

/* Trim Radzen's nested header padding so column titles aren't squeezed
   between the cell padding and the sort indicator. */
.th-grid .rz-grid-table thead th .rz-column-title {
    padding: 0;
    gap: 6px;
}

.th-grid .rz-grid-table thead th .rz-cell-data {
    padding: 0;
}

.th-grid .rz-grid-table thead th .rz-column-title-content {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
}

.th-grid .rz-grid-table tbody td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--th-line);
    vertical-align: middle;
    color: var(--th-ink);
    /* Explicit base background so Radzen Material's default white can't
       leak through in dark mode. The `:nth-child(even)` rule below
       composites on top of this for the zebra stripe. */
    background: var(--th-surface);
}

.th-grid .rz-grid-table tbody tr:nth-child(even) td {
    background: var(--th-grid-row-stripe);
}

.th-grid .rz-grid-table tbody tr:hover td {
    background: var(--th-grid-row-hover);
    cursor: pointer;
}

.th-grid .rz-grid-table tbody tr.rz-state-highlight td,
.th-grid .rz-grid-table tbody tr.rz-selected td {
    background: var(--th-amber-soft);
    box-shadow: inset 4px 0 0 var(--th-amber);
}

/* Radzen's paginator sits inside `.th-grid` after the table; without an
   override it inherits Material's white in dark mode and looks like an
   abandoned strip at the bottom of the card. */
.th-grid .rz-pager,
.th-grid .rz-paginator,
.th-grid .rz-data-grid-pager {
    color: var(--th-muted);
    background: var(--th-grid-head-bg);
    border-top: 1px solid var(--th-line);
    flex: 0 0 auto;
    position: sticky;
    bottom: 0;
    z-index: 3;
}

.th-grid .rz-pager .rz-paginator-element,
.th-grid .rz-pager .rz-paginator-page,
.th-grid .rz-pager .rz-paginator-pages > * {
    color: var(--th-ink);
    background: transparent;
}

.th-grid .rz-pager .rz-state-active {
    color: var(--th-surface);
    background: var(--th-teal);
}

/* The page-size dropdown defaults too narrow and truncates "100"/"200" to
   "1…". Give it room for three digits plus the chevron, and stop the label
   from clipping. */
.th-grid .rz-pager .rz-dropdown,
.th-grid .rz-paginator .rz-dropdown {
    width: auto;
    min-width: 76px;
}

.th-grid .rz-pager .rz-dropdown .rz-dropdown-label,
.th-grid .rz-paginator .rz-dropdown .rz-dropdown-label {
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
}

/* ===== Caption / footnote ===== */

.th-caption {
    margin: 0;
    color: var(--th-muted);
    font-size: 13px;
    line-height: 1.55;
}

/* ===== Empty state =====
   Centered placeholder for a section with nothing in it yet: soft icon disc
   (same treatment as the audit feed's category discs), muted message, then
   the call-to-action. */

.th-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 40px 24px 44px;
    text-align: center;
}

.th-empty-state__icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-bottom: 6px;
    border-radius: 999px;
    color: var(--th-muted);
    background: var(--th-badge-gray-bg);
}

.th-empty-state__text {
    margin: 0;
    color: var(--th-muted);
    font-size: 14px;
}

.th-empty-state .th-button {
    margin-top: 12px;
}

/* ===== Upload drop zone =====
   Styled stand-in for the native file input: the real input is stretched
   invisibly across the zone so clicking and drag-and-drop keep their built-in
   behavior without JS interop. Icon disc mirrors the empty-state treatment;
   amber accent on hover/focus. */

.th-upload {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    border: 1.5px dashed var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-field-bg);
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.th-upload:hover:not(.is-disabled),
.th-upload:has(.th-upload__input:focus-visible) {
    border-color: var(--th-amber);
    background: var(--th-grid-row-hover);
}

.th-upload:has(.th-upload__input:focus-visible) {
    outline: 2px solid var(--th-amber);
    outline-offset: 2px;
}

.th-upload.is-disabled {
    cursor: default;
    opacity: 0.6;
}

.th-upload__input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: inherit;
}

.th-upload__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    color: var(--th-muted);
    background: var(--th-badge-gray-bg);
    transition: color 0.15s ease;
}

.th-upload:hover:not(.is-disabled) .th-upload__icon {
    color: var(--th-amber);
}

.th-upload__text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.th-upload__title {
    font-weight: 600;
    font-size: 14px;
    color: var(--th-ink);
    overflow-wrap: anywhere;
}

.th-upload__hint {
    font-size: 12.5px;
    color: var(--th-muted);
}

/* Summary body of the import preview/result card: outcome counts, secondary
   lines, then the action — one left-aligned stack so the button stays visually
   attached to the counts it acts on. */

.th-import-summary {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 18px 18px;
}

.th-import-dialog {
    display: grid;
    gap: 16px;
}

/* The summary pads itself for a card; inside the dialog the body already does. */
.th-import-dialog .th-import-summary {
    padding: 0;
}

.th-import-summary__badges {
    flex-wrap: wrap;
    row-gap: 8px;
}

.th-import-summary .th-button {
    margin-top: 4px;
}

.th-import-summary .th-caption,
.th-import-summary .th-form-submit-error {
    margin: 0;
}

/* Import progress: the dashboard's bar track, in two modes — determinate while
   the upload's byte count is known, indeterminate for the parse/apply stages
   whose work has no measurable total. */

.th-import-progress {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.th-import-progress .th-caption {
    margin: 0;
}

.th-import-progress .th-bar-track,
.th-import-summary .th-bar-track {
    width: 100%;
    max-width: 420px;
}

.th-bar-fill.indeterminate {
    width: 38%;
    animation: th-bar-slide 1.2s ease-in-out infinite;
}

@keyframes th-bar-slide {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(265%);
    }
}

@media (prefers-reduced-motion: reduce) {
    .th-bar-fill.indeterminate {
        width: 100%;
        opacity: 0.45;
        animation: none;
    }
}

/* Operational defects ----------------------------------------------------- */

.th-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--th-muted);
    font-size: 12px;
    white-space: nowrap;
}

.th-check input {
    accent-color: var(--th-teal);
}

.th-defect-severity {
    display: inline-grid;
    place-items: center;
    min-width: 34px;
    height: 28px;
    padding: 0 8px;
    border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
    border-radius: 7px;
    font-family: var(--th-font-mono);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .06em;
    line-height: 1;
    flex: none;
}

.th-defect-severity.is-critical {
    color: var(--th-red);
    background: var(--th-red-soft);
}

.th-defect-severity.is-fixed {
    color: var(--th-badge-green-color);
    background: var(--th-badge-green-bg);
}

.th-defect-severity.is-advisory {
    color: var(--th-amber);
    background: var(--th-amber-soft);
}

.th-inspection-findings {
    margin-top: 0;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: color-mix(in srgb, var(--th-surface-2) 72%, transparent);
}

.th-inspection-findings__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.th-inspection-findings__header > div {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.th-inspection-findings__header small,
.th-defect-kicker {
    color: var(--th-muted);
    font-family: var(--th-font-mono);
    font-size: 10px;
    letter-spacing: .11em;
    text-transform: uppercase;
}

.th-inspection-findings__list {
    display: grid;
    gap: 7px;
    margin-top: 10px;
}

.th-inspection-finding {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border: 1px solid var(--th-line);
    border-radius: 8px;
    background: var(--th-surface);
    color: var(--th-ink);
    text-decoration: none;
}

.th-inspection-finding:hover {
    border-color: var(--th-teal);
    background: var(--th-teal-soft);
}

.th-inspection-finding > span:nth-child(2) {
    display: grid;
}

.th-inspection-finding small {
    color: var(--th-muted);
}

.th-inspection-finding.is-archived {
    opacity: .68;
}

.th-defect-entry-dialog,
.th-defect-transition-dialog {
    display: grid;
    gap: 18px;
}

.th-defect-entry-dialog__step {
    display: grid;
    gap: 3px;
    padding: 11px 13px;
    border-left: 3px solid var(--th-teal);
    background: var(--th-teal-soft);
}

.th-defect-entry-dialog__step span {
    color: var(--th-muted);
    font-family: var(--th-font-mono);
    font-size: 10px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.th-defect-choice-list {
    display: grid;
    gap: 7px;
}

.th-defect-choice {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--th-line);
    border-radius: 8px;
    background: var(--th-surface);
    color: var(--th-ink);
    text-align: left;
    cursor: pointer;
}

.th-defect-choice:hover:not(:disabled),
.th-defect-choice.is-selected {
    border-color: var(--th-teal);
    background: var(--th-teal-soft);
}

.th-defect-choice:disabled {
    cursor: default;
    opacity: .64;
}

.th-defect-choice > span:nth-child(2) {
    display: grid;
    gap: 2px;
}

.th-defect-choice small {
    color: var(--th-muted);
}

.th-defect-choice__indicator {
    width: 15px;
    height: 15px;
    border: 2px solid var(--th-faint);
    border-radius: 50%;
}

.th-defect-choice.is-selected .th-defect-choice__indicator {
    border: 4px solid var(--th-teal);
}

.th-defect-severity-hint {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    padding: 10px 12px;
    border-left: 3px solid var(--th-amber);
    background: var(--th-amber-soft);
    color: var(--th-ink);
    font-size: 12px;
}

.th-defect-severity-hint.is-critical {
    border-color: var(--th-red);
    background: var(--th-red-soft);
}

.th-defect-severity-hint.is-fixed {
    border-color: var(--th-badge-green-color);
    background: var(--th-badge-green-bg);
}

.th-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    padding-top: 4px;
}

.th-defect-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
    gap: 16px;
    align-items: start;
}

.th-defect-photos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    padding: 18px;
}

.th-defect-photo {
    display: block;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
}

.th-defect-photo:hover,
.th-defect-photo:focus-visible {
    border-color: var(--th-teal);
}

.th-defect-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.th-defect-hero {
    border-left: 4px solid var(--th-amber);
}

.th-defect-hero.is-critical {
    border-left-color: var(--th-red);
}

.th-defect-hero.is-fixed {
    border-left-color: var(--th-badge-green-color);
}

.th-defect-kicker {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 8px;
}

.th-context-link {
    display: grid;
    gap: 3px;
    margin-top: 10px;
    padding: 11px 12px;
    border: 1px solid var(--th-line);
    border-radius: 8px;
    background: var(--th-surface);
    color: var(--th-ink);
    text-decoration: none;
}

.th-context-link:hover {
    border-color: var(--th-teal);
}

.th-context-link span {
    color: var(--th-muted);
    font-size: 12px;
}

.th-defect-history {
    display: grid;
    gap: 7px;
    padding: 16px 18px 18px;
}

.th-defect-history-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--th-line);
    border-radius: 8px;
    background: var(--th-surface);
    color: var(--th-ink);
    text-align: left;
    cursor: pointer;
}

.th-defect-history-row:hover {
    border-color: var(--th-teal);
    background: var(--th-surface-2);
}

.th-defect-history-main {
    display: grid;
    gap: 2px;
}

.th-defect-history-main small {
    color: var(--th-muted);
}

.th-button--defects {
    border-color: color-mix(in srgb, var(--th-red) 45%, var(--th-line));
    background: var(--th-red-soft);
    color: var(--th-red);
}

@media (max-width: 1050px) {
    .th-defect-detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 680px) {
    .th-inspection-findings__header,
    .th-dialog-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .th-inspection-findings__header .th-button,
    .th-dialog-actions .th-button {
        width: 100%;
    }

    .th-defect-history-row {
        grid-template-columns: auto minmax(0, 1fr);
    }
}

/* Inspection execution — compact, industrial status rail built on the manager palette. */
.th-inspection-detail {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    min-width: 0;
}

.th-inspection-detail > .th-detail-toolbar {
    flex-wrap: wrap;
}

/* Pinned under the sticky topbar (~93px tall with the page header) while the steps scroll. */
.th-inspection-steps-bar {
    position: sticky;
    top: 92px;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px 14px;
    margin-bottom: -10px;
    padding: 6px 10px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
    box-shadow: 0 4px 10px -8px rgba(0, 0, 0, 0.35);
}

.th-inspection-steps-bar__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.th-inspection-progress {
    display: flex;
    align-items: center;
    gap: 10px;
}

.th-inspection-progress small {
    color: var(--th-muted);
}

.th-inspection-progress strong {
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.th-inspection-progress .th-progress-track {
    width: 120px;
}

.th-progress-track {
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--th-badge-gray-bg);
}

.th-progress-track > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--th-teal);
    transition: width 0.18s ease;
}

.th-inspection-steps {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    min-width: 0;
}

.th-inspection-validation-summary {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 11px;
    margin-bottom: 10px;
    padding: 12px 14px;
    border: 1px solid color-mix(in srgb, var(--th-red) 45%, transparent);
    border-radius: var(--th-radius);
    background: linear-gradient(110deg, color-mix(in srgb, var(--th-red-soft) 72%, var(--th-surface)), var(--th-surface) 72%);
}

.th-inspection-validation-summary__mark {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    color: #fff;
    background: var(--th-red);
    font-family: var(--th-font-mono);
    font-weight: 800;
}

.th-inspection-validation-summary > div > strong {
    color: var(--th-red);
    font-size: 14px;
}

.th-inspection-validation-summary p {
    margin: 2px 0 9px;
    color: var(--th-muted);
    font-size: 13px;
}

.th-inspection-validation-summary__steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 6px;
}

.th-inspection-validation-summary__steps a {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    padding: 7px 9px;
    border: 1px solid color-mix(in srgb, var(--th-red) 24%, var(--th-line));
    border-radius: 6px;
    background: color-mix(in srgb, var(--th-surface) 88%, transparent);
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.th-inspection-validation-summary__steps a:hover {
    border-color: var(--th-red);
    background: var(--th-surface);
}

.th-inspection-validation-summary__steps a > span:first-child {
    color: var(--th-red);
    font-family: var(--th-font-mono);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
}

.th-inspection-validation-summary__steps a > span:last-child {
    min-width: 0;
    display: grid;
    gap: 1px;
}

.th-inspection-validation-summary__steps strong,
.th-inspection-validation-summary__steps small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.th-inspection-validation-summary__steps strong {
    color: var(--th-ink);
    font-size: 12px;
}

.th-inspection-validation-summary__steps small {
    color: var(--th-red);
    font-size: 11px;
}

.th-inspection-step {
    position: relative;
    overflow: hidden;
    min-width: 0;
    padding: 0 0 0 6px;
    scroll-margin-top: 130px;
}

.th-inspection-step::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--th-faint);
}

.th-inspection-step.is-passed::before { background: var(--th-badge-green-color); }
.th-inspection-step.is-failed::before { background: var(--th-red); }
.th-inspection-step.is-na::before { background: var(--th-faint); }
.th-inspection-step.is-pending::before { background: var(--th-blue); }

.th-inspection-step.has-completion-error {
    border-color: color-mix(in srgb, var(--th-red) 58%, transparent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--th-red) 14%, transparent);
}

.th-inspection-step.has-completion-error::before {
    background: var(--th-red);
}

.th-inspection-step__header {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto auto;
    gap: 10px;
    align-items: center;
    padding: 3px 8px;
}

.th-inspection-step.is-expanded .th-inspection-step__header {
    border-bottom: 1px solid var(--th-line);
}

.th-inspection-step__number {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: var(--th-teal);
    background: var(--th-teal-soft);
    font-size: 11px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.th-inspection-step.is-passed .th-inspection-step__number {
    color: var(--th-badge-green-color);
    background: var(--th-badge-green-bg);
}

.th-inspection-step.is-failed .th-inspection-step__number {
    color: var(--th-red);
    background: var(--th-red-soft);
}

.th-inspection-step__summary {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 16px;
    gap: 8px;
    align-items: center;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.th-inspection-step__summary:focus {
    outline: none;
}

.th-inspection-step__summary:focus-visible {
    outline: 2px solid var(--th-teal);
    outline-offset: 2px;
    border-radius: 6px;
}

.th-inspection-step__summary:hover .th-inspection-step__name,
.th-inspection-step__summary:focus-visible .th-inspection-step__name {
    color: var(--th-teal);
}

.th-inspection-step__title {
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.th-inspection-step__title small {
    flex: none;
    white-space: nowrap;
}

.th-inspection-step__name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13.5px;
    font-weight: 650;
    line-height: 1.25;
}

.th-inspection-step__title small,
.th-inspection-suggestions > small,
.th-inspection-limit small {
    color: var(--th-muted);
}

.th-inspection-step__chips {
    display: flex;
    flex: none;
    gap: 4px;
}

.th-inspection-step__chip {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--th-surface-2);
    color: var(--th-muted);
    font-family: var(--th-font-mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.th-inspection-step__chip.is-defect {
    color: var(--th-red);
    background: var(--th-red-soft);
}

.th-inspection-step__chevron {
    width: 16px;
    height: 16px;
    display: grid;
    place-items: center;
    color: var(--th-muted);
}

.th-inspection-step__chevron::before {
    content: "";
    width: 6px;
    height: 6px;
    border-right: 1.6px solid currentColor;
    border-bottom: 1.6px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.th-inspection-step.is-expanded .th-inspection-step__chevron::before {
    transform: rotate(225deg);
}

.th-inspection-result {
    grid-column: -2;
    width: auto;
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    justify-self: end;
    border: 1px solid var(--th-line);
    border-radius: 8px;
    overflow: hidden;
    background: var(--th-surface-2);
}

.th-inspection-result__option {
    min-width: 48px;
    min-height: 26px;
    padding: 0 9px;
    border: 0;
    border-right: 1px solid var(--th-line);
    background: transparent;
    color: var(--th-muted);
    font-family: var(--th-font-mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
}

.th-inspection-result__option:focus {
    outline: none;
}

.th-inspection-result__option:focus-visible {
    z-index: 1;
    outline: 2px solid var(--th-teal);
    outline-offset: -2px;
}

.th-inspection-result__option:last-of-type {
    border-right: 0;
}

.th-inspection-result__option:hover:not(:disabled):not(.is-active) {
    background: var(--th-paper);
    color: var(--th-ink);
}

.th-inspection-result__option:disabled {
    cursor: default;
}

.th-inspection-result__option.is-passed.is-active {
    color: var(--th-badge-green-color);
    background: var(--th-badge-green-bg);
}

.th-inspection-result__option.is-failed.is-active {
    color: var(--th-red);
    background: var(--th-red-soft);
}

.th-inspection-result__option.is-na.is-active {
    color: var(--th-ink);
    background: var(--th-surface);
}

.th-inspection-result.has-completion-error {
    border-color: var(--th-red);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--th-red) 13%, transparent);
}

.th-inspection-result .th-inspection-step__field-error {
    flex: 1 0 100%;
    padding: 4px 8px 6px;
    border-top: 1px solid color-mix(in srgb, var(--th-red) 35%, var(--th-line));
}

.th-inspection-step__save {
    min-height: 30px;
    min-width: 0;
    padding: 0 10px;
}

.th-inspection-step__body {
    display: grid;
    gap: 10px;
    min-width: 0;
    padding: 8px 10px 10px 42px;
}

.th-inspection-step__field-error {
    display: flex;
    gap: 5px;
    align-items: flex-start;
    color: var(--th-red);
    font-size: 11.5px;
    line-height: 1.35;
}

.th-inspection-step__field-error::before {
    content: "!";
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    display: grid;
    place-items: center;
    margin-top: 1px;
    border-radius: 50%;
    color: #fff;
    background: var(--th-red);
    font-family: var(--th-font-mono);
    font-size: 9px;
    font-weight: 800;
}

.th-form-field.has-completion-error .has-error,
.th-form-field.has-completion-error .has-error input {
    border-color: var(--th-red) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--th-red) 13%, transparent);
}

.th-inspection-measurement {
    display: flex;
    align-items: center;
    gap: 8px;
}

.th-inspection-measurement .th-form-field {
    gap: 2px;
}

/* Fixed widths keep the value and result columns aligned from row to row. */
.th-inspection-limit {
    width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--th-muted);
    white-space: nowrap;
}

.th-inspection-measurement .rz-numeric {
    height: 28px;
}

.th-inspection-value-entry {
    display: flex;
    align-items: center;
    gap: 8px;
}

.th-inspection-value-entry > .rz-numeric,
.th-inspection-measured-value {
    width: 100px;
    flex: none;
}

.th-inspection-measurement .th-inspection-measured-value {
    padding: 3px 8px;
    font-size: 13px;
}

.th-inspection-unit {
    flex: none;
    min-width: 28px;
    color: var(--th-ink);
    font-family: var(--th-font-mono);
    font-size: 12px;
    text-transform: none;
}

.th-inspection-readonly {
    display: block;
    padding: 10px 12px;
    border: 1px solid var(--th-line);
    border-radius: 7px;
    background: var(--th-surface);
    color: var(--th-ink);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.th-inspection-note__value {
    white-space: pre-wrap;
}

.th-inspection-suggestions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 10px;
    margin-top: 0;
    padding: 7px 9px;
    border: 1px dashed var(--th-line);
    border-radius: 7px;
    background: var(--th-surface-2);
}

.th-inspection-suggestions > small {
    flex: 0 0 auto;
}

.th-inspection-suggestions .th-badge-row {
    gap: 6px;
}

.th-inspection-step__footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
    margin-top: 0;
    min-width: 0;
}

.th-inspection-note {
    min-width: 0;
    gap: 4px;
}

.th-inspection-note .th-inspection-note__control,
.th-inspection-note .rz-textarea,
.th-inspection-note .rz-textarea textarea {
    width: 100%;
    min-width: 0;
}

.th-inspection-note .th-inspection-note__control {
    height: 32px;
    min-height: 32px;
    padding-top: 6px;
    padding-bottom: 6px;
    line-height: 1.4;
}

/* Radzen inputs default to 16px; match the 13.5px step text in the compact list. */
.th-inspection-note .th-inspection-note__control,
.th-inspection-measurement input {
    font-size: 13px;
}

.th-device-inspections {
    display: grid;
    gap: 12px;
    padding: 16px 18px 18px;
}

.th-inspection-history-list {
    display: grid;
    border: 1px solid var(--th-line);
    border-radius: 8px;
    overflow: hidden;
}

.th-inspection-history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid var(--th-line);
}

.th-inspection-history-row:last-child { border-bottom: 0; }
.th-inspection-history-row:hover { background: var(--th-surface-2); }

.th-inspection-history-row > span:first-child {
    display: grid;
    gap: 3px;
}

.th-inspection-history-row small { color: var(--th-muted); }

@media (max-width: 760px) {
    .th-inspection-steps-bar {
        top: 0;
    }

    .th-inspection-step__title {
        flex-wrap: wrap;
        row-gap: 0;
    }

    .th-inspection-step__name {
        white-space: normal;
    }

    .th-inspection-step__header {
        grid-template-columns: 24px minmax(0, 1fr);
    }

    .th-inspection-step__header .th-inspection-measurement {
        grid-column: 2 / -1;
    }

    .th-inspection-result {
        grid-column: 1 / -1;
        flex-wrap: wrap;
    }

    .th-inspection-header .th-detail-title {
        flex-wrap: wrap;
    }

    .th-inspection-header .th-detail-title > div {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .th-inspection-result__option {
        flex: 1 1 auto;
    }

    .th-inspection-step__body {
        padding-left: 12px;
    }

    .th-inspection-step__footer {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
}

/* ===== Layout responsive ===== */

@media (max-width: 1100px) {
    .th-shell {
        grid-template-columns: 1fr;
        background: var(--th-main-bg);
    }

    .th-sidebar {
        position: relative;
        height: auto;
        min-height: auto;
        overflow-y: visible;
        scrollbar-gutter: auto;
    }

    .th-detail-grid {
        grid-template-columns: 1fr;
    }

}

@media (max-width: 760px) {
    .th-topbar,
    .th-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    /* The stacked topbar is ~150px tall; pinning it would eat a phone screen. */
    .th-topbar {
        position: static;
    }

    .th-search,
    .th-search-field {
        width: 100%;
    }

    /* Stacked toolbar: the search and filters wrap onto their own lines, so a
       left-edge divider would float above the filter group instead of between
       the two. Drop it. */

    .th-field-grid {
        grid-template-columns: 1fr;
    }

}

/* ===== Theme switch transitions =====
   Targeted to surfaces and chrome whose colors actually change between
   themes. Kept off interactive states (hover/focus) so flips stay snappy. */

.th-panel,
.th-card,
.th-toolbar,
.th-grid,
.th-search,
.th-field,
.th-columns-menu__panel,
.th-tabs,
.th-tab,
.th-button.secondary {
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

/* ===== Dark theme =====
   "Dimmed forest cabin" — deep mossy near-black surfaces, cream ink,
   the same sage/amber/teal accent character lifted just enough to keep
   contrast on dark. Sidebar tightens against the chrome instead of
   floating, since now the rest of the shell shares its tone. */

html[data-th-theme="dark"] {
    /* Workspace surfaces are a cool neutral slate — the forest-green
       sidebar reads as a deliberate "navigation pillar" against this
       cooler background instead of bleeding the same hue into the whole
       chrome. Elevation runs bg < main < surface < surface-2, each step
       a resolved colour (no transparency) so Radzen Material can't peek
       through. Amber and sage stay as warm accents on top. */
    --th-bg: #15191f;
    --th-paper: #1a1f26;
    --th-surface: #1e242c;
    --th-surface-2: #272e37;
    --th-ink: #ecedf0;
    --th-muted: #9aa1ab;
    --th-faint: #5e6670;
    --th-line: rgba(236, 240, 245, 0.13);
    --th-sidebar: #141f1c;
    --th-sidebar-2: #1d2926;
    --th-sidebar-text: #eef3ee;
    --th-sage: #9ab69e;
    --th-sage-soft: #25342f;
    --th-teal: #3fa7a0;
    --th-teal-strong: #51beb6;
    --th-teal-soft: #163632;
    --th-amber: #ebad4d;
    --th-amber-soft: #3f2f14;
    --th-red: #d8665a;
    --th-red-soft: #3b211b;
    --th-blue: #7aa3c5;
    --th-blue-soft: #1d2c38;
    --th-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);

    --th-body-grid-line: rgba(236, 240, 245, 0.035);
    --th-body-glow: rgba(232, 169, 73, 0.08);
    --th-main-bg: #181d24;
    --th-topbar-bg: rgba(24, 29, 36, 0.84);
    --th-tabs-bg: #1b2129;
    --th-field-bg: #1e242c;
    --th-grid-head-bg: #1b2129;
    /* Stripe sits one notch above the surface — solid colour, never
       translucent, so it composites cleanly over the cell background
       even when Radzen sets its own. */
    --th-grid-row-stripe: #232a33;
    --th-grid-row-hover: rgba(232, 169, 73, 0.11);
    --th-badge-green-color: #a4d0ac;
    --th-badge-green-bg: rgba(111, 143, 115, 0.18);
    --th-badge-gray-bg: rgba(236, 240, 245, 0.09);
    --th-sidebar-active: rgba(232, 169, 73, 0.20);
    --th-sidebar-toggle-border: rgba(236, 241, 237, 0.14);
    --th-sidebar-toggle-bg: rgba(236, 241, 237, 0.04);

    color-scheme: dark;
}

/* ===== Radzen theme bridge =====
   `<RadzenTheme>` in App.razor loads Radzen's themed CSS (material in
   light, material-dark in dark). Material's stock primary is purple /
   indigo, which clashes with the editorial sage+amber direction this
   shell commits to, so we re-point Radzen's high-traffic CSS variables
   at our `--th-*` palette. This way dropdowns, dialogs, paginator,
   tooltips, NotificationService toasts, etc. inherit our accent colours
   without needing per-widget overrides.

   `color-mix()` gives us the translucent tints Radzen uses for hover /
   selection states — supported in all evergreen browsers we target. */

:root {
    --rz-primary: var(--th-teal);
    --rz-primary-light: var(--th-teal);
    --rz-primary-dark: var(--th-teal-strong);
    --rz-primary-lighter: color-mix(in srgb, var(--th-teal) 14%, transparent);
    --rz-primary-darker: var(--th-teal-strong);
    --rz-on-primary: #ffffff;

    --rz-secondary: var(--th-amber);
    --rz-secondary-light: var(--th-amber);
    --rz-secondary-lighter: color-mix(in srgb, var(--th-amber) 16%, transparent);
    --rz-on-secondary: #1f2926;

    --rz-success: #34734a;
    --rz-success-lighter: color-mix(in srgb, #34734a 14%, transparent);
    --rz-info: var(--th-blue);
    --rz-info-lighter: color-mix(in srgb, var(--th-blue) 14%, transparent);
    --rz-warning: var(--th-amber);
    --rz-warning-lighter: color-mix(in srgb, var(--th-amber) 14%, transparent);
    --rz-danger: var(--th-red);
    --rz-danger-lighter: color-mix(in srgb, var(--th-red) 14%, transparent);

    --rz-body-background-color: var(--th-bg);
    --rz-base-background-color: var(--th-bg);
    --rz-layout-background-color: var(--th-bg);
    --rz-content-background-color: var(--th-surface);
    --rz-panel-background-color: var(--th-surface);
    --rz-card-background-color: var(--th-surface);
    --rz-dialog-background-color: var(--th-surface);

    --rz-text-color: var(--th-ink);
    --rz-text-secondary-color: var(--th-muted);
    --rz-text-tertiary-color: var(--th-faint);
    --rz-text-title-color: var(--th-ink);
    --rz-text-anchor-color: var(--th-teal);

    --rz-border-color: var(--th-line);
    --rz-border-radius: var(--th-radius);

    /* Empty enabled fields should read as clearly as entered text in both themes. */
    --rz-input-placeholder-color: var(--th-ink);

    /* Radzen's body font would normally win against ours because it's
       loaded by RadzenTheme. Re-bind to IBM Plex Sans so paragraph copy
       inside Radzen widgets matches the rest of the shell. */
    --rz-text-font-family: var(--th-font-body);

    /* Material's tabs are uppercase and tracked out; match our tab strips instead. */
    --rz-tabs-tab-font-size: var(--th-tab-font-size);
    --rz-tabs-tab-font-weight: var(--th-tab-font-weight);
    --rz-tabs-tab-letter-spacing: var(--th-tab-letter-spacing);
    --rz-tabs-tab-text-transform: none;
    --rz-tabs-tab-color: var(--th-tab-color);
}

/* Cover native search/filter inputs and textareas as well as Radzen inputs.
   Remove browser placeholder fading; Radzen retains its disabled-state color. */
input:not(:disabled)::placeholder,
textarea:not(:disabled)::placeholder {
    color: var(--rz-input-placeholder-color);
    opacity: 1;
}

/* Inline "Show archived" toggle in the customers toolbar — a muted labelled
   checkbox that reads as a control, not a form field. */
.th-inline-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--th-muted);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.th-inline-check input {
    cursor: pointer;
    accent-color: var(--th-teal);
}

/* Spacing for the "Archived" chip shown beside the status badge in the grid. */
.th-archived-chip {
    margin-left: 6px;
}

/* Radzen dialog title bar. Radzen's base ships a beige header band on a white
   body, leaves the flex container's align/justify unset (top-aligned title +
   close), and renders a small pure-black ✕. Restyle to a seamless on-brand
   header: same surface as the body, centered title vs. close, balanced spacing,
   and a muted ✕ with a hover affordance. */
.rz-dialog .rz-dialog-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--th-surface);
    padding: 20px 24px 0;
    border: none;
}

.rz-dialog .rz-dialog-titlebar .rz-dialog-title {
    margin: 0;
    line-height: 1.25;
    font-size: 17px;
    font-weight: 600;
    color: var(--th-ink);
}

.rz-dialog .rz-dialog-titlebar .rz-dialog-titlebar-close {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin: -4px -6px -4px 0;
    border-radius: 7px;
    color: var(--th-muted);
    font-size: 16px;
    transition: background 0.15s ease, color 0.15s ease;
}

.rz-dialog .rz-dialog-titlebar .rz-dialog-titlebar-close:hover {
    background: color-mix(in srgb, var(--th-ink) 8%, transparent);
    color: var(--th-ink);
}

/* Tighten the gap under the now-seamless title (the title bar carries no bottom
   padding, so the content's top padding alone spaces the message). */
.rz-dialog .rz-dialog-content {
    padding: 14px 24px 22px;
}

html[data-th-theme="dark"] {
    /* Primary text on a teal button needs to stay legible — in dark
       mode our brighter teal still reads against deep ink rather than
       white. */
    --rz-on-primary: #0f1716;
    --rz-on-secondary: #0f1716;
}

/* Lift the amber/red/blue badge text/background so they stay readable
   against the dark surfaces without breaking the light-mode palette. */
html[data-th-theme="dark"] .th-badge.amber {
    color: #f4c177;
    background: rgba(217, 151, 50, 0.16);
}

html[data-th-theme="dark"] .th-badge.red {
    color: #e88876;
    background: rgba(184, 74, 58, 0.18);
}

html[data-th-theme="dark"] .th-badge.blue {
    color: #8fb4d2;
    background: rgba(52, 107, 143, 0.20);
}

/* Selected rows: keep the amber accent but render it on a darker tile so
   it reads as "warm highlight" instead of "blown-out cream". */
html[data-th-theme="dark"] .th-grid .rz-grid-table tbody tr.rz-state-highlight td,
html[data-th-theme="dark"] .th-grid .rz-grid-table tbody tr.rz-selected td {
    background: rgba(217, 151, 50, 0.14);
}

/* KPI accent gradient: keep the amber wash but seat it on the dark
   surface, otherwise the gradient blooms white. */

/* Primary button text needs to stay legible against the brighter dark-mode
   teal — switch from the surface token (which is now near-black) to a
   deep ink. Scoped with `:not(.secondary)` so the secondary variant keeps
   its cream text on a dark surface (otherwise the "Columns" button reads
   as near-black ink on near-black surface — invisible). */
/* Filled buttons keep the light theme's deeper teal so white text clears AA;
   dark ink on the brighter dark-mode teal read as muddy. */
html[data-th-theme="dark"] .th-button:not(.secondary),
html[data-th-theme="dark"] .rz-button.rz-primary.rz-variant-filled {
    color: #ffffff;
    background-color: #287b75;
}

html[data-th-theme="dark"] .th-button:not(.secondary):hover,
html[data-th-theme="dark"] .rz-button.rz-primary.rz-variant-filled:not(.rz-state-disabled):hover {
    background-color: #1f6962;
}

html[data-th-theme="dark"] .th-avatar {
    color: #0f1716;
}

/* The light popover shadow disappears on dark surfaces; deepen it so the
   profile menu still reads as a lifted layer. */
html[data-th-theme="dark"] .th-usermenu__panel {
    box-shadow: 0 22px 52px rgba(0, 0, 0, 0.55);
}

/* Reduce-motion users: collapse the theme transitions so toggling is an
   instant, intentional swap rather than a fade. */
@media (prefers-reduced-motion: reduce) {
    body,
    .th-main,
    .th-topbar,
    .th-panel,
    .th-card,
    .th-toolbar,
    .th-grid,
    .th-search,
    .th-field,
    .th-columns-menu__panel,
    .th-tabs,
    .th-tab,
    .th-button.secondary {
        transition: none;
    }
}

/* ===== Form page shell =====
   The container, toolbar, and sticky action bar shared by every create/edit
   page (devices, customers, contacts). The editable form body that sits inside
   it is styled in the "Form body" section below. */

.th-form {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.th-form-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Sticky action bar — keeps the primary action one click away no matter how
   long the form grows. The negative margins widen it to the workspace edges so
   it reads as a true footer, not a card. */
.th-form-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 8px -24px -24px;
    padding: 14px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid var(--th-line);
    background: var(--th-surface);
    backdrop-filter: blur(8px);
}

.th-form-actions .th-button {
    min-width: 160px;
    justify-content: center;
}

/* ===== Form body =====
   The editable field sections shared by the device, customer, and contact
   forms (DeviceForm/CustomerForm/ContactForm). These are plain, app-specific
   th- classes, so they live here once and apply to every form rather than
   being copied into each component's scoped stylesheet. Rules that reach into
   Radzen-rendered DOM are written as ordinary descendant selectors (no `::deep`
   — that combinator is only needed inside isolated component stylesheets). */

.th-form-section {
    padding: 22px 26px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.th-form-section > header {
    font-family: var(--th-font-mono);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--th-faint);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--th-line);
}

/* ----- Field grid ----- */

.th-form-grid {
    display: grid;
    gap: 16px;
}

.th-form-grid.one-col {
    grid-template-columns: 1fr;
}

.th-form-grid.two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.th-form-grid.four-col {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1024px) {
    .th-form-grid.four-col {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .th-form-grid.two-col,
    .th-form-grid.four-col {
        grid-template-columns: 1fr;
    }
}

.th-form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.th-form-field label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--th-font-mono);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: var(--th-muted);
}

.th-required-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--th-amber);
    display: inline-block;
}

/* ----- Yes/No toggle (contact form's IsPrimary / CanReceiveDocuments) -----
   A RadzenSwitch sat next to its live state label, sized to line up with the
   text inputs in the same grid row. */

.th-toggle-box {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 38px;
}

.th-toggle-state {
    font-family: var(--th-font-mono);
    font-size: 12px;
    letter-spacing: 0.08em;
    color: var(--th-muted);
}

/* ----- Radzen reach-through -----
   Form inputs are Radzen components whose base look comes from the Radzen theme
   bridge above; these are the few form-specific tweaks that bridge can't know
   about. The `has-error` class lands on the Radzen component root — the input
   itself for text/numeric/area, the wrapper element for the dropdown — so cover
   both it and any inner input. */

.th-form-field textarea {
    resize: vertical;
    min-height: 80px;
}

.th-form-field .has-error,
.th-form-field .has-error input {
    border-color: var(--th-red) !important;
}

/* ----- Read-only field + unit suffix (device form) ----- */

.th-form-readonly {
    padding: 10px 12px;
    border: 1px dashed var(--th-line);
    border-radius: 7px;
    color: var(--th-ink);
    font-size: 14px;
    background: transparent;
}

.th-form-number-wrap {
    position: relative;
}

.th-form-suffix {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--th-font-mono);
    font-size: 10.5px;
    color: var(--th-faint);
    letter-spacing: 0.10em;
    text-transform: none;
    pointer-events: none;
}

/* Reserve room for the unit suffix overlay. The only input rendered under a
   `has-suffix` field is the RadzenNumeric spinner input. */
.th-form-field.has-suffix input {
    padding-right: 64px;
}

/* ----- Validation messages ----- */

.th-form-field-error {
    margin-top: 1px;
    color: var(--th-red);
    font-size: 12px;
}

.th-form-submit-error {
    margin: 0;
    padding: 12px 14px;
    border: 1px solid color-mix(in srgb, var(--th-red) 40%, transparent);
    border-radius: 7px;
    color: var(--th-red);
    background: color-mix(in srgb, var(--th-red) 6%, transparent);
    font-size: 13.5px;
}

/* ===== Generated-number field (device MT number, customer number) =====
   A bordered group that keeps the amber accent and monospaced identifier feel
   while sizing like any other field cell, plus the "auto" generate button and
   its label row. Shared by the device and customer forms. */

.th-form-idnum-labelrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.th-form-idnum-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 12px;
    border: 1px solid rgba(217, 151, 50, 0.30);
    border-radius: 7px;
    background: var(--th-field-bg);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.th-form-idnum-input-group:focus-within {
    border-color: var(--th-teal);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--th-teal) 18%, transparent);
}

.th-form-idnum-input-group.has-error {
    border-color: var(--th-red);
}

.th-form-idnum-prefix {
    flex: none;
    font-family: var(--th-font-mono);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--th-amber);
}

/* Strip the Radzen input's own chrome so the group reads as one field. The
   `!important`s beat Radzen's :hover/:focus border + background states, which
   would otherwise paint a second box inside the group. */
.th-form-idnum-input-group .rz-textbox {
    flex: 1 1 auto;
    min-width: 0;
    height: auto;
    margin: 0;
    padding: 9px 10px 9px 0;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    font-family: var(--th-font-mono);
    font-size: 15px;
    letter-spacing: 0.08em;
    color: var(--th-ink);
}

.th-form-idnum-input-group.has-error .rz-textbox {
    color: var(--th-red);
}

.th-form-idnum-auto {
    flex: none;
    padding: 2px 9px;
    border: 1px solid rgba(217, 151, 50, 0.36);
    border-radius: 5px;
    background: rgba(217, 151, 50, 0.10);
    color: var(--th-amber);
    font-family: var(--th-font-mono);
    font-size: 9.5px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.th-form-idnum-auto:hover {
    background: rgba(217, 151, 50, 0.18);
    border-color: rgba(217, 151, 50, 0.52);
}

.th-form-idnum-auto:focus-visible {
    outline: 2px solid var(--th-amber);
    outline-offset: 2px;
}

/* ===== Audit activity feed =====
   The audit log reads as a chronological story, not a spreadsheet: each entry
   is one human sentence (built in Audit.razor) with a category icon, grouped
   under day headers. Colour is deliberately quiet — a soft category tint on the
   icon disc for normal events — so the rare amber (denied) / red (failed) rows
   are the only thing that shouts. */

.th-audit-toolbar {
    margin-bottom: 18px;
}

/* Day separator: a small mono caption with a hairline rule running to the edge. */
.th-audit-day {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 22px 2px 9px;
    color: var(--th-faint);
    font-family: var(--th-font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.th-audit-day:first-of-type {
    margin-top: 0;
}

.th-audit-day::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--th-line);
}

.th-audit-group {
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
    overflow: hidden;
}

.th-event {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--th-line);
    transition: background 0.12s ease;
}

.th-event:last-child {
    border-bottom: none;
}

.th-event:hover {
    background: var(--th-grid-row-hover);
}

/* Outcome accents: a left rule that only appears when something went wrong. */
.th-event--denied {
    box-shadow: inset 3px 0 0 var(--th-amber);
}

.th-event--failure {
    box-shadow: inset 3px 0 0 var(--th-red);
}

.th-event__icon {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    color: var(--th-muted);
    background: var(--th-badge-gray-bg);
}

.th-event__icon svg {
    width: 17px;
    height: 17px;
}

.th-event__icon.blue {
    color: var(--th-blue);
    background: var(--th-blue-soft);
}

.th-event__icon.teal {
    color: var(--th-teal);
    background: var(--th-teal-soft);
}

.th-event__icon.green {
    color: var(--th-badge-green-color);
    background: var(--th-badge-green-bg);
}

.th-event__icon.amber {
    color: #a16411;
    background: var(--th-amber-soft);
}

.th-event__icon.red {
    color: var(--th-red);
    background: var(--th-red-soft);
}

.th-event__body {
    flex: 1;
    min-width: 0;
}

.th-event__text {
    color: var(--th-ink);
    font-size: 14px;
    line-height: 1.45;
}

.th-event__who {
    font-weight: 600;
}

/* Secondary line: time, optional outcome tag, role chip, failure reason. */
.th-event__sub {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 9px;
    margin-top: 3px;
    color: var(--th-muted);
    font-size: 12.5px;
}

.th-event__time {
    font-family: var(--th-font-mono);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
    color: var(--th-faint);
}

.th-event__tag,
.th-event__role {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.th-event__role {
    color: var(--th-muted);
    background: var(--th-badge-gray-bg);
}

.th-event__tag.denied {
    color: #a16411;
    background: var(--th-amber-soft);
}

.th-event__tag.failure {
    color: var(--th-red);
    background: var(--th-red-soft);
}

.th-audit-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 16px;
}

/* Dark-mode lifts for the hardcoded amber/red/blue tints (mirrors the
   .th-badge dark overrides — the soft-bg vars already theme themselves). */
html[data-th-theme="dark"] .th-event__icon.amber,
html[data-th-theme="dark"] .th-event__tag.denied {
    color: #f4c177;
    background: rgba(217, 151, 50, 0.16);
}

html[data-th-theme="dark"] .th-event__icon.red,
html[data-th-theme="dark"] .th-event__tag.failure {
    color: #e88876;
    background: rgba(184, 74, 58, 0.18);
}

html[data-th-theme="dark"] .th-event__icon.blue {
    color: #8fb4d2;
    background: rgba(52, 107, 143, 0.20);
}

/* ===== Test-plan tab ===== */

/* Tab body: compact supporting controls above a two-pane planning workspace. */
.th-testplan {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: 18px;
}

.th-testplan__workspace {
    /* Leave room for the page header, plan selection and pane controls. Keep
       a usable list height on short screens, where the page can still scroll. */
    --th-testplan-list-height: max(12rem, calc(100dvh - 28rem));
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(360px, 2fr);
    grid-template-areas:
        "plan-head palette-head"
        "plan-body palette-body";
    align-items: start;
    column-gap: 12px;
}

.rz-dialog.th-test-step-dialog {
    max-width: calc(100vw - 32px);
    max-height: calc(100dvh - 32px);
}

.th-test-step-dialog .rz-dialog-content {
    display: flex;
    min-height: 0;
    overflow: hidden;
}

.th-test-step-dialog .rz-dialog-titlebar .rz-dialog-titlebar-close {
    width: 40px;
    height: 40px;
}

.th-step-dialog {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    min-width: 0;
    min-height: 0;
}

.th-step-dialog__body {
    min-height: 0;
    overflow-y: auto;
}

.th-step-dialog__hint {
    margin: 0 0 20px;
    text-wrap: pretty;
}

.th-step-dialog__fields {
    display: grid;
    gap: 20px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.th-step-dialog .th-form-section {
    gap: 16px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.th-step-dialog .th-form-section:first-child > header {
    display: none;
}

.th-step-dialog .th-form-grid.four-col {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px 12px;
}

.th-step-dialog .th-form-grid > .th-form-field:first-child {
    grid-column: 1 / -1;
}

.th-step-dialog .th-dialog-actions {
    flex-shrink: 0;
    flex-wrap: wrap;
    padding-top: 16px;
    border-top: 1px solid var(--th-line);
}

.th-step-dialog .th-dialog-actions .th-button {
    min-height: 40px;
    justify-content: center;
}

@media (max-width: 480px) {
    .th-step-dialog .th-form-grid.four-col {
        grid-template-columns: 1fr;
    }
}

.th-step-palette__create.th-button {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 12px;
    margin-left: auto;
}

.th-testplan__pane {
    display: contents;
}

.th-testplan__pane--plan > .th-testplan__pane-head {
    grid-area: plan-head;
}

.th-testplan__pane--plan > .th-plan-dropzone {
    grid-area: plan-body;
}

.th-testplan__pane--palette > .th-step-palette__head {
    grid-area: palette-head;
}

.th-testplan__pane--palette > .th-step-palette {
    grid-area: palette-body;
}

/* Generated-at status and its occasional action are supporting metadata, not
   a second toolbar. Keep them together in a quiet inline cluster so the plan
   table begins sooner and the action remains easy to find. */
.th-testplan__meta {
    min-height: 28px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
}

.th-testplan__meta--hint {
    justify-content: flex-start;
}

.th-testplan__meta .th-caption {
    margin: 0;
}

.th-testplan__meta-action.th-button {
    min-height: 28px;
    padding: 0 10px;
    font-size: 10px;
}

/* Screen-reader-only text (e.g. the drag column's header label). */
.th-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    clip-path: inset(50%);
    overflow: hidden;
    white-space: nowrap;
}

/* Plan table + palette are the two halves of the drag-and-drop pair: rows drag
   down into the palette to remove, chips drag up into the plan to add. Both
   zones advertise themselves while a compatible drag is in flight via
   .is-target (state comes from the server, set on dragstart). */

.th-plan-dropzone,
.th-step-palette {
    border: 1px dashed transparent;
    border-radius: 0 0 var(--th-radius) var(--th-radius);
    border-top: 0;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

/* Only the step lists scroll: plan controls and the palette pager stay outside
   the scroll region. Wide tables also remain contained within their own pane. */
.th-plan-dropzone,
.th-step-palette {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    max-height: var(--th-testplan-list-height);
}

.th-plan-dropzone {
    overflow: hidden;
    border-color: var(--th-line);
    background: var(--th-surface);
}

.th-testplan__table-scroll,
.th-step-palette__scroll {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scroll-padding-top: 40px;
}

.th-testplan__table-scroll:focus-visible,
.th-step-palette__scroll:focus-visible {
    outline: 2px solid var(--th-teal);
    outline-offset: -2px;
}

.th-plan-dropzone.is-target,
.th-step-palette.is-target {
    border-color: var(--th-teal);
    background: var(--th-teal-soft);
}

.th-plan-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}

.th-plan-table--plan {
    min-width: 700px;
}

.th-plan-table--palette {
    min-width: 460px;
}

.th-plan-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 8px 10px;
    color: var(--th-muted);
    background: var(--th-grid-head-bg);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    box-shadow: 0 1px 0 var(--th-line);
}

.th-plan-table td {
    padding: 8px 10px;
    border-top: 1px solid var(--th-line);
    vertical-align: middle;
}

.th-plan-table th.num,
.th-plan-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.th-plan-table th.actions,
.th-plan-table td.actions {
    width: 44px;
    text-align: center;
    white-space: nowrap;
}

.th-plan-action.th-button {
    width: 30px;
    min-height: 30px;
    padding: 0;
}

.th-plan-table__grip-col {
    width: 26px;
}

.th-plan-table__row {
    cursor: grab;
    background: var(--th-surface);
}

.th-plan-table__row:hover {
    background: var(--th-grid-row-hover);
}

.th-plan-table__row.is-dragging {
    opacity: 0.45;
}

.th-plan-table__row.is-reorder-target td {
    /* Insertion indicator: the dragged step will land above this row. */
    box-shadow: inset 0 2px 0 var(--th-teal);
}

.th-plan-table__grip {
    color: var(--th-faint);
    text-align: center;
}

.th-plan-table__empty td {
    padding: 18px 10px;
    color: var(--th-muted);
    text-align: center;
}

/* Scope bar: which level (device vs model) subsequent edits write to. */

.th-scope-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.th-scope-bar__label {
    color: var(--th-muted);
    font-size: 13px;
}

.th-scope-toggle {
    position: relative;
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--th-line);
    border-radius: 999px;
    background: var(--th-surface-2);
}

.th-scope-toggle__option {
    padding: 5px 14px;
    border: 0;
    border-radius: 999px;
    color: var(--th-muted);
    background: transparent;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.th-scope-toggle__option:hover {
    color: var(--th-ink);
}

.th-scope-toggle__option.active {
    color: var(--th-teal-strong);
    background: var(--th-teal-soft);
    font-weight: 600;
}

.th-scope-toggle__option:focus-visible {
    outline: 2px solid var(--th-teal);
    outline-offset: 1px;
}

.th-scope-tip {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 20;
    width: max-content;
    max-width: 320px;
    padding: 8px 10px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    color: var(--th-ink);
    background: var(--th-surface);
    box-shadow: 0 12px 28px rgba(31, 41, 38, 0.22);
    font-size: 12px;
    line-height: 1.45;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.12s ease, visibility 0s linear 0.12s;
}

/* The delay keeps the tip from flashing while the pointer just passes over. */
.th-scope-toggle__option:hover + .th-scope-tip,
.th-scope-toggle__option:focus-visible + .th-scope-tip {
    opacity: 1;
    visibility: visible;
    transition-delay: 0.3s;
}

/* The shared header row keeps both table headers on the same baseline even
   though the available-step pane has more controls. */

.th-testplan__pane-head,
.th-step-palette__head {
    align-self: stretch;
    min-height: 52px;
    padding: 8px 12px;
    border: 1px dashed var(--th-line);
    border-bottom: 0;
    border-radius: var(--th-radius) var(--th-radius) 0 0;
    background: var(--th-surface);
}

.th-testplan__pane-head {
    display: flex;
    align-items: center;
}

.th-testplan__pane-head > .th-scope-bar {
    width: 100%;
}

.th-scope-bar > .th-testplan__meta {
    margin-left: auto;
}

.th-testplan__pane-head h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

/* Palette: every step not in the plan, presented beside the active plan. */

.th-step-palette {
    overflow: hidden;
    border: 1px dashed var(--th-line);
    border-top: 0;
    background: var(--th-surface);
}

.th-step-palette__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.th-step-palette__search {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1 1 320px;
    min-width: 0;
}

.th-step-palette__search .th-search {
    flex: 1 1 140px;
    min-width: 0;
}

.th-step-type-filter {
    width: 200px;
    max-width: 100%;
}

.th-step-palette__search .th-step-type-filter {
    flex: 0 1 225px;
    min-width: 0;
}

.th-step-palette__no-results {
    padding: 12px 16px;
}

.th-step-palette > .th-caption {
    margin: 0;
    padding: 16px;
}

.th-step-palette__pager {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    min-height: 42px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 10px;
    border-top: 1px solid var(--th-line);
    background: var(--th-surface-2);
}

.th-step-palette__pager-summary,
.th-step-palette__pager-page {
    color: var(--th-muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.th-step-palette__pager-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.th-step-palette__pager-button {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--th-line);
    border-radius: 6px;
    color: var(--th-ink);
    background: var(--th-surface);
    cursor: pointer;
}

.th-step-palette__pager-button:hover:not(:disabled) {
    border-color: var(--th-teal);
    background: var(--th-teal-soft);
}

.th-step-palette__pager-button:focus-visible {
    outline: 2px solid var(--th-teal);
    outline-offset: 1px;
}

.th-step-palette__pager-button:disabled {
    opacity: 0.4;
    cursor: default;
}

.th-step-palette__pager-button span {
    margin-top: -2px;
    font-size: 20px;
    line-height: 1;
}

/* An excluded step stays listed with its fields; only the instruction is
   struck through, the note beneath names the exclusion's scope. */
.th-plan-table__row.is-excluded .th-plan-table__instruction {
    color: var(--th-muted);
    text-decoration: line-through;
    text-decoration-color: var(--th-faint);
}

.th-plan-table__note {
    display: block;
    color: var(--th-muted);
    font-size: 12px;
}

@media (max-width: 1180px) {
    .th-testplan__workspace {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "plan-head"
            "plan-body"
            "palette-head"
            "palette-body";
    }

    .th-testplan__pane--palette > .th-step-palette__head {
        margin-top: 12px;
    }
}

/* ===== Dashboard =====
   The landing page: a greeting hero, a grid of clickable stat cards that deep-link
   into the sections they summarise, a portfolio-breakdown panel, and quick actions.
   Reuses the shared --th-* tokens (so light/dark theme for free) and the .th-panel /
   .th-button primitives; only the dashboard-specific composition lives here. */

.th-dash-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: linear-gradient(135deg, var(--th-teal-soft), var(--th-surface) 62%);
}

.th-dash-hero__title {
    font-size: 19px;
    font-weight: 600;
}

.th-dash-hero__sub {
    margin-top: 4px;
    color: var(--th-muted);
    font-size: 13.5px;
}

/* Stat cards — auto-fit so the row reflows from six across down to one without
   media-query breakpoints; each card stays at least wide enough for its value. */
.th-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
}

.th-stat {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
    color: var(--th-ink);
    text-decoration: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

a.th-stat:hover {
    border-color: var(--th-sage);
    box-shadow: 0 10px 26px rgba(34, 40, 36, 0.12);
    transform: translateY(-2px);
}

a.th-stat:focus-visible {
    outline: 2px solid var(--th-teal);
    outline-offset: 2px;
}

.th-stat__icon {
    flex: none;
    width: 42px;
    height: 42px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    color: var(--th-teal);
    background: var(--th-teal-soft);
}

/* NavIcon hard-codes its own (sidebar) colour on .th-nav-icon, so its currentColor
   mask would ignore the disc tone — re-inherit so the glyph picks up the disc colour. */
.th-stat__icon .th-nav-icon {
    width: 21px;
    height: 21px;
    color: inherit;
}

.th-stat__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.th-stat__label {
    color: var(--th-muted);
    font-size: 12.5px;
}

.th-stat__value {
    font-size: 25px;
    font-weight: 600;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.th-stat__value--muted {
    color: var(--th-faint);
}

.th-stat__sub {
    color: var(--th-faint);
    font-size: 12px;
}

/* Icon-disc tones. Glyphs, not text, so the softer token contrast reads fine. */
.th-stat--teal .th-stat__icon {
    color: var(--th-teal);
    background: var(--th-teal-soft);
}

.th-stat--sage .th-stat__icon {
    color: var(--th-badge-green-color);
    background: var(--th-badge-green-bg);
}

.th-stat--blue .th-stat__icon {
    color: var(--th-blue);
    background: var(--th-blue-soft);
}

.th-stat--amber .th-stat__icon {
    color: var(--th-amber);
    background: var(--th-amber-soft);
}

.th-stat--red .th-stat__icon {
    color: var(--th-red);
    background: var(--th-red-soft);
}

.th-stat--admin .th-stat__icon {
    color: var(--th-ink);
    background: var(--th-badge-gray-bg);
}

/* Emphasis when a count is actionable: a tinted wash + matching border so the
   "with defects" / "due soon" cards stand out from the calm metrics. The washes
   land on a near-black soft token in dark mode, so they tint rather than bloom. */
.th-stat.is-alert {
    border-color: color-mix(in srgb, var(--th-red) 38%, transparent);
    background: linear-gradient(135deg, var(--th-red-soft), var(--th-surface) 72%);
}

.th-stat.is-warn {
    border-color: rgba(217, 151, 50, 0.34);
    background: linear-gradient(135deg, var(--th-amber-soft), var(--th-surface) 72%);
}

/* Lower row: breakdown panel beside quick actions, stacking on narrow viewports. */
.th-dash-cols {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

@media (max-width: 1100px) {
    .th-dash-cols {
        grid-template-columns: 1fr;
    }
}

/* Proportion bars — one labelled track per entity, primary share filled. */
.th-bar-row {
    margin-top: 18px;
}

.th-bar-row:first-of-type {
    margin-top: 4px;
}

.th-bar-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 7px;
    font-size: 13.5px;
}

.th-bar-head b {
    font-weight: 600;
}

.th-bar-total {
    color: var(--th-muted);
    font-family: var(--th-font-mono);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.th-bar-track {
    height: 9px;
    border-radius: 999px;
    background: var(--th-surface-2);
    overflow: hidden;
}

.th-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

.th-bar-fill.teal {
    background: var(--th-teal);
}

.th-bar-fill.sage {
    background: var(--th-sage);
}

.th-bar-fill.blue {
    background: var(--th-blue);
}

.th-bar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 8px;
    color: var(--th-muted);
    font-size: 12px;
}

.th-bar-legend > span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.th-bar-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    flex: none;
}

.th-bar-dot.teal {
    background: var(--th-teal);
}

.th-bar-dot.sage {
    background: var(--th-sage);
}

.th-bar-dot.blue {
    background: var(--th-blue);
}

.th-bar-dot.rest {
    background: var(--th-surface-2);
    border: 1px solid var(--th-line);
}

/* Quick actions: full-width tiles with a tinted entity icon, a label, and a
   go-chevron that nudges on hover — the same icon-disc language as the stat cards. */
.th-dash-actions {
    display: grid;
    gap: 8px;
    margin-top: 2px;
}

.th-dash-action {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface);
    color: var(--th-ink);
    text-decoration: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.th-dash-action:hover {
    border-color: var(--th-sage);
    background: var(--th-surface-2);
}

.th-dash-action:focus-visible {
    outline: 2px solid var(--th-teal);
    outline-offset: 2px;
}

.th-dash-action__icon {
    flex: none;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: var(--th-teal);
    background: var(--th-teal-soft);
}

.th-dash-action__icon .th-nav-icon {
    width: 17px;
    height: 17px;
    color: inherit;
}

.th-dash-action__label {
    flex: 1;
    min-width: 0;
    font-size: 13.5px;
    font-weight: 500;
}

.th-dash-action__arrow {
    flex: none;
    display: inline-flex;
    color: var(--th-faint);
    transition: transform 0.15s ease, color 0.15s ease;
}

.th-dash-action__arrow .th-nav-icon {
    width: 16px;
    height: 16px;
    color: inherit;
}

.th-dash-action:hover .th-dash-action__arrow {
    color: var(--th-teal);
    transform: translateX(3px);
}

.th-dash-action--teal .th-dash-action__icon {
    color: var(--th-teal);
    background: var(--th-teal-soft);
}

.th-dash-action--sage .th-dash-action__icon {
    color: var(--th-badge-green-color);
    background: var(--th-badge-green-bg);
}

.th-dash-action--blue .th-dash-action__icon {
    color: var(--th-blue);
    background: var(--th-blue-soft);
}

.th-dash-action--admin .th-dash-action__icon {
    color: var(--th-ink);
    background: var(--th-badge-gray-bg);
}

@media (prefers-reduced-motion: reduce) {
    .th-stat,
    .th-bar-fill,
    .th-dash-action__arrow {
        transition: none;
    }
}

.th-company-logo {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.th-company-logo > img {
    max-height: 56px;
    max-width: 240px;
    padding: 6px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: #ffffff;
}

/* Column-filtered list grids: summary line, toolbar with chips, compact header filters. */
.th-grid-toolbar {
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 8px 10px;
}
.th-grid-toolbar__actions,
.th-grid-toolbar__options { display: flex; align-items: center; gap: 8px; flex: none; }
.th-grid-toolbar__actions { padding-right: 14px; border-right: 1px solid var(--th-line); }
/* The columns picker opens from the left-hand toolbar actions. */
.th-grid-toolbar__actions .th-columns-menu__panel { left: 0; right: auto; }
.th-grid-toolbar__actions .th-button { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.th-grid-toolbar__options .th-grid-toolbar__add { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 5px 10px; font-size: 12px; white-space: nowrap; }
.th-grid-toolbar__add svg { flex: none; }
/* Its own toolbar section between the columns menu and the chips. */
.th-grid-summary { display: flex; flex: none; align-items: center; gap: 14px; padding-right: 14px; border-right: 1px solid var(--th-line); font-size: 12px; font-variant-numeric: tabular-nums; }
.th-grid-summary__count { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; color: var(--th-muted); }
.th-grid-summary__count strong { color: var(--th-teal); font-size: 16px; font-weight: 600; }
.th-grid-summary__metric { white-space: nowrap; color: var(--th-muted); }
.th-grid-summary__metric b { color: var(--th-ink); font-weight: 600; }
.th-grid-toolbar__options { margin-left: auto; font-size: 12px; }
.th-grid-toolbar__options .th-inline-check { font-size: 12px; white-space: nowrap; }
.th-grid-toolbar__add:focus-visible,
.th-column-filter-clear:focus-visible { outline: 2px solid var(--th-teal); outline-offset: 2px; }
@media (max-width: 1100px) {
    .th-grid-toolbar .th-grid-filter-chips { order: 3; flex: 1 0 100%; padding-top: 6px; border-top: 1px solid var(--th-line); }
}
.th-column-filter-clear {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 28px;
    padding: 3px 7px;
    border: 1px solid var(--th-line);
    border-radius: 4px;
    background: transparent;
    color: var(--th-ink);
    font: inherit;
    cursor: pointer;
}
.th-column-filter-clear b { padding: 0 4px; border-radius: 3px; background: var(--th-teal-soft); color: var(--th-teal-strong); }
.th-column-filter-clear:hover:not(:disabled) { border-color: var(--th-teal); background: var(--th-teal-soft); }
.th-column-filter-clear:disabled { color: var(--th-muted); cursor: default; }

/* Override both the host cell and Radzen's nested padding. */
.th-column-grid .rz-grid-table > thead > tr > th { padding: 3px 8px; height: 30px; }
.th-column-grid .rz-grid-table > thead > tr > th > div { padding: 0; }
.th-column-grid .rz-grid-table > thead > tr > th .rz-column-title-content { white-space: nowrap; }
.th-column-total { display: block; color: var(--th-teal); font-variant-numeric: tabular-nums; }
.th-column-grid .rz-grid-table > thead > tr:has(.rz-cell-filter) > th {
    padding: 2px 8px 6px;
    height: 36px;
    top: 30px;
}
.th-column-grid .rz-cell-filter { padding: 0; margin: 0; }
.th-column-grid .rz-cell-filter-content { min-width: 0; min-height: 28px; }
.th-column-grid .rz-cell-filter-label { height: 28px !important; border: 0; }
.th-column-grid .rz-cell-filter :is(.rz-textbox, .rz-dropdown, .rz-datepicker, .rz-numeric) {
    width: 100%;
    min-width: 0;
    height: 28px;
    min-height: 28px;
    border: 1px solid var(--th-line);
    border-radius: 4px;
    background: var(--th-field-bg);
    color: var(--th-ink);
    font-size: 12px;
}
.th-column-grid .rz-cell-filter input { height: 26px; min-height: 0; padding: 3px 7px; color: var(--th-ink); font-size: 12px; }
.th-column-grid .rz-cell-filter .rz-dropdown { padding: 0; }
.th-column-grid .rz-cell-filter .rz-dropdown-label {
    box-sizing: border-box;
    height: 26px;
    min-height: 26px;
    padding: 0 26px 0 7px;
    line-height: 26px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.th-column-grid .rz-cell-filter .rz-dropdown:has(> .rz-dropdown-clear-icon) > .rz-dropdown-label { padding-right: 46px; }
.th-column-grid .rz-cell-filter .rz-dropdown-clear-icon { width: 20px; height: 26px; right: 24px; top: 0; font-size: 16px; }
.th-column-grid .rz-cell-filter :is(.rz-dropdown-trigger, .rz-datepicker-trigger) { width: 24px; min-height: 0; padding: 0; }
.th-column-grid .rz-cell-filter input { font-family: inherit; }
.th-column-grid .rz-cell-filter input::placeholder,
.th-column-grid .rz-cell-filter .rz-dropdown-label.rz-placeholder { color: var(--rz-input-placeholder-color); opacity: 1; }
/* Radzen gives the date picker's input its own box; the wrapper already draws the field. */
.th-column-grid .rz-cell-filter .rz-datepicker > .rz-inputtext { border: 0; border-radius: 4px; background: transparent; box-shadow: none; }
.th-column-grid .rz-cell-filter :is(.rz-textbox:focus, .rz-dropdown:focus-within, .rz-datepicker:focus-within) {
    border-color: var(--th-teal);
    box-shadow: 0 0 0 1px var(--th-teal);
}
/* Radzen sizes pager buttons as large buttons (48px min-height + padding); keep them toolbar-sized and
   centre the content so page numbers line up with the icon buttons. */
.th-grid .rz-pager { padding: 3px 8px; --rz-pager-gap: 2px; }
.th-grid .rz-pager :is(.rz-pager-element, .rz-pager-page) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 28px;
    height: 28px;
    padding: 0 6px;
    line-height: 1;
}
/* Flex items so the icon buttons' line box doesn't add descender space under them. */
.th-grid .rz-pager .rz-pager-item { display: flex; }
.th-grid .rz-pager .rz-pager-icon { width: 18px; height: 18px; font-size: 18px; line-height: 18px; }
/* Three digits plus the chevron; the margins keep the tight button gap off the size picker. */
.th-grid .rz-pager .rz-dropdown {
    width: 76px;
    min-height: 30px;
    height: 30px;
    margin: 0 8px 0 10px;
    padding: 0;
}
.th-grid .rz-pager .rz-dropdown > .rz-dropdown-label {
    box-sizing: border-box;
    height: 28px;
    min-height: 28px;
    padding: 0 30px 0 10px;
    line-height: 28px;
}
.th-grid .rz-pager .rz-dropdown-trigger { height: 28px; top: 0; }

.th-column-grid .rz-data-grid { max-height: calc(100dvh - 250px); }

/* Multiple alternatives stay visible even when their column is hidden. */
.th-grid-filter-chips { display: flex; align-items: center; flex-wrap: wrap; flex: 1; gap: 6px 12px; min-width: 180px; }
.th-grid-filter-hint { color: var(--th-muted); font-size: 12px; }
.th-grid-filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.th-grid-filter-group__label { font-size: 11px; font-weight: 600; color: var(--th-muted); margin-right: 2px; }
.th-grid-filter-or { font-size: 10px; color: var(--th-muted); }
.th-grid-filter-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 7px; min-height: 26px; border: 1px solid var(--th-line); border-radius: 5px; background: var(--th-teal-soft); color: var(--th-ink); font: inherit; font-size: 12px; cursor: pointer; }
.th-grid-filter-chip > span:first-child { max-width: 180px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.th-grid-filter-chip > span:last-child { font-size: 16px; line-height: 1; color: var(--th-muted); }
.th-grid-filter-chip:hover { border-color: var(--th-teal); }
.th-grid-filter-chip:focus-visible { outline: 2px solid var(--th-teal); outline-offset: 2px; }
.th-column-grid .th-column-value-entry { display: flex; align-items: stretch; width: 100%; height: 28px; border: 1px solid var(--th-line); border-radius: 4px; background: var(--th-field-bg); }
.th-column-grid .th-column-value-entry:focus-within { border-color: var(--th-teal); box-shadow: 0 0 0 1px var(--th-teal); }
.th-column-grid .th-column-value-entry input { flex: 1; min-width: 0; width: 0; border: 0; background: transparent; border-radius: 4px; outline: none; box-shadow: none; }
.th-column-grid .th-column-value-entry button { flex: none; width: 24px; border: 0; border-left: 1px solid var(--th-line); border-radius: 0 3px 3px 0; background: transparent; color: var(--th-teal); font-size: 17px; cursor: pointer; }
.th-column-grid .th-column-value-entry button:disabled { color: var(--th-muted); opacity: .45; cursor: default; }
.th-column-grid .th-column-value-entry button:hover:not(:disabled) { background: var(--th-teal-soft); }
.th-date-comparison { display: flex; width: 100%; }
.th-date-comparison > .rz-button { flex: 1; }

/* Radzen portals the popup to body and sets its width from the narrow trigger.
   Mark the list wrapper so only these searchable column menus get a wider panel. */
.rz-dropdown-panel:has(> .rz-dropdown-items-wrapper[style*="--th-column-options"]) {
    min-width: min(320px, calc(100vw - 32px)) !important;
    max-width: calc(100vw - 32px);
}
.rz-dropdown-panel:has(> .rz-dropdown-items-wrapper[style*="--th-column-options"]) .rz-dropdown-items-wrapper,
.rz-dropdown-panel:has(> .rz-dropdown-items-wrapper[style*="--th-column-options"]) .rz-dropdown-items,
.rz-dropdown-panel:has(> .rz-dropdown-items-wrapper[style*="--th-column-options"]) .rz-dropdown-item {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
}
.rz-dropdown-panel:has(> .rz-dropdown-items-wrapper[style*="--th-column-options"]) .rz-dropdown-item,
.rz-dropdown-panel:has(> .rz-dropdown-items-wrapper[style*="--th-column-options"]) .rz-dropdown-item > span {
    white-space: normal;
    overflow-wrap: anywhere;
    min-width: 0;
}

/* ===== Company profile detail ===== */
.th-company-logo-preview {
    max-height: 56px;
    max-width: 180px;
    padding: 6px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    /* Logos are drawn for white paper, so keep them on white in dark mode too. */
    background: #ffffff;
}

.th-card > .th-company-missing {
    margin: 0;
    color: var(--th-ink);
    background: var(--th-amber-soft);
    border-bottom: 1px solid var(--th-line);
}

.th-company-tab-body {
    padding: 16px 18px;
}

.th-detail-section > header.th-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 30px;
    padding-top: 12px;
}

.th-section-body {
    padding: 12px 18px 18px;
}

.th-section-body--stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.th-section-edit {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 12px 18px 18px;
}

.th-section-edit__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.th-field-grid--four {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1024px) {
    .th-field-grid--four {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.th-field--multiline strong {
    white-space: pre-line;
    font-weight: 500;
}

/* Signatures are written for white email bodies, so the preview stays white in dark mode. */
.th-signature-preview {
    display: block;
    width: 100%;
    max-width: 640px;
    height: 160px;
    resize: vertical;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: #ffffff;
}

.th-signature-editor {
    height: 340px;
}

.th-setting-token {
    display: block;
    margin-top: 3px;
    color: var(--th-muted);
    font-family: var(--th-font-mono);
    font-size: 11px;
}

.th-setting-add {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 8px;
    margin-top: 10px;
}

@media (max-width: 1024px) {
    .th-setting-add {
        grid-template-columns: 1fr;
    }
}

/* Company pick lists (Lists tab): one compact chip per value. */
.th-list-values {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.th-list-value {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 1px 2px 1px 9px;
    border: 1px solid var(--th-line);
    border-radius: 999px;
    background: var(--th-surface-2);
    color: var(--th-ink);
    font-size: 13px;
}

.th-list-add {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.th-list-add .rz-textbox {
    width: 200px;
}

/* Single-row inline-edit grids (Users, Employees). */
.th-inline-grid__muted {
    color: var(--th-muted);
}

.th-inline-grid__empty {
    color: var(--th-faint);
}

/* Edit-row controls use the column-filter sizing so the row keeps its height. */
.th-inline-grid .rz-data-row :is(.rz-textbox, .rz-dropdown) {
    width: 100%;
    min-width: 0;
    height: 28px;
    min-height: 28px;
    border: 1px solid var(--th-line);
    border-radius: 4px;
    background: var(--th-field-bg);
    color: var(--th-ink);
    font-size: inherit;
}

.th-inline-grid .rz-data-row .rz-textbox {
    padding: 3px 7px;
}

.th-inline-grid .rz-data-row .rz-dropdown {
    padding: 0;
}

.th-inline-grid .rz-data-row .rz-dropdown-label {
    box-sizing: border-box;
    height: 26px;
    min-height: 26px;
    padding: 0 24px 0 7px;
    line-height: 26px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.th-inline-grid .rz-data-row .rz-dropdown-trigger {
    width: 22px;
    min-height: 0;
    padding: 0;
}

.th-inline-grid .rz-data-row :is(.rz-textbox:focus, .rz-dropdown:focus-within) {
    border-color: var(--th-teal);
    box-shadow: 0 0 0 1px var(--th-teal);
}

.th-inline-grid .rz-data-row .th-form-field {
    gap: 2px;
}

.th-inline-grid .rz-data-row .th-form-field-error {
    font-size: 11px;
    line-height: 1.3;
}

/* ===== Theme switch (System / Light / Dark), th-manager's ThemeSwitcher and th-technician's ThemeSwitch ===== */

/* Three-segment pill: System / Light / Dark.

   Geometry note: each segment is exactly 30px wide so the absolutely
   positioned thumb can stop at translateX(0), translateX(30), and
   translateX(60) without measuring DOM nodes. If the segment count
   changes, update the data-active stops below. */

.th-theme {
    position: relative;
    display: inline-flex;
    align-items: stretch;
    padding: 3px;
    border: 1px solid var(--th-line);
    border-radius: var(--th-radius);
    background: var(--th-surface-2);
    isolation: isolate;
}

/* The sliding highlight that sits *behind* the icons. Width matches a
   single segment (30px) and lives inside the 3px padding gutter so the
   pill border stays a clean hairline. */
.th-theme-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 30px;
    height: calc(100% - 6px);
    border-radius: 6px;
    background: var(--th-surface);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08), inset 0 0 0 1px rgba(217, 151, 50, 0.10);
    transform: translateX(0);
    transition: transform 0.32s cubic-bezier(0.4, 0.14, 0.26, 1),
    background-color 0.25s ease,
    box-shadow 0.25s ease;
    pointer-events: none;
    z-index: 0;
}

/* Thumb position follows the *mode* attribute that the pre-paint bootstrap
   (js/theme-bootstrap.js) writes on <html>, not server-rendered markup — so
   the active segment is correct on the very first paint. ThemeState defaults
   to System on the server (it can't read localStorage), so keying this off
   the component's own markup would paint System first and then slide to the
   stored choice once the Blazor circuit hydrates. */
html[data-th-theme-mode="system"] .th-theme-thumb {
    transform: translateX(0);
}

html[data-th-theme-mode="light"] .th-theme-thumb {
    transform: translateX(30px);
}

html[data-th-theme-mode="dark"] .th-theme-thumb {
    transform: translateX(60px);
}

.th-theme-option {
    position: relative;
    z-index: 1;
    width: 30px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--th-faint);
    cursor: pointer;
    font: inherit;
    transition: color 0.18s ease, transform 0.18s ease;
}

.th-theme-option:hover {
    color: var(--th-muted);
}

.th-theme-option:focus-visible {
    outline: 2px solid var(--th-teal);
    outline-offset: 2px;
    border-radius: 6px;
}

/* The active segment's icon is emphasised from the same pre-paint <html>
   attribute (matched against each option's data-mode) rather than the
   server-rendered .active class, so it can't disagree with the thumb on the
   first frame. */
html[data-th-theme-mode="system"] .th-theme-option[data-mode="system"],
html[data-th-theme-mode="light"] .th-theme-option[data-mode="light"],
html[data-th-theme-mode="dark"] .th-theme-option[data-mode="dark"] {
    color: var(--th-ink);
}

/* When the active segment is Dark, lift the thumb to a slightly warmer
   amber-edged glow — adds a hint of the moon's halo without disturbing
   the otherwise neutral pill. */
html[data-th-theme-mode="dark"] .th-theme-thumb {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), inset 0 0 0 1px rgba(217, 151, 50, 0.22);
}

/* Sun and moon get the slightest weight emphasis when selected, so the
   icon — not just the highlight — reads as the active control. */
html[data-th-theme-mode="system"] .th-theme-option[data-mode="system"] svg,
html[data-th-theme-mode="light"] .th-theme-option[data-mode="light"] svg,
html[data-th-theme-mode="dark"] .th-theme-option[data-mode="dark"] svg {
    stroke-width: 1.7;
}

@media (prefers-reduced-motion: reduce) {
    .th-theme-thumb,
    .th-theme-option {
        transition: none;
    }
}
