/* =============================================================
   ASSOC-IA — CHAT SITE (chat.assoc-ia.fr)
   Interface épurée pour les adhérents qui veulent juste discuter
   avec l'IA, sans passer par le portail admin complet.
   ============================================================= */
:root {
  --bg: #FCFCFC;
  --surface: #FFFFFF;
  --sidebar-bg: #F6F6F4;
  --text: #0D0D0D;
  --text-secondary: #4B4B4B;
  --text-tertiary: #8A8A8A;
  --border: #E4E4E4;
  --border-strong: #D6D6D6;
  --accent-gold: #FFD700;
  --accent-gold-text: #7A5C00;
  --accent-gold-wash: rgba(255, 215, 0, 0.10);
  --radius-micro: 4px;
  --radius-standard: 8px;
  --radius-large: 16px;
  --radius-pill: 999px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --header-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

a:focus-visible, button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: var(--radius-micro);
}

/* ---------- Logo ---------- */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 44px;
  padding: 0 6px 0 2px;
  border-radius: var(--radius-standard);
  text-decoration: none;
  color: var(--text);
}
.logo svg { width: 26px; height: 26px; display: block; flex-shrink: 0; }
.logo-text { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.logo-accent { color: var(--accent-gold-text); }

/* ---------- Boutons pilule ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-pill);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
.btn-outline { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-outline:hover { background: #F5F5F5; }
.btn-filled { background: var(--text); color: var(--surface); border: 1px solid var(--text); }
.btn-filled:hover { background: #262626; border-color: #262626; }
.btn-block { width: 100%; height: 44px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Champs de formulaire ---------- */
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.field input {
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-standard);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  width: 100%;
}
.field input::placeholder { color: var(--text-tertiary); }
.field input:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.field-hint { font-size: 12px; color: var(--text-tertiary); margin: 2px 0 0; text-align: left; }

.disclaimer { margin: 20px 0 0; max-width: 520px; font-size: 13px; line-height: 1.6; color: var(--text-tertiary); }
.link { color: var(--accent-gold-text); text-decoration: none; border-bottom: 1px solid transparent; }
.link:hover { border-bottom-color: var(--accent-gold-text); }

.error-banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: #FDECEC;
  border: 1px solid #F3B9B9;
  border-radius: var(--radius-standard);
  color: #8A1F1F;
  font-size: 13px;
  text-align: left;
}

/* ---------- Pages d'authentification ---------- */
.auth-body { min-height: 100vh; display: flex; flex-direction: column; }
.site-header { height: var(--header-height); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.auth-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 20px 64px; }
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card .logo { justify-content: center; margin: 0 auto 24px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.auth-card .subtitle { margin: 0 0 28px; font-size: 14px; color: var(--text-tertiary); }
form.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-footnote { margin-top: 24px; font-size: 14px; color: var(--text-secondary); }
.auth-legal { margin: 32px auto 0; text-align: center; }

/* ---------- Application de chat ---------- */
html.chat-app, body.chat-app { height: 100%; overflow: hidden; }
.app-shell { display: flex; height: 100vh; }

.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  padding: 12px;
}
.sidebar-header { display: flex; align-items: center; padding: 4px 4px 14px; }
.sidebar-header .logo { height: 36px; }
.sidebar-header .logo svg { width: 22px; height: 22px; }
.sidebar-header .logo-text { font-size: 14px; }

