:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #161d22;
  --panel-2: #1e272e;
  --panel-3: #26323a;
  --line: #33424c;
  --muted: #8ea0aa;
  --text: #e8eef1;
  --accent: #4cc9a6;
  --accent-2: #ffcf5a;
  --danger: #ff6b64;
  --canvas: #081014;
  --grid: rgba(137, 157, 167, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 "Segoe UI", Roboto, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

button.active,
.tool.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06100d;
}

.app-shell {
  display: grid;
  grid-template-rows: 26px 48px 1fr;
  width: 100vw;
  height: 100vh;
}

.menubar {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 0 6px;
  background: #0d1317;
  border-bottom: 1px solid #26323a;
  overflow: visible;
  z-index: 100;
}

.menu {
  position: relative;
}

.menu > button {
  height: 25px;
  min-width: 46px;
  padding: 0 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #d8e2e7;
}

.menu > button:hover,
.menu:focus-within > button {
  background: var(--panel-2);
}

.menu-panel {
  position: absolute;
  top: 25px;
  left: 0;
  display: none;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--line);
  background: #172027;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.34);
  z-index: 120;
}

.menu:hover .menu-panel,
.menu:focus-within .menu-panel,
.menu.open .menu-panel {
  display: grid;
  gap: 2px;
}

.menu-panel button {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  text-align: left;
}

.menu-panel button:hover,
.menu-panel button:focus-visible {
  background: var(--panel-3);
}

.help-menu {
  margin-left: auto;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr) 280px;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 4px 8px;
  background: #11191e;
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 30px;
  border: 1px solid #5f766f;
  border-radius: 6px;
  background: #17332c;
  color: #d7fff0;
  font-size: 12px;
  font-weight: 800;
}

.brand strong,
.brand span:last-child {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand span:last-child {
  color: var(--muted);
  font-size: 11px;
}

.top-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.top-actions button {
  flex: 0 0 auto;
  min-width: 44px;
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

#saveAsBtn {
  min-width: 76px;
}

#openBtn,
#saveBtn,
#saveAsProjectBtn,
#exportAllBtn {
  min-width: 86px;
}

.status-strip {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  color: #b7c4ca;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
}

#fileActionReadout {
  color: var(--accent-2);
}

.workspace {
  display: grid;
  grid-template-columns: 42px minmax(360px, 1fr) 280px;
  min-height: 0;
}

.toolrail {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px 5px;
  background: #121a20;
  border-right: 1px solid var(--line);
}

.toolrail button {
  width: 31px;
  min-width: 31px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  line-height: 1;
}

.toolrail button.rail-action {
  border-color: rgba(124, 199, 255, 0.42);
}

.toolrail svg {
  width: 18px;
  height: 18px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolrail svg path:first-child:not(:only-child),
.toolrail svg rect,
.toolrail svg circle {
  vector-effect: non-scaling-stroke;
}

.toolrail [data-tool="select"] svg path {
  fill: currentColor;
  stroke-width: 1.2;
}

.viewport-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

#cadCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.crosshair {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  pointer-events: none;
  background: rgba(93, 211, 177, 0.45);
  opacity: 0;
}

.crosshair.vertical {
  top: 0;
  bottom: 0;
  width: 1px;
  height: auto;
}

.command-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid rgba(117, 139, 149, 0.55);
  border-radius: 8px;
  background: rgba(13, 20, 24, 0.9);
  backdrop-filter: blur(8px);
}

.command-bar span {
  color: var(--accent-2);
  font-weight: 700;
}

.command-bar input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
}

.inspector {
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
  background: #121a20;
  border-left: 1px solid var(--line);
}

.panel {
  margin-bottom: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
  margin-bottom: 6px;
}

.panel h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
  color: #c7d2d8;
}

.panel-title button {
  width: 30px;
  height: 28px;
}

.field-row,
.check-row {
  display: grid;
  grid-template-columns: 82px 1fr;
  align-items: center;
  gap: 6px;
  margin: 5px 0;
  color: #c4d0d6;
}

.check-row {
  grid-template-columns: 18px 1fr;
}

.color-row {
  align-items: start;
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(6, 24px);
  gap: 6px;
}

.color-chip {
  width: 24px;
  min-width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  padding: 0;
}

.color-chip.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(76, 201, 166, 0.4);
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 4px 8px;
}

input[type="checkbox"] {
  accent-color: var(--accent);
}

.layer-list {
  display: grid;
  gap: 6px;
}

.layer-row {
  display: grid;
  grid-template-columns: 18px 18px 1fr 22px;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--panel-2);
}

.layer-row.active {
  border-color: var(--accent);
}

.layer-row button {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 5px;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.layer-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.properties-empty {
  min-height: 48px;
  color: var(--muted);
}

.prop-grid,
.measure-grid {
  display: grid;
  gap: 8px;
}

.measure-empty {
  min-height: 48px;
  color: var(--muted);
}

.metric-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.metric-card span {
  color: var(--muted);
}

.metric-card strong {
  color: var(--text);
  font-weight: 700;
}

.history-list {
  max-height: 150px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  overflow: auto;
}

.history-list li {
  margin: 4px 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid #557068;
  border-radius: 8px;
  background: rgba(20, 32, 37, 0.96);
  color: var(--text);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 8, 11, 0.62);
  z-index: 200;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(460px, 100%);
  border: 1px solid #42535c;
  border-radius: 8px;
  background: #141d23;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.5);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 15px;
}

.icon-btn {
  width: 30px;
  min-width: 30px;
  height: 30px;
  padding: 0;
}

.modal-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.modal-copy {
  margin: 0;
  color: #b7c5cb;
}

.modal-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
}

.primary-action {
  background: var(--accent);
  border-color: var(--accent);
  color: #06100d;
  font-weight: 700;
}

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

.format-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 104px;
  }

  .app-shell {
    grid-template-rows: 26px auto 1fr;
  }

  .menubar {
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 42px 1fr;
  }

  .inspector {
    display: none;
  }

  .status-strip {
    justify-content: flex-start;
  }
}
