:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2330;
  --muted: #667085;
  --accent: #2459d6;
  --accent-soft: #e8eefc;
  --ok: #17804a;
  --ok-soft: #e4f5ec;
  --warn: #a86400;
  --warn-soft: #fdf1dd;
  --err: #c0322b;
  --err-soft: #fde8e7;
  --code-bg: #0f1624;
  --code-text: #d6deeb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131a;
    --surface: #171c25;
    --surface-2: #1e2430;
    --border: #2a3140;
    --text: #e6e9ef;
    --muted: #97a0b0;
    --accent: #6d95ff;
    --accent-soft: #1f2a45;
    --ok: #4cc28a;
    --ok-soft: #173327;
    --warn: #f0b04f;
    --warn-soft: #3a2c12;
    --err: #ff7b72;
    --err-soft: #3d1c1c;
    --code-bg: #0b0f15;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* Mise en page */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { font-weight: 700; font-size: 16px; padding: 0 10px 18px; display: flex; gap: 8px; align-items: center; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.nav a {
  display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); margin-bottom: 2px; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 10px; color: var(--muted); font-size: 12px; }
.sidebar-foot form { margin-top: 6px; }
.main { padding: 28px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 4px; }
  .brand { padding: 0 10px 0 0; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; }
  .main { padding: 20px 16px 48px; }
}

/* Cartes et grilles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* Tableaux */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); border-top: none; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

/* Formulaires */
form.inline { display: inline; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
input[type=text], input[type=password], input[type=url], input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; min-height: 70px; }
.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-block;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.small { padding: 3px 10px; font-size: 12.5px; }
.btn-link { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.btn-link:hover { color: var(--text); text-decoration: underline; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }

/* Messages */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--ok-soft); color: var(--ok); font-weight: 500; }
.flash.error { background: var(--err-soft); color: var(--err); }
.secret-box { background: var(--warn-soft); border: 1px solid var(--warn); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.secret-box code { display: block; background: var(--surface); padding: 10px 12px; border-radius: 8px; margin: 8px 0; word-break: break-all; font-size: 14px; color: var(--text); }

/* Code */
pre.code {
  background: var(--code-bg); color: var(--code-text); padding: 14px 16px; border-radius: 8px;
  overflow: auto; max-height: 560px; margin: 0; white-space: pre; tab-size: 2;
}
pre.wrap { white-space: pre-wrap; word-break: break-word; }
.copy-wrap { position: relative; }
.copy-wrap .btn { position: absolute; top: 8px; right: 8px; }

/* Définitions */
dl.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Graphique horaire */
.bars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; align-items: end; height: 110px; }
.bar { background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.bar.zero { background: var(--border); }
.bar:hover { opacity: 1; }
.bar .err-part { position: absolute; bottom: 0; left: 0; right: 0; background: var(--err); border-radius: 0 0 0 0; }
.bars-axis { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; margin-top: 4px; font-size: 10.5px; color: var(--muted); text-align: center; }
.bars-axis span:nth-child(odd) { visibility: hidden; }

/* Annonces */
.listing-cell { display: flex; gap: 12px; align-items: center; min-width: 280px; }
.thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; background: var(--surface-2); flex: none; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.description { white-space: pre-line; }
.price-big { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.criteria-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: none; font: inherit; font-weight: 600; color: var(--muted); padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.pagination { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Connexion */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .field { margin-bottom: 12px; }
.login-card input { width: 100%; }
