:root {
  --bg: #f6f4ef;
  --bg-panel: #ffffff;
  --ink: #2a2f3a;
  --ink-mute: #5b6372;
  --accent: #2c5f5d;
  --accent-2: #c9a34a;
  --user-bg: #2c5f5d;
  --user-ink: #ffffff;
  --bot-bg: #ffffff;
  --bot-border: #e3dccd;
  --shadow: 0 2px 12px rgba(0,0,0,0.05);
  --radius: 14px;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Georgia", "Cambria", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
}

body {
  display: flex;
  min-height: 100vh;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 270px;
  flex-shrink: 0;
  background: #fbf9f3;
  border-right: 1px solid var(--bot-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-header {
  padding: 16px 14px 10px;
  border-bottom: 1px solid var(--bot-border);
}

.new-conv-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.new-conv-btn:hover { background: #1f4544; }
.new-conv-btn .plus { font-size: 18px; line-height: 1; font-weight: 300; }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  transition: background 0.12s;
  position: relative;
}
.conv-item:hover { background: #f1ece0; }
.conv-item.active { background: #eadfbf; font-weight: 500; }
.conv-item .conv-title {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conv-item .conv-title .conv-line2 {
  font-size: 10px;
  color: var(--ink-mute);
  font-weight: normal;
}
.conv-item .conv-del {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--ink-mute);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-del:hover { background: #e3d4a0; color: #8b3a1a; }
.conv-empty {
  padding: 16px 12px;
  color: var(--ink-mute);
  font-size: 12px;
  font-style: italic;
  text-align: center;
}

.conv-section {
  padding: 14px 12px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-mute);
  font-weight: 600;
  border-top: 1px dashed var(--bot-border);
  margin-top: 4px;
}
.conv-item.conv-remote { color: var(--ink-mute); font-style: italic; }
.conv-item.conv-remote .conv-badge { font-size: 11px; color: var(--accent-2); padding: 2px 4px; }
.conv-item.conv-remote:hover { color: var(--ink); font-style: normal; }
.conv-item.conv-remote.loading { opacity: 0.5; pointer-events: none; }

.hint-cricri {
  padding: 10px 14px;
  border-top: 1px solid var(--bot-border);
  font-size: 11px;
  color: var(--ink-mute);
  line-height: 1.4;
}
.hint-cricri code {
  background: #fff3d6;
  border: 1px solid #d4a93c;
  border-radius: 3px;
  padding: 0 4px;
  font-family: ui-monospace, monospace;
  color: #6b4f12;
  font-size: 10px;
}

.sidebar-footer {
  padding: 8px 14px 10px;
  border-top: 1px solid var(--bot-border);
  font-size: 10px;
  color: var(--ink-mute);
  text-align: center;
}

.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.burger {
  display: none;
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 10px;
}

header {
  padding: 18px 24px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--bot-border);
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
}

.brand { display: flex; gap: 14px; align-items: center; flex: 1; }

.logo {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-family: var(--font-serif);
  letter-spacing: 0.5px;
}

.titles h1 { margin: 0; font-size: 18px; font-family: var(--font-serif); color: var(--ink); }
.titles p { margin: 2px 0 0; font-size: 12px; color: var(--ink-mute); }

/* Language switcher : 2 drapeaux dans le header */
.lang-switch {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-right: 12px;
}
.flag-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--bot-border);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  transition: all 0.15s ease;
  opacity: 0.55;
}
.flag-btn:hover { opacity: 1; border-color: var(--accent); }
.flag-btn.active {
  opacity: 1;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.flag-btn .flag { font-size: 16px; line-height: 1; }
.flag-btn .flag-code { font-size: 11px; letter-spacing: 0.5px; }

.meta { display: flex; gap: 6px; align-items: center; }
.pill {
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.pill.subtle { background: var(--bg); color: var(--ink-mute); border: 1px solid var(--bot-border); }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

.conversation-area {
  display: flex;
  gap: 14px;
  min-height: calc(100vh - 280px);
  align-items: flex-start;
}

.chat {
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-width: 0;
  max-width: 780px;
}

.msg-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.msg-row.user-row { flex-direction: row-reverse; }
.msg-row .msg-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.msg-row.user-row .msg-wrap { align-items: flex-end; }
.msg-row.bot-row .msg-wrap { align-items: flex-start; }

.msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fadeIn 0.25s ease;
}

.msg.bot { align-self: flex-start; background: var(--bot-bg); border: 1px solid var(--bot-border); border-bottom-left-radius: 4px; }
.msg.user { align-self: flex-end; background: var(--user-bg); color: var(--user-ink); border-bottom-right-radius: 4px; }
.msg.user-cricri { align-self: flex-end; background: #8b5a3c; color: #fff; border-bottom-right-radius: 4px; }
.msg.cricri { align-self: flex-start; background: #fff3d6; border: 1px solid #d4a93c; border-left: 4px solid #8b5a3c; font-size: 13px; color: #4a3810; }
.msg.system { align-self: center; background: #fff5f5; border: 1px solid #fecaca; color: #b91c1c; font-size: 13px; max-width: 70%; text-align: center; }

/* ---------------- Panneau commentaires Christophe ---------------- */

.comment-slot {
  flex: 0 0 240px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.comment-box {
  width: 100%;
  min-height: 60px;
  max-height: 240px;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 12.5px;
  color: #4a3810;
  background: #fffaed;
  border: 1px dashed #d4a93c;
  border-left: 3px solid #8b5a3c;
  border-radius: 8px;
  resize: vertical;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.comment-box::placeholder {
  color: #b58c4a;
  font-style: italic;
}
.comment-box:focus {
  outline: none;
  background: #fff;
  border-color: #8b5a3c;
  box-shadow: 0 0 0 2px rgba(139, 90, 60, 0.15);
}
.comment-box.has-content {
  background: #fff5d6;
  border-style: solid;
}
.comment-status {
  font-size: 10px;
  color: var(--ink-mute);
  text-align: right;
  height: 12px;
  min-height: 12px;
}
.comment-status.saved { color: #6b8e23; }
.comment-status.saving { color: #b58c4a; }
.comment-status.error { color: #c4453a; }

@media (max-width: 1100px) {
  .comment-slot { flex-basis: 200px; }
  .comment-box { font-size: 12px; }
}
@media (max-width: 900px) {
  .conversation-area { flex-direction: column; }
  .comment-slot { flex-basis: auto; width: 100%; max-width: 100%; }
}

.msg.typing { display: flex; gap: 4px; align-items: center; padding: 14px 18px; }
.msg.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-mute); animation: blink 1.2s infinite; }
.msg.typing span:nth-child(2) { animation-delay: 0.2s; }
.msg.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.composer {
  display: flex;
  gap: 8px;
  background: var(--bg-panel);
  padding: 10px;
  border: 1px solid var(--bot-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  bottom: 10px;
}

textarea#input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  padding: 8px 10px;
  min-height: 20px;
  max-height: 200px;
  overflow-y: auto;
}

button {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, transform 0.05s;
}
button:hover:not(:disabled) { background: #1f4544; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.1);
  }
  .sidebar.open { transform: translateX(0); }
  .burger { display: inline-flex; }
  .msg { max-width: 92%; }
  header .meta { display: none; }
}

/* ---------------- Voice (TTS + reconnaissance) ---------------- */
.voice-toggle {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid var(--bot-border);
}
.voice-btn {
  background: transparent;
  border: 1px solid var(--bot-border);
  color: var(--ink-mute);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.voice-btn:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
.voice-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.voice-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.voice-select {
  width: 100%;
  padding: 5px 6px;
  font-size: 12px;
  border: 1px solid var(--bot-border);
  border-radius: 6px;
  background: var(--bg-panel);
  color: var(--ink);
  cursor: pointer;
}
.voice-select:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--bot-border);
  color: var(--ink-mute);
  width: 42px;
  padding: 0;
  font-size: 18px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.05s;
}
.icon-btn:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn.listening {
  background: #c4453a;
  color: #fff;
  border-color: #c4453a;
  animation: micPulse 1.1s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(196, 69, 58, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(196, 69, 58, 0); }
}
