:root {
  --navy-950: #102a43;
  --navy-900: #163a5f;
  --navy-700: #2f5f8f;
  --blue-100: #eaf3fb;
  --slate-900: #1f2933;
  --slate-700: #52606d;
  --slate-500: #7b8794;
  --slate-300: #cbd2d9;
  --slate-200: #e4e7eb;
  --slate-100: #f5f7fa;
  --white: #ffffff;
  --green-700: #147d64;
  --green-100: #e3f9f2;
  --amber-700: #9a6700;
  --amber-100: #fff3c4;
  --red-700: #b42318;
  --shadow: 0 14px 34px rgba(16, 42, 67, 0.12);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--slate-100);
  color: var(--slate-900);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px max(20px, calc((100vw - 1180px) / 2));
  background: linear-gradient(135deg, var(--navy-950), var(--navy-700));
  color: var(--white);
}

.app-header h1 {
  margin: 2px 0 8px;
  font-size: clamp(1.65rem, 4vw, 2.65rem);
  line-height: 1.08;
}

.header-copy {
  max-width: 740px;
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
}

.app-shell {
  display: grid;
  gap: 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 22px auto 46px;
}

.card,
.mode-tabs,
dialog {
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow);
}

.card {
  padding: clamp(18px, 3vw, 28px);
}

.section-heading,
.action-row,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.section-heading h2,
.dialog-header h2 {
  margin: 0;
  font-size: clamp(1.15rem, 2.2vw, 1.55rem);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--navy-700);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-header .eyebrow {
  color: rgba(255, 255, 255, 0.72);
}

.badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.badge {
  background: var(--blue-100);
  color: var(--navy-700);
}

.status-pill.neutral {
  background: var(--slate-100);
  color: var(--slate-700);
}

.status-pill.success {
  background: var(--green-100);
  color: var(--green-700);
}

.status-pill.warning {
  background: var(--amber-100);
  color: var(--amber-700);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.compact-grid {
  max-width: 760px;
}

label {
  display: grid;
  gap: 6px;
}

label span,
.result-detail span,
.primary-result span {
  color: var(--slate-700);
  font-size: 0.82rem;
  font-weight: 800;
}

small {
  color: var(--slate-500);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--slate-900);
  padding: 11px 12px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--navy-700);
  box-shadow: 0 0 0 4px rgba(47, 95, 143, 0.14);
}

textarea {
  resize: vertical;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
}

.tab-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-right: 1px solid var(--slate-200);
  background: var(--white);
  color: var(--slate-700);
  padding: 14px 10px;
  font-weight: 800;
}

.tab-button:last-child {
  border-right: 0;
}

.tab-button.active {
  background: var(--navy-950);
  color: var(--white);
}

.tab-number {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  font-size: 0.74rem;
}

.mode-panel {
  display: none;
}

.mode-panel.active {
  display: block;
}

.helper-text {
  margin: 12px 0 0;
  color: var(--slate-700);
}

.action-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 18px;
}

.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.icon-button {
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 800;
  transition: transform 160ms ease, opacity 160ms ease, background 160ms ease;
}

.primary-button {
  border: 1px solid var(--navy-950);
  background: var(--navy-950);
  color: var(--white);
}

.secondary-button {
  border: 1px solid var(--navy-700);
  background: var(--white);
  color: var(--navy-700);
}

.ghost-button {
  align-self: flex-start;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.08);
  color: var(--white);
}

.text-button,
.icon-button {
  border: 0;
  background: transparent;
  color: var(--navy-700);
}

.icon-button {
  padding: 0 8px;
  color: var(--slate-700);
  font-size: 2rem;
  line-height: 1;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

.camera-frame {
  position: relative;
  display: grid;
  min-height: 320px;
  margin-top: 18px;
  overflow: hidden;
  place-items: center;
  border-radius: var(--radius-md);
  background: #071a2d;
}

.camera-frame.hidden-camera {
  min-height: 104px;
}

.camera-frame.hidden-camera video,
.camera-frame.hidden-camera .crosshair {
  display: none;
}

video {
  width: 100%;
  max-height: 520px;
  object-fit: cover;
}

.camera-placeholder {
  position: absolute;
  display: grid;
  max-width: 300px;
  gap: 5px;
  color: rgba(255, 255, 255, 0.8);
  padding: 16px;
  text-align: center;
}

.camera-placeholder.hidden {
  display: none;
}

.crosshair {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crosshair-horizontal,
.crosshair-vertical,
.crosshair-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  background: rgba(255, 255, 255, 0.86);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.52);
}

