/**
 * Documentoved Design System
 * Layer: Components
 *
 * Reusable, documented building blocks.
 * All components prefer CSS variables from design-tokens.css.
 *
 * Naming:
 * - .surface        — primitive solid surface
 * - .surface-card   — elevated container
 * - .feature-card   — compact action card
 * - .btn, .icon-btn — buttons
 * - .chip, .prompt-chip
 * - .input, .composer (higher level)
 *
 * Usage example:
 *   <div class="surface-card">...</div>
 *   <button class="btn btn--primary">Отправить</button>
 */

/* =========================================================
   Surface Primitives
   ========================================================= */
.surface {
  background: var(--ds-color-surface);
  border: 1px solid var(--ds-color-border);
  box-shadow: var(--ds-shadow-md);
  transition: background var(--ds-transition-base),
              border-color var(--ds-transition-base),
              box-shadow var(--ds-transition-base);
}

.surface-strong {
  background: var(--ds-color-surface-strong);
  border-color: var(--ds-color-border-strong);
}

.surface-subtle {
  background: var(--ds-color-bg-panel);
  border-color: var(--ds-color-border);
}

/* Hover lift for interactive surfaces */
.surface-interactive:hover {
  background: var(--ds-color-bg-panel);
  border-color: var(--ds-color-border-strong);
  transform: translateY(-1px);
}

.surface-interactive:active {
  transform: translateY(0);
}

/* =========================================================
   Cards
   ========================================================= */
.surface-card {
  background: var(--ds-color-surface);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-4);
}

.feature-card {
  position: relative;
  overflow: hidden;
  background: var(--ds-color-surface);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-5);
  cursor: pointer;
  transition: background var(--ds-transition-base), border-color var(--ds-transition-base);
}

.feature-card:hover {
  background: var(--ds-color-bg-panel);
  border-color: var(--ds-color-border-strong);
}

.feature-card .card-badge {
  position: absolute;
  top: var(--ds-space-3);
  right: var(--ds-space-3);
  background: var(--ds-color-bg-panel);
  border: 1px solid var(--ds-color-border);
  padding: 3px 9px;
  border-radius: var(--ds-radius-full);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-medium);
  letter-spacing: var(--ds-letter-spacing-wide);
  color: var(--ds-color-text-muted);
  text-transform: uppercase;
}

.feature-card .card-icon {
  width: 36px;
  height: 36px;
  background: var(--ds-color-bg-panel);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--ds-space-4);
  color: var(--ds-color-text-primary);
}

.feature-card h3 {
  font-size: var(--ds-font-size-md);
  font-weight: var(--ds-font-weight-semibold);
  margin-bottom: var(--ds-space-2);
  color: var(--ds-color-text-primary);
}

.feature-card p {
  font-size: var(--ds-font-size-sm);
  color: var(--ds-color-text-muted);
  line-height: var(--ds-line-height-normal);
  margin: 0;
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  padding: 10px 18px;
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-semibold);
  border-radius: var(--ds-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--ds-transition-fast);
  white-space: nowrap;
}

.btn--primary {
  background: var(--ds-color-accent);
  color: var(--ds-color-text-on-accent);
  box-shadow: var(--ds-shadow-sm);
}

.btn--primary:hover:not(:disabled) {
  background: var(--ds-color-accent-dark);
  box-shadow: var(--ds-shadow-sm);
}

.btn--primary:active:not(:disabled) {
  transform: scale(0.985);
}

.btn--ghost {
  background: transparent;
  color: var(--ds-color-text-secondary);
  border-color: var(--ds-color-border);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--ds-color-bg-panel);
  color: var(--ds-color-text-primary);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Icon buttons (square, used a lot in composer/sidebar) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ds-color-text-muted);
  cursor: pointer;
  transition: background-color var(--ds-transition-fast),
              color var(--ds-transition-fast),
              transform var(--ds-transition-fast);
}

.icon-btn:hover:not(:disabled) {
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-text-primary);
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.icon-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.icon-btn--sm {
  width: 32px;
  height: 32px;
}

.icon-btn--primary {
  background: var(--ds-color-accent);
  color: #fff;
}

.icon-btn--primary:hover:not(:disabled) {
  background: var(--ds-color-accent-dark);
}

