:root {
    color-scheme: dark;
    --background: #0c0d0f;
    --surface: #17191d;
    --surface-raised: #202329;
    --border: #343840;
    --text: #f5f5f5;
    --muted: #a7abb3;
    --accent: #d62f2f;
    --accent-dark: #991f1f;
    --success: #35b56a;
    --warning: #e0a52e;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(214, 47, 47, 0.12), transparent 28rem),
        var(--background);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
    border-bottom: 1px solid var(--border);
    background: rgba(12, 13, 15, 0.92);
    padding: 1rem 2rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    max-width: 1120px;
    margin: 0 auto;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 0.5rem;
    background: var(--accent);
    color: white;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 0.15rem;
    color: var(--muted);
}

.container {
    width: min(1120px, calc(100% - 2rem));
    margin: 3rem auto;
}

.hero {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2rem;
    margin-bottom: 2rem;
}

.hero h1 {
    margin: 0.25rem 0 0.75rem;
    font-size: clamp(2rem, 5vw, 3.7rem);
    line-height: 1;
}

.hero p {
    max-width: 48rem;
    color: var(--muted);
    line-height: 1.7;
}

.eyebrow {
    color: var(--accent) !important;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.16em;
}

.status {
    flex: none;
    border: 1px solid;
    border-radius: 999px;
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 700;
}

.status-good {
    border-color: rgba(53, 181, 106, 0.5);
    background: rgba(53, 181, 106, 0.12);
    color: #79dfa1;
}

.status-warning {
    border-color: rgba(224, 165, 46, 0.5);
    background: rgba(224, 165, 46, 0.12);
    color: #f2c45c;
}

.panel {
    margin-top: 1.25rem;
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    background: linear-gradient(145deg, var(--surface-raised), var(--surface));
    padding: 1.5rem;
    box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.18);
}

.panel h2 {
    margin: 0 0 1.25rem;
    font-size: 1.1rem;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1px;
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    background: var(--border);
}

.status-grid div {
    background: var(--surface);
    padding: 1rem;
}

