/* ============================================
   VARIABLES & RESET
   ============================================ */

:root {
  --primary: #C2410C;
  --primary-dark: #9A3412;
  --primary-tint: #FBEDE7;
  --primary-light: #F0997B;
  --bg: #FAF8F5;
  --card-bg: #FFFFFF;
  --ink: #1C1917;
  --text: #1C1917;
  --text-light: #78716C;
  --text2: #78716C;
  --stone-light: #A8A29E;
  --border: #EDE8E1;
  --error: #DC2626;
  --success: #16A34A;
  --message-owner: #FBEDE7;
  --message-guest: #F1EFEA;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  /* Empêcher le débordement sur TOUS les éléments */
  max-width: 100%;
}

/* ============================================
   FIX : Empêcher COMPLÈTEMENT le scroll horizontal
   ============================================ */
html {
  overflow-x: hidden !important;
  width: 100vw;
  max-width: 100vw;
  position: fixed;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica', 'Arial', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden !important;
  overflow-y: auto;
  width: 100vw;
  max-width: 100vw;
  margin: 0;
  padding: 0;
  position: relative;
  height: 100%;
  -webkit-overflow-scrolling: touch;
}

/* Empêcher le débordement sur les éléments de contenu */
#pinScreen, #chatScreen {
  overflow-x: hidden !important;
  width: 100%;
  max-width: 100vw;
}

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

.screen {
  display: none;
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ============================================
   PIN SCREEN
   ============================================ */

.container {
  flex: 1;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom) 20px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* iPad : container plus large */
@media (min-width: 600px) {
  .container {
    max-width: 560px;
    padding-left: 32px;
    padding-right: 32px;
  }
  .card {
    padding: 40px 36px;
  }
  .pin-digit {
    width: 72px !important;
    max-width: 72px;
    height: 72px;
    font-size: 28px;
  }
}

/* Fix inputs date Safari — rectangles coupés */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 52px;
  height: 52px;
  line-height: 52px;
  padding: 0 16px !important;
  color: var(--text);
  display: block;
  width: 100%;
  box-sizing: border-box;
}
input[type="date"]::-webkit-datetime-edit { 
  color: var(--text);
  line-height: normal;
  padding: 14px 0;
}
input[type="date"]::-webkit-date-and-time-value {
  height: 52px;
  line-height: 52px;
}
input[type="date"]::-webkit-calendar-picker-indicator { opacity: 0.6; cursor: pointer; }

.header {
  padding: 24px 0;
  text-align: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
  margin-bottom: 20px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--ink);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(194, 65, 12, 0.28);
}

.logo-text {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.card {
  background: var(--card-bg);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  max-width: 100%;
  /* Fix Safari — forcer les enfants à rester dans la card */
  width: 100%;
  box-sizing: border-box;
}

.card-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--ink);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 20px;
  box-shadow: 0 4px 16px rgba(194, 65, 12, 0.28);
}

.card h1 {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  color: var(--text);
}

.subtitle {
  text-align: center;
  color: var(--text-light);
  font-size: 15px;
  margin-bottom: 32px;
}

/* ============================================
   FORM
   ============================================ */

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

.form-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
}

.form-group label i {
  color: var(--primary);
  font-size: 16px;
}

.optional {
  font-weight: 400;
  color: var(--text-light);
  font-size: 13px;
}

.form-group input,
.form-group select {
  width: 100%;
  max-width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  transition: all 0.2s ease;
  background: white;
  box-sizing: border-box;
  overflow: hidden;
  display: block;
  /* Fix Safari iOS — empêche le débordement */
  -webkit-box-sizing: border-box;
  min-width: 0;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(194, 65, 12, 0.12);
  transform: none !important; /* Empêcher le zoom sur iOS */
}

/* Empêcher le zoom automatique sur iOS */
@supports (-webkit-touch-callout: none) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

.form-group small {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-light);
}

/* PIN Input */
.pin-input {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 8px;
  max-width: 100%;
  overflow-x: hidden;
}

.pin-digit {
  width: 60px !important;
  max-width: 60px;
  height: 60px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0 !important;
  flex: 0 0 auto;
  box-sizing: border-box;
}

.pin-digit:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(194, 65, 12, 0.12);
}

