:root {
  --navy: #10243f;
  --blue: #2563eb;
  --orange: #f97316;
  --teal: #0f766e;
  --ink: #172033;
  --muted: #667085;
  --line: #d8e0ea;
  --paper: #f6f8fb;
  --surface: #ffffff;
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
}

.mobile-preview body {
  background: #111827;
  overflow: auto;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.demo-page.demo-gate-active {
  overflow: hidden;
}

.demo-page.demo-gate-active .app-shell {
  filter: blur(5px);
  pointer-events: none;
}

.demo-splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    linear-gradient(rgba(37, 99, 235, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.08) 1px, transparent 1px),
    rgba(246, 248, 251, 0.96);
  background-size: 34px 34px;
}

.demo-page.demo-gate-active .demo-splash {
  display: flex;
}

.demo-splash-panel {
  display: grid;
  gap: 18px;
  width: min(620px, 100%);
  padding: 24px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(16, 36, 63, 0.2);
}

.demo-splash-panel .brand-mark {
  color: var(--ink);
}

.demo-splash-panel .brand-icon {
  border-color: var(--navy);
}

.demo-splash-panel h1 {
  color: var(--ink);
  font-size: clamp(34px, 6vw, 54px);
  line-height: 1.02;
}

.demo-splash-panel p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.demo-splash-steps {
  display: grid;
  gap: 8px;
}

.demo-splash-steps span {
  min-height: 40px;
  padding: 10px 12px;
  color: var(--ink);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.demo-password-form {
  display: grid;
  gap: 10px;
}

.demo-password-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.demo-password-form input {
  margin-top: 6px;
}

.demo-password-status {
  min-height: 18px;
  margin: 0;
  color: #9a3412;
  font-size: 12px;
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.app-shell.is-rail-collapsed {
  grid-template-columns: 64px minmax(0, 1fr);
}

.mobile-preview .app-shell {
  width: min(430px, 100vw);
  margin: 0 auto;
  grid-template-columns: 1fr;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12), 0 24px 80px rgba(0, 0, 0, 0.45);
}

.mobile-preview .project-rail {
  min-height: auto;
  padding: 16px;
}

.mobile-preview .project-list {
  grid-auto-flow: column;
  grid-auto-columns: minmax(220px, 1fr);
  overflow-x: auto;
}

.mobile-preview .topbar {
  align-items: flex-start;
  flex-direction: column;
  min-height: auto;
  padding: 14px 16px;
}

.mobile-preview .topbar-actions {
  width: 100%;
  justify-content: flex-start;
}

.mobile-preview .file-button {
  flex: 1 1 170px;
}

.mobile-preview .measurement-surface {
  grid-template-columns: 1fr;
}

.mobile-preview .tool-panel {
  border-left: 0;
  border-top: 1px solid var(--line);
}

.mobile-preview #sheetCanvas {
  min-height: 66vh;
}

