﻿:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #637083;
  --line: #d7dee7;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #11815d;
  --red: #b42318;
  --amber: #a15c07;
  --shadow: 0 18px 50px rgba(18, 30, 45, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
  width: min(1440px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 0;
}

.top-bar,
.workspace-row,
.control-panel,
.viewer-panel,
.stats-panel,
.table-wrap {
  min-width: 0;
  max-width: 100%;
}

.top-bar,
.control-panel,
.viewer-panel,
.stats-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #ffffff 0%, #f6f8fb 52%, #eef2f6 100%);
}

.workspace-row {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}

.control-panel,
.viewer-panel {
  min-height: 0;
}

.control-panel {
  overflow: auto;
  padding: 18px;
}

.viewer-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.title-block {
  min-width: 0;
}

.cite-us {
  max-width: 1080px;
  margin: 7px 0 0;
  color: #667386;
  font-size: 11px;
  line-height: 1.45;
}

.cite-us span {
  font-weight: 700;
  color: #425062;
}

.cite-us a {
  color: var(--blue);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.cite-us a:hover {
  text-decoration: underline;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

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

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

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

.calibration-grid .number-field span {
  min-height: 32px;
  line-height: 1.25;
}

.advanced-panel {
  border: 1px solid #d8e0ea;
  border-radius: 8px;
  background: #fbfcfe;
}

.advanced-panel summary {
  cursor: pointer;
  padding: 10px 12px;
  color: #334155;
  font-size: 13px;
  font-weight: 650;
  list-style-position: inside;
}

.advanced-panel summary:hover {
  background: #f3f6fa;
}

.advanced-content {
  display: grid;
  gap: 14px;
  padding: 2px 12px 12px;
}


.section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.control-panel .section:first-child {
  padding-top: 0;
}

.action-section {
  border-bottom: 0;
  padding-bottom: 0;
}

.section:last-child {
  border-bottom: 0;
}

.section-title,
.field span,
.number-field span,
.slider-field span {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 650;
  color: #334155;
}

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

select,
.number-field input {
  width: 100%;
  height: 38px;
  border: 1px solid #c7d0dc;
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

select:focus,
.number-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.slider-field input {
  width: 100%;
  accent-color: var(--blue);
}

.slider-field strong {
  float: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.drop-zone {
  display: flex;
  min-height: 126px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 2px dashed #b9c4d2;
  border-radius: 8px;
  background: #f8fafc;
  color: #526071;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--blue);
  background: #eef5ff;
}

.drop-zone input {
  display: none;
}

.upload-icon {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: #dbeafe;
  color: var(--blue);
  font-size: 24px;
  line-height: 1;
}

.drop-zone small {
  color: #7a8798;
}

.preview-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  max-height: 190px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

#previewCanvas {
  max-width: 100%;
  max-height: 188px;
  object-fit: contain;
}

.icon-button {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 28px;
  height: 28px;
  border: 1px solid #cbd5e1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #475569;
  cursor: pointer;
}

.primary-button,
.secondary-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 12px;
  font-weight: 650;
  cursor: pointer;
}

.primary-button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-dark);
}

.secondary-button {
  border: 1px solid #c7d0dc;
  background: #fff;
  color: #334155;
}

.secondary-button:hover:not(:disabled) {
  background: #f8fafc;
}

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

.action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.measure-tools {
  display: grid;
  gap: 6px;
  margin-top: -4px;
}

.compact-action-row {
  margin-bottom: 0;
}

.model-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.model-row .secondary-button {
  white-space: nowrap;
}

.demo-action {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

.demo-action .secondary-button {
  min-width: 150px;
}

.wide-button {
  width: 100%;
}

.usage-info {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.message {
  margin-top: 14px;
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 13px;
  line-height: 1.45;
}

.message.error {
  background: #fff0ed;
  color: var(--red);
}

.message.info {
  background: #eef5ff;
  color: #1e4fb8;
}

.message.warn {
  background: #fff7e6;
  color: var(--amber);
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 14px;
  color: #748197;
  text-align: center;
  padding: 24px;
}

.empty-icon {
  width: 72px;
  height: 72px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 58%, rgba(37, 99, 235, 0.14) 58%),
    linear-gradient(45deg, rgba(17, 129, 93, 0.16), transparent 48%),
    #f8fafc;
}

.result-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.stats-panel {
  padding: 16px 18px 18px;
}

.stats-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats-table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
  font-size: 13px;
}

.stats-table th,
.stats-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.stats-table th {
  background: #f7f9fc;
  color: #334155;
  font-weight: 700;
}

.stats-table th:first-child,
.stats-table td:first-child {
  text-align: left;
}

.stats-table tbody tr:last-child td {
  border-bottom: 0;
}

.stats-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.stats-pagination .secondary-button {
  min-height: 32px;
}

.measuring {
  cursor: crosshair;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-rows: auto auto auto;
    width: min(100% - 24px, 1440px);
    height: auto;
    min-height: 100vh;
    padding: 12px 0;
  }

  .top-bar,
  .stats-heading {
    flex-direction: column;
  }

  .workspace-row {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 1fr);
  }

  .control-panel {
    max-height: none;
  }

  .viewer-panel {
    min-height: 360px;
  }
}

@media (max-width: 420px) {
  .calibration-grid,
  .model-row {
    grid-template-columns: 1fr;
  }
}


@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 16px, 1440px);
    gap: 10px;
    padding: 8px 0;
  }

  .top-bar,
  .control-panel,
  .stats-panel {
    width: 100%;
    padding: 12px;
  }

  .workspace-row {
    gap: 10px;
    grid-template-rows: auto minmax(260px, auto);
  }

  .viewer-panel {
    min-height: 260px;
  }

  h1 {
    font-size: 20px;
  }

  .cite-us {
    font-size: 10px;
  }

  .action-row,
  .compact-action-row,
  .calibration-grid,
  .model-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .primary-button,
  .secondary-button,
  select,
  .number-field input {
    width: 100%;
  }

  .model-row .secondary-button {
    white-space: normal;
  }

  .stats-heading {
    gap: 10px;
  }

  .stats-pagination {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    justify-content: stretch;
  }

  .stats-pagination span {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
  }

  .stats-pagination .secondary-button {
    grid-row: 2;
    padding: 0 8px;
  }

  .table-wrap {
    max-width: 100%;
  }

  .stats-table {
    min-width: 760px;
  }
}
