/* Control scene: the reply-policy panel (assistant, policy, threshold, capabilities)
   and a live routing feed. Every selector is scoped under [data-app-scene="control"].
   Shared tokens (--showcase-*) and the topbar chrome come from styles.css. */

[data-app-scene="control"] .control-layout {
  display: grid;
  grid-template-columns: minmax(196px, .84fr) minmax(0, 1fr);
  height: calc(100% - 42px);
  min-height: 0;
}

/* ---------- Policy column ---------- */

[data-app-scene="control"] .control-policy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  min-width: 0;
  padding: 14px 15px;
  border-inline-end: 1px solid var(--showcase-line);
  overflow: hidden;
}

[data-app-scene="control"] .control-agent {
  display: flex;
  align-items: center;
  gap: 9px;
}
[data-app-scene="control"] .control-agent-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: oklch(.66 .18 263 / .16);
  color: var(--showcase-blue);
}
[data-app-scene="control"] .control-agent-avatar svg { width: 14px; height: 14px; }
[data-app-scene="control"] .control-agent-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}
[data-app-scene="control"] .control-agent-copy strong {
  overflow: hidden;
  color: var(--showcase-text);
  font-size: 9px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="control"] .control-agent-copy small {
  overflow: hidden;
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

[data-app-scene="control"] .control-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}
[data-app-scene="control"] .control-label {
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 600;
  letter-spacing: 0;
}

/* Segmented reply-policy control */

[data-app-scene="control"] .control-segmented {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: 26px;
  padding: 2px;
  border: 1px solid var(--showcase-line);
  border-radius: 7px;
  background: var(--showcase-panel);
}
[data-app-scene="control"] .control-segmented-thumb {
  position: absolute;
  inset-block: 2px;
  inset-inline-start: calc(33.333% + 2px);
  width: calc(33.333% - 4px);
  border-radius: 5px;
  background: var(--showcase-panel-2);
  box-shadow: 0 0 0 1px var(--showcase-line), inset 0 1px 0 rgba(255, 255, 255, .05);
}
[data-app-scene="control"] .control-segmented button {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0 3px;
  overflow: hidden;
  border-radius: 5px;
  background: transparent;
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 200ms ease;
}
[data-app-scene="control"] .control-segmented button.is-active { color: var(--showcase-text); }
[data-app-scene="control"] .control-segmented button:hover { color: var(--showcase-text); }

/* Idle life: a soft ring around the selected policy segment. */
@media (prefers-reduced-motion: no-preference) {
  [data-app-scene="control"] .control-segmented-thumb { animation: control-ring 3.6s ease-in-out infinite; }
}
@keyframes control-ring {
  0%, 100% { box-shadow: 0 0 0 1px var(--showcase-line), 0 0 0 0 oklch(.66 .18 263 / 0); }
  50% { box-shadow: 0 0 0 1px oklch(.66 .18 263 / .55), 0 0 0 3px oklch(.66 .18 263 / .16); }
}

/* Auto-send threshold slider */

[data-app-scene="control"] .control-threshold-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
[data-app-scene="control"] .control-threshold-value {
  color: var(--showcase-muted);
  font-size: 8px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
[data-app-scene="control"] .control-threshold-value b { color: var(--showcase-text); font-size: 11px; font-weight: 700; }
[data-app-scene="control"] .control-slider {
  position: relative;
  height: 16px;
  margin-top: 2px;
}
[data-app-scene="control"] .control-slider::before {
  position: absolute;
  inset-inline: 0;
  top: 50%;
  height: 3px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--showcase-panel-2);
  content: "";
}
[data-app-scene="control"] .control-slider-fill {
  position: absolute;
  inset-inline-start: 0;
  top: 50%;
  width: 100%;
  height: 3px;
  transform: translateY(-50%) scaleX(.85);
  transform-origin: left center;
  border-radius: 999px;
  background: var(--showcase-blue);
}
[data-app-scene="control"] .control-slider-handle {
  position: absolute;
  top: 50%;
  inset-inline-start: 85%;
  width: 11px;
  height: 11px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--showcase-text);
  box-shadow: 0 0 0 3px oklch(.66 .18 263 / .22), 0 1px 3px rgba(0, 0, 0, .4);
}
[data-app-scene="control"] .control-slider.is-adjusting .control-slider-handle {
  box-shadow: 0 0 0 5px oklch(.66 .18 263 / .3), 0 1px 3px rgba(0, 0, 0, .4);
  transition: box-shadow 260ms ease;
}
[data-app-scene="control"] .control-threshold-note {
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 400;
  line-height: 1.5;
}

/* Capabilities */

