:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-warm: #fff7ed;
  --border: #d8e0ea;
  --border-soft: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --cut: #ef4444;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --warn-bg: #fef3c7;
  --warn-border: #facc15;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 12px 30px rgba(15, 23, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    linear-gradient(rgba(15, 23, 42, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.025) 1px, transparent 1px),
    var(--bg);
  background-size: 24px 24px;
  color: var(--text);
}

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

button {
  appearance: none;
  border: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(15, 118, 110, 0.35);
  outline-offset: 2px;
}

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

.srOnly {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 64px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

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

.brandMark {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.brandMark span,
.brandMark::before,
.brandMark::after {
  position: absolute;
  display: block;
  content: "";
  border: 2px solid #ffffff;
  border-radius: 3px;
}

.brandMark span {
  width: 18px;
  height: 14px;
  transform: translateY(2px);
}

.brandMark::before {
  width: 18px;
  height: 6px;
  transform: translateY(-9px) skewX(-18deg);
  border-bottom: 0;
}

.brandMark::after {
  width: 6px;
  height: 14px;
  transform: translate(12px, 2px) skewY(-16deg);
  border-left: 0;
  opacity: 0.86;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.header h1 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 15px;
  line-height: 1.25;
}

.ver {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.headerControls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.langSelect {
  width: auto;
  min-width: 140px;
}

.headerSticky {
  display: none;
  gap: 8px;
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: 344px minmax(520px, 1fr) 328px;
  grid-template-areas: "controls preview export";
  gap: 16px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 16px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.controlsPanel {
  grid-area: controls;
  padding: 14px;
}

.previewPanel {
  grid-area: preview;
  display: flex;
  min-height: calc(100vh - var(--header-h, 64px) - 32px);
  padding: 14px;
  flex-direction: column;
}

.exportPanel {
  grid-area: export;
  display: flex;
  padding: 14px;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 1100px) {
  .controlsPanel,
  .exportPanel {
    max-height: calc(100vh - var(--header-h, 64px) - 32px);
    overflow: auto;
  }
}

.panelHeader,
.previewHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.eyebrow {
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  text-transform: uppercase;
}

.panel h2,
.previewHeader h2 {
  margin-top: 2px;
  font-size: 18px;
  line-height: 1.2;
}

.pill,
.sectionTitle span:last-child,
.detailsBlock > summary span:last-child,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.sectionBlock {
  padding: 12px 0;
  border-top: 1px solid var(--border-soft);
}

.sectionBlock:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.sectionTitle,
.detailsBlock > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.detailsBlock > summary {
  margin-bottom: 0;
  list-style: none;
  cursor: pointer;
}

.detailsBlock[open] > summary {
  margin-bottom: 10px;
}

.detailsBlock > summary::-webkit-details-marker {
  display: none;
}

.row {
  display: flex;
  min-width: 0;
  margin-bottom: 10px;
  flex-direction: column;
  gap: 6px;
}

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

.fieldGrid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.fieldGrid .row {
  margin-bottom: 0;
}

label,
.checklistTitle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.25;
}

label[data-help] {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.infoBtn {
  display: inline-grid;
  width: 17px;
  height: 17px;
  min-width: 17px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}

.infoBtn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}

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

input[type="range"] {
  min-height: 30px;
  padding: 0;
  accent-color: var(--primary);
}

input[type="checkbox"] {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  accent-color: var(--primary);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.checkGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 8px 0 10px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switchTrack {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 160ms ease;
}

.switchTrack::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  content: "";
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.18);
  transition: transform 160ms ease;
}

.switch input:checked + .switchTrack {
  background: var(--primary);
}

.switch input:checked + .switchTrack::after {
  transform: translateX(14px);
}

.toolBtn,
.iconBtn,
.primaryBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 800;
  transition:
    border-color 140ms ease,
    color 140ms ease,
    background 140ms ease,
    transform 140ms ease;
}

.toolBtn:not(:disabled):hover,
.iconBtn:not(:disabled):hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #f0fdfa;
}

.toolBtn:not(:disabled):active,
.iconBtn:not(:disabled):active,
.primaryBtn:not(:disabled):active {
  transform: translateY(1px);
}

.iconBtn {
  width: 38px;
  padding: 8px 0;
  font-size: 16px;
}

.primaryBtn {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.primaryBtn:not(:disabled):hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.handoffActions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.cameraPanel {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.cameraPanel[hidden] {
  display: none;
}

.cameraPanel video {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #020617;
  object-fit: cover;
}

.large {
  width: 100%;
}

.readout {
  min-height: 38px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.4;
}

.readout.compact {
  display: flex;
  align-items: center;
}

.readout.bare {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.step {
  padding: 10px 0;
  border-top: 1px solid var(--border-soft);
}

.step:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.stepTitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 800;
}

.checklistTitle {
  margin: 10px 0 6px;
  color: var(--text);
}

.previewBar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.layerToolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface-soft);
}

