:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #238636;
  --accent-dim: #1f6feb;
  --danger: #da3633;
  --warn: #d29922;
  --font: "Segoe UI", system-ui, sans-serif;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 48px 1fr;
  height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-start {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.user-label {
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar .badge {
  font-size: 0.75rem;
  color: var(--muted);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0.75rem 0;
}

.nav-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 1rem;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}

.nav-btn.active {
  border-left-color: var(--accent-dim);
  background: rgba(31, 111, 235, 0.12);
}

main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 1rem;
}

.panel.active {
  display: flex;
  flex-direction: column;
}

.panel-split {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

@media (max-width: 1100px) {
  .panel-split {
    grid-template-columns: 1fr;
  }
}

#map {
  height: 100%;
  min-height: 420px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  z-index: 1;
}

/* Recherche Nominatim (contrôle Leaflet, en haut à gauche) */
.leaflet-control.sg-map-search {
  clear: both;
  margin-top: 0.5rem !important;
}

.sg-map-search .sg-map-search-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.sg-map-search input[type="search"] {
  width: min(260px, 42vw);
  min-width: 120px;
  border: none;
  background: var(--bg);
  color: var(--text);
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  border-radius: 4px 0 0 4px;
}

.sg-map-search .sg-map-search-row button {
  width: 38px;
  flex-shrink: 0;
  border: none;
  background: var(--accent-dim);
  color: #fff;
  cursor: pointer;
  border-radius: 0 4px 4px 0;
  font-size: 1.1rem;
  line-height: 1;
}

.sg-map-search .sg-map-search-row button:hover {
  filter: brightness(1.08);
}

.sg-map-search-list {
  margin-top: 6px;
  max-height: min(240px, 40vh);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  min-width: 100%;
}

.sg-map-search-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.35;
}

.sg-map-search-item:last-child {
  border-bottom: none;
}

.sg-map-search-item:hover:not(.muted):not(.err):not(.sg-map-search-loading) {
  background: rgba(255, 255, 255, 0.06);
}

.sg-map-search-item.muted,
.sg-map-search-loading {
  color: var(--muted);
  cursor: default;
}

.sg-map-search-item.err {
  color: var(--danger);
  cursor: default;
}

.leaflet-popup-content .btn {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
}

/* Contrôle des couches Leaflet — cohérence avec le thème sombre */
.leaflet-control-layers {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35) !important;
}

.leaflet-control-layers-expanded {
  padding: 0.5rem 0.65rem !important;
  min-width: 200px;
}

.leaflet-control-layers-list label {
  color: var(--text);
  font-size: 0.82rem;
  margin: 0.2rem 0;
}

.leaflet-control-layers-separator {
  border-top-color: var(--border) !important;
  margin: 0.35rem 0 !important;
}

.leaflet-control-layers-base label {
  font-weight: 500;
}

.leaflet-control-scale-line {
  border: 1px solid var(--border) !important;
  background: rgba(22, 27, 34, 0.92) !important;
  color: var(--text) !important;
}

.leaflet-bar a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-bar a:hover {
  background: var(--bg) !important;
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.card h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 500;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.form-grid {
  display: grid;
  gap: 0.5rem;
}

label {
  font-size: 0.8rem;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  padding: 1rem;
}

.modal h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.statut {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
}

.statut.disponible {
  background: rgba(35, 134, 54, 0.2);
  color: #3fb950;
}

.statut.en_intervention {
  background: rgba(210, 153, 34, 0.2);
  color: var(--warn);
}

.statut.ouverte {
  color: #58a6ff;
}

.statut.en_cours {
  color: var(--warn);
}

.statut.cloturee {
  color: var(--muted);
}

.statut.annulee {
  color: var(--muted);
  text-decoration: line-through;
}

.modal-wide {
  max-width: 560px;
}

.int-ref-row {
  margin: 0 0 1rem;
  font-size: 0.9rem;
}

.muted-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.filtre-int {
  font-size: 0.85rem;
  color: var(--muted);
  margin-right: 0.35rem;
}

.filtre-int-select {
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}

.tbl-actions-wrap .col-actions {
  width: 1%;
  white-space: nowrap;
}

.btn.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.78rem;
}

select.int-statut-inline {
  max-width: 9rem;
  padding: 0.25rem 0.35rem;
  font-size: 0.78rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.mc-list {
  max-height: 320px;
  overflow: auto;
  font-size: 0.85rem;
}

.mc-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.mc-item time {
  color: var(--muted);
  font-size: 0.75rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.35rem;
}

.legend-dot.moyen {
  background: #3fb950;
}

.legend-dot.intervention {
  background: #f85149;
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1rem 0;
}