.crosshair-horizontal {
  width: 86px;
  height: 2px;
}

.crosshair-vertical {
  width: 2px;
  height: 86px;
}

.crosshair-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.live-angle {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 2px;
  border-radius: 10px;
  background: rgba(7, 26, 45, 0.78);
  color: var(--white);
  padding: 9px 12px;
  text-align: right;
}

.live-angle span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.live-angle strong {
  font-size: 1.4rem;
}

.capture-grid,
.formula-grid,
.result-grid {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.capture-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.capture-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 16px;
}

.capture-card h3,
.formula-grid h3 {
  margin: 0;
  font-size: 1rem;
}

.capture-card p:not(.eyebrow) {
  margin: 5px 0 0;
  color: var(--slate-700);
  font-size: 0.9rem;
}

.captured-value {
  color: var(--navy-700);
  font-size: 1.3rem;
  font-weight: 900;
}

.callout {
  margin-top: 16px;
  border-left: 4px solid var(--amber-700);
  border-radius: 8px;
  background: var(--amber-100);
  color: #5c4200;
  padding: 12px 14px;
  font-size: 0.9rem;
}

.photo-reference-layout {
  display: grid;
  grid-template-columns: 1fr minmax(180px, 300px);
  gap: 16px;
  margin-top: 18px;
}

.upload-box {
  display: grid;
  min-height: 154px;
  place-content: center;
  border: 2px dashed var(--slate-300);
  border-radius: var(--radius-md);
  padding: 18px;
  text-align: center;
}

.upload-title {
  color: var(--navy-700);
  font-size: 1rem;
}

.upload-subtitle {
  margin-bottom: 10px;
  color: var(--slate-500);
  font-size: 0.84rem;
}

.reference-preview {
  width: 100%;
  max-height: 240px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.hidden {
  display: none !important;
}

.result-card {
  border-top: 5px solid var(--navy-700);
}

.result-grid {
  grid-template-columns: minmax(0, 1.5fr) repeat(2, minmax(0, 1fr));
}

.primary-result,
.result-detail {
  display: grid;
  align-content: start;
  gap: 6px;
  border-radius: var(--radius-md);
  background: var(--slate-100);
  padding: 16px;
}

.primary-result strong {
  color: var(--navy-950);
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1;
}

.result-detail strong {
  color: var(--navy-950);
}

.notes-field {
  margin-top: 18px;
}

.photo-status {
  margin: 10px 0 0;
  color: var(--slate-500);
  font-size: 0.84rem;
}

.formula-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.formula-grid article {
  border-radius: var(--radius-md);
  background: var(--blue-100);
  padding: 15px;
}

code {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  color: var(--navy-950);
}

dialog {
  width: min(900px, calc(100% - 24px));
  max-height: min(760px, calc(100vh - 30px));
  padding: 20px;
}

dialog::backdrop {
  background: rgba(16, 42, 67, 0.56);
}

.saved-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.saved-record {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 14px;
}

.saved-record h3 {
  margin: 0;
  color: var(--navy-950);
  font-size: 1rem;
}

.saved-record p {
  margin: 4px 0 0;
  color: var(--slate-700);
  font-size: 0.85rem;
}

.danger-text {
  color: var(--red-700);
}

.empty-state {
  border: 1px dashed var(--slate-300);
  border-radius: var(--radius-md);
  color: var(--slate-700);
  padding: 22px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100% - 36px));
  border-radius: 10px;
  background: var(--navy-950);
  color: var(--white);
  padding: 11px 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

