/*
 * Mr. RIVERO on a HUD (FEATURES.mrRiveroJarvis). Markup and script:
 * organisms/mr-rivero-chat.mjs; the orb: assets/js/mr-rivero-orb.js. The
 * panel keeps its own rules in mrRiveroChatStyle(); this sheet only adds to
 * `.mrc.is-jarvis` and the frame around it. It lives on the dark stage in
 * both themes, so its colors are the chat's own literals, not tokens.
 * Motion is transform, opacity and clip-path, and reduced motion holds it
 * all still (the chat's own rule covers everything inside the panel).
 */

/* ---------------------------------------------------------------- frame */

.jv-frame {
  position: relative;
  padding: 38px 14px 14px;
}
/* The strip over the panel: the shortcut, on the right (Marcus's copy
   review: the page is internal only, so the "Demo" chip is gone). */
.jv-bar {
  position: absolute;
  top: 0;
  left: 30px;
  right: 30px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font:
    500 11px / 1 'IBM Plex Mono',
    ui-monospace,
    monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8e97a6;
}
.jv-keys {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
}
.jv-keys kbd {
  padding: 4px 7px;
  font: inherit;
  letter-spacing: 0.06em;
  color: #b7bdc9;
  background: #12151c;
  border: 1px solid #2a303c;
  border-bottom-width: 2px;
  border-radius: var(--radius-sm, 8px);
}
/* Four brackets at the corners, and a tick ruler down each side. */
.jv-corners {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.jv-corners i {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 0 solid rgb(255 122 122 / 70%);
}
.jv-corners i:nth-child(1) {
  top: 0;
  left: 0;
  border-width: 1.5px 0 0 1.5px;
}
.jv-corners i:nth-child(2) {
  top: 0;
  right: 0;
  border-width: 1.5px 1.5px 0 0;
}
.jv-corners i:nth-child(3) {
  bottom: 0;
  left: 0;
  border-width: 0 0 1.5px 1.5px;
}
.jv-corners i:nth-child(4) {
  bottom: 0;
  right: 0;
  border-width: 0 1.5px 1.5px 0;
}
.jv-corners::before,
.jv-corners::after {
  content: '';
  position: absolute;
  top: 56px;
  bottom: 32px;
  width: 5px;
  background: repeating-linear-gradient(
    to bottom,
    rgb(255 122 122 / 32%) 0 1px,
    transparent 1px 14px
  );
}
.jv-corners::before {
  left: 3px;
}
.jv-corners::after {
  right: 3px;
}

/*
 * One fixed height, the conversation scrolling inside it. The plain panel
 * reserves the height of its first conversation (`--mrc-h`, measured as
 * the page parses); this one reserves nothing, so the section keeps its
 * size and the launcher sits in the middle of what is on screen. The
 * client sets `.is-sized` in both motion modes; without it the static
 * conversation keeps its natural height.
 */
.mrc.is-jarvis.is-sized {
  height: clamp(480px, 70vh, 640px);
}
.mrc.is-jarvis.is-sized .mrc-stage {
  min-height: 0;
}
.mrc.is-jarvis.is-sized .mrc-stage > * {
  flex-shrink: 0;
}
.mrc.is-jarvis.is-sized .mrc-thread {
  flex: 1 1 0;
  height: auto;
  min-height: 0;
  overflow-y: auto;
}

/* A scan line crosses the panel while he is calling Orchy. */
.mrc.is-jarvis::after {
  content: '';
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgb(255 122 122 / 0%) calc(100% - 90px),
    rgb(255 122 122 / 7%) calc(100% - 12px),
    rgb(255 122 122 / 35%) 100%
  );
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 0.3s ease;
}
.mrc.is-jarvis[data-voice='think']::after {
  opacity: 1;
  animation: jv-scan 1.8s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}

/* ----------------------------------------------------------------- orbs */

.jv-orb {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
}
.jv-orb canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.mrc.is-jarvis .mrc-head {
  padding: 4px 20px 4px 8px;
  gap: 6px;
}
.jv-orb-head {
  width: 92px;
  height: 92px;
}
.jv-orb-head .mrc-head-avatar,
.jv-orb-idle .mrc-launch {
  z-index: 1;
}
.jv-orb-idle {
  width: 240px;
  height: 240px;
}
/* The orb's rings take over from the launcher's own CSS ring. */
.mrc.is-jarvis .mrc-launch::before {
  display: none;
}
.jv-orb-idle canvas {
  transition: opacity 0.3s ease;
}
.mrc-idle.is-leaving .jv-orb-idle canvas {
  opacity: 0;
}

/* ----------------------------------------------------------- tool calls */

