:root {
  color-scheme: dark;
  --bg: #171918;
  --panel: #20231f;
  --panel-2: #292d28;
  --line: #3a4038;
  --text: #f2f4ef;
  --muted: #aeb7aa;
  --accent: #66d9c4;
  --accent-2: #f2c14e;
  --danger: #ef6f6c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app {
  display: grid;
  grid-template-columns: 260px minmax(480px, 1fr) 320px;
  min-height: 100vh;
}

.sidebar, .panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px;
}

.panel {
  border-right: 0;
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

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

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

.brand span, .topbar span, .pending, .measure small {
  color: var(--muted);
  font-size: 13px;
}

.file-button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.file-button {
  width: 100%;
  margin-bottom: 18px;
  color: #101412;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.file-button input { display: none; }

.tool-section {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.control-section {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1b1f1b;
}

.control-section label,
.map-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.line-controls strong {
  font-size: 13px;
}

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

.line-control-grid button {
  min-height: 32px;
  font-size: 12px;
}

.control-section input,
.control-section select,
.map-panel input,
.map-panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #151815;
  color: var(--text);
  padding: 8px;
}

.control-section label span {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
}

.color-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.color-swatch {
  min-height: 30px;
  border-radius: 6px;
  background: var(--swatch);
  border-color: rgba(255, 255, 255, 0.25);
}

.color-swatch.is-active {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.scale-status {
  color: var(--accent-2);
  font-size: 12px;
  line-height: 1.35;
}

.tool {
  justify-content: flex-start;
  padding: 0 12px;
}

.tool.is-active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.compact { grid-template-columns: 1fr 1fr; }

.workspace {
  display: grid;
  grid-template-rows: 58px 1fr;
  min-width: 0;
}

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

.topbar > div:first-child {
  display: grid;
  gap: 2px;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls button {
  min-width: 38px;
  padding: 0 10px;
}

#zoomLabel {
  min-width: 54px;
  text-align: center;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  background: #101210;
}

#viewer {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  color: var(--muted);
  pointer-events: none;
}

.empty-state strong {
  color: var(--text);
  font-size: 24px;
}

.empty-state.is-hidden { display: none; }

.panel h1 {
  margin: 0 0 12px;
  font-size: 22px;
}

.pending {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 12px;
}

.measurements {
  display: grid;
  gap: 10px;
}

.measure {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: var(--panel-2);
}

.measure.is-hidden {
  opacity: 0.58;
}

.measure header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.measure-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.fragment-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 6px;
}

.measure-actions button,
.fragment-actions button {
  min-height: 30px;
  font-size: 12px;
}

.measure strong { color: var(--accent); }
.measure b { color: var(--accent-2); }

.map-panel,
.angle-guide {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1b1f1b;
}

.map-panel h2,
.angle-guide h2 {
  margin: 0;
  font-size: 16px;
}

.map-panel textarea {
  resize: vertical;
  min-height: 72px;
}

.guide-note,
.angle-guide p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.angle-guide details {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.angle-guide summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}

.clinical-note {
  margin-top: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 220px 1fr; }
  .panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 34vh;
  }
}
