/* ==========================================================================
   Patcherly - Cursor agent-chat demo panel (mcp.php hero)
   Self-contained: loaded only by the MCP page, touches nothing global.
   Every selector is namespaced .pcx-cur*.
   ========================================================================== */

.pcx-cursor {
  /* Cursor-ish IDE palette, kept local to this component */
  --cur-chrome: #171717;
  --cur-bg: #1c1c1c;
  --cur-bg-2: #232323;
  --cur-line: #2e2e2e;
  --cur-line-2: #3d3d3d;
  --cur-fg: #e8e8e8;
  --cur-fg-2: #a6a6a6;
  --cur-fg-3: #7b7b7b;
  --cur-chip: #2b2b2b;
  --cur-accent: var(--pcx-emerald, #34d399);
  --cur-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --cur-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;

  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 22rem;
  overflow: hidden;
  background: var(--cur-bg);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--pcx-r-lg, 22px);
  box-shadow: var(--pcx-shadow-lg, 0 30px 80px rgba(0, 0, 0, 0.65)),
              0 0 0 1px rgba(52, 211, 153, 0.06),
              0 18px 60px -22px rgba(52, 211, 153, 0.22);
  font-family: var(--cur-ui);
  font-size: 0.8125rem;
  line-height: 1.5;
  letter-spacing: 0;
  color: var(--cur-fg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- window chrome: tab strip ---------- */
.pcx-cursor__chrome {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  flex: 0 0 auto;
  padding: 0 0.4rem 0 0;
  background: var(--cur-chrome);
  border-bottom: 1px solid var(--cur-line);
}

.pcx-cursor__tabs {
  display: flex;
  align-items: stretch;
  min-width: 0;
  flex: 1 1 auto;
}

.pcx-cursor__tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  padding: 0.45rem 0.65rem;
  font-size: 0.7rem;
  color: var(--cur-fg-3);
  border-right: 1px solid var(--cur-line);
  white-space: nowrap;
}

.pcx-cursor__tab.is-active {
  color: var(--cur-fg);
  background: var(--cur-bg);
}

.pcx-cursor__tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.pcx-cursor__tab i {
  font-size: 0.95rem;
  opacity: 0.75;
}

.pcx-cursor__tab-x {
  font-size: 0.85rem;
  opacity: 0.55;
}

.pcx-cursor__actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 0 0 auto;
  padding-left: 0.5rem;
  color: var(--cur-fg-3);
  font-size: 0.95rem;
}

.pcx-cursor__actions i { opacity: 0.8; }

/* Spinner on the working tab */
.pcx-cursor__spin {
  width: 0.7rem;
  height: 0.7rem;
  flex: none;
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--cur-accent);
  border-radius: 50%;
  animation: pcx-cur-spin 0.9s linear infinite;
}

@keyframes pcx-cur-spin { to { transform: rotate(360deg); } }

/* ---------- transcript ---------- */
.pcx-cursor__body {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden auto;
  padding: 0.9rem 0.95rem 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--cur-line-2) transparent;
}

.pcx-cursor__body::-webkit-scrollbar { width: 7px; }
.pcx-cursor__body::-webkit-scrollbar-thumb {
  background: var(--cur-line-2);
  border-radius: 4px;
}

.pcx-cursor__stream {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: auto;
}

/* Steps are visible by default so the panel still reads with JS off.
   Only once JS announces itself do we hide them for the replay.
   display:none matters as much as opacity here - an opacity:0 step still
   reserves its height, which would leave a hole under the live transcript
   and make the auto-scroll overshoot. JS adds .is-mounted, forces a reflow,
   then adds .is-visible so the fade still runs. */
html.pcx-js .pcx-cursor__step {
  display: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 260ms var(--pcx-ease-out, ease), transform 260ms var(--pcx-ease-out, ease);
}

html.pcx-js .pcx-cursor__step.is-mounted { display: block; }

html.pcx-js .pcx-cursor__step.is-visible {
  opacity: 1;
  transform: none;
}

/* empty state - shown before the first message, like a fresh agent panel */
.pcx-cursor__empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  color: var(--cur-fg-3);
  font-size: 0.7rem;
  text-align: center;
  transition: opacity 320ms var(--pcx-ease-out, ease);
}

.pcx-cursor__empty.is-gone {
  opacity: 0;
  pointer-events: none;
}

.pcx-cursor__empty i {
  margin-bottom: 0.15rem;
  font-size: 1.15rem;
  color: rgba(52, 211, 153, 0.75);
}

.pcx-cursor__empty b { color: var(--cur-fg-2); font-weight: 600; }
.pcx-cursor__empty-sub { opacity: 0.75; }

/* user turn */
.pcx-cursor__user {
  padding: 0.55rem 0.7rem;
  color: var(--cur-fg);
  background: var(--cur-bg-2);
  border: 1px solid var(--cur-line-2);
  border-radius: 0.6rem;
}

/* muted status lines: "Thought for 2s", "Explored ..." */
.pcx-cursor__muted {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--cur-fg-3);
  font-size: 0.75rem;
}

.pcx-cursor__say { color: var(--cur-fg-2); }
.pcx-cursor__say strong { color: var(--cur-fg); font-weight: 600; }

/* MCP tool call row */
.pcx-cursor__tool {
  padding: 0.45rem 0.6rem;
  background: rgba(52, 211, 153, 0.05);
  border: 1px solid rgba(52, 211, 153, 0.16);
  border-radius: 0.5rem;
  font-size: 0.75rem;
}

.pcx-cursor__tool-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--cur-mono);
}

.pcx-cursor__tool-head i {
  font-size: 0.9rem;
  color: var(--cur-accent);
}

