/* SOG Agent conversation history.

   A drawer over the thread rather than a column beside it: the panel is around
   420px wide, and a list narrow enough to sit next to a conversation would be
   too narrow to read a conversation's name in. It covers the thread while you
   choose, and gets out of the way once you have. */

/* The drawer is a grid item in the panel, in the same cell as the thread.

   It used to be position:absolute with a top offset measured in JS, which meant
   three things had to stay true at once: the panel had to be a containing block
   (it is display:grid with no position, so the drawer escaped to the viewport
   and covered the whole window), the offset had to be re-measured whenever the
   header or the engine console changed height, and inset:...0 0 0 stretched it
   to the panel's bottom edge -- swallowing the composer along with the thread.

   Asking for the thread's cell by name settles all three. Nothing is measured,
   nothing depends on the panel's position (which the <=1320px breakpoint
   changes to fixed anyway -- which is why the panel's position had ended up
   declared in three places), and the drawer ends where the thread ends, so you
   can still type while you are looking for a conversation. */
.agent-history {
  grid-area: thread;
  z-index: 40;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-1);
  border-top: 1px solid var(--hairline);
  animation: agent-history-in var(--motion-fast) var(--ease);
}

.agent-history[hidden] {
  display: none;
}

@keyframes agent-history-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

/* -- head --------------------------------------------------------------- */

.agent-history-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 8px;
}

.agent-history-tabs {
  display: flex;
  gap: 2px;
}

.agent-history-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border: 0;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--text-3);
  font-size: var(--fs-1);
  letter-spacing: .01em;
  cursor: pointer;
  transition: color var(--motion-fast) var(--ease),
              background var(--motion-fast) var(--ease);
}

.agent-history-tabs button:hover { color: var(--text-1); }

.agent-history-tabs button.is-active {
  background: var(--surface-3);
  color: var(--text-1);
}

/* An empty count would leave a gap the label has to step over. */
.agent-history-tabs b:empty { display: none; }

.agent-history-tabs b {
  min-width: 16px;
  padding: 1px 4px;
  border-radius: 20px;
  background: var(--surface-4, var(--surface-2));
  color: var(--text-3);
  font-size: 9px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.agent-history-head > button {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.agent-history-head > button:hover { color: var(--text-1); background: var(--surface-3); }

/* -- search ------------------------------------------------------------- */

.agent-history-search {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 12px 8px;
  padding: 0 9px;
  height: 30px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-1);
  background: var(--surface-2);
  color: var(--text-3);
}

.agent-history-search:focus-within {
  border-color: var(--hairline-strong);
  color: var(--text-2);
}

.agent-history-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--text-1);
  font: inherit;
  font-size: var(--fs-2);
  outline: none;
}

.agent-history-search input::-webkit-search-cancel-button { display: none; }

/* -- list --------------------------------------------------------------- */

