:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #f5f7fa;
  color: #172033;
}

* {
  box-sizing: border-box;
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
select,
input {
  font: inherit;
}

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

.sidebar {
  border-right: 1px solid #d8dee8;
  background: #ffffff;
  padding: 18px;
  min-height: 0;
  overflow: auto;
}

.brand {
  display: grid;
  gap: 4px;
  margin-bottom: 22px;
}

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

.brand strong {
  font-size: 20px;
}

.report-issue {
  flex: 0 0 auto;
  border: 1px solid #c9d2df;
  border-radius: 6px;
  color: #344054;
  font-size: 12px;
  line-height: 1;
  padding: 7px 9px;
  text-decoration: none;
}

.report-issue:hover {
  border-color: #7a8ba7;
  background: #f3f6fb;
}

.brand-link {
  width: fit-content;
  color: #176a76;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.brand-link:hover {
  text-decoration: underline;
}

.brand span,
.empty,
.meta-grid span,
p {
  color: #667085;
}

section {
  display: grid;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid #e6eaf0;
}

h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  color: #344054;
}

.field-group {
  display: grid;
  gap: 7px;
  font-size: 13px;
  color: #344054;
}

.coordinate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.axis-input {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

select,
button,
input[type="number"],
input[type="text"] {
  min-height: 36px;
  border: 1px solid #c9d2df;
  border-radius: 6px;
  background: #fff;
  color: #172033;
  padding: 0 10px;
}

button {
  cursor: pointer;
}

button:hover {
  background: #f3f6fb;
}

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

.primary-button {
  border-color: #176a76;
  background: #176a76;
  color: #fff;
}

.primary-button:hover {
  background: #125965;
}

.danger-button {
  border-color: #f4b2ac;
  background: #fff5f4;
  color: #b42318;
}

.danger-button:hover {
  border-color: #e67a73;
  background: #fee4e2;
}

input[type="range"] {
  width: 100%;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 8px;
  align-items: center;
}

output {
  color: #667085;
  font-size: 12px;
}

p {
  margin: 0;
  line-height: 1.55;
  font-size: 13px;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  font-size: 13px;
}

.inspector {
  display: grid;
  gap: 14px;
}

.component-library-name {
  color: #667085;
  font-size: 13px;
  line-height: 1.45;
}

.component-library-name strong {
  color: #344054;
}

.status {
  border: 1px solid #d8dee8;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  line-height: 1.5;
}

.status.valid {
  border-color: #35a36b;
  background: #eefaf4;
}

.status.invalid {
  border-color: #d94848;
  background: #fff1f1;
}

.status.warning {
  border-color: #d69521;
  background: #fff8e6;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 10px 14px;
  border-bottom: 1px solid #d8dee8;
  background: #ffffff;
}

.toolbar span {
  color: #667085;
  font-size: 13px;
}

.toolbar #readout {
  margin-left: 4px;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 190px;
}

.zoom-control input[type="range"] {
  width: 120px;
}

.zoom-control .icon-button {
  font-weight: 700;
}

#exportStatus {
  color: #176a76;
}

.toolbar-status {
  padding: 0 14px 8px;
  border-bottom: 1px solid #d8dee8;
  background: #ffffff;
}

.toolbar-status:has(#exportStatus:empty) {
  display: none;
}

.toolbar-status #exportStatus {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.language-control {
  display: flex;
  flex-direction: row;
  gap: 6px;
  align-items: center;
  margin-left: auto;
  color: #667085;
  font-size: 13px;
}

.language-control select {
  min-height: 34px;
  width: auto;
  padding: 0 28px 0 9px;
}

.placement-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(180px, 260px) auto auto;
  gap: 10px;
  align-items: center;
  min-height: 62px;
  padding: 10px 14px;
  border-bottom: 1px solid #94d2d8;
  background: #ecfafb;
}

.placement-label {
  gap: 4px;
  font-size: 12px;
}

.placement-label input {
  min-height: 32px;
}

.placement-bar small {
  display: block;
  margin-top: 3px;
  color: #52757a;
}

.placement-indicator {
  width: 12px;
  height: 12px;
  border: 2px solid #178494;
  border-radius: 50%;
  animation: placementPulse 1.3s ease-in-out infinite;
}

