:root {
  --hcp-burgundy: #6b001c;
  --hcp-red: #d60038;
  --hcp-blue: #005980;
  --hcp-bronze: #be7f37;
  --hcp-gray: #585858;
  --hcp-ink: #151515;
  --hcp-muted: #666b70;
  --hcp-line: #d9dde1;
  --hcp-soft-line: #eceff1;
  --hcp-surface: #ffffff;
  --hcp-soft: #f6f8f9;
  --hcp-blue-soft: #e8f3f7;
  --hcp-red-soft: #fff0f4;
  --radius: 6px;
  --shadow: 0 14px 34px rgba(21, 21, 21, 0.08);
  --font-body: "Sofia Pro", "Segoe UI", Arial, sans-serif;
  --font-display: "Kanit", "Sofia Pro", "Segoe UI", Arial, sans-serif;
  font-family: var(--font-body);
  color: var(--hcp-ink);
  background: #ffffff;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: #ffffff;
  color: var(--hcp-ink);
}

a {
  color: inherit;
}

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

button {
  cursor: pointer;
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--hcp-blue);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
}

.secondary-link:hover {
  color: var(--hcp-red);
}

button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(420px, 1fr) minmax(320px, 390px);
  gap: 16px;
  padding: 16px;
  min-height: 100vh;
  background: #ffffff;
}

.panel {
  background: var(--hcp-surface);
  border: 1px solid var(--hcp-line);
  box-shadow: var(--shadow);
}

.input-panel,
.output-panel {
  padding: 18px;
  overflow: auto;
  max-height: calc(100vh - 32px);
}

.viewer-panel {
  display: grid;
  grid-template-rows: auto auto minmax(520px, 1fr) auto;
  position: relative;
  overflow: hidden;
  max-height: calc(100vh - 32px);
}

.panel-heading,
.viewer-header {
  margin-bottom: 16px;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--hcp-red);
  text-transform: uppercase;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.76rem;
}

.viewer-title-line,
.panel-title-line {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-title-detail {
  color: var(--hcp-muted);
  text-transform: none;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  color: var(--hcp-burgundy);
}

h1,
h2 {
  margin-bottom: 0;
  font-size: clamp(1.32rem, 2.4vw, 1.82rem);
  font-weight: 700;
}

h3 {
  font-size: 1rem;
  margin-bottom: 10px;
  font-weight: 700;
}

.drop-zone {
  border: 1px dashed rgba(0, 89, 128, 0.48);
  background: var(--hcp-blue-soft);
  min-height: 144px;
  padding: 18px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 8px;
  cursor: pointer;
  color: var(--hcp-blue);
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.drop-zone.dragging,
.drop-zone:hover {
  border-color: var(--hcp-red);
  background: #ffffff;
  box-shadow: 0 0 0 4px var(--hcp-red-soft);
}

.file-prompt,
.file-loaded {
  min-height: 104px;
  width: 100%;
  display: grid;
  place-items: center;
  gap: 8px;
}

.file-loaded {
  grid-template-columns: auto minmax(0, 1fr) auto;
  min-height: 72px;
  text-align: left;
  cursor: default;
}

.file-loaded > strong {
  justify-self: stretch;
  color: var(--hcp-burgundy);
  font-family: var(--font-display);
  overflow-wrap: anywhere;
}

.clear-file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  border: 1px solid rgba(214, 0, 56, 0.3);
  border-radius: 2px;
  background: #ffffff;
  color: var(--hcp-red);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.clear-file-button:hover {
  background: var(--hcp-red);
  color: #ffffff;
}

.file-prompt[hidden],
.file-loaded[hidden] {
  display: none;
}

.drop-zone input {
  display: none;
}

.drop-zone svg {
  width: 34px;
  height: 34px;
  color: var(--hcp-red);
}

.drop-zone strong {
  color: var(--hcp-burgundy);
  font-family: var(--font-display);
}

.drop-zone span,
.file-status,
.helper,
.viewer-instructions,
.clip-axis span,
.notice,
td,
th {
  color: var(--hcp-muted);
}

.viewer-instructions {
  text-transform: none;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
}

#gridScaleLabel {
  display: inline-block;
  margin-left: 6px;
  color: var(--hcp-blue);
  font-weight: 700;
}

.file-status {
  min-height: 20px;
  margin: 10px 0 16px;
  font-size: 0.88rem;
}

.file-status:empty {
  display: none;
}

.input-warning {
  color: var(--hcp-red);
  font-size: 0.78rem;
  line-height: 1.3;
}

.field-grid {
  display: grid;
  gap: 12px;
}

.field-grid.two {
  grid-template-columns: 1fr 1fr;
}

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

.field > span,
.slider-field > span,
.radio-group legend {
  color: var(--hcp-ink);
  font-family: var(--font-display);
  font-weight: 700;
}

select,
input[type="number"],
textarea {
  width: 100%;
  color: var(--hcp-ink);
  background: #ffffff;
  border: 1px solid #cfd5da;
  border-radius: var(--radius);
  min-height: 42px;
  padding: 10px 12px;
}

select:focus,
input[type="number"]:focus,
textarea:focus {
  outline: 3px solid rgba(0, 89, 128, 0.16);
  border-color: var(--hcp-blue);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--hcp-red);
}

