:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #21252e;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #ff7a59;
  --accent-strong: #ff5722;
  --user-bubble: #2b3140;
  --assistant-bubble: #1e2230;
  --error: #ff6b6b;
  --sidebar-w: 320px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0c0e13;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 0 4px;
}
.sidebar-header h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.sidebar-header button {
  margin: 0;
  padding: 2px 10px;
  width: auto;
  font-size: 18px;
  line-height: 1;
}

.search-input {
  width: 100%;
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
}
.search-input::-webkit-search-cancel-button { cursor: pointer; }

.conversations {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conversations li {
  border-radius: 8px;
  cursor: pointer;
  padding: 10px 12px;
  color: var(--text);
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.conversations li:hover { background: var(--surface-2); }
.conversations li.active {
  background: #2a2f3a;
}
.conv-icon {
  font-size: 13px;
  opacity: 0.75;
  flex-shrink: 0;
}
.conv-delete {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: opacity 0.1s, background 0.1s;
}
.conversations li:hover .conv-delete,
.conversations li.active .conv-delete {
  opacity: 0.6;
}
.conv-delete:hover {
  background: rgba(255, 107, 107, 0.15);
  opacity: 1;
}
@media (hover: none) {
  .conv-delete { opacity: 0.55; }
}
.conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}
.conv-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 8px;
}

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 48px 24px 96px;
  width: 100%;
}

header h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 32px;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 20px;
}

.hidden { display: none !important; }

/* Upload */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 36px 20px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: #20242e;
}
.dropzone-icon { font-size: 28px; }
.dropzone-label { font-weight: 500; }
.dropzone-hint { color: var(--muted); font-size: 13px; }
.dropzone-filename { color: var(--accent); font-size: 13px; margin-top: 4px; }

button {
  margin-top: 16px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #1a1308;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
button:hover:not(:disabled) { background: var(--accent-strong); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:active:not(:disabled) { transform: translateY(1px); }

button.ghost {
  margin: 0;
  width: auto;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
}
button.ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}
button.ghost.danger:hover:not(:disabled) {
  color: var(--error);
  border-color: var(--error);
}

.status {
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
  min-height: 20px;
}
.status.error { color: var(--error); }

.separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 14px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.separator::before,
.separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

#url-form {
  display: flex;
  gap: 8px;
}
#url-form input {
  flex: 1;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14.5px;
}
#url-form input:focus {
  outline: none;
  border-color: var(--accent);
}
#url-form button {
  margin-top: 0;
  width: auto;
  padding: 0 18px;
  white-space: nowrap;
}

.hint {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.result-header h2 {
  margin: 0;
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 16px;
  font-size: 14.5px;
}

.meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12.5px;
}

/* Markdown rendering */
.markdown p { margin: 0.6em 0; }
.markdown ul, .markdown ol { padding-left: 1.4em; margin: 0.6em 0; }
.markdown li { margin: 0.2em 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
  margin: 0.8em 0 0.4em;
  line-height: 1.25;
}
.markdown h1 { font-size: 1.3em; }
.markdown h2 { font-size: 1.18em; }
.markdown h3 { font-size: 1.08em; }
.markdown h4 { font-size: 1em; }
.markdown code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}
.markdown pre {
  background: #0c0e13;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}
.markdown pre code { background: transparent; padding: 0; }
.markdown a { color: var(--accent); }
.markdown blockquote {
  margin: 0.6em 0;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.markdown strong { color: #fff; }
.markdown table {
  border-collapse: collapse;
  margin: 0.6em 0;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}

/* Chat */
.chat-card h2 { margin: 0 0 14px; font-size: 20px; }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 480px;
  min-height: 120px;
  overflow-y: auto;
  padding: 8px 4px;
  margin-bottom: 14px;
}
.chat-log:empty::before {
  content: "Pose une question pour commencer…";
  color: var(--muted);
  font-size: 13px;
  padding: 12px 8px;
}

.bubble {
  max-width: 85%;
  padding: 6px 14px;
  border-radius: 12px;
  word-wrap: break-word;
  font-size: 14.5px;
}
.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
  padding: 10px 14px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border-bottom-left-radius: 4px;
}
.bubble.assistant.thinking {
  color: var(--muted);
  font-style: italic;
  padding: 10px 14px;
}
.bubble.assistant.error {
  color: var(--error);
  padding: 10px 14px;
}

.chat-form {
  display: flex;
  gap: 8px;
}
.chat-form input {
  flex: 1;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14.5px;
}
.chat-form input:focus {
  outline: none;
  border-color: var(--accent);
}
.chat-form button {
  margin-top: 0;
  width: auto;
  padding: 0 18px;
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
  }
  .container { padding: 24px 16px 64px; }
}

/* ── Login page ────────────────────────────────────── */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-container {
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}
.login-card .subtitle {
  margin: 0 0 18px;
  font-size: 13.5px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field span {
  font-size: 13px;
  color: var(--muted);
}
.field input {
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14.5px;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-card .error {
  margin: 12px 0 0;
  color: var(--error);
  font-size: 13.5px;
  min-height: 18px;
}

/* ── Footer of sidebar (logout) ───────────────────── */
.sidebar-footer {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-footer form {
  margin: 0;
}
.sidebar-footer button {
  margin: 0;
  width: 100%;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
}
.sidebar-footer button:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}
