:root {
  --bg: #f5f7f8;
  --card: #ffffff;
  --ink: #172026;
  --muted: #637079;
  --line: #d9e0e4;
  --accent: #176b4d;
  --accent-dark: #0f533b;
  --danger: #a32f2f;
  --warning: #9a6a0a;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); }
.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 22px;
  background: #12251f;
  color: white;
}
.topbar a { color: white; text-decoration: none; }
.brand { font-weight: 750; font-size: 1.1rem; }
.subtitle { display: block; color: #b9c9c3; font-size: .8rem; margin-top: 2px; }
.topbar nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.inline-form { display: inline; margin: 0; }
.link-button {
  border: 0; background: none; color: white; padding: 0; cursor: pointer; font: inherit;
}
.page { padding: 22px; max-width: 1900px; margin: 0 auto; }
.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  margin-bottom: 18px;
}
.hero.compact h1 { margin: 0 0 5px; font-size: 1.65rem; }
.hero p { margin: 0; color: var(--muted); }
.stats { min-width: 90px; text-align: center; background: var(--card); padding: 10px 16px; border-radius: var(--radius); border: 1px solid var(--line); }
.stats strong { display: block; font-size: 1.65rem; }
.stats span { color: var(--muted); font-size: .85rem; }
.layout { display: grid; grid-template-columns: minmax(420px, .9fr) minmax(720px, 1.8fr); gap: 18px; align-items: start; }
.map-panel, .table-panel, .card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 3px 15px rgba(21, 35, 31, .04);
}
#map { height: 590px; border-radius: var(--radius) var(--radius) 0 0; }
#edit-map { height: 430px; margin-top: 18px; border: 1px solid var(--line); border-radius: 10px; }
.map-toolbar { padding: 12px; display: flex; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--line); }
.distance-summary { border-top: 1px solid var(--line); padding: 12px 14px 14px; font-size: .92rem; line-height: 1.45; }
.distance-summary ul { margin: 8px 0 0 18px; padding: 0; }
.table-tools { padding: 12px; border-bottom: 1px solid var(--line); }
.table-tools input { width: 100%; }
.table-wrap { overflow: auto; max-height: 720px; }
table { border-collapse: collapse; width: 100%; min-width: 950px; font-size: .86rem; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #eef3f1; z-index: 2; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; }
td small { display: block; color: var(--muted); margin-top: 3px; }
tr.selected { background: #eef8f3; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }
.status { display: inline-block; border-radius: 999px; padding: 3px 8px; font-size: .72rem; font-weight: 700; background: #e7ecea; }
.status-actif { background: #d8efe4; color: #15543d; }
.status-test, .status-maintenance { background: #fff0cd; color: #795003; }
.status-hs { background: #f6dada; color: #7c1d1d; }
.status-projet { background: #e4e7eb; color: #4b5660; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--accent); border-radius: 8px; padding: 9px 13px;
  background: var(--accent); color: white; text-decoration: none; cursor: pointer; font: inherit; font-weight: 650;
}
.button:hover { background: var(--accent-dark); }
.button.secondary { background: white; color: var(--accent); }
.button.danger { background: white; color: var(--danger); border-color: #cf8c8c; }
.button.small { padding: 6px 9px; font-size: .8rem; }
.card { padding: 18px; margin-bottom: 18px; }
.card.narrow { max-width: 470px; margin: 40px auto; }
.card h1, .card h2 { margin-top: 0; }
.form-stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 16px; }
label { display: grid; gap: 6px; font-weight: 650; font-size: .86rem; }
input, select, textarea {
  width: 100%; border: 1px solid #b9c4ca; border-radius: 8px; padding: 9px 10px; background: white; color: var(--ink); font: inherit;
}
textarea { resize: vertical; }
.node-form { display: grid; gap: 0; }
.form-actions { display: flex; gap: 10px; margin-bottom: 30px; }
.actions { display: flex; gap: 7px; align-items: center; }
.actions form { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.flash-stack { margin-bottom: 14px; }
.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; background: #e8edf0; }
.flash.success { background: #dff2e8; }
.flash.danger { background: #f7dede; }
.flash.warning { background: #fff0cd; }
.distance-label {
  background: white; border: 1px solid #7b8a83; border-radius: 6px; padding: 2px 5px; font-size: 11px; font-weight: 700; white-space: nowrap;
}

@media (max-width: 1150px) {
  .layout { grid-template-columns: 1fr; }
  #map { height: 500px; }
  .table-wrap { max-height: none; }
}
@media (max-width: 760px) {
  .topbar, .hero { align-items: flex-start; flex-direction: column; }
  .page { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  #map, #edit-map { height: 420px; }
}

/* Gestion des habilitations */
.nav-role { color: #b9c9c3; font-size: .82rem; }
.role-badge { display: inline-block; border-radius: 999px; padding: 4px 9px; font-size: .75rem; font-weight: 750; background: #e7ecea; }
.role-admin { background: #d8efe4; color: #15543d; }
.role-editor { background: #e6edf4; color: #34495e; }
.narrow-wide { max-width: 680px; margin-left: auto; margin-right: auto; }
.checkbox-label { display: flex; align-items: center; gap: 9px; }
.checkbox-label input { width: auto; }
.user-form-actions { margin-bottom: 0; }
.users-table { min-width: 760px; }

/* Étude radio V3 */
.form-hint { color: var(--muted); font-size: .82rem; margin: 12px 0 0; }
.radio-study-panel { border-top: 1px solid var(--line); padding: 16px; background: #fbfcfc; }
.radio-study-panel.hidden { display: none; }
.radio-study-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 10px; }
.radio-study-head h2 { margin: 0 0 4px; font-size: 1.2rem; }
.radio-study-head p { margin: 0; color: var(--muted); }
.radio-study-status { min-height: 24px; color: var(--muted); font-size: .9rem; margin: 8px 0 12px; }
.radio-metrics { display: grid; grid-template-columns: repeat(2, minmax(180px, 1fr)); gap: 8px; margin-bottom: 14px; }
.radio-metric { display: flex; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 8px; background: white; padding: 9px 11px; font-size: .84rem; }
.radio-metric span { color: var(--muted); }
.radio-metric strong { text-align: right; }
.radio-budget-wrap { overflow-x: auto; margin: 14px 0; }
.radio-budget-wrap h3 { margin: 0 0 8px; font-size: 1rem; }
.radio-budget-table { min-width: 720px; background: white; border: 1px solid var(--line); }
.radio-budget-table th { position: static; }
.link-quality { display: inline-block; border-radius: 999px; padding: 4px 8px; font-size: .76rem; font-weight: 750; }
.link-quality.good { background: #d8efe4; color: #15543d; }
.link-quality.ok { background: #e5f1db; color: #3d5c1d; }
.link-quality.warn { background: #fff0cd; color: #795003; }
.link-quality.bad { background: #f6dada; color: #7c1d1d; }
.good-text { color: #15543d; }
.warn-text { color: #8a5d00; }
.bad-text { color: #8a2424; }
.profile-wrap { background: white; border: 1px solid var(--line); border-radius: 9px; padding: 8px; overflow: hidden; }
#radio-profile { display: block; width: 100%; height: 300px; }
.radio-study-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.radio-study-note { color: var(--muted); font-size: .8rem; line-height: 1.45; margin: 12px 0 0; }
.radio-details { margin-top: 12px; font-size: .85rem; }
.radio-details p { margin: 6px 0; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid #c9d2ce; border-top-color: var(--accent); border-radius: 50%; vertical-align: -2px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .radio-metrics { grid-template-columns: 1fr; }
  .radio-study-head { flex-direction: column; }
}

/* Sortable table headers */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable::after {
  content: " ↕";
  color: #7d8b86;
  font-size: .85em;
}
th.sortable[aria-sort="ascending"]::after { content: " ▲"; color: var(--accent); }
th.sortable[aria-sort="descending"]::after { content: " ▼"; color: var(--accent); }
th.sortable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