.project-rail {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  color: white;
  background: var(--navy);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark strong,
.brand-mark span {
  display: block;
}

.brand-mark span {
  margin-top: 2px;
  color: #b9c8d7;
  font-size: 12px;
}

.rail-collapse {
  margin-left: auto;
  width: 30px;
  height: 30px;
  color: white;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
}

.app-shell.is-rail-collapsed .project-rail {
  padding: 16px 12px;
  align-items: center;
}

.app-shell.is-rail-collapsed .brand-mark {
  flex-direction: column;
  gap: 10px;
}

.app-shell.is-rail-collapsed .brand-mark div,
.app-shell.is-rail-collapsed .primary-action,
.app-shell.is-rail-collapsed .project-list {
  display: none;
}

.app-shell.is-rail-collapsed .rail-collapse {
  margin-left: 0;
  transform: rotate(180deg);
}

.brand-icon {
  position: relative;
  width: 38px;
  height: 38px;
  border: 2px solid #ffffff;
  border-radius: 8px;
}

.brand-icon::before,
.brand-icon::after {
  position: absolute;
  content: "";
  background: var(--orange);
}

.brand-icon::before {
  left: 8px;
  bottom: 8px;
  width: 18px;
  height: 3px;
  transform: rotate(-35deg);
  transform-origin: left center;
}

.brand-icon::after {
  left: 6px;
  bottom: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.project-list {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.project-item {
  width: 100%;
  padding: 12px;
  color: white;
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.project-item.is-active {
  background: rgba(249, 115, 22, 0.2);
  border-color: var(--orange);
}

.project-item strong,
.project-item span {
  display: block;
}

.project-item span {
  margin-top: 4px;
  color: #b9c8d7;
  font-size: 12px;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 78px;
  padding: 16px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  color: #0f5132;
  background: #dcfce7;
  border: 1px solid #86efac;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.is-offline {
  color: #7c2d12;
  background: #ffedd5;
  border-color: #fdba74;
}

.upload-status {
  padding: 10px 22px;
  color: #10243f;
  background: #dbeafe;
  border-bottom: 1px solid #bfdbfe;
  font-size: 13px;
  font-weight: 800;
}

.upload-status.is-error {
  color: #7f1d1d;
  background: #fee2e2;
  border-bottom-color: #fecaca;
}

.upload-status.is-success {
  color: #14532d;
  background: #dcfce7;
  border-bottom-color: #bbf7d0;
}

.canvas-controls {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 30;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 36, 63, 0.14);
  backdrop-filter: blur(8px);
}

.toolbar-label {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.canvas-controls .ghost-action {
  min-height: 34px;
  padding: 0 11px;
  background: white;
  white-space: nowrap;
}

.canvas-controls #zoomOutButton,
.canvas-controls #zoomInButton {
  min-width: 66px;
  padding: 0 10px;
  font-size: 13px;
}

.trace-controls {
  position: absolute;
  left: 16px;
  bottom: 64px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 36, 63, 0.14);
  backdrop-filter: blur(8px);
}

.trace-undo-action {
  color: var(--orange);
  border-color: rgba(249, 115, 22, 0.42);
}

.trace-undo-action:not(:disabled) {
  background: #fff7ed;
}

.trace-save-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  color: white;
  background: var(--orange);
  border: 1px solid var(--orange);
  border-radius: 8px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-action,
.secondary-action,
.ghost-action,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-action {
  color: white;
  background: var(--orange);
}

.secondary-action {
  color: white;
  background: var(--blue);
}

.ghost-action {
  color: var(--ink);
  background: white;
  border-color: var(--line);
}

.file-button {
  color: white;
  background: var(--blue);
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.measurement-surface {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 400px);
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(37, 99, 235, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.08) 1px, transparent 1px),
    #fdfefe;
  background-size: 34px 34px;
}

#sheetCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  cursor: url("../assets/crosshair.svg") 32 32, crosshair;
}

#sheetCanvas.is-trace-mode {
  cursor: url("../assets/crosshair.svg") 32 32, crosshair;
}

#sheetCanvas.is-dragging {
  cursor: grabbing;
}

.app-shell.is-trace-active .canvas-wrap {
  box-shadow: inset 0 0 0 2px rgba(249, 115, 22, 0.72);
}

.canvas-hint {
  position: absolute;
  left: 16px;
  bottom: 16px;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 14px;
  color: white;
  background: rgba(16, 36, 63, 0.88);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.empty-sheet-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background:
    linear-gradient(rgba(37, 99, 235, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.08) 1px, transparent 1px),
    #fbfdff;
  background-size: 34px 34px;
}

.empty-sheet-state[hidden] {
  display: none;
}

.onboarding-card {
  width: min(620px, 100%);
  padding: 24px;
  text-align: left;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(16, 36, 63, 0.14);
  backdrop-filter: blur(8px);
}

.onboarding-card h2 {
  max-width: 520px;
  color: var(--ink);
  font-size: 27px;
  line-height: 1.1;
  text-transform: none;
}

.onboarding-steps {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding: 0;
  list-style: none;
  counter-reset: onboarding;
}

.onboarding-steps li {
  position: relative;
  display: grid;
  gap: 3px;
  min-height: 56px;
  padding: 10px 12px 10px 48px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  counter-increment: onboarding;
}

.onboarding-steps li::before {
  position: absolute;
  top: 13px;
  left: 12px;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  color: white;
  background: var(--blue);
  border-radius: 50%;
  content: counter(onboarding);
  font-size: 12px;
  font-weight: 900;
}

.onboarding-steps strong {
  font-size: 14px;
}

.onboarding-steps span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.onboarding-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.onboarding-actions .file-button,
.onboarding-actions .ghost-action {
  min-width: 170px;
}

.onboarding-checklist {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
}

.onboarding-checklist[hidden] {
  display: none;
}

.onboarding-checklist h2 {
  color: #9a3412;
}

.onboarding-checklist-items {
  display: grid;
  gap: 6px;
}