/* New chat button (prominent in sidebar) */
.new-chat-btn {
  width: 100%;
  background: var(--ds-color-accent);
  border: none;
  color: var(--ds-color-text-on-accent);
  padding: var(--ds-space-3) var(--ds-space-4);
  border-radius: var(--ds-radius-pill);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-semibold);
  transition: background var(--ds-transition-base);
  box-shadow: var(--ds-shadow-sm);
}

.new-chat-btn:hover {
  background: var(--ds-color-accent-dark);
}

/* =========================================================
   Chips & Pills (prompts, quick actions)
   ========================================================= */
.chip,
.prompt-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  padding: 8px 14px;
  background: var(--ds-color-bg-panel);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  color: var(--ds-color-text-secondary);
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-medium);
  cursor: pointer;
  transition: background var(--ds-transition-fast), border-color var(--ds-transition-fast), color var(--ds-transition-fast);
  white-space: nowrap;
}

.prompt-chip:hover {
  background: var(--ds-color-primary-soft);
  border-color: var(--ds-color-accent-border);
  color: var(--ds-color-text-primary);
}

.prompt-chip:active {
  transform: translateY(0);
}

.quick-action-pill {
  background: var(--ds-color-surface);
  border: 1px solid var(--ds-color-border);
  padding: 8px 16px;
  border-radius: var(--ds-radius-md);
  font-size: var(--ds-font-size-sm);
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  cursor: pointer;
  transition: background var(--ds-transition-base), border-color var(--ds-transition-base), color var(--ds-transition-base);
  color: var(--ds-color-text-primary);
}

.quick-action-pill:hover {
  background: var(--ds-color-primary-soft);
  border-color: var(--ds-color-accent-border);
  color: var(--ds-color-accent-dark);
}

/* =========================================================
   Form Controls & Input
   ========================================================= */
.input,
.composer__input,
.input-field {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ds-color-text-primary);
  font-size: 1rem;
  resize: none;
  padding-left: 0;
  min-height: 24px;
  max-height: 160px;
  line-height: 1.5;
}

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

/* Composer */
.input-wrapper {
  width: 100%;
  max-width: 800px;
  background: var(--ds-color-surface);
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-radius: var(--ds-radius-composer);
  padding: var(--ds-space-4) var(--ds-space-5);
  position: relative;
  box-shadow: var(--ds-shadow-composer);
  transition: border-color var(--ds-transition-base), box-shadow var(--ds-transition-base);
  overflow: visible;
}

.input-wrapper:focus-within {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: var(--ds-focus-ring), var(--ds-shadow-composer);
}

.input-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--ds-space-3);
  gap: var(--ds-space-3);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  min-width: 0;
}

.toolbar-left {
  flex: 1;
  flex-wrap: wrap;
}

.tool-btn {
  background: transparent;
  border: none;
  color: var(--ds-color-text-muted);
  font-size: var(--ds-font-size-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: color var(--ds-transition-fast), background var(--ds-transition-fast);
  padding: 0;
  white-space: nowrap;
}

.tool-btn--icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
}

.tool-btn--icon:hover:not(:disabled) {
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-primary);
}

.tool-btn:hover:not(:disabled) {
  color: var(--ds-color-text-primary);
}

.tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: none;
  border-radius: var(--ds-radius-pill);
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-muted);
  cursor: pointer;
  font: inherit;
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-medium);
  transition: background var(--ds-transition-fast), color var(--ds-transition-fast), box-shadow var(--ds-transition-fast);
}

.mode-toggle .material-symbols-rounded {
  font-size: 16px;
}

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

.mode-toggle.is-active {
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-accent);
  box-shadow: var(--ds-focus-ring);
}

.mode-toggle.is-active .material-symbols-rounded {
  color: var(--ds-color-accent);
}

/* Picker (custom dropdown) */
.picker {
  position: relative;
  display: inline-flex;
  min-width: 0;
}

.picker__trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 28px 0 10px;
  border: none;
  border-radius: var(--ds-radius-pill);
  background: var(--ds-color-bg-subtle);
  color: var(--ds-color-text-secondary);
  cursor: pointer;
  font: inherit;
  transition: background var(--ds-transition-fast), color var(--ds-transition-fast), box-shadow var(--ds-transition-fast);
  max-width: 220px;
}

