:root {
  --bg: #0f1115;
  --bg-panel: #171a21;
  --bg-input: #1f242e;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-dim: #9aa3b2;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --user-bubble: #2b3b5c;
  --assistant-bubble: #1f242e;
  --danger: #ff6b6b;
  --ok: #3ddc84;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.hidden { display: none !important; }
.error { color: var(--danger); font-size: 0.9em; }

/* --- Écran de connexion --- */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: min(360px, 90vw);
}
.login-card h1 { font-size: 1.2rem; margin: 0 0 20px; }
.login-card label { display: block; margin-bottom: 6px; color: var(--text-dim); font-size: 0.85rem; }
.login-card input {
  width: 100%; padding: 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-input); color: var(--text);
  margin-bottom: 14px; font-size: 1rem;
}
.login-card button {
  width: 100%; padding: 10px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 1rem; cursor: pointer;
}
.login-card button:hover { background: var(--accent-hover); }

/* --- Barre supérieure --- */
#app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; }
.topbar button {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 0.9rem;
}
.topbar button:hover { background: var(--bg-input); }
.topbar-left, .topbar-right { display: flex; gap: 8px; align-items: center; }
.sync-indicator {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim); display: inline-block;
}
.sync-indicator.online { background: var(--ok); }
.sync-indicator.offline { background: var(--danger); }

/* --- Disposition --- */
.layout { flex: 1; display: flex; overflow: hidden; }
.sidebar {
  width: 280px; background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto; padding: 12px;
}
.side-section h2 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-dim); margin: 14px 0 8px;
}
.convo-list { list-style: none; margin: 0; padding: 0; }
.convo-list li {
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.convo-list li:hover { background: var(--bg-input); }
.convo-list li .date { color: var(--text-dim); font-size: 0.75rem; }
#memory-search {
  width: 100%; padding: 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-input); color: var(--text);
}
.memory-results { list-style: none; margin: 8px 0 0; padding: 0; }
.memory-results li { padding: 6px 8px; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.memory-results li .title { color: var(--accent); }
.memory-results li .snippet { color: var(--text-dim); }

/* --- Chat --- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.message { max-width: min(720px, 90%); display: flex; flex-direction: column; }
.message .bubble {
  padding: 10px 14px; border-radius: 14px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.message.user { align-self: flex-start; }
.message.user .bubble { background: var(--user-bubble); border-bottom-left-radius: 4px; }
.message.assistant { align-self: flex-start; }
.message.assistant .bubble { background: var(--assistant-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.message.error .bubble { background: #3a2226; border-color: var(--danger); }

/* Rendu markdown simple */
.bubble h1, .bubble h2, .bubble h3 { margin: 0.6em 0 0.3em; font-size: 1.05rem; }
.bubble h1 { font-size: 1.15rem; }
.bubble ul, .bubble ol { margin: 0.3em 0; padding-left: 1.3em; }
.bubble li { margin: 0.15em 0; }
.bubble p { margin: 0.35em 0; }
.bubble code { background: #0d1117; padding: 1px 5px; border-radius: 5px; font-size: 0.88em; }
.bubble pre { background: #0d1117; padding: 10px; border-radius: 8px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble blockquote { border-left: 3px solid var(--accent); margin: 0.4em 0; padding-left: 12px; color: var(--text-dim); }
.bubble table { border-collapse: collapse; margin: 0.4em 0; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 9px; }
.bubble a { color: var(--accent); }

/* Blocs interactifs */
.block {
  margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px;
}
.block button {
  background: var(--bg-input); border: 1px solid var(--accent); color: var(--text);
  border-radius: 20px; padding: 7px 14px; cursor: pointer; font-size: 0.9rem;
}
.block button:hover { background: var(--accent); color: #fff; }
.block button.primary { background: var(--accent); color: #fff; }
.block .block-extra { width: 100%; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.block input[type=date], .block input[type=time], .block input[type=number], .block select {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px; font-size: 0.9rem;
}
.block .slider-row { display: flex; align-items: center; gap: 8px; width: 100%; }
.block input[type=range] { flex: 1; }
.block .compose-box {
  width: 100%; background: #0d1117; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; font-size: 0.85rem; white-space: pre-wrap;
}
.block .file-input { color-scheme: dark; }

.status-line {
  min-height: 20px; padding: 0 20px; color: var(--text-dim); font-size: 0.85rem;
}
.status-line .tool { display: inline-block; margin-right: 8px; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }

.input-bar {
  display: flex; gap: 8px; padding: 12px 20px;
  border-top: 1px solid var(--border); background: var(--bg-panel);
}
#message-input {
  flex: 1; resize: none; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  font-size: 1rem; font-family: inherit; max-height: 150px;
}
#message-input:focus { outline: 2px solid var(--accent); }
#btn-send {
  width: 46px; border: none; border-radius: 12px; background: var(--accent);
  color: #fff; font-size: 1.2rem; cursor: pointer;
}
#btn-send:hover { background: var(--accent-hover); }
#btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

.typing { color: var(--text-dim); font-style: italic; }
@media (max-width: 720px) {
  .sidebar { position: fixed; left: 0; top: 48px; bottom: 0; z-index: 10; }
}
