/* qLink: flat, dense, built for daily use. Colors and sizes come only from theme.css (ADR 0006). */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: 1.45;
    color: var(--color-text);
    background: var(--color-bg);
}

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

:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

/* FocusOnNavigate focuses the page's h1 for screen readers; it isn't a keyboard stop. */
h1:focus { outline: none; }

code { font-family: var(--font-mono); color: var(--color-code); }

h1 { font-size: var(--font-size-xl); font-weight: var(--font-weight-bold); margin: 0 0 var(--space-4); }
h2 { font-size: var(--font-size-lg); font-weight: var(--font-weight-bold); margin: 0 0 var(--space-3); }

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

/* Buttons */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-4);
    min-height: 32px;
    border: var(--border-width) solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

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

.button-primary {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: var(--color-on-primary);
    font-weight: var(--font-weight-medium);
}

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

.button-wide { width: 100%; min-height: 38px; }

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: var(--border-width) solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
}

.icon-button:hover, .icon-button[aria-expanded="true"] {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.icon { width: 18px; height: 18px; flex: none; }

/* Logo: transparent PNG with navy text, so it always sits on a white tile. */
.logo-tile {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--color-logo-tile);
}

.logo-tile img { display: block; height: var(--logo-height); width: auto; }

/* Shell (app-shell-6): the navy rail, the middle bar, and the page. */
.shell {
    display: grid;
    grid-template-columns: var(--rail-width) auto minmax(0, 1fr);
    min-height: 100vh;
}

.rail {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    height: 100vh;
    padding: var(--space-3) 0;
    background: var(--color-rail);
    color: var(--color-on-rail);
}

.rail-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-bottom: var(--space-2);
    border-radius: var(--radius-md);
    background: var(--color-rail-active);
    color: var(--color-on-rail);
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    text-decoration: none;
}
.rail-brand:hover { color: var(--color-on-rail); }

.rail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }

.rail-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 64px;
    padding: var(--space-2) 0;
    border-radius: var(--radius-md);
    color: var(--color-on-rail-muted);
    font-size: 11px;
    text-decoration: none;
}
.rail-link .icon { width: 20px; height: 20px; }
.rail-link:hover { background: var(--color-rail-active); color: var(--color-on-rail); }
.rail-link.active { background: var(--color-rail-active); color: var(--color-on-rail); font-weight: var(--font-weight-bold); }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: var(--space-1); }
.rail .icon-button { color: var(--color-on-rail-muted); }
.rail .icon-button:hover, .rail .icon-button[aria-expanded="true"] { background: var(--color-rail-active); color: var(--color-on-rail); }
.rail :focus-visible { outline-color: var(--color-on-rail); }

/* Menus open beside the rail, from its foot upwards. */
.rail .menu-panel { top: auto; right: auto; bottom: 0; left: calc(100% + var(--space-2)); color: var(--color-text); }

.context {
    position: sticky;
    top: 0;
    width: var(--context-width);
    height: 100vh;
    overflow-y: auto;
    background: var(--color-context);
    border-right: var(--border-width) solid var(--color-border);
}
.context:empty { display: none; }

/* The middle bar's parts: a title, a list of links with counts, and lists of items (app-shell-7). */
.context-section { padding: var(--space-4); }
.context-section + .context-section { padding-top: 0; }
.context-title { margin: 0 0 var(--space-3); font-size: var(--font-size-lg); font-weight: var(--font-weight-bold); }
.context-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--space-3); }
.context-nav a {
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    text-decoration: none;
}
.context-nav a:hover { background: var(--color-surface-hover); color: var(--color-text); }
.context-nav a.active { background: var(--color-selected); font-weight: var(--font-weight-bold); }
.context-nav strong { font-variant-numeric: tabular-nums; }
.count-attention { color: var(--color-accent); }

.content {
    width: 100%;
    max-width: var(--content-max-width);
    min-width: 0;
    padding: var(--space-5);
}

.empty-state { max-width: 480px; padding: var(--space-6) 0; }
.empty-state p { margin: 0 0 var(--space-4); color: var(--color-text-muted); }
.empty-state .button { text-decoration: none; }

/* Menus (Settings, account) */
.menu { position: relative; }

.menu-backdrop { position: fixed; inset: 0; z-index: 10; }

