/* ===== Transformação: caos da semana x comprovantes emitidos ===== */
.transform-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.chaos-compare {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0 minmax(0, 1fr);
  margin-top: 30px;
}

.chaos-board,
.order-board {
  position: relative;
  border-radius: 22px;
}

.order-board {
  aspect-ratio: 1.16;
  container-type: inline-size;
}

.chaos-compare > .chaos-board {
  margin-right: 5px;
}

.chaos-compare > .order-board {
  margin-left: 5px;
}

.board-tag {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.board-tag i {
  font-size: 0.45rem;
}

.board-tag--before {
  background: #fff;
  color: #3b4659;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

.board-tag--before i {
  color: #e5484d;
}

.board-tag--after {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
}

.board-tag--after i {
  color: #42dca3;
}

/* Lado esquerdo: pilha de ficheiros e mensagens */
/* Sem fundo: os papéis ficam numa pilha sobre a página. */
.chaos-board {
  --k: 0.92;
  aspect-ratio: 1.16;
  container-type: size;
  cursor: default;
}

.chaos-stage {
  position: absolute;
  inset: 0;
  font-size: clamp(7px, 2.35cqw, 14px);
  color: #1f2a3d;
}

.chaos-card {
  position: absolute;
  left: calc(var(--px) * 1%);
  top: calc(var(--py) * 1%);
  z-index: calc(var(--i) + 1);
  /* Em repouso: pilha no centro do quadro (com um pequeno desvio de cada
     papel); ao passar o rato, cada um vai para o seu lugar (px/py). */
  rotate: var(--r);
  translate:
    calc(var(--k) * ((50 - var(--px)) * 1cqw - 50%) + var(--jx) * 1em)
    calc(var(--k) * ((50 - var(--py)) * 1cqh - 50%) + var(--jy) * 1em);
  border-radius: 1em;
  background: #fff;
  box-shadow: 0 0.5em 1.4em rgba(2, 8, 23, 0.35), 0 0 0 1px rgba(15, 23, 42, 0.06);
  transition:
    translate 0.65s cubic-bezier(0.2, 0.8, 0.2, 1),
    rotate 0.65s cubic-bezier(0.2, 0.8, 0.2, 1),
    scale 0.25s ease,
    box-shadow 0.3s ease;
  transition-delay: calc(var(--i) * 22ms);
}

.chaos-board.is-spread .chaos-card {
  translate: 0 0;
  rotate: var(--r2);
  box-shadow: 0 1em 2.4em rgba(2, 8, 23, 0.4), 0 0 0 1px rgba(15, 23, 42, 0.06);
}

@media (hover: hover) {
  .chaos-board:hover .chaos-card {
    translate: 0 0;
    rotate: var(--r2);
    box-shadow: 0 1em 2.4em rgba(2, 8, 23, 0.4), 0 0 0 1px rgba(15, 23, 42, 0.06);
  }

  .chaos-board .chaos-card:hover {
    z-index: 30;
    scale: 1.05;
    transition-delay: 0s;
  }
}

.chaos-card small {
  color: #7a8599;
}

.chaos-mail {
  width: 17em;
  padding: 1em 1.1em 1.1em;
}

.chaos-mail header {
  display: flex;
  align-items: center;
  gap: 0.7em;
  margin-bottom: 0.7em;
}

.chaos-mail header div {
  display: grid;
  flex: 1;
  line-height: 1.25;
}

.chaos-mail__avatar {
  display: grid;
  place-items: center;
  width: 2.3em;
  height: 2.3em;
  border-radius: 50%;
  background: #e5edff;
  color: #3b5bdb;
  font-weight: 700;
}

.chaos-dot {
  width: 0.65em;
  height: 0.65em;
  border-radius: 50%;
  background: #3b82f6;
}

.chaos-mail b {
  display: block;
  font-size: 1.05em;
}

.chaos-mail p {
  margin: 0.35em 0 0;
  color: #5b6577;
  line-height: 1.4;
}

.chaos-toll {
  display: grid;
  gap: 0.2em;
  width: 11em;
  padding: 0.9em 1em;
  border-left: 0.35em solid #16a34a;
}

.chaos-toll__brand {
  font-size: 0.85em;
  font-weight: 700;
  color: #15803d;
}

.chaos-toll strong {
  font-size: 1.35em;
}

.chaos-invoice {
  width: 12.5em;
  padding: 1em 1.1em 1.2em;
  border-radius: 0.4em;
  font-variant-numeric: tabular-nums;
}

.chaos-invoice header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.7em;
  letter-spacing: 0.08em;
}

.chaos-invoice p {
  display: flex;
  justify-content: space-between;
  margin: 0.3em 0;
  color: #4b5567;
}

.chaos-invoice__total {
  padding-top: 0.45em;
  border-top: 1px solid #e3e7ee;
  font-weight: 800;
  color: #1f2a3d !important;
}

.chaos-invoice em {
  position: absolute;
  left: -0.5em;
  bottom: -0.7em;
  padding: 0.25em 0.6em;
  rotate: -6deg;
  background: #dc2626;
  color: #fff;
  font-size: 0.78em;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.chaos-sheet,
.chaos-csv {
  overflow: hidden;
  border-radius: 0.7em;
}

.chaos-sheet header,
.chaos-csv header {
  display: flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.55em 0.8em;
  background: #f1f4f8;
  border-bottom: 1px solid #e3e7ee;
}

.chaos-sheet header > span,
.chaos-csv header > span {
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  background: #c7cfdb;
}

.chaos-sheet header small,
.chaos-csv header small {
  margin-left: 0.5em;
  font-weight: 600;
  white-space: nowrap;
}

.chaos-sheet {
  width: 21em;
}

.chaos-sheet table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.chaos-sheet th,
.chaos-sheet td {
  padding: 0.5em 0.7em;
  border-bottom: 1px solid #edf0f4;
  border-right: 1px solid #edf0f4;
  text-align: left;
  white-space: nowrap;
}

.chaos-sheet th {
  background: #f8fafc;
  font-weight: 700;
  color: #5b6577;
}

.chaos-sheet tr.is-bad td {
  background: #fdecec;
  color: #c2410c;
  font-weight: 700;
}

.chaos-sheet td.is-formula {
  color: #b91c1c;
  font-weight: 700;
}

.chaos-csv {
  width: 16em;
}

.chaos-csv code {
  display: block;
  padding: 0.8em 1em 1em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  line-height: 1.6;
  color: #475569;
}

.chaos-notebook {
  display: grid;
  gap: 0.25em;
  width: 11em;
  padding: 0.9em 1em 1em 1.6em;
  border-radius: 0.3em;
  background:
    linear-gradient(90deg, transparent 1.05em, #f3b0b0 1.05em, #f3b0b0 1.15em, transparent 1.15em),
    repeating-linear-gradient(180deg, #fffdf6 0 1.75em, #dbe4f0 1.75em calc(1.75em + 1px));
  font-family: Caveat, "Segoe Print", cursive;
  font-size: 1.3em;
  line-height: 1.35;
  color: #1e3a8a;
}

.chaos-notebook strong {
  font-size: 1.05em;
  color: #334155;
}

.chaos-sticky {
  width: 9.5em;
  padding: 1em 1em 1.2em;
  border-radius: 0.2em;
  background: #fde68a;
  box-shadow: 0 0.6em 1.4em rgba(120, 90, 10, 0.18);
  font-family: Caveat, "Segoe Print", cursive;
  font-size: 1.45em;
  line-height: 1.1;
  color: #5b4500;
}

.chaos-chat {
  width: 13.5em;
  padding: 0.8em 1em 0.6em;
  border-radius: 1.1em 1.1em 1.1em 0.3em;
}

.chaos-chat small {
  display: block;
  font-weight: 600;
}

.chaos-chat p {
  margin: 0.25em 0 0.2em;
  font-size: 1.12em;
  font-weight: 600;
  line-height: 1.3;
}

.chaos-chat time {
  display: block;
  text-align: right;
  font-size: 0.8em;
  color: #9aa3b2;
}

.chaos-unread {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 0.6em 1.1em;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}

.chaos-unread i {
  font-size: 0.6em;
  color: #e5484d;
}

@media (hover: none) {
  .chaos-board {
    cursor: pointer;
  }
}

/* Seta entre os dois lados */
.chaos-arrow {
  align-self: center;
  justify-self: center;
  z-index: 50;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #fff;
  color: #0b1d3b;
  font-size: 1.25rem;
  box-shadow: 0 10px 28px rgba(2, 8, 23, 0.35);
}

/* Lado direito: tela de comprovantes emitidos dentro de um tablet */
.order-board {
  display: grid;
  align-items: end;
  padding-top: 48px;
}

.order-stage {
  position: relative;
  font-size: clamp(7px, 2.05cqw, 11.5px);
  color: #0b1d3b;
}

.order-tablet {
  position: relative;
  aspect-ratio: 1200 / 865;
  filter: drop-shadow(0 1.6em 2.4em rgba(2, 8, 23, 0.55));
}

/* A tela fica por baixo da moldura (que tem o ecrã recortado). */
.order-screen {
  position: absolute;
  left: 3.6%;
  top: 4.7%;
  width: 92.8%;
  height: 90.6%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f3f7fc;
}

.order-tablet__frame {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.order-status {
  display: flex;
  justify-content: space-between;
  padding: 0.55em 1.6em 0.3em 1.8em;
  background: #082444;
  color: #fff;
  font-size: 0.78em;
  font-weight: 700;
}

.order-status span:last-child {
  display: flex;
  gap: 0.5em;
}

.order-window__body {
  display: grid;
  flex: 1;
  min-height: 0;
  grid-template-columns: 3.4em minmax(0, 1fr);
}

.order-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55em;
  padding: 0.8em 0.4em;
  background: #082444;
}

.order-side img {
  width: 2.3em;
  height: 2.3em;
  margin-bottom: 0.3em;
  padding: 0.2em;
  border-radius: 0.6em;
  background: #fff;
  object-fit: contain;
}

.order-side span {
  display: grid;
  place-items: center;
  width: 2.2em;
  height: 2.2em;
  border-radius: 0.6em;
  color: rgba(255, 255, 255, 0.55);
}

.order-side span.is-active {
  background: rgba(66, 220, 163, 0.16);
  color: #42dca3;
}

.order-main {
  padding: 1em 1.3em 1.3em;
}

.order-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
}

.order-head strong {
  font-size: 1.65em;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.order-head__btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.55em 0.9em;
  border-radius: 0.6em;
  background: #0b3a75;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.order-tabs {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0.9em 0 0.8em;
}

.order-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.5em 0.8em;
  border-radius: 0.6em;
  font-weight: 700;
  white-space: nowrap;
}

.order-tab b {
  padding: 0.05em 0.55em;
  border-radius: 999px;
  font-size: 0.9em;
}

.order-tab--done {
  background: linear-gradient(135deg, #15803d, #22c55e);
  color: #fff;
}

.order-tab--done b {
  background: #dcfce7;
  color: #14532d;
}

.order-tab--pending {
  background: #fef3c7;
  color: #92400e;
}

.order-tab--pending b {
  background: #fde68a;
  color: #92400e;
}

.order-period {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  margin-left: auto;
  padding: 0.5em 0.8em;
  border: 1px solid #dbe3ee;
  border-radius: 0.6em;
  background: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.order-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7em;
}

.order-card {
  border: 1px solid #e4eaf2;
  border-radius: 0.9em;
  background: #fff;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  transition:
    opacity 0.45s ease,
    translate 0.45s ease,
    transform 0.22s ease,
    box-shadow 0.22s ease,
    border-color 0.22s ease;
}

.order-card:hover {
  transform: translateY(-0.35em);
  border-color: #86efac;
  box-shadow: 0 0.9em 1.8em rgba(11, 42, 102, 0.18), 0 0 0 1px #86efac;
}

.order-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6em;
  padding: 0.75em 0.85em 0.6em;
}

.order-card__head div {
  display: grid;
  gap: 0.15em;
  min-width: 0;
}

.order-card__head strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-card__head small {
  color: #64748b;
  font-size: 0.82em;
  font-weight: 600;
}

.order-card__pill {
  padding: 0.2em 0.6em;
  border-radius: 999px;
  background: #15803d;
  color: #fff;
  font-size: 0.8em;
  font-weight: 700;
}

.order-card__vals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 0.55em 0.4em;
  border-block: 1px solid #edf1f6;
  text-align: center;
}

.order-card__vals div {
  display: grid;
  gap: 0.1em;
  min-width: 0;
}

.order-card__vals div + div {
  border-left: 1px solid #edf1f6;
}

.order-card__vals b {
  font-size: 0.95em;
}

.order-card__vals small {
  color: #64748b;
  font-size: 0.75em;
}

.order-card__vals .is-in {
  color: #1d6fe0;
}

.order-card__vals .is-out {
  color: #dc2626;
}

.order-card__vals .is-net {
  color: #15803d;
}

.order-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
  padding: 0.55em 0.85em 0.65em;
}

