/* =====================================================
 * VP DISCOVERY CHAT - BLUEPRINT NOIR
 * AI-powered Value Proposition discovery interface
 * Claude Desktop-style layout with sticky input at bottom
 * ===================================================== */

/* ===== PREVENT BODY SCROLL ===== */
/* When chat is active, prevent body scroll to keep layout clean */
body:has(.vp-discovery-chat) {
  overflow: hidden;
}

/* ===== CHAT LAYOUT ===== */
/* Full-height chat like Claude Desktop - sticky input at bottom */
/* Using position: fixed with insets for reliable iOS support */
.vp-discovery-chat {
  display: flex;
  flex-direction: column;
  /* Fallback height for non-fixed contexts */
  height: calc(100vh - 140px);
  height: calc(100dvh - 140px);
  max-width: 900px;
  margin: 0 auto;
  padding: 0;
  background: var(--bg-depth);
  position: relative;
  /* Prevent any content overflow */
  overflow: hidden;
}

/* ===== CHAT HEADER ===== */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 2rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-tech);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-title::before {
  content: '';
  display: block;
  width: 0.625rem;
  height: 0.625rem;
  background: var(--accent-copper);
  box-shadow: 0 0 10px var(--accent-copper-glow);
}

.chat-header-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  justify-items: end;
}

/* ===== PHASE INDICATOR ===== */
.phase-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.phase-step {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-sm);
  transition: all 0.3s ease;
}

.phase-step.active {
  background: var(--accent-copper-glow);
  border-color: var(--accent-copper);
}

.phase-step.complete {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
}

.phase-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-depth);
  border-radius: 50%;
  transition: all 0.3s ease;
}

.phase-step.active .phase-number {
  color: var(--accent-copper);
  background: var(--bg-card);
  box-shadow: 0 0 8px var(--accent-copper-glow);
}

.phase-step.complete .phase-number {
  color: #10B981;
  background: rgba(16, 185, 129, 0.2);
}

.phase-step.complete .phase-number {
  /* Hide the number */
  font-size: 0;
}

.phase-step.complete .phase-number::after {
  content: '';
  display: block;
  width: 0.5rem;
  height: 0.375rem;
  border: solid #10B981;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-1px);
}

.phase-name {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  transition: all 0.3s ease;
}

.phase-step.active .phase-name {
  color: var(--accent-copper);
}

.phase-step.complete .phase-name {
  color: #10B981;
}

/* Phase divider arrows */
.phase-divider {
  color: var(--text-muted);
  font-size: 0.75rem;
  opacity: 0.5;
}

/* ===== COST INDICATOR (dev only) ===== */
.cost-indicator {
  position: relative;
}

.cost-indicator-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  background: transparent;
  border: 1px dashed var(--border-tech);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  list-style: none;
  color: var(--text-muted);
}

.cost-indicator-toggle::-webkit-details-marker {
  display: none;
}

.cost-indicator-toggle:hover {
  border-color: rgba(16, 185, 129, 0.4);
  color: var(--text-secondary);
}

.cost-indicator[open] .cost-indicator-toggle {
  background: var(--bg-card);
  border-style: solid;
  border-color: rgba(16, 185, 129, 0.3);
}

.cost-label {
  display: none;
}

.cost-value {
  color: var(--text-muted);
  font-weight: 500;
}

.cost-indicator-toggle:hover .cost-value,
.cost-indicator[open] .cost-value {
  color: #10B981;
}

.cost-details {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  min-width: 240px;
  margin-top: 0.25rem;
  padding: 0.5rem;
  background: var(--bg-card);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
  font-family: var(--font-mono);
  font-size: 0.65rem;
}

.cost-row:not(:last-child) {
  border-bottom: 1px dashed var(--border-tech);
}

.cost-detail-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cost-detail-value {
  color: var(--text-secondary);
}

.cost-row.cost-total {
  margin-top: 0.125rem;
  padding-top: 0.375rem;
  border-top: 1px solid var(--border-tech);
}

.cost-row.cost-total .cost-detail-label {
  color: var(--text-primary);
}

.cost-row.cost-total .cost-detail-value {
  color: #10B981;
  font-weight: 600;
}

/* ===== MESSAGES CONTAINER ===== */
.messages-container {
  flex: 1;
  min-height: 0; /* Critical for flex overflow to work! */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
  /* Ensure scroll starts from bottom on load */
  overscroll-behavior: contain;
}

/* Custom scrollbar for messages */
.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: var(--bg-depth);
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border-tech);
  border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
  background: var(--accent-copper-dim);
}

