:root {
  color-scheme: dark;
  --bg: #071016;
  --panel: #101d26;
  --panel-soft: #142631;
  --line: rgba(191, 221, 235, 0.17);
  --text: #eaf4f8;
  --muted: #9fb3bd;
  --accent: #5dd5b2;
  --cut: #ff795f;
  --fill: #49a9ff;
  --neutral: #d8e2e7;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(circle at 20% -10%, #163340 0, transparent 38%), var(--bg);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, select, input { font: inherit; }
button, select {
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}
button { min-height: 38px; padding: 7px 11px; cursor: pointer; }
button:hover { background: rgba(255, 255, 255, 0.1); }
button.primary { color: #042018; border-color: transparent; background: var(--accent); font-weight: 700; }
select { min-height: 34px; padding: 5px 8px; }
input[type="range"] { accent-color: var(--accent); }

.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px clamp(16px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(5, 13, 18, 0.78);
  backdrop-filter: blur(16px);
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(22px, 3vw, 34px); line-height: 1.1; }
h2 { margin-bottom: 10px; font-size: 15px; }
.eyebrow { margin-bottom: 7px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
#report-subtitle { margin-bottom: 0; color: var(--muted); }
.report-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

#report-content { padding: 18px clamp(16px, 3vw, 42px) 42px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.metrics article, .inspection-panel, .report-notes {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(155deg, rgba(19, 35, 45, 0.94), rgba(10, 21, 28, 0.96));
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}
.metrics article { padding: 12px 14px; }
.metrics span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 11px; }
.metrics strong { font-size: 20px; font-variant-numeric: tabular-nums; }

.viewer-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; }
.viewer-column { min-width: 0; }
.viewer-toolbar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px 18px;
  min-height: 56px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  background: rgba(12, 25, 33, 0.96);
}
.viewer-toolbar label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; }
.viewer-toolbar label.check { display: flex; align-items: center; min-height: 34px; color: var(--text); font-size: 13px; }
.viewer-toolbar output { color: var(--text); }
.camera-presets { display: flex; align-items: center; gap: 5px; }
.camera-presets button { min-height: 34px; padding: 5px 8px; font-size: 11px; }
#viewer-frame {
  position: relative;
  height: min(68vh, 680px);
  min-height: 460px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
  background: linear-gradient(#0b171e, #071015);
}
#volume-canvas { display: block; width: 100%; height: 100%; outline: none; }
.axis-contract, .legend, #viewer-message {
  position: absolute;
  z-index: 2;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(4, 11, 16, 0.78);
  backdrop-filter: blur(8px);
}
.axis-contract { top: 10px; left: 10px; padding: 5px 8px; color: var(--muted); font: 11px ui-monospace, monospace; }
.legend { right: 10px; top: 10px; display: flex; flex-wrap: wrap; gap: 8px 12px; padding: 6px 8px; font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; }
.legend .cut { background: var(--cut); }.legend .fill { background: var(--fill); }.legend .neutral { background: var(--neutral); }
#viewer-message { left: 10px; bottom: 10px; max-width: calc(100% - 20px); margin: 0; padding: 5px 8px; color: var(--muted); font-size: 11px; }

.inspection-panel { padding: 14px; }
.inspection-panel dl { margin: 0; }
.inspection-panel dl div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.inspection-panel dt { color: var(--muted); }
.inspection-panel dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.mesh-summary { margin-top: 20px; }
.report-notes { margin-top: 14px; padding: 16px; }
.report-notes p { margin-bottom: 7px; color: var(--muted); }
#report-error { margin: 40px auto; max-width: 720px; padding: 20px; color: #ffd8d2; border: 1px solid rgba(255, 121, 95, 0.5); border-radius: 10px; background: rgba(91, 31, 24, 0.55); }

body.embedded .report-header { min-height: 48px; padding: 7px 14px; }
body.embedded .report-header > div:first-child { display: none; }
body.embedded #report-content { padding: 10px 14px 24px; }
body.embedded #viewer-frame { height: min(66vh, 720px); }

@media (max-width: 980px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .viewer-layout { grid-template-columns: 1fr; }
  .inspection-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
  .mesh-summary { margin-top: 0; }
}
@media (max-width: 620px) {
  .report-header { align-items: stretch; flex-direction: column; }
  .report-actions { justify-content: flex-start; }
  .report-actions button span { display: none; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .viewer-toolbar { align-items: stretch; flex-direction: column; }
  #viewer-frame { min-height: 400px; }
  .inspection-panel { display: block; }
  .mesh-summary { margin-top: 20px; }
  .legend { left: 10px; top: 42px; right: auto; }
}

@media print {
  :root { color-scheme: light; --text: #17202a; --muted: #40515a; --line: #aeb9bf; }
  body { color: #17202a; background: #fff; font-size: 10pt; }
  .no-print, #viewer-message { display: none !important; }
  .report-header { padding: 0 0 8mm; border-bottom: 1px solid #5f6b72; background: #fff; }
  #report-content { padding: 5mm 0 0; }
  .metrics { gap: 3mm; }
  .metrics article, .inspection-panel, .report-notes { color: #17202a; border: 1px solid #9aa5ab; background: #fff; box-shadow: none; }
  .metrics article { padding: 3mm; }
  .viewer-layout { display: block; }
  #viewer-frame { height: 128mm; min-height: 0; border: 1px solid #9aa5ab; border-radius: 0; background: #f3f6f7; break-inside: avoid; }
  .inspection-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 10mm; margin-top: 5mm; break-inside: avoid; }
  .axis-contract, .legend { color: #17202a; border-color: #9aa5ab; background: rgba(255,255,255,.88); }
  .report-notes { break-inside: avoid; }
  @page { size: A4 landscape; margin: 10mm; }
}