.status-grid dt {
    margin-bottom: 0.4rem;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.status-grid dd {
    margin: 0;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

footer {
    padding: 2rem;
    color: var(--muted);
    text-align: center;
    font-size: 0.8rem;
}

@media (max-width: 700px) {
    .topbar {
        padding-inline: 1rem;
    }

    .container {
        margin-top: 2rem;
    }

    .hero {
        display: block;
    }

    .status {
        display: inline-block;
        margin-top: 1rem;
    }
}

@media print {
    :root {
        color-scheme: light;
    }

    body {
        background: white;
        color: black;
    }

    .topbar {
        background: white;
        border-color: #bbb;
    }

    .panel {
        background: white;
        border-color: #bbb;
        box-shadow: none;
    }

    .status-grid {
        border-color: #bbb;
        background: #bbb;
    }

    .status-grid div {
        background: white;
    }
}

.setup-form {
    display: grid;
    gap: 2rem;
}

.setup-form fieldset {
    display: grid;
    gap: 1.25rem;
    margin: 0;
    padding: 0;
    border: 0;
}

.setup-form legend {
    width: 100%;
    margin-bottom: 0.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border, #3a3a3a);
    font-size: 1.25rem;
    font-weight: 700;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.form-group {
    display: grid;
    align-content: start;
    gap: 0.45rem;
}

.form-group label {
    font-weight: 700;
}

.form-group input,
.form-group select {
    width: 100%;
    min-height: 44px;
    padding: 0.7rem 0.8rem;
    border: 1px solid #555;
    border-radius: 6px;
    background: #181818;
    color: #fff;
    font: inherit;
}

.form-group input:focus,
.form-group select:focus {
    border-color: #d82929;
    outline: 2px solid rgba(216, 41, 41, 0.28);
    outline-offset: 1px;
}

.form-hint {
    margin: 0;
    color: #aaa;
    font-size: 0.9rem;
}

.form-error {
    margin: 0;
    color: #ff8f8f;
    font-size: 0.9rem;
    font-weight: 600;
}

/* Conditional form sections must remain hidden even when another class sets display. */
[hidden] {
    display: none !important;
}

.choice-group {
    display: grid;
    gap: 0.65rem;
    margin: 0;
    padding: 0;
    border: 0;
}

.choice-group legend {
    margin-bottom: 0.25rem;
    padding: 0;
    font-weight: 700;
}

.choice-option {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.8rem;
    align-items: start;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
}

.choice-option:hover,
.choice-option:focus-within {
    border-color: #777;
    background: rgba(255, 255, 255, 0.04);
}

.choice-option:has(input:checked) {
    border-color: #d82929;
    background: rgba(216, 41, 41, 0.1);
}

.form-group .choice-option input[type="radio"],
.choice-option input[type="radio"] {
    width: 1.15rem;
    height: 1.15rem;
    min-height: 0;
    margin: 0.15rem 0 0;
    padding: 0;
    accent-color: #d82929;
}

.choice-option__title {
    display: block;
    font-weight: 700;
}

.choice-option__description {
    display: block;
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 400;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 1rem;
    border-top: 1px solid #3a3a3a;
}

.pairing-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.pairing-actions .button:not(.button--primary) {
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
}

.pairing-actions .button:not(.button--primary):hover,
.pairing-actions .button:not(.button--primary):focus-visible {
    border-color: var(--accent);
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.1rem;
    border: 0;
    border-radius: 6px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.button--primary {
    background: #d82929;
    color: #fff;
}

.button--primary:hover {
    background: #eb3434;
}

.button--disabled {
    cursor: not-allowed;
    opacity: 0.5;
    pointer-events: none;
}

.alert {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border-radius: 6px;
}

.alert--error {
    border: 1px solid #a83232;
    background: rgba(168, 50, 50, 0.18);
    color: #ffb0b0;
}

.alert--success {
    border: 1px solid #347c48;
    background: rgba(52, 124, 72, 0.18);
    color: #a6e7b8;
}

.alert--warning {
    border: 1px solid #a9791f;
    background: rgba(169, 121, 31, 0.18);
    color: #f2c45c;
}

.static-export-form input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
}

.static-export-machine-row {
    background: rgba(255, 255, 255, 0.025);
}

.static-export-configuration-row td:nth-child(2) {
    padding-left: 2rem;
}

.record-kind {
    display: inline-block;
    margin-left: 0.45rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.1rem 0.4rem;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
}

.static-preview-record {
    margin-top: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.static-preview-record:first-of-type {
    margin-top: 0;
    border-top: 0;
    padding-top: 0;
}

.static-preview-record h3 {
    margin: 0.25rem 0 0.5rem;
}

.static-preview-record__content {
    line-height: 1.65;
    overflow-wrap: anywhere;
}

.static-preview-metrics {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.static-preview-summary,
.static-preview-privacy {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.static-preview-privacy > div:last-child {
    grid-column: span 2;
}

.static-preview-metrics .static-preview-scope {
    color: var(--text);
    text-transform: none;
    letter-spacing: normal;
}

.static-preview-table {
    width: 100%;
    min-width: 700px;
    table-layout: fixed;
}

.static-preview-table th,
.static-preview-table td {
    padding: 0.85rem 0.75rem;
    vertical-align: top;
    overflow-wrap: anywhere;
}

.static-preview-table tbody tr:last-child td {
    border-bottom: 0;
}

.static-preview-table--machines th:nth-child(1),
.static-preview-table--machines td:nth-child(1) {
    width: 24%;
}

.static-preview-table--machines th:nth-child(2),
.static-preview-table--machines td:nth-child(2),
.static-preview-table--machines th:nth-child(3),
.static-preview-table--machines td:nth-child(3) {
    width: 16%;
}

.static-preview-table--configurations th:nth-child(1),
.static-preview-table--configurations td:nth-child(1),
.static-preview-table--configurations th:nth-child(2),
.static-preview-table--configurations td:nth-child(2) {
    width: 30%;
}

.static-preview-table--hardware th:nth-child(1),
.static-preview-table--hardware td:nth-child(1) {
    width: 25%;
}

.static-preview-table--hardware th:nth-child(2),
.static-preview-table--hardware td:nth-child(2) {
    width: 14%;
}

.static-preview-table--hardware th:nth-child(3),
.static-preview-table--hardware td:nth-child(3) {
    width: 31%;
}

.static-preview-table--attachments th:nth-child(1),
.static-preview-table--attachments td:nth-child(1) {
    width: 112px;
}

.static-preview-table--attachments th:nth-child(1) {
    white-space: nowrap;
}

.static-preview-table--attachments th:nth-child(2),
.static-preview-table--attachments td:nth-child(2) {
    width: 24%;
}

.static-preview-table--attachments th:nth-child(3),
.static-preview-table--attachments td:nth-child(3) {
    width: 10%;
}

.static-preview-table--attachments th:nth-child(5),
.static-preview-table--attachments td:nth-child(5) {
    width: 17%;
}

.static-preview-scope {
    display: grid;
    gap: 0.2rem;
}

.static-preview-scope > span {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.static-preview-scope > strong {
    line-height: 1.35;
}

.static-preview-attachment__preview img {
    display: block;
    width: 64px;
    height: 64px;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    object-fit: cover;
}

.static-preview-file-icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    color: var(--muted);
    background: var(--surface);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
}

.static-preview-attachment__link {
    display: inline-block;
    font-weight: 700;
}

.static-preview-attachment__description {
    display: block;
    margin-top: 0.25rem;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.4;
}

@media (max-width: 700px) {
    .static-preview-summary,
    .static-preview-privacy {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 700px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        justify-content: stretch;
    }

    .form-actions .button {
        width: 100%;
    }

    .pairing-actions .button {
        width: 100%;
    }
}

.login-panel {
    max-width: 560px;
    margin-inline: auto;
}

.login-form {
    display: grid;
    gap: 1.25rem;
}

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

.hero-actions {
    display: flex;
    flex: 0 0 100%;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

.section-navigation {
    padding: 0.75rem;
}

.section-navigation__items {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 0.4rem;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    padding: 0 0 0.25rem;
    border-top: 0;
    scrollbar-width: thin;
}

.section-navigation__items .button {
    flex: 1 0 auto;
    min-height: 40px;
    padding: 0.55rem 0.7rem;
    white-space: nowrap;
}

.section-navigation__items .button[aria-current="page"] {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.section-navigation__items .button[aria-current="page"]:hover {
    border-color: var(--accent-dark);
    background: var(--accent-dark);
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.section-heading h2 {
    margin-bottom: 0;
}

.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
    border: 1px dashed var(--border-colour);
    border-radius: 0.75rem;
}

.empty-state h3 {
    margin-top: 0;
}

/*
 * Search autocomplete
 *
 * Suggestions remain attached to their input and use a listbox so mouse,
 * arrow-key and Tab completion all share the same visible choices.
 */
.search-autocomplete {
    position: relative;
}

.search-suggestions {
    position: absolute;
    z-index: 20;
    top: calc(100% + 0.35rem);
    right: 0;
    left: 0;
    max-height: 22rem;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    background: #181818;
    box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.42);
}

.search-suggestion {
    display: grid;
    width: 100%;
    gap: 0.2rem;
    padding: 0.75rem 0.85rem;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.search-suggestion:last-child {
    border-bottom: 0;
}

.search-suggestion:hover,
.search-suggestion:focus-visible,
.search-suggestion[aria-selected="true"] {
    outline: 0;
    background: rgba(216, 41, 41, 0.18);
    color: #fff;
}

.search-suggestion__label {
    font-weight: 700;
}

.search-suggestion__meta {
    color: var(--muted);
    font-size: 0.82rem;
}

.search-results-table td:first-child {
    min-width: 18rem;
}

.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border-colour);
}

.data-table th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.machine-link {
    display: block;
    font-weight: 700;
}

.machine-id {
    display: block;
    margin-top: 0.2rem;
    font-family: monospace;
    font-size: 0.8rem;
    opacity: 0.7;
}

.machine-status {
    display: inline-flex;
    padding: 0.25rem 0.55rem;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: 0.78rem;
    white-space: nowrap;
}

.account-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.account-panel p {
    margin-bottom: 0.25rem;
}

@media (max-width: 700px) {
    .section-heading,
    .account-panel {
        align-items: stretch;
        flex-direction: column;
    }
}

/* Stage 24A: component foundation */

textarea {
    width: 100%;
    padding: 0.7rem 0.8rem;
    border: 1px solid #555;
    border-radius: 6px;
    background: #181818;
    color: #fff;
    font: inherit;
    resize: vertical;
}

textarea:focus {
    border-color: #d82929;
    outline: 2px solid rgba(216, 41, 41, 0.28);
    outline-offset: 1px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.machine-form {
    display: grid;
    gap: 1.25rem;
}

.form-actions {
    flex-wrap: wrap;
    gap: 0.75rem;
}

.button {
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
    text-decoration: none;
}

.button[aria-disabled="true"] {
    cursor: default;
    opacity: 0.5;
}

a {
    color: #ff7676;
}

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

    .hero-actions {
        align-items: stretch;
        flex-direction: column;
        margin-top: 1rem;
    }
}

/* Stage 24A: component foundation */

textarea {
    width: 100%;
    padding: 0.7rem 0.8rem;
    border: 1px solid #555;
    border-radius: 6px;
    background: #181818;
    color: #fff;
    font: inherit;
    resize: vertical;
}

textarea:focus {
    border-color: #d82929;
    outline: 2px solid rgba(216, 41, 41, 0.28);
    outline-offset: 1px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.machine-form {
    display: grid;
    gap: 1.25rem;
}

.form-actions {
    flex-wrap: wrap;
    gap: 0.75rem;
}

.button {
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
    text-decoration: none;
}

.button[aria-disabled="true"] {
    cursor: default;
    opacity: 0.5;
}

a {
    color: #ff7676;
}

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

    .hero-actions {
        align-items: stretch;
        flex-direction: column;
        margin-top: 1rem;
    }
}

/*
 * Reference Data
 *
 * Keep the editable value and its action on the same row at normal
 * desktop/tablet widths. The surrounding table wrapper handles
 * horizontal overflow where necessary.
 */
.reference-data-inline-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.75rem;
    align-items: end;
}

.reference-data-inline-form--compact {
    min-width: 24rem;
}

.reference-data-inline-form .form-group {
    min-width: 0;
}

.reference-data-inline-form .button {
    white-space: nowrap;
}

/* Compact per-row QR label visibility control in the Parts Store. */
.data-table .qr-label-cell {
    width: 128px;
    text-align: center;
}

.qr-label-cell img {
    margin-inline: auto;
}

.qr-label-toggle-form {
    margin-top: 0.4rem;
    text-align: center;
}

.qr-label-toggle-form .qr-label-toggle {
    appearance: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #ff7676;
    font: inherit;
    font-size: 0.8rem;
    text-decoration: underline;
    text-underline-offset: 0.2rem;
    cursor: pointer;
}

.qr-label-toggle-form .qr-label-toggle:hover,
.qr-label-toggle-form .qr-label-toggle:focus-visible {
    color: #ff9a9a;
}

.table-row-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.table-row-actions .button {
    min-height: 40px;
    padding: 0.55rem 0.75rem;
}

@media (max-width: 700px) {
    .reference-data-inline-form {
        grid-template-columns: 1fr;
    }

    .reference-data-inline-form--compact {
        min-width: 16rem;
    }

    .reference-data-inline-form .button {
        width: 100%;
    }
}

/* Canonical interaction states for enabled application buttons. */
.button {
    transition:
        background-color 120ms ease,
        border-color 120ms ease,
        color 120ms ease;
}

.button:not(:disabled):not([aria-disabled="true"]):hover,
.button:not(:disabled):not([aria-disabled="true"]):focus-visible {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.button:not(:disabled):not([aria-disabled="true"]):focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.85);
    outline-offset: 2px;
}

.section-navigation__items .button[aria-current="page"]:hover,
.section-navigation__items .button[aria-current="page"]:focus-visible {
    border-color: var(--accent-dark);
    background: var(--accent-dark);
}
