/* ============================================
   CHAT WIDGET STYLES - Relais San Martino
   ============================================ */

:root {
  --primary: #BDAFA6;
  --primary-dark: #9A8B7F;
  --secondary: #D6D3D1;
  --accent: #8B7355;
  --gold: #C4A962;
  --cream: #FAF8F5;
  --white: #FFFFFF;
  --text-dark: #2C2825;
  --text-muted: #6B6560;
  --text-light: #9A9590;
  --success: #4CAF50;
  --error: #e74c3c;
  --shadow-soft: 0 4px 24px rgba(0,0,0,0.06);
  --shadow-medium: 0 8px 32px rgba(0,0,0,0.1);
  --shadow-strong: 0 16px 48px rgba(0,0,0,0.15);
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --composer-base-padding: 14px;
  --composer-height: 88px;
  --viewport-bottom-offset: 0px;
  --app-height: 100dvh;
  --composer-safe-padding: calc(var(--composer-base-padding) + var(--safe-bottom));
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--cream);
  min-height: 100vh;
  min-height: 100dvh;
  min-height: var(--app-height);
  margin: 0;
  display: block;
  color: var(--text-dark);
  overflow: hidden;
}

/* ============================================
   MAIN CONTAINER
   ============================================ */

.chat-widget {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height);
  background: var(--white);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ============================================
   SCREENS
   ============================================ */

.screen {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.screen.hidden { 
  display: none;
}

/* ============================================
   WELCOME SCREEN
   ============================================ */

.welcome-screen {
  background: linear-gradient(180deg, var(--cream) 0%, var(--white) 100%);
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
}

.welcome-header {
  margin-bottom: 40px;
}

.hotel-logo {
  width: 90px;
  height: 90px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: var(--shadow-medium);
  overflow: hidden;
}

.hotel-logo img {
  width: 60px;
  height: 60px;
  object-fit: contain;
}

.welcome-header h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.8rem;
  color: var(--text-dark);
  margin-bottom: 8px;
}

.hotel-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Language Selector */
.language-selector {
  margin-bottom: 36px;
  width: 100%;
  max-width: 320px;
}

.language-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Language Selector Dropdown */
.language-select {
  width: 100%;
  padding: 14px 18px;
  background: var(--white);
  border: 2px solid var(--secondary);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-dark);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-soft);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%238B7355' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 18px;
}

.language-select:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.language-select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(196, 169, 98, 0.1);
}

/* Start Chat Button */
.start-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 32px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--accent) 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-soft);
}

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

.start-chat-btn svg {
  stroke: currentColor;
}

/* ============================================
   CHAT SCREEN
   ============================================ */

.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding-bottom: calc(var(--composer-height) + var(--viewport-bottom-offset));
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) calc(20px + var(--safe-right)) 16px calc(20px + var(--safe-left));
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  flex-shrink: 0;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-avatar {
  width: 42px;
  height: 42px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-avatar svg {
  stroke: var(--white);
}

.header-text h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.1rem;
  color: var(--white);
  font-weight: 500;
}

.status {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.8);
}

.status.online::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  margin-right: 6px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.icon-btn:hover {
  background: rgba(255,255,255,0.25);
}

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

.icon-btn.locked:hover {
  background: rgba(255,255,255,0.15);
}

.icon-btn svg {
  stroke: var(--white);
}

/* ============================================
   MESSAGES AREA
   ============================================ */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 20px calc(20px + var(--safe-right)) 24px calc(20px + var(--safe-left));
  background: var(--cream);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--secondary); border-radius: 3px; }

/* Messages */
.message {
  display: flex;
  margin-bottom: 16px;
  animation: messageSlide 0.4s ease-out;
}

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

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

.message-content {
  max-width: 80%;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.55;
}

.user-message .message-content {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  border-bottom-right-radius: 6px;
}

.ai-message .message-content {
  background: var(--white);
  color: var(--text-dark);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(189, 175, 166, 0.2);
}

/* ============================================
   MARKDOWN STYLING
   ============================================ */

