/* chat.css — styles for views/chat.js
 *
 * Spec: specs/services/chat/spec.yaml > ui
 *       specs/ui-platform.yaml > components.chat_message_bubble + chat_composer
 * Tack: TRK-475 (v1) + TRK-482 (Claude-app polish)
 *
 * Aesthetic targets:
 *   - Composer: single rounded card with the send button inset bottom-right.
 *   - Bubbles: assistant has no bubble (full-width text); user is right-
 *     aligned with a soft accent background — Claude/ChatGPT signature.
 *   - Threads: section headers (Today / Past 7 days / Older) instead of a
 *     flat list.
 *   - Empty state: large greeting + 4 starter-prompt cards.
 *
 * Layering: this stylesheet only declares chat-view-specific selectors.
 * Round buttons reuse .sift-icon-btn (app/css/05-icon-btn.css). Card edges,
 * shadows, palette tokens come from app/next/css/themes.css. Sizes consume
 * the platform scale (--fs-*, --sp-*, --r-*) declared in themes.css.
 */

.chat-view {
  font-size: var(--fs-base);          /* platform body baseline */
  height: 100%;
  display: block;
}

.chat-shell {
  display: grid;
  grid-template-columns: var(--chat-rail-w, 240px) 1fr;
  height: 100%;
  min-height: 0;
}

@media (max-width: 720px) {
  .chat-shell { grid-template-columns: 1fr; }
  .chat-threads { display: none; }
}

/* ── Thread list rail ─────────────────────────────────────────────── */

.chat-threads {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border, rgba(0,0,0,0.08));
  background: var(--surface, transparent);
  min-height: 0;
}

.chat-threads__header {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
}

.chat-threads__title {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, rgba(0,0,0,0.55));
  flex: 1;
}

.chat-threads__list {
  list-style: none;
  margin: 0;
  padding: var(--sp-1) var(--sp-2) var(--sp-3);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.chat-threads__group-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted, rgba(0,0,0,0.55));
  padding: var(--sp-3) var(--sp-2) var(--sp-1);
  letter-spacing: 0.02em;
}

.chat-threads__group-label:first-child {
  padding-top: var(--sp-1);
}

.chat-thread-row {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-2);
  border-radius: var(--r-md);
  cursor: pointer;
  color: var(--fg, rgba(0,0,0,0.85));
  font-size: var(--fs-base);
  transition: background var(--motion-tooltip-fade, 80ms) ease;
  margin: 1px 0;
}

.chat-thread-row:hover {
  background: var(--hover, rgba(0,0,0,0.04));
}

.chat-thread-row.is-active {
  background: var(--ui-sidebar-btn-active, rgba(0,0,0,0.06));
  color: var(--ui-sidebar-btn-active-fg, var(--fg));
}

.chat-thread-row__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-thread-row__del {
  /* Smaller icon-btn variant — context override per platform pattern
   * (see .row-actions in 60-table-area.css). */
  --icon-btn-size: 20px;
  --icon-btn-glyph: 12px;
  opacity: 0;
  transition: opacity var(--motion-tooltip-fade, 80ms) ease;
}

.chat-thread-row:hover .chat-thread-row__del,
.chat-thread-row.is-active .chat-thread-row__del {
  opacity: 1;
}

.chat-thread-row--empty {
  padding: var(--sp-3);
  color: var(--muted, rgba(0,0,0,0.55));
  font-style: italic;
  cursor: default;
}

.chat-thread-row--empty:hover { background: transparent; }

/* ── Active thread pane ───────────────────────────────────────────── */

.chat-active {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--surface, #fff);
}

.chat-active__messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5) max(var(--sp-5), calc(50% - var(--chat-bubble-max, 720px) / 2 + var(--sp-5)));
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-height: 0;
}

/* ── Empty state ──────────────────────────────────────────────────── */

.chat-empty {
  margin: auto;
  text-align: center;
  width: 100%;
  max-width: var(--chat-empty-max, 640px);
  padding: var(--sp-6) var(--sp-5);
}

.chat-empty__title {
  font-size: var(--chat-empty-title-fs, 28px);
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0 0 var(--sp-3);
  color: var(--fg, rgba(0,0,0,0.9));
}

.chat-empty__sub {
  font-size: var(--fs-base);
  color: var(--muted, rgba(0,0,0,0.6));
  line-height: 1.5;
  margin: 0 0 var(--sp-5);
}

.chat-empty__starters {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

@media (max-width: 540px) {
  .chat-empty__starters { grid-template-columns: 1fr; }
}

.chat-starter-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-1);
  padding: var(--sp-3);
  background: transparent;
  border: 1px solid var(--border, rgba(0,0,0,0.10));
  border-radius: var(--r-lg);
  font-size: var(--fs-base);
  font-family: inherit;
  color: var(--fg, rgba(0,0,0,0.85));
  text-align: left;
  cursor: pointer;
  transition: background var(--motion-tooltip-fade, 80ms) ease,
              border-color var(--motion-tooltip-fade, 80ms) ease;
}

.chat-starter-card:hover {
  background: var(--hover, rgba(0,0,0,0.03));
  border-color: var(--accent, rgba(0,100,225,0.45));
}

.chat-starter-card__heading {
  font-weight: 500;
  color: var(--fg, rgba(0,0,0,0.9));
}

.chat-starter-card__hint {
  font-size: var(--fs-xs);
  color: var(--muted, rgba(0,0,0,0.55));
}

/* ── Bubbles ──────────────────────────────────────────────────────── */
/* Claude pattern: assistant has no bubble (just full-width text);
   user message is right-aligned with a soft accent background. */

.chat-bubble {
  display: flex;
  max-width: var(--chat-bubble-max, 720px);
  width: 100%;
  align-self: center;
}