.pcx-cursor__tool-server { color: var(--cur-fg-3); }
.pcx-cursor__tool-sep { color: var(--cur-fg-3); opacity: .7; }
.pcx-cursor__tool-name { color: var(--cur-accent); }
.pcx-cursor__tool-args { color: var(--cur-fg-3); }

.pcx-cursor__tool-out {
  margin-top: 0.3rem;
  padding-left: 1.3rem;
  color: var(--cur-fg-2);
  font-family: var(--cur-mono);
  font-variant-ligatures: none;
  font-size: 0.7rem;
}

/* answer block */
.pcx-cursor__h {
  margin: 0.15rem 0 0.35rem;
  padding: 0;
  font-family: var(--cur-ui);
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.35;
  color: #fff;
}

/* Defensive: styles.css gives every h1-h6 a section rhythm (4rem top / 2.5rem
   bottom at lg). Nothing inside a chat transcript should inherit that. */
.pcx-cursor h1,
.pcx-cursor h2,
.pcx-cursor h3,
.pcx-cursor h4,
.pcx-cursor h5,
.pcx-cursor h6 {
  margin-top: 0;
  padding-bottom: 0;
}

.pcx-cursor code,
.pcx-cursor .pcx-cursor__code {
  font-variant-ligatures: none;
  padding: 0.08em 0.36em;
  background: var(--cur-chip);
  border-radius: 0.28rem;
  font-family: var(--cur-mono);
  font-size: 0.92em;
  color: #d8d8d8;
  white-space: nowrap;
}

/* proposed patch diff */
.pcx-cursor__diff {
  overflow-x: auto;
  padding: 0.5rem 0.6rem;
  background: #141414;
  border: 1px solid var(--cur-line);
  border-radius: 0.5rem;
  font-family: var(--cur-mono);
  font-variant-ligatures: none;
  font-size: 0.7rem;
  line-height: 1.7;
  white-space: pre;
}

.pcx-cursor__diff .d-file { display: block; color: var(--cur-fg-3); }
.pcx-cursor__diff .d-del { display: block; color: #f4857c; background: rgba(239, 68, 68, 0.09); }
.pcx-cursor__diff .d-add { display: block; color: #6ee7b7; background: rgba(52, 211, 153, 0.09); }

/* "your options" list */
.pcx-cursor__opts {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pcx-cursor__opts li {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  color: var(--cur-fg-2);
  font-size: 0.75rem;
}

.pcx-cursor__opts i {
  margin-top: 0.15rem;
  font-size: 0.85rem;
  color: var(--cur-accent);
}

.pcx-cursor__note {
  padding-top: 0.45rem;
  border-top: 1px solid var(--cur-line);
  color: var(--cur-fg-3);
  font-size: 0.7rem;
}

.pcx-cursor__foot {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--cur-fg-3);
  font-size: 0.7rem;
}

/* ---------- composer ---------- */
.pcx-cursor__composer {
  flex: 0 0 auto;
  margin: 0 0.7rem 0.7rem;
  padding: 0.55rem 0.6rem 0.45rem;
  background: var(--cur-bg);
  border: 1px solid var(--cur-line-2);
  border-radius: 0.75rem;
}

.pcx-cursor__input {
  display: flex;
  align-items: baseline;
  min-height: 2.1rem;
  color: var(--cur-fg);
  font-size: 0.78rem;
}

.pcx-cursor__typed { white-space: pre-wrap; }

.pcx-cursor__input.is-empty .pcx-cursor__typed { display: none; }

.pcx-cursor__placeholder { color: var(--cur-fg-3); }
.pcx-cursor__input:not(.is-empty) .pcx-cursor__placeholder { display: none; }

.pcx-cursor__caret {
  flex: none;
  display: inline-block;
  width: 1px;
  height: 0.95em;
  margin-left: 1px;
  background: var(--cur-fg);
  vertical-align: text-bottom;
  animation: pcx-cur-blink 1.1s step-end infinite;
}

@keyframes pcx-cur-blink { 50% { opacity: 0; } }

.pcx-cursor__composer-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.4rem;
  color: var(--cur-fg-2);
  font-size: 0.7rem;
}

.pcx-cursor__pill {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.18rem 0.45rem;
  background: var(--cur-chip);
  border-radius: 999px;
}

.pcx-cursor__pill i { font-size: 0.8rem; }

.pcx-cursor__model {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.pcx-cursor__composer-row .ms-auto { margin-left: auto; }

.pcx-cursor__mic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  background: #ededed;
  border-radius: 50%;
  color: #1c1c1c;
  font-size: 0.8rem;
}

/* ---------- loop scrubber ---------- */
.pcx-cursor__scrub {
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.06);
}

.pcx-cursor__scrub span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, rgba(52, 211, 153, 0.35), var(--cur-accent));
}

/* ---------- caption under the panel ---------- */
.pcx-cursor-caption {
  margin: 0.75rem 0 0;
  color: #94a3b8;
  font-size: 0.75rem;
  text-align: center;
}

/* ---------- responsive ---------- */
@media (max-width: 991.98px) {
  .pcx-cursor { height: 21rem; margin-top: 1.5rem; }
}

@media (max-width: 575.98px) {
  .pcx-cursor { height: 20rem; font-size: 0.78rem; }
  .pcx-cursor__tab:nth-child(2) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .pcx-cursor__empty { display: none; }
  .pcx-cursor__spin { animation: none; }
  .pcx-cursor__caret { animation: none; }
  html.pcx-js .pcx-cursor__step { display: block; opacity: 1; transform: none; transition: none; }
  .pcx-cursor__scrub { display: none; }
}