.picker__trigger:hover:not(:disabled) {
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-text-primary);
}

.picker__trigger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.picker.is-open .picker__trigger {
  background: var(--ds-color-surface);
  color: var(--ds-color-text-primary);
  box-shadow: var(--ds-focus-ring);
}

.picker__icon {
  font-size: 16px;
  color: var(--ds-color-text-muted);
  flex-shrink: 0;
}

.picker.is-open .picker__icon {
  color: var(--ds-color-accent);
}

.picker__label {
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.picker__chevron {
  position: absolute;
  right: 6px;
  font-size: 18px;
  color: var(--ds-color-text-muted);
  transition: transform var(--ds-transition-fast);
}

.picker.is-open .picker__chevron {
  transform: rotate(180deg);
  color: var(--ds-color-accent);
}

.picker__menu {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 40;
  min-width: 240px;
  max-width: min(300px, calc(100vw - 32px));
  padding: var(--ds-space-2);
  border-radius: var(--ds-radius-lg);
  background: var(--ds-color-surface);
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow: var(--ds-shadow-lg);
  display: none;
  flex-direction: column;
  gap: 2px;
}

.picker.is-open .picker__menu {
  display: flex;
  max-height: 280px;
  overflow-y: auto;
}

.picker__option {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--ds-radius-md);
  background: transparent;
  color: var(--ds-color-text-primary);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: background var(--ds-transition-fast);
}

.picker__option:hover {
  background: var(--ds-color-bg-subtle);
}

.picker__option.is-selected {
  background: var(--ds-color-primary-soft);
}

.picker__option-icon {
  font-size: 18px;
  color: var(--ds-color-text-muted);
  flex-shrink: 0;
}

.picker__option.is-selected .picker__option-icon {
  color: var(--ds-color-accent);
}

.picker__option-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.picker__option-label {
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-medium);
  line-height: 1.3;
}

.picker__option-hint {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-muted);
  line-height: 1.3;
}

.picker__option-check {
  font-size: 16px;
  color: var(--ds-color-accent);
  opacity: 0;
  flex-shrink: 0;
}

.picker__option.is-selected .picker__option-check {
  opacity: 1;
}

.picker__empty {
  padding: 10px 12px;
  font-size: var(--ds-font-size-sm);
  color: var(--ds-color-text-muted);
  text-align: center;
}

.picker__group-label {
  padding: 8px 12px 4px;
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.composer-hint {
  display: block;
  width: 100%;
  max-width: 800px;
  margin: var(--ds-space-4) auto 0;
  padding: 0 var(--ds-space-2);
  border: none;
  background: transparent;
  color: var(--ds-color-text-muted);
  font-size: var(--ds-font-size-sm);
  text-align: center;
  cursor: pointer;
  transition: color var(--ds-transition-fast);
}

.composer-hint:hover {
  color: var(--ds-color-accent);
}

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

.send-btn {
  background: var(--ds-color-accent);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--ds-transition-fast), transform var(--ds-transition-fast);
  color: white;
  flex-shrink: 0;
}

.send-btn .material-symbols-rounded {
  font-size: 18px;
}

.send-btn:hover:not(:disabled) {
  background: var(--ds-color-accent-dark);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Legacy source-select (if used elsewhere) */
.source-select {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-secondary);
}

/* =========================================================
   Sidebar & Menu Items
   ========================================================= */
.sidebar-label {
  padding: 0 var(--ds-space-3) var(--ds-space-2);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--ds-letter-spacing-wide);
  color: var(--ds-color-text-muted);
}

.session-item-container {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--ds-radius-sm);
  border: 1px solid transparent;
  transition: background-color var(--ds-transition-fast), border-color var(--ds-transition-fast);
}

.session-item-container:hover {
  background: var(--ds-color-bg-panel);
}

.session-item-container.is-active {
  background: var(--ds-color-primary-soft);
  border-color: var(--ds-color-accent-border);
}

.session-item {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ds-color-text-secondary);
  cursor: pointer;
  padding: var(--ds-space-2) var(--ds-space-3);
  font-size: var(--ds-font-size-sm);
  transition: color var(--ds-transition-fast);
}

