:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e3e8ee;
  --accent: #1264a3;
  --green: #1e8e3e;
  --orange: #f9ab00;
  --red: #d93025;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column; height: 100vh;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 56px; box-sizing: border-box; flex: none;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow); z-index: 1000; flex-wrap: nowrap;
}
.brand { font-size: 18px; }
.brand .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 4px; }
/* Onglets : boutons ET liens partagent la MÊME géométrie (police héritée,
   même box), pour un header identique au pixel d'une page à l'autre. */
.tabs { display: flex; align-items: center; gap: 4px; }
.tabs button, .tabs .tablink {
  display: inline-flex; align-items: center;
  font: inherit; font-size: 14px; line-height: 1.4; font-weight: 400;
  padding: 6px 10px; border: none; border-radius: 6px;
  background: none; color: var(--muted); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.tabs button:hover, .tabs .tablink:hover { background: #eef1f4; color: var(--accent); }
/* État actif : fond + couleur uniquement (pas de gras → aucune variation de largeur). */
.tabs button.active, .tabs .tablink.active { background: #e8f0fe; color: var(--accent); }
.search { position: relative; flex: 1; min-width: 260px; max-width: 520px; margin-left: auto; }
.search input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.suggestions {
  position: absolute; top: 100%; left: 0; right: 0; margin: 4px 0 0; padding: 0; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  z-index: 2000; max-height: 280px; overflow: auto;
}
.suggestions li { padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f1f3f5; }
.suggestions li:hover, .suggestions li.active { background: #e8f0fe; }
.hidden { display: none !important; }

/* Layout */
main { flex: 1; overflow: hidden; position: relative; }
.view { display: none; height: 100%; }
.view.active { display: block; }
#view-carte { display: none; }
#view-carte.active { display: flex; }
#map { flex: 1; height: 100%; min-width: 200px; }
.panel {
  width: 460px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 22px 22px 32px;
}
/* Poignée de redimensionnement du volet */
.resizer {
  flex: none; width: 8px; cursor: col-resize; background: var(--line);
  display: flex; align-items: center; justify-content: center; transition: background .15s; touch-action: none;
}
.resizer:hover, .resizer.active { background: var(--accent); }
.resizer span { width: 2px; height: 34px; background: #fff; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.06); }
.panel-empty h2 { margin-top: 0; }
.muted { color: var(--muted); font-size: 13px; }

/* Fiche */
.fiche h2 { margin: 0 0 2px; font-size: 19px; letter-spacing: -.2px; }
.fiche .addr-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.gauge-row {
  display: flex; align-items: center; gap: 18px; margin-bottom: 16px;
  padding: 16px; border-radius: 14px; background: linear-gradient(135deg, #fbfcfe, #f2f6fb);
  border: 1px solid var(--line);
}

/* Anneau de score circulaire */
.gauge-ring { position: relative; width: 108px; height: 108px; flex: none; }
.gauge-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge-ring .track { fill: none; stroke: #e7ecf2; stroke-width: 9; }
.gauge-ring .prog { fill: none; stroke-width: 9; stroke-linecap: round;
  transition: stroke-dashoffset .6s cubic-bezier(.4,0,.2,1), stroke .3s; }
.gauge-ring .gnum { position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; }
.gauge-num-val { font-size: 32px; font-weight: 800; line-height: 1; letter-spacing: -1px; }
.gauge-num-max { font-size: 11px; color: var(--muted); font-weight: 600; }

.flags { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.flag {
  background: #fdecea; color: var(--red); border: 1px solid #f5c2c0; border-radius: 8px;
  padding: 8px 11px; font-size: 12.5px; font-weight: 600; line-height: 1.35;
}
.flag.ok { background: #e6f4ea; color: var(--green); border-color: #b7e1c1; font-weight: 600; }

.subscores { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin: 14px 0; }
.card {
  border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px 12px; background: #fff;
  transition: box-shadow .15s, transform .15s; position: relative; overflow: hidden;
}
.card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--bar, var(--line)); }
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card h3 { margin: 0 0 9px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.badge { font-size: 15px; font-weight: 800; min-width: 30px; text-align: center; padding: 2px 9px; border-radius: 7px; color: #fff; }
.card details { font-size: 12px; }
.card summary { cursor: pointer; color: var(--accent); font-size: 12px; }
.detail-line { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-bottom: 1px dashed #eef1f4; }
.detail-line .impact { font-variant-numeric: tabular-nums; font-weight: 600; }
.impact.pos { color: var(--green); } .impact.neg { color: var(--red); } .impact.zero { color: var(--muted); }
.note { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 6px; }

.section { margin: 16px 0; }
.section h3 { font-size: 14px; margin: 0 0 8px; border-bottom: 2px solid var(--line); padding-bottom: 4px; }
table.risks { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.risks td { padding: 5px 6px; border-bottom: 1px solid #f1f3f5; }
table.risks td:last-child { text-align: right; font-weight: 600; }

/* Orientation schema */
.orient { display: flex; gap: 14px; align-items: center; }
.compass { width: 120px; height: 120px; position: relative; flex: none; }
.compass svg { width: 100%; height: 100%; }

/* Formulaire manuel */
form.manuel label { display: block; font-size: 12.5px; margin: 7px 0 2px; color: var(--ink); }
form.manuel input[type=number], form.manuel input[type=text] {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
}
form.manuel .checks label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
form.manuel .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.weights { display: grid; grid-template-columns: 1fr; gap: 4px; font-size: 12px; }
.weights .wrow { display: grid; grid-template-columns: 110px 1fr 38px; align-items: center; gap: 8px; }
.weights input[type=range] { width: 100%; }

.actions { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
button.btn {
  background: var(--accent); color: #fff; border: none; padding: 9px 14px; border-radius: 8px;
  font-size: 13px; cursor: pointer; font-weight: 600;
}
button.btn.secondary { background: #eef1f4; color: var(--ink); }
button.btn.danger { background: #fdecea; color: var(--red); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

.loading { color: var(--muted); font-size: 13px; padding: 8px 0; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid #cfd6dd; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.err { color: var(--red); font-size: 12.5px; }

/* Comparateur */
.comparateur-wrap { padding: 22px; height: 100%; overflow: auto; }
#comparateur table { border-collapse: collapse; width: 100%; font-size: 13px; background: #fff; box-shadow: var(--shadow); }
#comparateur th, #comparateur td { border: 1px solid var(--line); padding: 8px 10px; text-align: center; }
#comparateur th { background: #f1f5f9; position: sticky; top: 0; }
#comparateur td.label { text-align: left; font-weight: 600; background: #fafbfc; }
#comparateur .best { background: #e6f4ea; font-weight: 700; }
#comparateur .scorecell { color: #fff; font-weight: 700; border-radius: 6px; }

.attrib { font-size: 11px; color: var(--muted); padding: 7px 16px; background: var(--panel); border-top: 1px solid var(--line); text-align: center; }
.attrib a { color: var(--accent); text-decoration: none; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2933; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 4000;
}

/* Compas d'orientation flottant, centré sur l'emprise : rose des vents nue,
   sans fond ni libellé. Ombre douce pour le détacher du fond de carte. */
.orient-float { background: none; border: none; pointer-events: none; user-select: none; }
.orient-float svg { display: block; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35)); }

/* Marker score pill */
.score-pill {
  background: #fff; border-radius: 14px; padding: 1px 7px; font-weight: 700; font-size: 12px;
  border: 2px solid #fff; box-shadow: var(--shadow); white-space: nowrap;
}

@media (max-width: 760px) {
  #view-carte.active { flex-direction: column; }
  #map { height: 40vh; }
  .panel { width: 100% !important; max-width: 100%; }
  .resizer { display: none; }
  .subscores { grid-template-columns: 1fr; }
}

/* Actualités locales (fiche bien) */
.news-item { border-left: 3px solid #e8710a; padding: 3px 0 3px 11px; margin-bottom: 10px; }
.news-title { display: block; font-size: 13px; font-weight: 600; line-height: 1.35;
  color: var(--accent); text-decoration: none; }
.news-title:hover { text-decoration: underline; }
.news-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Impression / PDF */
@media print {
  .topbar, .attrib, #map, .actions, .tabs, .search, form.manuel, .weights, summary { display: none !important; }
  body, main, .view, #view-carte.active { display: block !important; height: auto !important; overflow: visible !important; }
  .panel { width: 100% !important; max-width: 100% !important; border: none; }
  .card details[open] summary ~ * { display: block; }
  .fiche { font-size: 12px; }
}