/* ===== MESSAGE BUBBLES ===== */
.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User messages - right aligned */
.message-user {
  align-self: flex-end;
}

.message-user .message-content {
  background: var(--bg-card);
  border: 1px solid var(--accent-copper);
  border-left: 3px solid var(--accent-copper);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  color: var(--text-primary);
}

/* AI messages - left aligned */
.message-assistant {
  align-self: flex-start;
}

.message-assistant .message-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  color: var(--text-primary);
}

/* Message content typography */
.message-content {
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.7;
}

.message-content p {
  margin: 0 0 0.75rem 0;
}

.message-content p:last-child {
  margin-bottom: 0;
}

/* Markdown styling for AI responses */
.message-content strong,
.message-content b {
  color: var(--accent-copper);
  font-weight: 600;
}

.message-content em,
.message-content i {
  font-style: italic;
  color: var(--text-secondary);
}

.message-content ul,
.message-content ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}

.message-content li {
  margin-bottom: 0.375rem;
}

.message-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-depth);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
  color: var(--accent-copper);
}

/* Chat headings for VP variants and sections */
.message-content .chat-heading {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent-copper);
  margin: 1.25rem 0 0.75rem 0;
  padding-bottom: 0.375rem;
  border-bottom: 1px dashed var(--border-tech);
}

.message-content h3.chat-heading {
  font-size: 1.1rem;
}

.message-content h4.chat-heading {
  font-size: 0.95rem;
}

.message-content .chat-heading:first-child {
  margin-top: 0;
}

/* Horizontal rule dividers between VP variants */
.message-content hr.chat-divider {
  border: none;
  border-top: 1px dashed var(--border-tech);
  margin: 1.5rem 0;
  opacity: 0.6;
}

/* Message metadata */
.message-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.375rem;
  padding: 0 0.25rem;
}

.message-time {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

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

/* ===== ERROR MESSAGE ===== */
.message-error {
  align-self: center;
  max-width: 90%;
}

.message-error .message-content {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-left: 3px solid #EF4444;
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
}

.message-error .error-message {
  color: #FCA5A5;
  font-family: var(--font-body);
  font-size: 0.9rem;
  margin: 0;
}

/* ===== TYPING INDICATOR ===== */
/* Inside messages container, styled like AI message (left-aligned) */
/* order: 9999 ensures it's always last in flex container, regardless of DOM position */
/* This is necessary because Turbo Stream appends new messages AFTER the indicator in DOM */
.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 0.75rem 0;
  order: 9999;
}

.typing-indicator.visible {
  display: block;
}

.typing-indicator-bubble {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 1rem 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-sm);
}

.typing-dot {
  width: 0.5rem;
  height: 0.5rem;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingPulse 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingPulse {
  0%, 60%, 100% {
    transform: scale(1);
    opacity: 0.4;
  }
  30% {
    transform: scale(1.2);
    opacity: 1;
    background: var(--accent-copper);
  }
}

/* ===== INPUT AREA ===== */
/* Always stays at bottom - never scrolls away */
.chat-input-area {
  flex-shrink: 0;
  padding: 1.5rem 2rem;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-tech);
  /* Ensure it stays above everything and at bottom */
  position: relative;
  z-index: 10;
  /* Subtle shadow for depth separation */
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.chat-input-form {
  display: flex;
  align-items: center; /* Wyśrodkuj przyciski wertykalnie względem inputu */
  gap: 1rem;
}

.chat-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
}

.chat-input {
  width: 100%;
  min-height: 48px;
  max-height: 150px;
  padding: 0.75rem 1rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-sm);
  resize: none;
  outline: none;
  transition: all 0.2s ease;
}

.chat-input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.chat-input:focus {
  border-color: var(--accent-copper);
  background: var(--bg-card);
  box-shadow: 0 0 15px var(--accent-copper-glow);
}

.chat-input:disabled {
  background: var(--bg-depth);
  color: var(--text-muted);
  cursor: not-allowed;
  border-style: dashed;
}

/* ===== MIC BUTTON (Voice Recording) ===== */

/* Pulsing animation for recording state */
@keyframes mic-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(184, 115, 51, 0.7);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(184, 115, 51, 0);
  }
}

.chat-mic-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.chat-mic-btn:hover {
  color: var(--accent-copper);
  border-color: var(--accent-copper-dim);
  background: var(--accent-copper-glow);
}

.chat-mic-btn .btn-icon {
  width: 1.125rem;
  height: 1.125rem;
}