@media (max-width: 760px) {
  .app-header,
  .section-heading,
  .dialog-header {
    align-items: flex-start;
  }

  .app-header {
    display: grid;
    padding: 22px 18px;
  }

  .ghost-button {
    justify-self: start;
  }

  .app-shell {
    width: min(100% - 20px, 1180px);
    margin-top: 12px;
  }

  .card {
    padding: 16px;
    border-radius: 17px;
  }

  .mode-tabs {
    border-radius: 16px;
  }

  .tab-button {
    display: grid;
    gap: 4px;
    padding: 10px 4px;
    font-size: 0.74rem;
  }

  .tab-number {
    margin: auto;
  }

  .form-grid,
  .capture-grid,
  .formula-grid,
  .result-grid,
  .photo-reference-layout {
    grid-template-columns: 1fr;
  }

  .camera-frame {
    min-height: 255px;
  }

  .action-row button {
    flex: 1 1 auto;
  }

  .saved-record {
    grid-template-columns: 1fr;
  }
}


/* Mobile wizard additions. The original prototype CSS above is retained. */
.mobile-shell {
  width: min(760px, calc(100% - 20px));
}

.wizard-screen {
  display: none;
}

.wizard-screen.active {
  display: block;
}

.wizard-progress {
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow);
  padding: 13px 14px 11px;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--slate-200);
}

.progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--green-700);
  transition: width 180ms ease;
}

.progress-steps {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin: 11px 0 0;
  padding: 0;
  list-style: none;
}

.progress-steps li {
  display: grid;
  justify-items: center;
  gap: 3px;
  color: var(--slate-500);
  font-size: 0.68rem;
  font-weight: 800;
  text-align: center;
}

.progress-number {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  background: var(--slate-200);
  color: var(--slate-700);
  font-size: 0.72rem;
}

.progress-steps li.complete,
.progress-steps li.active {
  color: var(--navy-950);
}

.progress-steps li.complete .progress-number {
  background: var(--green-700);
  color: var(--white);
}

.progress-steps li.active .progress-number {
  background: var(--navy-950);
  color: var(--white);
}

.wizard-nav {
  justify-content: space-between;
}

.text-link {
  display: inline-flex;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--navy-700);
  padding: 10px 0;
  font-weight: 800;
  text-decoration: none;
}

.measurement-summary {
  display: grid;
  gap: 4px;
  margin-top: 16px;
  border-radius: var(--radius-md);
  background: var(--blue-100);
  padding: 14px;
}

.measurement-summary span {
  color: var(--slate-700);
  font-size: 0.8rem;
  font-weight: 800;
}

.measurement-summary strong {
  color: var(--navy-950);
  font-size: 1.25rem;
}

.measurement-summary small {
  color: var(--slate-700);
}

.focus-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58px;
  height: 58px;
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(16, 42, 67, 0.55), 0 0 10px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  transition: top 160ms ease, left 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.focus-ring.pulse {
  transform: translate(-50%, -50%) scale(0.74);
  opacity: 0.78;
}

.focus-note {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: 150px;
  border-radius: 9px;
  background: rgba(7, 26, 45, 0.78);
  color: rgba(255, 255, 255, 0.84);
  padding: 7px 9px;
  font-size: 0.68rem;
  font-weight: 800;
}

.camera-error {
  margin-top: 12px;
  border-left: 4px solid var(--red-700);
  border-radius: 8px;
  background: #fff1f0;
  color: var(--red-700);
  padding: 11px 13px;
  font-size: 0.86rem;
}

.manual-fallback {
  margin-top: 16px;
  border-top: 1px solid var(--slate-200);
  padding-top: 14px;
}

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

.review-grid article {
  display: grid;
  gap: 5px;
  border-radius: var(--radius-md);
  background: var(--slate-100);
  padding: 14px;
}

.review-grid span {
  color: var(--slate-700);
  font-size: 0.78rem;
  font-weight: 800;
}

.review-grid strong {
  color: var(--navy-950);
  font-size: 0.95rem;
}

.primary-result.mobile-result {
  margin-top: 18px;
  background: var(--blue-100);
}

.mobile-result strong {
  font-size: clamp(2.6rem, 8vw, 4.2rem);
}

.saved-drawer {
  display: none;
}

.saved-drawer.open {
  display: block;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.storage-note {
  margin-top: 12px;
  color: var(--slate-500);
  font-size: 0.82rem;
}

@media (max-width: 760px) {
  .mobile-shell {
    width: min(100% - 20px, 760px);
  }

  .progress-steps li {
    font-size: 0.6rem;
  }

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

  .focus-note {
    max-width: 128px;
    font-size: 0.62rem;
  }
}
