/* ==========================================================================
   AI Sessions — Terminal-grade chat with mission control aesthetics
   ========================================================================== */

/* ── Provider identity dots ── */
.ai-provider-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  display: inline-block;
  flex-shrink: 0;
}
.ai-provider-dot--anthropic { background: #d97706; box-shadow: 0 0 6px rgba(217, 119, 6, 0.4); }
.ai-provider-dot--openai    { background: #10a37f; box-shadow: 0 0 6px rgba(16, 163, 127, 0.4); }
.ai-provider-dot--gemini    { background: #4285f4; box-shadow: 0 0 6px rgba(66, 133, 244, 0.4); }

/* Provider badge variants */
.badge--anthropic { background: rgba(217, 119, 6, 0.15); color: #d97706; }
.badge--openai    { background: rgba(16, 163, 127, 0.15); color: #10a37f; }
.badge--gemini    { background: rgba(66, 133, 244, 0.15); color: #4285f4; }

[data-theme="dark"] .badge--anthropic { color: #fbbf24; background: rgba(251, 191, 36, 0.12); }
[data-theme="dark"] .badge--openai    { color: #34d399; background: rgba(52, 211, 153, 0.12); }
[data-theme="dark"] .badge--gemini    { color: #60a5fa; background: rgba(96, 165, 250, 0.12); }

/* ── Sessions Index ── */

.ai-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-4);
  text-align: center;
}

.ai-empty__icon {
  color: var(--text-muted);
  opacity: 0.4;
  margin-bottom: var(--space-4);
}

.ai-empty__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 var(--space-2);
}

.ai-empty__desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0 0 var(--space-6);
}

.ai-empty__desc code {
  font-family: var(--font-mono);
  background: var(--bg-surface-raised);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}

/* Session cards grid */
.ai-sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-3);
}

@media (max-width: 480px) {
  .ai-sessions-grid {
    grid-template-columns: 1fr;
  }
}

.ai-scard {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  animation: ai-card-in 300ms var(--ease-out) both;
}

@keyframes ai-card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-scard:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.ai-scard__link {
  display: block;
  padding: var(--space-4);
  text-decoration: none;
  color: inherit;
}

.ai-scard__top {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--text-xs);
}

.ai-scard__provider {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.ai-scard__separator {
  color: var(--border);
}

.ai-scard__model {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.ai-scard__time {
  margin-left: auto;
  color: var(--text-muted);
}

.ai-scard__preview {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-scard__bottom {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.ai-scard__stat--tools {
  color: var(--accent);
}

.ai-scard__id {
  margin-left: auto;
  opacity: 0.5;
}

.ai-scard__del {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: var(--text-lg);
  line-height: 1;
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}

.ai-scard__del:focus-visible {
  opacity: 1;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.ai-scard:hover .ai-scard__del {
  opacity: 0.6;
}

.ai-scard__del:hover {
  opacity: 1;
  color: var(--status-failed);
  background: var(--danger-bg);
}

/* ── New Session ── */

.ai-new-session {
  max-width: 560px;
}

.ai-new-form__label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

/* Provider picker cards */
.ai-provider-cards {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.ai-pcard {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-3);
  background: var(--bg-surface);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.ai-pcard__radio {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.ai-pcard__radio:checked + .ai-pcard__dot {
  width: 10px;
  height: 10px;
}

.ai-pcard:has(.ai-pcard__radio:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-sm);
}

.ai-pcard__name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.ai-pcard__count {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Model picker */
.ai-model-picker {
  margin-bottom: var(--space-5);
}

.ai-model-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.ai-mcard {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.ai-mcard__radio {
  accent-color: var(--accent);
}

.ai-mcard:has(.ai-mcard__radio:checked) {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.ai-mcard__name {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-primary);
}

/* Message input */
.ai-message-input {
  margin-bottom: var(--space-5);
}

.ai-new-form__textarea {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
}

.ai-new-form__textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.ai-new-form__actions {
  display: flex;
}

/* ── Chat Session View ── */

/* Session header (replaces page-header) */
.ai-session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}

.ai-session-header__left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.ai-session-header__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  color: var(--text-muted);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.ai-session-header__back:hover {
  color: var(--text-primary);
  background: var(--bg-surface-raised);
}

.ai-session-header__model {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
}

.ai-session-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.ai-session-header__id {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  opacity: 0.6;
}

/* Chat container */
.ai-chat {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 180px);
  min-height: 400px;
}

/* Empty chat state */
.ai-chat__empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: center;
  padding: var(--space-8);
}

/* Message timeline */
.ai-chat__timeline {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  scroll-behavior: smooth;
  /* Subtle scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Message bubbles */
.ai-msg {
  display: flex;
  gap: var(--space-2);
  animation: ai-msg-in 250ms var(--ease-out) both;
}

@keyframes ai-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-msg--user {
  justify-content: flex-end;
  padding-left: 15%;
}

.ai-msg--ai {
  padding-right: 10%;
}

.ai-msg__indicator {
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  background: var(--accent-subtle);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: var(--space-1);
}

.ai-msg__bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: var(--text-sm);
}

.ai-msg--user .ai-msg__bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.ai-msg--ai .ai-msg__bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: var(--radius-sm);
}

.ai-msg--error {
  padding-left: 36px;
}

.ai-msg__bubble--error {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: var(--text-xs);
}

.ai-msg__text {
  word-break: break-word;
}

.ai-msg__text p {
  margin: 0 0 var(--space-2);
}

.ai-msg__text p:last-child {
  margin-bottom: 0;
}

.ai-msg__time {
  font-size: 10px;
  opacity: 0.5;
  margin-top: var(--space-1);
  display: block;
}

.ai-msg--user .ai-msg__time {
  text-align: right;
}

.ai-msg__footer {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-2);
  font-size: 10px;
  color: var(--text-muted);
}

.ai-msg__cost {
  font-family: var(--font-mono);
}

.ai-msg__tokens {
  opacity: 0.6;
  margin-left: var(--space-1);
}

.ai-msg__total {
  opacity: 0.6;
  margin-left: var(--space-2);
  padding-left: var(--space-2);
  border-left: 1px solid var(--border-subtle);
}

/* Tool call indicators */
.ai-tool {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  margin-left: 36px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  animation: ai-msg-in 200ms var(--ease-out) both;
}

.ai-tool__icon {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  background: var(--success-bg);
  color: var(--success);
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-tool__icon--err {
  background: var(--danger-bg);
  color: var(--danger);
}

.ai-tool__name {
  font-weight: 600;
  color: var(--accent);
}

.ai-tool__arg {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.7;
}

/* Compose area */
.ai-chat__compose {
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-3) 0 0;
}

.ai-compose__config {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.ai-compose__provider,
.ai-compose__model {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-mono);
}

.ai-compose__model {
  flex: 1;
}

.ai-compose__provider:focus,
.ai-compose__model:focus {
  outline: none;
  border-color: var(--accent);
}

.ai-compose__row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}

.ai-compose__input {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  min-height: 40px;
  max-height: 160px;
  transition: border-color var(--transition-fast);
}

.ai-compose__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.ai-compose__send {
  height: 40px;
  padding: 0 var(--space-4);
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
}

.ai-compose__send:hover {
  background: var(--accent-hover);
}

.ai-compose__send:active {
  transform: scale(0.97);
}

/* ── Dark theme overrides ── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    .ai-msg--user .ai-msg__bubble {
      background: var(--accent);
    }
    .ai-provider-dot--anthropic { box-shadow: 0 0 8px rgba(251, 191, 36, 0.3); }
    .ai-provider-dot--openai    { box-shadow: 0 0 8px rgba(52, 211, 153, 0.3); }
    .ai-provider-dot--gemini    { box-shadow: 0 0 8px rgba(96, 165, 250, 0.3); }
  }
}

[data-theme="dark"] {
  .ai-msg--user .ai-msg__bubble {
    background: var(--accent);
  }
  .ai-provider-dot--anthropic { box-shadow: 0 0 8px rgba(251, 191, 36, 0.3); }
  .ai-provider-dot--openai    { box-shadow: 0 0 8px rgba(52, 211, 153, 0.3); }
  .ai-provider-dot--gemini    { box-shadow: 0 0 8px rgba(96, 165, 250, 0.3); }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .ai-scard,
  .ai-msg,
  .ai-tool {
    animation: none !important;
  }
  .ai-scard:hover {
    transform: none;
  }
  .ai-compose__send:active {
    transform: none;
  }
  .ai-chat__timeline {
    scroll-behavior: auto;
  }
}

/* ── Screen reader only ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