.jv-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-left: 44px;
}
.jv-tools .mrc-thinking {
  align-self: flex-start;
  margin-bottom: 2px;
  font-size: 14px;
}
.jv-tool {
  position: relative;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
  padding: 9px 12px 10px;
  overflow: hidden;
  font:
    500 12px / 1.4 'IBM Plex Mono',
    ui-monospace,
    monospace;
  background: #151922;
  border: 1px solid #262c38;
  border-left: 2px solid #ff7a7a;
  border-radius: var(--radius-sm, 8px);
}
.jv-tool-tick {
  position: relative;
  width: 14px;
  height: 14px;
}
.jv-tool-head {
  min-width: 0;
  color: #e6e9ef;
}
.jv-tool-verb {
  color: #ff7a7a;
}
.jv-tool-arrow {
  color: #6b7383;
}
.jv-tool-body {
  grid-column: 2;
  color: #8e97a6;
}
/* The call's progress, along its foot. */
.jv-tool-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: #ff7a7a;
  transform: scaleX(0);
  transform-origin: left center;
}
.jv-tool.is-running .jv-tool-bar {
  transform: scaleX(1);
  transition: transform 520ms linear;
}
.jv-tool.is-done {
  border-left-color: #6bd18a;
}
.jv-tool.is-done .jv-tool-bar {
  transform: scaleX(1);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.jv-tool.is-done .mrc-spin {
  opacity: 0;
}
.jv-tool.is-done .mrc-tick-check {
  opacity: 1;
  transform: none;
}
/* Once he answers, the calls fold into one line of chips above it. */
.jv-tools.is-collapsed {
  flex-direction: row;
  flex-wrap: wrap;
}
.jv-tools.is-collapsed .mrc-thinking,
.jv-tools.is-collapsed .jv-tool-body,
.jv-tools.is-collapsed .jv-tool-bar {
  display: none;
}
.jv-tools.is-collapsed .jv-tool {
  padding: 4px 9px 4px 7px;
  font-size: 11px;
  color: #8e97a6;
  background: transparent;
  border-left-width: 1px;
}
.jv-tools.is-collapsed .jv-tool-head {
  color: #8e97a6;
}
.jv-tools.is-collapsed .jv-tool-verb {
  color: inherit;
}

/*
 * --------------------------------------------------------------- results
 * What a reply hands back, all on one fictional load: the clean manifest,
 * the catalog's cards, the matching markets. Rows and cards come in one
 * after another on `--i`.
 */

.jv-res {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  margin-left: 44px;
}
.jv-res-head,
.jv-res-foot {
  margin: 0;
  font:
    500 11px / 1.3 'IBM Plex Mono',
    ui-monospace,
    monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8e97a6;
}
.jv-res-lot {
  color: #ff7a7a;
}
.jv-res-foot {
  color: #6b7383;
  letter-spacing: 0.06em;
}

/* Re-manifest: one clean line per SKU. */
.jv-table-wrap {
  overflow-x: auto;
  background: #151922;
  border: 1px solid #262c38;
  border-radius: var(--radius-sm, 8px);
  scrollbar-width: none;
}
.jv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.4;
}
.jv-table th {
  padding: 8px 10px;
  font:
    500 10px / 1.2 'IBM Plex Mono',
    ui-monospace,
    monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: left;
  color: #8e97a6;
  border-bottom: 1px solid #262c38;
}
.jv-table td {
  padding: 7px 10px;
  vertical-align: top;
  color: #e6e9ef;
  border-top: 1px solid #1d222c;
}
.jv-table tbody tr {
  animation: mrc-fade 0.3s ease-out both;
  animation-delay: calc(120ms + var(--i, 0) * 90ms);
}
.jv-table .jv-mono {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 11px;
  white-space: nowrap;
  color: #b7bdc9;
}
.jv-table .jv-num {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Catalog: a card per SKU, the photo still an empty slot. */
.jv-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.jv-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: #151922;
  border: 1px solid #262c38;
  border-radius: var(--radius-sm, 8px);
  animation: mrc-rise 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 90ms);
}
.jv-card-media {
  display: block;
  aspect-ratio: 4 / 3;
  padding: 6px;
  background: #12151c;
}
.jv-card-slot {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 4px;
  box-sizing: border-box;
  font:
    500 10px / 1.3 'IBM Plex Mono',
    ui-monospace,
    monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  color: #6b7383;
  border: 1px dashed #3a4252;
  border-radius: 6px;
}
.jv-card-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 8px 10px 10px;
}
.jv-card-meta,
.jv-card-qty {
  font:
    500 10px / 1.3 'IBM Plex Mono',
    ui-monospace,
    monospace;
  letter-spacing: 0.06em;
  color: #8e97a6;
}
.jv-card-title {
  display: -webkit-box;
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: #e6e9ef;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.jv-card-qty {
  color: #b7bdc9;
}
.jv-card-price {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #ff7a7a;
}

/* Buyers: a market per row, its flag and its rep. */
.jv-markets {
  margin: 0;
  padding: 0;
  list-style: none;
  background: #151922;
  border: 1px solid #262c38;
  border-radius: var(--radius-sm, 8px);
}
.jv-market {
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid #1d222c;
  animation: mrc-rise 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 90ms);
}
.jv-market:first-child {
  border-top: 0;
}
.jv-market-flag {
  display: block;
  width: 27px;
  height: 18px;
  object-fit: cover;
  border-radius: 2px;
}
.jv-market-country {
  font-size: 13px;
  font-weight: 600;
}
.jv-market-rep {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #b7bdc9;
}
.jv-market-rep img {
  flex: none;
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 50%;
}
.jv-market-rep-label {
  font:
    500 10px / 1 'IBM Plex Mono',
    ui-monospace,
    monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #6b7383;
}

/* The way back in when nothing matched: the three use cases as chips. */
.jv-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.mrc.is-enhanced .jv-pick {
  opacity: 1;
  transform: none;
}

/* ------------------------------------------------------------ keyframes */

@keyframes jv-scan {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(100%);
  }
}

/* ---------------------------------------------------- lighter on phones */

@media (hover: none) {
  .jv-keys {
    display: none;
  }
}
@media (max-width: 640px) {
  .jv-frame {
    padding: 34px 0 0;
  }
  .jv-bar {
    left: 0;
    right: 0;
    height: 34px;
  }
  .jv-corners {
    display: none;
  }
  .jv-tools,
  .jv-res {
    margin-left: 0;
  }
  /* The rep goes under the country, so the name never squeezes it. */
  .jv-market {
    grid-template-columns: 27px minmax(0, 1fr);
    row-gap: 4px;
  }
  .jv-market-rep {
    grid-column: 2;
  }
  /* One row that scrolls sideways instead of three cramped columns. */
  .jv-cards {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 58%;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
  }
  .jv-card {
    scroll-snap-align: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mrc.is-jarvis::after {
    display: none;
  }
}
