/* /account/agent — show.html.erb
 *
 * Figma work-file screens #6a (empty state, 137:3210) and #6b (active chat,
 * 137:4243), assembled from the Input AI Chat (152:5729) and AI Agent
 * Conversation List Item (137:4109) component sets. Rail (Conversations +
 * Documents) beside the chat column — Björn moved it to the right (the Figma
 * has it on the left); radius is corner-radius-xs (4px) throughout.
 */

/* ============ Page layout ============ */
.agent-page {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-24);
  height: calc(100vh - 9rem); /* Note: viewport minus nav clearance + bottom gutter */
}
/* .app-main's top padding drops to 5rem on mobile, so the column reclaims the
   2rem it no longer has to clear. */
@media (max-width: 47.999rem) {
  .agent-page { height: calc(100vh - 7rem); }
}
@media (min-width: 64rem) {
  .agent-page { flex-direction: row; gap: var(--spacing-32); }
}

/* ============ Right rail (desktop) ============ */
/* `order: 1` places the rail after the chat column (chat stays first in the
   DOM for reading order). The Figma puts it on the left; Björn moved it right. */
.agent-sidebar { display: none; }
@media (min-width: 64rem) {
  .agent-sidebar {
    display: block;
    order: 1;
    width: 20rem; /* Note: Figma sidebar = 320px */
    flex-shrink: 0;
    overflow-y: auto;
  }
}

.agent-sidebar-divider {
  border: 0;
  border-top: var(--stroke-weight-1) solid var(--border-default);
  margin-block: var(--spacing-8);
}

.agent-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-8);
  padding: var(--spacing-8) 0 var(--spacing-8) var(--spacing-8);
}

.agent-sidebar-heading {
  font-size: var(--font-size-16);
  font-weight: var(--font-weight-600);
  line-height: 1;
  letter-spacing: var(--font-letter-spacing-wider);
  color: var(--text-primary);
}

.agent-sidebar-count {
  color: var(--text-tertiary);
  font-weight: var(--font-weight-600);
}

/* The grey New / Upload buttons keep their auto width; the upload form wrapper
   must not introduce its own box (the <label> is the button). */
.agent-upload-form { display: contents; }
.agent-sidebar-action { cursor: pointer; }

.agent-sidebar-list {
  & > * + * { margin-top: var(--spacing-4); }
}

.agent-sidebar-empty {
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--font-size-14);
  line-height: 1.25rem;
  padding-block: var(--spacing-24);
}

.agent-sidebar-empty-hint {
  font-size: var(--font-size-12);
  line-height: 1rem;
  margin-top: var(--spacing-4);
}

/* ============ List item — conversations + documents ============ */
/* AI Agent Conversation List Item (137:4109). */
.agent-item {
  position: relative;
  border-radius: var(--corner-radius-xs);
}
.agent-item:hover { background-color: var(--background-hover); }
.agent-item--active { background-image: var(--brand-gradient); }

.agent-item-button {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-4);
  width: 100%;
  text-align: left;
  padding: var(--spacing-4) var(--spacing-8);
}