/* Recording state - copper accent background */
.chat-mic-btn--recording {
  background: linear-gradient(135deg, var(--accent-copper) 0%, var(--accent-copper-dim) 100%);
  border-color: var(--accent-copper);
  color: #0B0E11;
  animation: mic-pulse 1.5s ease-in-out infinite;
}

.chat-mic-btn--recording:hover {
  background: linear-gradient(135deg, var(--accent-copper) 0%, var(--accent-copper-dim) 100%);
  color: #0B0E11;
  filter: brightness(1.1);
}

/* Hidden state for unsupported browsers */
.chat-mic-btn.hidden {
  display: none;
}

/* Send button */
.chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 1.25rem;
  min-width: 100px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #0B0E11;
  background: linear-gradient(135deg, var(--accent-copper) 0%, var(--accent-copper-dim) 100%);
  border: 1px solid var(--accent-copper);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.3s ease;
}

.chat-send-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 20px var(--accent-copper-glow);
  filter: brightness(1.1);
}

.chat-send-btn:disabled {
  background: var(--bg-card);
  color: var(--text-muted);
  border-color: var(--border-tech);
  border-style: dashed;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  filter: none;
}

.chat-send-btn .btn-icon {
  width: 1.125rem;
  height: 1.125rem;
}

/* Loading state for send button */
.chat-send-btn.loading {
  color: transparent !important;
  position: relative;
}

.chat-send-btn.loading .btn-icon,
.chat-send-btn.loading span {
  visibility: hidden;
}

.chat-send-btn.loading::after {
  content: '';
  position: absolute;
  width: 1.25rem;
  height: 1.25rem;
  top: 50%;
  left: 50%;
  margin-top: -0.625rem;
  margin-left: -0.625rem;
  border: 2px solid var(--bg-depth);
  border-radius: 50%;
  border-top-color: transparent;
  animation: sendBtnSpin 0.75s linear infinite;
}

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

/* ===== VP VARIANTS SECTION ===== */
/* Now rendered inside messages-container for proper scrolling */
.vp-variants {
  padding: 2rem;
  margin: 1rem -2rem -2rem -2rem; /* Compensate for messages-container padding */
  background: var(--bg-surface);
  border-top: 2px solid var(--accent-copper);
}

.vp-variants-header {
  text-align: center;
  margin-bottom: 2rem;
}

.vp-variants-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.5rem 0;
}

.vp-variants-subtitle {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Variants grid */
.variants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

/* Variant card */
.vp-variant-card {
  background: var(--bg-card);
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  position: relative;
  transition: all 0.3s ease;
}

.vp-variant-card:hover {
  border-color: var(--accent-copper-dim);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.vp-variant-card.selected {
  border-color: var(--accent-copper);
  background: var(--accent-copper-glow);
  box-shadow: 0 0 20px var(--accent-copper-glow);
}

.vp-variant-header {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px dashed var(--border-tech);
}

.vp-variant-headline {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
  line-height: 1.3;
}

.vp-variant-subheadline {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--accent-copper);
  margin: 0;
  line-height: 1.4;
}

.vp-variant-statement {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1rem;
}

.vp-variant-details {
  margin-bottom: 1.25rem;
}

.vp-variant-detail {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  display: flex;
  gap: 0.375rem;
}

.vp-variant-detail strong {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

.vp-variant-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* VP variant select button - inherits from btn-secondary btn-sm */
.vp-variant-actions .btn {
  flex: 1;
  justify-content: center;
}

.vp-variant-actions .btn:hover {
  background: var(--accent-copper-glow);
  border-color: var(--accent-copper);
}

/* Selected badge */
.selected-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #10B981;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-sm);
}

.selected-badge::before {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  background: #10B981;
  border-radius: 50%;
}

/* Export actions */
.export-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-tech);
}

.export-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.export-actions .btn-icon-left {
  width: 1.125rem;
  height: 1.125rem;
}

/* ===== RESET BUTTON ===== */
.chat-reset-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-reset-btn:hover {
  color: #EF4444;
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
}

.chat-reset-btn .btn-icon {
  width: 0.875rem;
  height: 0.875rem;
}

/* Disabled state for reset button (no credits) */
.chat-reset-btn--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.chat-reset-btn--disabled:hover {
  color: var(--text-muted);
  border-color: var(--border-tech);
  background: transparent;
}

/* ===== CREDITS BADGE ===== */
.chat-credits-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: rgba(42, 52, 65, 0.5);
  border: 1px solid rgba(212, 165, 116, 0.25);
  border-radius: var(--radius-sm);
  color: var(--color-copper-light);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
}

