:root {
  --bg:          var(--pw-bg-2, #0f0a1a);
  --surface:     var(--surface-solid, #161028);
  --fg:          var(--pw-text, #e8eef8);
  --muted:       var(--pw-muted, rgba(196, 181, 220, 0.72));
  --border:      var(--pw-border, rgba(120, 80, 180, 0.28));
  --accent:      var(--pw-cyan, #a78bfa);
  --accent-2:    #c4b5fd;
  --accent-bg:   rgba(167, 139, 250, 0.16);
  --bubble-ai:   #152238;
  --bubble-user: #9333ea;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; background: var(--shell-bg, #06040c); }

body.chat-page {
  font-family: 'Inter', sans-serif;
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.chat-app {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 24px);
}

/* ── Mode bar (sous la nav) ── */
.chat-mode-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--surface-solid);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 9;
}

.chat-mode-info {
  flex: 1;
  min-width: 0;
}

/* ── Header legacy (titres mode) ── */
.chat-header {
  display: none;
}

.back-btn {
  display: none;
}

.header-title {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 16px;
  font-weight: 500;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 1px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-bg);
  border: 1px solid rgba(124, 58, 237, 0.28);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
  position: relative;
}

.mode-btn:hover { background: rgba(124, 58, 237, 0.14); }

.mode-btn-label {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.mode-btn-icon { font-size: 14px; }
.mode-btn-arrow { font-size: 10px; color: var(--accent); opacity: 0.7; }

/* ── Mode dropdown ── */
.mode-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(18,50,56,0.12);
  z-index: 100;
  overflow: hidden;
  min-width: 220px;
  display: none;
  animation: dropIn 0.18s ease;
}

.mode-dropdown.open { display: block; }

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-title {
  padding: 12px 16px 8px;
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid var(--border);
  width: 100%;
  border-left: none;
  border-right: none;
  border-top: none;
  background: transparent;
  text-align: left;
  font: inherit;
}

.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--accent-bg); }
.dropdown-item.active { background: var(--accent-bg); }

.dropdown-item-icon { font-size: 16px; width: 20px; text-align: center; }
.dropdown-item-text { flex: 1; }
.dropdown-item-name { font-size: 13px; font-weight: 500; color: var(--fg); }
.dropdown-item-desc { font-size: 11px; color: var(--muted); margin-top: 1px; }
.dropdown-item-check { color: var(--accent); font-size: 14px; }
.dropdown-item-premium {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #c084fc;
  border: 1px solid rgba(192, 132, 252, 0.35);
  border-radius: 999px;
  vertical-align: middle;
}

.dropdown-item-essentiel {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #ddd6fe;
  border: 1px solid rgba(196, 181, 253, 0.4);
  border-radius: 999px;
  vertical-align: middle;
}

/* ── Banner ── */
.chat-banner {
  padding: 8px 14px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--fg);
  background: rgba(124, 58, 237, 0.12);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-banner[hidden] { display: none; }
.chat-banner a { color: var(--accent-2); }

/* ── Messages ── */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 0; }

.day-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
}

.day-sep::before, .day-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.day-sep-text {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  white-space: nowrap;
}

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: msgIn 0.25s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.user { align-items: flex-end; }
.msg-row.ai   { align-items: flex-start; }

.bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 20px;
  font-size: 14.5px;
  line-height: 1.6;
  position: relative;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.user .bubble {
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg-row.ai .bubble {
  background: var(--bubble-ai);
  color: var(--fg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 12px rgba(18,50,56,0.05);
}

.msg-row.ai .bubble::before {
  content: '';
  position: absolute;
  left: 0;
  top: 16px;
  bottom: 16px;
  width: 3px;
  background: linear-gradient(to bottom, var(--accent), var(--accent-2));
  border-radius: 0 2px 2px 0;
  opacity: 0.4;
}

.bubble-time {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  padding: 0 4px;
  opacity: 0.7;
}

.cursor {
  display: inline-block;
  width: 2px;
  height: 15px;
  background: var(--accent);
  border-radius: 2px;
  margin-left: 2px;
  vertical-align: middle;
  animation: blink 0.75s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

.typing-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: msgIn 0.2s ease;
}

.typing-bubble {
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  border-radius: 20px;
  border-bottom-left-radius: 6px;
  padding: 14px 18px;
  display: flex;
  gap: 5px;
  align-items: center;
  box-shadow: 0 2px 12px rgba(18,50,56,0.05);
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: typingPulse 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50%       { opacity: 1;   transform: scale(1.25); }
}

.mode-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--accent-bg);
  border: 1px solid rgba(124, 58, 237, 0.28);
  border-radius: 999px;
  align-self: center;
  animation: msgIn 0.25s ease;
}

.mode-notice-text {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── Input bar ── */
.input-bar {
  padding: 12px 14px 20px;
  background: rgba(244, 247, 250, 0.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 10px 14px;
  transition: border-color 0.2s;
  gap: 8px;
}

.input-wrap:focus-within {
  border-color: rgba(139,92,246,0.4);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.08);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: 'Inter', sans-serif;
  font-size: 14.5px;
  color: var(--fg);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  min-height: 22px;
}

.chat-input::placeholder { color: var(--muted); opacity: 0.7; }

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--btn-radius, 14px);
  background: linear-gradient(135deg, #e879f9 0%, #9333ea 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
  box-shadow: var(--btn-shadow, 0 4px 20px rgba(168, 85, 247, 0.28));
}

.send-btn:hover   { transform: translateY(-1px); box-shadow: var(--btn-shadow-hover, 0 8px 28px rgba(168, 85, 247, 0.4)); }
.send-btn:active  { transform: scale(0.96); }
.send-btn:disabled { background: var(--border); box-shadow: none; cursor: default; transform: none; }
.send-btn svg { width: 18px; height: 18px; fill: #ffffff; }

.char-count {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  padding-bottom: 2px;
  opacity: 0.6;
  align-self: flex-end;
}

.quota-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(139,92,246,0.05);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.quota-text {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.quota-accent {
  color: var(--accent);
  font-size: 10px;
}

.quota-dots { display: flex; gap: 3px; }

.qdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
}

.qdot.used { opacity: 1; }