[data-app-scene="control"] .control-capability-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
[data-app-scene="control"] .control-capability-list li {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px;
  border-bottom: 1px solid var(--showcase-line);
  transition: background 160ms ease;
}
[data-app-scene="control"] .control-capability-list li:last-child { border-bottom: 0; }
[data-app-scene="control"] .control-capability-list li:hover { background: var(--showcase-panel-2); }
[data-app-scene="control"] .control-capability-list li span {
  overflow: hidden;
  min-width: 0;
  color: var(--showcase-text);
  font-size: 8px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="control"] .control-switch {
  position: relative;
  flex: none;
  width: 24px;
  height: 14px;
  border: 1px solid var(--showcase-line);
  border-radius: 999px;
  background: var(--showcase-panel-2);
  transition: background 200ms ease, border-color 200ms ease;
}
[data-app-scene="control"] .control-switch i {
  position: absolute;
  top: 1px;
  inset-inline-start: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--showcase-muted);
  transition: transform 200ms cubic-bezier(.22, 1, .36, 1), background 200ms ease;
}
[data-app-scene="control"] .control-switch.is-on { border-color: oklch(.72 .16 150 / .5); background: oklch(.72 .16 150 / .18); }
[data-app-scene="control"] .control-switch.is-on i { transform: translateX(10px); background: oklch(.72 .16 150); }
[data-app-scene="control"] .control-switch:hover i { filter: brightness(1.15); }
[data-app-scene="control"] .control-capability-note {
  margin-top: 2px;
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 400;
  line-height: 1.5;
}

/* ---------- Feed column ---------- */

[data-app-scene="control"] .control-feed {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}
[data-app-scene="control"] .control-feed-head {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--showcase-line);
}
[data-app-scene="control"] .control-feed-head strong { color: var(--showcase-text); font-size: 9px; font-weight: 700; }
[data-app-scene="control"] .control-feed-live {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 600;
}
[data-app-scene="control"] .control-feed-live i { width: 5px; height: 5px; border-radius: 50%; background: oklch(.72 .16 150); }
@media (prefers-reduced-motion: no-preference) {
  [data-app-scene="control"] .control-feed-live i { animation: control-live-pulse 2.2s ease-in-out infinite; }
}
@keyframes control-live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

[data-app-scene="control"] .control-feed-list {
  display: flex;
  flex-direction: column;
  padding: 2px 14px 10px;
  overflow: hidden;
}
[data-app-scene="control"] .control-feed-row {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--showcase-line);
  border-radius: 6px;
}
[data-app-scene="control"] .control-feed-row:last-child { border-bottom: 0; }
[data-app-scene="control"] .control-feed-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--showcase-panel-2);
  color: var(--showcase-text);
  font-size: 7px;
  font-weight: 700;
}
[data-app-scene="control"] img.control-feed-avatar {
  object-fit: cover;
  border: 1px solid var(--showcase-line);
}
/* Signed-in user in the shared topbar: styled to match the initials badge it replaces. */
[data-app-scene="control"] img.app-user {
  width: 23px;
  height: 23px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--showcase-line);
}
[data-app-scene="control"] .control-feed-meta {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}
[data-app-scene="control"] .control-feed-meta strong {
  overflow: hidden;
  color: var(--showcase-text);
  font-size: 9px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="control"] .control-feed-meta small {
  overflow: hidden;
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="control"] .control-feed-chip {
  display: flex;
  flex: none;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  transition: background 220ms ease, border-color 220ms ease;
}
[data-app-scene="control"] .control-feed-chip b { color: var(--showcase-text); font-size: 9px; font-weight: 700; }
[data-app-scene="control"] .control-feed-chip small { font-size: 7px; font-weight: 500; white-space: nowrap; }
[data-app-scene="control"] .control-feed-dot { width: 5px; height: 5px; flex: none; border-radius: 50%; }
[data-app-scene="control"] .control-feed-chip.is-sent { border-color: oklch(.72 .16 150 / .35); background: oklch(.72 .16 150 / .12); }
[data-app-scene="control"] .control-feed-chip.is-sent small { color: oklch(.72 .16 150); }
[data-app-scene="control"] .control-feed-chip.is-sent .control-feed-dot { background: oklch(.72 .16 150); }
[data-app-scene="control"] .control-feed-chip.is-waiting { border-color: oklch(.8 .15 80 / .35); background: oklch(.8 .15 80 / .12); }
[data-app-scene="control"] .control-feed-chip.is-waiting small { color: oklch(.8 .15 80); }
[data-app-scene="control"] .control-feed-chip.is-waiting .control-feed-dot { background: oklch(.8 .15 80); }

/* Idle life: a breathing dot on the newest (first) feed row. */
@media (prefers-reduced-motion: no-preference) {
  [data-app-scene="control"] .control-feed-list li:first-child .control-feed-dot {
    animation: control-dot-breathe 2.4s ease-in-out infinite;
  }
}
@keyframes control-dot-breathe {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: .55; }
}

/* A row re-evaluated after the threshold moved. */
[data-app-scene="control"] .control-feed-row.is-rechecked { animation: control-recheck 900ms cubic-bezier(.22, 1, .36, 1); }
@keyframes control-recheck {
  0% { background: transparent; box-shadow: 0 0 0 0 oklch(.8 .15 80 / 0); }
  28% { background: oklch(.8 .15 80 / .08); box-shadow: 0 0 0 1px oklch(.8 .15 80 / .45); }
  100% { background: transparent; box-shadow: 0 0 0 0 oklch(.8 .15 80 / 0); }
}

