/* Krinec Reply — page chat plein écran, mobile-first, dark mode auto */

:root {
  --primary: #0f6bff;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --text-muted: #6b7280;
  --assistant-bubble: #ffffff;
  --user-bubble: var(--primary);
  --border: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101318;
    --surface: #1a1e26;
    --text: #eef0f4;
    --text-muted: #9aa2b1;
    --assistant-bubble: #222835;
    --border: #2b3140;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

/* --- En-tête --- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
}

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

.chat-header h1 {
  font-size: 17px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  margin-top: 2px;
}
.badge.open { background: #d1fadf; color: #027a48; }
.badge.closed { background: #fee4e2; color: #b42318; }

.call-btn {
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 10px;
  white-space: nowrap;
}

/* --- Zone chat --- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.45;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.assistant {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg.user {
  background: var(--user-bubble);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg.system-note {
  align-self: center;
  font-size: 13px;
  color: var(--text-muted);
  background: none;
}

/* --- Indicateur de frappe --- */
.typing {
  display: flex;
  gap: 4px;
  padding: 4px 20px 8px;
}
.typing[hidden] { display: none; }
.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* --- Saisie --- */
.chat-input {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

#chat-form {
  display: flex;
  gap: 8px;
}

#message-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 12px 16px;
  font-size: 16px; /* 16px minimum : évite le zoom auto iOS */
  background: var(--bg);
  color: var(--text);
  outline: none;
}
#message-input:focus { border-color: var(--primary); }

#send-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
#send-btn:disabled { opacity: .5; }

.powered {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin: 6px 0 0;
}
.powered a { color: var(--text-muted); }

/* --- Page 404 --- */
.page-404 { justify-content: center; align-items: center; display: flex; }
.notfound { text-align: center; padding: 32px; max-width: 420px; }
.notfound .cta {
  display: inline-block;
  margin-top: 12px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 600;
}