.agent-item-title {
  font-size: var(--font-size-16);
  font-weight: var(--font-weight-600);
  line-height: 1.25;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-item-meta {
  font-size: var(--font-size-14);
  font-weight: var(--font-weight-400);
  line-height: 1;
  color: var(--text-tertiary);
}
.agent-item:hover .agent-item-meta { color: var(--text-secondary); }

/* Active rows sit on the brand gradient, which is dark in both themes — pin their
   text and icons to the fixed-light tokens so they don't flip in light mode. */
.agent-item--active .agent-item-title { color: var(--text-light); }
.agent-item--active .agent-item-meta,
.agent-item--active:hover .agent-item-meta { color: var(--text-light); }

/* Row actions (trash / download) — revealed on hover, top-right. */
.agent-item-actions {
  display: none;
  position: absolute;
  top: var(--spacing-4);
  right: var(--spacing-4);
  align-items: center;
  gap: var(--spacing-2);
  background-color: inherit; /* mask the truncated title underneath */
}
.agent-item:hover .agent-item-actions,
.agent-item--active .agent-item-actions { display: flex; }

/* Active rows paint the gradient via background-image, not background-color, so the
   `inherit` mask above must stay transparent here — otherwise hovering anywhere on
   the row (including these buttons, which also triggers .agent-item:hover) picks up
   the flat --background-hover color and paints a visible patch over the gradient. */
.agent-item--active .agent-item-actions { background-color: transparent; }

.agent-item-action {
  padding: var(--spacing-4);
  border-radius: var(--corner-radius-xs);
  color: var(--symbol-default);
}
.agent-item-action:hover { color: var(--text-primary); }
.agent-item--active .agent-item-action,
.agent-item--active .agent-item-action:hover { color: var(--symbol-light); }

.agent-item-action-icon { width: 1rem; height: 1rem; }

/* Trash button — fixed 20x20 hit area; dimmed on gradient (active) rows until hovered. */
.agent-item-action--trash {
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.agent-item--active .agent-item-action--trash { opacity: 0.75; }
.agent-item--active .agent-item-action--trash:hover { opacity: 1; }

/* Conversation overflow disclosure */
.agent-convo-overflow { margin-top: var(--spacing-4); }

.agent-convo-overflow-toggle {
  cursor: pointer;
  list-style: none;
  font-size: var(--font-size-12);
  line-height: 1rem;
  color: var(--text-tertiary);
  padding: var(--spacing-4) var(--spacing-8);

  &::-webkit-details-marker { display: none; }
  &:hover { color: var(--text-primary); }
}
.agent-convo-overflow[open] .agent-convo-overflow-more { display: none; }
.agent-convo-overflow:not([open]) .agent-convo-overflow-less { display: none; }
.agent-convo-overflow-list > * + * { margin-top: var(--spacing-4); }
.agent-convo-overflow-list { margin-top: var(--spacing-4); }

/* ============ Chat column ============ */
.agent-chat {
  flex: 1 1 0%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* Shared content measure — Figma chat content is 740px in an 848px column. */
.agent-empty-inner,
.agent-thread-inner,
.agent-topbar,
.agent-composer,
.agent-composer-wrap .agent-paywall-card {
  width: 100%;
  max-width: 46.25rem; /* Note: Figma chat content width = 740px */
  margin-inline: auto;
}

/* ---- Empty state ---- */
.agent-empty {
  flex: 1 1 0%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.agent-empty-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-48);
}

.agent-empty-title {
  font-size: var(--font-size-32);
  font-weight: var(--font-weight-700);
  line-height: 1.15;
  letter-spacing: var(--font-letter-spacing-tight);
  color: var(--text-primary);
  text-align: center;
}

/* ---- Active thread ---- */
.agent-thread {
  flex: 1 1 0%;
  overflow-y: auto;
  min-height: 0;
}

.agent-thread-inner {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-24);
  padding-bottom: var(--spacing-16);
}

/* Sticky title bar fading the messages scrolling beneath it. On mobile it also
   carries the side-panel toggle, pinned to the right (see agent-sidepanel.css). */
.agent-topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-8);
  padding-bottom: var(--spacing-16);
  background-image: linear-gradient(var(--background-base) 40%, transparent);
}

/* An untitled thread renders the row only to hold that toggle, so it collapses
   on desktop where the toggle is hidden. */
@media (min-width: 64rem) {
  .agent-topbar--untitled { display: none; }
}

.agent-topbar-title {
  font-size: var(--font-size-14);
  font-weight: var(--font-weight-600);
  line-height: 1.15;
  color: var(--text-primary);
}

/* Thinking / Documenting status pill (Figma "Frame 134"). */
.agent-status {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-12);
  padding: var(--spacing-4);
  border-radius: var(--corner-radius-xs);
  background-color: var(--background-base);
  color: var(--text-secondary);
}

.agent-status-icon { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }

.agent-status-label {
  font-size: var(--font-size-16);
  line-height: 1.25;
}

.agent-status-dots { display: inline-flex; }

.agent-status-dot {
  opacity: 0;
  animation: 1.6s infinite;
  animation-timing-function: step-end;
}
.agent-status-dot::after { content: "."; }
.agent-status-dot:nth-child(1) { animation-name: agent-status-dot-1; }
.agent-status-dot:nth-child(2) { animation-name: agent-status-dot-2; }
.agent-status-dot:nth-child(3) { animation-name: agent-status-dot-3; }

/* Dots accumulate one at a time (1, then 1+2, then 1+2+3), then all clear together. */
@keyframes agent-status-dot-1 {
  0%, 74.9% { opacity: 1; }
  75%, 100% { opacity: 0; }
}
@keyframes agent-status-dot-2 {
  0%, 24.9% { opacity: 0; }
  25%, 74.9% { opacity: 1; }
  75%, 100% { opacity: 0; }
}
@keyframes agent-status-dot-3 {
  0%, 49.9% { opacity: 0; }
  50%, 74.9% { opacity: 1; }
  75%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .agent-status-dot { animation: none; opacity: 1; }
}