.new-chat-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 40px; padding: 0 12px;
  border-radius: var(--radius-standard); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-family: var(--font); font-size: 14px; font-weight: 500; cursor: pointer;
  margin-bottom: 16px; text-decoration: none; transition: background-color 150ms ease;
}
.new-chat-btn:hover { background: #EFEFEC; }
.new-chat-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.conv-scroll { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.conv-empty { font-size: 12px; color: var(--text-tertiary); text-align: center; padding: 24px 8px; }
.conv-item-row { display: flex; align-items: center; gap: 2px; }
.conv-item {
  display: block; flex: 1; min-width: 0; text-align: left; padding: 9px 10px; border: none;
  border-radius: var(--radius-standard); background: transparent; font-family: var(--font); font-size: 14px;
  color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; transition: background-color 150ms ease;
}
.conv-item:hover { background: #ECECE9; }
.conv-item.active { background: var(--surface); border: 1px solid var(--border-strong); font-weight: 500; padding: 8px 9px; }
.conv-delete {
  flex-shrink: 0; width: 26px; height: 26px; border: none; background: transparent; border-radius: var(--radius-micro);
  color: var(--text-tertiary); cursor: pointer; opacity: 0; transition: opacity 150ms ease, color 150ms ease;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.conv-item-row:hover .conv-delete { opacity: 1; }
.conv-delete:hover { color: #B42318; }

.sidebar-footer { border-top: 1px solid var(--border-strong); padding-top: 10px; margin-top: 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: none; background: transparent; border-radius: var(--radius-standard); text-align: left; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--text); color: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-org { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-logout { flex-shrink: 0; font-size: 12px; color: var(--text-tertiary); text-decoration: none; }
.user-logout:hover { color: var(--text); }

.main-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 16px; flex-shrink: 0; }
.menu-toggle { display: none; }
.topbar h2 { margin: 0; font-size: 14px; font-weight: 500; color: var(--text-secondary); }

.messages { flex: 1; overflow-y: auto; padding: 8px 20px 24px; }
.messages-inner { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

.message.user { display: flex; justify-content: flex-end; }
.message.user .bubble { max-width: 75%; background: var(--sidebar-bg); border: 1px solid var(--border); border-radius: var(--radius-large); padding: 12px 16px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; }

.message.assistant { display: flex; gap: 12px; align-items: flex-start; }
.message.assistant .avatar { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: var(--text); font-size: 13px; }
.message.assistant .bubble { font-size: 15px; line-height: 1.65; padding-top: 3px; max-width: 75ch; }
.message.assistant .bubble.error { color: #B42318; }
.message.assistant .bubble p { margin: 0 0 12px; }
.message.assistant .bubble p:last-child { margin-bottom: 0; }

.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 20px; }
.empty-state[hidden], .messages[hidden] { display: none; }
.empty-state-inner { width: 100%; max-width: 640px; text-align: center; }
.empty-state-inner h1 { margin: 0 0 8px; font-size: clamp(22px, 4vw, 28px); font-weight: 600; letter-spacing: -0.01em; }
.empty-state-inner p { color: var(--text-tertiary); font-size: 14px; margin: 0; }

.composer-dock { flex-shrink: 0; padding: 4px 20px 20px; }
.composer-dock-inner { max-width: 720px; margin: 0 auto; }
.composer-dock .disclaimer { text-align: center; margin: 10px auto 0; font-size: 12px; max-width: none; }

.composer { width: 100%; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-large); padding: 14px 14px 10px; text-align: left; }
.composer textarea { width: 100%; resize: none; border: none; outline: none; background: transparent; font-family: var(--font); font-size: 16px; line-height: 1.5; color: var(--text); max-height: 200px; min-height: 24px; padding: 2px 4px 10px; }
.composer textarea::placeholder { color: var(--text-tertiary); }
.composer-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 6px; }

.tier-switch { display: flex; gap: 4px; flex-wrap: wrap; }
.tier-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.tier-btn:hover { background: #F5F5F5; }
.tier-btn.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.tier-btn .tier-price { opacity: 0.65; font-size: 10px; margin-left: 3px; }
@media (max-width: 640px) { .tier-btn { font-size: 11px; padding: 0 9px; } .tier-btn .tier-price { display: none; } }

.send-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: var(--radius-pill); border: 1px solid var(--text); background: var(--text); color: var(--surface); cursor: pointer; transition: opacity 150ms ease, background-color 150ms ease; }
.send-btn svg { width: 16px; height: 16px; }
.send-btn:disabled { background: var(--surface); border-color: var(--border-strong); color: var(--text-tertiary); cursor: not-allowed; }
.send-btn:not(:disabled):hover { background: #262626; }

.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform 200ms ease; }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); box-shadow: 8px 0 24px rgba(0,0,0,0.10); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.25); opacity: 0; pointer-events: none; transition: opacity 200ms ease; z-index: 30; }
  .app-shell.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius-pill); border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; }
  .messages, .empty-state { padding-left: 14px; padding-right: 14px; }
  .composer-dock { padding-left: 14px; padding-right: 14px; }
  .message.assistant .bubble { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
