:root {
  color-scheme: dark;
  --bg: #050606;
  --bg-panel: #0b0d0f;
  --card: rgba(18, 21, 24, 0.94);
  --card-strong: #15191d;
  --text: #f4f5f2;
  --muted-text: #a8b0b7;
  --border: #2b3136;
  --table-border: #272d32;
  --table-head: #11161a;
  --brand: rgba(5, 6, 6, 0.94);
  --link: #f8f8f3;
  --link-accent: #e2a047;
  --accent: #d68e25;
  --accent-strong: #ffb454;
  --accent-text: #15100a;
  --btn-bg: #d68e25;
  --btn-border: #f0a43e;
  --input-bg: #0a0d10;
  --input-border: #3a4248;
  --code-bg: #0c1014;
  --code-text: #f6c46e;
  --success-bg: rgba(64, 178, 116, 0.16);
  --success-text: #78e0a4;
  --danger-bg: rgba(238, 82, 82, 0.16);
  --danger-text: #ff9a9a;
  --arm-fill-start: #c81e1e;
  --arm-fill: #ff3b3b;
  --arm-filled-text: #ffffff;
  --arm-glow: rgba(170, 24, 24, 0.35);
  --arm-glow-ring: #ff5c5c;
  --arm-glow-tail: rgba(205, 32, 32, 0.6);
  --arm-glow-track: rgba(140, 20, 20, 0.45);
  --pending-bg: rgba(168, 176, 183, 0.14);
  --pending-text: #c5ccd1;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #efeee9;
  --bg-panel: #f7f6f0;
  --card: rgba(255, 255, 255, 0.96);
  --card-strong: #f7f6f0;
  --text: #17191b;
  --muted-text: #5d6670;
  --border: #d4d0c5;
  --table-border: #ded9cf;
  --table-head: #ebe7dd;
  --brand: rgba(8, 9, 10, 0.96);
  --link: #f8f8f3;
  --link-accent: #9c5e12;
  --accent: #b96d16;
  --accent-strong: #d68e25;
  --accent-text: #fffaf0;
  --btn-bg: #17191b;
  --btn-border: #17191b;
  --input-bg: #ffffff;
  --input-border: #c2beb4;
  --code-bg: #f0eadf;
  --code-text: #7a470d;
  --success-bg: #e2f6e9;
  --success-text: #146b37;
  --danger-bg: #fde8e8;
  --danger-text: #9b1c1c;
  --arm-fill-start: #b91c1c;
  --arm-fill: #e02424;
  --arm-filled-text: #ffffff;
  --arm-glow: rgba(155, 28, 28, 0.28);
  --arm-glow-ring: #e02424;
  --arm-glow-tail: rgba(185, 28, 28, 0.5);
  --arm-glow-track: rgba(155, 28, 28, 0.3);
  --pending-bg: #e7e8ea;
  --pending-text: #4d5560;
  --shadow: 0 14px 36px rgba(23, 25, 27, 0.1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(214, 142, 37, 0.08), transparent 260px),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.026) 0 1px, transparent 1px 9px),
    var(--bg);
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035), transparent 18%, transparent 82%, rgba(255, 255, 255, 0.025)),
    linear-gradient(180deg, rgba(0, 0, 0, 0.08), transparent 34rem);
  pointer-events: none;
}