.menu-panel {
    position: absolute;
    top: calc(100% + var(--space-1));
    right: 0;
    z-index: 11;
    width: var(--menu-width);
    padding: var(--space-2);
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border-strong);
    border-radius: var(--radius-md);
}

.menu-heading {
    margin: var(--space-1) var(--space-2) var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.menu-item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.menu-item:hover { background: var(--color-surface-hover); color: var(--color-text); }

.menu-divider { height: var(--border-width); margin: var(--space-2) 0; background: var(--color-border); }

/* Notifications (notifications-1): the bell's unread count, and its panel. */
.bell-button { position: relative; }
.bell-count {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    padding: 0 var(--space-1);
    border-radius: var(--radius-md);
    background: var(--color-danger);
    color: var(--color-on-primary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    line-height: 16px;
    text-align: center;
}
.notification-panel { width: var(--notification-panel-width); max-width: calc(100vw - 2 * var(--space-4)); }
.notification-heading { display: flex; align-items: baseline; justify-content: space-between; padding-right: var(--space-2); }
.notification-list { list-style: none; margin: 0; padding: 0; max-height: var(--notification-list-height); overflow-y: auto; }
.notification-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    padding: var(--space-2);
    border: none;
    border-left: 2px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--color-text-muted);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.notification-item strong { font-weight: var(--font-weight-medium); }
.notification-item:hover { background: var(--color-surface-hover); }
.notification-item.is-unread { border-left-color: var(--color-primary); color: var(--color-text); }
.notification-item.is-unread strong { font-weight: var(--font-weight-bold); }

.menu-identity { padding: var(--space-1) var(--space-2) var(--space-2); overflow-wrap: anywhere; }

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 2px;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-muted);
}

.segmented button {
    padding: var(--space-1) var(--space-2);
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    font: inherit;
    cursor: pointer;
}

.segmented button[aria-checked="true"] {
    background: var(--color-surface);
    color: var(--color-text);
    font-weight: var(--font-weight-bold);
    outline: var(--border-width) solid var(--color-border-strong);
}

/* Login */
.login-page {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.login-card {
    width: 100%;
    max-width: var(--login-card-width);
    padding: var(--space-6);
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    border-top: 3px solid var(--color-primary);
    text-align: center;
}

.login-card .logo-tile { margin-bottom: var(--space-5); }
.login-card .logo-tile img { height: 44px; }
.login-card h1 { margin-bottom: var(--space-1); color: var(--color-primary); }
.login-card p { margin: 0 0 var(--space-5); color: var(--color-text-muted); }
.status-card .logo-tile { margin-bottom: var(--space-4); }
.status-line { display: flex; align-items: center; justify-content: center; gap: var(--space-3); color: var(--color-text-muted); }

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 2.4s; }
}

.login-footer { margin-top: var(--space-4); font-size: var(--font-size-sm); color: var(--color-text-muted); }

/* Dashboard placeholder */
.page-header { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }
.page-header h1 { margin: 0; }
.page-subtitle { color: var(--color-text-muted); }

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
}

.tile {
    min-height: 140px;
    padding: var(--space-4);
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
}

.tile-wide { grid-column: span 2; min-height: 240px; }

/* Home dashboard (inspection-flow-7). */
.kpi-row { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: var(--space-4); }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); align-items: start; }
.panel h2.spaced { margin-top: var(--space-5); }

.pipeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.pipeline a {
    display: grid;
    grid-template-columns: 170px 1fr 40px;
    align-items: center;
    gap: var(--space-3);
    padding: 3px var(--space-1);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    text-decoration: none;
}
.pipeline a:hover { background: var(--color-row-hover); }
.pipeline-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pipeline-track { height: 12px; }
/* Thin bars anchored at the baseline, rounded only at the data end. */
.pipeline-bar { display: block; height: 100%; min-width: 3px; border-radius: 0 4px 4px 0; background: var(--color-primary); }
.pipeline a:hover .pipeline-bar { background: var(--color-primary-hover); }
.pipeline-count { text-align: right; font-variant-numeric: tabular-nums; color: var(--color-text-muted); }

.meter { height: 8px; margin: var(--space-2) 0; border-radius: 4px; background: var(--color-surface-hover); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 4px; background: var(--color-success); }