/* ---------- Entrance, keyed on .is-scene-active ---------- */

[data-app-scene="control"] .app-preview.is-scene-active .control-agent,
[data-app-scene="control"] .app-preview.is-scene-active .control-field,
[data-app-scene="control"] .app-preview.is-scene-active .control-feed-head,
[data-app-scene="control"] .app-preview.is-scene-active .control-feed-row {
  animation: control-rise-in 420ms cubic-bezier(.22, 1, .36, 1) both;
}
[data-app-scene="control"] .app-preview.is-scene-active .control-agent { animation-delay: 20ms; }
[data-app-scene="control"] .app-preview.is-scene-active .control-field-policy { animation-delay: 100ms; }
[data-app-scene="control"] .app-preview.is-scene-active .control-field-threshold { animation-delay: 180ms; }
[data-app-scene="control"] .app-preview.is-scene-active .control-field-capabilities { animation-delay: 260ms; }
[data-app-scene="control"] .app-preview.is-scene-active .control-feed-head { animation-delay: 60ms; }
[data-app-scene="control"] .app-preview.is-scene-active .control-feed-row:nth-child(1) { animation-delay: 160ms; }
[data-app-scene="control"] .app-preview.is-scene-active .control-feed-row:nth-child(2) { animation-delay: 240ms; }
[data-app-scene="control"] .app-preview.is-scene-active .control-feed-row:nth-child(3) { animation-delay: 320ms; }
[data-app-scene="control"] .app-preview.is-scene-active .control-feed-row:nth-child(4) { animation-delay: 400ms; }
@keyframes control-rise-in {
  from { opacity: .32; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* A live arrival mid-loop reads differently from the initial settle: it drops in and pops. */
[data-app-scene="control"] .control-feed-row.is-entering {
  animation: control-arrive-in 420ms cubic-bezier(.22, 1, .36, 1) both !important;
  animation-delay: 0ms !important;
}
@keyframes control-arrive-in {
  0% { opacity: 0; transform: translateY(-10px) scale(.94); }
  60% { opacity: 1; transform: translateY(1px) scale(1.015); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* The arrival's own space opens first: a wrapper transitions grid-template-rows from 0fr to
   1fr, slow and linear on purpose. Many tiny, even per-frame layout deltas keep each frame's
   affected region small (and so keep the measured layout-shift score small); a fast or eased
   reveal covers the same total distance in fewer, bigger steps and scores worse. Child needs
   min-height:0 so the collapsed 0fr state has somewhere real to go. Once the transition ends,
   control.js swaps in the row's own pop-in (control-arrive-in above). */
[data-app-scene="control"] .control-feed-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 480ms linear;
}
[data-app-scene="control"] .control-feed-wrap.is-open { grid-template-rows: 1fr; }
[data-app-scene="control"] .control-feed-wrap-inner { min-height: 0; overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  [data-app-scene="control"] .app-preview.is-scene-active .control-agent,
  [data-app-scene="control"] .app-preview.is-scene-active .control-field,
  [data-app-scene="control"] .app-preview.is-scene-active .control-feed-head,
  [data-app-scene="control"] .app-preview.is-scene-active .control-feed-row,
  [data-app-scene="control"] .control-feed-row.is-entering,
  [data-app-scene="control"] .control-feed-row.is-rechecked,
  [data-app-scene="control"] .control-segmented-thumb,
  [data-app-scene="control"] .control-feed-live i,
  [data-app-scene="control"] .control-feed-list li:first-child .control-feed-dot {
    animation: none !important;
  }
  [data-app-scene="control"] .control-feed-wrap { transition: none; }
}

/* ---------- Phone host: threshold control and feed only, stacked ---------- */

@container app-scene (max-width: 640px) {
  [data-app-scene="control"] .control-layout { display: flex; height: calc(100% - 42px); flex-direction: column; }
  [data-app-scene="control"] .control-policy {
    flex: none;
    justify-content: flex-start;
    padding: 12px 13px 6px;
    border-inline-end: 0;
    border-bottom: 1px solid var(--showcase-line);
  }
  [data-app-scene="control"] .control-agent,
  [data-app-scene="control"] .control-field-policy,
  [data-app-scene="control"] .control-field-capabilities,
  [data-app-scene="control"] .control-threshold-note {
    display: none;
  }
  [data-app-scene="control"] .control-feed { flex: 1; min-height: 0; }
  [data-app-scene="control"] .control-feed-list { padding: 0 13px 8px; }
  [data-app-scene="control"] .control-feed-row { min-height: 40px; }
  [data-app-scene="control"] .control-feed-row:nth-child(n+4) { display: none; }
  [data-app-scene="control"] .control-label { font-size: 8px; }
  [data-app-scene="control"] .control-threshold-value b { font-size: 13px; }
  [data-app-scene="control"] .control-feed-meta strong { font-size: 10px; }
  [data-app-scene="control"] .control-feed-chip b { font-size: 10px; }
  [data-app-scene="control"] .control-feed-head strong { font-size: 10px; }
}
