:root {
  color-scheme: light;
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #151923;
  --muted: #687083;
  --line: #d7dce5;
  --accent: #246bfe;
  --accent-dark: #164dc6;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(31, 41, 55, 0.15);
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

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

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
}

button:hover {
  background: var(--accent-dark);
}

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

.hidden {
  display: none !important;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.login-view {
  align-items: center;
  display: flex;
  min-height: 100vh;
  justify-content: center;
  padding: 24px;
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 440px;
  padding: 34px;
  width: 100%;
}

.login-panel h1,
.topbar h1 {
  margin: 0;
}

.login-panel label {
  color: var(--muted);
  display: block;
  font-weight: 700;
  margin: 28px 0 8px;
}

.password-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
}

.login-panel > input,
.password-row input,
.control-grid input,
.control-grid select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

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

#standardTextSelect {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

.login-error {
  color: var(--danger);
  font-weight: 700;
  min-height: 22px;
}

.editor-view {
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 16px 24px;
}

.brand-block {
  align-items: center;
  display: flex;
  gap: 14px;
}

.app-logo {
  display: block;
  height: 48px;
  object-fit: contain;
  width: 132px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.ghost-button {
  background: #edf2ff;
  color: var(--accent);
}

.ghost-button:hover {
  background: #dfe8ff;
}

.workspace-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: calc(100vh - 82px);
}

.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 20px;
}

.sidebar section + section {
  border-top: 1px solid var(--line);
  margin-top: 22px;
  padding-top: 22px;
}

.sidebar h2 {
  font-size: 0.95rem;
  margin: 0 0 12px;
}

.surface-list {
  display: grid;
  gap: 10px;
}

.surface-button {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--ink);
  display: flex;
  justify-content: space-between;
}

.surface-button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 254, 0.16);
}

.surface-button:hover {
  background: #edf2ff;
  color: var(--ink);
}

.file-drop {
  align-items: center;
  background: #f8fafc;
  border: 2px dashed #b8c0ce;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  min-height: 110px;
  padding: 18px;
  text-align: center;
}

.file-drop.drag-over,
.artboard.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(36, 107, 254, 0.12);
}

.file-drop input {
  display: none;
}

.control-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.control-grid label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  font-weight: 700;
  gap: 5px;
}

.text-label {
  color: var(--muted);
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 5px;
}

.wide-button {
  margin-top: 12px;
  width: 100%;
}

.align-buttons {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 10px;
}

.align-buttons button {
  background: #edf2ff;
  color: var(--accent);
  min-height: 36px;
  padding: 0 8px;
}

.align-buttons button.active {
  background: var(--accent);
  color: #fff;
}

#scaleRange {
  margin: 16px 0;
  width: 100%;
}

.button-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
}

.button-row button,
#clearButton,
#previewButton {
  background: #151923;
}

.button-row button:hover,
#clearButton:hover,
#previewButton:hover {
  background: #303848;
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tool-strip {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(240px, 1fr) minmax(320px, 1.5fr);
  padding: 16px 20px 8px;
}

.tool-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.tool-card h2 {
  font-size: 0.95rem;
  margin: 0 0 12px;
}

.tool-card .file-drop {
  min-height: 146px;
}

.stage-toolbar {
  align-items: center;
  display: flex;
  justify-content: flex-end;
  padding: 8px 20px;
}

.stage-toolbar span,
.model-board-wrap h2 {
  color: var(--muted);
  font-weight: 800;
}

.stage-scroll {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: auto;
  padding: 8px 26px 26px;
  align-items: center;
  gap: 26px;
}

.stage,
.measurement-board {
  min-width: min-content;
}

.measurement-board {
  display: grid;
  grid-template-columns: 42px auto;
  grid-template-rows: 28px 34px auto;
}

