/* ==========================================================================
   Portex Global — product widgets + data palette
   Card language follows the "technical UI" references: soft dark surfaces,
   rounded cards, mono data, rolling digits, dotted textures, glow on activity.
   ========================================================================== */

:root {
  /* Categorical data palette (freight cost categories).
     Validated for the dark surface #141514: lightness band, chroma,
     adjacent-pair CVD ΔE ≥ 12.7, normal-vision ΔE ≥ 15.2, contrast ≥ 3:1.
     Use in this fixed order; never cycle. */
  --cat-1: #3D7BEA; /* ocean   */
  --cat-2: #22A3B5; /* air     */
  --cat-3: #8763E8; /* rail    */
  --cat-4: #B08C1E; /* customs */
  --cat-5: #D2427F; /* road    */
  --cat-6: #D9701F; /* D&D     */

  /* Status — reserved, never a series colour */
  --ok: #56F24E;
  --fail: #F0524A;

  /* Widget surfaces */
  --w-surface: #141514;
  --w-panel: #1B1C1B;
  --w-raised: #232423;
  --w-hair: rgba(255, 255, 255, .07);
  --w-ink: #ECEEE8;
  --w-ink-2: #A3A8A0;
  --w-ink-3: #858A82;   /* ≥ 4.5:1 on the card surfaces */
  /* Berkeley Mono (file in use) swaps '/' for '\\' — widgets use Geist Mono for code/data */
  --f-code: "Geist Mono", ui-monospace, Menlo, monospace;
}

/* ---------- Rolling digits ---------- */
.num { font-variant-numeric: tabular-nums; }
.num .d { display: inline-block; }
.num .d.roll { animation: digit-roll .42s cubic-bezier(.2, .8, .2, 1); }
@keyframes digit-roll {
  0% { transform: translateY(-.45em); filter: blur(2.5px); opacity: .15; }
  100% { transform: none; filter: none; opacity: 1; }
}

/* ---------- Stage: dotted-grid backdrop that hosts a widget card ---------- */
.stage {
  display: flex; justify-content: center; align-items: center;
  padding: 64px 40px;
  background:
    radial-gradient(rgba(255, 255, 255, .055) 1px, transparent 1.2px) 0 0 / 14px 14px,
    radial-gradient(ellipse 70% 60% at 50% 50%, rgba(86, 242, 78, .045), transparent 70%);
}
.stage--tight { padding: 28px; }

