:root {
  --bg: #e8eaee;
  --card: #fff;
  --line: #e4e7ec;
  --ink: #192231;
  --body: #4d5868;
  --mut: #98a1b0;
  --mut2: #aab2bf;
  --blue: #2563eb;
  --green: #1f9d57;
  --amber: #d9911a;
  --red: #d23b3b;
  --navy: #193053;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

html,
body {
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

button {
  min-height: 40px;
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 600;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.15s ease, box-shadow 0.18s ease;
}

button:hover {
  filter: none;
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 1px;
}

.topbar {
  position: relative;
  min-height: 78px;
  padding: 14px 28px;
  gap: 28px;
  overflow: hidden;
  background:
    radial-gradient(640px 300px at 85% -40%, rgba(64, 120, 210, 0.52), transparent 62%),
    linear-gradient(118deg, #13223b 0%, #193053 68%, #1f3a63 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 4px 18px rgba(15, 31, 54, 0.12);
}

.topbar::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image: linear-gradient(105deg, transparent 0 44%, rgba(255, 255, 255, 0.08) 44.2%, transparent 44.6%);
}

.topbar > * {
  position: relative;
  z-index: 1;
}

.brand {
  gap: 16px;
  min-width: 0;
}

.brand-logo {
  height: 34px;
  width: auto;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-divider {
  width: 1px;
  height: 38px;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.18);
}

.brand > div {
  padding-left: 0;
  border-left: 0;
  line-height: 1.25;
  letter-spacing: 0;
}

.brand small,
.heading > span {
  display: block;
  margin-bottom: 3px;
  color: rgba(255, 255, 255, 0.55);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.67rem;
  font-weight: 500;
  letter-spacing: 0.18em;
}

.brand strong {
  display: block;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
}

.heading {
  margin-left: auto;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.07);
}

.heading h1 {
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0;
}

.heading p {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.56);
  font-size: 0.72rem;
}

.top-actions {
  margin-left: 0;
  gap: 8px;
}

.top-actions button,
.quiet {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.86);
  box-shadow: none;
}

.top-actions button:hover,
.quiet:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
}

.top-actions .primary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.connection {
  min-height: 38px;
  padding: 8px 28px;
  border-bottom: 1px solid #d9dde4;
  background: #f6f7f9;
  color: var(--body);
  font-size: 0.78rem;
}

.connection.cloud {
  background: #edf8f2;
  color: #276044;
}

.text-button {
  min-height: 24px;
  color: var(--blue);
  font-size: 0.78rem;
}

.text-button:hover {
  transform: none;
  text-decoration: underline;
}

main {
  display: grid;
  grid-template-columns: 280px minmax(500px, 1fr) 300px;
  gap: 16px;
  min-height: calc(100dvh - 116px);
  padding: 20px;
}

.sidebar,
.inspector,
.viewer-heading,
.metrics > div,
#viewport {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.sidebar,
.inspector {
  padding: 20px;
}

.sidebar {
  border-right: 1px solid var(--line);
  gap: 10px;
}

.inspector {
  border-left: 1px solid var(--line);
  gap: 10px;
}

.sidebar-title,
.parts-heading {
  min-height: 25px;
}

.item-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: #eef0f3;
}

.item-tabs button {
  min-height: 34px;
  padding: 6px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--body);
  font-size: 0.75rem;
}

.item-tabs button:hover {
  transform: none;
}

.item-tabs button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.1);
}

.sidebar-title h2,
.parts-heading h2,
.inspector h2 {
  color: var(--ink);
  font-weight: 700;
}

.sidebar-title h2 {
  font-size: 1.05rem;
}

.count {
  padding: 3px 8px;
  border-color: #e1e5eb;
  border-radius: 999px;
  background: #f1f3f6;
  color: var(--body);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
}

#groups {
  gap: 7px;
  margin: 6px 0 20px;
}

.group {
  min-height: 60px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8f9fb;
  color: var(--body);
}

.group:hover {
  border-color: #d5dae2;
  background: #f0f2f5;
}

