/* AI View & Insights */
.ai-view {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 1000px;
  margin: 0 auto;
}

.ai-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

/* Pusta karta raportu: zwarta, żeby czat był widoczny bez przewijania */
.ai-analysis-empty {
  padding: 1.25rem 1rem 0.75rem;
}

.ai-analysis-empty-icon {
  font-size: 2.25rem;
  margin-bottom: 0.25rem;
}

.ai-analysis-empty p {
  max-width: 440px;
  margin-bottom: 1rem;
}

@media (min-width: 1100px) {
  .ai-view {
    max-width: 1200px;
  }

  .ai-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    align-items: start;
  }

  /* Czat przyklejony pod nawigacją — przy długim raporcie zostaje w zasięgu */
  .ai-chat-card {
    position: sticky;
    top: 5.5rem;
  }

  .ai-chat-messages {
    max-height: calc(100vh - 22rem);
    min-height: 320px;
  }
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.ai-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.ai-badge .pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-primary);
  animation: pulseDot 1.5s infinite;
}

@keyframes pulseDot {
  0% { transform: scale(0.95); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.6; }
}

/* Analysis Card */
.ai-analysis-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.ai-card-glow {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6, #22c55e);
}

.ai-analysis-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.ai-analysis-header h2 {
  font-size: 1.25rem;
  margin: 0;
}

.ai-analysis-timestamp {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ai-analysis-content {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--text-primary);
}

.ai-analysis-content h3 {
  font-size: 1.05rem;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  color: #93c5fd;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-analysis-content h3:first-child {
  margin-top: 0;
}

.ai-analysis-content p {
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
}

.ai-analysis-content ul, .ai-analysis-content ol {
  margin-left: 1.25rem;
  margin-bottom: 1rem;
}

.ai-analysis-content li {
  margin-bottom: 0.35rem;
  color: var(--text-secondary);
}

.ai-analysis-content strong {
  color: var(--text-primary);
}

/* Chat Section */
.ai-chat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ai-chat-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-chat-header h2 {
  font-size: 1.15rem;
  margin: 0;
}

/* Quick prompt chips */
.ai-chips-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  overflow-x: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(15, 17, 23, 0.3);
  scrollbar-width: none;
}

.ai-chips-row::-webkit-scrollbar {
  display: none;
}

