:root {
  --bg: #e9ecef;
  --bg-grid: rgba(18, 31, 43, 0.08);
  --surface: #ffffff;
  --surface-2: #f5f7f8;
  --ink: #17212b;
  --muted: #64717d;
  --line: #cfd6dc;
  --line-strong: #aeb9c2;
  --accent: #cf641f;
  --accent-strong: #9c4316;
  --accent-soft: #fff0e4;
  --teal: #08766f;
  --teal-soft: #e4f5f2;
  --danger: #b42318;
  --success: #0f6b3f;
  --shadow: 0 18px 48px rgba(22, 31, 40, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "IBM Plex Sans", "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    linear-gradient(145deg, #eef1f3 0%, #dfe5e8 48%, #edf0f1 100%);
  background-size: 28px 28px, 28px 28px, auto;
}

button,
input {
  font: inherit;
}

#app {
  width: min(1380px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 44px;
}

.topbar {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 58px;
  padding-top: 44px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(16, 28, 39, 0.1);
  flex: 0 0 auto;
}

.brand-mark span {
  width: 18px;
  height: 18px;
  border: 4px solid var(--teal);
  border-left-color: var(--accent);
  border-radius: 50%;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2.1vw, 1.55rem);
  line-height: 1.16;
}

.brand-kicker {
  margin: 0 0 4px;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions,
.command-actions,
.tour-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ghost-btn,
.primary-anchor,
.secondary-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  font-size: 0.92rem;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
  white-space: nowrap;
}

.gallery-link {
  position: absolute;
  top: 16px;
  left: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
}

.gallery-link::before {
  content: "";
  width: 18px;
  height: 10px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-left: 3px;
}

.primary-anchor {
  color: #fff;
  border-color: var(--accent-strong);
  background: var(--accent);
}

.ghost-btn:hover,
.secondary-anchor:hover,
.primary-anchor:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.command-strip {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
  gap: 18px;
  align-items: stretch;
}