.group.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  box-shadow: 0 5px 14px rgba(37, 99, 235, 0.2);
}

.search span,
.filter-label,
#record-form label,
#login-form label {
  color: var(--body);
  font-size: 0.78rem;
  font-weight: 600;
}

input:not([type="checkbox"]):not([type="range"]),
select,
textarea {
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #d9dee6;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

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

input:not([type="checkbox"]):not([type="range"]):hover,
select:hover,
textarea:hover {
  border-color: #c6cdd8;
}

.parts {
  margin: 7px -5px;
  padding: 0 5px;
  scrollbar-color: #dfe3e8 transparent;
}

.part {
  min-height: 52px;
  padding: 9px;
  border: 1px solid transparent;
  border-bottom-color: #eef0f3;
  border-radius: 9px;
  color: var(--body);
}

.part:hover {
  border-color: var(--line);
  background: #f5f6f8;
}

.part.active {
  border-color: #bfd1fb;
  background: #eef4ff;
  color: var(--ink);
  box-shadow: inset 3px 0 0 var(--blue), 0 2px 8px rgba(37, 99, 235, 0.08);
}

.part .dot {
  margin-top: 5px;
}

.dot {
  width: 11px;
  height: 11px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(61, 75, 92, 0.32), 0 1px 4px rgba(16, 24, 40, 0.18);
}

.outline {
  border-color: #d8dde5;
  background: #fff;
  color: var(--body);
}

.outline:hover {
  border-color: #c8ced8;
  background: #f5f6f8;
  color: var(--ink);
}

.primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.18);
}

.primary:hover {
  background: #1d4ed8;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.24);
}

.workspace {
  min-width: 0;
  padding: 0;
}

.viewer-heading {
  min-height: 74px;
  padding: 14px 18px;
}

.viewer-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.viewer-actions label {
  color: var(--mut);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.viewer-actions select {
  display: block;
  min-width: 138px;
  min-height: 40px;
  margin-top: 4px;
  padding-top: 7px;
  padding-bottom: 7px;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: none;
}

.viewer-actions button {
  white-space: nowrap;
}

.viewer-heading h2 {
  margin-top: 3px;
  font-size: 1.45rem;
  font-weight: 700;
}

.eyebrow {
  color: var(--mut);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.08em;
}

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

.metrics > div {
  min-width: 0;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.metrics > div:first-child,
.metrics > div:last-child {
  padding-left: 16px;
  border: 1px solid var(--line);
}

.metrics span {
  color: var(--ink);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.1;
}

.metrics > div:nth-child(2) span {
  color: var(--green);
}

.metrics small {
  color: var(--mut);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.67rem;
  text-transform: uppercase;
}

#viewport {
  min-height: 480px;
  border-color: #dfe3e8;
  background: #f3f4f6;
}

#viewport.registering-joint canvas {
  cursor: crosshair;
}

#joint-register-hint {
  position: absolute;
  z-index: 5;
  top: 72px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 28px);
  padding: 10px 12px;
  border: 1px solid #b9cdf8;
  border-radius: 10px;
  background: rgba(238, 244, 255, 0.96);
  color: #254678;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
  font-size: 0.78rem;
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
}

#joint-register-hint strong,
#joint-register-hint span {
  white-space: nowrap;
}

#joint-register-hint button {
  min-height: 30px;
  padding: 4px 9px;
  border-color: #b9cdf8;
  background: #fff;
  color: #254678;
  font-size: 0.72rem;
}

.view-tools {
  top: 14px;
  left: 14px;
  padding: 4px;
  gap: 2px;
  border-color: #e0e4ea;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.08);
  backdrop-filter: blur(8px);
}

.view-tools button {
  min-height: 31px;
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--body);
}

.view-tools button:hover {
  background: #edf0f4;
  color: var(--ink);
  transform: none;
}

.view-bottom > label {
  padding: 9px 11px;
  border-color: #e0e4ea;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--body);
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.06);
  backdrop-filter: blur(8px);
}

.view-bottom input[type="range"],
input[type="checkbox"] {
  accent-color: var(--blue);
}