a {
  color: var(--link-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.75rem;
  color: var(--text);
  font-weight: 800;
  line-height: 1.1;
  text-transform: uppercase;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1rem;
}

h4 {
  margin-top: 1.2rem;
  color: var(--accent-strong);
  font-size: 0.86rem;
}

p {
  margin: 0 0 0.9rem;
}

em {
  color: var(--muted-text);
}

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

main.container {
  padding: 24px 0 52px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  color: var(--link);
  background: var(--brand);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.header .container {
  padding: 12px 0;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: max-content;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 26px;
  background:
    linear-gradient(135deg, #f2f2ec 0 42%, #686f75 43% 57%, var(--accent) 58% 100%);
  clip-path: polygon(0 52%, 72% 0, 100% 18%, 40% 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.brand-kicker,
.logo {
  display: block;
}

.brand-kicker {
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.logo {
  color: var(--link);
  font-size: 1rem;
  font-weight: 800;
  text-transform: uppercase;
}

.primary-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.primary-nav a,
.primary-nav form button,
.theme-btn,
.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  background: var(--card-strong);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.primary-nav a,
.primary-nav form button,
.theme-btn {
  color: var(--link);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.14);
}

.primary-nav a:hover,
.primary-nav form button:hover,
.theme-btn:hover,
.btn:hover,
button:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}

button,
.btn {
  color: var(--accent-text);
  background: var(--btn-bg);
  border-color: var(--btn-border);
}

.quiet-btn {
  color: var(--text);
  background: var(--card-strong);
  border-color: var(--border);
}

.danger-btn {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-color: var(--danger-text);
}

button:disabled,
button[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.theme-btn {
  width: 42px;
  min-width: 42px;
  padding: 0;
}

.theme-icon {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: inset -5px -4px 0 rgba(5, 6, 6, 0.58);
}

[data-theme="dark"] .theme-icon {
  background: #f7f4e8;
  box-shadow:
    0 -7px 0 -5px #f7f4e8,
    0 7px 0 -5px #f7f4e8,
    7px 0 0 -5px #f7f4e8,
    -7px 0 0 -5px #f7f4e8;
}

.card {
  margin-bottom: 18px;
  padding: clamp(18px, 2vw, 26px);
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card > :last-child {
  margin-bottom: 0;
}

/* Assembly tables scroll independently of the surrounding preview content. */
.assembly-card {
  min-width: 0;
  overflow: visible;
  overflow-wrap: anywhere;
}

.assembly-card fieldset {
  min-inline-size: 0;
  max-width: 100%;
  margin-inline: 0;
}

.assembly-card legend {
  max-width: 100%;
  white-space: normal;
}

.assembly-table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.assembly-table-scroll:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.assembly-table-scroll th {
  white-space: nowrap;
}

.assembly-table-scroll .assembly-registered-table {
  min-width: 0;
}

.assembly-selection-preview {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.assembly-scroll-hint {
  display: none;
}

.muted {
  color: var(--muted-text);
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 14px;
  align-items: end;
}

/* The assembly form's hint sits a little below its fields, and the details heading below the hint. */
.assembly-fields-hint {
  margin-top: 0.9rem;
}

.assembly-fields-heading {
  margin-top: 1.8rem;
}

/* A card heading with a button beside it, such as Assemblies and its History button. */
.section-header {
  align-items: center;
  margin-bottom: 0.75rem;
}

.section-header h3 {
  margin: 0;
}

.history-filters {
  margin-bottom: 1rem;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted-text);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--text);
  background: var(--input-bg);
  font: inherit;
  font-size: 0.92rem;
  outline: none;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(214, 142, 37, 0.22);
}

input[readonly] {
  color: var(--muted-text);
  background: color-mix(in srgb, var(--input-bg), var(--border) 18%);
}

input[type="checkbox"] {
  width: 1.1rem;
  min-height: 1.1rem;
  padding: 0;
  accent-color: var(--accent);
}

input[type="file"] {
  padding: 7px;
}

select {
  cursor: pointer;
}

textarea {
  min-height: 74px;
  resize: vertical;
}

table {
  width: 100%;
  min-width: 720px;
  margin-top: 12px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--table-border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted-text);
  background: var(--table-head);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: rgba(214, 142, 37, 0.07);
}

code {
  padding: 2px 7px;
  color: var(--code-text);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.inline-form button {
  min-height: 32px;
}

.right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-editor td {
  vertical-align: middle;
}

/* Line the Remove column up with the add buttons under the table. */
.row-editor .remove-cell {
  width: 1%;
  padding-right: 0;
  text-align: right;
  white-space: nowrap;
}

.row-editor .remove-cell button {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-color: color-mix(in srgb, var(--danger-text) 40%, var(--border));
}

/* A tick box beside its label text, as one row of a form grid. */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: end;
  min-height: 40px;
}

/* Marks a detail line that is itself an assembly glued in as a whole. */
.assembly-badge {
  display: inline-block;
  padding: 0 8px;
  border: 1px solid var(--input-border);
  border-radius: 999px;
  background: var(--input-bg);
  font-size: 0.78rem;
  white-space: nowrap;
}

/* One reviewed assembly in the import review: a line that opens to show its fields and details. */
.import-group {
  border-top: 1px solid var(--border);
}

.import-group > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 12px 0;
  cursor: pointer;
  list-style: none;
}

.import-group > summary::-webkit-details-marker {
  display: none;
}

/* The arrow turns down when the assembly is open. */
.import-group > summary::before {
  content: "\25B8";
  order: -1;
  width: 1em;
  color: var(--accent-strong);
  transition: transform 0.15s ease;
}

.import-group[open] > summary::before {
  transform: rotate(90deg);
}

.import-group-title {
  font-weight: 700;
}

.import-group-code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.import-group.has-error > summary {
  color: var(--danger-text);
}

.import-group-body {
  padding: 0 0 16px 1.6em;
}

.import-group ul {
  margin: 6px 0;
}

.import-toggle-all {
  margin-bottom: 8px;
}

.assembly-badge.is-problem {
  color: var(--danger-text);
  border-color: var(--danger-text);
  background: var(--danger-bg);
}

.import-warning {
  color: var(--danger-text);
}

/* An import error, with the rows it names listed one per line below it. */
.import-error {
  color: var(--danger-text);
  padding-bottom: 18px;
}

.import-error p {
  margin-bottom: 6px;
}

.import-error ul {
  margin: 0;
  padding-left: 1.4em;
}

.import-error li + li {
  margin-top: 4px;
}

.import-error a {
  color: inherit;
  font-weight: 700;
}

.row-editor + .action-row {
  margin: 18px 0 26px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-header p {
  margin-bottom: 0;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.status-metric {
  display: inline-flex;
  align-items: baseline;
  min-height: 34px;
  padding: 6px 10px;
  color: var(--muted-text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-metric strong {
  margin-right: 7px;
  color: var(--text);
  font-size: 1.05rem;
}

/* A metric that opens the page behind it, such as Real number missing. */
a.status-metric {
  text-decoration: none;
}

a.status-metric:hover,
a.status-metric:focus-visible {
  border-color: var(--accent);
  color: var(--text);
}

/* The import's three file fields: room above them, and a plain-text hint under each label. */
.import-files {
  margin-top: 28px;
}

.field-hint {
  color: var(--muted-text);
  font-size: 0.85rem;
  font-weight: 400;
  text-transform: none;
}

/* Assembly lists: one line per assembly, with its details sliding open in a row underneath. */
.assembly-table td {
  vertical-align: middle;
}

.assembly-table tr.is-expanded > td {
  border-bottom-color: transparent;
}

.assembly-table .assembly-details-row > td {
  padding: 0;
  border-bottom-width: 0;
}

.assembly-table .assembly-details-row.is-open > td {
  border-bottom-width: 1px;
}

.assembly-table .assembly-details-row:hover {
  background: transparent;
}

.assembly-details {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 0.28s ease, opacity 0.28s ease;
}

.assembly-details.is-open {
  grid-template-rows: 1fr;
  opacity: 1;
}

.assembly-details-inner {
  min-height: 0;
  overflow: hidden;
  padding: 0 10px 0 28px;
  line-height: 1.7;
  transition: padding 0.28s ease;
}

.assembly-details.is-open .assembly-details-inner {
  padding-top: 2px;
  padding-bottom: 14px;
}

/* A small arrow on Details that turns over while the details are open. */
.details-toggle::after {
  content: "\25BE";
  display: inline-block;
  margin-left: 6px;
  transition: transform 0.28s ease;
}

.details-toggle[aria-expanded="true"]::after {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .assembly-details,
  .assembly-details-inner,
  .details-toggle::after {
    transition: none;
  }
}

.assembly-filters,
.kit-filters {
  align-items: end;
  margin-bottom: 1rem;
}

.pager {
  justify-content: center;
  margin-top: 1rem;
}

/* Project items: steps signed outside the part's own list, e.g. from Edit All. */
.extra-steps {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 0.74rem;
  font-weight: 800;
  cursor: help;
}

.step-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 16px;
}

.box-progress-table {
  min-width: 680px;
}

.progress-percent {
  display: inline-block;
  min-width: 42px;
  margin-right: 8px;
  color: var(--text);
  font-weight: 800;
}

.progress-meter {
  display: inline-flex;
  width: min(150px, 100%);
  height: 9px;
  overflow: hidden;
  vertical-align: middle;
  background: var(--pending-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.progress-meter span {
  display: block;
  min-width: 0;
  background: linear-gradient(90deg, var(--accent), var(--success-text));
}

.production-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.production-done {
  color: var(--success-text);
  background: var(--success-bg);
}

.production-active {
  color: var(--pending-text);
  background: var(--pending-bg);
}

.project-filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(150px, 0.8fr) minmax(220px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  margin: 12px 0 16px;
}

.part-filter-bar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  margin: 12px 0 16px;
}

.filter-count {
  align-self: center;
  color: var(--muted-text);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.step-filter {
  margin-top: 18px;
}

.step-filter fieldset {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.step-filter legend {
  padding: 0 6px;
  color: var(--muted-text);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.step-filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.check-option {
  display: inline-grid;
  grid-template-columns: auto max-content;
  align-items: center;
  width: auto;
  min-height: 34px;
  padding: 6px 10px;
  column-gap: 7px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  font-size: 0.86rem;
  font-weight: 700;
  text-transform: none;
  cursor: pointer;
}

.check-option input {
  grid-column: 1;
  margin: 0;
}

.check-option span {
  grid-column: 2;
}

.qc-notes-table {
  min-width: 1060px;
}

.note-field {
  min-width: 240px;
}

.note-form {
  display: grid;
  gap: 8px;
}

.note-form button {
  justify-self: start;
}

.template-block {
  margin-bottom: 12px;
}

.sm {
  width: min(100%, 160px);
}

.xs {
  width: min(100%, 86px);
}

.sm-btn {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 0.78rem;
}

.step-order {
  align-items: center;
  flex-wrap: nowrap;
}

.step-order [data-order-position] {
  min-width: 1.6em;
  font-weight: 800;
}

input.xs,
input.sm,
select.sm {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 0.82rem;
}

.auth-shell {
  width: min(480px, 100%);
  margin: 44px auto;
}

.auth-card {
  padding: clamp(24px, 5vw, 38px);
}

.auth-card h1 {
  margin: 0 0 8px;
}

.auth-form {
  grid-template-columns: 1fr;
}

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

.auth-error {
  margin: 0 0 12px;
}

.modal.hidden,
.modal:not([open]) {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 18px;
  color: var(--text);
  background: transparent;
  border: 0;
}

.modal::backdrop {
  background: transparent;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  margin: 12vh auto;
  overflow: hidden;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--table-head);
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
}

.modal-body {
  padding: 18px 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

/* Assembly page popups fade in and out; the page script toggles .is-visible. */
.popup-dialog {
  opacity: 0;
  transition: opacity 200ms ease;
}

/* Centre the popup in the window; it is hidden by .modal:not([open]) until opened. */
.popup-dialog[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup-dialog .modal-card {
  display: flex;
  flex-direction: column;
  max-height: 100%;
  margin: 0;
  transform: translateY(8px);
  transition: transform 200ms ease;
}

.assembly-dialog .modal-card,
.kit-dialog .modal-card {
  width: min(1000px, 100%);
}

.confirm-dialog .modal-card {
  width: min(520px, 100%);
}

/*
 * The final Delete assembly button arms before it works: hovering (or holding on a touch screen,
 * or focusing with the keyboard) sweeps a red bar across them, and leaving drains it back.
 * The page script drives --arm from 0 to 1 and adds .is-armed when the bar is full.
 */
@property --arm-glow-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

.arm-btn {
  --arm: 0;
  position: relative;
  background-image: linear-gradient(90deg, var(--arm-fill-start), var(--arm-fill));
  background-repeat: no-repeat;
  background-size: calc(var(--arm) * 100%) 100%;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.arm-btn[aria-disabled="true"] {
  cursor: progress;
}

/* Keep the text readable once the bar is under most of it. */
.arm-btn.is-half-armed,
.arm-btn.is-armed {
  color: var(--arm-filled-text);
}

.arm-btn:disabled {
  cursor: not-allowed;
}

.arm-btn.is-armed {
  border-color: var(--arm-glow-track);
  box-shadow: 0 0 8px var(--arm-glow);
}

/*
 * An armed button gets a comet that keeps circling its border: a bright head with a fading
 * tail on a faint red track (::after), and a soft halo that travels around the outside with
 * it (::before). Both spin on the same angle, so they move together.
 */
.arm-btn::before,
.arm-btn::after {
  position: absolute;
  content: "";
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.arm-btn::after {
  inset: -2px;
  padding: 2px;
  border-radius: 6px;
  background: conic-gradient(
    from var(--arm-glow-angle),
    var(--arm-glow-track) 0 68%,
    var(--arm-glow-tail) 88%,
    var(--arm-glow-ring) 97%,
    var(--arm-glow-track) 97%
  );
}

.arm-btn::before {
  inset: -9px;
  padding: 9px;
  border-radius: 13px;
  background: conic-gradient(from var(--arm-glow-angle), transparent 0 72%, var(--arm-glow) 94%, transparent 100%);
  filter: blur(4px);
}

.arm-btn.is-armed::before,
.arm-btn.is-armed::after {
  opacity: 1;
  animation: arm-glow-spin 1.8s linear infinite;
}

@keyframes arm-glow-spin {
  to {
    --arm-glow-angle: 360deg;
  }
}

@media (prefers-reduced-motion: reduce) {
  .arm-btn.is-armed::before {
    opacity: 0;
  }

  .arm-btn.is-armed::after {
    animation: none;
    background: var(--arm-glow-tail);
  }
}

/* Delete assembly and Delete kit sit apart from Cancel and Save. */
.assembly-dialog .modal-footer .danger-btn,
.kit-dialog .modal-footer .danger-btn {
  margin-right: auto;
}

/* In a short window only the body scrolls; the header and buttons stay in view. */
.popup-dialog form {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* The editor columns fit the popups, so drop the page-wide table minimum. */
.assembly-dialog table,
.kit-dialog table {
  min-width: 0;
}

.popup-dialog.is-visible {
  opacity: 1;
}

.popup-dialog.is-visible .modal-card {
  transform: none;
}

.popup-dialog .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 75vh;
  overflow-y: auto;
}

.popup-dialog .modal-footer {
  gap: 8px;
}

/* Labels and buttons set their own display, which would otherwise show hidden popup parts. */
.popup-dialog [hidden] {
  display: none;
}

.assembly-dialog-error,
.kit-dialog-error,
.danger-note {
  margin-top: 0;
  color: var(--danger-text);
}

/* What the Delete assembly popup would remove, as label and value rows. */
.delete-summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin: 0 0 16px;
}

.delete-summary dt {
  color: var(--muted-text);
}

.delete-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* The Delete assembly name check reads as one plain sentence above its input. */
.confirm-name-label {
  /* Padding, not margin, so it adds to the summary's bottom margin instead of collapsing into it. */
  padding-top: 24px;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 400;
  text-transform: none;
}

.confirm-name-prompt {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-wrap: anywhere;
}

.warning-icon {
  flex: none;
  width: 1.15em;
  height: 1.15em;
  color: var(--accent-strong);
}

@media (prefers-reduced-motion: reduce) {
  .popup-dialog,
  .popup-dialog .modal-card {
    transition: none;
  }
}

.modal-close {
  width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--text);
  background: transparent;
  border-color: transparent;
  font-size: 1.25rem;
}

.table-fixed {
  table-layout: fixed;
  width: 100%;
}

.project-items-table {
  min-width: 1040px;
}

.table-fixed th,
.table-fixed td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.nowrap {
  white-space: nowrap;
}

.wrap {
  white-space: normal;
  word-break: break-word;
}

.serial {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.field-group {
  display: grid;
  gap: 7px;
}

.serial-scan-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.qr-scan-btn {
  white-space: nowrap;
}

.qr-scanner {
  display: grid;
  gap: 10px;
  width: min(100%, 430px);
  margin-top: 16px;
}

.qr-video-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.qr-video-frame video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qr-frame-guide {
  position: absolute;
  inset: 17%;
  border: 2px solid var(--accent-strong);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.signature-photo-field {
  display: grid;
  gap: 10px;
}

.signature-photo-preview {
  display: grid;
  gap: 8px;
}

.signature-photo-preview img,
.signature-photo-thumb {
  display: block;
  width: 100%;
  object-fit: cover;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.signature-photo-preview img {
  max-width: 320px;
  aspect-ratio: 4 / 3;
}

.signature-photo-thumb {
  width: 84px;
  height: 64px;
}

.col-detail {
  width: 12%;
}

.col-version {
  width: 8%;
}

.col-part {
  width: 21%;
}

.col-serial {
  width: 15%;
}

.col-step {
  width: 14%;
}

.col-progress {
  width: 12%;
}

.col-added {
  width: 10%;
}

.col-qc {
  width: 8%;
}

.qc-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.qc-ok {
  color: var(--success-text);
  background: var(--success-bg);
}

.qc-bad {
  color: var(--danger-text);
  background: var(--danger-bg);
}

.qc-pending {
  color: var(--pending-text);
  background: var(--pending-bg);
}

tr.ok {
  background: rgba(64, 178, 116, 0.08);
}

tr.bad {
  background: rgba(238, 82, 82, 0.09);
}

tr.pending {
  background: transparent;
}

.warn {
  margin-top: 4px;
  color: var(--danger-text);
  font-size: 0.76rem;
  font-weight: 800;
}

.instructions-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
  gap: 18px;
  align-items: start;
}

.instructions-layout > .card {
  min-width: 0;
  overflow-wrap: anywhere;
}

.instructions-item-list {
  display: grid;
  gap: 8px;
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
}

.instructions-item-list a {
  display: grid;
  gap: 4px;
  min-height: 44px;
  padding: 12px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.instructions-item-list a[aria-current="true"] {
  border-color: var(--accent-strong);
  background: var(--pending-bg);
}

.instructions-step-list {
  margin: 0 0 20px;
  padding-left: 28px;
}

.instructions-step-list li {
  padding: 10px 4px;
  border-bottom: 1px solid var(--table-border);
}

.instructions-step-list h4 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
}

.instructions-empty {
  margin-top: 10px;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 4px;
}

.instructions-empty p {
  margin: 0;
}

.instructions-empty .instructions-content-label {
  margin-bottom: 8px;
  font-weight: 700;
}

@media (max-width: 820px) {
  .instructions-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .assembly-scroll-hint {
    display: block;
  }

  .container {
    width: min(calc(100% - 22px), 1180px);
  }

  main.container {
    padding-top: 16px;
  }

  .header {
    position: static;
  }

  .header > .container.header-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand {
    width: 100%;
  }

  .primary-nav {
    width: 100%;
    justify-content: flex-start;
  }

  .primary-nav a,
  .primary-nav form button {
    flex: 1 1 auto;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 16px;
  }

  .header-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-header {
    flex-direction: column;
  }

  .right {
    width: 100%;
    justify-content: stretch;
  }

  .right button,
  .right .btn,
  .form-grid > button {
    width: 100%;
  }

  .project-filter-bar,
  .part-filter-bar {
    grid-template-columns: 1fr;
  }

  .filter-count {
    justify-self: start;
  }

  /* Manage Steps: stack each step row into a card instead of a wide table. */
  .step-table {
    min-width: 0;
  }

  .step-table thead {
    display: none;
  }

  .step-table tbody {
    display: grid;
    gap: 12px;
  }

  .step-table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "order save"
      "name name"
      "station station";
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--table-border);
    border-radius: 6px;
  }

  .step-table td {
    display: grid;
    gap: 6px;
    padding: 0;
    border: 0;
  }

  .step-table td[data-cell="order"] { grid-area: order; }
  .step-table td[data-cell="name"] { grid-area: name; }
  .step-table td[data-cell="station"] { grid-area: station; }
  .step-table td[data-cell="save"] { grid-area: save; }

  .step-table td[data-label]::before {
    content: attr(data-label);
    color: var(--muted-text);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  .step-table input,
  .step-table select {
    width: 100%;
    min-height: 44px;
  }

  .step-table [data-move],
  .step-table td[data-cell="save"] button {
    min-width: 44px;
    min-height: 44px;
    font-size: 1rem;
  }

  .step-order-actions {
    flex-wrap: wrap;
    margin-top: 12px;
  }

  .step-order-actions > span {
    flex-basis: 100%;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .container {
    width: 100%;
    padding-right: 11px;
    padding-left: 11px;
  }

  .header .container {
    padding: 12px 11px;
  }

  main.container {
    padding: 16px 11px 52px;
  }

  h1 {
    font-size: 1.65rem;
  }

  h2 {
    font-size: 1.12rem;
  }

  .brand-mark {
    width: 36px;
    height: 23px;
  }

  .primary-nav {
    gap: 6px;
  }

  .primary-nav a,
  .primary-nav form,
  .primary-nav form button {
    width: 100%;
  }

  .theme-btn {
    width: 100%;
  }

  .serial-scan-row {
    grid-template-columns: 1fr;
  }

  .qr-scan-btn {
    width: 100%;
  }

  table {
    min-width: 640px;
  }

  .auth-shell {
    width: 100%;
    max-width: none;
    margin: 18px auto;
  }
}
