/**
 * Documentoved — Chat Application Layer
 *
 * Specific layout, states and overrides for the streaming chat UI.
 * Consumes tokens + components from the Design System.
 *
 * This file replaces the bulk of the old monolithic stream_ui.css.
 */

/* =========================================================
   Shell & App Container
   ========================================================= */
body {
  background: var(--ds-color-bg-app);
  overflow-x: hidden;
}

.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;
  background: var(--ds-color-bg-app);
}

/* Sidebar */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  display: none;
  flex-direction: column;
  background: var(--ds-color-surface);
  border-right: 1px solid var(--ds-color-border);
  padding: var(--ds-space-6);
  gap: var(--ds-space-6);
  overflow-y: auto;
}

.sidebar__history {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar__projects {
  padding: var(--ds-space-3);
  border-top: 1px solid var(--ds-color-border);
  flex-shrink: 0;
}

.sidebar-projects-link {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  padding: var(--ds-space-2) var(--ds-space-3);
  border-radius: var(--ds-radius-md);
  color: var(--ds-color-text-secondary);
  text-decoration: none;
  font-size: var(--ds-font-size-sm);
  transition: background var(--ds-transition-fast), color var(--ds-transition-fast);
}

.sidebar-projects-link:hover {
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-primary);
}

.sidebar-search {
  position: relative;
  margin-bottom: var(--ds-space-3);
  flex-shrink: 0;
}

.sidebar-search__icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--ds-color-text-muted);
  pointer-events: none;
}

.sidebar-search__input {
  width: 100%;
  padding: 8px 10px 8px 34px;
  border-radius: var(--ds-radius-pill);
  border: none;
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-primary);
  font-size: var(--ds-font-size-sm);
  outline: none;
  transition: background var(--ds-transition-fast), box-shadow var(--ds-transition-fast);
}

.sidebar-search__input:focus {
  background: var(--ds-color-surface);
  box-shadow: var(--ds-focus-ring);
}

.sidebar-search__input::placeholder {
  color: var(--ds-color-text-muted);
}

.session-empty {
  padding: var(--ds-space-4) var(--ds-space-3);
  font-size: var(--ds-font-size-sm);
  color: var(--ds-color-text-muted);
  text-align: center;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 4px;
  min-height: 0;
}

.chat-item {
  display: block;
  padding: 10px 12px;
  border: none;
  border-radius: var(--ds-radius-md);
  color: var(--ds-color-text-secondary);
  text-decoration: none;
  transition: background var(--ds-transition-fast), color var(--ds-transition-fast);
}

.chat-item:hover {
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-primary);
}

.chat-item--active {
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-text-primary);
}

.chat-item__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-medium);
}

.chat-item__meta {
  margin-top: 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-2);
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-muted);
}

.chat-item__preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-item__time {
  flex-shrink: 0;
}

.chat-list__group-label {
  padding: var(--ds-space-4) var(--ds-space-3) var(--ds-space-1);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-medium);
  color: var(--ds-color-text-muted);
}

@media (min-width: 768px) {
  .sidebar { display: flex; }
}

@media (max-width: 767px) {
  .sidebar {
    display: flex;
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    z-index: 100;
    transition: left var(--ds-transition-base);
    box-shadow: var(--ds-shadow-lg);
  }

  .shell.sidebar-open .sidebar {
    left: 0;
  }
}

.logo-area {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  font-size: var(--ds-font-size-lg);
  font-weight: var(--ds-font-weight-semibold);
  letter-spacing: var(--ds-letter-spacing-tight);
  color: var(--ds-color-text-primary);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: -4px;
}

/* Main content */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.main-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* Messages area */
.messages-wrap {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 0 var(--ds-space-8);
  scroll-behavior: smooth;
}

@media (max-width: 767px) {
  .messages-wrap { padding: 0 var(--ds-space-4); }
}

/* Desktop chat title */
.chat-header {
  display: none;
  flex-shrink: 0;
  padding: var(--ds-space-4) var(--ds-space-8) 0;
}

