:root,
html[data-theme="light"] {
  --ink: #1A1A18;
  --ink-on-gold: #1A1A18;
  --bg: #EDEBE4;
  --surface: #FFFFFF;
  --sidebar-bg: #F5F3EC;
  --border: #DCDACF;
  --text: #201F1C;
  --text-muted: #6B6A62;
  --gold: #D9A441;
  --gold-dark: #B8862F;
  --bubble-user-bg: #1A1A18;
  --bubble-user-text: #D9A441;
  --nav-active-bg: var(--gold);
  --nav-hover-bg: #E6E3D8;
}

html[data-theme="dark"] {
  --ink: #17170F;
  --ink-on-gold: #1A1A18;
  --bg: #17170F;
  --surface: #211F19;
  --sidebar-bg: #0F0F0B;
  --border: #3A3830;
  --text: #EDEBE4;
  --text-muted: #A6A499;
  --gold: #D9A441;
  --gold-dark: #EBBE6E;
  --bubble-user-bg: #D9A441;
  --bubble-user-text: #1A1A18;
  --nav-active-bg: var(--gold);
  --nav-hover-bg: #29271F;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen { height: 100vh; display: flex; flex-direction: column; }

#login-view { align-items: center; justify-content: center; padding: 24px; }

.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
}

.login-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}
.login-logo { width: 72px; height: 72px; margin-bottom: 16px; }
.login-title {
  font-family: Georgia, "Iowan Old Style", ui-serif, serif;
  font-size: 26px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text);
  margin: 0 0 6px;
}
.login-card input { text-align: left; }
.muted.center { text-align: center; margin-bottom: 20px; }

.checkbox-label.small {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: left;
  margin: 10px 0;
  cursor: pointer;
  line-height: 1.4;
}
.checkbox-label.small input[type="checkbox"] {
  width: auto;
  margin: 2px 0 0;
  flex-shrink: 0;
  accent-color: var(--gold);
}
.checkbox-label.small a { color: var(--gold-dark); }

.login-card button { width: 100%; margin-top: 8px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.modal-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 28px;
  max-width: 460px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-card h2 {
  font-family: Georgia, "Iowan Old Style", ui-serif, serif;
  font-size: 20px;
  font-weight: 500;
  margin: 0 0 16px;
  color: var(--text);
}
.modal-body { font-size: 14px; line-height: 1.6; color: var(--text); }
.modal-body p { margin: 0 0 12px; }
.modal-card button { width: 100%; margin-top: 12px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.brand-mark { width: 32px; height: 32px; }
.brand-word {
  font-family: Georgia, "Iowan Old Style", ui-serif, serif;
  font-size: 22px;
  letter-spacing: 0.02em;
  color: var(--text);
}

.muted { color: var(--text-muted); font-size: 14px; margin: 4px 0 0; }
.error { color: #A32D2D; font-size: 14px; min-height: 18px; }

input[type="password"], input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  margin: 16px 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--ink);
  color: var(--gold);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
button:hover { opacity: 0.9; }

/* ---------- Coquille avec menu latéral (identique à l'admin) ---------- */

.app-shell {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 0.5px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 20px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-spacer { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--nav-hover-bg); opacity: 1; }
.nav-item.active { background: var(--nav-active-bg); color: var(--ink-on-gold); font-weight: 500; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 6px 10px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
.conversation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conversation-item:hover { background: var(--nav-hover-bg); opacity: 1; color: var(--text); }
.conversation-item.new-conversation { color: var(--gold-dark); font-weight: 500; width: 100%; flex: none; }
.conversation-item .nav-icon { width: 14px; height: 14px; }

.conversation-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 6px;
}
.conversation-row.active .conversation-item {
  background: var(--nav-hover-bg);
  color: var(--text);
  font-weight: 500;
}
.conversation-delete {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
}
.conversation-row:hover .conversation-delete { display: flex; }
.conversation-delete:hover { background: var(--danger-tint, rgba(163,45,45,0.12)); color: #A32D2D; opacity: 1; }
.conversation-delete .nav-icon { width: 14px; height: 14px; }

.clarification-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  max-width: 90%;
  margin-top: -4px;
}
.clarification-chip {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold-dark);
  font-size: 13px;
  font-weight: 500;
  width: auto;
  white-space: nowrap;
}
.clarification-chip:hover { background: var(--gold); color: var(--ink); opacity: 1; }

/* ---------- Zone de chat ---------- */

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

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
}
.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}
.bubble.ai {
  align-self: flex-start;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble.sources {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.bubble.empty-hint {
  align-self: center;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  max-width: 90%;
  margin-top: 24px;
}

#chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
}
#chat-form input { margin: 0; flex: 1; }
#chat-form button { flex-shrink: 0; background: var(--gold); color: var(--ink); }
#chat-form button:hover { background: var(--gold-dark); }

/* ---------- Repli en barre horizontale sur petit écran (smartphone) ---------- */

@media (max-width: 640px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 8px 10px;
    border-right: none;
    border-bottom: 0.5px solid var(--border);
    gap: 2px;
  }
  .sidebar-brand { padding: 4px 8px; margin-right: 4px; }
  .sidebar-brand .brand-word { display: none; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .nav-item { width: auto; padding: 8px 10px; font-size: 13px; }
  .sidebar-spacer { display: none; }
  #theme-toggle span, #logout-btn { font-size: 0; }
  #theme-toggle span { display: none; }
  #logout-btn .nav-icon { margin: 0; }

  .conversation-list {
    flex-basis: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-left: none;
    border-top: 0.5px solid var(--border);
    margin: 6px 0 0;
    padding: 6px 0 0;
  }
  .conversation-item { width: auto; flex-shrink: 0; max-width: 130px; }
  .conversation-row { flex-shrink: 0; }
  .conversation-delete { display: flex; }
}