.health { display: flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-2); }
.health-good { color: var(--color-success); }
.health-bad { color: var(--color-danger); }
.health strong { font-weight: var(--font-weight-bold); }

.activity { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.activity li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

@media (max-width: 1100px) {
    .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
}

.tile-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    border-style: dashed;
    border-color: var(--color-border-strong);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
}

/* Tables */
.grid {
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: var(--space-4);
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.grid th, .grid td {
    padding: var(--space-2) var(--space-3);
    border-bottom: var(--border-width) solid var(--color-border);
    text-align: left;
    vertical-align: middle;
}

.grid tr:last-child > th, .grid tr:last-child > td { border-bottom: none; }
.grid thead tr:last-child > th { border-bottom: var(--border-width) solid var(--color-border); }

.grid thead th {
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

/* Key-value tables (Status, Account): the row label is a th in the body. */
.grid tbody th { width: 160px; color: var(--color-text-muted); font-weight: var(--font-weight-medium); }

.grid tbody tr { transition: background var(--transition-fast); }
.grid tbody tr:hover { background: var(--color-row-hover); }

.grid .number { text-align: right; font-variant-numeric: tabular-nums; }

.status-good { color: var(--color-success); }
.status-bad { color: var(--color-danger); }

/* Forms: drawn by qLink, not the browser, so they match the theme. */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field > span { color: var(--color-text-muted); font-size: var(--font-size-sm); font-weight: var(--font-weight-medium); }

input:where([type="text"], [type="number"], [type="email"], [type="search"], [type="password"], [type="tel"], [type="url"]),
select,
textarea {
    appearance: none;
    min-height: var(--control-height);
    padding: 0 var(--space-2);
    border: var(--border-width) solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background-color: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

textarea { padding: var(--space-2); min-height: calc(var(--control-height) * 3); resize: vertical; }

input::placeholder, textarea::placeholder { color: var(--color-text-muted); opacity: 1; }

input:hover, select:hover, textarea:hover { border-color: var(--color-text-muted); }

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

input:disabled, select:disabled, textarea:disabled {
    background-color: var(--color-surface-muted);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

/* Number inputs: no spinners; the value is typed. */
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Select: a chevron drawn from two token-colored triangles instead of the OS arrow. */
select {
    padding-right: calc(var(--space-2) + 18px);
    background-image:
        linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%),
        linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
    background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    cursor: pointer;
}

select option { background-color: var(--color-surface); color: var(--color-text); }

.valid.modified:not([type=checkbox]) { border-color: var(--color-success); }
.invalid { border-color: var(--color-danger); }
.invalid:focus-visible { box-shadow: 0 0 0 3px var(--color-danger-surface); }
.validation-message { color: var(--color-danger); font-size: var(--font-size-sm); }

/* AQL calculator */
.aql-inputs { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-3); }
.aql-inputs .field input { width: 160px; }
.aql-plan input.count { width: 80px; }

.aql-summary { margin: 0 0 var(--space-2); }
.aql-note { margin: 0 0 var(--space-2); color: var(--color-primary); font-weight: var(--font-weight-bold); }
.hint { color: var(--color-text-muted); }

.aql-plan tbody th { width: auto; color: var(--color-text); font-weight: var(--font-weight-medium); }
.aql-plan select { min-width: 160px; }
.aql-plan tfoot th, .aql-plan tfoot td {
    border-top: var(--border-width) solid var(--color-border);
    background: var(--color-surface-muted);
    font-weight: var(--font-weight-bold);
}

.verdict { font-weight: var(--font-weight-bold); }
.verdict-accept { color: var(--color-success); }
.verdict-reject { color: var(--color-danger); }

/* The inspection form (inspection-form brief): dense, keyboard first, with the AQL panel kept in view. */
.form-header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.save-state { font-size: var(--font-size-sm); color: var(--color-text-muted); }
.save-state.is-saving { color: var(--color-primary); }
.save-state.is-failed { color: var(--color-danger); font-weight: var(--font-weight-medium); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--space-4); align-items: start; }
.form-main { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.form-side { position: sticky; top: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.setup-facts { grid-template-columns: max-content 1fr max-content 1fr; }
.codes-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin-top: var(--space-3); }
.codes-row .field input { width: 96px; text-transform: uppercase; font-family: var(--font-mono); }
.codes-row output { padding-bottom: var(--space-1); font-family: var(--font-mono); color: var(--color-code); }
.form-locked {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1) var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-border-strong);
    border-left: 4px solid var(--color-primary);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
}
.form-locked span { flex-basis: 100%; color: var(--color-text-muted); }
.sheet td input:disabled, .sheet td select:disabled { background: var(--color-surface-muted); color: var(--color-text-muted); cursor: not-allowed; opacity: 1; }
.remarks textarea { width: 100%; min-height: 120px; resize: vertical; }