/* Error */
.error-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  color: var(--error);
  font-size: 14px;
}

.error-box i {
  font-size: 18px;
  flex-shrink: 0;
}

/* Button */
.btn-verify {
  width: 100%;
  padding: 16px;
  background: var(--ink);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(194, 65, 12, 0.28);
}

.btn-verify:active {
  transform: scale(0.98);
}

.btn-verify:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.security-note {
  margin-top: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.security-note i {
  color: var(--success);
}

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

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
}

.chat-header {
  background: var(--ink);
  color: white;
  padding: env(safe-area-inset-top) 16px 16px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-back {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

.property-name {
  font-size: 18px;
  font-weight: 700;
}

.property-dates {
  font-size: 13px;
  opacity: 0.9;
  margin-top: 2px;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.loading {
  text-align: center;
  color: var(--text-light);
  padding: 40px 20px;
}

.loading i {
  font-size: 24px;
  margin-bottom: 8px;
}

.message {
  display: flex;
  gap: 8px;
  max-width: 80%;
}

.message.guest {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-bubble {
  background: var(--message-owner);
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
}

.message.guest .message-bubble {
  background: var(--primary);
  color: white;
}

.message-time {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
  text-align: right;
}

.message.guest .message-time {
  color: rgba(255, 255, 255, 0.7);
}

/* ============================================
   PHOTOS DANS LES MESSAGES
   ============================================ */

.message-photo {
  max-width: 200px;
  max-height: 200px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.message-photo:hover {
  transform: scale(1.02);
}

.message.guest .message-photo {
  border: 2px solid rgba(255, 255, 255, 0.3);
}

/* Image Overlay (plein écran) */
.image-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.image-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.close-overlay {
  position: absolute;
  top: env(safe-area-inset-top, 20px);
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   INPUT CONTAINER (avec emoji & photo)
   ============================================ */

.chat-input-container {
  padding: 12px 16px env(safe-area-inset-bottom);
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  position: relative;
}

#messageInput {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 100px;
  min-height: 40px;
}

#messageInput:focus {
  outline: none;
  border-color: var(--primary);
}

/* Boutons emoji et photo */
.input-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.btn-emoji,
.btn-photo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg);
  border: none;
  color: var(--text-light);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-emoji:hover,
.btn-photo:hover {
  background: var(--border);
  color: var(--primary);
}

.btn-emoji:active,
.btn-photo:active {
  transform: scale(0.95);
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--success);
  border: none;
  color: white;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.btn-send:active {
  transform: scale(0.95);
}

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

/* ============================================
   EMOJI PICKER
   ============================================ */

.emoji-picker {
  position: absolute;
  bottom: 100%;
  left: 16px;
  right: 16px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  padding: 12px;
  display: none;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.emoji-picker.active {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.emoji-item {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.emoji-item:hover {
  background: var(--bg);
  transform: scale(1.2);
}

.emoji-item:active {
  transform: scale(0.9);
}

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


/* ============================================
   TRANSLATION BUTTON
   ============================================ */

.tx-bar { margin-top: 5px; display: flex; }
.message.owner .tx-bar { justify-content: flex-start; }
.message.guest .tx-bar { justify-content: flex-end; }

.tx-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 7px;
  background: rgba(255,255,255,0.6);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  color: #6b7280;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background 0.15s, color 0.15s;
  outline: none;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.tx-chip:hover { background: rgba(124,58,237,0.08); color: var(--primary); }
.tx-chip:focus { outline: none; box-shadow: none; }
.tx-chip.translated { background: rgba(124,58,237,0.08); color: var(--primary); }
.tx-chip:disabled { opacity: 0.4; cursor: wait; }
.tx-chip .tx-flags { font-size: 12px; line-height: 1; }
.tx-chip .tx-label { font-size: 10.5px; }

@media (max-width: 390px) {
  .pin-digit {
    width: 52px !important;
    height: 52px;
    font-size: 20px;
  }
  
  .logo-text {
    font-size: 20px;
  }
  
  .card h1 {
    font-size: 24px;
  }
  
  .emoji-picker.active {
    grid-template-columns: repeat(6, 1fr);
  }
  
  .emoji-item {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }
}