.chat-header__title {
  margin: 0;
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-medium);
  color: var(--ds-color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 768px) {
  body:not(.is-empty-chat) .chat-header {
    display: block;
  }
}

/* Intro */
.intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  padding: var(--ds-space-10) 0 var(--ds-space-6);
  text-align: center;
  gap: var(--ds-space-6);
}

body.is-empty-chat .intro {
  flex: 1;
  min-height: 0;
}

.intro__inner {
  width: 100%;
  min-width: 0;
  max-width: 800px;
  text-align: center;
}

.intro__title {
  margin: 0 0 var(--ds-space-6);
  font-size: 2rem;
  font-weight: var(--ds-font-weight-medium);
  letter-spacing: -0.02em;
  color: var(--ds-color-text-primary);
  overflow-wrap: break-word;
  text-wrap: balance;
}

@media (min-width: 768px) {
  .intro__title { font-size: 2.25rem; }
}

.intro__subtitle {
  margin: -16px 0 var(--ds-space-6);
  font-size: var(--ds-font-size-md);
  color: var(--ds-color-text-muted);
}

.composer-slot {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 var(--ds-space-2);
}

body:not(.is-empty-chat) .composer-slot {
  display: none;
}

.intro-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto var(--ds-space-5);
  border: none;
  border-radius: 50%;
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.intro-mark .material-symbols-rounded {
  font-size: 26px;
}

@media (max-width: 520px) {
  .intro {
    padding-top: var(--ds-space-6);
  }

  .intro__inner,
  .composer-slot {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    padding-left: 0;
    padding-right: 0;
  }

  .intro__title {
    font-size: 1.75rem;
    line-height: 1.18;
  }

  .input-wrapper {
    padding: var(--ds-space-3) var(--ds-space-4);
  }
}
.message-list {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-6);
  width: 100%;
  min-height: 100%;
  padding-bottom: var(--ds-space-4);
}

.msg-row {
  display: flex;
  align-items: flex-start;
  width: 100%;
}

.msg-row--user {
  justify-content: flex-end;
}

.msg-row--assistant { justify-content: flex-start; }

.msg-content {
  max-width: min(82%, 720px);
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-1);
}

.msg-row--assistant .msg-content {
  width: 100%;
  max-width: 760px;
}

.msg-row--user .msg-content {
  align-items: flex-end;
}

.msg-bubble {
  max-width: 100%;
  padding: var(--ds-space-1) 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--ds-color-text-primary);
  overflow-wrap: anywhere;
}

.msg-row--user .msg-bubble {
  padding: var(--ds-space-3) var(--ds-space-4);
  border-radius: var(--ds-radius-bubble);
  background: var(--ds-color-accent);
  color: #fff;
  box-shadow: none;
}

.msg-row--assistant .msg-bubble {
  padding: var(--ds-space-1) 0;
}

.msg-row--assistant .msg-text.prose {
  color: var(--ds-color-text-secondary);
}

.msg-row--user .msg-text code {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.msg-text {
  font-size: var(--ds-font-size-md);
  line-height: var(--ds-line-height-relaxed);
}

.msg-text code,
.msg-reasoning code {
  padding: 0.1em 0.32em;
  border-radius: var(--ds-radius-xs);
  background: var(--ds-color-accent-soft);
  color: var(--ds-color-accent);
  font-family: var(--ds-font-mono);
  font-size: 0.9em;
}

.msg-meta {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ds-color-text-muted);
  font-size: var(--ds-font-size-xs);
}

.msg-row--user .msg-meta {
  justify-content: flex-end;
}

.msg-feedback-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--ds-radius-xs);
  background: transparent;
  color: var(--ds-color-text-muted);
  cursor: pointer;
  transition: background var(--ds-transition-fast), color var(--ds-transition-fast);
}

.msg-feedback-btn:hover {
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-text-primary);
}