.material-summary {
  border-left: 4px solid var(--hcp-red);
  background: var(--hcp-red-soft);
  padding: 12px;
  margin: -4px 0 14px;
  color: var(--hcp-muted);
}

.material-summary strong {
  color: var(--hcp-burgundy);
}

.material-summary a {
  color: var(--hcp-blue);
  font-weight: 700;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--hcp-ink);
  font-weight: 700;
  margin-bottom: 14px;
}

.check-row input {
  margin-top: 4px;
  accent-color: var(--hcp-red);
}

.nre-toggle {
  padding: 10px 12px;
  border: 1px solid var(--hcp-line);
  border-radius: var(--radius);
  background: var(--hcp-soft);
}

.multi-material {
  background: var(--hcp-soft);
  border: 1px solid var(--hcp-line);
  padding: 12px;
  margin-bottom: 14px;
}

.multi-material[hidden] {
  display: none;
}

.helper {
  font-size: 0.88rem;
  line-height: 1.45;
  margin-bottom: 14px;
}

.radio-group {
  border: 1px solid var(--hcp-line);
  border-radius: var(--radius);
  padding: 12px;
  margin: 0 0 14px;
}

.compact-group legend span {
  color: var(--hcp-muted);
  font-family: var(--font-body);
  font-weight: 500;
}

.segmented-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.segmented-options label {
  margin: 0;
  display: block;
  position: relative;
}

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

.segmented-options span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  min-width: 116px;
  border: 1px solid var(--hcp-line);
  border-radius: var(--radius);
  color: var(--hcp-blue);
  background: #ffffff;
  padding: 8px 14px;
  font-family: var(--font-display);
  font-weight: 700;
  white-space: nowrap;
}

.material-mode-group .segmented-options span {
  min-height: 34px;
  min-width: 0;
  padding: 7px 12px;
  font-size: 0.92rem;
}

.build-plate-group .segmented-options span {
  min-width: 88px;
  padding-inline: 22px;
}

.segmented-options input:checked + span {
  color: #ffffff;
  background: var(--hcp-blue);
  border-color: var(--hcp-blue);
}

.radio-group label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 12px;
  color: var(--hcp-muted);
  line-height: 1.35;
}

.radio-group input {
  accent-color: var(--hcp-red);
}

.radio-group strong {
  display: block;
  color: var(--hcp-ink);
  margin-bottom: 2px;
}

.notice {
  border: 1px solid var(--hcp-line);
  background: var(--hcp-soft);
  padding: 12px;
  line-height: 1.45;
  border-radius: var(--radius);
}

.privacy {
  border-left: 4px solid var(--hcp-blue);
}

.disclaimer {
  margin-top: 16px;
  font-size: 0.86rem;
}

.disclaimer a {
  color: var(--hcp-blue);
  font-weight: 800;
}

.cta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.icon-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  min-height: 40px;
  padding: 10px 12px;
  color: #ffffff;
  background: var(--hcp-blue);
  font-family: var(--font-display);
  font-weight: 700;
}

.icon-button {
  min-width: 88px;
  color: var(--hcp-blue);
  background: #ffffff;
  border: 1px solid rgba(0, 89, 128, 0.36);
}

.primary-button:hover {
  background: #003f5a;
}

.icon-button:hover {
  color: #ffffff;
  background: var(--hcp-blue);
}

.icon-button.is-active {
  color: #ffffff;
  background: var(--hcp-blue);
}

.viewer-stage {
  position: relative;
  min-height: 520px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(246, 248, 249, 0.8)),
    #ffffff;
}

.view-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 18px 12px;
  align-items: center;
}

.view-button {
  min-height: 34px;
  border: 1px solid rgba(0, 89, 128, 0.24);
  border-radius: 999px;
  background: #ffffff;
  color: var(--hcp-blue);
  padding: 6px 12px;
  font-family: var(--font-display);
  font-weight: 700;
}

.view-button:hover {
  background: var(--hcp-blue);
  color: #ffffff;
}

.view-button svg {
  width: 16px;
  height: 16px;
}

.view-command {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: var(--radius);
}

.view-command.is-active {
  color: #ffffff;
  background: var(--hcp-blue);
}

#viewerCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewer-badge {
  display: none;
}

.clip-panel,
.rotate-panel {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 3;
  border: 1px solid rgba(0, 89, 128, 0.24);
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  gap: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 12px 26px rgba(21, 21, 21, 0.14);
  max-height: calc(100% - 28px);
  overflow: auto;
}

.clip-panel[hidden],
.rotate-panel[hidden] {
  display: none;
}

.clip-axis,
.rotate-axis {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 90px;
  gap: 8px;
  align-items: center;
}

.clip-axis div,
.rotate-axis div {
  display: grid;
  gap: 1px;
}

.clip-axis strong,
.rotate-axis strong {
  color: var(--hcp-ink);
  font-family: var(--font-display);
  font-size: 0.84rem;
}

