/* ===== DOCTOR AI — Chat UI Styles ===== */
/* Usa le CSS variables di styles.css (--bg-primary, --accent-primary, ecc.) */

/* ===== LAYOUT PRINCIPALE ===== */
.doctor-wrapper {
  display: grid;
  grid-template-columns: 260px 1fr;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-4);
  gap: var(--space-4);
  height: calc(100dvh - 80px);
}

/* ===== SIDEBAR ===== */
.doctor-sidebar {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  height: 100%;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--divider);
}

.sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Health Summary */
.health-summary {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: var(--space-3);
}

.health-summary-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

.health-summary-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.health-summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.health-summary-label {
  color: var(--text-secondary);
}

.health-summary-value {
  color: var(--text-primary);
  font-weight: 600;
}

.health-summary-empty {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  text-align: center;
  padding: var(--space-2) 0;
}

/* Pulsante Nuova Chat */
.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  border: none;
  border-radius: 8px;
  padding: var(--space-3) var(--space-4);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  width: 100%;
  min-height: 44px;
}

.btn-new-chat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Sessioni recenti */
.sessions-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sessions-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

.sessions-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.session-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.session-item:hover {
  background: var(--bg-tertiary);
}

.session-item.active {
  background: linear-gradient(135deg, rgba(193, 165, 123, 0.15), rgba(139, 115, 85, 0.15));
  border-left: 3px solid var(--accent-primary);
}

.session-item-text {
  flex: 1;
  min-width: 0;
}

.session-item-title {
  font-size: 0.8rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.session-item-date {
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.session-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.15s, background-color 0.15s;
}

.session-item:hover .session-delete-btn {
  opacity: 1;
}

.session-delete-btn:hover {
  background: rgba(229, 62, 62, 0.1);
  color: #e53e3e;
}

/* Link profilo */
.sidebar-profile-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.8rem;
  transition: color 0.15s, background-color 0.15s;
  border-top: 1px solid var(--divider);
  padding-top: var(--space-4);
  margin-top: auto;
}

.sidebar-profile-link:hover {
  color: var(--accent-primary);
}

/* ===== AREA CHAT ===== */
.chat-container {
  background: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Header chat */
.chat-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.chat-header-icon {
  font-size: 1.5rem;
}

.chat-header-info {
  flex: 1;
}

.chat-header-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-header-subtitle {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

.chat-header-actions {
  display: flex;
  gap: var(--space-2);
}

.chat-header-btn {
  background: transparent;
  border: 1px solid var(--divider);
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.chat-header-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Messaggi */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch; /* momentum scroll on iOS (IMP-03) */
  overscroll-behavior: contain; /* prevent pull-to-refresh (IMP-05) */
}

/* Welcome screen (prima della prima chat) */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-5);
  padding: var(--space-8);
  text-align: center;
}

.chat-welcome-icon {
  font-size: 4rem;
}

.chat-welcome-title {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chat-welcome-description {
  color: var(--text-secondary);
  max-width: 500px;
  line-height: 1.6;
}

.chat-welcome-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  width: 100%;
  max-width: 560px;
}

.suggestion-chip {
  background: var(--bg-tertiary);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s, color 0.2s, transform 0.2s;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.suggestion-chip:hover {
  border-color: var(--accent-primary);
  background: linear-gradient(135deg, rgba(193, 165, 123, 0.08), rgba(139, 115, 85, 0.08));
  color: var(--text-primary);
  transform: translateY(-2px);
}

/* Messaggio singolo */
.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: messageIn 0.25s var(--ease-elegant);
}

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

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--divider);
}

/* Badge agenti */
.message-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  flex-wrap: wrap;
}

.agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.agent-badge-lab       { background: rgba(72, 187, 120, 0.15); color: #48bb78; }
.agent-badge-nutrition { background: rgba(237, 137, 54, 0.15);  color: #ed8936; }
.agent-badge-symptoms  { background: rgba(245, 101, 101, 0.15); color: #f56565; }
.agent-badge-pathology { background: rgba(159, 122, 234, 0.15); color: #9f7aea; }
.agent-badge-fitness   { background: rgba(56, 178, 172, 0.15);  color: #38b2ac; }
.agent-badge-mental    { background: rgba(99, 102, 241, 0.15);  color: #818cf8; }

.urgency-badge-high   { background: rgba(229, 62, 62, 0.15);  color: #e53e3e;  padding: 2px 8px; border-radius: 20px; font-size: 0.7rem; font-weight: 700; }
.urgency-badge-medium { background: rgba(237, 137, 54, 0.15); color: #ed8936;  padding: 2px 8px; border-radius: 20px; font-size: 0.7rem; font-weight: 700; }

.message-time {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-top: 4px;
  padding: 0 var(--space-1);
}

/* Messaggio documento */
.message-document {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(193, 165, 123, 0.15), rgba(139, 115, 85, 0.15));
  border: 1px solid var(--accent-border);
  max-width: 340px;
}

.message-document-icon { font-size: 2rem; }
.message-document-info { flex: 1; }
.message-document-name { font-weight: 600; font-size: 0.85rem; color: var(--text-primary); }
.message-document-meta { font-size: 0.75rem; color: var(--text-secondary); }

/* Markdown rendering nel bubble assistente */
.message.assistant .message-bubble strong { font-weight: 700; }
.message.assistant .message-bubble em { font-style: italic; }
.message.assistant .message-bubble code {
  background: var(--bg-secondary);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85em;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-tertiary);
  font-size: 0.85rem;
  padding: var(--space-2) 0;
}

.typing-dots span {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 2px;
  background: var(--accent-primary);
  border-radius: 50%;
  animation: typingBounce 1.3s ease-in-out infinite;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== AREA INPUT ===== */
.chat-input-area {
  border-top: 1px solid var(--divider);
  padding: var(--space-4);
  flex-shrink: 0;
}

/* Preview file selezionato */
.file-preview {
  display: none;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: var(--space-3);
  border: 1px solid var(--divider);
}

.file-preview.visible {
  display: flex;
}

.file-preview-icon { font-size: 1.5rem; }

.file-preview-info {
  flex: 1;
}

.file-preview-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview-size {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.file-preview-remove {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 1.2rem;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.15s, color 0.15s;
}

.file-preview-remove:hover {
  background: rgba(229, 62, 62, 0.1);
  color: #e53e3e;
}

/* Upload progress */
.upload-progress {
  display: none;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: var(--space-3);
}

.upload-progress.visible {
  display: flex;
}

.upload-progress-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.upload-progress-bar {
  height: 4px;
  background: var(--divider);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 2px;
  animation: progressPulse 1.5s ease-in-out infinite;
}

@keyframes progressPulse {
  0%, 100% { width: 30%; }
  50% { width: 75%; }
}

/* Input row */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

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

#chatInput {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  padding: var(--space-3) var(--space-4);
  padding-right: 50px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem; /* ≥16px — prevents iOS Safari auto-zoom (CRIT-01) */
  font-family: var(--font-body);
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.5;
  box-sizing: border-box;
}

#chatInput:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(193, 165, 123, 0.12);
}

#chatInput::placeholder {
  color: var(--text-tertiary);
}

.btn-upload {
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid var(--divider);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1.2rem;
  transition: border-color 0.2s, color 0.2s, background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-upload:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: rgba(193, 165, 123, 0.08);
}

.btn-send {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: white;
  font-size: 1.1rem;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

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

.char-counter {
  position: absolute;
  right: var(--space-3);
  bottom: var(--space-2);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  pointer-events: none;
}

.char-counter.warn { color: #ed8936; }
.char-counter.error { color: #e53e3e; }

.chat-disclaimer {
  margin-top: var(--space-2);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  text-align: center;
}

/* Sidebar toggle button — visibile solo su mobile (see @media below) */
.btn-sidebar-toggle {
  display: none;
}

/* ===== ONBOARDING WIZARD ===== */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.onboarding-card {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: var(--space-8);
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow-xl);
  animation: slideUpIn 0.35s var(--ease-elegant);
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

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

.onboarding-title {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-2);
}

.onboarding-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: var(--space-6);
  line-height: 1.5;
}

.onboarding-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input,
.form-select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--divider);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem; /* ≥16px — prevents iOS Safari auto-zoom (CRIT-01) */
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(193, 165, 123, 0.12);
}

.form-hint {
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

.onboarding-actions {
  display: flex;
  gap: var(--space-3);
}

.btn-onboarding-save {
  flex: 1;
  padding: var(--space-3);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-onboarding-save:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-onboarding-skip {
  padding: var(--space-3) var(--space-4);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--divider);
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.btn-onboarding-skip:hover {
  border-color: var(--text-secondary);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .doctor-wrapper {
    grid-template-columns: 220px 1fr;
  }
}

@media (max-width: 768px) {
  .doctor-wrapper {
    display: flex;
    flex-direction: column;
    grid-template-columns: unset;
    height: calc(100dvh - 72px - env(safe-area-inset-top, 0px)); /* CRIT-03 */
    min-height: 0;
    padding: var(--space-2);
    gap: var(--space-2);
    overflow: hidden;
  }

  .doctor-sidebar {
    flex-shrink: 0;
    height: auto;
    overflow: hidden;
    transition: opacity var(--duration-medium) var(--ease-elegant),
                height var(--duration-medium) var(--ease-elegant);
  }

  .doctor-sidebar.sidebar-collapsed {
    display: none;
  }

  .btn-sidebar-toggle {
    display: inline-flex;
    min-width: 44px;
    min-height: 44px;
  }

  .health-summary-items {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-1);
  }

  .sessions-container {
    display: none;
  }

  .sidebar-profile-link {
    display: none;
  }

  .chat-container {
    flex: 1;
    min-height: 0;
    height: auto;
  }

  .chat-header-subtitle {
    display: none;
  }

  .chat-welcome {
    padding: var(--space-4);
    gap: var(--space-3);
  }

  .chat-welcome-icon {
    font-size: 2.5rem;
  }

  .chat-welcome-title {
    font-size: 1.5rem;
  }

  .chat-welcome-description {
    font-size: 0.875rem;
  }

  .chat-welcome-suggestions {
    grid-template-columns: 1fr;
  }

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

  .onboarding-card {
    padding: var(--space-5) var(--space-4); /* IMP-02: reduce padding on small screens */
  }

  .onboarding-title {
    font-size: 1.4rem;
  }
}

@media (max-width: 480px) {
  .doctor-wrapper {
    padding: var(--space-2);
  }

  .chat-messages {
    padding: var(--space-3);
  }

  .chat-input-area {
    padding: var(--space-3);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px)); /* CRIT-03 */
  }

  .message {
    max-width: 95%;
  }
}

/* ===== DESKTOP: hide footer on doctor-ai (full-height app shell) ===== */
@media (min-width: 769px) {
  footer,
  site-footer {
    display: none;
  }
}