.chat-credits-badge .credits-icon {
  width: 1rem;
  height: 1rem;
  opacity: 0.8;
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {
  .vp-discovery-chat {
    /* Use position: fixed on mobile for reliable iOS support */
    /* This bypasses problematic dvh/vh calculations */
    position: fixed;
    top: 56px; /* mobile nav height */
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    max-width: none;
    margin: 0;
    border-radius: 0;
  }

  .chat-header {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    align-items: center;
    justify-content: space-between;
    /* Widoczny separator od wiadomości */
    background: var(--bg-card);
    border-bottom: 1px solid var(--accent-copper-dim);
  }

  /* Ukryj tytuł na mobile - user wie gdzie jest */
  .chat-header-left {
    display: none;
  }

  .chat-header-actions {
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    /* Reset po lewej, kredyty po prawej */
    justify-content: space-between;
    gap: 0.5rem;
  }

  /* Ukryj cost indicator na mobile (i tak jest dev-only) */
  .cost-indicator {
    display: none;
  }

  /* Reset button - tylko ikona na mobile */
  .chat-reset-btn {
    padding: 0.5rem;
    min-width: 40px;
    justify-content: center;
  }

  .chat-reset-btn span {
    display: none;
  }

  /* Credits badge - bardziej kompaktowy */
  .chat-credits-badge {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }

  .phase-indicator {
    flex-wrap: wrap;
    gap: 0.375rem;
  }

  .phase-step {
    padding: 0.25rem 0.5rem;
  }

  .phase-name {
    display: none;
  }

  .messages-container {
    padding: 1rem;
    gap: 1rem;
  }

  .message {
    max-width: 90%;
  }

  .chat-input-area {
    padding: 1rem;
    /* Safe area for iOS devices with home bar */
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .chat-input-form {
    flex-direction: row;
    flex-wrap: nowrap;  /* INLINE: bez zawijania - wszystko w jednym rzędzie */
    gap: 0.5rem;
    align-items: flex-end;  /* Wyrównaj do dołu dla textarea */
  }

  .chat-input-wrapper {
    flex: 1;  /* Zajmuje dostępną przestrzeń */
    min-width: 0;  /* Pozwala się kurczyć poniżej content-size */
  }

  /* Mic button: tylko ikona, kwadratowy */
  .chat-input-form > .chat-mic-btn {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Send button: tylko tekst "Wyślij", bez ikony */
  .chat-input-form > .chat-send-btn {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 1rem;
  }

  /* Ukryj ikonę w Send button na mobile */
  .chat-send-btn .btn-icon {
    display: none;
  }

  .variants-grid {
    grid-template-columns: 1fr;
  }

  .vp-variants {
    padding: 1.5rem 1rem;
    margin: 1rem -1rem -1rem -1rem; /* Compensate for mobile messages-container padding */
  }
}

/* ===== CONVERSATION ENDED STATE ===== */
/* Replaces input area when message limit is reached */
.conversation-ended {
  text-align: center;
}

.conversation-ended-content {
  max-width: 480px;
  margin: 0 auto;
}

.conversation-ended-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  margin-bottom: 1rem;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 50%;
}

.conversation-ended-icon svg {
  width: 2rem;
  height: 2rem;
  color: #10B981;
}

.conversation-ended-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.conversation-ended-message {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin: 0 0 1.5rem 0;
}

.export-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
}

.export-btn .btn-icon {
  width: 1.125rem;
  height: 1.125rem;
}

.export-btn.btn-secondary {
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-tech);
}

.export-btn.btn-secondary:hover {
  border-color: var(--accent-copper);
  background: var(--accent-copper-glow);
}

.export-btn.btn-primary {
  color: #0B0E11;
  background: linear-gradient(135deg, var(--accent-copper) 0%, var(--accent-copper-dim) 100%);
  border: 1px solid var(--accent-copper);
}

.export-btn.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 20px var(--accent-copper-glow);
  filter: brightness(1.1);
}

.pdf-hint {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px dashed var(--border-tech);
  border-radius: var(--radius-sm);
}

.export-hint {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
}