.agent-archive-clear { flex: none; margin: 0 12px 8px; color: var(--text-3); font-size: 11px; }
.agent-archive-clear[hidden], .agent-archive-clear [hidden] { display: none; }
.agent-archive-clear > button, .agent-archive-clear [data-archive-clear-preview] button { border: 1px solid var(--hairline-strong); border-radius: var(--r-1); padding: 6px 9px; background: var(--surface-2); color: var(--text-1); font: inherit; cursor: pointer; }
.agent-archive-clear > button { color: var(--danger, #e5484d); }
.agent-archive-clear button:disabled { opacity: .45; cursor: not-allowed; }
.agent-archive-clear p { margin: 6px 0; line-height: 1.5; }
.agent-archive-clear [data-archive-clear-preview] { max-height: 42vh; overflow: auto; padding: 10px; border: 1px solid var(--danger, #e5484d); border-radius: var(--r-1); background: var(--surface-2); color: var(--text-2); }
.agent-archive-clear [data-archive-clear-preview] > div { display: flex; gap: 8px; flex-wrap: wrap; }
.agent-archive-clear [data-archive-clear-confirm] { color: var(--danger, #e5484d) !important; border-color: currentColor !important; }
.agent-archive-clear :focus-visible { outline: 2px solid var(--gold-ring); outline-offset: 2px; }

.agent-history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 14px;
  overscroll-behavior: contain;
}

.agent-history-list h4 {
  margin: 10px 0 4px;
  padding: 0 4px;
  color: var(--text-3);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.agent-history-list ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.agent-history-note {
  margin: 18px 12px;
  color: var(--text-3);
  font-size: var(--fs-2);
  line-height: 1.5;
}

.agent-history-row {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--r-1);
}

/* A public workflow example stays separate from dated, account-owned history. */
.agent-history-example-section { margin: 0 0 12px; }
.agent-history-example { border: 1px solid var(--hairline); border-radius: var(--r-1); background: var(--surface-2); }
.agent-history-example summary { padding: 10px; cursor: pointer; color: var(--text-1); }
.agent-history-example summary strong { font-size: var(--fs-2); font-weight: 600; overflow-wrap: anywhere; }
.agent-history-example summary small { display: block; margin-top: 3px; color: var(--text-3); font-size: 10px; }
.agent-history-example-body { padding: 0 12px 12px; color: var(--text-2); font-size: var(--fs-2); line-height: 1.55; }
.agent-history-example-body h5 { margin: 12px 0 6px; color: var(--text-1); font: inherit; font-weight: 600; }
.agent-history-example-body p { margin: 8px 0; }
.agent-history-example-body ol { margin: 6px 0; padding-left: 20px; }
.agent-history-example-body li { margin: 6px 0; }
.agent-history-example-body label { display: grid; gap: 5px; margin: 12px 0 6px; color: var(--text-3); }
.agent-history-example-body select { width: 100%; min-width: 0; padding: 6px; border: 1px solid var(--hairline); border-radius: var(--r-1); background: var(--surface-1); color: var(--text-1); font: inherit; }
.agent-history-example-body blockquote { margin: 8px 0; padding: 10px; border-left: 2px solid var(--hairline-strong); background: var(--surface-1); color: var(--text-2); overflow-wrap: anywhere; white-space: pre-wrap; }
.agent-history-example-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.agent-history-example-actions button { padding: 7px 10px; border: 1px solid var(--hairline-strong); border-radius: var(--r-1); background: var(--surface-3); color: var(--text-1); font: inherit; cursor: pointer; }
.agent-history-example-actions button:hover { background: var(--surface-1); }
.agent-history-example-body .agent-history-example-limit { font-size: 11px; color: var(--text-3); }
.agent-history-example [data-example-notice]:empty { display: none; }
.agent-history-example .agent-example-reference { display: block; max-width: 100%; max-height: 340px; width: auto; margin: 8px auto; border-radius: 4px; }
.agent-history-example :focus-visible { outline: 2px solid var(--gold-ring); outline-offset: 2px; }

.agent-history-row:hover { background: var(--surface-2); }

.agent-history-row.is-current { background: var(--gold-soft); }

.agent-history-open {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
  padding: 7px 8px;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.agent-history-open strong {
  display: block;
  overflow: hidden;
  color: var(--text-1);
  font-size: var(--fs-2);
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.agent-history-open small {
  color: var(--text-3);
  font-size: 10px;
}

.agent-history-row.is-current .agent-history-open strong { color: var(--text-1); }

/* -- row actions --------------------------------------------------------
   Hidden until the row is hovered or something inside it has focus, so the
   list reads as names rather than as rows of buttons. Keyboard users get them
   from :focus-within, which is why this is not display:none. */

.agent-history-actions {
  display: flex;
  gap: 1px;
  padding-right: 5px;
  opacity: 0;
  transition: opacity var(--motion-fast) var(--ease);
}

.agent-history-row:hover .agent-history-actions,
.agent-history-row:focus-within .agent-history-actions { opacity: 1; }

.agent-history-actions button {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.agent-history-actions button:hover { background: var(--surface-3); color: var(--text-1); }
.agent-history-actions button:last-child:hover { color: var(--danger, #e5484d); }

.agent-history-row :focus-visible {
  outline: 2px solid var(--gold-ring);
  outline-offset: -2px;
  border-radius: var(--r-1);
}

/* -- renaming ----------------------------------------------------------- */

.agent-history-row.is-renaming form {
  display: flex;
  align-items: center;
  gap: 3px;
  width: 100%;
  padding: 4px 5px 4px 8px;
}

.agent-history-row.is-renaming input {
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 7px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-1);
  background: var(--surface-1);
  color: var(--text-1);
  font: inherit;
  font-size: var(--fs-2);
  outline: none;
}

.agent-history-row.is-renaming button {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.agent-history-row.is-renaming button:hover { background: var(--surface-3); color: var(--text-1); }

/* -- deleting -----------------------------------------------------------
   Confirmed in the row itself. Archiving is one click because it is
   reversible; deleting is not, so it asks. */

.agent-history-row.is-confirming {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--hairline-strong);
}

.agent-history-row.is-confirming p {
  margin: 0;
  color: var(--text-2);
  font-size: var(--fs-2);
}

.agent-history-row.is-confirming div { display: flex; gap: 6px; }

.agent-history-row.is-confirming button {
  padding: 4px 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-1);
  background: var(--surface-1);
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-1);
  cursor: pointer;
}

.agent-history-row.is-confirming button.danger {
  border-color: var(--danger, #e5484d);
  color: var(--danger, #e5484d);
}

.agent-history-row.is-confirming button:hover { border-color: var(--hairline-strong); }

@media (prefers-reduced-motion: reduce) {
  .agent-history { animation: none; }
  .agent-history-actions,
  .agent-history-tabs button { transition: none; }
}

/* Saved Ruby case: file status and the actual conversation. */
.su-case-file { display:grid; gap:10px; padding:14px; margin-bottom:18px; border:1px solid var(--hairline-strong); border-radius:var(--r-1); }
.su-case-file p { margin:0; }
.su-case-file button,.su-case-download { justify-self:start; }
.su-case-file button:disabled { opacity:.5; cursor:not-allowed; }
.su-case-download { padding:9px 14px; border:1px solid var(--hairline-strong); border-radius:var(--r-1); color:var(--text-1); }
.su-case-file code { overflow-wrap:anywhere; }
.su-case-message { padding:18px 0; border-bottom:1px solid var(--hairline); }
.su-case-message header { display:flex; justify-content:space-between; gap:12px; margin-bottom:9px; }
.su-case-message header span { color:var(--text-3); font-size:11px; }
.su-case-message-text { white-space:pre-wrap; overflow-wrap:anywhere; line-height:1.65; color:var(--text-2); }
.su-case-transcript { border-top:1px solid var(--hairline); }