.aql-live .field { margin-bottom: var(--space-3); }
.aql-live .field select { width: 100%; }
.aql-facts { margin-bottom: var(--space-3); }
.aql-sample { font-size: var(--font-size-lg); }
.aql-classes select { min-width: 0; width: 100%; }
.aql-note-small { margin: var(--space-2) 0 0; font-size: var(--font-size-sm); }
.lot-verdict { margin: 0 0 var(--space-3); padding: var(--space-2) var(--space-3); border: var(--border-width) solid currentColor; border-radius: var(--radius-sm); font-size: var(--font-size-lg); font-weight: var(--font-weight-bold); }
.lot-verdict .hint { font-size: var(--font-size-sm); font-weight: normal; }
.sheet td select.class-critical { color: var(--color-danger); font-weight: var(--font-weight-bold); }
.sheet tr.is-invalid td.row-number { color: var(--color-danger); font-weight: var(--font-weight-bold); }
.sheet .remove-column { width: 32px; }
.sheet .photo-column { width: 96px; }
.sheet td.photo-cell { display: flex; align-items: center; justify-content: space-between; gap: var(--space-1); }

.drop-zone {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 64px;
    margin-bottom: var(--space-3);
    border: var(--border-width) dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    cursor: pointer;
}
.drop-zone:hover, .drop-zone:focus-within { border-color: var(--color-focus); color: var(--color-text); }
.drop-zone input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-3); }
.photo { margin: 0; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; background: var(--color-surface); }
.photo.is-unsaved { border-color: var(--color-primary); }
.photo img { display: block; width: 100%; height: 150px; object-fit: cover; background: var(--color-surface-muted); }
.photo figcaption { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-2); }
.photo figcaption input, .photo figcaption select { width: 100%; }
.photo-meta { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--font-size-sm); }
.photo-meta .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* A sheet: borderless inputs in a gridded table, so it reads and moves like a spreadsheet (as on the request form). */
/* At its minimum width every column keeps its room; a narrower panel scrolls the sheet rather than squeezing it. */
.sheet { width: 100%; min-width: 640px; border-collapse: collapse; table-layout: fixed; }
.sheet th {
    padding: var(--space-1) var(--space-2);
    border: var(--border-width) solid var(--color-border);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    text-align: left;
    white-space: nowrap;
}
.sheet th.number, .sheet td.number { text-align: right; }
.sheet th.narrow { width: 88px; }
.sheet th.wide-cell { width: 200px; }
.sheet td .pct { display: block; font-size: var(--font-size-xs, 0.75rem); color: var(--color-text-muted); text-align: right; line-height: 1; }
.sheet-scroll { overflow-x: auto; }
.defects-sheet { min-width: 900px; }
.checks-sheet { min-width: 760px; }
.checks-sheet .code-cell { width: 120px; }
.product-checks { margin-bottom: var(--space-3); }
.product-checks h3 { margin: var(--space-2) 0 var(--space-1); font-size: var(--font-size-base, 1rem); }
.product-checks .checks-sheet { min-width: 0; }
.results-summary .segmented { grid-template-columns: repeat(4, minmax(56px, auto)); }
.results-summary .segmented button.outcome-fail { color: var(--color-danger); }
.results-summary .segmented button.outcome-hold { color: var(--color-warning, var(--color-text)); }
.sheet td input.is-overridden { font-weight: var(--font-weight-bold); }
.verdict-hold { color: var(--color-warning, var(--color-text)); }
.report-header input[type=date] { font: inherit; }
.override-form { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-2); margin-top: var(--space-2); }
.sign-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.problem-list { margin: 0 0 var(--space-3); padding-left: var(--space-4); }
.problem-list li { margin-bottom: var(--space-1); }
.changes summary { cursor: pointer; }
.changes summary h2 { display: inline; }
.code-filters { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-2); margin-bottom: var(--space-2); }
.lines-sheet { min-width: 1180px; }
.panel-heading .toggle { display: inline-flex; align-items: center; gap: var(--space-1); margin-left: auto; font-size: var(--font-size-sm); }
.aql-levels { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.sheet th.wide { width: 30%; }
.sheet th.code-column { width: 110px; }
.sheet .row-number { width: 32px; text-align: center; color: var(--color-text-muted); font-size: var(--font-size-sm); }
.sheet td { padding: 0 var(--space-2); border: var(--border-width) solid var(--color-border); height: 28px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet td.cell { padding: 0; }
.sheet td input:not([type="checkbox"]), .sheet td select { width: 100%; height: 28px; border: none; border-radius: 0; background: transparent; }
.sheet td input[type="number"] { text-align: right; }
.sheet td input:focus-visible, .sheet td select:focus-visible { box-shadow: inset 0 0 0 2px var(--color-focus); }
.sheet td input.invalid { box-shadow: inset 0 0 0 2px var(--color-danger); }
.sheet tr.is-unsaved td.row-number { color: var(--color-primary); font-weight: var(--font-weight-bold); }
.sheet tbody tr:hover { background: var(--color-row-hover); }
.sheet tfoot td { background: var(--color-surface-muted); font-weight: var(--font-weight-bold); }

/* Beside the rail, the AQL panel leaves the sheets too little room below this width. Stacked, the AQL panel goes
   first, so its live feedback stays in sight of the setup. */
@media (max-width: 1140px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-side { position: static; order: -1; }
}
@media (max-width: 1000px) {
    .setup-facts { grid-template-columns: max-content 1fr; }
}

/* The dev panel (feature-flags-2, copied from the intake app): shown only when the dev-tools flag is on. Dashed accent border, so it's never
   mistaken for part of the form. */
.dev-panel {
    position: fixed;
    right: var(--space-3);
    bottom: var(--space-3);
    z-index: 10;
    max-width: min(520px, calc(100vw - 2 * var(--space-3)));
    border: var(--border-width) dashed var(--color-accent);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
    font-size: var(--font-size-sm);
}
.dev-panel-toggle {
    display: block;
    width: 100%;
    padding: var(--space-1) var(--space-3);
    border: none;
    background: none;
    color: var(--color-accent);
    font: inherit;
    font-weight: var(--font-weight-bold);
    text-align: left;
    cursor: pointer;
}
.dev-panel-body { padding: 0 var(--space-3) var(--space-3); }
.dev-panel-fill { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.dev-panel-json-heading { display: flex; justify-content: space-between; margin-top: var(--space-2); }
.dev-panel-json {
    max-height: 35vh;
    margin: var(--space-1) 0 0;
    padding: var(--space-2);
    overflow: auto;
    border-radius: var(--radius-sm);
    background: var(--color-surface-muted);
    font-family: var(--font-mono);
    color: var(--color-code);
}
/* Taller than the open panel (its controls plus the 35vh JSON), so the form's last row can scroll above it. */
.dev-panel-spacer { height: var(--space-6); }
.dev-panel-spacer.open { height: calc(35vh + 160px); }

/* Blazor startup and error UI */
/* Inspection flow: lists, detail pages, state badges, lifecycle diagrams (inspection-flow). */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.filter-tabs { display: flex; gap: 2px; padding: 2px; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface-muted); }
.filter-tabs a { padding: var(--space-1) var(--space-3); border-radius: var(--radius-sm); color: var(--color-text-muted); text-decoration: none; }
.filter-tabs a:hover { color: var(--color-text); }
.filter-tabs a.active { background: var(--color-surface); color: var(--color-primary); font-weight: var(--font-weight-medium); }

.grid.list { width: 100%; }
.grid.list tbody th, .grid.compact tbody th { width: auto; }
.grid.compact { width: 100%; }
.grid.compact th, .grid.compact td { padding: var(--space-1) var(--space-2); }
.grid tfoot th, .grid tfoot td { border-top: var(--border-width) solid var(--color-border); color: var(--color-text-muted); font-weight: var(--font-weight-medium); }
.hint { color: var(--color-text-muted); font-size: var(--font-size-sm); }

.state-badge {
    display: inline-block;
    padding: 0 var(--space-2);
    border: var(--border-width) solid currentColor;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    line-height: 20px;
    white-space: nowrap;
    vertical-align: middle;
}
.tone-new { color: var(--color-focus); }
.tone-active { color: var(--color-primary); }
.tone-attention { color: var(--color-accent); background: var(--color-danger-surface); }
.tone-done { color: var(--color-success); }
.tone-stopped { color: var(--color-text-muted); }

.breadcrumb { margin: 0 0 var(--space-2); font-size: var(--font-size-sm); }
.page-header h1 { display: flex; align-items: center; gap: var(--space-3); }

.actions-bar { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.link-button { border: none; background: none; color: var(--color-primary); font: inherit; cursor: pointer; padding: 0; }

.panel { overflow-x: auto; padding: var(--space-3) var(--space-4); border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); }
.panel h2 { font-size: var(--font-size-base); }
.panel-heading { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.panel-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-1) var(--space-4); margin: 0; }
.facts dt { color: var(--color-text-muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.seal { font-size: var(--font-size-sm); font-weight: var(--font-weight-medium); }
.seal-good { color: var(--color-success); }
.seal-bad { color: var(--color-danger); }
.revision-banner { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: baseline; margin: 0 0 var(--space-3); padding: var(--space-2) var(--space-3); border: var(--border-width) solid var(--color-border-strong); border-radius: var(--radius-sm); }
.revision-banner.is-reopened { border-color: var(--color-danger); border-width: 2px; }
.revision-banner.is-reopened strong { color: var(--color-danger); }
.revision-banner.is-revised { border-color: var(--color-primary); }
.revisions { margin-bottom: var(--space-3); }
.attachment-list { margin: var(--space-2) 0 0; padding: 0; list-style: none; }
.attachment-list li { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: baseline; padding: var(--space-1) 0; border-bottom: var(--border-width) solid var(--color-border); }
.artifact pre { max-height: 360px; overflow: auto; font-size: var(--font-size-sm); white-space: pre-wrap; overflow-wrap: anywhere; }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.history li { padding-left: var(--space-3); border-left: 2px solid var(--color-border); }
.history-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.history-meta { color: var(--color-text-muted); font-size: var(--font-size-sm); }
.history-note { color: var(--color-text-muted); font-size: var(--font-size-sm); }

/* Mermaid draws the diagram as inline SVG. These rules recolor it from the theme, and mark the current state. */
.lifecycle { margin: 0; }
.lifecycle-diagram { overflow-x: auto; }
.lifecycle-diagram svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.lifecycle-diagram .node rect,
.lifecycle-diagram .node path { fill: var(--color-surface-muted) !important; stroke: var(--color-border-strong) !important; }
.lifecycle-diagram .node .nodeLabel,
.lifecycle-diagram .node text { color: var(--color-text) !important; fill: var(--color-text) !important; }
.lifecycle-diagram .node.current rect,
.lifecycle-diagram .node.current path { fill: var(--color-primary) !important; stroke: var(--color-primary) !important; }
.lifecycle-diagram .node.current .nodeLabel,
.lifecycle-diagram .node.current text { color: var(--color-on-primary) !important; fill: var(--color-on-primary) !important; }

/* Stat tiles: one number with a label, for the dashboard and diagnostics. */
.tile.stat { min-height: 0; display: flex; flex-direction: column; gap: var(--space-1); text-decoration: none; color: var(--color-text); }
a.tile.stat:hover { border-color: var(--color-border-strong); background: var(--color-surface-hover); }
.stat-label { color: var(--color-text-muted); font-size: var(--font-size-sm); font-weight: var(--font-weight-medium); }
/* Big standalone numbers keep proportional figures; tabular figures are for columns. */
.stat-value { font-size: 28px; font-weight: var(--font-weight-bold); line-height: 1.1; }
.diagnostics-tiles { margin-bottom: var(--space-4); }

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

.diagnostics-panel { border-style: dashed; }
.diagnostics-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2); }
.diagnostics-form .field { min-width: 160px; }
.field.grow { flex: 1 1 200px; }

.mailbox { margin-top: var(--space-4); }
.mailbox details { padding: var(--space-2) 0; border-bottom: var(--border-width) solid var(--color-border); }
.mailbox details:last-child { border-bottom: none; }
.mailbox summary { display: flex; flex-wrap: wrap; gap: var(--space-3); cursor: pointer; }
.mailbox details p { margin: var(--space-2) 0 0; }


#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 1000;
    width: 100%;
    padding: var(--space-3) var(--space-5);
    background: var(--color-danger-surface);
    color: var(--color-text);
    border-top: var(--border-width) solid var(--color-danger);
}

