/* LUMIVALE — Lattice Ledger (orders)
   Named grid areas · date slabs · expandable invoice perforations
   NOT Lantern Dossier bento/split · NOT fruit-chronicle spine */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=Public+Sans:wght@400;500;600;700;800&display=swap');

.page-lattice {
  --ld-ink: #070b12;
  --ld-panel: #101826;
  --ld-panel-2: #162033;
  --ld-line: rgba(232, 223, 208, 0.12);
  --ld-paper: #e8dfd0;
  --ld-paper-dim: #cfc4b0;
  --ld-mute: #c2cad8;
  --ld-text: #eef2f8;
  --ld-cobalt: #4f8cff;
  --ld-stamp: #e85d4c;
  --ld-sage: #3ecf8e;
  --ld-amber: #f0b429;
  --ld-font: 'Public Sans', system-ui, sans-serif;
  --ld-display: 'DM Serif Display', Georgia, serif;
  --ld-ease: cubic-bezier(0.2, 0.9, 0.25, 1);
  --ld-fluid: clamp(0.92rem, 0.3vw + 0.88rem, 1.05rem);
  background:
    radial-gradient(120% 80% at 10% -10%, rgba(79, 140, 255, 0.18), transparent 55%),
    radial-gradient(90% 60% at 100% 0%, rgba(232, 93, 76, 0.12), transparent 50%),
    linear-gradient(180deg, #0a101c 0%, var(--ld-ink) 40%, #05080e 100%) !important;
  color: var(--ld-text);
  font-family: var(--ld-font);
  font-size: var(--ld-fluid);
}

.page-lattice .page-main {
  overflow-x: clip;
  padding-bottom: 4rem;
}

.ld {
  position: relative;
  max-width: 920px;
  margin: 0 auto;
  padding: 1.5rem var(--space-container, 1.25rem) 2.5rem;
}

/* —— Mast —— */
.ld-mast {
  display: grid;
  grid-template-areas:
    'brand brand'
    'title lede';
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 0.35rem 1.5rem;
  margin-bottom: 1.75rem;
  align-items: end;
}

.ld-brand {
  grid-area: brand;
  margin: 0;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ld-cobalt);
}

.ld-mast h1 {
  grid-area: title;
  margin: 0;
  font-family: var(--ld-display);
  font-weight: 400;
  font-size: clamp(2.6rem, 9vw, 4.4rem);
  line-height: 0.92;
  letter-spacing: -0.02em;
}

.ld-mast h1 em {
  font-style: italic;
  color: var(--ld-paper);
}

.ld-lede {
  grid-area: lede;
  margin: 0;
  color: var(--ld-mute);
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  line-height: 1.45;
  max-width: 34ch;
  padding-bottom: 0.35rem;
}

@media (max-width: 720px) {
  .ld-mast {
    grid-template-areas:
      'brand'
      'title'
      'lede';
    grid-template-columns: 1fr;
  }
}

/* —— Loading / gate / empty —— */
.ld-loading {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1.25rem 1.1rem;
  border: 1px solid var(--ld-line);
  border-radius: 14px;
  background: var(--ld-panel);
  color: var(--ld-mute);
}

.ld-loading-bar {
  width: 2.4rem;
  height: 0.28rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ld-cobalt), var(--ld-stamp), var(--ld-sage));
  background-size: 200% 100%;
  animation: ld-shimmer 1.1s linear infinite;
}

@keyframes ld-shimmer {
  to { background-position: -200% 0; }
}

.ld-gate,
.ld-empty {
  padding: 2.4rem 1.5rem;
  text-align: center;
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(79, 140, 255, 0.08), transparent 40%),
    var(--ld-panel);
  border: 1px dashed var(--ld-line);
}

.ld-gate h2,
.ld-empty h2 {
  margin: 0 0 0.4rem;
  font-family: var(--ld-display);
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 400;
}

.ld-gate p,
.ld-empty p {
  margin: 0 auto 1.25rem;
  max-width: 36ch;
  color: var(--ld-mute);
}