.onboarding-checklist-items span {
  position: relative;
  min-height: 30px;
  padding: 7px 9px 7px 30px;
  color: #7c2d12;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(251, 146, 60, 0.32);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
}

.onboarding-checklist-items span::before {
  position: absolute;
  top: 8px;
  left: 9px;
  width: 13px;
  height: 13px;
  border: 2px solid #fb923c;
  border-radius: 50%;
  content: "";
}

.onboarding-checklist-items span.is-current {
  background: white;
  box-shadow: inset 3px 0 0 var(--orange);
}

.onboarding-checklist-items span.is-complete {
  color: #166534;
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.onboarding-checklist-items span.is-complete::before {
  background: #22c55e;
  border-color: #22c55e;
  box-shadow: inset 0 0 0 3px #f0fdf4;
}

.tool-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow: auto;
}

.tool-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.tool-button {
  min-height: 44px;
  color: var(--ink);
  background: #eef3f9;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}

.tool-button.is-active {
  color: white;
  background: var(--orange);
  border-color: var(--orange);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.sheet-panel,
.view-panel,
.measurement-editor,
.measurement-list-wrap {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.view-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.view-actions .ghost-action {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.trace-save-tip {
  margin: -2px 0 0;
  color: #9a3412;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.calibration-control {
  margin-bottom: -2px;
}

.sheet-list {
  display: grid;
  gap: 8px;
}

.pdf-page-picker {
  display: grid;
  gap: 6px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pdf-page-picker[hidden] {
  display: none;
}

.pdf-page-picker span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.analysis-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.analysis-toggle {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 12px;
}

.analysis-toggle input {
  width: auto;
  min-height: 0;
  padding: 0;
}

.analysis-results {
  display: grid;
  gap: 8px;
}

.analysis-summary {
  display: grid;
  gap: 2px;
  font-size: 12px;
}

.analysis-summary span,
.analysis-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.dimension-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.dimension-candidate {
  min-height: 30px;
  padding: 0 9px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.sheet-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 6px;
  align-items: stretch;
}

.sheet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  text-align: left;
  color: var(--ink);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sheet-delete {
  color: var(--danger);
  background: #fff7f7;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-weight: 900;
}

.sheet-item.is-active {
  border-color: var(--blue);
  box-shadow: inset 3px 0 0 var(--blue);
}

.sheet-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-badge {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.measurement-list {
  display: grid;
  gap: 8px;
}

.measurement-layer-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toggle-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.toggle-row input {
  width: auto;
  min-height: 0;
  padding: 0;
}

.toggle-row.is-idle {
  color: var(--muted);
}

.measurement-row {
  display: grid;
  gap: 6px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.measurement-row.is-selected {
  border-color: var(--orange);
  box-shadow: inset 3px 0 0 var(--orange);
}

.measurement-row.is-hidden {
  background: #ffffff;
  opacity: 0.72;
}

.measurement-row.is-locked {
  border-style: dashed;
}

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

.measurement-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.measurement-value {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-weight: 800;
}

.measurement-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.category-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hide-button,
.zoom-button,
.edit-button,
.lock-button,
.delete-button {
  min-height: 28px;
  padding: 0 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 900;
}

.hide-button,
.zoom-button,
.edit-button,
.lock-button {
  color: var(--ink);
}

.hide-button[aria-pressed="true"],
.lock-button[aria-pressed="true"] {
  color: var(--blue);
  background: #eff6ff;
  border-color: #bfdbfe;
}

.delete-button {
  color: var(--danger);
  border-color: #fecaca;
}

.measurement-state {
  flex: 0 0 auto;
  padding: 2px 6px;
  color: var(--muted);
  background: #eef3f9;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

@media (max-width: 1280px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .measurement-surface {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
  }

  .project-rail {
    padding: 18px;
  }

  .topbar {
    padding: 14px 18px;
  }

  .tool-panel {
    padding: 14px;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .project-rail {
    gap: 14px;
    padding: 16px;
  }

  .brand-mark {
    align-items: flex-start;
  }

  .brand-mark span {
    display: none;
  }

  .project-item {
    padding: 10px;
  }

  .project-item span {
    display: none;
  }

  .topbar {
    align-items: flex-start;
    min-height: auto;
  }

  .topbar h1 {
    font-size: 21px;
    line-height: 1.18;
  }

  .measurement-surface {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(480px, 1fr) auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .canvas-wrap {
    min-height: 480px;
  }

  #sheetCanvas {
    min-height: 480px;
  }

  .tool-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-content: start;
    gap: 12px;
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }

  .measurement-list-wrap {
    grid-column: 1 / -1;
  }

  .onboarding-checklist {
    grid-column: 1 / -1;
  }

  .sheet-panel,
  .view-panel,
  .measurement-editor,
  .measurement-list-wrap {
    align-self: start;
  }

  .view-actions {
    grid-template-columns: 1fr;
  }

  .canvas-controls .toolbar-label,
  .trace-controls .toolbar-label {
    display: none;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .project-rail {
    gap: 10px;
    min-height: auto;
    padding: 12px 14px;
  }

  .brand-mark {
    min-height: 38px;
  }

  .brand-icon {
    width: 32px;
    height: 32px;
  }

  .brand-mark span {
    display: none;
  }

  .rail-collapse {
    display: none;
  }

  .project-rail .primary-action,
  .project-list {
    display: none;
  }

  .workspace {
    min-height: 0;
  }

  .topbar {
    align-items: flex-start;
    gap: 10px;
    min-height: auto;
    padding: 12px 14px;
  }

  .topbar h1 {
    font-size: 19px;
    line-height: 1.15;
  }

  .topbar-actions {
    flex: 0 0 auto;
    gap: 8px;
  }

  .status-pill {
    min-height: 34px;
    padding: 0 9px;
    white-space: nowrap;
  }

  .upload-status {
    padding: 9px 14px;
  }

  .measurement-surface {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 58dvh) auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tool-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 12px;
    padding: 12px;
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }

  .measurement-list-wrap {
    grid-column: 1 / -1;
  }

  .onboarding-card {
    width: min(620px, calc(100% - 28px));
    padding: 18px;
  }

  .onboarding-card h2 {
    font-size: 23px;
  }

  .onboarding-steps {
    gap: 8px;
    margin: 14px 0;
  }

  .onboarding-steps li {
    min-height: 50px;
    padding: 9px 10px 9px 44px;
  }

  .onboarding-checklist {
    grid-column: 1 / -1;
  }

  .sheet-panel,
  .view-panel,
  .measurement-editor,
  .measurement-list-wrap {
    align-self: start;
    padding-top: 10px;
  }

  .canvas-wrap {
    min-height: 420px;
  }

  #sheetCanvas {
    min-height: 420px;
  }

  .canvas-hint {
    left: 12px;
    bottom: 12px;
    max-width: calc(100% - 24px);
    padding: 8px 10px;
    font-size: 12px;
  }

  .canvas-controls,
  .trace-controls {
    box-shadow: 0 6px 18px rgba(16, 36, 63, 0.16);
  }

  .toolbar-label {
    display: none;
  }

  .primary-action,
  .secondary-action,
  .ghost-action,
  .file-button,
  .trace-save-action,
  input,
  select {
    min-height: 44px;
  }
}

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

  .topbar-actions {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    width: 100%;
  }

  .file-button {
    width: 100%;
  }

  .measurement-surface {
    grid-template-rows: minmax(440px, 62dvh) auto;
  }

  .canvas-wrap,
  #sheetCanvas {
    min-height: 440px;
  }

  .canvas-controls {
    top: 10px;
    left: 10px;
    right: 10px;
    justify-content: center;
    display: grid;
    grid-template-columns: 1fr 52px 52px;
  }

  .canvas-controls .ghost-action {
    min-width: 0;
    padding: 0 8px;
    font-size: 12px;
  }

  .trace-controls {
    left: 10px;
    right: 10px;
    bottom: 54px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    padding: 5px;
  }

  .trace-controls .ghost-action,
  .trace-save-action {
    min-height: 40px;
    min-width: 0;
    padding: 0 8px;
    font-size: 12px;
  }

  .canvas-hint {
    bottom: 10px;
    padding: 7px 9px;
    font-size: 11px;
  }

  .tool-panel {
    grid-template-columns: 1fr;
  }

  .onboarding-card {
    padding: 14px;
  }

  .onboarding-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .onboarding-actions .file-button,
  .onboarding-actions .ghost-action {
    width: 100%;
  }

  .view-actions {
    grid-template-columns: 1fr 1fr;
  }

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

  .measurement-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    justify-content: stretch;
  }

  .hide-button,
  .zoom-button,
  .edit-button,
  .lock-button,
  .delete-button {
    min-height: 36px;
    padding: 0 6px;
  }
}
