/* =========================================================================
   Claysend · BRUTALIST MONO — ⌘J Claude CLI 副驾 (copilot panel)
   Slide-out right panel that drives the left SaaS. Models the bob server's
   `claude -p --output-format stream-json` flow: assistant text + tool_use
   cards (queued → running → done) wired to real app actions over AppBus.
   Requires colors_and_type.css + brutalist.css linked first.
   ========================================================================= */

:root { --cop-w: 412px; }

/* push the app left so the panel never covers the working surface */
#root { transition: padding-right .18s ease; }
#root.cop-open { padding-right: var(--cop-w); }

/* ---------- launcher (when closed) ---------- */
.cop-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 78;
  display: inline-flex; align-items: center; gap: 9px; height: 40px; padding: 0 14px;
  background: var(--ink); color: var(--surface); border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow); cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: 0.04em;
  transition: transform .08s, box-shadow .08s, background .08s;
}
.cop-fab:hover { transform: translate(-1px,-1px); box-shadow: var(--shadow-lg); background: #000; }
.cop-fab:active { transform: translate(1px,1px); box-shadow: var(--shadow-sm); }
.cop-fab .dot { width: 8px; height: 8px; background: var(--green); border: var(--bw-hair) solid var(--surface); animation: blink 1.4s steps(1) infinite; }
.cop-fab .kj { font-family: var(--font-mono); font-size: 10px; font-weight: 700; border: var(--bw-hair) solid var(--surface); padding: 1px 5px; }

/* ---------- panel shell ---------- */
.cop {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--cop-w); z-index: 80;
  background: var(--surface-2); border-left: var(--bw) solid var(--ink);
  display: flex; flex-direction: column; min-height: 0;
  transform: translateX(100%); transition: transform .18s ease;
  box-shadow: -7px 0 0 rgba(10,10,10,.06);
}
.cop.open { transform: translateX(0); }

/* head — black bar */
.cop-head {
  flex: none; height: 50px; display: flex; align-items: center; gap: 10px; padding: 0 12px 0 14px;
  background: var(--ink); color: var(--surface); border-bottom: var(--bw) solid var(--ink);
}
.cop-mark { width: 26px; height: 26px; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--ink); border: var(--bw) solid var(--surface); }
.cop-title { font-family: var(--font-display); font-weight: 700; font-size: 13.5px; letter-spacing: var(--ls-tight); text-transform: uppercase; }
.cop-ver { font-family: var(--font-mono); font-size: 9.5px; color: var(--mute); }
.cop-head .live { width: 8px; height: 8px; background: var(--green); border: var(--bw-hair) solid var(--surface); animation: blink 1.4s steps(1) infinite; }
.cop-head .kj { font-family: var(--font-mono); font-size: 10px; font-weight: 700; color: var(--surface); border: var(--bw-hair) solid var(--surface); padding: 1px 5px; }
.cop-xbtn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; flex: none;
  border: var(--bw-hair) solid transparent; background: transparent; color: var(--surface); }
.cop-xbtn:hover { background: var(--surface); color: var(--ink); border-color: var(--surface); }

/* agent switcher in the header — a clearly-clickable control. Was an invisible
   dark-on-dark blob (the <button> reset the inherited light color). Light border
   + light text on the ink header; inverts to a solid chip on hover so it reads
   as pressable. */
.cop-agent-sw { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%;
  padding: 4px 9px 4px 8px; border: var(--bw-hair) solid var(--surface); background: transparent;
  color: var(--surface); cursor: pointer; }
.cop-agent-sw:hover { background: var(--surface); color: var(--ink); }
.cop-agent-name { font-family: var(--font-display); font-weight: 700; font-size: 12.5px;
  letter-spacing: var(--ls-tight); text-transform: uppercase; line-height: 1.15; }