.ai-message .message-content h1,
.ai-message .message-content h2,
.ai-message .message-content h3 {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--accent);
  margin: 12px 0 8px 0;
}

.ai-message .message-content h1:first-child,
.ai-message .message-content h2:first-child,
.ai-message .message-content h3:first-child { margin-top: 0; }

.ai-message .message-content h1 { font-size: 1.2rem; }
.ai-message .message-content h2 { font-size: 1.1rem; }
.ai-message .message-content h3 { font-size: 1rem; }

.ai-message .message-content p { margin: 8px 0; }
.ai-message .message-content p:first-child { margin-top: 0; }
.ai-message .message-content p:last-child { margin-bottom: 0; }

.ai-message .message-content ul,
.ai-message .message-content ol { margin: 10px 0; padding-left: 20px; }
.ai-message .message-content li { margin: 6px 0; }

.ai-message .message-content strong { color: var(--accent); font-weight: 600; }
.ai-message .message-content em { color: var(--text-muted); }

.ai-message .message-content blockquote {
  border-left: 3px solid var(--gold);
  padding-left: 12px;
  margin: 12px 0;
  color: var(--text-muted);
  font-style: italic;
}

.ai-message .message-content a {
  color: var(--gold);
  text-decoration: none;
  border-bottom: 1px solid var(--gold);
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.typing-indicator .message-content {
  background: var(--white);
  padding: 12px 18px;
}

.typing-dots { 
  display: flex; 
  align-items: center; 
  gap: 4px; 
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.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); }
  30% { transform: translateY(-6px); }
}

/* ============================================
   CONTACT FORM CONTAINER
   ============================================ */

.contact-form-container {
  flex-shrink: 0;
}

.contact-form-container.hidden {
  display: none;
}

.contact-form {
  background: linear-gradient(135deg, rgba(196, 169, 98, 0.08) 0%, rgba(139, 115, 85, 0.08) 100%);
  border-top: 2px solid var(--gold);
  padding: 16px 20px;
  animation: slideUp 0.4s ease-out;
}

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

.contact-form.required {
  border-top-color: var(--gold);
  background: linear-gradient(135deg, rgba(196, 169, 98, 0.15) 0%, rgba(250, 248, 245, 0.95) 100%);
  padding: 20px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-top-width: 3px;
}

.contact-form.required .contact-form-header {
  text-align: center;
  margin-bottom: 16px;
}

.contact-form.required .contact-form-header h3 {
  font-size: 1.25rem;
  color: var(--gold);
  margin-bottom: 8px;
}

.contact-form.required .contact-form-header p {
  font-size: 0.9rem;
  color: var(--text-dark);
}

.contact-form-header {
  margin-bottom: 12px;
}

.contact-form-header h3 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.contact-form-header p {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--secondary);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--white);
  transition: var(--transition);
}

.form-group input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(196, 169, 98, 0.15);
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.submit-btn {
  flex: 1;
  padding: 12px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--accent) 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.submit-btn:hover { 
  transform: translateY(-2px); 
  box-shadow: var(--shadow-soft); 
}

.submit-btn-required {
  background: linear-gradient(135deg, var(--gold) 0%, #D4B872 100%);
  font-size: 1rem;
  padding: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.submit-btn-required:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-medium);
}

.skip-btn {
  padding: 12px 20px;
  background: transparent;
  border: 1.5px solid var(--secondary);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.skip-btn:hover {
  border-color: var(--primary);
  color: var(--text-dark);
}

/* ============================================
   INPUT AREA
   ============================================ */

.message-form {
  padding: 14px calc(16px + var(--safe-right)) max(14px, var(--composer-safe-padding)) calc(16px + var(--safe-left));
  background: var(--white);
  border-top: 1px solid var(--secondary);
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--viewport-bottom-offset);
  z-index: 20;
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--cream);
  border-radius: var(--radius-md);
  padding: 6px;
  border: 2px solid transparent;
  transition: var(--transition);
}

.input-wrapper:focus-within { 
  border-color: var(--primary); 
  background: var(--white); 
}

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-dark);
  line-height: 1.4;
}