.session-item-container.is-active .session-item {
  color: var(--ds-color-text-primary);
}

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

.session-item__preview {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.session-item__delete-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--ds-color-text-muted);
  cursor: pointer;
  border-radius: var(--ds-radius-xs);
  margin-right: var(--ds-space-2);
}

.session-item-container:hover .session-item__delete-btn {
  display: flex;
}

.session-item__delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--ds-color-error);
}

/* Menu items in sidebar (future sections) */
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  padding: 9px 12px;
  border-radius: var(--ds-radius-sm);
  color: var(--ds-color-text-muted);
  cursor: pointer;
  font-size: var(--ds-font-size-sm);
  transition: all var(--ds-transition-fast);
}

.menu-item:hover,
.menu-item.active {
  background: var(--ds-color-bg-panel);
  color: var(--ds-color-text-primary);
}

/* =========================================================
   Modal
   ========================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-4);
  background: rgba(15, 23, 42, 0.28);
}

.modal-backdrop.is-open {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 520px;
  border-radius: var(--ds-radius-md);
  background: var(--ds-color-surface);
  border: 1px solid var(--ds-color-border-strong);
  box-shadow: var(--ds-shadow-lg);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ds-space-4) var(--ds-space-5);
  border-bottom: 1px solid var(--ds-color-line);
}

.modal__title {
  margin: 0;
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-color-text-primary);
}

.modal__body {
  padding: var(--ds-space-5);
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-4);
}

.modal__textarea {
  width: 100%;
  border-radius: var(--ds-radius-md);
  border: 1px solid var(--ds-color-border);
  background: var(--ds-color-surface);
  padding: var(--ds-space-3);
  font-size: var(--ds-font-size-md);
  color: var(--ds-color-text-primary);
  outline: none;
  resize: vertical;
  min-height: 90px;
}

.modal__textarea:focus {
  border-color: var(--ds-color-accent);
}

.modal__hint {
  border-radius: var(--ds-radius-sm);
  background: var(--ds-color-bg-panel);
  padding: var(--ds-space-3);
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-muted);
  border: 1px solid var(--ds-color-line);
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--ds-space-3);
}

/* =========================================================
   Toast (notification)
   ========================================================= */
.toast {
  position: fixed;
  right: var(--ds-space-6);
  bottom: var(--ds-space-6);
  z-index: 1000;
  min-width: 260px;
  max-width: 380px;
  background: var(--ds-color-surface);
  color: var(--ds-color-text-primary);
  border: 1px solid var(--ds-color-border);
  border-left: 4px solid var(--ds-color-accent);
  padding: var(--ds-space-3) var(--ds-space-4);
  border-radius: var(--ds-radius-md);
  box-shadow: var(--ds-shadow-md);
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-medium);
  animation: toast-in var(--ds-transition-base) forwards;
  cursor: pointer;
  word-break: break-word;
}

.toast--success { border-left-color: var(--ds-color-success); }
.toast--error   { border-left-color: var(--ds-color-error); }
.toast--warn    { border-left-color: var(--ds-color-warning); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* =========================================================
   Misc (citation, reasoning, status)
   ========================================================= */
.citation-badge {
  display: inline-flex;
  align-items: center;
  border-radius: var(--ds-radius-sm);
  border: 1px solid var(--ds-color-border-strong);
  background: var(--ds-color-accent-soft);
  padding: 1px 7px;
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-color-accent);
  text-decoration: none;
  vertical-align: baseline;
}

.citation-badge:hover {
  background: var(--ds-color-primary-soft);
}

.reasoning-panel {
  margin-bottom: var(--ds-space-3);
  font-size: var(--ds-font-size-sm);
  color: var(--ds-color-text-muted);
}

.reasoning-panel summary {
  cursor: pointer;
  user-select: none;
}

.msg-status {
  margin-top: var(--ds-space-2);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--ds-letter-spacing-wide);
  color: var(--ds-color-accent);
}

.msg-error {
  margin-top: var(--ds-space-2);
  font-size: var(--ds-font-size-sm);
  color: var(--ds-color-error);
}
