/* Shared UI primitives: command rows, copy buttons, the selector + menu, and
   the title sweep. One definition, themed per surface through custom
   properties instead of per-section descendant overrides.

   Surfaces set three knobs:
     --cmd-ink   text color family for command content
     --cmd-line  row border color
     --cmd-copy  copy-button resting color
   Consumers (homepage sections, the demo widget, the chat page) get identical
   rendering by class alone. */

:root {
  --cmd-ink: var(--carbon);
  --cmd-line: var(--line-paper);
  --cmd-copy: color-mix(in srgb, var(--carbon) 72%, transparent);
  /* the "Choose any file from your computer." contract: every piece of small
     print sitting under a field, button, or rounded element uses these */
  --under-size: 13px;
  --under-ink: color-mix(in srgb, var(--cmd-ink) 55%, transparent);
  --under-action-ink: color-mix(in srgb, var(--cmd-ink) 82%, transparent);
}
.surface-charcoal {
  --cmd-ink: var(--paper);
  --cmd-line: var(--line-charcoal);
  --cmd-copy: var(--paper);
}

/* ---- title sweep ---- */

.title-sweep {
  background-image: linear-gradient(105deg,
    currentColor 0,
    currentColor 46.5%,
    var(--signal) 46.5%,
    var(--signal) 48.25%,
    var(--electric) 48.25%,
    var(--electric) 50%,
    var(--pulse) 50%,
    var(--pulse) 51.75%,
    var(--oxide) 51.75%,
    var(--oxide) 53.5%,
    transparent 53.5%,
    transparent 100%);
  background-size: 300% 100%;
  background-position: 90% 0;
  background-repeat: no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.title-sweep.is-swept { animation: title-sweep-in 3.2s cubic-bezier(0.1, 0.7, 0.3, 1) forwards; }
@keyframes title-sweep-in { to { background-position: 0 0; } }

/* The chat status reuses the same chromatic stripe with solid color tails so
   its replaceable label never disappears between looping passes. */
.status-sweep {
  background-image: linear-gradient(105deg,
    currentColor 0,
    currentColor 46.5%,
    var(--signal) 46.5%,
    var(--signal) 48.25%,
    var(--electric) 48.25%,
    var(--electric) 50%,
    var(--pulse) 50%,
    var(--pulse) 51.75%,
    var(--oxide) 51.75%,
    var(--oxide) 53.5%,
    currentColor 53.5%,
    currentColor 100%);
  background-size: 300% 100%;
  background-position: 100% 0;
  background-repeat: no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: status-sweep-pass 3.2s cubic-bezier(0.1, 0.7, 0.3, 1) infinite;
}
@keyframes status-sweep-pass {
  0% { background-position: 100% 0; }
  70%, 100% { background-position: 0 0; }
}

/* ---- standalone command row (install widget) ---- */

.install-command {
  position: relative;
  width: max-content;
  max-width: 100%;
  height: 66px;
  display: inline-grid;
  grid-template-columns: auto minmax(0, auto) 46px;
  align-items: center;
  gap: 14px;
  padding: 0 8px 0 20px;
  border: 1px solid var(--cmd-line);
  border-radius: 10px;
  background: transparent;
  overflow: visible;
}
.install-command__prompt {
  color: color-mix(in srgb, var(--cmd-ink) 50%, transparent);
  font: 400 18px/1 var(--font-mono);
}
.install-command code {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  color: color-mix(in srgb, var(--cmd-ink) 94%, transparent);
  font: 500 18px/1.25 var(--font-mono);
  letter-spacing: -0.025em;
  scrollbar-width: none;
  white-space: nowrap;
}
.install-command code::-webkit-scrollbar { display: none; width: 0; height: 0; }
.install-command__copy {
  width: 46px;
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--cmd-copy);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}
.install-command__copy:hover {
  background: transparent;
  color: var(--cmd-ink);
}
.install-command__copy svg { width: 21px; height: 21px; }

/* ---- result row: command + selector ---- */

.demo-result__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 10px;
}
.demo-result__command {
  position: relative;
  min-width: 0;
  width: 100%;
  height: 66px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 46px;
  align-items: center;
  gap: 12px;
  padding-left: 20px;
  border: 1px solid var(--cmd-line);
  border-radius: 10px;
  background: transparent;
}
.demo-result__command:not(.is-terminal):not(.is-agent) { grid-template-columns: minmax(0, 1fr) 46px; }
.demo-result__command .install-command__prompt {
  color: color-mix(in srgb, var(--cmd-ink) 50%, transparent);
}
.demo-result__command code {
  min-width: 0;
  overflow-x: auto;
  color: color-mix(in srgb, var(--cmd-ink) 94%, transparent);
  font: 500 18px/1.25 var(--font-mono);
  letter-spacing: -0.025em;
  scrollbar-width: none;
  white-space: nowrap;
  -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 30px), transparent 100%);
  mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 30px), transparent 100%);
}
.demo-result__command code::-webkit-scrollbar { display: none; }
.demo-result__agent-icons {
  display: inline-flex;
  align-items: center;
  flex: none;
}
.demo-result__agent-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--cmd-ink) 18%, transparent);
  border-radius: 50%;
  background: var(--paper);
  color: var(--carbon);
}
.demo-result__agent-icon + .demo-result__agent-icon { margin-left: -6px; }
.demo-result__agent-icon svg { width: 19px; height: 19px; }
.demo-result__copy {
  width: 46px;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--cmd-copy);
  cursor: pointer;
}
.demo-result__copy:hover { color: var(--cmd-ink); }
.demo-result__copy svg { width: 21px; height: 21px; }