#loading {
  background: rgba(243, 244, 246, 0.94);
}

.spinner {
  border-color: #d7dce4;
  border-top-color: var(--blue);
}

.legend {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--body);
}

.method-note {
  margin: 9px 4px 0;
  color: #7d8795;
}

.inspector h2 {
  margin-top: -2px;
  font-size: 1.1rem;
}

.empty {
  margin-top: 8px;
  padding: 46px 12px;
  border: 1px dashed #d7dce4;
  border-radius: 12px;
  background: #fafbfc;
}

.selection-symbol {
  color: #a4adba;
}

.selected-label {
  border-color: var(--line);
}

.batch-hint {
  margin-top: 12px;
  padding: 11px 12px;
  border: 1px solid #b9cdf8;
  border-radius: 10px;
  background: #eef4ff;
  color: #254678;
  font-size: 0.78rem;
  line-height: 1.5;
}

#joint-record-form {
  margin-top: 14px;
}

#joint-record-form label {
  display: block;
  margin: 18px 0 7px;
  color: var(--body);
  font-size: 0.78rem;
  font-weight: 600;
}

.danger-outline {
  border: 1px solid #efc2c2;
  background: #fff;
  color: var(--red);
}

.danger-outline:hover {
  border-color: #e7a5a5;
  background: #fff5f5;
}

.selected-label span,
.metadata,
.project-note {
  color: var(--mut);
}

.applicability-note {
  margin-top: 7px;
  padding: 9px 10px;
  border: 1px solid #e1e5eb;
  border-radius: 9px;
  background: #f5f6f8;
  color: var(--body);
  font-size: 0.73rem;
  line-height: 1.45;
}

.project-note {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8f9fb;
}

.project-note strong {
  color: var(--body);
}

#toast {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 11px;
  background: #192a43;
  box-shadow: 0 12px 40px rgba(16, 24, 40, 0.25);
}

dialog {
  border-color: var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(16, 24, 40, 0.25);
}

dialog::backdrop {
  background: rgba(15, 26, 44, 0.72);
  backdrop-filter: blur(3px);
}

#joint-editor-form > label {
  display: block;
  margin: 16px 0 7px;
  color: var(--body);
  font-size: 0.78rem;
  font-weight: 600;
}

#joint-editor-form .joint-size-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

#joint-marker-size {
  width: 100%;
  accent-color: var(--blue);
}

#joint-marker-size-value {
  color: var(--blue);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
}

#joint-editor-form .joint-size-note {
  margin-top: 4px;
  font-size: 0.72rem;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  border-radius: 8px;
  background: #dfe3e8;
}

@keyframes portalIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sidebar,
.workspace,
.inspector {
  animation: portalIn 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.workspace {
  animation-delay: 0.04s;
}

.inspector {
  animation-delay: 0.08s;
}

@media (min-width: 1600px) {
  main {
    grid-template-columns: 300px minmax(560px, 1fr) 320px;
    gap: 18px;
    padding: 22px;
  }

  .workspace {
    padding: 0;
  }

  #viewport {
    min-height: 590px;
  }
}

@media (max-width: 1180px) {
  main {
    grid-template-columns: 250px minmax(430px, 1fr);
  }

  .inspector {
    grid-column: 1 / -1;
    border: 1px solid var(--line);
  }

  .heading {
    display: none;
  }
}