.clip-axis span,
.rotate-axis span {
  font-size: 0.72rem;
}

.angle-input {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 0.82rem;
}

.heatmap-legend {
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 3;
  display: grid;
  grid-template-columns: auto 92px auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid rgba(0, 89, 128, 0.24);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  color: var(--hcp-muted);
  font-size: 0.76rem;
  box-shadow: 0 10px 22px rgba(21, 21, 21, 0.12);
}

.heatmap-legend[hidden] {
  display: none;
}

.heatmap-ramp {
  display: block;
  width: 92px;
  height: 9px;
  border-radius: 999px;
  background: linear-gradient(90deg, #d60038, #be7f37, #005980);
}

.calculation-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(21, 21, 21, 0.42);
}

.calculation-overlay[hidden] {
  display: none;
}

.calculation-dialog {
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  border: 1px solid rgba(0, 89, 128, 0.26);
  border-top: 5px solid var(--hcp-blue);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 22px 46px rgba(21, 21, 21, 0.22);
  padding: 18px;
}

.calculation-dialog strong {
  color: var(--hcp-burgundy);
  font-family: var(--font-display);
}

.calculation-dialog span {
  color: var(--hcp-muted);
  line-height: 1.4;
}

.side-toggle {
  border: 1px solid rgba(0, 89, 128, 0.36);
  border-radius: var(--radius);
  min-height: 30px;
  color: var(--hcp-blue);
  background: #ffffff;
  font-family: var(--font-display);
  font-size: 0.76rem;
  font-weight: 700;
}

.side-toggle:hover {
  color: #ffffff;
  background: var(--hcp-blue);
}

.estimate-total {
  border-top: 5px solid var(--hcp-blue);
  background: var(--hcp-blue-soft);
  padding: 16px;
  margin-bottom: 16px;
}

.estimate-total span,
.estimate-total small {
  display: block;
  color: var(--hcp-gray);
}

.estimate-total strong {
  display: block;
  margin: 4px 0;
  color: var(--hcp-blue);
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  line-height: 1;
  overflow-wrap: anywhere;
}

.chart-wrap {
  display: grid;
  grid-template-columns: minmax(140px, 210px) 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

#costPie {
  width: 100%;
  max-width: 210px;
  height: auto;
}

.pie-legend {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.pie-legend li {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 8px;
  align-items: center;
  color: var(--hcp-muted);
  font-size: 0.86rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.table-block {
  margin-bottom: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border: 1px solid var(--hcp-line);
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--hcp-soft-line);
  font-size: 0.9rem;
}

th {
  color: var(--hcp-burgundy);
  font-family: var(--font-display);
  font-weight: 700;
  background: var(--hcp-soft);
}

td:last-child,
th:last-child {
  text-align: right;
}

tr.highlight-quantity td {
  background: var(--hcp-blue-soft);
  color: var(--hcp-ink);
  font-weight: 800;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.metrics-details {
  border-top: 1px solid var(--hcp-line);
  background: #ffffff;
  padding: 0 18px 18px;
}

.metrics-details[open] {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  max-height: min(78vh, 620px);
  overflow: auto;
  border-top: 1px solid rgba(0, 89, 128, 0.28);
  box-shadow: 0 -16px 32px rgba(21, 21, 21, 0.14);
  scrollbar-gutter: stable;
}

.metrics-details summary {
  cursor: pointer;
  padding: 14px 0;
  color: var(--hcp-blue);
  font-family: var(--font-display);
  font-weight: 700;
}

.metrics-details[open] summary {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #ffffff;
}

.metrics-details .metrics-grid {
  margin-bottom: 0;
}

.metric-card {
  border: 1px solid var(--hcp-line);
  background: #ffffff;
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}

.metric-card span {
  display: block;
  color: var(--hcp-muted);
  font-size: 0.8rem;
}

.metric-card strong {
  display: block;
  color: var(--hcp-ink);
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.insight-box {
  border: 1px solid rgba(0, 89, 128, 0.28);
  background: var(--hcp-blue-soft);
  border-left: 4px solid var(--hcp-blue);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.insight-box h3 {
  margin-bottom: 8px;
}

.insight-box p {
  color: var(--hcp-muted);
  margin-bottom: 8px;
  line-height: 1.45;
}

.insight-box strong {
  color: var(--hcp-blue);
}

.pdf-row {
  margin: -4px 0 16px;
}

.quote-button {
  text-decoration: none;
}

@media (max-width: 1220px) {
  .app-shell {
    grid-template-columns: minmax(300px, 360px) minmax(420px, 1fr);
  }

  .output-panel {
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .input-panel,
  .output-panel,
  .viewer-panel {
    max-height: none;
  }

  .viewer-panel {
    grid-template-rows: auto auto minmax(430px, 64vh) auto;
  }

  .viewer-header {
    flex-direction: column;
  }

  .clip-axis,
  .rotate-axis {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .field-grid.two,
  .chart-wrap,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .estimate-total strong {
    font-size: 2rem;
  }
}
