/* ------------------------------------------------------------------
   Cartographie des datacenters europeens — feuille de style unique.
   Mise en page : barre superieure + panneau lateral + carte + fiche.
   ------------------------------------------------------------------ */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --border: #d9dfe9;
  --text: #16202e;
  --text-muted: #5b6779;
  --primary: #0b6bcb;
  --primary-dark: #08519c;
  --danger: #c02525;
  --ok: #12a150;
  --warn: #b45309;
  --shadow: 0 6px 24px rgba(16, 27, 43, .12);
  --radius: 10px;
  --topbar-h: 56px;
  --sidebar-w: 360px;
  --detail-w: 420px;
  font-synthesis: none;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #131c2b;
  --surface-2: #1a2436;
  --border: #2a3648;
  --text: #e8edf5;
  --text-muted: #9aa7b9;
  --primary: #4d9bf0;
  --primary-dark: #2f7fd4;
  --danger: #f16a6a;
  --ok: #34c77b;
  --warn: #eab308;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; letter-spacing: .01em; }
h4 { font-size: .85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 1rem; }
p { margin: 0 0 .6em; }
a { color: var(--primary); }

/* ---------- barre superieure ---------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 0 .7rem;
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 1200;
}

.brand { display: flex; align-items: center; gap: .45rem; font-weight: 650; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--primary); color: #fff; font-size: 15px;
}
.brand-text { font-size: .98rem; }

.search-wrap { flex: 1; min-width: 0; }
.search {
  width: 100%;
  height: 36px;
  padding: 0 .75rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-2);
  color: inherit;
  font-size: .92rem;
}
.search:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.topbar-actions { display: flex; align-items: center; gap: .3rem; }

/* ---------- mise en page ---------- */

