:root {
  --hwe-green: #174f38;
  --hwe-green-dark: #103b2a;
  --hwe-gold: #c8a34b;
  --hwe-cream: #f7f4ec;
  --hwe-ink: #17211c;
  --hwe-muted: #64716a;
  --hwe-border: #d9e0db;
  --hwe-danger: #9f2d2d;
  --hwe-warning: #7b5b13;
}

.jsm-hwe,
.jsm-hwe * {
  box-sizing: border-box;
}

.jsm-hwe {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  color: var(--hwe-ink);
  font-family: inherit;
}

.jsm-hwe button,
.jsm-hwe input,
.jsm-hwe select {
  font: inherit;
}

.hwe-shell {
  overflow: hidden;
  border: 1px solid var(--hwe-border);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 16px 45px rgba(20, 48, 35, 0.09);
}

.hwe-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--hwe-border);
  background: linear-gradient(135deg, var(--hwe-green-dark), var(--hwe-green));
  color: #fff;
}

.hwe-logo {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  padding: 5px;
}

.hwe-logo-fallback {
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--hwe-green);
}

.hwe-header-copy {
  min-width: 0;
}

.hwe-brand {
  margin: 0 0 2px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.82;
}

.hwe-title {
  margin: 0;
  color: inherit;
  font-size: clamp(1.25rem, 4vw, 1.8rem);
  line-height: 1.15;
}

.hwe-progress {
  height: 7px;
  background: #e9eee9;
}

.hwe-progress > span {
  display: block;
  height: 100%;
  width: var(--hwe-progress, 0%);
  background: var(--hwe-gold);
  transition: width 0.25s ease;
}

.hwe-body {
  padding: clamp(18px, 4vw, 30px);
}

.hwe-heading {
  margin: 0 0 8px;
  color: var(--hwe-green-dark);
  font-size: clamp(1.25rem, 4vw, 1.75rem);
}

.hwe-lead {
  margin: 0 0 20px;
  color: var(--hwe-muted);
  font-size: 1rem;
  line-height: 1.55;
}

.hwe-grid {
  display: grid;
  gap: 16px;
}

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

.hwe-card {
  border: 1px solid var(--hwe-border);
  border-radius: 18px;
  background: #fff;
  padding: 18px;
}

.hwe-card-soft {
  background: var(--hwe-cream);
}

.hwe-step-list {
  display: grid;
  gap: 12px;
  margin: 20px 0;
}

.hwe-step-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
}

.hwe-step-number {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--hwe-green);
  color: #fff;
  font-weight: 800;
}

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

.hwe-field label,
.hwe-field .hwe-label {
  font-weight: 700;
}

.hwe-input,
.hwe-select {
  width: 100%;
  min-height: 48px;
  border: 1px solid #bdc8c0;
  border-radius: 12px;
  background: #fff;
  color: var(--hwe-ink);
  padding: 10px 12px;
}

.hwe-input:focus,
.hwe-select:focus,
.hwe-range:focus,
.hwe-btn:focus-visible {
  outline: 3px solid rgba(200, 163, 75, 0.45);
  outline-offset: 2px;
}

.hwe-height-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hwe-segmented {
  display: flex;
  padding: 4px;
  border: 1px solid var(--hwe-border);
  border-radius: 13px;
  background: #f3f6f3;
}

.hwe-segmented button {
  flex: 1;
  border: 0;
  border-radius: 9px;
  background: transparent;
  padding: 9px 12px;
  color: var(--hwe-ink);
}

.hwe-segmented button.is-active {
  background: var(--hwe-green);
  color: #fff;
  font-weight: 700;
}

.hwe-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 16px;
  line-height: 1.45;
}

.hwe-check input {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  accent-color: var(--hwe-green);
}

.hwe-callout {
  border-left: 5px solid var(--hwe-gold);
  border-radius: 10px;
  background: #fff9e9;
  padding: 14px 16px;
  color: #574719;
  line-height: 1.5;
}

.hwe-callout-danger {
  border-left-color: var(--hwe-danger);
  background: #fff2f2;
  color: #6e2424;
}

.hwe-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
}

.hwe-actions-end {
  justify-content: flex-end;
}

.hwe-btn {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 750;
  line-height: 1.2;
}

.hwe-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.hwe-btn-primary {
  background: var(--hwe-green);
  color: #fff;
}

.hwe-btn-primary:hover:not(:disabled) {
  background: var(--hwe-green-dark);
}

.hwe-btn-secondary {
  border-color: var(--hwe-border);
  background: #fff;
  color: var(--hwe-ink);
}

.hwe-btn-danger {
  border-color: #e7c6c6;
  background: #fff5f5;
  color: var(--hwe-danger);
}

.hwe-btn-link {
  border: 0;
  background: transparent;
  color: var(--hwe-green);
  text-decoration: underline;
}

.hwe-install-panel {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  border: 1px dashed #b9c7bd;
  border-radius: 14px;
  background: #f8fbf8;
  padding: 14px;
}

.hwe-camera-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-height: 76vh;
  border-radius: 18px;
  background: #111;
}


.hwe-camera-wrap[data-stage="side"] {
  aspect-ratio: 4 / 3;
}

.hwe-camera-wrap[data-stage="front"] {
  aspect-ratio: 3 / 4;
}