.cop-agent-sub { font-family: var(--font-mono); font-size: 9px; opacity: 0.72; line-height: 1.1; }
.cop-agent-cv { flex: none; opacity: 0.85; transition: transform .12s; }
.cop-agent-sw.open .cop-agent-cv { transform: rotate(180deg); }

/* status strip — grounds it in the CLI/MCP world */
.cop-status {
  flex: none; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; padding: 6px 14px;
  background: var(--surface); border-bottom: var(--bw) solid var(--ink);
  font-family: var(--font-mono); font-size: 9.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em;
}
.cop-status b { color: var(--ink); }
.cop-status .ok { color: var(--green); }
.cop-status .sep { color: var(--mute); }
.cop-status .busy { color: var(--accent); display: inline-flex; align-items: center; gap: 5px; margin-left: auto; }
.cop-status .busy i { width: 7px; height: 7px; background: var(--accent); animation: blink .8s steps(1) infinite; }

/* ---------- thread ---------- */
.cop-thread { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 14px; }

/* empty / welcome state */
.cop-empty { margin: auto 0; display: flex; flex-direction: column; gap: 14px; padding: 8px 2px; }
.cop-empty-ic { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--surface); border: var(--bw) solid var(--ink); box-shadow: var(--shadow-sm); }
.cop-empty h3 { font-family: var(--font-display); font-weight: 700; font-size: 17px; text-transform: uppercase; letter-spacing: var(--ls-tight); }
.cop-empty p { font-size: 12.5px; color: var(--ink-3); line-height: 1.55; }
.cop-empty .lbl { font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--mute); margin: 4px 0 2px; }

/* a clickable starter command */
.cop-seed { display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px; cursor: pointer;
  background: var(--surface); border: var(--bw) solid var(--ink); box-shadow: var(--shadow-sm);
  transition: transform .08s, box-shadow .08s, background .08s; text-align: left; }
.cop-seed:hover { transform: translate(-1px,-1px); box-shadow: var(--shadow); background: var(--hi); }
.cop-seed .si { width: 24px; height: 24px; flex: none; display: flex; align-items: center; justify-content: center; border: var(--bw-hair) solid var(--ink); background: var(--surface-2); }
.cop-seed:hover .si { background: var(--surface); }
.cop-seed .st { font-size: 12.5px; color: var(--ink); line-height: 1.45; font-weight: 500; }

/* user turn */
.cop-user { align-self: flex-end; max-width: 92%; display: flex; gap: 8px; align-items: flex-start; }
.cop-user .ub {
  background: var(--ink); color: var(--surface); border: var(--bw) solid var(--ink); box-shadow: var(--shadow-sm);
  padding: 8px 11px; font-size: 12.5px; line-height: 1.5; }
.cop-user .ut { font-family: var(--font-mono); font-size: 9px; font-weight: 700; color: var(--mute); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; flex: none; }

/* assistant turn */
.cop-asst { display: flex; gap: 9px; align-items: flex-start; }
.cop-asst .av { width: 22px; height: 22px; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--surface); border: var(--bw-hair) solid var(--ink);
  font-family: var(--font-display); font-weight: 700; font-size: 11px; }
.cop-asst .at { flex: 1; min-width: 0; font-size: 13px; line-height: 1.6; color: var(--ink); white-space: pre-wrap; }
.cop-asst.final .at { padding: 10px 12px; background: var(--surface); border: var(--bw) solid var(--ink); box-shadow: var(--shadow-sm); }
.cop-cursor { display: inline-block; width: 7px; height: 14px; background: var(--accent); margin-left: 1px; vertical-align: -2px; animation: blink .7s steps(1) infinite; }

