/* Calculadora de Precificação
   Tokens: mesa de aço (fundo), folha (painéis), tinta, PEI dourado (lucro),
   e uma cor de filamento por camada de custo. */

:root {
  --plate: #E6E8EB;
  --sheet: #FFFFFF;
  --ink: #15171C;
  --muted: #5D636D;
  --rule: #D3D7DD;
  --field: #F4F5F7;
  --pei: #B8862B;
  --pei-deep: #8C6316;
  --loss: #CF3F2B;

  --f-filamento: #2E9C74;
  --f-energia: #E3AE1E;
  --f-desgaste: #6C7A89;
  --f-acabamento: #C46A9A;
  --f-embalagem: #A08463;
  --f-frete: #3A6BD4;
  --f-imposto: #7D55C7;
  --f-taxa: #DD5A35;

  --display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --body: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Martian Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --radius: 6px;
  --gutter: clamp(16px, 4vw, 40px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --plate: #111317;
    --sheet: #1A1D23;
    --ink: #ECEEF1;
    --muted: #9AA1AC;
    --rule: #2B3038;
    --field: #22262D;
    --pei: #D3A447;
    --pei-deep: #E8C072;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --plate: #111317;
  --sheet: #1A1D23;
  --ink: #ECEEF1;
  --muted: #9AA1AC;
  --rule: #2B3038;
  --field: #22262D;
  --pei: #D3A447;
  --pei-deep: #E8C072;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--plate);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  font-variation-settings: "wdth" 100;
}

:focus-visible { outline: 2px solid var(--pei); outline-offset: 2px; }

/* ---------- Topo ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 32px;
  padding: 28px var(--gutter) 20px;
  max-width: 1240px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 34px; height: 34px; fill: var(--ink); }
.brand-mark .l1 { fill: var(--pei); }
.brand-mark .l2 { fill: var(--f-filamento); }
.brand-name {
  font-family: var(--display);
  font-variation-settings: "wdth" 125;
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.01em;
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand-sub {
  font-variation-settings: "wdth" 62;
  font-weight: 500;
  font-size: 18px;
  color: var(--muted);
}
.top-lede { margin: 0; color: var(--muted); max-width: 46ch; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 440px);
  gap: 24px;
  align-items: start;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 var(--gutter) 48px;
}

/* ---------- Formulário ---------- */
.inputs { display: grid; gap: 14px; min-width: 0; }

.group {
  margin: 0;
  min-width: 0;
  padding: 20px 22px 18px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
}
.group-title {
  float: left;
  width: 100%;
  margin: 0 0 14px;
  padding: 0;
  font-family: var(--display);
  font-variation-settings: "wdth" 125;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.group-title + * { clear: both; }

.row { display: grid; gap: 12px; margin-top: 12px; }
.row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.field { display: grid; gap: 5px; min-width: 0; }
.field-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.input {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--field);
  transition: border-color .15s, background .15s;
}
.input:focus-within { border-color: var(--pei); background: var(--sheet); }
.input input {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-variation-settings: "wdth" 87.5;
  font-size: 14px;
  padding: 0;
  outline: none;
}
.input b, .input i {
  font-style: normal;
  font-weight: 500;
  font-family: var(--mono);
  font-variation-settings: "wdth" 75;
  font-size: 11.5px;
  color: var(--muted);
}
.input-big { height: 50px; }
.input-big input { font-size: 18px; font-weight: 600; }

.note { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); }
.note:empty { display: none; }