#blazor-error-ui .reload { margin-left: var(--space-2); }

#blazor-error-ui .dismiss {
    position: absolute;
    right: var(--space-3);
    top: var(--space-2);
    cursor: pointer;
}

.blazor-error-boundary {
    padding: var(--space-4);
    background: var(--color-danger-surface);
    border: var(--border-width) solid var(--color-danger);
    border-radius: var(--radius-sm);
    color: var(--color-text);
}

.blazor-error-boundary::after { content: "An error has occurred."; }

.loading-progress {
    position: absolute;
    display: block;
    width: 6rem;
    height: 6rem;
    inset: 30vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--color-border);
    stroke-width: 0.5rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--color-primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    inset: calc(30vh + 2.4rem) 0 auto 0;
    text-align: center;
    color: var(--color-text-muted);
}

.loading-progress-text::after { content: var(--blazor-load-percentage-text, "Loading"); }

/* Today (app-shell-7): one calm column, grouped by who the work waits on. */
.today { max-width: 880px; }
.today h1 { margin-bottom: var(--space-1); font-size: 26px; }
.today-summary { margin: 0 0 var(--space-5); color: var(--color-text-muted); font-size: var(--font-size-lg); }
.today-group { margin-bottom: var(--space-5); }
.today-heading {
    margin: 0 0 var(--space-1);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.today-heading.attention { color: var(--color-accent); }
details.today-group > summary { padding: var(--space-2) 0; cursor: pointer; }
.today-line {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3) var(--space-2);
    border: none;
    border-top: var(--border-width) solid var(--color-border);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: var(--font-size-lg);
    text-align: left;
    cursor: pointer;
}
.today-line:hover { background: var(--color-row-hover); }
.today-what { flex: 1; min-width: 0; }
.today-what strong { font-weight: var(--font-weight-bold); }