.msg-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 6px;
  opacity: 0;
  transition: opacity var(--ds-transition-fast);
}

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

@media (hover: none) {
  .msg-actions {
    opacity: 1;
  }
}

.msg-row--streaming .msg-bubble::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.15em;
  margin-left: 3px;
  vertical-align: -0.18em;
  border-radius: 2px;
  background: var(--ds-color-accent);
  animation: stream-caret 0.9s steps(2, start) infinite;
}

@keyframes stream-caret {
  50% { opacity: 0; }
}

.msg-bubble--user.msg-bubble--file-card {
  background: var(--ds-color-surface);
  color: var(--ds-color-text-primary);
  border: 1px solid var(--ds-color-border-strong);
  padding: 10px 14px;
}

.file-message-card {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
}

.file-message-card .material-symbols-rounded {
  font-size: 26px;
  color: var(--ds-color-accent);
  background: var(--ds-color-primary-soft);
  padding: 7px;
  border-radius: var(--ds-radius-sm);
}

.msg-reasoning {
  margin-bottom: var(--ds-space-3);
  border: none;
  border-radius: var(--ds-radius-md);
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-muted);
  font-size: var(--ds-font-size-sm);
}

.msg-reasoning summary {
  padding: 7px 10px;
  cursor: pointer;
  font-weight: var(--ds-font-weight-medium);
}

.msg-reasoning details > div {
  padding: 0 10px 10px;
}

.msg-sources {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-2);
  margin-top: var(--ds-space-3);
  padding-top: var(--ds-space-3);
  border-top: none;
}

.msg-sources a {
  max-width: 100%;
  padding: 5px 12px;
  border-radius: var(--ds-radius-pill);
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-accent);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-medium);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: none;
}

/* Message actions row */
.message-actions {
  margin-top: var(--ds-space-1);
  display: flex;
  gap: 2px;
}

.message-action {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ds-color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--ds-transition-fast), color var(--ds-transition-fast);
}

.message-action:hover {
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-text-primary);
}

.message-action.is-active,
.message-action.is-copied {
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-accent);
}

/* Composer area at bottom (active chat) */
.chat-footer {
  flex-shrink: 0;
  padding: 0 var(--ds-space-4) var(--ds-space-5);
  overflow: visible;
}

@media (min-width: 768px) {
  .chat-footer { padding: 0 var(--ds-space-8) var(--ds-space-6); }
}

.composer-form {
  max-width: 800px;
  margin: 0 auto;
}

body.is-empty-chat .chat-footer {
  display: none;
}

body:not(.is-empty-chat) .messages-wrap {
  padding-top: var(--ds-space-4);
  padding-bottom: var(--ds-space-4);
}

/* Attachment chips, doc mode, upload status — keep inside input-wrapper */
.composer__attachments,
#docModeBar,
#uploadStatusBar {
  padding: 0 var(--ds-space-1) var(--ds-space-2);
}

.doc-mode,
.upload-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-3);
  padding: var(--ds-space-2) var(--ds-space-2) var(--ds-space-3);
  margin: 0 2px 6px;
  border-bottom: 1px solid var(--ds-color-line);
  font-size: var(--ds-font-size-xs);
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  max-width: 100%;
  padding: 6px 12px;
  font-size: var(--ds-font-size-xs);
  border-radius: var(--ds-radius-pill);
  background: var(--ds-color-bg-subtle);
  border: none;
  color: var(--ds-color-text-secondary);
}

/* Suggested prompts container */
.suggested-prompts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--ds-space-3);
  margin-top: var(--ds-space-6);
  max-width: 620px;
  margin-left: auto;
  margin-right: auto;
}

.suggested-prompts--composer {
  margin-top: 0;
  margin-bottom: var(--ds-space-3);
  justify-content: flex-start;
  max-width: 100%;
  padding: 0 2px;
}

/* Sources details (inside assistant message) */
.sources-details {
  margin-top: var(--ds-space-4);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  background: var(--ds-color-surface);
  overflow: hidden;
}