/* ---- Composer (Input AI Chat 152:5729) ---- */
.agent-composer-wrap { flex-shrink: 0; padding-top: var(--spacing-16); }

.agent-composer {
  display: flex;
  align-items: flex-end;
  gap: var(--spacing-8);
  padding: var(--spacing-12) var(--spacing-8) var(--spacing-12) var(--spacing-16);
  border-radius: var(--corner-radius-xs);
  border: var(--stroke-weight-1) solid transparent;
  background-color: var(--background-surface-2);
  transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1), border-color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.agent-composer:focus-within {
  background-color: var(--background-hover);
  border-color: var(--border-strong);
}

.agent-composer-input {
  flex: 1 1 0%;
  resize: none;
  border: 0;
  background: transparent;
  /* Floor at the Figma multi-row content height (116px) so the empty field reads
     as the 140px box; chat#autoGrow grows it from here, capped at 200px. */
  min-height: 7.25rem;
  padding: var(--spacing-2) 0;
  color: var(--text-primary);
  font-size: var(--font-size-16);
  line-height: 1.25;

  &::placeholder { color: var(--text-secondary); }
  &:focus { outline: none; }
  &:disabled { opacity: 0.5; cursor: not-allowed; }
}

.agent-composer-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--spacing-32);
  height: var(--spacing-32);
  border: 0;
  border-radius: var(--corner-radius-xs);
  background-image: var(--brand-gradient);
  color: var(--text-light);
  cursor: pointer;

  &:hover { background-image: var(--brand-gradient-hover); }
  &:disabled { opacity: 0.5; cursor: not-allowed; }
}

.agent-composer-send-icon { width: var(--spacing-16); height: var(--spacing-16); }

/* ---- Paywall (over cap) ---- */
.agent-paywall-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-12);
  text-align: center;
  padding: var(--spacing-24);
  border-radius: var(--corner-radius-xs);
  background-color: var(--background-surface-1);
  color: var(--text-secondary);
}

/* ============ Document modal ============ */
.agent-doc-image, .agent-doc-pdf { border-radius: var(--corner-radius-xs); }
.agent-doc-image { max-width: 100%; }
.agent-doc-pdf { width: 100%; }
.agent-doc-prose { max-width: none; }

.agent-modal {
  position: fixed;
  inset: var(--spacing-0);
  z-index: 50;
  margin: var(--spacing-0);
  height: 100%;
  width: 100%;
  max-height: 100%;
  max-width: 100%;
  background-color: transparent;
  padding: var(--spacing-0);

  &::backdrop { background-color: rgb(0 0 0 / 0.5); }
}

.agent-modal-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: var(--spacing-16);
}

.agent-modal-card {
  background-color: var(--background-surface-1);
  border-radius: var(--corner-radius-xs);
  max-width: 42rem; /* Note: bespoke modal width */
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.agent-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-16) var(--spacing-24);
  border-bottom: var(--stroke-weight-1) solid var(--border-default);
}

.agent-modal-title {
  font-size: var(--font-size-16);
  font-weight: var(--font-weight-600);
  color: var(--text-primary);
}

/* Pinned to the top of the header rather than centred, so a long title that
   wraps to a second line pushes the row down without dragging the buttons with
   it. */
.agent-modal-actions {
  display: flex;
  align-self: flex-start;
  align-items: center;
  gap: var(--spacing-4);
}

.agent-modal-action-button--download,
.agent-modal-action-button--close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--corner-radius-xs);
  color: var(--symbol-default);

  &:hover { color: var(--text-primary); background-color: var(--background-hover); }
}

.agent-modal-action-icon { width: 1.25rem; height: 1.25rem; }

.agent-modal-body {
  padding: var(--spacing-16) var(--spacing-24);
  overflow-y: auto;
  flex: 1 1 0%;
}

/* Medical disclaimer — this page hides the global footer, which carries the
   same line everywhere else. Sits below the composer, on the shared 740px
   content measure. */
.agent-disclaimer {
  flex-shrink: 0;
  width: 100%;
  max-width: 46.25rem;
  margin: var(--spacing-8) auto 0;
  padding-bottom: var(--spacing-8);
  color: var(--text-tertiary);
  font-size: var(--font-size-12);
  text-align: center;
}