.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.dot-attention { background: var(--color-accent); }
.dot-active { background: var(--color-primary); }
.dot-waiting { background: var(--color-text-muted); }
.dot-done { background: var(--color-success); }

/* An overlay from the right with a card's facts (app-shell-7). */
.drawer-scrim { position: fixed; inset: 0; z-index: 20; background: var(--color-scrim); }
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 21;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    width: min(var(--drawer-width), 100%);
    padding: var(--space-5);
    overflow-y: auto;
    background: var(--color-surface);
    border-left: var(--border-width) solid var(--color-border);
    box-shadow: var(--shadow-overlay);
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.drawer-head h2 { margin: 0; font-size: var(--font-size-xl); }
.drawer-next {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    font-weight: var(--font-weight-medium);
}

/* The board (app-shell-8): the whole flow in columns. While a card is dragged, the columns that take it light up. */
.board {
    display: grid;
    grid-template-columns: repeat(7, minmax(180px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-3);
    overflow-x: auto;
    align-items: start;
}
.board-column {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-height: 240px;
    padding: var(--space-2);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
    transition: border-color var(--transition-fast), opacity var(--transition-fast);
}
.board-column.can-drop { border-color: var(--color-focus); border-style: dashed; }
.board-column.no-drop { opacity: 0.55; }
.board-column-title { display: flex; justify-content: space-between; margin: var(--space-1) var(--space-1) var(--space-1); font-size: var(--font-size-sm); }
.board-card {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    text-decoration: none;
    cursor: grab;
}
.board-card:hover { border-color: var(--color-border-strong); color: var(--color-text); }
.board-card.is-dragging { opacity: 0.5; }
.board-card-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.board-card-client { color: var(--color-text-muted); font-size: var(--font-size-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-card-when { margin-top: var(--space-1); color: var(--color-text-muted); font-size: var(--font-size-sm); }

.context-search { width: 100%; }
.inspector-list { list-style: none; margin: 0 0 var(--space-2); padding: 0; display: flex; flex-direction: column; gap: 2px; }
.inspector {
    display: flex;
    width: 100%;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.inspector:hover { background: var(--color-surface-hover); }
.inspector.active { background: var(--color-selected); font-weight: var(--font-weight-bold); }
.inspector.can-drop { border-color: var(--color-focus); border-style: dashed; }

/* A move's input, inline under the actions or in the drop dialog (app-shell-8). */
.move-prompt { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2); margin-bottom: var(--space-3); }
.move-prompt .field { min-width: 180px; }
.move-prompt-buttons { display: flex; gap: var(--space-2); }

.dialog-scrim { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-start; justify-content: center; padding: 12vh var(--space-4) var(--space-4); background: var(--color-scrim); }
.dialog {
    width: min(520px, 100%);
    padding: var(--space-5);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-overlay);
}
.dialog h2 { margin-bottom: var(--space-1); }
.dialog .move-prompt { margin: var(--space-4) 0 0; }

/* Split views (app-shell-9): the list in the middle bar, the chosen item on the right, the rest of it in tabs. */
.context > p { padding: 0 var(--space-4); }
.context .filter-tabs { margin-bottom: var(--space-3); }
.context-search-form { margin: 0; }
.queue { list-style: none; margin: 0; padding: 0; border-top: var(--border-width) solid var(--color-border); }
.queue-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-3) var(--space-4);
    border-bottom: var(--border-width) solid var(--color-border);
    color: var(--color-text);
    text-decoration: none;
}
.queue-item:hover { background: var(--color-surface-hover); color: var(--color-text); }
.queue-item.selected { background: var(--color-selected); box-shadow: inset 3px 0 0 var(--color-primary); }
.queue-line { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-width: 0; }
.queue-line > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.detail-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-4); margin-bottom: var(--space-4); }
.detail-header h1 { display: flex; align-items: center; gap: var(--space-3); margin: 0; font-size: 24px; }
.detail-header .button { margin-left: auto; text-decoration: none; }

