/*
 * AI features of the chat page (W3.x): the summary side panel, the task/Finding draft dialog and
 * the "Exact words | Similar meaning" switch of the search. Tokens and the shared classes
 * chat-button, chat-field, chat-input and chat-error come from chat.css; the dialog shell from
 * admin.css. This file only adds chat-ai-*, chat-draft-* and chat-search-mode* classes.
 */

/* Summary side panel */

.chat-ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: min(420px, 100vw);
  border-left: 1px solid var(--line-strong);
  background: var(--panel-solid);
  box-shadow: -16px 0 40px rgb(15 23 42 / 0.16);
}

.chat-ai-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.chat-ai-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

/* The heading only receives focus so the panel is announced; it is not a control. */
.chat-ai-title:focus {
  outline: none;
}

.chat-ai-private {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.chat-ai-close {
  flex: none;
  font-size: 18px;
  line-height: 1;
}

.chat-ai-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 14px 16px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Progress of a running job (panel and draft dialog) */

.chat-ai-progress {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-raised);
}

.chat-ai-progress-text {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 2px 10px;
  align-items: baseline;
  min-width: 0;
}

.chat-ai-stage {
  font-weight: 600;
}

.chat-ai-elapsed {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chat-ai-spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--cyan-soft);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: chat-ai-spin 0.9s linear infinite;
}

@keyframes chat-ai-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-ai-spinner {
    border-color: var(--cyan);
    animation: none;
  }
}

.chat-ai-actions:has(> [hidden]:only-child),
.chat-ai-actions:empty {
  display: none;
}

/* Summary result */

.chat-ai-result {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-ai-result:empty {
  display: none;
}

.chat-ai-basis {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.chat-ai-section-title {
  margin: 4px 0 6px;
  color: var(--muted-bright);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-ai-items {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-left: 18px;
}

.chat-ai-item {
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.chat-ai-sources {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.chat-ai-source {
  color: var(--muted-bright);
  font-weight: 600;
}

a.chat-ai-source {
  color: var(--cyan);
  text-decoration: none;
}

a.chat-ai-source:hover {
  text-decoration: underline;
}

.chat-ai-cost {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  .chat-ai-panel {
    width: 100vw;
    border-left: 0;
    box-shadow: none;
  }
}

/* Draft dialog (task or Finding from a thread) */

.chat-admin-dialog.chat-draft-dialog {
  max-width: 640px;
}

.chat-draft-lead,
.chat-draft-origin {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.chat-draft-form > .chat-draft-origin,
.chat-draft-form > .chat-draft-field,
.chat-draft-form > .chat-ai-cost {
  flex: 1 1 100%;
  margin: 0;
}

/* Scope, repository area and target kind share a line on wide screens. */
.chat-draft-form > .chat-draft-field[data-field="scope"],
.chat-draft-form > .chat-draft-field[data-field="repo_area"],
.chat-draft-form > .chat-draft-field[data-field="target_kind"] {
  flex: 1 1 160px;
}

.chat-draft-text {
  min-height: 96px;
  resize: vertical;
  line-height: 1.45;
}

.chat-draft-field-error {
  font-size: 12px;
}

.chat-draft-form .chat-admin-form-actions {
  justify-content: flex-end;
}

.chat-draft-status {
  margin-right: auto;
  color: var(--muted);
  font-size: 13px;
}

.chat-draft-done {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}

.chat-draft-id {
  font-family: var(--mono);
  font-size: 14px;
}

a.chat-draft-id {
  color: var(--cyan);
}

/* Search: exact words or similar meaning */

.chat-search-mode {
  display: inline-flex;
  align-self: flex-start;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-raised);
}

.chat-search-mode-option {
  min-height: 28px;
  padding: 3px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-bright);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chat-search-mode-option:hover:not([aria-pressed="true"]) {
  color: var(--text);
}

.chat-search-mode-option[aria-pressed="true"] {
  background: var(--panel-solid);
  color: var(--cyan);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.14);
}

.chat-search-mode-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

/* The search tools row: the mode switch, and on a phone the "Filters" button (search_view.js). */
.chat-search-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chat-search-filter-open {
  display: none;
}

/* ---------------------------------------------------------------------------------------------
   Phones (EPIC 0caed80242c8, plan item 5): the summary panel is a full-height sheet (sheet.js,
   data-surface="sheet"); the draft dialog and the search are full-screen with 44 px targets. */

.chat-ai-panel[data-surface="sheet"] {
  position: static;
  z-index: auto;
  width: auto;
  min-height: 100%;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.chat-ai-panel[data-surface="sheet"] .chat-ai-head {
  padding: 0 0 10px;
}

.chat-ai-panel[data-surface="sheet"] .chat-ai-title {
  font-size: 18px;
}

.chat-ai-panel[data-surface="sheet"] .chat-ai-private {
  font-size: 13px;
}

.chat-ai-panel[data-surface="sheet"] .chat-ai-close {
  min-width: 44px;
  min-height: 44px;
  font-size: 24px;
}

.chat-ai-panel[data-surface="sheet"] .chat-ai-body {
  padding: 12px 0 16px;
  overflow: visible;
}

.chat-ai-panel[data-surface="sheet"] :is(.chat-ai-cancel, .chat-ai-actions .chat-button) {
  min-height: 44px;
  padding: 0 16px;
}

.chat-ai-panel[data-surface="sheet"] :is(.chat-ai-basis, .chat-ai-sources, .chat-ai-elapsed, .chat-ai-section-title) {
  font-size: 13px;
}

.chat-ai-panel[data-surface="sheet"] .chat-ai-item {
  font-size: 15px;
}

.chat-ai-panel[data-surface="sheet"] .chat-ai-source {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
  font-size: 14px;
}

html[data-chat-layout="phone"] :is(.chat-draft-lead, .chat-draft-origin, .chat-draft-status) {
  font-size: 15px;
}

html[data-chat-layout="phone"] .chat-draft-dialog .chat-field-hint {
  font-size: 13px;
}

html[data-chat-layout="phone"] .chat-draft-dialog .chat-ai-cancel {
  min-height: 44px;
}

html[data-chat-layout="phone"] :is(.chat-search-row .chat-input, .chat-search-row .chat-button, .chat-search-more) {
  min-height: 44px;
}

html[data-chat-layout="phone"] .chat-search-mode-option {
  min-height: 44px;
  padding: 0 14px;
  font-size: 14px;
}

html[data-chat-layout="phone"] .chat-search-filter-open {
  display: inline-flex;
  min-height: 44px;
  margin-left: auto;
  padding: 0 14px;
  font-size: 15px;
}

html[data-chat-layout="phone"] .chat-search-form > .chat-search-filters {
  display: none;
}

/* The filters in their sheet: one per line, full width, 44 px tall. */
.chat-search-filters[data-surface="sheet"] {
  display: grid;
  gap: 12px;
  padding: 2px 4px 4px;
}

.chat-search-filters[data-surface="sheet"] :is(select, input[type="date"]) {
  width: 100%;
  max-width: none;
  min-height: 44px;
  font-size: 16px;
}

.chat-search-filters[data-surface="sheet"] .chat-search-date {
  display: grid;
  gap: 4px;
  color: var(--muted-bright);
  font-size: 14px;
}

.chat-search-filters[data-surface="sheet"] .chat-search-check {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  color: var(--text);
  font-size: 16px;
}

.chat-search-filters[data-surface="sheet"] .chat-search-check input {
  width: 22px;
  height: 22px;
  accent-color: var(--cyan);
}
