/* Application layout and components: topbar, left inspector, stage, right side panel, status bar.
   Controls stay flat — backgrounds appear on hover/active only, not as permanent boxes. */

.app {
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr) 24px;
  width: 100%;
  height: 100%;
  min-width: 980px;
  background: var(--bg);
}

/* ---------- shared controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  white-space: nowrap;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}

.btn:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.icon-btn.is-active {
  color: var(--accent);
}

.icon-btn--sm {
  width: 26px;
  height: 26px;
}

.icon-btn--sm .material-symbols-rounded {
  font-size: 17px;
}

.icon-btn .material-symbols-rounded {
  font-size: 19px;
}

/* ---------- topbar ---------- */

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

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

.topbar__sep {
  flex: none;
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--line);
}

.project-name {
  min-width: 60px;
  max-width: 260px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  padding: 0 8px;
  color: var(--text);
  font-weight: 500;
  text-overflow: ellipsis;
}

.project-name:hover {
  background: var(--surface-2);
}

.project-name:focus {
  border-color: var(--accent);
  background: var(--surface-2);
  outline: none;
}

.topbar__center {
  display: flex;
  align-items: center;
  gap: 2px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

/* ---------- workspace ---------- */

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

/* ---------- inspector (left) ---------- */

.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.panel {
  border-bottom: 1px solid var(--line-soft);
  padding: 14px 14px 16px;
}

.panel__title,
.side-panel__title {
  margin: 0;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.panel__title {
  display: block;
  margin-bottom: 12px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.field:last-child {
  margin-bottom: 0;
}

.field__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 12px;
}

.field__label output {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
}

.input {
  width: 100%;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 0 9px;
  color: var(--text);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  transition: border-color 120ms var(--ease), background-color 120ms var(--ease);
}

.input:hover:not(:disabled) {
  border-color: var(--line-strong);
}

.input:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
}

.select {
  width: 100%;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  padding: 0 8px;
  transition: border-color 120ms var(--ease);
}

.color-input {
  width: 100%;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 3px;
  cursor: pointer;
}

.color-input:hover {
  border-color: var(--line-strong);
}

.hint {
  margin: 0;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.5;
}

.progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress__bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 120ms linear;
}

.progress.is-indeterminate .progress__bar {
  width: 40%;
  animation: bg-indeterminate 1.1s ease-in-out infinite;
}

@keyframes bg-indeterminate {
  from {
    margin-left: -40%;
  }
  to {
    margin-left: 100%;
  }
}

.select:hover {
  border-color: var(--line-strong);
}

.select:focus {
  border-color: var(--accent);
  outline: none;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.measure {
  position: relative;
}

.measure::after {
  content: attr(data-unit);
  position: absolute;
  top: 50%;
  right: 9px;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  pointer-events: none;
}

.measure .input {
  padding-right: 24px;
}

.dim-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 8px;
}

.dim-row__x {
  color: var(--text-faint);
}

.link-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
}

.link-btn:hover {
  background: var(--surface-3);
  color: var(--text-dim);
}

.link-btn.is-active {
  color: var(--accent);
}

.link-btn .material-symbols-rounded {
  font-size: 18px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: background-color 120ms var(--ease);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]:hover::-webkit-slider-thumb {
  background: var(--accent-strong);
}

input[type="range"]:hover::-moz-range-thumb {
  background: var(--accent-strong);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segmented label {
  position: relative;
}

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

.segmented span {
  display: grid;
  place-items: center;
  height: 30px;
  color: var(--text-dim);
  font-size: 12px;
}

.segmented label + label span {
  border-left: 1px solid var(--line);
}

.segmented input:checked + span {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.inspector__empty {
  margin: auto;
  padding: 28px 18px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--workspace);
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#view.is-panning {
  cursor: grabbing;
}

.stage__toolbar {
  position: absolute;
  z-index: 4;
  bottom: 14px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 2px;
  transform: translateX(-50%);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--surface), transparent 8%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.toolbar-sep {
  width: 1px;
  height: 18px;
  margin: 0 3px;
  background: var(--line);
}

.zoom-readout {
  min-width: 54px;
  height: 32px;
  padding: 0 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}

.zoom-readout:hover {
  background: var(--surface-3);
}

.stage__drop {
  position: absolute;
  inset: 14px;
  z-index: 6;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent-soft), transparent 10%);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
}

.stage.is-dropping .stage__drop {
  display: grid;
}

/* ---------- side panel (right) ---------- */

.side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.side-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-panel--nav {
  border-bottom: 1px solid var(--line);
}

.side-panel__head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 8px 0 14px;
  flex: 0 0 auto;
}

.side-panel__count {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.side-panel__spacer {
  flex: 1;
}

.nav-body {
  padding: 0 12px 12px;
}

#minimap {
  display: block;
  width: 100%;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--workspace);
}

.layer-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 8px 10px;
}

.layer-list__empty {
  margin-top: 28px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

.layer-row {
  display: grid;
  grid-template-columns: 26px 40px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms var(--ease);
}

.layer-row:hover {
  background: var(--surface-2);
}

.layer-row.is-active {
  background: var(--accent-soft);
}

.layer-row.is-hidden .layer-row__thumb,
.layer-row.is-hidden .layer-row__name {
  opacity: 0.45;
}

.layer-row.is-drop-before {
  border-top-color: var(--accent);
}

.layer-row.is-drop-after {
  border-bottom-color: var(--accent);
}

.layer-row__vis {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
}

.layer-row__vis:hover {
  background: var(--surface-3);
  color: var(--text);
}

.layer-row__vis .material-symbols-rounded {
  font-size: 18px;
}

.layer-row__thumb {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background-color: var(--workspace);
}

.layer-row__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

/* ---------- export panel ---------- */

.side-panel--export {
  border-top: 1px solid var(--line);
}

.export-body {
  display: grid;
  gap: 9px;
  padding: 2px 12px 12px;
}

.export-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.export-grid {
  display: grid;
  gap: 7px;
}

.export-grid-inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.export-hint {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.export-btn {
  width: 100%;
}

/* ---------- status bar ---------- */

.statusbar {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-faint);
  font-size: 11px;
  overflow: hidden;
}

.statusbar span {
  display: flex;
  gap: 6px;
  padding: 0 12px;
  border-right: 1px solid var(--line-soft);
  white-space: nowrap;
}

.statusbar b {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-weight: 500;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  z-index: 20;
  max-width: min(460px, calc(100% - 40px));
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}

.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast[data-tone="error"] {
  border-color: color-mix(in srgb, var(--danger), transparent 40%);
  color: var(--danger);
}

@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: 240px minmax(0, 1fr) 224px;
  }
}