/* Impressoras: cartões com a barra de consumo relativo (190 W = cheia) */
.printers { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.printer { position: relative; cursor: pointer; min-width: 0; }
.printer input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.printer span {
  display: grid;
  gap: 1px;
  height: 100%;
  padding: 10px 12px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  transition: border-color .15s, background .15s, color .15s;
}
.printer small { font-size: 11.5px; color: var(--muted); line-height: 1.2; }
.printer b { font-size: 14px; font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.printer em {
  font-style: normal;
  font-family: var(--mono);
  font-variation-settings: "wdth" 87.5;
  font-size: 11.5px;
  color: var(--muted);
}
.printer i {
  display: block;
  height: 4px;
  margin-top: 7px;
  border-radius: 2px;
  background: linear-gradient(var(--f-energia), var(--f-energia)) 0 0 / var(--w) 100% no-repeat, var(--field);
}
.printer-other span { border-style: dashed; }
.printer:hover span { border-color: var(--muted); }
.printer input:checked + span { border-color: var(--ink); background: var(--ink); color: var(--sheet); }
.printer input:checked + span small,
.printer input:checked + span em { color: inherit; opacity: .7; }
.printer input:checked + span i { background: linear-gradient(var(--pei), var(--pei)) 0 0 / var(--w) 100% no-repeat, rgba(127,127,127,.35); }
.printer input:focus-visible + span { outline: 2px solid var(--pei); outline-offset: 2px; }
.printers + .row { margin-top: 12px; }

/* Canais e modos: botões segmentados */
.channels { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.channel, .mode { position: relative; cursor: pointer; }
.channel input, .mode input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.channel span, .mode span {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.25;
  transition: border-color .15s, background .15s, color .15s;
}
.channel small { font-weight: 400; color: var(--muted); font-size: 12px; }
.channel:hover span, .mode:hover span { border-color: var(--muted); }
.channel input:checked + span, .mode input:checked + span {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--sheet);
}
.channel input:checked + span small { color: inherit; opacity: .7; }
.channel input:focus-visible + span, .mode input:focus-visible + span { outline: 2px solid var(--pei); outline-offset: 2px; }

.reset {
  justify-self: start;
  border: 0;
  background: none;
  padding: 4px 0;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.reset:hover { color: var(--ink); }

/* ---------- Peças salvas ---------- */
.save-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}
.btn {
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--sheet);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn:hover { background: var(--pei-deep); color: #fff; }
.status { margin: 8px 0 0; font-size: 13px; color: var(--pei-deep); min-height: 0; }
.status:empty { display: none; }

.saved { margin-top: 14px; border-top: 1px solid var(--rule); padding-top: 12px; }
.saved summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  list-style: none;
}
.saved summary::-webkit-details-marker { display: none; }
.saved summary::before {
  content: "";
  width: 7px; height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .15s;
}
.saved[open] summary::before { transform: rotate(45deg); }
.count {
  font-family: var(--mono);
  font-variation-settings: "wdth" 75;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--field);
  color: var(--muted);
}

.piece-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.piece {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.piece-open {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.piece-open:hover { background: var(--field); }
.piece-text { display: grid; min-width: 0; }
.piece-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.piece-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.piece-result {
  font-family: var(--mono);
  font-variation-settings: "wdth" 87.5;
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  color: var(--pei-deep);
  font-variant-numeric: tabular-nums;
}
.piece-result small { display: block; font-size: 10.5px; font-weight: 400; color: var(--muted); }
.piece-result.is-loss { color: var(--loss); }
.piece-del {
  border: 0;
  border-left: 1px solid var(--rule);
  background: none;
  padding: 0 12px;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.piece-del:hover { color: var(--loss); background: var(--field); }
.piece-del[data-armed="1"] { color: #fff; background: var(--loss); }

.backup { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; }
.link {
  border: 0;
  background: none;
  padding: 2px 0;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--ink); }
.link:focus-within { outline: 2px solid var(--pei); outline-offset: 2px; }

/* ---------- Resultado ---------- */
.result {
  position: sticky;
  top: calc(16px + env(safe-area-inset-top, 0px));
  display: grid;
  gap: 0;
  border-radius: var(--radius);
  background: var(--sheet);
  border: 1px solid var(--rule);
  overflow: hidden;
}

.verdict { padding: 22px 24px 18px; border-bottom: 1px solid var(--rule); }
.verdict-label {
  margin: 0;
  font-family: var(--display);
  font-variation-settings: "wdth" 125;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.verdict-value {
  margin: 4px 0 2px;
  font-family: var(--display);
  font-variation-settings: "wdth" 112;
  font-weight: 800;
  font-size: clamp(40px, 6vw, 56px);
  letter-spacing: -0.02em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--pei-deep);
}
.result.is-loss .verdict-value { color: var(--loss); }
.verdict-meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-family: var(--mono);
  font-variation-settings: "wdth" 87.5;
  font-size: 12.5px;
  color: var(--muted);
}
.verdict-meta .dot { opacity: .5; }

/* A fatia: o preço empilhado em camadas */
.slice {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--rule);
}
.slice-stage { position: relative; display: grid; grid-template-rows: minmax(300px, 1fr) auto; }
.slice-axis {
  position: absolute;
  left: 0; top: 0; bottom: 10px;
  width: 100%;
  background: repeating-linear-gradient(to top, var(--rule) 0 1px, transparent 1px 26px);
  opacity: .55;
}
.stack {
  position: relative;
  margin: 0 18px;
  display: flex;
  flex-direction: column-reverse;
}
.layer {
  position: relative;
  flex: none;
  height: 0;
  background-color: var(--c);
  /* linhas de camada, como uma peça impressa vista de lado */
  background-image: repeating-linear-gradient(to bottom,
    rgba(255,255,255,.22) 0 1px, transparent 1px 3px,
    rgba(0,0,0,.10) 3px 4px);
  transition: height .55s cubic-bezier(.2,.7,.2,1), filter .15s, opacity .15s;
}
.layer + .layer { box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.layer-profit {
  background-color: var(--pei);
  background-image: repeating-linear-gradient(to bottom,
    rgba(255,255,255,.30) 0 1px, transparent 1px 3px,
    rgba(0,0,0,.12) 3px 4px);
}
.stack.is-hovering .layer { opacity: .35; }
.stack.is-hovering .layer.is-on { opacity: 1; }

.price-line {
  position: absolute;
  left: -18px; right: -18px;
  bottom: 0;
  height: 0;
  border-top: 1.5px dashed var(--ink);
  z-index: 3;
  transition: bottom .55s cubic-bezier(.2,.7,.2,1);
}
.price-line span {
  position: absolute;
  right: 0; top: 4px;
  font-family: var(--mono);
  font-variation-settings: "wdth" 75;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--sheet);
  padding: 0 3px;
}
.loss {
  position: absolute;
  left: 0; right: 0;
  z-index: 2;
  background: repeating-linear-gradient(135deg, rgba(207,63,43,.85) 0 5px, rgba(207,63,43,.35) 5px 10px);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.loss span {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--loss);
  padding: 1px 4px;
}

.nozzle {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 40px;
  transform: translate(-50%, -2px);
  z-index: 4;
  transition: bottom .55s cubic-bezier(.2,.7,.2,1);
  pointer-events: none;
}
.nozzle svg { display: block; width: 40px; height: 30px; fill: var(--ink); }
.nozzle .drip { fill: var(--pei); animation: drip 1.6s ease-in-out infinite; }
@keyframes drip { 0%, 100% { opacity: 1; } 50% { opacity: .2; } }

.plate {
  height: 10px;
  border-radius: 2px;
  background:
    radial-gradient(circle, rgba(0,0,0,.18) 0.8px, transparent 1.2px) 0 0 / 4px 4px,
    linear-gradient(var(--pei), var(--pei-deep));
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  gap: 2px;
  min-width: 0;
}
.legend li {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  margin: 0 -6px;
  border-radius: 4px;
  cursor: default;
  font-size: 13px;
}
.legend li:hover, .legend li.is-on { background: var(--field); }
.legend .chip { width: 10px; height: 10px; border-radius: 2px; background: var(--c); }
.legend .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend .val {
  font-family: var(--mono);
  font-variation-settings: "wdth" 87.5;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.legend .val small { display: block; color: var(--muted); font-size: 10px; }
.legend .is-profit { font-weight: 700; }
.legend .is-profit .val { color: var(--pei-deep); }
.result.is-loss .legend .is-profit .val { color: var(--loss); }
.result.is-loss .legend .is-profit .chip { background: var(--loss); }
.legend .is-zero { opacity: .45; }

.facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; }
.fact { margin: 0; padding: 16px 24px; border-top: 1px solid var(--rule); }
.fact:nth-child(2) { border-right: 1px solid var(--rule); }
.fact-wide { grid-column: 1 / -1; border-top: 0; }
.fact dt { font-size: 12.5px; color: var(--muted); }
.fact dd {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-variation-settings: "wdth" 100;
  font-weight: 600;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.fact-wide dd { font-size: 24px; }
.fact-note { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.fact-note:empty { display: none; }

/* ---------- Rodapé ---------- */
.foot {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 var(--gutter) 40px;
  font-size: 12.5px;
  color: var(--muted);
}
.foot p { margin: 0; max-width: 72ch; }

/* ---------- Barra fixa no celular ---------- */
.dock { display: none; }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .result { position: static; }
  .dock {
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 10;
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--ink);
    color: var(--sheet);
    text-decoration: none;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
    transition: opacity .2s, transform .2s;
  }
  .dock.is-hidden { opacity: 0; transform: translateY(12px); pointer-events: none; }
  .dock-label { font-size: 12.5px; opacity: .75; }
  .dock-value {
    margin-left: auto;
    font-family: var(--display);
    font-variation-settings: "wdth" 112;
    font-weight: 800;
    font-size: 20px;
    font-variant-numeric: tabular-nums;
    color: var(--pei);
  }
  .dock.is-loss .dock-value { color: #FF7A63; }
  .dock-margin { font-family: var(--mono); font-size: 12px; opacity: .75; }
  .foot { padding-bottom: 96px; }
}

@media (max-width: 640px) {
  .channels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .printers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-3, .row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-3 > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .group { padding: 18px 16px 16px; }
  .slice { grid-template-columns: 104px minmax(0, 1fr); gap: 14px; padding: 20px 16px; }
  .slice-stage { grid-template-rows: minmax(260px, 1fr) auto; }
  .stack { margin: 0 12px; }
  .price-line { left: -12px; right: -12px; }
  .verdict, .fact { padding-left: 16px; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .layer, .price-line, .nozzle, .dock { transition: none; }
  .nozzle .drip { animation: none; }
}

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.input input[name="nome"] { font-family: var(--body); font-variation-settings: "wdth" 100; font-size: 15px; }
.top-link { color: var(--pei-deep); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }
.top-link:hover { color: var(--ink); }
