/* STL price calculator (prices page only). Tokens come from styles.css :root.
   Layout, top to bottom: plates strip → model card (preview, position, numbers) next to its settings → order total. */

.section-calc {
  padding-top: 24px;
}

.section-calc .section-head {
  margin-bottom: 32px;
}

.calc [hidden] {
  display: none !important;
}

.calc {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.calc-model,
.calc-panel,
.calc-summary {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.calc-field > label,
.calc-field-head label,
.calc-label,
.calc-total > span {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* ---------- notices about files (unreadable, too big, too many) ---------- */

.calc-alert,
.calc-msg,
.calc-order-msg {
  display: grid;
  gap: 8px;
}

.calc-alert:empty,
.calc-msg:empty,
.calc-order-msg:empty {
  display: none;
}

.calc-alert span,
.calc-msg span,
.calc-order-msg span {
  padding-left: 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-2);
  border-left: 2px solid var(--accent);
}

.calc-alert {
  padding: 14px 16px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--panel);
}

.calc-alert span {
  color: var(--text);
}

/* ---------- plates: one model per plate ---------- */
/* A grid of cards, so every plate is in view at once (no sideways scrolling on a desktop);
   the "add a model" cell is always the last one. */

.calc-plates {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

.calc-plates-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.calc-plates-count {
  font-size: 13px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.calc-plates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
}

.calc-plates-list {
  display: contents;
}

.calc-plate {
  position: relative;
  display: flex;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  transition: border-color .2s ease, background .2s ease;
}

.calc-plate:hover {
  border-color: var(--text-3);
}

.calc-plate.is-active {
  border-color: var(--accent);
  background: linear-gradient(var(--accent-dim), var(--accent-dim)), var(--panel);
}

.calc-plate-pick {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px 12px 8px 8px;
  font: inherit;
  text-align: left;
  color: inherit;
  border: 0;
  border-radius: 12px;
  background: none;
  cursor: pointer;
}

.calc-plate-pick:focus-visible,
.calc-plate-del:focus-visible,
.calc-plate-add:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.calc-plate-thumb {
  flex: none;
  width: 58px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 9px;
  object-fit: cover;
  background: var(--bg-2);
}

.calc-plate.is-active .calc-plate-thumb {
  border-color: transparent;
}

.calc-plate-text {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
  min-width: 0;
}

.calc-plate-n {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 22px; /* the remove button sits in this corner */
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.calc-plate.is-active .calc-plate-n {
  color: var(--accent);
}

.calc-plate-own {
  padding: 2px 6px;
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
}

.calc-plate-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
}

.calc-plate-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.calc-plate-info {
  flex: 0 1000 auto; /* gives way first: the price must stay readable */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-3);
}

.calc-plate-sum {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* the model does not fit the bed: details are shown when the plate is opened */
.calc-plate.is-warn .calc-plate-sum::after {
  content: ' ⚠';
}

.calc-plate-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  font: 400 18px/1 var(--sans);
  color: var(--text-3);
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  transition: color .2s ease, background .2s ease;
}

.calc-plate-del:hover {
  color: var(--text);
  background: var(--line-2);
}

.calc-plate-add {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 76px;
  padding: 8px 12px 8px 8px;
  font: inherit;
  text-align: left;
  color: var(--text);
  border: 1px dashed var(--line-2);
  border-radius: 12px;
  background: none;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease;
}

.calc-plate-add:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.calc-plate-plus {
  flex: none;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  font: 400 26px/1 var(--sans);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: var(--accent-dim);
}

.calc-plate-add b {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.calc-plate-add small {
  font-size: 13px;
  color: var(--text-3);
}

/* ---------- model card + its settings ---------- */

.calc-main {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: start;
  gap: 14px;
}

.calc-model {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* the settings column can get long (advanced mode): keep the preview and its numbers in view */
@media (min-width: 961px) and (min-height: 700px) {
  .calc-model {
    position: sticky;
    top: calc(var(--header-h) + 14px);
  }
}

/* stage: drop zone, then the 3D preview */

.calc-stage {
  position: relative;
  display: flex;
  height: clamp(320px, 46vh, 480px);
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(closest-side, rgba(198, 244, 50, .06), transparent 75%),
    var(--bg-2);
  transition: background-color .2s ease;
}

.calc-stage.is-over {
  background-color: var(--panel-2);
}

.calc-drop {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 14px;
  padding: 32px 24px;
  text-align: center;
  border: 1px dashed var(--line-2);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .2s ease;
}

.calc-drop:hover,
.calc-drop:focus-within,
.calc-stage.is-over .calc-drop {
  border-color: var(--accent);
}

.calc-drop:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.calc-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.calc-drop-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 6px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--accent-dim);
  transition: transform .2s var(--ease);
}

.calc-drop-icon::before {
  content: 'STL';
  font: 500 14px/1 var(--display);
  color: var(--accent);
}

.calc-drop:hover .calc-drop-icon {
  transform: translateY(-3px);
}

.calc-drop-text {
  color: var(--text-2);
  max-width: 22em;
}

.calc-drop-text b {
  display: block;
  font-weight: 600;
  color: var(--text);
}

.calc-drop-hint {
  max-width: 26em;
  font-size: 13px;
  color: var(--text-3);
}

.calc-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: pan-y;
}