.ld-cta,
.ld-track {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.72rem 1.15rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none !important;
  color: #061018 !important;
  background: var(--ld-paper);
  border: none;
  cursor: pointer;
  transition: transform 0.2s var(--ld-ease), background 0.2s ease;
}

.ld-cta:hover,
.ld-track:hover {
  background: #fff;
  transform: translateY(-1px);
  color: #061018 !important;
}

.ld-track {
  background: var(--ld-cobalt);
  color: #fff !important;
}

.ld-track:hover {
  background: #6aa0ff;
  color: #fff !important;
}

/* —— Meter ribbon (CSS grid areas) —— */
.ld-meters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.35fr);
  grid-template-areas: 'm0 m1 m2 m3 m4';
  gap: 0.55rem;
  margin-bottom: 1.4rem;
}

.ld-meter {
  grid-area: m0;
  position: relative;
  padding: 0.85rem 0.9rem 0.95rem;
  border-radius: 12px;
  background: var(--ld-panel);
  border: 1px solid var(--ld-line);
  overflow: hidden;
  container-type: inline-size;
}

.ld-meter[style*='--m:1'] { grid-area: m1; }
.ld-meter[style*='--m:2'] { grid-area: m2; }
.ld-meter[style*='--m:3'] { grid-area: m3; }
.ld-meter[style*='--m:4'] { grid-area: m4; }

.ld-meter::before {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--ld-cobalt) 80%, transparent),
    color-mix(in srgb, var(--ld-sage) 70%, transparent)
  );
  transform: scaleX(calc(0.35 + (var(--m) * 0.12)));
  transform-origin: left;
}

.ld-meter span {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ld-mute);
  margin-bottom: 0.35rem;
}

.ld-meter strong {
  display: block;
  font-family: var(--ld-display);
  font-size: clamp(1.35rem, 4cqi + 0.8rem, 1.85rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
}

.ld-meter em {
  display: block;
  margin-top: 0.35rem;
  font-style: normal;
  font-size: 0.78rem;
  color: var(--ld-paper-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ld-meter--wide {
  background:
    linear-gradient(120deg, rgba(240, 180, 41, 0.08), transparent 55%),
    var(--ld-panel-2);
}

@media (max-width: 860px) {
  .ld-meters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      'm0 m1'
      'm2 m3'
      'm4 m4';
  }
}

/* —— Stream —— */
.ld-stream {
  position: relative;
}

.ld-stream::before {
  content: '';
  position: absolute;
  left: calc(3.1rem + 0.5vw);
  top: 0.5rem;
  bottom: 0.5rem;
  width: 1px;
  background: linear-gradient(180deg, transparent, var(--ld-line) 8%, var(--ld-line) 92%, transparent);
  pointer-events: none;
}

.ld-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* —— Order slate (named areas) —— */
.ld-slate {
  --tone: var(--ld-cobalt);
  position: relative;
  border-radius: 16px;
  background: var(--ld-panel);
  border: 1px solid var(--ld-line);
  overflow: clip;
  animation: ld-rise 0.55s var(--ld-ease) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}

@keyframes ld-rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

.ld-slate.tone-placed { --tone: var(--ld-cobalt); }
.ld-slate.tone-packed { --tone: var(--ld-amber); }
.ld-slate.tone-shipped { --tone: #38bdf8; }
.ld-slate.tone-delivered { --tone: var(--ld-sage); }
.ld-slate.tone-cancelled { --tone: var(--ld-stamp); }

.ld-face {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: 'date body state';
  gap: 0 0.85rem;
  align-items: stretch;
  width: 100%;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ld-face:focus-visible {
  outline: 2px solid var(--ld-cobalt);
  outline-offset: -2px;
}

.ld-date {
  grid-area: date;
  display: grid;
  grid-template-areas:
    'day'
    'mon'
    'yr';
  align-content: center;
  justify-items: center;
  min-width: 4.4rem;
  padding: 1rem 0.65rem;
  background:
    linear-gradient(165deg, color-mix(in srgb, var(--tone) 28%, transparent), transparent 70%),
    #0c1422;
  border-right: 1px solid var(--ld-line);
}

.ld-date-day {
  grid-area: day;
  font-family: var(--ld-display);
  font-size: clamp(1.7rem, 4vw, 2.15rem);
  line-height: 0.9;
  color: var(--ld-paper);
}

.ld-date-mon {
  grid-area: mon;
  margin-top: 0.15rem;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tone);
}

.ld-date-yr {
  grid-area: yr;
  font-size: 0.68rem;
  color: var(--ld-mute);
  letter-spacing: 0.06em;
}

.ld-body {
  grid-area: body;
  display: grid;
  grid-template-areas:
    'issue'
    'id'
    'meta';
  padding: 0.95rem 0.15rem;
  min-width: 0;
}

.ld-issue {
  grid-area: issue;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ld-mute);
}

.ld-id {
  grid-area: id;
  margin: 0.15rem 0 0.25rem;
  font-family: var(--ld-display);
  font-size: clamp(1.15rem, 2.8vw, 1.45rem);
  font-weight: 400;
  line-height: 1.15;
  word-break: break-word;
}

.ld-meta {
  grid-area: meta;
  margin: 0;
  color: var(--ld-mute);
  font-size: 0.86rem;
}

.ld-state {
  grid-area: state;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.9rem 1rem 0.9rem 0;
}

.ld-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.55rem;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--tone) 18%, transparent);
  color: color-mix(in srgb, var(--tone) 85%, white);
  border: 1px solid color-mix(in srgb, var(--tone) 35%, transparent);
}