/* ---------- Card ---------- */
.wcard {
  position: relative; width: 100%; max-width: 1040px;
  background: var(--w-surface);
  border: 1px solid var(--w-hair); border-radius: 16px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 40px 80px -30px rgba(0, 0, 0, .8), 0 0 0 1px rgba(0, 0, 0, .4);
  padding: 28px;
  font-family: var(--f-sans); color: var(--w-ink);
}
.wcard__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.wcard__sub { margin-top: 6px; font-size: 14px; line-height: 1.4; color: var(--w-ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wcard__sub code { font-family: var(--f-code); font-size: 12.5px; color: var(--w-ink-3); margin-left: 4px; }

.wbtn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 7px 12px; border-radius: 8px;
  font: 500 13px/1.2 var(--f-sans); color: var(--w-ink);
  background: var(--w-raised); border: 1px solid var(--w-hair);
  cursor: pointer; transition: background-color .2s ease, transform .15s ease, opacity .2s ease;
}
.wbtn:hover:not(:disabled) { background: #2c2d2c; }
.wbtn:disabled { opacity: .55; cursor: default; }
.wbtn.is-pressed { transform: scale(.96); background: #333433; }
.wbtn svg { width: 14px; height: 14px; }
.wbtn[hidden] { display: none; }
.wbtn--quiet { background: transparent; border-color: transparent; color: var(--w-ink-3); }
.wbtn--quiet:hover:not(:disabled) { background: var(--w-raised); color: var(--w-ink); }

.spinner {
  width: 14px; height: 14px; flex: none; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 20%, var(--w-ink-2) 20% 30%, transparent 30% 45%, var(--w-ink-2) 45% 55%, transparent 55% 70%, var(--w-ink-2) 70% 80%, transparent 80%);
  -webkit-mask: radial-gradient(circle, transparent 3px, #000 3.5px); mask: radial-gradient(circle, transparent 3px, #000 3.5px);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.okmark { display: inline-flex; width: 16px; height: 16px; flex: none; border-radius: 50%; background: rgba(86, 242, 78, .14); color: var(--ok); }
.okmark svg { width: 16px; height: 16px; }

.wtip {
  position: absolute; bottom: calc(100% + 8px); left: 0; transform: translate(-50%, 4px);
  display: flex; flex-direction: column; gap: 2px; white-space: nowrap;
  padding: 8px 11px; border-radius: 8px;
  background: #262726; border: 1px solid rgba(255, 255, 255, .08); box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  font: 12.5px/1.35 var(--f-sans); color: var(--w-ink-2);
  pointer-events: none; opacity: 0; transition: opacity .15s ease, transform .15s ease; z-index: 3;
}
.wtip b { font-weight: 500; color: var(--w-ink); }
.wtip.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- [03] Spend recovery ---------- */
.spend__total { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.spend__amount { font: 500 32px/1.1 var(--f-sans); letter-spacing: -.02em; color: #fff; }
.spend__of { font-size: 16px; color: var(--w-ink-2); white-space: nowrap; }
/* ledger: 13 week columns of $10K pixels + Recovered meter */
.ledger { position: relative; height: 200px; margin: 30px 0 26px; cursor: crosshair; }
.ledger canvas { display: block; width: 100%; height: 100%; }
.ledger__meter { position: absolute; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.ledger__k { font: 10px/1 var(--f-code); letter-spacing: 1.2px; color: var(--w-ink-3); }
.ledger__v { font: 500 20px/1.1 var(--f-sans); color: var(--ok); }

.spend__legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 36px; }
.spend__legend li {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; margin: 0 -8px;
  border-radius: 8px; font-size: 15px; color: var(--w-ink); cursor: default;
  transition: opacity .25s ease, background-color .2s ease;
}
.spend__legend li:hover { background: rgba(255, 255, 255, .035); }
.spend__legend li.is-dim { opacity: .35; }
.spend__legend li.is-pending { opacity: .45; }
.spend__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spend__val { margin-left: auto; color: var(--w-ink-2); white-space: nowrap; }
.ico { display: inline-flex; width: 18px; height: 18px; flex: none; color: var(--c); }
.ico svg { width: 18px; height: 18px; }

.wcard__foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin: 24px -28px -28px; padding: 16px 28px; min-height: 64px;
  border-top: 1px solid var(--w-hair);
}
.wcard__msg { display: flex; align-items: center; gap: 10px; font-size: 14.5px; line-height: 1.45; color: var(--w-ink-2); min-width: 0; animation: msg-in .35s ease both; }
.wcard__msg.is-ok { color: var(--w-ink); }
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } }

/* ---------- [06] Simulation ---------- */
.sim { max-width: none; }
.sim__head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.sim__icon {
  position: relative; width: 40px; height: 40px; border-radius: 10px; background: var(--w-raised);
  display: inline-grid; grid-template-columns: repeat(3, 4px); grid-auto-rows: 4px; gap: 3px; place-content: center;
}
.sim__icon i { width: 4px; height: 4px; background: #3A3D39; animation: blink 1.2s steps(1) infinite; }
.sim__icon i:nth-child(1) { animation-delay: 0s; } .sim__icon i:nth-child(2) { animation-delay: .1s; } .sim__icon i:nth-child(3) { animation-delay: .2s; }
.sim__icon i:nth-child(6) { animation-delay: .3s; } .sim__icon i:nth-child(9) { animation-delay: .4s; } .sim__icon i:nth-child(8) { animation-delay: .5s; }
.sim__icon i:nth-child(7) { animation-delay: .6s; } .sim__icon i:nth-child(4) { animation-delay: .7s; } .sim__icon i:nth-child(5) { animation: none; background: var(--w-ink-3); }
@keyframes blink { 0%, 30% { background: var(--w-ink); } 31%, 100% { background: #3A3D39; } }
.sim__icon.is-ok, .sim__icon.is-fail { gap: 0; }
.sim__icon.is-ok i, .sim__icon.is-fail i { display: none; }
.sim__icon.is-ok::after, .sim__icon.is-fail::after {
  content: ""; width: 18px; height: 18px; border-radius: 50%;
  background-repeat: no-repeat; background-position: center; background-size: 12px;
}
.sim__icon.is-ok::after { background-color: rgba(86, 242, 78, .9); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.8 6.2l2.1 2.1L9.3 3.9' fill='none' stroke='%23101110' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.sim__icon.is-fail::after { background-color: rgba(240, 82, 74, .9); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M6 3v3.6M6 8.6v.1' fill='none' stroke='%23101110' stroke-width='1.7' stroke-linecap='round'/%3E%3C/svg%3E"); }
.sim__name { font: 500 17px/1.3 var(--f-sans); color: var(--w-ink); }
.sim__meta { text-align: right; }
.sim__time { font: 500 17px/1.3 var(--f-sans); color: var(--w-ink); }
.sim__meta .wcard__sub .is-fail { color: var(--fail); }

.sim__chart-head, .sim__foot { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--w-ink-3); }
.sim__chart-head { margin: 26px 0 8px; }
.sim__foot { margin-top: 8px; font-size: 12.5px; }
.sim__chart { position: relative; height: 132px; border-radius: 10px; background: var(--w-panel); overflow: hidden; }
.sim__chart canvas { position: absolute; inset: 10px 12px 8px; width: calc(100% - 24px); height: calc(100% - 18px); }
.sim__fix {
  position: absolute; top: 0; right: 0; bottom: 0; width: 30%; z-index: 1; background-blend-mode: normal;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
  background: rgba(27, 28, 27, .55);
  border-left: 1px solid var(--w-hair);
  font-size: 13px; color: var(--w-ink); animation: msg-in .35s ease both;
}
.sim__fix[hidden] { display: none; }
.sim__fix p { display: flex; align-items: center; gap: 7px; }
.sim__fix svg { width: 13px; height: 13px; color: var(--w-ink-2); }
.sim__fix code { font: 12px/1.4 var(--f-code); color: var(--w-ink-3); }
.sim__fix .plus { color: var(--ok); font-weight: 400; }
.sim__fix .minus { color: var(--fail); font-weight: 400; }



.sim__rows { margin-top: 22px; display: flex; flex-direction: column; gap: 14px; }
.sim__rows li { display: grid; grid-template-columns: 150px minmax(0, 1fr) 92px; gap: 16px; align-items: center; transition: opacity .3s ease; }
.sim__rows { gap: 12px; }
.sim__rows li.is-dim { opacity: .35; }
.sim__agent { font: 13px/1 var(--f-code); color: var(--w-ink-3); transition: color .2s ease; }
.sim__rows li.is-active .sim__agent { color: var(--w-ink); }
.sim__res { font: 13px/1 var(--f-code); color: var(--w-ink-3); text-align: right; white-space: nowrap; }
.sim__res.is-fail { color: var(--fail); }
.cells { display: flex; gap: 3px; min-width: 0; overflow: hidden; }
.cells i { flex: none; width: 10px; height: 10px; border-radius: 2px; background: #242524; transition: background-color .15s ease, box-shadow .15s ease; }
.cells i.p { background: var(--ok); }
.cells i.f { background: var(--fail); box-shadow: 0 0 8px rgba(240, 82, 74, .6); }
.cells i.a { background: #fff; box-shadow: 0 0 8px rgba(255, 255, 255, .5); }

/* ---------- [08] Control & security ---------- */
.guard__card { display: flex; flex-direction: column; gap: 14px; padding: 28px 24px; }
.guard__icon {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin-bottom: 6px;
  border-radius: 9px; color: var(--accent); background: rgba(86, 242, 78, .06); border: 1px solid rgba(86, 242, 78, .2);
}
.guard__icon svg { width: 20px; height: 20px; }

/* ---------- [09] Rollout ---------- */
.rollout { list-style: none; }
.step { display: flex; flex-direction: column; gap: 12px; padding: 28px 24px; }
.step__week { font-family: var(--f-mono); font-size: 11px; line-height: 13.2px; letter-spacing: 1.5px; color: var(--dim); }
.step .body-sm { flex: 1; }
.step__meter { display: flex; gap: 3px; margin-top: 10px; }
.step__meter i { width: 7px; height: 18px; border-radius: 2px; background: #2A2B2A; transition: background-color .3s ease; }
.js .step.is-in .step__meter i.on { background: #CFD2CC; }
.js .step.is-in .step__meter i.full { background: var(--ok); }
html:not(.js) .step__meter i.on { background: #CFD2CC; }
html:not(.js) .step__meter i.full { background: var(--ok); }
.step__label { font-family: var(--f-mono); font-size: 10px; line-height: 12px; letter-spacing: 1px; color: var(--dim); }
.step__label.accent { color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 1199px) {
  .spend__legend { gap: 4px 24px; }
}
@media (max-width: 950px) {
  .stage { padding: 40px 20px; }
  .spend__legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 582px) {
  .stage, .stage--tight { padding: 14px 10px; }
  .wcard { padding: 20px 16px; border-radius: 14px; }
  .wcard__foot { margin: 20px -16px -20px; padding: 14px 16px; flex-direction: column; align-items: flex-start; }
  .spend__amount { font-size: 26px; }
  .spend__of { font-size: 14px; }
  .spend__bar { height: 96px; margin: 20px 0 22px; }
  .spend__legend { grid-template-columns: 1fr; }
  .spend__legend li { font-size: 14px; }
  .wcard__sub { font-size: 13px; }
  .wcard__sub code { display: none; }
  .guard { grid-template-columns: 1fr; }
  .sim__head { grid-template-columns: auto minmax(0, 1fr); }
  .sim__meta { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; text-align: left; }
  .sim__meta .wcard__sub { margin-top: 0; }
  .sim__chart { height: 110px; }
  .sim__fix { width: 48%; padding: 10px; }
  .sim__rows li { grid-template-columns: 108px minmax(0, 1fr) auto; gap: 10px; }
  .sim__agent, .sim__res { font-size: 11.5px; }
  .wcard__msg { font-size: 13.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .num .d.roll, .wcard__msg, .sim__fix { animation: none; }
  .spinner, .sim__icon i { animation: none; }
}

/* ---------- [04] Context layer matrix ---------- */
.ctx__title { font: 500 17px/1.3 var(--f-sans); color: var(--w-ink); }
.live-pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 9px; border-radius: 6px; background: rgba(86, 242, 78, .08); font: 10.5px/1 var(--f-code); letter-spacing: 1.2px; color: var(--ok); flex: none; }
.live-pill i { width: 5px; height: 5px; background: var(--ok); animation: pulse 1.6s ease-in-out infinite; }
.ctx__matrix { display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 14px; margin-top: 24px; }
.ctx__bands { display: flex; flex-direction: column; }
.ctx__bands li { height: var(--ctx-band, 36px); display: flex; align-items: flex-start; gap: 8px; padding-top: 4px; font: 10px/1.2 var(--f-code); letter-spacing: 1px; color: var(--w-ink-3); }
.ctx__bands li i { width: 6px; height: 6px; flex: none; margin-top: 2px; background: var(--c); }
.ctx__canvas { position: relative; height: 230px; cursor: crosshair; }
.ctx__canvas canvas { display: block; width: 100%; height: 100%; }
.ctx__log { margin: 20px -28px -28px; padding: 14px 28px 16px; border-top: 1px solid var(--w-hair); display: flex; flex-direction: column; gap: 10px; min-height: 148px; list-style: none; }
.ctx__log li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font: 12px/1.5 var(--f-code); color: var(--w-ink-3); animation: msg-in .35s ease both; }
.ctx__log li:nth-child(2) { opacity: .6; } .ctx__log li:nth-child(3) { opacity: .35; }
.ctx__t { color: var(--w-ink-3); }
.ctx__a { color: var(--w-ink); }
.ctx__a.ok { color: var(--ok); }
.ctx__q { color: var(--w-ink-2); }
.ctx__facts { display: flex; flex-wrap: wrap; gap: 6px; flex-basis: 100%; }
.fact { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 5px; background: var(--w-panel); color: var(--w-ink-2); font-size: 11.5px; animation: msg-in .3s ease both; }
.fact i { width: 5px; height: 5px; background: var(--c); }

@media (max-width: 582px) {
  .ctx__matrix { grid-template-columns: 1fr; gap: 10px; }
  .ctx__bands { flex-direction: row; flex-wrap: wrap; gap: 8px 14px; }
  .ctx__bands li { height: auto; padding: 0; }
  .ctx__log { margin: 16px -16px -20px; padding: 12px 16px 14px; min-height: 170px; }
  .cells { gap: 2px; }
  .cells i { width: 6px; height: 6px; border-radius: 1px; }
  .ledger__v { font-size: 16px; }
  .wbtn__label { display: none; }
  .sim__fix code { display: none; }
  .sim__fix { width: 42%; }
}

/* very narrow phones (≤ 400px) */
.wcard__head > div { min-width: 0; }
@media (max-width: 400px) {
  .wcard__head { flex-wrap: wrap; }
  .wcard { padding: 18px 14px; }
  .wcard__foot { margin: 18px -14px -18px; padding: 14px; }
  .ctx__log { margin: 14px -14px -18px; padding: 12px 14px; }
}