.order-card__plate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #1e4f91;
  font-size: 0.85em;
  font-weight: 600;
}

.order-card__plate em {
  margin-right: 0.3em;
  padding: 0.05em 0.4em;
  border: 1px solid #cfd8e5;
  border-left: 0.25em solid #1e4f91;
  border-radius: 0.3em;
  color: #0b1d3b;
  font-style: normal;
  font-weight: 800;
}

.order-card__actions {
  display: flex;
  gap: 0.35em;
}

.order-card__actions i {
  display: grid;
  place-items: center;
  width: 1.9em;
  height: 1.9em;
  border: 1px solid #cfd8e5;
  border-radius: 0.5em;
  color: #475569;
  font-size: 0.85em;
}

.order-card:hover .order-card__actions i {
  border-color: #93c5fd;
  color: #1d4ed8;
}

/* Entrada ao aparecer no ecrã */
.chaos-compare.is-animated .order-card {
  opacity: 0;
  translate: 0 0.8em;
}

.chaos-compare.is-animated.is-visible .order-card {
  opacity: 1;
  translate: 0 0;
  transition-delay: calc(0.15s + var(--i) * 90ms), calc(0.15s + var(--i) * 90ms), 0s, 0s, 0s;
}

@media (max-width: 620px) {
  .chaos-compare {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 0 auto;
  }

  .chaos-compare > .chaos-board {
    margin: 0 0 4px;
  }

  .chaos-compare > .order-board {
    margin: 4px 0 0;
  }

  .chaos-arrow {
    rotate: 90deg;
  }

  .chaos-board,
  .order-board {
    border-radius: 18px;
  }

  .chaos-board {
    aspect-ratio: 1 / 1.05;
  }

  .chaos-card--optional {
    display: none;
  }

  .chaos-arrow {
    width: 46px;
    height: 46px;
    font-size: 1rem;
  }

  .order-board {
    aspect-ratio: auto;
    padding-top: 46px;
  }

  .order-head__btn {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chaos-card,
  .order-card,
  .chaos-compare.is-animated .order-card {
    transition: none !important;
  }

  .chaos-compare.is-animated .order-card {
    opacity: 1;
    translate: 0 0;
    scale: 1;
  }
}