.hwe-video,
.hwe-capture-canvas,
.hwe-review-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hwe-video {
  position: absolute;
  inset: 0;
}

.hwe-camera-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.24), transparent 20%, transparent 74%, rgba(0,0,0,0.35));
  pointer-events: none;
}

.hwe-guide {
  position: absolute;
  inset: 8% 5% 10%;
  pointer-events: none;
  color: rgba(255, 255, 255, 0.93);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
}

.hwe-guide svg {
  width: 100%;
  height: 100%;
}

.hwe-guide .guide-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 5;
  stroke-dasharray: 14 12;
}

.hwe-guide .guide-fill {
  fill: rgba(255,255,255,0.06);
}

.hwe-camera-top,
.hwe-camera-bottom {
  position: absolute;
  z-index: 3;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hwe-camera-top {
  top: 12px;
}

.hwe-camera-bottom {
  bottom: 12px;
  flex-direction: column;
}

.hwe-chip {
  border-radius: 999px;
  background: rgba(0,0,0,0.66);
  color: #fff;
  padding: 7px 11px;
  font-size: 0.88rem;
  backdrop-filter: blur(5px);
}

.hwe-chip-good {
  background: rgba(23,79,56,0.86);
}

.hwe-chip-warn {
  background: rgba(123,91,19,0.9);
}

.hwe-chip-bad {
  background: rgba(159,45,45,0.9);
}

.hwe-scan-status {
  width: 100%;
  border-radius: 12px;
  background: rgba(0,0,0,0.68);
  color: #fff;
  padding: 10px 12px;
  text-align: center;
  line-height: 1.35;
}

.hwe-hold-bar {
  overflow: hidden;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.3);
}

.hwe-hold-bar > span {
  display: block;
  height: 100%;
  width: var(--hold, 0%);
  border-radius: inherit;
  background: var(--hwe-gold);
  transition: width 0.12s linear;
}

.hwe-camera-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.hwe-capture-button {
  width: 70px;
  height: 70px;
  border: 6px solid #fff;
  border-radius: 50%;
  background: var(--hwe-gold);
  box-shadow: 0 0 0 2px var(--hwe-green), 0 5px 16px rgba(0,0,0,0.2);
}

.hwe-scan-help {
  display: grid;
  gap: 9px;
  margin: 14px 0 0;
  color: var(--hwe-muted);
}

.hwe-review-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.hwe-review-stage {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  background: #121212;
}

.hwe-review-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.hwe-review-controls {
  display: grid;
  gap: 12px;
}

.hwe-range-row {
  display: grid;
  gap: 6px;
}

.hwe-range-row label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 650;
}

.hwe-range {
  width: 100%;
  accent-color: var(--hwe-green);
}

.hwe-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.hwe-tabs button {
  flex: 1;
}

.hwe-metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 10px;
  margin: 20px 0;
}

.hwe-metric {
  border: 1px solid var(--hwe-border);
  border-radius: 14px;
  background: #fff;
  padding: 14px;
  text-align: center;
}

.hwe-metric span {
  display: block;
  color: var(--hwe-muted);
  font-size: 0.84rem;
}

.hwe-metric strong {
  display: block;
  margin-top: 4px;
  color: var(--hwe-green-dark);
  font-size: 1.15rem;
}

.hwe-result {
  text-align: center;
}

.hwe-result-number {
  display: inline-grid;
  place-items: center;
  width: 190px;
  height: 190px;
  margin: 12px auto;
  border: 10px solid #e8efe9;
  border-top-color: var(--hwe-green);
  border-right-color: var(--hwe-gold);
  border-radius: 50%;
}

.hwe-result-number strong {
  display: block;
  color: var(--hwe-green-dark);
  font-size: 3rem;
  line-height: 1;
}

.hwe-result-number span {
  color: var(--hwe-muted);
}

.hwe-range-result {
  margin: 4px 0 10px;
  font-size: 1.12rem;
}

.hwe-confidence {
  display: inline-block;
  border-radius: 999px;
  background: #e8f1ea;
  color: var(--hwe-green-dark);
  padding: 7px 12px;
  font-weight: 750;
}

.hwe-history {
  margin-top: 22px;
  text-align: left;
}

.hwe-history-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--hwe-border);
}

.hwe-history-row:last-child {
  border-bottom: 0;
}

.hwe-small {
  color: var(--hwe-muted);
  font-size: 0.88rem;
}

.hwe-error {
  min-height: 1.35em;
  margin: 10px 0 0;
  color: var(--hwe-danger);
  font-weight: 650;
}

.hwe-hidden {
  display: none !important;
}

@media (max-width: 720px) {
  .hwe-shell {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

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

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

  .hwe-camera-wrap[data-stage="front"] {
    aspect-ratio: 3 / 4;
  }
}

@media (max-width: 430px) {
  .hwe-body {
    padding: 16px;
  }

  .hwe-header {
    padding: 14px 16px;
  }

  .hwe-logo {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .hwe-height-row {
    grid-template-columns: 1fr;
  }

  .hwe-actions .hwe-btn {
    flex: 1 1 auto;
  }

  .hwe-camera-top {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media print {
  .hwe-header,
  .hwe-progress,
  .hwe-actions,
  .hwe-install-panel,
  .hwe-btn,
  .hwe-history {
    display: none !important;
  }

  .hwe-shell {
    border: 0;
    box-shadow: none;
  }
}