@media (max-width: 760px) {
  body {
    width: 100%;
    max-width: 100vw;
  }

  .topbar {
    width: 100%;
    min-height: auto;
    padding: 14px 16px;
    gap: 12px;
  }

  .brand {
    width: 100%;
  }

  .brand > div {
    display: block;
  }

  .brand-logo {
    height: 28px;
  }

  .brand-divider {
    height: 32px;
  }

  .brand strong {
    font-size: 1.05rem;
  }

  .top-actions {
    width: 100%;
    min-width: 0;
  }

  .top-actions button {
    min-width: 0;
    flex: 1 1 0;
    padding-right: 8px;
    padding-left: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .connection {
    padding: 8px 16px;
  }

  main {
    display: flex;
    width: 100%;
    max-width: 100vw;
    padding: 14px;
    gap: 14px;
    overflow: hidden;
  }

  main > *,
  .viewer-heading,
  .metrics,
  #viewport {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .sidebar,
  .inspector {
    padding: 18px;
  }

  .sidebar-title {
    margin: 0;
    padding: 18px 18px 0;
  }

  #groups {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin: 0;
    padding: 10px 18px 16px;
  }

  .workspace {
    padding: 0;
  }

  .viewer-heading {
    padding: 13px 15px;
    align-items: flex-start;
    flex-direction: column;
  }

  .viewer-actions {
    width: 100%;
    align-items: flex-end;
    flex-wrap: wrap;
  }

  .viewer-actions label {
    flex: 1 1 130px;
  }

  .viewer-actions select {
    width: 100%;
    min-width: 0;
  }

  .viewer-actions button {
    flex: 1 1 auto;
  }

  .metrics {
    margin: 10px 0;
    gap: 8px;
  }

  .metrics > div,
  .metrics > div:first-child,
  .metrics > div:last-child {
    padding: 11px;
  }

  .metrics span {
    font-size: 1.4rem;
  }

  .metrics small {
    font-size: 0.6rem;
  }

  #viewport {
    height: 480px;
    min-height: 480px;
  }

  .parts-heading,
  .item-tabs,
  .search,
  .filter-label,
  #filter,
  .parts,
  #export-csv {
    margin-right: 18px;
    margin-left: 18px;
  }

  #export-joints {
    order: 8;
    width: calc(100% - 36px);
    margin: 0 18px 18px;
  }

  #filter,
  #export-csv {
    width: calc(100% - 36px);
  }

  .inspector {
    margin-top: 0;
  }
}

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

  .viewer-heading h2 {
    font-size: 1.25rem;
  }

  .viewer-heading .outline {
    padding-inline: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Role-specific workspace: monitoring is also the initial, fail-closed view. */
body[data-mode="monitor"] [data-editor-only],
body[data-mode="monitor"] #import-backup { display: none !important; }
.monitor-stages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 10px 0; }
.stage-card { background: white; border: 1px solid var(--line); padding: 12px 14px; text-align: left; color: var(--ink); min-width: 0; }
.stage-card.active { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.stage-card-title { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: .85rem; }
.stage-card-title strong { font-size: 1.3rem; color: var(--navy); }
.stage-progress { display: block; height: 5px; border-radius: 5px; overflow: hidden; background: #e7edf4; margin: 8px 0; }
.stage-progress i { display: block; height: 100%; background: var(--green); }
.stage-card small { display: block; color: var(--body); font-size: .72rem; font-weight: 400; }
.monitor-detail { background: white; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-top: 8px; font-size: .8rem; color: var(--body); overflow-wrap: anywhere; }
.monitor-detail-title { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 8px; }
.monitor-detail-title strong { color: var(--ink); }
.monitor-detail small { font-size: .7rem; }
.status-chips { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.status-chips > span { display: inline-flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.monitor-note { white-space: pre-wrap; margin: 8px 0; }

@media (min-width: 960px) {
  body { height: 100dvh; display: grid; grid-template-rows: auto auto minmax(0, 1fr); overflow: hidden; }
  .topbar { min-height: 64px; padding: 10px 18px; gap: 18px; }
  .heading { padding: 5px 10px; }
  .heading p { display: none; }
  .brand-logo { height: 28px; }
  .connection { min-height: 30px; padding: 5px 18px; }
  #connection { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { grid-row: 3; min-height: 0; grid-template-columns: 220px minmax(0, 1fr) 270px; padding: 12px; gap: 12px; }
  body[data-mode="monitor"] main { grid-template-columns: 240px minmax(0, 1fr); }
  .sidebar, .inspector { min-height: 0; min-width: 0; padding: 14px; gap: 8px; }
  .sidebar { overflow: hidden; }
  .sidebar > * { flex-shrink: 0; }
  #groups { max-height: 205px; overflow-y: auto; margin: 0 0 4px; gap: 4px; }
  .group { min-height: 62px; padding: 6px 8px; gap: 1px; font-size: .8rem; }
  .group small { font-size: .65rem; }
  .parts { flex: 1 1 0; min-height: 0; max-height: none; margin-top: 0; margin-bottom: 0; }
  .sidebar input, .sidebar select { padding: 7px !important; }
  .sidebar button.full { font-size: .75rem; min-height: 34px; padding: 6px; }
  .search span { margin-bottom: 3px; }
  .workspace { min-height: 0; padding: 0; overflow: hidden; }
  .workspace > * { flex-shrink: 0; }
  .viewer-heading { min-height: 58px; padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .viewer-heading h2 { font-size: 1.3rem; margin-top: 1px; }
  .viewer-heading .eyebrow { font-size: .65rem; }
  .viewer-actions { gap: 6px; flex-wrap: wrap; }
  .viewer-actions label { display: flex; align-items: center; gap: 8px; }
  .viewer-actions button { padding: 7px 9px; min-height: 34px; font-size: .75rem; }
  .viewer-actions select { min-width: 110px; padding: 6px; }
  .stage-card { padding: 8px 12px; }
  .stage-progress { margin: 5px 0; }
  .metrics { gap: 8px; margin: 8px 0; }
  .metrics > div, .metrics > div:first-child, .metrics > div:last-child { padding: 9px 12px; }
  .metrics span { font-size: 1.4rem; }
  .metrics small { font-size: .65rem; }
  #viewport { flex: 1 1 0; min-height: 0; height: auto; }
  .legend { margin-top: 8px; padding: 8px 10px; gap: 6px 12px; font-size: .7rem; }
  .method-note { margin: 5px 3px 0; font-size: .65rem; }
  .monitor-detail { max-height: 130px; overflow-y: auto; }
  .inspector { grid-column: auto; overflow-y: auto; }
  #record-form { display: block; }
  #record-form label { margin: 14px 0 6px; }
  .inspector h2 { font-size: 1rem; }
  .project-note { padding-top: 14px; }
}

@media (max-width: 959px) {
  body { height: auto; overflow-y: auto; }
  .topbar { flex-wrap: wrap; padding: 12px 14px; gap: 12px; }
  .heading { display: none; }
  .top-actions { flex-wrap: wrap; }
  .top-actions #toggle-monitor { flex: 1 0 100%; order: 1; }
  .connection { padding: 7px 14px; overflow-wrap: anywhere; }
  main { display: flex; flex-direction: column; padding: 10px; gap: 12px; min-height: 0; }
  .workspace { order: 0; padding: 0; min-width: 0; }
  .sidebar { order: 1; display: flex; padding: 14px; min-width: 0; }
  .sidebar > * { order: initial !important; margin-left: 0 !important; margin-right: 0 !important; width: 100% !important; }
  .sidebar-title { padding: 0; margin: 0; }
  #groups { padding: 0; margin: 4px 0 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 220px; overflow-y: auto; }
  .group { min-height: 66px; padding: 7px; }
  .parts { flex: auto; min-height: 100px; max-height: 260px; }
  .inspector { order: 2; padding: 16px; }
  #record-form { display: block; }
  #record-form label { margin: 14px 0 6px; }
  #viewport { flex: auto; height: 52dvh; min-height: 320px; }
  .viewer-heading { flex-wrap: wrap; padding: 12px; gap: 10px; }
  .viewer-actions { flex-wrap: wrap; min-width: 0; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .monitor-stages { gap: 6px; }
  .stage-card { padding: 9px 8px; }
  .stage-card-title { flex-wrap: wrap; font-size: .75rem; }
  .stage-card-title strong { font-size: 1.1rem; }
  .stage-card small { font-size: .65rem; }
  .view-bottom { flex-wrap: wrap; gap: 5px; }
  .view-bottom > label { padding: 6px; font-size: .7rem; }
  .view-bottom input[type=range] { width: 65px; }
  #canvas-hint { font-size: .65rem; }
}