/* selector chip: charcoal on every surface (matches the live-demo result) */
.demo-result__selector {
  position: relative;
  min-width: 148px;
  height: 66px;
  border: 1px solid var(--charcoal);
  border-radius: 10px;
  background: var(--charcoal);
}
.demo-result__selector > summary {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 17px;
  color: var(--paper);
  cursor: pointer;
  list-style: none;
  font: 500 18px/1.25 var(--font-mono);
  letter-spacing: -0.025em;
  white-space: nowrap;
}
.demo-result__selector > summary::-webkit-details-marker { display: none; }
.demo-result__selector > summary::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-3px) rotate(45deg);
  transform-origin: center;
}
.demo-result__selector[open] > summary::after { transform: translateY(3px) rotate(225deg); }

/* menu panel: nav-dropdown style items (Inter, 13px, 38px rows) */
.demo-result__menu {
  position: absolute;
  z-index: 6;
  top: calc(100% + 8px);
  right: 0;
  width: 210px;
  padding: 10px;
  border: 1px solid var(--line-paper);
  border-radius: 8px;
  background: var(--paper);
  color: var(--carbon);
  box-shadow: 0 18px 50px rgba(19, 23, 28, 0.14);
}
.demo-result__menu button {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: 400 13px/1.2 var(--font-sans);
  text-align: left;
}
.demo-result__menu button:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
.demo-result__menu button[aria-current="true"] { color: var(--oxide); }

/* under-row + developer options popover. Self-sufficient: same treatment as
   the widget's under-text (13px, muted ink, underlined actions). */
/* class doubled: outranks .demo-form__under (components.css) on homepage
   elements that carry both classes, despite this file loading first */
.demo-result__under.demo-result__under {
  position: relative;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.25em;
  margin-top: 14px;
  color: var(--under-ink);
  font-size: var(--under-size);
  font-weight: 400;
}
.demo-result__under.demo-result__under a,
.demo-result__under.demo-result__under summary,
.demo-result__under.demo-result__under > button {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--under-action-ink);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
}
.demo-result__under.demo-result__under > button:disabled {
  opacity: 1;
  cursor: not-allowed;
}
.demo-result__options { display: inline; }
.demo-result__options summary { list-style: none; }
.demo-result__options summary::-webkit-details-marker { display: none; }
.demo-result__options > div {
  position: absolute;
  z-index: 6;
  top: 28px;
  left: 0;
  display: flex;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line-paper);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 30px rgba(19, 23, 28, 0.1);
  white-space: nowrap;
}
.demo-result__options a,
.demo-result__options button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--carbon);
  cursor: pointer;
  font: 13px/1.25 var(--font-sans);
}

/* space-aware menus: interactions.js adds .menu-up when a panel would leave
   the viewport, and the panel opens upward instead */
details.menu-up .demo-result__menu { top: auto; bottom: calc(100% + 8px); }
details.demo-result__options.menu-up > div { top: auto; bottom: 28px; }

/* ---- copy effects ---- */

.install-check-icon { display: none; }
.install-command__copy.is-copied,
.demo-result__copy.is-copied { color: var(--signal); }
.install-command__copy.is-copied .install-copy-icon,
.demo-result__copy.is-copied .install-copy-icon { display: none; }
.install-command__copy.is-copied .install-check-icon,
.demo-result__copy.is-copied .install-check-icon {
  display: block;
  animation: install-check-pop 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes install-check-pop {
  45% { transform: scale(1.22); }
}
.install-copy-feedback {
  position: absolute;
  z-index: 2;
  top: 8px;
  right: 56px;
  width: max-content;
  max-width: calc(100% - 70px);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 13px;
  border: 0;
  border-radius: 0;
  background: var(--electric);
  color: #fff;
  box-shadow: 0 10px 28px rgba(86, 0, 245, 0.24);
  font: 600 12px/1.2 var(--font-sans);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-45%) scale(0.94);
  transform-origin: right bottom;
  transition:
    opacity 280ms ease,
    transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.install-copy-feedback::before {
  content: "✓";
  font: 600 11px/1 var(--font-mono);
}
.install-copy-feedback.is-visible {
  opacity: 1;
  transform: translateY(-72%) scale(1);
}

/* ---- mobile ---- */

@media (max-width: 560px) {
  .install-command {
    height: 56px;
    grid-template-columns: auto minmax(0, 1fr) 40px;
    gap: 10px;
    padding: 0 6px 0 14px;
    border-radius: 10px;
  }
  .install-command__prompt { font-size: 18px; }
  .install-command code {
    font-size: 18px;
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 30px), transparent 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 30px), transparent 100%);
  }
  .install-command__copy { width: 40px; min-height: 0; }
  .install-command__copy svg { width: 19px; height: 19px; }
  .install-copy-feedback { left: auto; right: 8px; width: max-content; max-width: calc(100% - 16px); }
  .demo-result__command,
  .demo-result__selector { height: 56px; }
  .demo-result__row { grid-template-columns: minmax(0, 1fr); }
  .demo-result__options > div {
    max-width: calc(100vw - 40px);
    flex-wrap: wrap;
    white-space: normal;
  }
}