@media (max-width: 480px) {
  .vp-discovery-chat {
    /* position: fixed inherited from 768px query */
    /* Just adjust top offset for smaller mobile nav */
    top: 48px;
  }

  .chat-title {
    font-size: 1.25rem;
  }

  /* Hide phase indicator on very small screens - it takes too much space */
  .phase-indicator {
    display: none;
  }

  /* Pełna szerokość wiadomości na bardzo małych ekranach */
  .messages-container {
    padding: 0.75rem;
  }

  .message {
    max-width: 98%;
  }

  .message-content {
    font-size: 0.9rem;
    padding: 0.75rem 1rem;
  }

  /* Kompaktowe touch targets dla mobile */
  .chat-input {
    min-height: 48px;
    padding: 0.875rem 1rem;
    font-size: 1rem;
  }

  .chat-send-btn {
    min-height: 44px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }

  .chat-mic-btn {
    min-height: 44px;
  }

  .chat-reset-btn {
    padding: 0.75rem 1.25rem;
    font-size: 0.8rem;
  }

  /* VP variant cards touch-friendly */
  .vp-variant-card {
    padding: 1.25rem;
  }

  .vp-variant-actions .btn {
    min-height: 48px;
    padding: 0.875rem 1.25rem;
  }

  /* Conversation ended mobile */
  .export-buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .export-btn {
    justify-content: center;
    min-height: 52px;
  }

  .conversation-ended-title {
    font-size: 1.1rem;
  }
}

/* ===== EXPORT MENU ===== */
/* Dropdown menu for export options, opens upward */
.chat-export-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.chat-export-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.3s ease;
}

.chat-export-btn:hover,
.chat-export-btn.active {
  color: var(--accent-copper);
  border-color: var(--accent-copper-dim);
  background: var(--accent-copper-glow);
}

.chat-export-btn .btn-icon {
  width: 1.125rem;
  height: 1.125rem;
}

/* Menu dropdown - opens upward */
.export-menu {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0;
  min-width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-sm);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.2s ease;
  z-index: 100;
}

.export-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Menu items */
.export-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.875rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.export-menu-item:hover {
  background: var(--bg-surface);
  color: var(--accent-copper);
}

.export-menu-item:not(:last-child) {
  border-bottom: 1px solid var(--border-tech);
}

.export-menu-item .menu-icon {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: color 0.2s ease;
}

.export-menu-item:hover .menu-icon {
  color: var(--accent-copper);
}

/* Highlighted menu item (PDF report) */
.export-menu-item--highlight {
  background: var(--accent-copper-glow);
  border-top: 1px solid var(--accent-copper-dim) !important;
}

.export-menu-item--highlight:hover {
  background: rgba(184, 115, 51, 0.25);
}

.export-menu-item--highlight .menu-icon {
  color: var(--accent-copper);
}

/* Report option container for Turbo updates */
#export-menu-report-option:empty {
  display: none;
}

/* ===== LOADING MODAL ===== */
/* Full-screen overlay for PDF generation */
.loading-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(11, 14, 17, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.loading-modal.visible {
  opacity: 1;
  visibility: visible;
}

.loading-modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-tech);
  border-radius: var(--radius-md);
  max-width: 320px;
  text-align: center;
}

/* Spinner animation */
.loading-spinner {
  width: 3rem;
  height: 3rem;
  border: 3px solid var(--border-tech);
  border-top-color: var(--accent-copper);
  border-radius: 50%;
  animation: loading-spin 1s linear infinite;
}

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

.loading-text {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-secondary);
  margin: 0;
  min-height: 1.5em;
  animation: loading-text-fade 0.3s ease;
}

@keyframes loading-text-fade {
  from {
    opacity: 0.5;
  }
  to {
    opacity: 1;
  }
}

/* ===== TOAST NOTIFICATIONS ===== */
/* Brief feedback for clipboard copy, etc. */
.export-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 0.875rem 1.5rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  z-index: 1001;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.export-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.export-toast--success {
  background: rgba(16, 185, 129, 0.95);
  color: #fff;
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.3);
}

.export-toast--error {
  background: rgba(239, 68, 68, 0.95);
  color: #fff;
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.3);
}

/* ===== EXPORT MENU MOBILE ===== */
@media (max-width: 768px) {
  .chat-export-wrapper {
    order: -1; /* Move before other buttons */
  }

  .chat-export-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
  }

  .export-menu {
    right: auto;
    left: 0;
    min-width: 200px;
  }

  .export-menu-item {
    padding: 1rem;
    font-size: 0.95rem;
    /* Touch-friendly tap target */
    min-height: 48px;
  }

  .loading-modal-content {
    margin: 0 1rem;
    padding: 2rem 1.5rem;
  }

  .export-toast {
    bottom: calc(1rem + env(safe-area-inset-bottom));
    left: 1rem;
    right: 1rem;
    transform: translateY(20px);
  }

  .export-toast.visible {
    transform: translateY(0);
  }
}