#message-input:focus { outline: none; }
#message-input::placeholder { color: var(--text-light); }
#message-input:disabled { background: transparent; cursor: not-allowed; opacity: 0.6; }

.send-btn {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.send-btn svg { stroke: var(--white); }

/* ============================================
   OPEN BUTTON (when minimized)
   ============================================ */

.chat-open-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-medium);
  transition: var(--transition);
  z-index: 1000;
}

.chat-open-btn:hover {
  transform: scale(1.1);
}

.chat-open-btn.hidden {
  display: none;
}

.chat-open-btn svg {
  stroke: var(--white);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 520px) {
  .chat-widget {
    height: 100svh;
    height: 100dvh;
    height: var(--app-height);
  }

  .chat-header {
    padding-top: calc(10px + var(--safe-top));
    padding-bottom: 10px;
  }

  .chat-messages {
    padding-top: 16px;
    padding-bottom: 20px;
  }

  .message-form {
    padding-top: 10px;
    padding-bottom: max(10px, calc(10px + var(--safe-bottom)));
  }

  .input-wrapper {
    border-radius: 18px;
  }

  #message-input {
    min-height: 22px;
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

/* ============================================
   BOOKING WIDGET
   ============================================ */

.booking-widget-wrapper {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--secondary);
}

.booking-helper-message {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(189, 175, 166, 0.12) 0%, rgba(180, 146, 104, 0.12) 100%);
  border: 1px solid rgba(189, 175, 166, 0.35);
  color: var(--text-dark);
  font-size: 0.82rem;
  line-height: 1.5;
}

.booking-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--accent) 100%);
  color: var(--white);
  border: none;
  border-radius: 20px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-soft);
}

.booking-toggle-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-medium);
}

.booking-toggle-btn svg {
  stroke: currentColor;
  flex-shrink: 0;
}

/* Booking Form Container */
.booking-form-container {
  margin-top: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--white);
  box-shadow: var(--shadow-medium);
  border: 1px solid var(--secondary);
  animation: expandBooking 0.3s ease-out;
}

.booking-form-container.hidden {
  display: none;
}

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

.booking-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  font-size: 0.85rem;
  font-weight: 500;
}

.booking-close-btn {
  width: 28px;
  height: 28px;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.booking-close-btn:hover {
  background: rgba(255,255,255,0.3);
}

.booking-close-btn svg {
  stroke: var(--white);
}

/* Booking Form Body */
.booking-form-body {
  padding: 14px;
}

.booking-form {
  margin: 0;
}

.booking-dates-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.booking-field {
  flex: 1;
  min-width: 0;
}

.booking-field label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.booking-field input[type="date"],
.booking-select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--secondary);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-dark);
  background: var(--background);
  transition: var(--transition);
}

.booking-field input[type="date"]:focus,
.booking-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(189, 175, 166, 0.2);
}

.booking-field-arrow {
  flex-shrink: 0;
  padding-top: 18px;
  color: var(--text-muted);
}

.booking-field-arrow svg {
  stroke: var(--text-muted);
}

.booking-guests-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.booking-field-small {
  flex: 1;
}

.booking-submit-btn {
  width: 100%;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
}

.booking-submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-medium);
}

.booking-submit-btn svg {
  stroke: currentColor;
}

@media (max-width: 520px) {
  .booking-helper-message {
    padding: 11px 12px;
    font-size: 0.85rem;
    line-height: 1.55;
  }

  .booking-toggle-btn {
    width: 100%;
    justify-content: center;
  }

  .booking-form-body {
    padding: 12px;
  }

  .booking-dates-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .booking-field-arrow {
    display: none;
  }

  .booking-field input[type="date"] {
    font-size: 16px;
    padding: 10px 12px;
  }

  .booking-guests-row {
    gap: 8px;
  }

  .booking-select {
    font-size: 16px;
    padding: 10px 12px;
  }

  .booking-submit-btn {
    padding: 14px 16px;
    font-size: 1rem;
  }
}