.calc-canvas:active {
  cursor: grabbing;
}

.calc-canvas.is-picking {
  cursor: crosshair;
}

.calc-canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* zoom buttons over the preview */
.calc-zoom {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  gap: 6px;
}

.calc-zoom button,
.calc-orient button {
  min-width: 38px;
  min-height: 38px;
  padding: 0 12px;
  font: 600 14px/1 var(--sans);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: rgba(12, 14, 15, .82);
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}

.calc-zoom button {
  padding: 0;
  font-size: 18px;
}

.calc-zoom button:hover,
.calc-orient button:hover:not(:disabled) {
  border-color: var(--accent);
}

/* file name and hints over the bottom edge of the preview */
.calc-bar {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(12, 14, 15, .82);
  pointer-events: none;
}

.calc-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.calc-legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}

.calc-legend::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: #dbe0e0;
}

.calc-legend[hidden] + .calc-hint {
  margin-left: auto;
}

.calc-hint {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
}

.calc-hint.is-on {
  color: var(--accent);
  white-space: normal;
}

.calc-other {
  flex: none;
  min-height: 34px;
  padding: 0 12px;
  font: 600 13px/1 var(--sans);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  pointer-events: auto;
  transition: border-color .2s ease;
}

.calc-other:hover {
  border-color: var(--accent);
}

/* position on the bed: right under the preview it changes */
.calc-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.calc-orient {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.calc-orient button {
  flex: 1 1 auto;
  background: var(--bg-2);
}

/* highlighted = how the model lies now (as in the file / as "Auto" laid it), or the face-picking mode is on */
.calc-orient .is-current,
.calc-orient [aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.calc-orient button:disabled {
  opacity: .4;
  cursor: default;
}

/* quantity and file units: they belong to the model on this plate, not to the print settings */
.calc-piece {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 24px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.calc-piece .calc-field {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.calc-piece .calc-qty,
.calc-piece .calc-unit {
  min-height: 42px;
}

.calc-qty:disabled,
.calc-unit:disabled {
  opacity: .45;
  cursor: default;
}

/* numbers of the open model */
.calc-out {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.calc-out > div {
  padding: 14px 18px;
  background: var(--panel);
}

.calc-out dt,
.calc-sum-stats dt {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-3);
}

.calc-out dd,
.calc-sum-stats dd {
  margin-top: 2px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.calc-msg {
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

/* ---------- settings of the open model ---------- */

.calc-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
}

.calc-h {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  font: 500 17px/1.2 var(--display);
  letter-spacing: -0.02em;
}

/* whose settings the form edits: common for all plates, or the open plate's own */
.calc-scope {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--bg-2);
}

.calc-scope button {
  display: grid;
  gap: 3px;
  padding: 9px 8px;
  font: inherit;
  text-align: center;
  color: var(--text-2);
  border: 1px solid transparent;
  border-radius: 9px;
  background: none;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}

.calc-scope b {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.calc-scope small {
  font-size: 12px;
  color: var(--text-3);
}

.calc-scope button:hover:not(:disabled) {
  border-color: var(--line-2);
}

.calc-scope [aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.calc-scope [aria-pressed="true"] b {
  color: var(--accent);
}

.calc-scope button:disabled {
  opacity: .45;
  cursor: default;
}

.calc-scope button:focus-visible,
.calc-own:focus-visible,
.calc-reset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.calc-scope-hint {
  margin-top: -6px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-3);
}

.calc-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 24px;
}

/* a parameter the open plate overrides */
.calc-field.is-own .calc-field-head label,
.calc-field.is-own .calc-field-head .calc-label {
  color: var(--accent);
}

.calc-own {
  flex: none;
  padding: 5px 9px;
  font: 600 12px/1 var(--sans);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-dim);
  cursor: pointer;
  transition: background .2s ease, color .2s ease;
}

.calc-own:hover {
  color: var(--accent-ink);
  background: var(--accent);
}


.calc-field {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 0;
}

.calc-mat,
.calc-unit,
.calc-support,
.calc-qty,
.calc-walls {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  font: 500 16px/1 var(--sans);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background-color: var(--bg-2);
  transition: border-color .2s ease;
}

.calc-mat,
.calc-unit,
.calc-support {
  appearance: none;
  padding-right: 38px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent) 50%),
    linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.calc-mat option,
.calc-unit option,
.calc-support option {
  background: var(--panel);
}

.calc-mat:hover,
.calc-unit:hover,
.calc-support:hover,
.calc-qty:hover,
.calc-walls:hover,
.calc-mat:focus,
.calc-unit:focus,
.calc-support:focus,
.calc-qty:focus,
.calc-walls:focus {
  border-color: var(--accent);
}

.calc-qty,
.calc-walls {
  font-variant-numeric: tabular-nums;
}

.calc-seg {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.calc-seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.calc-seg span {
  display: grid;
  gap: 4px;
  padding: 10px 6px;
  text-align: center;
  font-size: 13px;
  color: var(--text-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--bg-2);
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}

.calc-seg b {
  font: 500 15px/1 var(--display);
  color: var(--text);
  white-space: nowrap;
}

.calc-seg span:hover {
  border-color: var(--text-3);
}

.calc-seg input:checked + span {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.calc-seg input:checked + span b {
  color: var(--accent);
}

.calc-seg input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* advanced mode: switch + extra settings */

.calc-mode {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--bg-2);
  cursor: pointer;
  transition: border-color .2s ease;
}

.calc-mode:hover {
  border-color: var(--text-3);
}

.calc-mode input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.calc-switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--line-2);
  transition: background .2s ease;
}

.calc-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  transition: transform .2s var(--ease), background .2s ease;
}

