/* Co-design (slice 3, spec §6): the Co-design card, the working note, the undo
   notice and the marks in the history. The card and the notice use the warnings
   card's frame and place (.warn-card in app.css): below the top bar on desktop,
   over the dock on a phone. Nothing here shows to someone who does not
   co-design, beyond the Co-design button. The app has one theme, a light one,
   so there is one set of colours. */

:root {
  /* The colour of "made by an AI" (C96): the badge, the note's dot and the notice's title. */
  --ai: #7c5cff;
  --ai-bg: rgba(124, 92, 255, .12);
}

/* ---------- The button ---------- */

.codesign-btn { position: relative; }
.codesign-dot { display: none; }
.is-live > .codesign-dot {
  display: inline-block;
  width: 8px; height: 8px;
  margin-left: var(--space-2);
  border-radius: 50%;
  background: var(--c-accent);
  vertical-align: middle;
}

/* ---------- The card ---------- */

.codesign-card { width: 340px; }
.codesign-body { display: grid; gap: var(--space-2); padding: 0 var(--space-2) var(--space-2); }
.codesign-text { font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.codesign-quiet { color: var(--c-text-2); font-size: 12px; }
.codesign-strong { font-weight: 600; }
.codesign-row { display: flex; gap: var(--space-2); align-items: center; }
.codesign-field {
  flex: 1 1 auto; min-width: 0;
  height: var(--ctl-h);
  padding: 0 var(--space-2);
  font-size: 13px;
  background: var(--c-input-bg);
  border: 1px solid var(--c-input-border);
  border-radius: var(--radius-ctl);
  text-overflow: ellipsis;
}
.codesign-field:focus-visible { border-color: var(--c-primary-dark); outline: none; box-shadow: var(--focus-ring); }
.codesign-copy { flex: none; }
.codesign-line { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.codesign-status { display: flex; align-items: center; gap: var(--space-2); font-size: 13px; min-width: 0; }
.codesign-status-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: rgba(0, 0, 0, .28); }
.codesign-status.is-joined .codesign-status-dot { background: var(--c-accent); }
.codesign-status.is-lost .codesign-status-dot { background: var(--c-warn); }
.codesign-setup { font-size: 13px; padding: 0 var(--space-2); }
.codesign-start, .codesign-stop, .codesign-reload, .codesign-pot { justify-self: start; }
.codesign-more { justify-self: start; color: var(--c-primary-dark); font-size: 13px; text-underline-offset: 2px; }
.codesign-sub { display: flex; align-items: center; gap: var(--space-1); margin-left: calc(var(--space-2) * -1); }
.codesign-subtitle { font-size: 13px; font-weight: 600; }
.codesign-apps { margin: 0; padding-left: var(--space-4); font-size: 13px; line-height: 1.4; display: grid; gap: var(--space-1); }
.codesign-said { min-height: 0; padding: 0 var(--space-2); font-size: 12px; color: var(--c-text-2); overflow-wrap: anywhere; }
.codesign-said:empty { display: none; }
.codesign-said:not(:empty) { padding-bottom: var(--space-2); }

@media (max-width: 760px) {
  .codesign-card { width: auto; }
  .codesign-body { gap: var(--space-3); padding: 0 var(--space-1) var(--space-2); }
  .codesign-text, .codesign-status, .codesign-apps, .codesign-setup, .codesign-subtitle { font-size: 15px; }
  .codesign-quiet, .codesign-said { font-size: 13px; }
  .codesign-field { height: 44px; font-size: 16px; }
  .codesign-card .btn { min-height: 44px; }
  .codesign-card .btn-icon { min-width: 44px; }
}

/* ---------- The working note ---------- */

/* At the foot of the stage, inside the region the pot is fitted into and below the pot itself,
   so it is never over the pot (D22). main.js keeps the region in --stage-*. */
#codesign-note {
  position: fixed;
  left: calc(var(--stage-left, 0px) + var(--stage-width, 100vw) / 2);
  bottom: calc(var(--stage-foot, 0px) + var(--space-1));
  transform: translateX(-50%);
  z-index: 20;
  display: flex; align-items: center; gap: var(--space-2);
  max-width: calc(var(--stage-width, 100vw) - var(--space-4));
  padding: 6px var(--space-3);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  box-shadow: var(--shadow-2);
  pointer-events: none;
}
.codesign-note-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ai); animation: codesign-pulse 1.4s ease-in-out infinite; }
@keyframes codesign-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .codesign-note-dot { animation: none; } }

/* ---------- The undo notice ---------- */

.codesign-notice { width: 320px; }
.codesign-notice-title { color: var(--ai); }
.codesign-parts { display: grid; }
.codesign-part { padding: var(--space-2); display: grid; gap: var(--space-1); }
.codesign-part + .codesign-part { border-top: 1px solid var(--c-border); }
.codesign-part-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.codesign-part-name { font-size: 13px; font-weight: 600; }
.codesign-part-lines { font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.codesign-correction {
  font-size: 12px; line-height: 1.4; overflow-wrap: anywhere;
  padding: var(--space-1) var(--space-2);
  background: var(--c-warn-bg);
  border-radius: var(--radius-ctl);
}
.codesign-undo { min-height: 32px; height: 32px; padding: 0 var(--space-3) 0 var(--space-2); gap: var(--space-1); font-size: 13px; }
.codesign-undo-icon { display: inline-flex; }
.codesign-undo-icon svg { width: 16px; height: 16px; }
.codesign-kept { display: grid; gap: var(--space-1); }
.codesign-kept-line { padding: 0 var(--space-2) var(--space-2); font-size: 12px; color: var(--c-text-2); overflow-wrap: anywhere; }

@media (max-width: 760px) {
  #codesign-note { font-size: 13px; }
  .codesign-notice { width: auto; }
  .codesign-part-name, .codesign-part-lines { font-size: 15px; }
  .codesign-correction, .codesign-kept-line { font-size: 13px; }
  .codesign-undo { min-height: 44px; height: 44px; font-size: 15px; }
}

/* ---------- The marks in the history (spec §6.4) ---------- */

/* Only in a history that holds an AI's step (C46). The picture keeps its size and place; the
   marks sit on its corners, so the column stays as wide as it was. */
.history-pic { position: relative; flex: none; display: block; line-height: 0; }
.history-marks { position: absolute; inset: 0; pointer-events: none; line-height: 1; }
.history-by, .history-parts {
  position: absolute;
  padding: 1px 3px;
  font-size: 9px; font-weight: 700; letter-spacing: .02em; line-height: 1.2;
  border-radius: 4px;
  white-space: nowrap;
}
.history-by { top: -2px; left: -2px; color: #fff; background: var(--ai); }
.history-parts { right: -2px; bottom: -2px; color: var(--c-text); background: rgba(255, 255, 255, .92); box-shadow: 0 0 0 1px var(--c-border); }
.history-dot {
  position: absolute; top: -2px; right: -2px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c-warn);
  box-shadow: 0 0 0 1.5px #fff;
}
/* The phone's column and its full list stack the picture over the time: the picture takes the width. */
.history-overlay .history-pic { width: 100%; }
@media (max-width: 760px) {
  .history-card .history-pic { width: 100%; max-height: 52px; display: flex; justify-content: center; }
  .history-card .history-marks { left: 50%; right: auto; width: min(100%, 52px); transform: translateX(-50%); }
  .history-by, .history-parts { font-size: 9px; }
  .history-overlay .history-by, .history-overlay .history-parts { font-size: 11px; padding: 2px 5px; }
  .history-overlay .history-dot { width: 10px; height: 10px; }
}
