:root {
  /* Palette alignée sur polarsite */
  --bg: #080f1e;
  --bg-2: #0d1828;
  --panel: #0d1828;
  --panel-2: #102030;
  --border: rgba(96, 165, 250, 0.18);
  --border-2: rgba(96, 165, 250, 0.3);
  --text: #e8f2ff;
  --muted: #7a91ae;
  --accent: #60a5fa;
  --accent-dark: #3b82f6;
  --accent-2: #22d3ee;
  --user-bubble: #16243d;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: "Outfit", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.accent { color: var(--accent); }

.app { display: flex; height: 100vh; position: relative; }

/* ---------- Logo ---------- */
.logo-img { width: 28px; height: 28px; object-fit: contain; }
.logo-text { font-weight: 900; letter-spacing: 2px; font-size: 1.15rem; }
.logo-text .lt-polar { color: var(--accent); }
.logo-text .lt-ai { color: #fff; }

/* ---------- Rail latéral (façon Gemini, sans fond) ---------- */
.rail {
  width: 60px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
}
.rail-logo { display: block; margin-bottom: 6px; }
.rail-logo img { width: 30px; height: 30px; object-fit: contain; }
.rail-btn {
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 12px;
  color: var(--muted); cursor: pointer;
  transition: color .15s, background .15s;
}
.rail-btn:hover { color: var(--text); background: rgba(96, 165, 250, 0.12); }

/* Panneau de recherche de conversations */
.search-panel {
  position: absolute;
  top: 16px; left: 68px;
  width: 300px;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  padding: 10px;
  z-index: 30;
}
.search-panel[hidden] { display: none; }
#searchInput {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit; font-size: .92rem;
  outline: none;
  margin-bottom: 8px;
}
#searchInput::placeholder { color: var(--muted); }
#searchInput:focus { border-color: var(--accent); }
.search-panel .convos { overflow-y: auto; padding: 0; gap: 2px; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 270px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left .25s ease;
}
.sidebar.hidden { margin-left: -270px; }

.sidebar-head { padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; text-decoration: none; }
.home-link {
  display: block;
  font-size: .82rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 14px;
  transition: color .15s;
}
.home-link:hover { color: var(--accent); }

.new-chat {
  width: 100%;
  padding: 11px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-weight: 700;
  font-size: .92rem;
  cursor: pointer;
  transition: transform .12s, box-shadow .2s;
}
.new-chat:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(96,165,250,.3); }

.convos {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.convo {
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid transparent;
  transition: background .15s;
}
.convo:hover { background: var(--panel-2); color: var(--text); }
.convo.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  background: transparent;
}
.icon-btn {
  background: none; border: none; color: var(--muted);
  font-size: 1.3rem; cursor: pointer; line-height: 1;
}
.icon-btn:hover { color: var(--text); }
.title { font-weight: 700; }
.title .sub { color: var(--muted); font-weight: 400; font-size: .9rem; }
.status { margin-left: auto; font-size: .8rem; color: var(--muted); }

/* ---------- Messages (style Gemini) ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 0;
  scroll-behavior: smooth;
}
.msg-row { width: 100%; padding: 10px 20px; }
.msg {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
}

/* Utilisateur : aligné à droite, en bulle */
.msg.is-user { justify-content: flex-end; }
.msg.is-user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 16px;
  max-width: 80%;
}

/* IA : aligné à gauche, texte plein sans bulle */
.msg.is-ai .bubble {
  width: 100%;
  padding: 2px 0;
}

.bubble { min-width: 0; }
.bubble .content {
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text);
}
.bubble .content code {
  background: rgba(96,165,250,0.12);
  padding: 2px 6px; border-radius: 5px;
  font-family: ui-monospace, monospace; font-size: .9em;
}
.bubble .content pre {
  background: #0b1422;
  padding: 12px 14px; border-radius: 10px;
  overflow-x: auto; margin: 8px 0;
  border: 1px solid var(--border);
}
.bubble .content pre code { background: none; padding: 0; }

.msg-img {
  display: block;
  max-width: 320px;
  width: 100%;
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

/* Lightbox (image agrandie) */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: zoom-out;
  padding: 24px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 12px;
  box-shadow: 0 20px 80px #000;
}

/* curseur de frappe */
.cursor {
  display: inline-block; width: 7px; height: 1.05em;
  background: var(--accent); vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite; margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* points "en train d'écrire" */
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-5px);opacity:1} }

/* ---------- Welcome ---------- */
.welcome { max-width: 720px; margin: 60px auto; text-align: center; padding: 0 20px; }
.welcome h1 { font-size: 2rem; font-weight: 800; margin-bottom: 12px; }
.welcome p { color: var(--muted); max-width: 480px; margin: 0 auto 30px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.suggestion {
  text-align: left;
  padding: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: .92rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, transform .12s;
}
.suggestion:hover { border-color: var(--accent); transform: translateY(-2px); }

/* ---------- Composer ---------- */
.composer {
  background: transparent;
  padding: 16px 20px 12px;
}
.composer-form {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 12px;
  transition: border-color .15s;
}
.composer-form:focus-within { border-color: var(--accent); }
#input {
  flex: 1;
  background: none; border: none; outline: none;
  color: var(--text); resize: none;
  font-family: inherit; font-size: 1rem; line-height: 1.5;
  max-height: 200px; padding: 6px 0;
}
#input::placeholder { color: var(--muted); }
.send-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  border: none; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; font-size: 1.1rem; cursor: pointer;
  transition: transform .12s, opacity .2s;
}
.send-btn:hover { transform: translateY(-1px); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* Bouton joindre une image */
.attach-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--panel); color: var(--muted);
  font-size: 1.3rem; line-height: 1; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.attach-btn:hover { color: var(--text); border-color: var(--accent); }

/* Aperçu de l'image jointe */
.attach-preview {
  max-width: 760px; margin: 0 auto 10px;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 12px;
}
.attach-preview[hidden] { display: none; }
.attach-preview img {
  width: 44px; height: 44px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border);
}
.attach-name {
  flex: 1; color: var(--muted); font-size: .85rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attach-remove {
  background: none; border: none; color: var(--muted);
  font-size: 1rem; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.attach-remove:hover { color: var(--accent); background: var(--panel); }

.disclaimer { max-width: 760px; margin: 8px auto 0; text-align: center; font-size: .75rem; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .sidebar { position: absolute; z-index: 20; height: 100%; box-shadow: 4px 0 30px #000a; }
  .suggestions { grid-template-columns: 1fr; }
}