.canvas-shell {
  grid-area: canvas;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.canvas-controls {
  --drawing-viewport-width: 720px;
  --drawing-viewport-height: 540px;
  display: grid;
  grid-template-areas:
    "canvas y-axis"
    "x-axis corner";
  grid-template-columns: var(--drawing-viewport-width) 44px;
  grid-template-rows: var(--drawing-viewport-height) 44px;
  align-self: start;
  justify-self: start;
  margin: 28px;
  min-height: 0;
  min-width: 0;
}

.axis-control {
  --axis-track-color: #cfd8e4;
  --axis-window-color: #2f80ed;
  --axis-border-color: #b7c3d0;
  --axis-thumb-border: #667085;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.axis-control input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  min-width: 0;
}

.axis-control input[type="range"]::-webkit-slider-runnable-track {
  height: 7px;
  border: 1px solid var(--axis-border-color);
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--axis-track-color) 0,
    var(--axis-track-color) var(--axis-workspace-start, 34.375%),
    var(--axis-window-color) var(--axis-workspace-start, 34.375%),
    var(--axis-window-color) var(--axis-workspace-end, 65.625%),
    var(--axis-track-color) var(--axis-workspace-end, 65.625%),
    var(--axis-track-color) 100%
  );
}

.axis-control input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -6.5px;
  border: 2px solid #1f5fa8;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(23, 32, 51, 0.22);
  -webkit-appearance: none;
}

.axis-control input[type="range"]::-moz-range-track {
  height: 7px;
  border: 1px solid var(--axis-border-color);
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--axis-track-color) 0,
    var(--axis-track-color) var(--axis-workspace-start, 34.375%),
    var(--axis-window-color) var(--axis-workspace-start, 34.375%),
    var(--axis-window-color) var(--axis-workspace-end, 65.625%),
    var(--axis-track-color) var(--axis-workspace-end, 65.625%),
    var(--axis-track-color) 100%
  );
}

.axis-control input[type="range"]::-moz-range-progress {
  background: transparent;
}

.axis-control input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #1f5fa8;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(23, 32, 51, 0.22);
}

.axis-control.active {
  --axis-window-color: #f59f00;
  --axis-thumb-border: #b54708;
}

.axis-control input[type="range"]::-webkit-slider-thumb {
  border-color: var(--axis-thumb-border);
}

.axis-control input[type="range"]::-moz-range-thumb {
  border-color: var(--axis-thumb-border);
}

.x-axis-control {
  grid-area: x-axis;
  padding: 6px 28px 8px;
}

.x-axis-control input[type="range"] {
  flex: 1;
}

.y-axis-control {
  grid-area: y-axis;
  flex-direction: column;
  justify-content: flex-start;
  position: relative;
  min-height: 0;
  padding: 28px 8px;
}

.y-axis-control input[type="range"] {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--drawing-viewport-height) - 56px);
  height: 28px;
  min-height: 0;
  transform: translate(-50%, -50%) rotate(-90deg);
  transform-origin: center;
}

.resize-workspace {
  grid-area: corner;
  align-self: stretch;
  justify-self: stretch;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: nwse-resize;
  touch-action: none;
  position: relative;
}

.resize-workspace:hover {
  background: transparent;
}

.resize-workspace::before {
  content: "";
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 18px;
  height: 18px;
  border-right: 2px solid #667085;
  border-bottom: 2px solid #667085;
  box-shadow:
    5px 5px 0 -3px #667085,
    10px 10px 0 -6px #667085;
  opacity: 0.8;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  touch-action: none;
  user-select: none;
  background: #e9edf3;
  border: 1px solid #ccd4df;
  border-radius: 8px;
}

#canvas * {
  touch-action: none;
}

.table {
  fill: #fbfcfe;
  stroke: rgba(102, 112, 133, 0.34);
  stroke-width: 1;
}

.hole {
  fill: #ffffff;
  stroke: rgba(102, 112, 133, 0.36);
  stroke-width: 0.9;
}

.hole.candidate {
  fill: #dff7ea;
  stroke: #1b8350;
  stroke-width: 2;
}

.component,
.clamp-group,
.screw {
  cursor: grab;
}

.component:active,
.clamp-group:active,
.screw:active {
  cursor: grabbing;
}

.selected-outline {
  pointer-events: none;
}

.selected-outline {
  fill: none;
  stroke: rgba(0, 0, 0, 0.42);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}

.pending-outline {
  pointer-events: none;
  fill: rgba(17, 141, 154, 0.08);
  stroke: #168d9a;
  stroke-width: 2;
  stroke-dasharray: 7 5;
  animation: pendingOutline 1.2s ease-in-out infinite;
}

.component.pending {
  opacity: 0.88;
}

.clamp-group.pending .clamp {
  fill: #bcebed;
  stroke: #147783;
}

.clamp-group.pending .slot {
  stroke: #155e68;
}

