/* Archivo (SIL OFL), self-hosted: no third-party requests. Latin covers Spanish. */
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  src: url('assets/fonts/archivo-latin-wdth-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Palette from the port: ink navy, customs-form paper, and container colours
   used only to carry meaning (cost groups, seller vs buyer). */
:root {
  --ink: #1B2A3A;
  --ink-soft: #46576A;
  --paper: #EDF1EE;
  --sheet: #F8FAF8;
  --line: rgba(27, 42, 58, 0.22);
  --line-strong: #1B2A3A;
  --steel: #2F6F9F;
  --signal: #F2B630;
  --rust: #B5532E;
  --harbour: #2E8B74;
  --slate: #6B7A89;
  --focus: #F2B630;
  --seller: var(--steel);
  --buyer: var(--signal);
  --radius: 3px;
  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #E3EAE6;
    --ink-soft: #A9B7C3;
    --paper: #0F1C27;
    --sheet: #162633;
    --line: rgba(227, 234, 230, 0.2);
    --line-strong: #C9D4DC;
    --steel: #5A9BCB;
    --rust: #D27652;
    --harbour: #4FB096;
    --slate: #8C9BA9;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.visually-hidden, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 10; background: var(--signal); color: #1B2A3A; padding: 6px 12px; }

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

/* ---- masthead ---------------------------------------------------------- */

.masthead {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 24px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.masthead h1 {
  margin: 0;
  font-stretch: 125%;
  font-weight: 800;
  font-size: clamp(2rem, 5.2vw, 3.6rem);
  line-height: 0.98;
  letter-spacing: -0.01em;
  max-width: 14ch;
}
.tagline {
  margin: 14px 0 0;
  max-width: 46ch;
  font-size: 1.125rem;
  color: var(--ink-soft);
}
.lang {
  flex: none;
  font: inherit;
  font-weight: 600;
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 6px 14px;
  cursor: pointer;
}
.lang:hover { background: var(--sheet); }

/* ---- layout ------------------------------------------------------------ */

.calc {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 430px);
  gap: 40px;
  align-items: start;
}
@media (max-width: 900px) {
  .calc { grid-template-columns: 1fr; gap: 28px; }
}

/* Each group is a box on a customs form: the legend sits in the border. */
.group {
  margin: 0 0 22px;
  padding: 18px 20px 20px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--sheet);
}
.group legend {
  padding: 0 8px;
  margin-left: -8px;
  font-stretch: 112%;
  font-weight: 700;
  font-size: 1.15rem;
}
.hint { margin: 0 0 14px; color: var(--ink-soft); max-width: 62ch; font-size: 0.95rem; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 560px) { .row-2 { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span:first-child { font-weight: 600; font-size: 0.95rem; }
.field small, .check small, .tax-row small { color: var(--ink-soft); font-size: 0.82rem; }
.field.inline { margin: 8px 0 0 30px; }

input, select {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-bottom: 2px solid var(--line-strong);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 8px 10px;
  min-height: 42px;
  width: 100%;
}
input:disabled { opacity: 0.7; border-bottom-style: dashed; }
input::placeholder { color: var(--slate); opacity: 0.8; font-size: 0.85rem; }

.money { position: relative; display: flex; align-items: stretch; }
.money .cur {
  display: flex; align-items: center;
  padding: 0 8px;
  font-size: 0.8rem; font-weight: 600;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-right: 0;
  border-bottom: 2px solid var(--line-strong);
  border-radius: var(--radius) 0 0 0;
  background: var(--sheet);
}
.money input { border-top-left-radius: 0; text-align: right; }
.money.pct { max-width: 140px; }
.money.pct .cur { border-right: 1px solid var(--line); border-left: 0; border-radius: 0 var(--radius) 0 0; order: 2; }
.money.pct input { border-radius: var(--radius) 0 0 0; }

/* Incoterm picker: a tight grid of codes. */
.terms { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.term, .seg label { position: relative; }
.term input, .seg input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; opacity: 0; pointer-events: none; }
.term span {
  display: block;
  text-align: center;
  padding: 8px 0;
  font-stretch: 112%;
  font-weight: 700;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--paper);
}
.term input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.term input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.term span:hover { border-color: var(--line-strong); }

/* Journey stages: a real sequence, so they are numbered. */
.stages { list-style: none; margin: 0 0 14px; padding: 0; counter-reset: stage; }
.stage {
  counter-increment: stage;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto 160px;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
}
.stage::before {
  content: counter(stage);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-align: right;
}
.stage-name { font-weight: 500; }
.badge {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--buyer) 30%, transparent);
  white-space: nowrap;
}
.stage.included .badge { background: color-mix(in srgb, var(--seller) 22%, transparent); }
.stage.included .stage-name { color: var(--ink-soft); }
@media (max-width: 560px) {
  .stage { grid-template-columns: 22px 1fr auto; }
  .stage .money { grid-column: 2 / -1; }
}