.layout {
  position: relative;
  display: flex;
  height: calc(100% - var(--topbar-h));
  /* Contient la fiche detaillee et la barre laterale escamotees : sans cela
     elles debordent hors de la fenetre et elargissent la page. */
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: margin-left .18s ease;
  min-width: 0;
}
body:not(.sidebar-open) .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.tabs-main { display: flex; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.tab-main {
  flex: 1;
  padding: .65rem .2rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
  position: relative;
}
.tab-main.is-active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.panel { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: .6rem; }

.map { flex: 1; min-width: 0; background: var(--surface-2); }

/* ---------- fiche detaillee ---------- */

.detail-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: var(--detail-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform .2s ease;
  z-index: 1100;
  display: flex;
  flex-direction: column;
}
body.detail-open .detail-panel { transform: none; }
.detail-close { position: absolute; top: .5rem; right: .5rem; z-index: 2; }
.detail-content { overflow-y: auto; padding: .9rem; padding-bottom: 2rem; }

.detail-head { border-bottom: 1px solid var(--border); padding-bottom: .7rem; margin-bottom: .7rem; }
.detail-title-row { display: flex; align-items: flex-start; gap: .5rem; padding-right: 2rem; }
.detail-title { font-size: 1.1rem; margin: 0; }
.detail-sub { color: var(--text-muted); font-size: .87rem; }
.detail-address { color: var(--text-muted); font-size: .85rem; margin: .5rem 0; }
.detail-actions, .nav-links { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.detail-body { padding-top: .3rem; }

/* ---------- boutons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .8rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: .875rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn-sm { padding: .32rem .6rem; font-size: .82rem; }
.btn-xs { padding: .2rem .5rem; font-size: .78rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.icon-btn.is-on { background: var(--primary); color: #fff; }
.icon-btn.star.is-on { color: #eab308; background: none; font-size: 1.3rem; }
.icon-btn[disabled] { opacity: .3; cursor: default; }

.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--primary); font: inherit; font-size: .87rem;
  text-align: left; cursor: pointer; text-decoration: underline;
}

.badge-count {
  position: absolute; top: 1px; right: 1px;
  min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 8px;
  background: var(--danger); color: #fff;
  font-size: 10px; line-height: 15px; text-align: center;
}
.tab-main .badge-count { position: static; display: inline-block; margin-left: .3rem; background: var(--primary); }

.sync-dot {
  position: absolute; bottom: 3px; right: 3px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
}
.sync-ok { background: var(--ok); }
.sync-error { background: var(--danger); }
.sync-running { background: var(--warn); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }

/* ---------- liste des sites ---------- */

.list-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .2rem .3rem .5rem;
}
.list-count { color: var(--text-muted); font-size: .82rem; }

.dc-list { list-style: none; margin: 0; padding: 0; }
.dc-item {
  display: flex; align-items: flex-start; gap: .5rem;
  padding: .55rem .5rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.dc-item:hover { background: var(--surface-2); }
.dc-item.is-selected { background: color-mix(in srgb, var(--primary) 12%, transparent); border-color: var(--primary); }
.dc-item:focus-visible { outline: 2px solid var(--primary); }
.dc-item-main { flex: 1; min-width: 0; }
.dc-item-title { display: flex; align-items: center; gap: .3rem; }
.dc-item-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-item-sub, .dc-item-meta { color: var(--text-muted); font-size: .79rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-item-actions { display: flex; gap: .1rem; }
.dc-item-actions .icon-btn { width: 28px; height: 28px; font-size: .9rem; }
.star-inline { color: #eab308; }

.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: .35rem; flex: 0 0 auto; background: var(--text-muted); }
.dot-live { background: #12a150; }
.dot-construction { background: #f5a524; }
.dot-planned { background: #7828c8; }
.dot-decommissioned { background: #71717a; }

/* ---------- fiches, champs ---------- */

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem .8rem; margin-bottom: .8rem; }
.field { display: flex; flex-direction: column; min-width: 0; }
.field-full { grid-column: 1 / -1; }
.field-label { color: var(--text-muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; }
.field-value { font-size: .9rem; overflow-wrap: anywhere; }

.block { margin: .9rem 0; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.stack { display: flex; flex-direction: column; gap: .5rem; }
.pre { white-space: pre-wrap; }
.muted { color: var(--text-muted); }
.small { font-size: .8rem; }
.warn { color: var(--warn); }
.row-inline { display: flex; gap: .35rem; align-items: center; }
.row-inline.wrap { flex-wrap: wrap; }

.badges { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0; }
.badge {
  display: inline-block; padding: .12rem .45rem;
  border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: .74rem; color: var(--text-muted);
}
.badge-live { background: color-mix(in srgb, #12a150 18%, transparent); color: #0a7a3c; border-color: transparent; }
.badge-construction { background: color-mix(in srgb, #f5a524 22%, transparent); color: #8a5a00; border-color: transparent; }
.badge-planned { background: color-mix(in srgb, #7828c8 18%, transparent); color: #5b1d97; border-color: transparent; }
.badge-ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); border-color: transparent; }
.badge-warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); border-color: transparent; }
.badge-customer { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); border-color: transparent; }
.badge-negotiation { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); border-color: transparent; }
.badge-lost { text-decoration: line-through; }
html[data-theme="dark"] .badge-live { color: #4ade80; }
html[data-theme="dark"] .badge-construction { color: #fbbf24; }
html[data-theme="dark"] .badge-planned { color: #c084fc; }

.chips { display: flex; flex-wrap: wrap; gap: .25rem; }
.chip {
  padding: .1rem .45rem; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .78rem;
}
.chip-tag { background: color-mix(in srgb, var(--primary) 12%, transparent); border-color: transparent; }

.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.row-item {
  display: flex; align-items: flex-start; gap: .5rem;
  padding: .5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.row-main { flex: 1; min-width: 0; }
.row-title { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.row-actions { display: flex; gap: .1rem; }
.row-actions .icon-btn { width: 28px; height: 28px; font-size: .85rem; }

.meter { height: 9px; border-radius: 5px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.meter-fill { display: block; height: 100%; background: var(--primary); }

.stat { display: flex; flex-direction: column; align-items: flex-start; }
.stat-value { font-size: 1.25rem; font-weight: 650; }
.stat-label { color: var(--text-muted); font-size: .76rem; }

.empty { padding: 2rem 1rem; text-align: center; color: var(--text-muted); }

/* ---------- clients, tournee ---------- */

.clients-toolbar { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .5rem; }
.client-row .row-main { display: flex; flex-direction: column; gap: .1rem; }

.trip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.trip-item { display: flex; align-items: flex-start; gap: .5rem; padding: .45rem; border: 1px solid var(--border); border-radius: 8px; }
.trip-index {
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: .78rem; flex: 0 0 auto;
}
.trip-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .7rem; }

/* ---------- formulaires ---------- */

.input, input[type="text"], input[type="url"], input[type="tel"], input[type="email"],
input[type="number"], input[type="date"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  padding: .42rem .55rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .88rem;
}
textarea { resize: vertical; }
.input-sm { width: auto; padding: .3rem .45rem; font-size: .82rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.form { display: block; }
.form-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .7rem .8rem;
  margin: 0 0 .8rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .55rem .7rem;
}
.form-group > legend { padding: 0 .3rem; font-weight: 600; font-size: .82rem; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; }
.form-field { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.form-field-full { grid-column: 1 / -1; }
.form-field label { font-size: .78rem; color: var(--text-muted); }
.form-field-check { flex-direction: row; align-items: center; gap: .4rem; }
.form-field-check input { width: auto; }
.form-field-check label { font-size: .85rem; color: var(--text); }
.form-hint { color: var(--text-muted); font-size: .73rem; }

.stacked-label { display: flex; flex-direction: column; gap: .15rem; font-size: .8rem; color: var(--text-muted); }
.check { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--text); }
.check input { width: auto; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .2rem .5rem; }

.filters section { margin-bottom: .9rem; }
.settings-section { margin-bottom: 1.4rem; }
.settings-section > h3 { border-bottom: 1px solid var(--border); padding-bottom: .3rem; margin-bottom: .6rem; }

/* ---------- modales et notifications ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 16, 26, .5);
  display: grid; place-items: center;
  padding: 1rem;
  z-index: 3000;
}
.modal {
  width: min(560px, 100%);
  max-height: min(88vh, 100%);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-wide { width: min(920px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .7rem .9rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 1rem; }
.modal-body { padding: .9rem; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: .4rem; padding: .7rem .9rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.modal-text { font-size: .92rem; }
.help ul { margin: .2rem 0 .6rem 1.1rem; padding: 0; }

.toast-host {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(1rem + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: .4rem;
  z-index: 4000;
  width: min(440px, calc(100vw - 2rem));
}
.toast {
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem .7rem;
  border-radius: 9px;
  background: #1f2937; color: #fff;
  box-shadow: var(--shadow);
  font-size: .87rem;
}
.toast-ok { background: #15803d; }
.toast-error { background: #b91c1c; }
.toast-msg { flex: 1; }
.toast-close { background: none; border: 0; color: inherit; font-size: 1.1rem; cursor: pointer; line-height: 1; }

/* ---------- marqueurs ---------- */

.dc-pin { background: none; border: 0; }
.pin-body {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--pin, #0b6bcb);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
  position: relative;
}
.pin-glyph { transform: rotate(45deg); color: #fff; font-size: 12px; line-height: 1; }
.pin-star { position: absolute; top: -9px; left: -7px; transform: rotate(45deg); color: #eab308; font-size: 13px; text-shadow: 0 0 2px #000; }
.pin-badge {
  position: absolute; top: -8px; right: -8px;
  transform: rotate(45deg);
  min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 8px;
  background: #111827; color: #fff;
  font-size: 10px; line-height: 15px; text-align: center;
  border: 1px solid #fff;
}
.dc-pin.is-selected .pin-body { outline: 3px solid var(--primary); outline-offset: 2px; }
.popup-sub { color: #555; font-size: .82rem; }
.popup-meta { font-size: .8rem; }

.leaflet-container { font: inherit; background: var(--surface-2); }
html[data-theme="dark"] .leaflet-tile { filter: brightness(.85); }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  :root { --sidebar-w: 100%; --detail-w: 100%; }
  .brand-text { display: none; }
  .layout { position: relative; }
  .sidebar {
    position: absolute;
    inset: 0;
    /* Au-dessus des controles Leaflet, qui montent a z-index 1000. */
    z-index: 1050;
    border-right: 0;
  }
  body:not(.sidebar-open) .sidebar { margin-left: 0; display: none; }
  .detail-panel { border-left: 0; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-group { grid-template-columns: 1fr; }
  .topbar { padding: 0 .4rem; gap: .35rem; }
  .search { height: 34px; }
}

@media (max-width: 420px) {
  .brand { display: none; }
  .fields { grid-template-columns: 1fr; }
  .topbar-actions .btn { padding: .32rem .5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- fenetre « Sources de donnees » ---------- */

.sources .source-block {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: .7rem .8rem;
}
.sources .source-block > h3 { margin-bottom: .3rem; }
.country-bar { margin-bottom: .4rem; }
.country-grid {
  max-height: 190px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .4rem .5rem;
  background: var(--surface-2);
}
.progress-zone {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: .6rem .8rem;
  background: var(--surface-2);
}
.progress-zone .meter { margin-bottom: .4rem; }
.progress-zone p:last-child { margin-bottom: 0; }

.map-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.map-table th, .map-table td {
  text-align: left;
  padding: .3rem .4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.map-table th { color: var(--text-muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; }
.map-table td:first-child { font-weight: 600; }
.map-table td:nth-child(2) { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-table select { min-width: 170px; }

/* ---------- choix d'un point sur la carte ---------- */

body.picking-point .leaflet-container { cursor: crosshair; }
body.picking-point .leaflet-marker-icon { cursor: move; }

.map-picker {
  position: fixed;
  top: calc(var(--topbar-h) + .6rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1300;
  display: flex;
  align-items: center;
  gap: .6rem;
  max-width: calc(100vw - 1.2rem);
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: .88rem;
}
.map-picker-label { color: var(--text-muted); }
.map-picker-coords {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 620px) {
  .map-picker { flex-wrap: wrap; justify-content: center; text-align: center; }
}