.ai-chip {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.ai-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

/* Chat history */
.ai-chat-messages {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 420px;
  min-height: 250px;
  overflow-y: auto;
}

.ai-msg {
  display: flex;
  gap: 0.75rem;
  max-width: 85%;
}

.ai-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

.ai-msg-user .ai-msg-avatar {
  background: var(--accent-primary);
  color: white;
}

.ai-msg-bubble {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.ai-msg-model .ai-msg-bubble {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-top-left-radius: 2px;
  border: 1px solid var(--border);
}

.ai-msg-retry {
  margin-top: 0.6rem;
  min-height: 44px;
}

.ai-msg-user .ai-msg-bubble {
  background: var(--accent-primary);
  color: #ffffff;
  border-top-right-radius: 2px;
}

.ai-msg-bubble .md-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ai-msg-bubble .md-body p {
  margin: 0;
  line-height: 1.55;
}

.ai-msg-bubble .md-body h2,
.ai-msg-bubble .md-body h3,
.ai-msg-bubble .md-body h4 {
  margin: 0.5rem 0 0.2rem 0;
  color: #93c5fd;
  font-weight: 600;
}

.ai-msg-bubble .md-body h4 {
  font-size: 0.95rem;
}

.ai-msg-bubble .md-body ul,
.ai-msg-bubble .md-body ol {
  margin: 0.2rem 0 0.2rem 1.25rem;
  padding: 0;
}

.ai-msg-bubble .md-body li {
  margin-bottom: 0.25rem;
  line-height: 1.5;
}

.ai-msg-bubble .md-body .md-spacer {
  height: 0.35rem;
}

.ai-msg-bubble .md-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.ai-msg-user .ai-msg-bubble .md-body strong {
  color: #ffffff;
}

.ai-msg-bubble .md-body code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

/* Chat input bar */
.ai-chat-input-bar {
  display: flex;
  gap: clamp(0.4rem, 2vw, 0.75rem);
  padding: 1rem clamp(0.5rem, 3vw, 1.25rem);
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

/* Przycisk „Wyślij" i ikona aparatu nie mogą się kurczyć — to one mają
   stałą szerokość, a pole tekstowe oddaje im miejsce. */
.ai-chat-input-bar > .btn,
.ai-chat-input-bar > .ai-attach-btn {
  flex-shrink: 0;
}

.ai-chat-input {
  flex: 1;
  /* Bez tego `<input>` nie schodzi poniżej własnej szerokości minimalnej
     (domyślne `size`), bo element flex ma `min-width: auto`. Na ekranie
     360 px wypychało to przycisk „Wyślij" o 44 px poza kadr — a że
     `overflow-x: hidden` obcina po cichu, przycisk był częściowo
     niewidoczny i nie dało się go w całości dotknąć. */
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.ai-chat-input:focus {
  border-color: var(--accent-primary);
}

/* Loading indicators */
.ai-loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

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

.ai-typing {
  display: inline-flex;
  gap: 4px;
  padding: 6px 10px;
}

.ai-typing span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}

.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.ai-chat-actions {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Archiwum rozmów */
.ai-archive-search {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0 var(--sp-5);
  margin-bottom: var(--sp-5);
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--fs-base);
}

.ai-archive-search:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.ai-archive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.ai-archive-item {
  width: 100%;
  min-height: var(--tap-min);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-1);
  padding: var(--sp-5) var(--sp-6);
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.ai-archive-item:hover,
.ai-archive-item:focus-visible {
  background: var(--bg-hover);
  border-color: var(--accent-primary);
}

.ai-archive-title {
  font-size: var(--fs-base);
  font-weight: 500;
}

.ai-archive-meta {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.ai-archive-empty {
  text-align: center;
  padding: var(--sp-7) 0;
}

.ai-archive-toolbar {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

.ai-archive-toolbar-right {
  display: flex;
  gap: var(--sp-4);
}

.ai-chat-messages.ai-archive-messages {
  padding: var(--sp-6) 0 0;
  max-height: none;
  min-height: 0;
  overflow: visible;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .ai-header {
    flex-direction: column;
    align-items: stretch;
  }
  .ai-chat-header {
    flex-wrap: wrap;
    gap: var(--sp-4);
  }
  .ai-msg {
    max-width: 95%;
  }
  .ai-analysis-card {
    padding: 1.25rem;
  }
  .ai-layout {
    gap: 1rem;
  }
  .ai-chat-header {
    padding: 1rem;
  }
  .ai-chips-row {
    padding: 0.6rem 1rem;
  }
  .ai-chip {
    min-height: 36px;
  }
}

/* ═══════════════════════════════════════════════════
   STREAMING CURSOR
   ═══════════════════════════════════════════════════ */

.ai-stream-cursor::after {
  content: '▊';
  animation: streamBlink 0.8s step-end infinite;
  color: var(--accent-primary);
  font-weight: 300;
  margin-left: 2px;
}

@keyframes streamBlink {
  50% { opacity: 0; }
}

/* ═══════════════════════════════════════════════════
   ACTION CARDS (Function Calling)
   ═══════════════════════════════════════════════════ */

.ai-action-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 0.5rem;
}

.ai-action-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.ai-action-icon {
  font-size: 1.25rem;
}

.ai-action-card-body {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.ai-action-card-body ol,
.ai-action-card-body ul {
  margin: 0.25rem 0;
  padding-left: 1.25rem;
}

.ai-action-card-body li {
  margin-bottom: 0.25rem;
}

.ai-action-card-body li strong {
  color: var(--text-primary);
}

.ai-action-card-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.ai-action-btn-approve {
  background: var(--accent-strength) !important;
  color: white !important;
  border: none !important;
  padding: 0.5rem 1rem !important;
  border-radius: var(--radius-md) !important;
  font-size: 0.85rem !important;
  cursor: pointer;
  transition: var(--transition);
}

.ai-action-btn-approve:hover {
  filter: brightness(1.1);
}

.ai-action-btn-reject {
  background: var(--bg-surface) !important;
  color: var(--text-secondary) !important;
  border: 1px solid var(--border) !important;
  padding: 0.5rem 1rem !important;
  border-radius: var(--radius-md) !important;
  font-size: 0.85rem !important;
  cursor: pointer;
  transition: var(--transition);
}

.ai-action-btn-reject:hover {
  background: var(--bg-hover) !important;
  color: var(--text-primary) !important;
}

.ai-action-status {
  font-size: 0.85rem;
  padding: 0.5rem 0;
}

.ai-action-approved .ai-action-card-header {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(16, 185, 129, 0.1));
}

.ai-action-rejected {
  opacity: 0.6;
}

.ai-action-exercises {
  list-style-type: decimal;
}

/* ═══════════════════════════════════════════════════
   IMAGE ATTACHMENT
   ═══════════════════════════════════════════════════ */

.ai-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 1.25rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.ai-attach-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-primary);
}

.ai-attach-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
}

.ai-attach-preview img {
  max-height: 80px;
  max-width: 120px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.ai-attach-remove {
  background: var(--accent-danger);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-msg-image {
  max-width: 200px;
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE ADJUSTMENTS
   ═══════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .ai-action-card-actions {
    flex-direction: column;
  }
  
  .ai-action-btn-approve,
  .ai-action-btn-reject {
    width: 100% !important;
    text-align: center !important;
  }
  
  .ai-attach-preview img {
    max-height: 60px;
    max-width: 80px;
  }
}

/* ── Łącznik Claude (MCP) ─────────────────────────────────────── */
.ai-mcp-card {
  margin-top: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.ai-mcp-card summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  font-weight: 600;
  list-style: none;
}

.ai-mcp-card summary::-webkit-details-marker {
  display: none;
}

.ai-mcp-card summary::after {
  content: '▾';
  margin-left: auto;
  color: var(--text-muted);
  transition: var(--transition);
}

.ai-mcp-card[open] summary::after {
  transform: rotate(180deg);
}

.ai-mcp-body {
  padding: 0 1.25rem 1.25rem;
  font-size: 0.9rem;
}

.ai-mcp-steps {
  margin: 0.75rem 0;
  padding-left: 1.25rem;
  line-height: 1.6;
}

.ai-mcp-url-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ai-mcp-url {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: nowrap;
  font-size: 0.85rem;
}

.ai-mcp-hint {
  font-size: 0.8rem;
  margin-bottom: 1rem;
  overflow-wrap: anywhere;
}