.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; cursor: pointer; }
.check input { width: 20px; min-height: 20px; height: 20px; margin-top: 2px; accent-color: var(--steel); flex: none; }
.check > span { display: flex; flex-direction: column; }

.seg { display: inline-flex; border: 1.5px solid var(--line-strong); border-radius: var(--radius); width: max-content; }
.seg label { cursor: pointer; }
.seg span { display: block; padding: 8px 16px; font-weight: 600; }
.seg input:checked + span { background: var(--ink); color: var(--paper); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); }

.taxes { display: grid; gap: 4px; margin-top: 4px; }
.tax-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  align-items: center;
  gap: 4px 12px;
  padding: 6px 0;
  border-top: 1px dashed var(--line);
}
.tax-row small { grid-column: 1 / -1; }

/* ---- result panel ------------------------------------------------------- */

.result {
  position: sticky;
  top: 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 24px 24px 20px;
  --line: rgba(237, 241, 238, 0.22);
}
@media (prefers-color-scheme: dark) {
  .result { background: #E3EAE6; color: #0F1C27; --line: rgba(15, 28, 39, 0.2); }
}
@media (max-width: 900px) { .result { position: static; } }
.result:focus { outline: none; }

.headline .label { margin: 0; font-weight: 600; opacity: 0.85; }
.headline .big {
  margin: 2px 0 0;
  font-stretch: 112%;
  font-weight: 800;
  font-size: clamp(2.1rem, 4vw, 2.9rem);
  line-height: 1.05;
  letter-spacing: -0.01em;
}
.headline .unit { margin: 4px 0 0; font-size: 1.15rem; font-weight: 600; }
.headline .local { margin: 4px 0 0; opacity: 0.8; font-size: 0.92rem; }

/* The container stack: each cost group is a corrugated box, width = share. */
.stack-wrap { margin: 22px 0 6px; }
.stack-wrap figcaption { font-weight: 600; font-size: 0.92rem; margin-bottom: 8px; opacity: 0.9; }
.stack { display: flex; gap: 3px; height: 58px; }
.box {
  flex-basis: 0;
  min-width: 6px;
  border-radius: 2px;
  background-color: var(--c);
  background-image:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.16) 0 2px, transparent 2px 4px, rgba(0, 0, 0, 0.12) 4px 5px, transparent 5px 9px);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.18), inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  transform-origin: left;
  animation: load 0.5s ease-out both;
}
.box:nth-child(2) { animation-delay: 0.06s; }
.box:nth-child(3) { animation-delay: 0.12s; }
.box:nth-child(4) { animation-delay: 0.18s; }
.box:nth-child(5) { animation-delay: 0.24s; }
@keyframes load { from { transform: scaleX(0.2); opacity: 0; } to { transform: none; opacity: 1; } }

.g-goods { --c: var(--steel); }
.g-origin { --c: var(--slate); }
.g-transport { --c: var(--harbour); }
.g-destination { --c: var(--rust); }
.g-taxes { --c: var(--signal); }

.legend { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 3px; font-size: 0.9rem; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto 64px; gap: 8px; align-items: center; }
.legend .sw { width: 12px; height: 12px; border-radius: 2px; background: var(--c); }
.legend .am, .legend .sh { text-align: right; white-space: nowrap; }
.legend .sh { opacity: 0.75; }
.legend li.zero { opacity: 0.45; }

.figures { margin: 18px 0 8px; display: grid; gap: 0; }
.figures div {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.figures dt { display: flex; flex-direction: column; font-size: 0.92rem; }
.figures dt small { opacity: 0.7; font-size: 0.78rem; }
.figures dd { margin: 0; font-weight: 700; white-space: nowrap; }

.tax-detail { border-top: 1px solid var(--line); padding-top: 10px; font-size: 0.88rem; }
.tax-detail summary { cursor: pointer; font-weight: 600; }
.tax-detail table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.tax-detail th, .tax-detail td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); font-weight: 400; }
.tax-detail th[scope="row"], .tax-detail thead th:first-child { text-align: left; }
.tax-detail thead th { font-weight: 600; opacity: 0.8; }
.tag { font-size: 0.72rem; padding: 0 6px; border-radius: 999px; border: 1px solid currentColor; opacity: 0.8; white-space: nowrap; }
.note { opacity: 0.85; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 10px; }
.actions button {
  font: inherit; font-size: 0.9rem; font-weight: 600;
  color: inherit;
  background: transparent;
  border: 1.5px solid currentColor;
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
}
.actions button:first-child { background: var(--signal); color: #1B2A3A; border-color: var(--signal); }
.actions button.quiet { border-color: transparent; text-decoration: underline; padding-inline: 4px; }
.disclaimer { margin: 0; font-size: 0.8rem; opacity: 0.75; }

/* ---- Incoterms explorer ----------------------------------------------- */

.explorer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 24px 56px;
  border-top: 1.5px solid var(--line-strong);
}
.explorer-head h2 { margin: 0; font-stretch: 125%; font-weight: 800; font-size: clamp(1.6rem, 3.4vw, 2.4rem); }
.explorer-head p { margin: 6px 0 18px; color: var(--ink-soft); }
.terms-big { grid-template-columns: repeat(11, minmax(0, 1fr)); max-width: 820px; }
@media (max-width: 760px) { .terms-big { grid-template-columns: repeat(6, 1fr); } }