.ld-badge i {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--tone);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 25%, transparent);
}

.ld-total {
  font-family: var(--ld-display);
  font-size: 1.15rem;
  color: var(--ld-paper);
}

.ld-chev {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  border: 1px solid var(--ld-line);
  display: grid;
  place-items: center;
  color: var(--ld-mute);
  transition: transform 0.3s var(--ld-ease), color 0.2s ease, border-color 0.2s ease;
}

.ld-chev::before {
  content: '';
  width: 0.4rem;
  height: 0.4rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
}

.ld-slate.is-open .ld-chev {
  transform: rotate(180deg);
  color: var(--ld-cobalt);
  border-color: color-mix(in srgb, var(--ld-cobalt) 40%, transparent);
}

@media (max-width: 560px) {
  .ld-stream::before { display: none; }
  .ld-face {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      'date body'
      'date state';
  }
  .ld-state {
    align-items: flex-start;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0 0.85rem 0.95rem 0;
  }
}

/* —— Invoice panel (expand) —— */
.ld-invoice {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    'stamp'
    'pipe'
    'cargo'
    'foot';
  gap: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.45s var(--ld-ease), opacity 0.3s ease;
  background:
    repeating-linear-gradient(
      -12deg,
      transparent,
      transparent 11px,
      rgba(232, 223, 208, 0.015) 11px,
      rgba(232, 223, 208, 0.015) 12px
    ),
    linear-gradient(180deg, #121c2c, #0e1624);
  border-top: 1px dashed color-mix(in srgb, var(--ld-paper) 22%, transparent);
}

.ld-slate.is-open .ld-invoice {
  max-height: 1200px;
  opacity: 1;
}

.ld-stamp {
  grid-area: stamp;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    'kicker seal'
    'facts seal';
  gap: 0.65rem 1rem;
  padding: 1.15rem 1.15rem 0.85rem;
  position: relative;
}

.ld-stamp::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 8px;
  background:
    radial-gradient(circle at 8px 0, transparent 7px, var(--ld-ink) 8px) 0 0 / 16px 8px;
  transform: translateY(50%);
  opacity: 0.55;
  pointer-events: none;
}

.ld-stamp-kicker {
  grid-area: kicker;
  margin: 0;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ld-paper-dim);
}

.ld-facts {
  grid-area: facts;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  gap: 0.55rem 1rem;
  margin: 0;
}

.ld-facts > div {
  min-width: 0;
}

.ld-facts dt {
  margin: 0;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ld-mute);
}

.ld-facts dd {
  margin: 0.15rem 0 0;
  font-weight: 600;
  font-size: 0.92rem;
  word-break: break-word;
}