.component-body {
  fill: #dee8f6;
  stroke: rgba(55, 90, 127, 0.48);
  stroke-width: 1.1;
}

.missing-component-body {
  fill: #fff1f0;
  stroke: #d92d20;
  stroke-dasharray: 5 3;
}

.missing-mark {
  stroke: #d92d20;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.post {
  fill: #3d4656;
}

.optic {
  fill: #b8e0e4;
  stroke: rgba(22, 118, 132, 0.54);
  stroke-width: 1.1;
}

.splitter-face {
  stroke: rgba(69, 163, 173, 0.72);
  stroke-width: 2;
  stroke-linecap: round;
}

.waveplate-face {
  stroke: rgba(100, 116, 139, 0.58);
  stroke-width: 4;
  stroke-linecap: round;
}

.mirror-back,
.mirror-face {
  stroke-linecap: round;
}

.mirror-back {
  stroke: rgba(61, 82, 104, 0.5);
  stroke-width: 4.6;
}

.mirror-face {
  stroke: rgba(217, 251, 255, 0.82);
  stroke-width: 2;
}

.source-aperture {
  fill: #fff6d6;
  stroke: rgba(161, 92, 0, 0.54);
  stroke-width: 1;
}

.source-symbol {
  fill: #f2b84b;
  stroke: rgba(161, 92, 0, 0.54);
  stroke-width: 1;
}

.beam-layer {
  pointer-events: none;
}

.beam {
  stroke-width: 2.4;
  stroke-linecap: round;
}

.beam.reflected {
  stroke-opacity: 0.88;
}

.pivot {
  fill: #172033;
}

.clamp {
  fill: #f7d99d;
  stroke: rgba(159, 107, 19, 0.5);
  stroke-width: 1;
}

.slot {
  stroke: rgba(111, 72, 12, 0.62);
  stroke-width: 4.2;
  stroke-linecap: round;
}

.slot.invalid {
  stroke: #c92a2a;
}

.screw {
  fill: #f8fafc;
  stroke: rgba(23, 32, 51, 0.54);
  stroke-width: 1.1;
}

.screw.invalid {
  fill: #ffe3e3;
  stroke: #c92a2a;
}

.screw.warning {
  fill: #fff4bf;
  stroke: #d69521;
}

.label {
  fill: #344054;
  font-size: 11px;
  pointer-events: none;
  user-select: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(22, 29, 42, 0.38);
}

.picker-dialog {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(860px, 100%);
  max-height: min(720px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid #cad4df;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(25, 35, 51, 0.2);
}

.export-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(980px, 100%);
  height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid #cad4df;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(25, 35, 51, 0.2);
}

.export-preview-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  background: #eef2f6;
}

.export-preview-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border: 1px solid #cbd5e1;
  background: #e9edf3;
  box-shadow: 0 6px 18px rgba(25, 35, 51, 0.12);
}

.export-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid #e3e8ef;
}

.export-footer div {
  display: grid;
  gap: 3px;
  margin-right: auto;
}

.export-footer span {
  color: #667085;
  font-size: 12px;
}

.picker-header,
.picker-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
}

.picker-header {
  justify-content: space-between;
  border-bottom: 1px solid #e3e8ef;
}

.picker-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-picker-confirm {
  display: none;
}

.picker-header h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.picker-header p {
  margin-top: 4px;
}

.icon-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.picker-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #e3e8ef;
  background: #f8fafc;
}

input[type="search"] {
  min-height: 36px;
  border: 1px solid #c9d2df;
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
}

.component-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  overflow: auto;
  scrollbar-color: #8aa0b8 #e7edf4;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  padding: 16px 18px;
}

.component-catalog::-webkit-scrollbar {
  width: 10px;
}

.component-catalog::-webkit-scrollbar-track {
  background: #e7edf4;
}

.component-catalog::-webkit-scrollbar-thumb {
  border: 2px solid #e7edf4;
  border-radius: 999px;
  background: #8aa0b8;
}

.catalog-item {
  display: grid;
  grid-template-rows: 84px auto auto;
  gap: 7px;
  align-content: start;
  min-height: 146px;
  padding: 10px;
  text-align: left;
}

.catalog-item.selected {
  border-color: #168d9a;
  outline: 2px solid rgba(22, 141, 154, 0.18);
  background: #effbfc;
}

.catalog-item strong {
  font-size: 14px;
}

.catalog-item span {
  color: #667085;
  font-size: 12px;
}

.catalog-thumbnail {
  display: block;
  width: 100%;
  height: 84px;
  border: 1px solid #d6dee8;
  border-radius: 5px;
  background: #f8fafc;
}