.key-facts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-3);
    margin: 0 0 var(--space-5);
}
.key-facts > div { padding: var(--space-3); border-radius: var(--radius-md); background: var(--color-surface); border: var(--border-width) solid var(--color-border); }
.key-facts dt { color: var(--color-text-muted); font-size: var(--font-size-sm); }
.key-facts dd { margin: 2px 0 0; font-weight: var(--font-weight-medium); overflow-wrap: anywhere; }

.tabs { display: flex; flex-wrap: wrap; gap: var(--space-4); border-bottom: var(--border-width) solid var(--color-border); }
.tab {
    display: inline-flex;
    gap: var(--space-1);
    align-items: baseline;
    padding: var(--space-2) 2px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--color-text-muted);
    font: inherit;
    cursor: pointer;
}
.tab:hover { color: var(--color-text); }
.tab[aria-selected="true"] { border-bottom-color: var(--color-primary); color: var(--color-text); font-weight: var(--font-weight-bold); }
.tab-panel { padding: var(--space-4) 0; overflow-x: auto; }
.tab-panel h2 { font-size: var(--font-size-base); }
.tab-panel h2.spaced { margin-top: var(--space-5); }

/* Narrow windows: the rail runs along the top, and the middle bar stacks above the page. */
@media (max-width: 720px) {
    .shell { display: flex; flex-direction: column; }
    .rail {
        flex-direction: row;
        width: 100%;
        height: var(--rail-height-narrow);
        padding: 0 var(--space-2);
    }
    .rail-brand { margin: 0; flex: none; }
    .rail-list { flex-direction: row; overflow-x: auto; min-width: 0; }
    .rail-link { width: auto; padding: var(--space-1) var(--space-2); }
    .rail-foot { flex-direction: row; margin: 0 0 0 auto; }
    .rail .menu-panel { position: fixed; top: var(--rail-height-narrow); right: var(--space-2); bottom: auto; left: auto; }
    .context { position: static; width: 100%; height: auto; max-height: 40vh; border-right: none; border-bottom: var(--border-width) solid var(--color-border); }
    .content { padding: var(--space-4); }
    .tile-wide { grid-column: auto; }
}