.chat-bubble--user {
  justify-content: flex-end;
}

.chat-bubble--assistant {
  justify-content: flex-start;
}

.chat-bubble__body {
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--fg, rgba(0,0,0,0.9));
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* User bubble: pill with soft accent bg, max ~75% width. */
.chat-bubble--user .chat-bubble__body {
  background: var(--ui-sidebar-btn-active, rgba(0,0,0,0.06));
  border-radius: var(--r-lg);
  padding: var(--sp-2) var(--sp-3);
  max-width: 75%;
}

/* Assistant: no bubble — just text, full width of the message column. */
.chat-bubble--assistant .chat-bubble__body {
  background: transparent;
  padding: 0;
  width: 100%;
}

.chat-bubble--error .chat-bubble__body,
.chat-bubble.chat-bubble--error {
  background: var(--debit-bg, rgba(220,40,40,0.10));
  color: var(--debit-fg, rgba(180,30,30,0.95));
  align-self: stretch;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-lg);
}

.chat-bubble__tool-use {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
  font-size: var(--fs-sm);
  background: var(--code-bg, rgba(0,0,0,0.05));
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-md);
  margin: var(--sp-1) 0;
  display: inline-block;
  color: var(--muted, rgba(0,0,0,0.6));
}

/* ── Composer ─────────────────────────────────────────────────────── */
/* Single rounded card with the textarea on top and a controls row at the
   bottom. Send button is inset bottom-right; chip row sits bottom-left. */

.chat-composer {
  flex: 0 0 auto;
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  background: transparent;
  display: flex;
  justify-content: center;
}

.chat-composer__card {
  width: 100%;
  max-width: var(--chat-bubble-max, 720px);
  background: var(--surface, #fff);
  border: 1px solid var(--border, rgba(0,0,0,0.12));
  border-radius: var(--r-lg);
  box-shadow: var(--lf-shadow-card, 0 0 28px rgba(0,0,0,0.08));
  padding: var(--sp-2) var(--sp-3) var(--sp-2);
  transition: border-color var(--motion-tooltip-fade, 80ms) ease,
              box-shadow   var(--motion-tooltip-fade, 80ms) ease;
}

.chat-composer__card:focus-within {
  border-color: var(--accent, rgba(0,100,225,1));
}

.chat-composer__textarea {
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--fg, rgba(0,0,0,0.9));
  padding: var(--sp-2) 0 var(--sp-1);
  max-height: var(--chat-textarea-max, 240px);
  min-height: var(--chat-textarea-min, 56px);
}

.chat-composer__textarea::placeholder {
  color: var(--muted, rgba(0,0,0,0.42));
}

.chat-composer__row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}

.chat-composer__chips {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex: 1;
  min-width: 0;
}

.chat-composer__send {
  /* Standard sift-icon-btn — pinned at bottom-right of the card. */
  flex: 0 0 auto;
  margin-left: auto;
}

.chat-composer__send[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

/* ── Privacy chip + popover ───────────────────────────────────────── */

.chat-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  height: 22px;
  font-size: var(--fs-xs);
  color: var(--muted, rgba(0,0,0,0.55));
  background: transparent;
  border: 1px solid var(--border, rgba(0,0,0,0.12));
  border-radius: var(--r-pill);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background var(--motion-tooltip-fade, 80ms) ease,
              color var(--motion-tooltip-fade, 80ms) ease,
              border-color var(--motion-tooltip-fade, 80ms) ease;
}

.chat-chip:hover {
  background: var(--hover, rgba(0,0,0,0.04));
  color: var(--fg, rgba(0,0,0,0.85));
}

.chat-chip.is-active {
  background: var(--ui-sidebar-btn-active, rgba(0,100,225,0.10));
  color: var(--ui-sidebar-btn-active-fg, var(--accent));
  border-color: transparent;
}

.chat-chip > svg, .chat-chip > i {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
}

.chat-chip--estimate {
  margin-left: auto;
  cursor: default;
  border-color: transparent;
  font-variant-numeric: tabular-nums;
}

.chat-chip--estimate:hover {
  background: transparent;
  color: var(--muted, rgba(0,0,0,0.55));
}

.chat-chip--estimate:empty {
  display: none;
}

/* Popover: anchored to the privacy chip; absolute-positioned by JS. */
.chat-privacy-popover {
  position: fixed;
  z-index: 1000;
  background: var(--surface, #fff);
  border: 1px solid var(--border, rgba(0,0,0,0.12));
  border-radius: var(--r-md);
  box-shadow: var(--lf-shadow-card, 0 8px 24px rgba(0,0,0,0.12));
  padding: var(--sp-2);
  min-width: 240px;
  font-size: var(--fs-base);
  color: var(--fg, rgba(0,0,0,0.85));
}

.chat-privacy-popover__title {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, rgba(0,0,0,0.55));
  padding: var(--sp-1) var(--sp-2);
}

.chat-privacy-popover__row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  user-select: none;
}

.chat-privacy-popover__row:hover {
  background: var(--hover, rgba(0,0,0,0.04));
}

.chat-privacy-popover__row input[type="checkbox"] {
  margin-top: 2px;
  flex: 0 0 auto;
}

.chat-privacy-popover__row input[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.chat-privacy-popover__row input[disabled] ~ .chat-privacy-popover__rowtext {
  opacity: 0.5;
}

.chat-privacy-popover__rowtext {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-privacy-popover__rowtitle {
  font-size: var(--fs-base);
  color: var(--fg, rgba(0,0,0,0.9));
}

.chat-privacy-popover__rowsub {
  font-size: var(--fs-xs);
  color: var(--muted, rgba(0,0,0,0.55));
  line-height: 1.4;
}