.picker-footer {
  justify-content: flex-end;
  border-top: 1px solid #e3e8ef;
}

.picker-footer span {
  margin-right: auto;
  color: #667085;
  font-size: 13px;
}

@keyframes placementPulse {
  50% {
    box-shadow: 0 0 0 5px rgba(23, 132, 148, 0.16);
  }
}

@keyframes pendingOutline {
  50% {
    stroke-opacity: 0.46;
  }
}

@media (pointer: coarse) {
  select,
  button,
  input[type="number"],
  input[type="search"],
  input[type="text"] {
    font-size: 16px;
    min-height: 44px;
  }

  select {
    font-size: 16px;
  }

  input[type="range"] {
    min-height: 44px;
  }

  .sidebar {
    padding: 16px;
  }

  .toolbar,
  .picker-header,
  .picker-footer,
  .export-footer {
    gap: 8px;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .zoom-control {
    min-width: 220px;
  }

  .zoom-control input[type="range"] {
    width: 140px;
  }

  .language-control {
    margin-left: 0;
  }

  .placement-bar {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
  }

  .placement-label {
    grid-column: 1 / -1;
  }

  .icon-button {
    width: 44px;
    min-width: 44px;
    padding: 0;
  }

  .catalog-item {
    min-height: 162px;
  }

  .catalog-thumbnail {
    height: 92px;
  }
}

@media (max-width: 820px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .workspace {
    display: grid;
    grid-template-areas:
      "placement"
      "canvas"
      "toolbar"
      "status";
    grid-template-rows: auto auto auto auto;
    order: 1;
    min-height: 0;
    border-bottom: 1px solid #d8dee8;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    order: 2;
    border-right: 0;
    border-bottom: 0;
    max-height: none;
    overflow: visible;
  }

  .brand {
    order: 6;
    margin: 8px 0 0;
    padding-top: 14px;
    border-top: 1px solid #e6eaf0;
  }

  .component-library-panel {
    order: 1;
  }

  .selected-component-panel {
    order: 2;
  }

  .table-panel {
    order: 3;
  }

  .mounting-rules-panel {
    order: 4;
  }

  .optical-rules-panel {
    order: 5;
  }

  .toolbar {
    grid-area: toolbar;
    flex-wrap: wrap;
    min-height: 0;
    border-top: 1px solid #d8dee8;
    border-bottom: 1px solid #e6eaf0;
  }

  .zoom-control {
    min-width: 220px;
  }

  .language-control {
    margin-left: 0;
  }

  .toolbar-status {
    grid-area: status;
  }

  .placement-bar {
    grid-area: placement;
  }

  .canvas-controls {
    grid-area: canvas;
    grid-template-columns: var(--drawing-viewport-width) 40px;
    grid-template-rows: var(--drawing-viewport-height) 40px;
    justify-self: center;
    margin: 10px;
    max-width: calc(100vw - 20px);
  }

  .x-axis-control {
    padding: 4px 16px 6px;
  }

  .y-axis-control {
    padding: 16px 4px;
  }

  .placement-bar,
  .picker-toolbar {
    grid-template-columns: 1fr;
  }

  .placement-indicator {
    display: none;
  }

  .placement-bar button {
    width: 100%;
  }

  .picker-header,
  .picker-footer,
  .export-footer {
    flex-wrap: wrap;
  }

  .modal-backdrop {
    align-items: center;
    justify-items: center;
    padding: 12px;
  }

  .picker-dialog {
    width: min(430px, calc(100vw - 24px));
    height: min(720px, calc(100dvh - 24px));
    max-height: calc(100dvh - 24px);
    border: 1px solid #cad4df;
    border-radius: 8px;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  .picker-header {
    align-items: flex-start;
    padding: 12px 12px 10px;
  }

  .picker-header > div:first-child {
    min-width: 0;
  }

  .picker-header-actions {
    flex: 0 0 auto;
  }

  .picker-header h1 {
    font-size: 16px;
  }

  .picker-header p {
    font-size: 12px;
  }

  .mobile-picker-confirm {
    display: inline-flex;
    align-items: center;
    width: auto;
    white-space: nowrap;
  }

  .picker-toolbar {
    padding: 10px 12px;
  }

  .component-catalog {
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 8px 12px 12px;
    scrollbar-gutter: stable;
  }

  .picker-footer {
    padding: 10px 12px;
  }

  #confirmComponentPicker {
    display: none;
  }

  .picker-footer span,
  .export-footer div {
    flex-basis: 100%;
  }

  .export-dialog {
    max-height: calc(100dvh - 24px);
  }
}