.ld-seal {
  grid-area: seal;
  width: 4.6rem;
  height: 4.6rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.15;
  color: color-mix(in srgb, var(--tone) 90%, white);
  border: 2px dashed color-mix(in srgb, var(--tone) 55%, transparent);
  transform: rotate(-12deg);
  opacity: 0.9;
}

/* Pipeline as fluid fill meters */
.ld-pipe {
  grid-area: pipe;
  padding: 1.1rem 1.15rem 0.35rem;
}

.ld-pipe h3,
.ld-cargo h3 {
  margin: 0 0 0.7rem;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ld-mute);
}

.ld-pipe-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.ld-pipe-step {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: center;
}

.ld-pipe-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ld-mute);
}

.ld-pipe-step.is-done .ld-pipe-label,
.ld-pipe-step.is-active .ld-pipe-label {
  color: var(--ld-text);
}

.ld-pipe-track {
  height: 0.38rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.ld-pipe-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--tone), color-mix(in srgb, var(--tone) 40%, white));
  transition: width 0.55s var(--ld-ease);
}

.ld-pipe-step.is-done .ld-pipe-fill { width: 100%; }
.ld-pipe-step.is-active .ld-pipe-fill {
  width: 62%;
  animation: ld-pulse-fill 1.6s ease-in-out infinite;
}

.ld-pipe-step.is-wait .ld-pipe-fill { width: 0; }

@keyframes ld-pulse-fill {
  50% { opacity: 0.65; }
}

.ld-pipe-mark {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ld-mute);
  min-width: 2.2rem;
  text-align: right;
}

.ld-pipe-step.is-done .ld-pipe-mark { color: var(--ld-sage); }
.ld-pipe-step.is-active .ld-pipe-mark { color: var(--tone); }

.ld-cancel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--ld-stamp) 40%, transparent);
  background: color-mix(in srgb, var(--ld-stamp) 10%, transparent);
  color: #ffb4aa;
}

.ld-cancel-ring {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  border: 2px solid var(--ld-stamp);
  flex-shrink: 0;
}

/* Cargo lines */
.ld-cargo {
  grid-area: cargo;
  padding: 0.85rem 1.15rem 0.35rem;
}

.ld-lines {
  display: grid;
  gap: 0.4rem;
}

.ld-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: 'title qty total';
  gap: 0.5rem 0.75rem;
  align-items: baseline;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--ld-line);
}

.ld-line-title {
  grid-area: title;
  font-weight: 600;
  font-size: 0.92rem;
  min-width: 0;
}

.ld-line-qty {
  grid-area: qty;
  color: var(--ld-mute);
  font-variant-numeric: tabular-nums;
}

.ld-line-total {
  grid-area: total;
  font-family: var(--ld-display);
  color: var(--ld-paper);
}

.ld-cargo-empty {
  margin: 0;
  color: var(--ld-mute);
  font-size: 0.9rem;
}

.ld-foot {
  grid-area: foot;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  padding: 1rem 1.15rem 1.2rem;
}

.ld-secondary {
  color: var(--ld-mute) !important;
  text-decoration: underline !important;
  text-underline-offset: 0.18em;
  font-weight: 600;
  font-size: 0.9rem;
}

.ld-secondary:hover {
  color: var(--ld-paper) !important;
}

@media (max-width: 520px) {
  .ld-pipe-step {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      'label mark'
      'track track';
  }
  .ld-pipe-label { grid-area: label; }
  .ld-pipe-track { grid-area: track; }
  .ld-pipe-mark { grid-area: mark; }
  .ld-stamp {
    grid-template-columns: 1fr;
    grid-template-areas:
      'kicker'
      'facts'
      'seal';
  }
  .ld-seal {
    justify-self: start;
    transform: rotate(-6deg);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .ld-slate,
  .ld-loading-bar,
  .ld-pipe-fill,
  .ld-invoice,
  .ld-chev {
    animation: none !important;
    transition: none !important;
  }
  .ld-slate.is-open .ld-invoice {
    max-height: none;
  }
}