/* tool_use card — the signature black-label block */
.cop-tool { margin-left: 31px; border: var(--bw) solid var(--ink); background: var(--surface); box-shadow: var(--shadow-sm); }
.cop-tool-bar { display: flex; align-items: center; gap: 7px; padding: 5px 9px; background: var(--ink); color: var(--surface);
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em; }
.cop-tool-bar .tn { text-transform: none; }
.cop-tool-bar .grow { flex: 1; }
.cop-tool-st { display: inline-flex; align-items: center; gap: 5px; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 1px 6px; border: var(--bw-hair) solid var(--surface); }
.cop-tool-st.queued { color: var(--surface); opacity: .7; }
.cop-tool-st.running { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.cop-tool-st.done { background: var(--green); border-color: var(--green); color: #fff; }
.cop-tool-body { padding: 8px 10px; }
.cop-arg { display: flex; gap: 8px; font-family: var(--font-mono); font-size: 11px; line-height: 1.55; }
.cop-arg + .cop-arg { margin-top: 2px; }
.cop-arg .k { color: var(--mute); flex: none; min-width: 64px; }
.cop-arg .v { color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.cop-run-bar { display: inline-block; height: 10px; width: 100%; max-width: 150px; margin-top: 7px; border: var(--bw-hair) solid var(--ink);
  background: repeating-linear-gradient(45deg, var(--accent-soft) 0 6px, var(--surface) 6px 12px); background-size: 200% 100%; animation: march .8s linear infinite; }
.cop-result { display: flex; align-items: flex-start; gap: 7px; margin-top: 8px; padding-top: 8px; border-top: var(--bw-hair) solid var(--surface-3);
  font-family: var(--font-mono); font-size: 11px; color: var(--ink); line-height: 1.5; }
.cop-result .ic { color: var(--green); flex: none; margin-top: 1px; }
.spin { animation: spin .9s steps(8) infinite; }

/* ---------- composer ---------- */
.cop-foot { flex: none; border-top: var(--bw) solid var(--ink); background: var(--surface); }
.cop-chips { display: flex; gap: 6px; padding: 8px 10px 0; overflow-x: auto; }
.cop-chips::-webkit-scrollbar { height: 0; }
.cop-chip { flex: none; display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; cursor: pointer;
  border: var(--bw-hair) solid var(--ink); background: var(--surface-2); color: var(--ink-2);
  font-family: var(--font-mono); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
.cop-chip:hover { background: var(--hi); color: var(--ink); }
.cop-input-row { display: flex; align-items: flex-end; gap: 8px; padding: 10px; }
.cop-ta { flex: 1; min-height: 38px; max-height: 132px; resize: none; padding: 9px 10px; border: var(--bw) solid var(--ink); background: var(--surface);
  color: var(--ink); font-family: var(--font-body); font-size: 13px; line-height: 1.5; }
.cop-ta::placeholder { color: var(--mute); }
.cop-ta:focus { outline: none; box-shadow: var(--shadow-sm); border-color: var(--accent); }
.cop-send { width: 38px; height: 38px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border: var(--bw) solid var(--ink); background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm);
  transition: transform .08s, box-shadow .08s, background .08s; }
.cop-send:hover { transform: translate(-1px,-1px); box-shadow: var(--shadow); background: var(--accent-press); }
.cop-send:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--ink); }
.cop-send:disabled { opacity: .35; pointer-events: none; }
.cop-foot-meta { display: flex; align-items: center; gap: 8px; padding: 0 11px 9px; font-family: var(--font-mono); font-size: 9px; color: var(--mute); text-transform: uppercase; letter-spacing: 0.04em; }
.cop-foot-meta .kbd { font-size: 9px; padding: 0 4px; }

/* when the panel is open, re-center the app's fixed modals into the
   remaining space so the panel never covers them */
#root.cop-open .modal-scrim { right: var(--cop-w); }

/* ── real-copilot additions: history drawer + nudge badge ── */
.cop-nudge {
  position: absolute; top: -6px; right: -6px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--hi); color: var(--ink);
  border: var(--bw-hair, 1px) solid var(--ink);
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.cop-hist {
  border-bottom: var(--bw) solid var(--ink);
  background: var(--surface-2, #f4f3ee);
  max-height: 220px; overflow: auto;
}
.cop-hist-head {
  padding: 7px 12px; font-family: var(--font-mono); font-size: 10px;
  letter-spacing: .08em; text-transform: uppercase; color: var(--mute);
  border-bottom: var(--bw-hair, 1px) solid var(--ink);
}
.cop-hist-empty { padding: 12px; font-family: var(--font-mono); font-size: 11px; color: var(--mute); }
.cop-hist-item {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: 0; background: transparent; cursor: pointer;
  border-bottom: var(--bw-hair, 1px) solid rgba(10,10,10,.08);
  font-size: 12px; text-align: left; color: var(--ink);
}
.cop-hist-item:hover { background: var(--hi); }
.cop-hist-item.on { background: var(--ink); color: var(--surface); }

/* ── rendered markdown inside assistant bubbles ── */
.cop-md .cmd-p { margin: 0 0 7px; }
.cop-md .cmd-p:last-child { margin-bottom: 0; }
.cop-md .cmd-h { font-weight: 700; margin: 8px 0 4px; font-family: var(--font-display, inherit); }
.cop-md ul { margin: 4px 0 8px; padding: 0; list-style: none; }
.cop-md li { position: relative; padding-left: 14px; margin: 2px 0; }
.cop-md li::before { content: '›'; position: absolute; left: 0; color: var(--accent); font-family: var(--font-mono); }
.cop-md code { font-family: var(--font-mono); font-size: .88em; background: var(--surface-2, #f3f3ef); border: 1px solid rgba(10,10,10,.12); padding: 0 3px; }
.cop-md b { font-weight: 700; }
.cop-md a { color: var(--accent); text-decoration: underline; }
/* Markdown pipe tables — brutalist mono, horizontally scrollable when wide. */
.cop-md .cmd-tbl-wrap { margin: 8px 0; overflow-x: auto; border: var(--bw-hair, 1px) solid var(--ink); background: var(--surface); }
.cop-md .cmd-tbl { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 11px; line-height: 1.4; }
.cop-md .cmd-tbl thead th {
  background: var(--ink); color: var(--surface);
  font-weight: 700; text-align: left; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 5px 8px; white-space: nowrap;
  border-right: var(--bw-hair, 1px) solid var(--surface);
}
.cop-md .cmd-tbl thead th:last-child { border-right: none; }
.cop-md .cmd-tbl tbody td {
  padding: 4px 8px; vertical-align: top;
  border-top: var(--bw-hair, 1px) solid var(--ink);
  border-right: var(--bw-hair, 1px) solid rgba(10,10,10,.18);
  white-space: nowrap;
}
.cop-md .cmd-tbl tbody td:last-child { border-right: none; }
.cop-md .cmd-tbl tbody tr:nth-child(even) td { background: var(--surface-2, #f3f3ef); }
/* First column gets a bit of emphasis since it's usually the row label. */
.cop-md .cmd-tbl tbody td:first-child { font-weight: 700; }

/* ── compact tool rows (Claude-Code style, collapsible groups) ── */
.cop-toolrow {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 8px; margin: 2px 0;
  border: var(--bw-hair, 1px) solid var(--ink);
  background: var(--surface);
  font-size: 11.5px; width: 100%; text-align: left;
}
.cop-toolrow-name { font-family: var(--font-mono); font-weight: 700; flex: none; }
.cop-toolrow-sum {
  font-size: 10.5px; color: var(--mute);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.cop-toolrow-st.run { font-family: var(--font-mono); color: var(--accent); flex: none; }
.cop-toolgroup { border: var(--bw-hair, 1px) solid var(--ink); margin: 2px 0; }
.cop-toolgroup .cop-toolrow { border: 0; margin: 0; }
.cop-toolgroup-head { cursor: pointer; background: var(--surface-2, #f4f3ee); border-bottom: var(--bw-hair, 1px) solid var(--ink); }
.cop-toolgroup-item { border-top: 1px solid rgba(10,10,10,.08) !important; padding-left: 24px; }