.layerLegend {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.layerLegend i {
  display: inline-block;
  width: 18px;
  height: 2px;
  background: var(--cut);
}

.preview {
  position: relative;
  flex: 1;
  min-height: 540px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(15, 23, 42, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.045) 1px, transparent 1px),
    #ffffff;
  background-size: 20px 20px;
  cursor: grab;
}

.preview:active {
  cursor: grabbing;
}

#svgWrap {
  display: inline-block;
  min-width: 1px;
  min-height: 1px;
  padding: 20px;
  will-change: transform;
}

.preview svg {
  display: block;
  max-width: none;
  height: auto;
  background: white;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

.preview pre {
  margin: 0;
  padding: 16px;
  color: #991b1b;
  white-space: pre-wrap;
}

.hilite path {
  stroke: var(--primary) !important;
}

.fitModelCard {
  margin-top: 12px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--success-bg);
  padding: 10px 12px;
}

.statusDot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.14);
}

.statusCard,
.packCard {
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 12px;
}

.statusLabel {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.status {
  margin-top: 4px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.4;
}

.warnings {
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  background: var(--warn-bg);
  color: var(--text);
  padding: 12px;
  font-size: 12px;
  line-height: 1.45;
}

.warnings ul {
  margin: 8px 0 0 18px;
  padding: 0;
}

.warnings li + li {
  margin-top: 6px;
}

.warnings code {
  color: #7f1d1d;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.warnings a {
  color: var(--primary);
  font-weight: 800;
}

.warnBlock + .warnBlock {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(146, 64, 14, 0.22);
}

.packCard h3 {
  margin-bottom: 8px;
  font-size: 14px;
}

.packCard ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 16px 18px;
  color: var(--muted);
  font-size: 12px;
}

.popover {
  position: fixed;
  z-index: 100;
  max-width: min(380px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  padding: 12px;
}

.popoverTitle {
  margin-bottom: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.popoverShort,
.popoverList,
.helpKeyMeta,
.helpTopic p,
.faqItem p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.popoverSection {
  margin-top: 10px;
}

.popoverSectionTitle {
  margin-bottom: 4px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.popoverList {
  margin: 0 0 0 18px;
  padding: 0;
}

.drawerOverlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.35);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  width: min(460px, 94vw);
  overflow: auto;
  border-left: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  padding: 14px;
}

.drawerHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}

.drawerTitle {
  font-weight: 900;
}

.drawerTools {
  padding-top: 12px;
}

.drawerSearch {
  width: 100%;
}

.drawerBody {
  padding-top: 12px;
}

.helpCategory {
  margin: 14px 0 8px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.helpTopic,
.faqItem {
  margin-bottom: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 10px;
}

.helpTopic h4,
.faqItem h4 {
  margin: 0 0 6px;
  font-size: 13px;
}

.helpTopicBody {
  margin-top: 8px;
}

.helpKeyMeta {
  margin-top: -2px;
  font-size: 11px;
}

.controlsToggle {
  display: none;
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 330px minmax(440px, 1fr);
    grid-template-areas:
      "controls preview"
      "export preview";
  }

  .exportPanel {
    align-self: start;
  }
}

@media (max-width: 980px) {
  .header {
    align-items: flex-start;
    flex-direction: column;
  }

  .headerControls {
    justify-content: flex-start;
    width: 100%;
  }

  .headerSticky {
    display: flex;
  }

  .headerSticky button {
    flex: 1;
  }

  .controlsToggle {
    display: inline-flex;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "preview"
      "export"
      "controls";
  }

  .previewPanel {
    min-height: 64vh;
  }

  .controlsPanel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 70;
    width: min(420px, 94vw);
    overflow: auto;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    border-radius: 0 var(--radius) var(--radius) 0;
    box-shadow: var(--shadow-md);
  }

  body.drawerOpen .controlsPanel {
    transform: translateX(0);
  }
}

@media (max-width: 640px) {
  .header {
    padding: 12px;
  }

  .brandBlock {
    min-width: 0;
  }

  .headerControls > * {
    flex: 1 1 auto;
  }

  .switch {
    justify-content: center;
  }

  .langSelect {
    min-width: min(100%, 180px);
  }

  .workspace {
    gap: 12px;
    padding: 12px;
  }

  .panel {
    padding: 12px;
  }

  .preview {
    min-height: 420px;
  }

  .previewHeader,
  .panelHeader {
    align-items: flex-start;
    flex-direction: column;
  }

  .previewBar {
    width: 100%;
  }

  .previewBar .toolBtn {
    flex: 1;
  }

  .fieldGrid,
  .fieldGrid.three {
    grid-template-columns: 1fr;
  }

  .layerLegend {
    margin-left: 0;
    width: 100%;
  }
}
