:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2357d9;
  --accent-soft: #e8eefc;
  --ok: #17803d;
  --ok-soft: #e3f4e8;
  --warn: #a35c00;
  --warn-soft: #fff3df;
  --error: #b42318;
  --error-soft: #fdeceb;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --card: #1d2128;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --line: #2e333c;
    --accent: #7ea2ff;
    --accent-soft: #233257;
    --ok: #5cc985;
    --ok-soft: #1c3526;
    --warn: #f0b35a;
    --warn-soft: #3a2c15;
    --error: #ff8a80;
    --error-soft: #3d1f1d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }
.card h2, .card h3 { margin-top: 0; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: .4rem 0 .8rem; }
s { color: var(--muted); }
pre { white-space: pre-wrap; word-break: break-word; }

/* Layout */
.page { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.narrow { max-width: 440px; margin: 0 auto; padding: 3rem 1rem; }
.narrow-card { max-width: 560px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { margin-bottom: .3rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.inactive { opacity: .6; }
.top-gap { margin-top: .75rem; }
form.top-gap { display: block; }
.footer-line { margin-top: 1.5rem; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .55rem 1rem;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.nav { display: flex; gap: .2rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: .4rem .65rem; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.me { display: flex; align-items: center; gap: .6rem; white-space: nowrap; font-size: .9rem; }
.pill { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .75rem; font-weight: 700; }
.subnav { display: flex; gap: .3rem; flex-wrap: wrap; margin: -.4rem 0 1rem; }
.subnav a { padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.subnav a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: .3rem .8rem; padding: .5rem .75rem; }
  .nav { order: 3; flex-basis: 100%; }
  .me { margin-left: auto; }
  h1 { font-size: 1.3rem; }
}

/* Text helpers */
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ok-text { color: var(--ok); }
.error-text { color: var(--error); }
.right { margin-left: auto; text-align: right; }
.grow { flex: 1; min-width: 0; }

/* Messages */
.flash { padding: .65rem .9rem; border-radius: 8px; margin: 0 0 1rem; background: var(--accent-soft); }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--error-soft); color: var(--error); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }
.flash-info { background: var(--accent-soft); }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; gap: .3rem; padding: .5rem .9rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--error); }
.btn-danger:hover { border-color: var(--error); }
.btn-small { padding: .3rem .6rem; font-size: .85rem; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
form.inline { display: inline; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; font-weight: 500; }
label small, .form-grid small { font-weight: 400; color: var(--muted); font-size: .8rem; }
.label { font-size: .9rem; font-weight: 500; display: block; margin-bottom: .3rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: .5rem .6rem; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[readonly] { background: var(--bg); }
input[type="checkbox"] { width: auto; }
label.check { flex-direction: row; align-items: center; gap: .45rem; font-weight: 400; }
.checks { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .75rem; margin: 0; min-width: 0; }
.profile-form > fieldset { border: 0; padding: 0; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem 1rem; align-items: start; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid.inner { margin-top: .2rem; }
.form-grid > button { align-self: end; }
.sticky-save { position: sticky; bottom: 0; padding: .75rem 0; background: linear-gradient(transparent, var(--bg) 30%); }
details summary { cursor: pointer; color: var(--accent); }
details.help { margin: 0 0 .75rem; }
details.help ol { margin: .5rem 0 0; padding-left: 1.2rem; }
.copy-box { display: flex; gap: .5rem; margin: 1rem 0; }

/* Filters */
.filters-wrap > summary { font-weight: 600; margin-bottom: .2rem; }
.filters-wrap[open] > summary { margin-bottom: .75rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.filters label { flex: 1 1 140px; }
.filters label.check { flex: 0 1 auto; padding-bottom: .5rem; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; color: var(--text); display: flex; flex-direction: column; }
a.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat strong { font-size: 1.6rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .85rem; }

.checklist ol { margin: 0; padding-left: 1.3rem; }
.checklist li { margin: .25rem 0; }
.checklist li.done { color: var(--ok); list-style: none; margin-left: -1.3rem; }

/* Lists */
.mini-list, .activity, .notes, .user-list, .links { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-top: 1px solid var(--line); }
.mini-list li:first-child { border-top: 0; }
.activity li { padding: .35rem 0; border-top: 1px solid var(--line); }
.activity li:first-child { border-top: 0; }
.activity li > .muted:first-child { display: inline-block; min-width: 7.5rem; }
.notes li { border-top: 1px solid var(--line); padding: .5rem 0; }
.notes p { margin: .2rem 0 0; white-space: pre-wrap; }
.user-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.user-list li:first-child { border-top: 0; }
.user-list select { width: auto; padding: .3rem .4rem; font-size: .85rem; }
.explain { padding-left: 1.1rem; margin: .5rem 0 0; color: var(--muted); }
.links li { word-break: break-all; }

/* Score, status, chips */
.score {
  display: inline-flex; align-items: center; justify-content: center; min-width: 2.4rem; height: 1.9rem;
  border-radius: 8px; font-weight: 700; font-size: .95rem; flex-shrink: 0;
}
.score-high { background: var(--ok-soft); color: var(--ok); }
.score-mid { background: var(--warn-soft); color: var(--warn); }
.score-low, .score-out { background: var(--error-soft); color: var(--error); }
.score-out { font-size: .75rem; font-weight: 600; }
.score-none { background: var(--bg); color: var(--muted); border: 1px dashed var(--line); }
.score.provisional { border: 1px dashed currentColor; }
.status { font-size: .8rem; padding: .15rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.status-a_appeler, .status-visite_prevue, .status-offre_faite { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.status-achetee { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status-ecartee { color: var(--muted); text-decoration: line-through; }
.chip { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); margin: .1rem .25rem .1rem 0; }
.chip-warn, .chip-pending, .chip-waiting_budget { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip-ok, .chip-done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip-error { background: var(--error-soft); color: var(--error); border-color: transparent; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
.card .table-wrap { border: 0; border-radius: 0; margin: 0 -1.1rem; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .6rem .7rem; border-top: 1px solid var(--line); vertical-align: top; }
thead th { border-top: 0; font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
table.compact td { padding: .45rem .7rem; font-size: .9rem; }
.main-cell { min-width: 220px; }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell > * { margin-left: .25rem; }

@media (max-width: 760px) {
  table.listings thead { display: none; }
  table.listings, table.listings tbody, table.listings tr, table.listings td { display: block; width: 100%; }
  table.listings tr { padding: .7rem .8rem; border-top: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; }
  table.listings td { border: 0; padding: 0; }
  table.listings td:first-child { grid-row: span 6; }
  table.listings td.num { text-align: left; }
  table.listings td[data-label]:not(:first-child)::before { content: attr(data-label) " : "; color: var(--muted); font-size: .8rem; }
  table.listings .actions-cell { text-align: left; white-space: normal; }
  table.listings .actions-cell > * { margin: .3rem .3rem 0 0; }
}

/* Listing page */
.key-figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin: 1rem 0; }
.key-figures div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; display: flex; flex-direction: column; }
.key-figures span { color: var(--muted); font-size: .8rem; }
.key-figures strong { font-size: 1.2rem; }
.key-figures small { color: var(--muted); }
.figures { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; margin: .5rem 0; }
.figures dt { color: var(--muted); }
.figures dd { margin: 0; }
.calc details { margin-top: .5rem; }
.row-form { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; padding: .5rem 0; border-top: 1px solid var(--line); }
.row-form:first-of-type { border-top: 0; }
.row-form input, .row-form select { width: auto; flex: 1 1 110px; }
.email-text { background: var(--bg); padding: .8rem; border-radius: 8px; font-size: .85rem; max-height: 480px; overflow: auto; }
.pager { display: flex; gap: 1rem; justify-content: center; align-items: center; margin: 1rem 0; }
.empty { text-align: center; padding: 2rem 1rem; }

.busy { opacity: .6; pointer-events: none; }

/* Search dialogue */
.alerts-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .alerts-layout { grid-template-columns: 1fr; } }
.chat .messages { display: flex; flex-direction: column; gap: .7rem; max-height: 70vh; overflow-y: auto; padding: .2rem; margin-bottom: .8rem; }
.bubble { border-radius: 12px; padding: .6rem .85rem; max-width: 92%; }
.bubble p { margin: .2rem 0; white-space: pre-wrap; }
.bubble-user { align-self: flex-end; background: var(--accent-soft); }
.bubble-assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); }
.bubble .who { margin-bottom: .1rem; }
.examples { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.chip-btn { border: 1px solid var(--line); background: var(--card); color: var(--accent); border-radius: 999px; padding: .3rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; }
.chip-btn:hover { border-color: var(--accent); }
.proposal { background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: .7rem .85rem; margin-top: .6rem; }
.proposal h3 { margin-bottom: .3rem; }
.proposal details { margin-top: .4rem; }
.brief-text { white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: .6rem .7rem; margin-top: .4rem; }
.chat-form { display: flex; gap: .5rem; align-items: flex-end; }
.chat-form textarea { flex: 1; }
.side .card textarea { font-size: .9rem; }
.group-title { font-size: .9rem; margin: 1rem 0 .3rem; }
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .55rem 0; border-top: 1px solid var(--line); }
.alert-list li:first-child { border-top: 0; }
.alert-list .actions { gap: .3rem; }
.faded { opacity: .7; }

/* Claude's judgement on a listing */
.fit { border-left: 3px solid var(--line); padding: .3rem 0 .3rem .7rem; margin: .5rem 0; }
.fit p, .fit ul { margin: .2rem 0; }
.fit-correspond { border-color: var(--ok); }
.fit-a_verifier { border-color: var(--warn); }
.fit-hors_cible { border-color: var(--error); }

/* Charts (Sites page). Site colours: validated categorical palette, fixed order. */
:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --series-4: #eda100; --series-5: #e87ba4; --series-6: #008300; --series-other: #9aa0a8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-other: #6b7280;
  }
}
.series-1 { fill: var(--series-1); background: var(--series-1); }
.series-2 { fill: var(--series-2); background: var(--series-2); }
.series-3 { fill: var(--series-3); background: var(--series-3); }
.series-4 { fill: var(--series-4); background: var(--series-4); }
.series-5 { fill: var(--series-5); background: var(--series-5); }
.series-6 { fill: var(--series-6); background: var(--series-6); }
.series-other { fill: var(--series-other); background: var(--series-other); }
.series-1-stroke { stroke: var(--series-1); }
svg.chart { width: 100%; height: auto; display: block; margin: .3rem 0; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 11px; }
svg.chart .hit { fill: transparent; }
svg.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .dot { stroke: var(--card); stroke-width: 2; }
svg.chart rect:not(.hit):hover, svg.chart path:not(.line):hover, svg.chart .dot:hover { opacity: .8; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin: 0 0 .3rem; padding: 0; font-size: .85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .35rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .4rem; vertical-align: middle; flex-shrink: 0; }
.periods { margin: 0; }
.stat small { font-size: .9rem; font-weight: 500; }
.sites-table td { white-space: nowrap; }