.sources-details summary {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  padding: 9px 12px;
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-color-text-secondary);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.sources-details[open] summary {
  border-bottom: 1px solid var(--ds-color-line);
  background: var(--ds-color-bg-panel);
}

/* Mobile header */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--ds-space-3);
  background: var(--ds-color-surface);
  border-bottom: 1px solid var(--ds-color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

@media (max-width: 767px) {
  .mobile-header { display: flex; }
}

.mobile-header__title {
  font-size: var(--ds-font-size-md);
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-color-text-primary);
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.22);
  z-index: 90;
  opacity: 0;
  transition: opacity var(--ds-transition-base);
}

.shell.sidebar-open .sidebar-overlay {
  display: block;
  opacity: 1;
}

/* Audio panel (right sidebar when active) */
.audio-panel {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-4);
  padding: var(--ds-space-4);
  background: var(--ds-color-surface);
  border-left: 1px solid var(--ds-color-border);
  overflow-y: auto;
  overscroll-behavior: contain;
}

@media (max-width: 1100px) {
  .audio-panel {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 30;
    box-shadow: var(--ds-shadow-lg);
    width: min(360px, 100%);
  }
}

.audio-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--ds-space-3);
}

.audio-panel__eyebrow {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--ds-letter-spacing-wide);
}

.audio-player {
  width: 100%;
  height: 36px;
}

.audio-status {
  padding: 8px 10px;
  border-radius: var(--ds-radius-sm);
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-accent);
  font-size: var(--ds-font-size-xs);
}

.audio-pipeline {
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  background: var(--ds-color-surface);
}

.audio-pipeline summary {
  display: flex;
  justify-content: space-between;
  gap: var(--ds-space-2);
  padding: var(--ds-space-3);
  color: var(--ds-color-text-primary);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  cursor: pointer;
  list-style: none;
}

.audio-pipeline__step {
  position: relative;
  display: flex;
  gap: var(--ds-space-2);
  padding: 6px 0;
  color: var(--ds-color-text-muted);
  font-size: var(--ds-font-size-xs);
}

.audio-pipeline__step:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 24px;
  bottom: -4px;
  width: 1px;
  background: var(--ds-color-line);
}

.audio-section {
  border-top: 1px solid var(--ds-color-line);
  padding-top: var(--ds-space-3);
}

.audio-section h3 {
  margin: 0 0 var(--ds-space-2);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-color-text-secondary);
}

.source-hint {
  margin: var(--ds-space-2) 0 0;
  padding: 0 2px;
  text-align: left;
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-warning);
}

/* Disclaimer */
.disclaimer {
  margin-top: var(--ds-space-3);
  text-align: center;
  font-size: 10px;
  line-height: 1.4;
  color: var(--ds-color-text-muted);
  opacity: 0.45;
}

/* Feedback reasons */
.feedback-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-2);
}

.feedback-reason {
  cursor: pointer;
  border-radius: var(--ds-radius-sm);
  border: 1px solid var(--ds-color-border);
  padding: 7px 11px;
  font-size: var(--ds-font-size-sm);
  color: var(--ds-color-text-secondary);
  transition: background var(--ds-transition-fast);
}

.feedback-reason:hover {
  background: var(--ds-color-primary-soft);
}

.feedback-reason input:checked + span {
  color: var(--ds-color-accent);
  font-weight: var(--ds-font-weight-semibold);
}

/* Toast container positioning */
.toast-container {
  position: fixed;
  bottom: var(--ds-space-6);
  right: var(--ds-space-6);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-2);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
}

/* Small polish: hide old composer styles that we overrode */
.composer {
  /* Old composer is now inside .input-wrapper */
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

/* Doc mode highlight on the input wrapper */
.input-wrapper--doc-mode,
.composer--doc-mode {
  border-color: var(--ds-color-accent);
  box-shadow: var(--ds-focus-ring);
}