.model-board-wrap {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.model-board-wrap h2 {
  font-size: 0.95rem;
  margin: 0;
}

.linked-model-wrap {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.linked-model-wrap h2 {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}

.linked-artboard {
  box-shadow: 0 10px 28px rgba(30, 41, 59, 0.12);
}

.zone-label-row {
  align-items: end;
  display: flex;
  grid-column: 2;
  grid-row: 1;
  min-height: 28px;
}

.zone-label-segment {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  overflow: hidden;
  padding: 0 4px 4px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.horizontal-ruler {
  align-items: end;
  display: flex;
  grid-column: 2;
  grid-row: 2;
  height: 34px;
}

.ruler-segment {
  align-items: center;
  background: repeating-linear-gradient(to right, #687083 0 1px, transparent 1px 30px);
  border-left: 1px solid #687083;
  border-top: 1px solid #687083;
  color: var(--muted);
  display: flex;
  font-size: 0.72rem;
  font-weight: 800;
  height: 26px;
  justify-content: center;
  white-space: nowrap;
}

.ruler-gap {
  background: transparent;
  border-top: 1px dashed #9aa3b4;
  color: var(--muted);
}

.vertical-ruler {
  align-items: center;
  background: repeating-linear-gradient(to bottom, #687083 0 1px, transparent 1px 30px);
  border-left: 1px solid #687083;
  border-top: 1px solid #687083;
  color: var(--muted);
  display: flex;
  font-size: 0.72rem;
  font-weight: 800;
  grid-column: 1;
  grid-row: 3;
  justify-content: center;
  width: 34px;
  writing-mode: vertical-rl;
}

.stage {
  grid-column: 2;
  grid-row: 3;
}

.admin-view {
  min-height: 100vh;
}

.admin-shell {
  display: grid;
  gap: 20px;
  justify-items: center;
  padding: 26px;
}

.admin-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 22px;
  max-width: 980px;
  padding: 24px;
  width: 100%;
}

.admin-panel h2,
.login-panel h2 {
  margin: 0 0 12px;
}

.admin-field {
  color: var(--muted);
  display: grid;
  font-weight: 700;
  gap: 6px;
  max-width: 260px;
}

.admin-field.wide {
  max-width: 520px;
}

.admin-field input,
.admin-editor input,
.admin-editor select {
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  padding: 10px;
  width: 100%;
}

.linked-model-admin {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.linked-model-admin label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  font-weight: 700;
  gap: 6px;
}

.linked-model-admin label:has(input[type="checkbox"]) {
  align-items: center;
  display: flex;
}

.linked-model-admin input[type="checkbox"] {
  width: auto;
}

.admin-help {
  color: var(--muted);
  margin: 0 0 10px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.admin-status {
  color: var(--accent);
  font-weight: 800;
  min-height: 22px;
}

.preview-modal {
  align-items: center;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 30;
}

.preview-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  max-height: 90vh;
  max-width: 980px;
  overflow: auto;
  padding: 22px;
  width: min(980px, 100%);
}

.preview-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.preview-header h2 {
  margin: 0;
}

.preview-list {
  display: grid;
  gap: 18px;
}

.preview-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px;
}

.preview-item figcaption {
  color: var(--muted);
  font-weight: 800;
}

.preview-item img {
  background: #fff;
  border: 1px solid var(--line);
  display: block;
  max-width: 100%;
}

.download-link {
  color: var(--accent);
  font-weight: 800;
}

.admin-actions.compact {
  margin-bottom: 12px;
}

.admin-surface-layout {
  display: grid;
  gap: 20px;
  grid-template-columns: 260px 1fr;
}

.admin-text-layout {
  display: grid;
  gap: 20px;
  grid-template-columns: 260px 1fr;
}

.admin-surface-list,
.admin-zone-list {
  display: grid;
  gap: 10px;
}

.admin-surface-item,
.admin-zone-card {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.admin-surface-item {
  color: var(--ink);
  display: block;
  min-height: auto;
  text-align: left;
  width: 100%;
}

.admin-surface-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 254, 0.16);
}

.admin-editor {
  display: grid;
  gap: 16px;
}

.admin-preview-wrap {
  background: #eef1f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  padding: 18px;
}

.admin-preview {
  background: #d8dde7;
  border: 1px solid #c9ced8;
  position: relative;
}

.admin-preview-zone {
  align-items: center;
  background: #fff;
  border: 1px solid #b8c0ce;
  color: var(--muted);
  cursor: grab;
  display: flex;
  font-size: 0.72rem;
  font-weight: 800;
  justify-content: center;
  overflow: hidden;
  position: absolute;
  text-align: center;
  touch-action: none;
}

.admin-preview-zone.locked {
  background: #f1f5f9;
  cursor: not-allowed;
}

.admin-preview-zone:active {
  cursor: grabbing;
}

.admin-preview-zone img {
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.admin-zone-card .control-grid {
  margin-bottom: 10px;
}

.admin-zone-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.admin-zone-tools label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.admin-zone-tools input[type="file"] {
  max-width: 240px;
}

.artboard {
  background: #d8dde7;
  border: 1px solid #c9ced8;
  box-shadow: 0 16px 40px rgba(30, 41, 59, 0.18);
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.white-zone {
  background: #fff;
  border: 1px solid #b8c0ce;
  cursor: grab;
  position: absolute;
  z-index: 0;
}

.white-zone::after {
  border: 1px dashed rgba(36, 107, 254, 0.35);
  content: "";
  inset: 3px;
  pointer-events: none;
  position: absolute;
}

.white-zone.active-zone {
  box-shadow: inset 0 0 0 2px rgba(36, 107, 254, 0.35);
}

.white-zone:active {
  cursor: grabbing;
}

.zone-resize-handle {
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  bottom: -8px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
  cursor: ew-resize;
  height: 16px;
  position: absolute;
  right: -8px;
  width: 16px;
  z-index: 3;
}

.locked-zone {
  cursor: not-allowed;
}

.locked-zone::after {
  border-color: rgba(104, 112, 131, 0.35);
}

.locked-zone-image {
  display: block;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  width: 100%;
}

.graphic {
  cursor: grab;
  left: 0;
  position: absolute;
  top: 0;
  transform-origin: center;
  touch-action: none;
  user-select: none;
}

.graphic:active {
  cursor: grabbing;
}

.graphic.selected {
  outline: 2px solid var(--accent);
}

.graphic img {
  display: block;
  height: auto;
  pointer-events: none;
  width: 100%;
}

.text-object {
  color: #151923;
  line-height: 1.05;
  max-width: 100%;
  min-width: 20px;
  padding: 0;
  text-align: center;
  white-space: pre-wrap;
}

.text-object .text-content {
  display: inline-block;
  pointer-events: none;
}

.resize-handle,
.rotate-handle {
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
  display: none;
  height: 18px;
  position: absolute;
  width: 18px;
  z-index: 2;
}

.graphic.selected .resize-handle,
.graphic.selected .rotate-handle {
  display: block;
}

.resize-handle {
  bottom: -9px;
  cursor: nwse-resize;
  right: -9px;
}

.rotate-handle {
  cursor: grab;
  left: 50%;
  top: -36px;
  transform: translateX(-50%);
}

@media (max-width: 860px) {
  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar {
    align-items: flex-start;
    gap: 14px;
    flex-direction: column;
  }

  .tool-strip {
    grid-template-columns: 1fr;
  }

  .admin-surface-layout {
    grid-template-columns: 1fr;
  }

  .admin-text-layout {
    grid-template-columns: 1fr;
  }
}
