:root {
  color-scheme: light dark;
  --accent: #d64545;
  --border: #d0d0d0;
  --bg-soft: #f5f5f5;
  --bg-page: #ffffff;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  line-height: 1.5;
  background: var(--bg-page);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.topbar nav { display: flex; gap: 1rem; align-items: center; }
.brand { font-weight: 700; text-decoration: none; color: inherit; }
.user-badge { opacity: 0.7; font-size: 0.9rem; }

main { max-width: 720px; margin: 2rem auto; padding: 0 1rem; width: 100%; }

/* --- Pages d'administration : colonne large + navigation latérale, cohérent sur toutes les pages --- */
body.admin-page main {
  max-width: 1150px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  width: 100%;
}
.admin-shell { display: flex; gap: 2.5rem; align-items: flex-start; }
.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 190px;
  flex-shrink: 0;
  position: sticky;
  top: 1.5rem;
}
.admin-nav a {
  padding: 0.55rem 0.8rem;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  font-size: 0.95rem;
}
.admin-nav a:hover { background: var(--bg-soft); }
.admin-content { flex: 1; min-width: 0; }
.admin-content h1 { margin-top: 0; }
.admin-content section { margin-bottom: 2.5rem; }
.admin-content section h2 { font-size: 1.1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }

@media (max-width: 800px) {
  .admin-shell { flex-direction: column; }
  .admin-nav { flex-direction: row; position: static; width: 100%; overflow-x: auto; }
}

/* --- Page de chat : disposition pleine hauteur, colonne large, façon claude.ai --- */
body.chat-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
body.chat-page main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-shell { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 2rem 0 1rem;
}

.empty-state { text-align: center; margin: auto; }
.empty-state h1 { margin-bottom: 0.5rem; }

.msg { max-width: 85%; padding: 0.9rem 1.2rem; border-radius: 16px; line-height: 1.55; }
.msg p:first-child { margin-top: 0; }
.msg p:last-child { margin-bottom: 0; }
.msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}
.msg-assistant {
  align-self: flex-start;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  width: 100%;
  max-width: 100%;
}
.msg-warning { border-left: 4px solid #b08900; }
.msg-error { border-left: 4px solid var(--accent); }
.msg-success { border-left: 4px solid #2a8f4f; }
.msg-result { border-left: 4px solid #2a6fb0; }

.composer { padding: 1rem 0 1.75rem; }
.composer-form {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 0.4rem 0.4rem 0.4rem 1.3rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}
.composer-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-family: inherit;
  padding: 0.6rem 0;
  resize: none;
  max-height: 220px;
  overflow-y: hidden;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.4;
  text-align: left;
}
.composer-input:focus { outline: none; }
.composer-form button {
  border-radius: 999px;
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* --- Cartes (login, admin) --- */
.card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}
.card.narrow { max-width: 420px; margin: 3rem auto; }

form { display: flex; flex-direction: column; gap: 0.75rem; margin: 1rem 0; }
form.inline-form { display: inline; margin: 0.25rem 0.5rem 0.25rem 0; }
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; }
input[type="text"], input[type="email"] {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
}
button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 0.95rem;
  width: fit-content;
}
button.danger { background: #444; }
button.link-button { background: none; color: inherit; text-decoration: underline; padding: 0; }
.button-google {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  text-decoration: none;
  font-size: 0.95rem;
}

.box { border: 1px solid var(--border); border-radius: 6px; padding: 1rem; margin: 1rem 0; background: var(--bg-soft); }
.box-row { flex-direction: row; align-items: center; justify-content: space-between; }
.box-question { border-left: 4px solid #b08900; }
.box-warning { border-left: 4px solid #b08900; }
.box-error { border-left: 4px solid var(--accent); }
.box-success { border-left: 4px solid #2a8f4f; }
.box-result { border-left: 4px solid #2a6fb0; }

.answer { font-size: 1.15rem; font-weight: 600; }
.muted { opacity: 0.65; font-size: 0.9rem; }
.sql-block { background: #1e1e1e; color: #d4d4d4; padding: 0.75rem; border-radius: 6px; overflow-x: auto; font-size: 0.85rem; }
.rows { max-height: 260px; overflow-y: auto; padding-left: 1.2rem; }

.table-scroll { overflow-x: auto; margin: 0.75rem 0; max-height: 400px; overflow-y: auto; }
.result-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.result-table th, .result-table td { padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.result-table th { font-weight: 600; background: var(--bg-soft); position: sticky; top: 0; }

.textarea-mono { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.sql-tools-form { margin: 0.5rem 0; }
.sql-edit {
  width: 100%;
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 0.75rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

/* --- Indicateur de chargement --- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.45);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  z-index: 1000;
  color: white;
}
#loading-overlay.visible { display: flex; }
#loading-overlay p { margin: 0; font-size: 0.95rem; }
.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-color-scheme: dark) {
  :root { --border: #444; --bg-soft: #2a2a2a; --bg-page: #1a1a1a; }
  body { color: #eee; }
  input[type="text"], input[type="email"] { background: #2a2a2a; color: #eee; }
  .composer-form { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); }
}
