/* ===========================================================================
   Formation SQL — thème clair/sombre via [data-theme] sur <html>
   =========================================================================== */
:root {
  --bg: #f7f8fa;
  --bg-elev: #ffffff;
  --bg-code: #f0f2f5;
  --border: #e2e6ec;
  --text: #1c2430;
  --text-soft: #5a6573;
  --accent: #2f6df6;
  --accent-soft: #e7eefe;
  --ok: #1a9d63;
  --err: #d6334c;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08), 0 4px 16px rgba(20, 30, 50, 0.06);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Menlo, Consolas, monospace;
  --console-h: 42vh;
}
[data-theme="dark"] {
  --bg: #0f141b;
  --bg-elev: #161d27;
  --bg-code: #0b1017;
  --border: #263241;
  --text: #e6edf3;
  --text-soft: #93a1b1;
  --accent: #4d8bff;
  --accent-soft: #16273f;
  --ok: #3fcf8e;
  --err: #ff6b81;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 56px; /* place pour le bouton console */
}

/* --- Barre supérieure --- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand .logo {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent); color: #fff; font-weight: 700;
  transform: translateY(4px);
}
.brand strong { font-size: 17px; }
.brand .subtitle { color: var(--text-soft); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.db-status { font-size: 12.5px; color: var(--text-soft); white-space: nowrap; }
.db-status.ok { color: var(--ok); }
.db-status.err { color: var(--err); }

/* --- Layout principal --- */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  max-width: 1180px; margin: 0 auto;
}
.sidebar {
  position: sticky; top: 53px; align-self: start;
  height: calc(100vh - 53px); overflow-y: auto;
  padding: 24px 12px; border-right: 1px solid var(--border);
}
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: block; padding: 8px 12px; border-radius: 8px;
  color: var(--text-soft); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--accent-soft); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.content { padding: 32px 40px 80px; min-width: 0; }

/* --- Modules --- */
.module { scroll-margin-top: 70px; padding-bottom: 28px; }
.module + .module { border-top: 1px solid var(--border); padding-top: 28px; }
.module h2 { font-size: 26px; margin: 8px 0 6px; }
.module-intro { color: var(--text-soft); font-size: 16px; margin-top: 0; }

.prose { margin: 18px 0; }
.prose h3 { font-size: 18px; margin: 26px 0 8px; }
.prose p { margin: 10px 0; }
.prose ul { margin: 10px 0; padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose code, .example code, .exercise code {
  font-family: var(--mono); font-size: 0.88em;
  background: var(--bg-code); padding: 1px 6px; border-radius: 5px;
}
.prose pre.schema {
  background: var(--bg-code); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; overflow-x: auto;
  font-family: var(--mono); font-size: 13px; line-height: 1.5; color: var(--text-soft);
}

/* --- Exemples de code --- */
.example {
  margin: 16px 0; padding: 16px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.example figcaption { color: var(--text-soft); font-size: 14px; margin-bottom: 10px; }
pre.code {
  margin: 0 0 12px; padding: 14px 16px; background: var(--bg-code);
  border: 1px solid var(--border); border-radius: 9px;
  overflow-x: auto; font-family: var(--mono); font-size: 13.5px; line-height: 1.55;
}
pre.code code { background: none; padding: 0; }

/* --- Exercices --- */
.exercise {
  margin: 18px 0; padding: 18px 20px; border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.exercise-title { font-weight: 700; color: var(--accent); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.exercise-enonce { margin: 6px 0 12px; }
.exercise-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hint {
  margin: 12px 0 0; padding: 10px 14px; font-size: 14px;
  background: var(--bg-elev); border-left: 3px solid var(--accent); border-radius: 6px;
}
.solution { margin-top: 12px; }
.hidden { display: none; }

/* --- Boutons --- */
.btn {
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text); transition: filter 0.12s, background 0.12s;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.try { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { background: transparent; }

/* --- Console SQL --- */
.console-toggle {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  border: none; border-top: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px; padding: 14px;
  cursor: pointer; text-align: center;
}
.console {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: var(--console-h);
  background: var(--bg-elev); border-top: 1px solid var(--border);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  transform: translateY(100%); transition: transform 0.22s ease;
  display: flex; flex-direction: column;
}
body.console-open .console { transform: translateY(0); }
body.console-open .console-toggle { display: none; }
.console-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text-soft);
}
.console-head-actions { display: flex; gap: 8px; }
.console-body { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
#editor {
  border: none; resize: none; padding: 16px;
  font-family: var(--mono); font-size: 14px; line-height: 1.6;
  background: var(--bg-code); color: var(--text); outline: none;
  border-right: 1px solid var(--border);
}
.results { overflow: auto; padding: 12px 16px; }
.result-meta { font-size: 12px; color: var(--text-soft); margin-bottom: 8px; }
.msg { color: var(--text-soft); font-size: 14px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); font-family: var(--mono); font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 6px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--bg-elev); color: var(--text-soft); font-weight: 600; }
tbody tr:hover { background: var(--accent-soft); }
.null { color: var(--text-soft); font-style: italic; opacity: 0.7; }

/* --- Responsive --- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav-list { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 24px 18px 80px; }
  .console-body { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  #editor { border-right: none; border-bottom: 1px solid var(--border); }
  .console { height: 64vh; }
  .brand .subtitle { display: none; }
}