.route { margin: 26px 0 10px; overflow-x: auto; padding-bottom: 6px; }
.places, .strip { min-width: 820px; }
.places {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  font-size: 0.82rem; font-weight: 600; color: var(--ink-soft);
  margin-bottom: 6px;
}
.places span { border-left: 2px solid var(--line-strong); padding-left: 6px; }
.places span:nth-child(1), .places span:nth-child(3), .places span:nth-child(4), .places span:nth-child(5) { grid-column: span 2; }
.strip { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; position: relative; }
.cell {
  position: relative;
  min-height: 92px;
  padding: 8px 8px 6px;
  border-radius: 2px;
  display: flex; flex-direction: column; justify-content: space-between;
  font-size: 0.8rem; line-height: 1.25;
}
.cell.seller { background: var(--seller); color: #F8FAF8; }
.cell.buyer { background: var(--buyer); color: #1B2A3A; }
.cell-payer { font-weight: 700; font-stretch: 112%; }
/* Markers: a flag where risk passes, a bracket where seller costs end. */
.cell.risk-after::after, .strip.risk-start::before {
  content: '';
  position: absolute;
  top: -10px; bottom: -10px;
  right: -3px;
  width: 4px;
  background: var(--rust);
  border-radius: 2px;
}
.strip.risk-start::before { left: -6px; right: auto; }
.cell.cost-after { box-shadow: inset -5px 0 0 var(--ink); }
.route-keys { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 0.85rem; margin: 14px 0 0; }
.route-keys span { display: inline-flex; align-items: center; gap: 8px; }
.k-risk::before { content: ''; width: 4px; height: 18px; background: var(--rust); border-radius: 2px; }
.k-cost::before { content: ''; width: 14px; height: 18px; background: var(--seller); box-shadow: inset -5px 0 0 var(--ink); border-radius: 2px; }

.term-text { max-width: 70ch; margin-top: 18px; }
.term-name { margin: 0; font-stretch: 125%; font-weight: 800; font-size: 1.6rem; }
.term-text p { margin: 4px 0 0; }
.mode { color: var(--ink-soft); font-size: 0.9rem; }

.foot { max-width: 1180px; margin: 0 auto; padding: 0 24px 40px; color: var(--ink-soft); font-size: 0.9rem; }

/* ---- small screens: result bar ---------------------------------------- */

.minibar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: none;
  justify-content: space-between;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--paper);
  font-weight: 700;
  cursor: pointer;
  z-index: 5;
}
.minibar.show { display: flex; }
@media (prefers-color-scheme: dark) { .minibar { background: #E3EAE6; color: #0F1C27; } }

.toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: var(--signal); color: #1B2A3A; font-weight: 600;
  padding: 8px 16px; border-radius: var(--radius); z-index: 6;
}

@media (prefers-reduced-motion: reduce) {
  .box { animation: none; }
  html { scroll-behavior: auto; }
}

@media print {
  body { background: #fff; color: #000; }
  .masthead .lang, .explorer, .actions, .minibar, .skip, .foot { display: none !important; }
  .calc { grid-template-columns: 1fr 1fr; gap: 16px; padding: 0; }
  .group { break-inside: avoid; background: #fff; }
  .result { position: static; background: #fff; color: #000; border: 1.5px solid #000; --line: #999; }
  .box { animation: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .legend .sw { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Phones: the route reads top to bottom instead of scrolling sideways. */
@media (max-width: 640px) {
  .places { display: none; }
  .places, .strip { min-width: 0; }
  .strip { grid-template-columns: 1fr; gap: 3px; }
  .cell { min-height: 0; flex-direction: row; align-items: center; gap: 12px; padding: 10px 12px; }
  .cell.risk-after::after { top: auto; bottom: -5px; left: -8px; right: -8px; width: auto; height: 4px; }
  .strip.risk-start::before { top: -7px; bottom: auto; left: -8px; right: -8px; width: auto; height: 4px; }
  .cell.cost-after { box-shadow: inset 0 -5px 0 var(--ink); }
  .k-risk::before { width: 18px; height: 4px; }
  .k-cost::before { box-shadow: inset 0 -5px 0 var(--ink); }
}
@media (max-width: 900px) { body { padding-bottom: 64px; } }