.calc-mode input:checked + .calc-switch {
  background: var(--accent);
}

.calc-mode input:checked + .calc-switch::after {
  background: var(--accent-ink);
  transform: translateX(18px);
}

.calc-mode input:focus-visible + .calc-switch {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.calc-mode-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.calc-mode-text b {
  font-weight: 600;
  color: var(--text);
}

.calc-mode-text small {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-3);
}

.calc-adv {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.calc-range {
  display: flex;
  align-items: center;
  gap: 14px;
}

.calc-range input {
  flex: 1;
  min-width: 0;
  height: 28px;
  accent-color: var(--accent);
  cursor: pointer;
}

.calc-range output {
  flex: none;
  min-width: 3.2em;
  text-align: right;
  font: 500 15px/1 var(--display);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.calc-reset {
  align-self: flex-start;
  min-height: 34px;
  padding: 0;
  font: 500 14px/1 var(--sans);
  color: var(--text-2);
  text-decoration: underline;
  text-underline-offset: 3px;
  border: 0;
  background: none;
  cursor: pointer;
  transition: color .2s ease;
}

.calc-reset:hover {
  color: var(--accent);
}

/* ---------- order: everything on all plates ---------- */

.calc-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 380px);
  align-items: center;
  gap: 20px 32px;
  padding: 24px;
  border-color: var(--line-2);
}

.calc-sum-main,
.calc-sum-side {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.calc-total {
  display: grid;
  gap: 6px;
}

.calc-total output {
  font: 500 clamp(28px, 3.4vw, 44px)/1.1 var(--display);
  letter-spacing: -0.03em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.calc-sum-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 32px;
}

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

.calc-actions .btn {
  flex: 1 1 auto;
}

.calc-actions .calc-send {
  flex-basis: 100%;
}

.calc-save:disabled,
.calc-copy:disabled {
  opacity: .45;
  cursor: default;
  transform: none;
}

.calc-status {
  font-size: 14px;
  line-height: 1.5;
  color: var(--accent);
}

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

.calc-disclaimer {
  max-width: 76em;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-3);
}

@media (max-width: 960px) {
  .calc-zoom button,
  .calc-orient button,
  .calc-other {
    min-width: 42px;
    min-height: 42px;
  }

  .calc-main,
  .calc-summary {
    grid-template-columns: minmax(0, 1fr);
  }

  .calc-stage {
    height: clamp(300px, 46vh, 420px);
  }
}

@media (max-width: 600px) {
  .calc-stage {
    height: 300px;
  }

  /* on a phone the cards go in one swipeable row that runs to the screen edges; "add" stays under it */
  .calc-plates-grid {
    display: flex;
    flex-direction: column;
  }

  .calc-plates-list {
    position: relative;
    display: flex;
    gap: 10px;
    margin: 0 calc(var(--gutter) * -1);
    padding: 0 var(--gutter);
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scroll-padding: 0 var(--gutter);
    scrollbar-width: none;
  }

  .calc-plates-list::-webkit-scrollbar {
    display: none;
  }

  .calc-plate {
    flex: none;
    width: 272px;
    scroll-snap-align: start;
  }

  .calc-plate-add {
    min-height: 60px;
  }

  .calc-plate-plus {
    width: 44px;
    height: 44px;
  }

  .calc-tools .calc-label {
    flex-basis: 100%;
  }

  .calc-tools,
  .calc-piece,
  .calc-msg {
    padding: 12px 14px;
  }

  .calc-piece {
    gap: 12px;
  }

  .calc-piece .calc-field {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .calc-out {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .calc-out > div {
    padding: 12px 14px;
  }

  .calc-panel,
  .calc-summary {
    padding: 18px;
  }

  .calc-seg {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .calc-hint:not(.is-on),
  .calc-legend {
    display: none;
  }

  .calc-hint.is-on {
    margin-left: auto;
  }

  .calc-other {
    margin-left: auto;
  }
}