.command-copy {
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.badge,
.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.command-copy h2 {
  max-width: 25ch;
  margin: 12px 0 10px;
  font-size: clamp(1.55rem, 3vw, 2.45rem);
  line-height: 1.08;
}

.command-copy p:not(.badge) {
  max-width: 76ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.52;
}

.command-actions {
  margin-top: 18px;
  flex-wrap: wrap;
}

.drawing-preview {
  min-height: 260px;
  border: 1px solid #243241;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    #202b35;
  background-size: 22px 22px, 22px 22px, auto;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.preview-toolbar {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  color: #dce8ed;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.preview-sheet {
  position: relative;
  height: calc(100% - 40px);
  min-height: 220px;
}

.flange-shape {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 132px;
  height: 132px;
  transform: translate(-50%, -50%);
  border: 3px solid #d9f4ef;
  border-radius: 50%;
  box-shadow: inset 0 0 0 32px #202b35, inset 0 0 0 35px rgba(217, 244, 239, 0.92);
}

.flange-shape::before,
.flange-shape::after,
.flange-shape span {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid #d9f4ef;
  border-radius: 50%;
  background: #202b35;
}

.flange-shape::before {
  left: 17px;
  top: 56px;
}

.flange-shape::after {
  right: 17px;
  top: 56px;
}

.flange-shape span:nth-child(1) {
  left: 58px;
  top: 17px;
}

.flange-shape span:nth-child(2) {
  left: 58px;
  bottom: 17px;
}

.flange-shape span:nth-child(3),
.flange-shape span:nth-child(4) {
  display: none;
}

.dimension-line {
  position: absolute;
  color: #d9f4ef;
  border-color: rgba(217, 244, 239, 0.72);
  font-size: 0.78rem;
}

.dimension-x {
  left: 50%;
  top: 78%;
  width: 148px;
  padding-top: 8px;
  border-top: 1px solid;
  text-align: center;
  transform: translateX(-50%);
}

.dimension-y {
  right: 30px;
  top: 30%;
  height: 110px;
  writing-mode: vertical-rl;
  padding-left: 8px;
  border-left: 1px solid;
}

.stamp-block {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 158px;
  padding: 10px;
  border: 1px solid rgba(217, 244, 239, 0.7);
  color: #d9f4ef;
  background: rgba(10, 18, 24, 0.56);
  font-size: 0.78rem;
}

.stamp-block b,
.stamp-block span {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.left-pane {
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel,
.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 28px rgba(17, 28, 38, 0.08);
}

.panel {
  padding: 14px;
}

.panel-title-row,
.status-head,
.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-title-row {
  justify-content: flex-start;
}

.step-index {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-weight: 700;
  font-size: 0.86rem;
}

.panel h3,
.panel h4,
.panel p {
  margin: 0;
}

.panel h3 {
  font-size: 1rem;
}

.panel p {
  color: var(--muted);
  line-height: 1.45;
}

.panel-upload .upload-box {
  margin-top: 12px;
  display: block;
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 14px;
  background: var(--accent-soft);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.panel-upload .upload-box:hover,
.panel-upload .upload-box.drag-over {
  border-color: var(--accent-strong);
  background: #ffe6d3;
  transform: translateY(-1px);
}

.upload-box input {
  display: block;
  width: 100%;
  margin-bottom: 10px;
}

.upload-title,
.upload-subtitle,
.sample-name,
.sample-meta {
  display: block;
}

.upload-title,
.sample-name {
  font-weight: 700;
}

.upload-subtitle,
.sample-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.subtle-text {
  margin-top: 10px !important;
  font-size: 0.88rem;
}

.demo-boundary {
  padding: 8px 10px;
  border-left: 3px solid var(--line-strong);
  background: var(--surface-2);
}

.sample-grid {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.sample-btn {
  min-height: 70px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.sample-btn:hover,
.sample-btn.active {
  border-color: var(--teal);
  background: var(--teal-soft);
  transform: translateY(-1px);
}

.source-name {
  margin-top: 8px !important;
  color: var(--ink) !important;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.signal-list,
.chips,
.results-list,
.result-grid ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.signal-list {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.signal-list li {
  padding: 7px 9px;
  border-left: 3px solid var(--teal);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.84rem;
}

.chips {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  padding: 6px 9px;
  border-radius: 999px;
  border: 1px solid rgba(8, 118, 111, 0.35);
  background: var(--teal-soft);
  font-size: 0.82rem;
  line-height: 1.25;
}

.chip-muted {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--muted);
}

.right-pane {
  min-width: 0;
}

.panel-status {
  border-color: var(--line-strong);
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 0.78rem;
  white-space: nowrap;
}

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

.result-card {
  padding: 14px;
  overflow: hidden;
}

.order-id {
  margin: 0;
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: 700;
}

.result-head h4 {
  margin: 4px 0 6px;
  font-size: clamp(1rem, 1.5vw, 1.14rem);
  line-height: 1.22;
}

.meta-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.87rem;
  overflow-wrap: anywhere;
}

.recommendation-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
}

.recommendation-box h5 {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.recommendation-box p {
  margin: 0;
  color: var(--ink);
  line-height: 1.42;
  font-size: 0.9rem;
}

.score-badge {
  min-width: 76px;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid rgba(207, 100, 31, 0.28);
}

.score-badge b {
  font-size: 1.08rem;
}

.score-badge span {
  font-size: 0.72rem;
}

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

.result-grid section {
  min-height: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.result-grid h5 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 0.9rem;
}

.result-grid p,
.result-grid li {
  margin: 0;
  color: var(--muted);
  line-height: 1.42;
  font-size: 0.86rem;
}

.result-grid ul {
  display: grid;
  gap: 6px;
  list-style: disc;
  padding-left: 18px;
}

.diff-box {
  border-color: rgba(207, 100, 31, 0.42) !important;
  background: var(--accent-soft) !important;
}

.micro {
  margin-top: 8px !important;
  font-size: 0.78rem !important;
}

.result-foot {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.status-error {
  color: var(--danger) !important;
}

.status-success {
  color: var(--success) !important;
}

.result-card-loading {
  display: grid;
  gap: 12px;
}

.loading-line,
.loading-grid span {
  display: block;
  min-height: 13px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e1e6ea 0%, #f5f7f8 48%, #e1e6ea 100%);
  background-size: 200% 100%;
  animation: loading-pulse 1.2s linear infinite;
}

.loading-line {
  width: 54%;
}

.loading-line.wide {
  width: 76%;
}

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

.loading-grid span {
  min-height: 88px;
  border-radius: 8px;
}

.onboarding {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 40;
  pointer-events: none;
}

.onboarding.hidden {
  display: none;
}

.onboarding-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 20, 27, 0.68);
  pointer-events: auto;
}

.onboarding-card {
  position: relative;
  width: min(440px, calc(100vw - 28px));
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: #18222d;
  color: #f6f8fa;
  padding: 18px;
  box-shadow: 0 26px 70px rgba(7, 13, 18, 0.36);
  pointer-events: auto;
}

.tour-progress {
  margin: 0 0 8px;
  color: #ffc08a;
  font-size: 0.82rem;
}

.onboarding-card h3 {
  margin: 0 0 8px;
  font-size: 1.08rem;
}

.onboarding-card p {
  margin: 0;
  color: #cfd8df;
  line-height: 1.45;
}

.tour-actions {
  justify-content: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
}

.tour-actions button {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: #f6f8fa;
  padding: 7px 10px;
  cursor: pointer;
}

.tour-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.tour-highlight {
  position: relative;
  z-index: 42;
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(13, 20, 27, 0.42), 0 0 0 6px rgba(207, 100, 31, 0.22);
  transition: box-shadow 0.22s ease, outline-color 0.22s ease;
}

@keyframes loading-pulse {
  from {
    background-position: 200% 0;
  }

  to {
    background-position: -200% 0;
  }
}

@media (max-width: 1080px) {
  .command-strip,
  .workspace {
    grid-template-columns: 1fr;
  }

  .drawing-preview {
    min-height: 240px;
  }

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

  .source-panel,
  #features-panel {
    grid-column: span 1;
  }
}

@media (max-width: 760px) {
  #app {
    width: min(100vw - 20px, 1380px);
    padding-top: 12px;
  }

  main {
    display: flex;
    flex-direction: column;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .workspace {
    order: 1;
  }

  .command-strip {
    order: 2;
  }

  .right-pane {
    order: -1;
  }

  .topbar-actions,
  .command-actions {
    width: 100%;
  }

  .ghost-btn,
  .primary-anchor,
  .secondary-anchor {
    flex: 1 1 0;
    white-space: normal;
    text-align: center;
  }

  .command-copy {
    padding: 18px;
  }

  .left-pane,
  .result-grid,
  .loading-grid {
    grid-template-columns: 1fr;
  }

  .result-head,
  .status-head {
    align-items: flex-start;
  }

  .score-badge {
    min-width: 68px;
  }
}

@media (max-width: 520px) {
  .brand {
    align-items: flex-start;
  }

  .command-copy h2 {
    font-size: 1.42rem;
  }

  .drawing-preview {
    min-height: 220px;
  }

  .flange-shape {
    width: 108px;
    height: 108px;
    box-shadow: inset 0 0 0 26px #202b35, inset 0 0 0 29px rgba(217, 244, 239, 0.92);
  }

  .dimension-y {
    right: 18px;
  }

  .stamp-block {
    width: 140px;
  }

  .tour-actions {
    justify-content: stretch;
  }

  .tour-actions button {
    flex: 1 1 88px;
  }
}
