/* =========================================================
   VARIABLES GLOBALES
   ========================================================= */
@font-face {
  font-family: 'PP Fragment';
  src: url('fonts/PPFragment-GlareExtraBold.otf') format('opentype');
  font-style: normal;
  font-weight: 800;
  font-display: swap;
}

:root {
  --primary-color: #0d3380;
  --secondary-color: #439543;
  --background-color: #f7f3eb;
  --header-height: 78px;

  --btn-size-desktop: 30px;
  --btn-size-mobile: 40px;

  --radius: 6px;
  --transition: 0.25s ease;
}

/* =========================================================
   RESET & BASE
   ========================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--background-color);
  color: #003366;
  overflow-x: hidden;
  touch-action: pan-x pan-y;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  caret-color: transparent !important;
  outline: none;
}

button *,
[role="button"],
[role="button"] * {
  user-select: none;
  -webkit-user-select: none;
  caret-color: transparent !important;
}

button:focus,
button:focus-visible,
button[type="button"]:focus-visible {
  outline: 2px solid rgba(13, 51, 128, 0.35);
  outline-offset: 2px;
}

/* =========================================================
   HEADER
   ========================================================= */
header {
  position: relative;
  z-index: 12001;
  height: var(--header-height);
  margin: 5px;
  padding: 0 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
}

.logo {
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo-link {
  display: inline-flex;
  flex-shrink: 0;
  border-radius: 4px;
}

.logo-link:focus-visible {
  outline: 2px solid rgba(13, 51, 128, 0.45);
  outline-offset: 3px;
}

.title-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  width: max-content;
  overflow: visible;
}

.logo_entre {
  display: block;
  width: 180px;
  flex-shrink: 0;
}

.titre {
  margin: 0;
  font-family: 'PP Fragment', Georgia, serif;
  font-size: 20px;
  font-weight: 800;
  color: var(--primary-color);
  white-space: nowrap;
}

.sous-titre {
  margin: 0;
  font-family: inherit;
  font-weight: 400;
  font-size: 12px;
  margin-left: 100%;
  align-self: flex-start;
  text-align: left;
  white-space: nowrap;
}

/* =========================================================
   BARRE DE RECHERCHE
   ========================================================= */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  margin-left: auto;
  order: 2;
}

#address-input {
  width: 340px;
  padding: 8px 38px 8px 12px;
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 20px;
  outline: none;
  box-shadow: none;
  appearance: none;
}

#address-input:focus {
  border-color: #ccc;
  outline: none;
  box-shadow: none;
}

.search-btn {
  position: absolute;
  right: 2px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Liste de suggestions d'adresses */
.address-suggestions-list {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  max-height: 250px;
  overflow-y: auto;
  z-index: 1001;
  border: 1px solid #e0e0e0;
}

.suggestion-item {
  padding: 10px 15px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover {
  background: #f5f5f5;
}

.suggestion-item:active {
  background: #e3f2fd;
}

/* =========================================================
   CARTE
   ========================================================= */
#map-container {
  position: relative;
  height: calc(100vh - var(--header-height) - 10px);
  overflow: hidden;
}

.map {
  display: block;
  width: 100%;
  height: calc(100vh - var(--header-height) - 10px);
  padding-left: 0;
}

#map,
#map .ol-viewport {
  width: 100% !important;
  height: 100% !important;
}

/* =========================================================
   BOUTONS DE CONTRÔLE (COMMUN)
   ========================================================= */
.myButton,
.controls button,
.plein_ecran #plein_ecran {
  display: none !important;
}

.myButton:hover,
.controls button:hover,
.plein_ecran #plein_ecran:hover {
  background: rgba(0, 60, 136, 1);
}

/* =========================================================
   POSITIONS DES BOUTONS
   ========================================================= */
#zoButton,
#ziButton,
#homeButton,
#measure-distance,
#measure-area,
#measure-triangle,
#clear-measurements,
#plein_ecran {
  display: none !important;
}

/* =========================================================
   ICÔNES
   ========================================================= */
.button-icon {
  width: 20px;
  height: 20px;
  filter: brightness(0) invert(1);
}

/* =========================================================
   SÉLECTEUR DE FOND DE CARTE
   ========================================================= */
.image-container {
  position: absolute;
  top: 115px;
  right: 26px;
  width: var(--btn-size-desktop);
  height: var(--btn-size-desktop);
  z-index: 1000;
}

.layer-icon {
  width: 28px;
}

.dropdown-menu {
  position: absolute;
  left: -150px;
  top: 0;
  display: none;
  z-index: 1001;
  border-radius: 10px;
}

.image-container:hover .dropdown-menu {
  display: block;
}

.dropdown-menu ul {
  list-style: none;
  padding: 10px;
  margin: 0;
  background: #f8f9ff;
  border-radius: 10px;
  width: 180px;
}

.section-title {
  font-weight: bold;
  color: var(--primary-color);
  margin-bottom: 8px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
  transition: background 0.2s;
  line-height: 1.2;
}

.layer-toggle:hover {
  background: rgba(0, 102, 204, 0.1);
}

.layer-toggle input[type="radio"] {
  cursor: pointer;
  margin: 0;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.layer-toggle label {
  cursor: pointer;
  flex: 1;
  margin: 0;
  font-size: 13px;
  line-height: 1.2;
  display: flex;
  align-items: center;
}

/* =========================================================
   TOOLTIP MESURE
   ========================================================= */
.measure-tooltip {
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}

/* =========================================================
   RESPONSIVE MOBILE
   ========================================================= */
@media (max-width: 768px) {
  :root {
    --header-height: 60px;
  }

  header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .logo_entre {
    width: 100px;
  }
  .titre {
    font-size: 16px;
  }

  #address-input {
    width: 180px;
  }

  .map {
    height: 70vh;
    padding-left: 0;
  }

  #map-container {
    height: 70vh;
  }

  .myButton,
  .controls button,
  .plein_ecran #plein_ecran {
    width: var(--btn-size-mobile);
    height: var(--btn-size-mobile);
    top: auto;
    bottom: 20px;
  }
}

/* =========================================================
   PERFORMANCE & ACCESSIBILITÉ
   ========================================================= */
@media (hover: none) {
  *:hover {
    background-color: inherit !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* =========================================================
   PLEIN ÉCRAN
   ========================================================= */
:fullscreen,
:-webkit-full-screen,
:-moz-full-screen,
:-ms-fullscreen {
  width: 100% !important;
  height: 100% !important;
}

:fullscreen .map,
:-webkit-full-screen .map,
:-moz-full-screen .map,
:-ms-fullscreen .map {
  height: 100vh !important;
  width: 100% !important;
  padding-left: 0 !important;
}

:fullscreen #map-container,
:-webkit-full-screen #map-container,
:-moz-full-screen #map-container,
:-ms-fullscreen #map-container {
  width: 100% !important;
  height: 100vh !important;
}

:fullscreen header,
:-webkit-full-screen header,
:-moz-full-screen header,
:-ms-fullscreen header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  background: rgba(255, 255, 255, 0.95);
  margin: 0;
  padding: 0 15px;
}

@media (max-width: 768px) {
  :fullscreen .floating-toolbar,
  :-webkit-full-screen .floating-toolbar,
  :-moz-full-screen .floating-toolbar,
  :-ms-fullscreen .floating-toolbar {
    bottom: 30px;
    transform: translateX(-50%) scale(1.1);
  }
}

/* =========================================================
   POPUP FEATURE
   ========================================================= */
.feature-popup {
  position: fixed;
  top: 95px;
  left: 20px;
  width: 300px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 125px);
  display: none;
  flex-direction: column;
  background-color: white;
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.18);
  border-radius: 10px;
  overflow: hidden;
  z-index: 10000;
}

.feature-popup.is-active {
  display: flex;
}

.popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 10px;
  font-size: 14px;
  border-bottom: 2px solid var(--primary-color);
  padding: 10px 14px;
  background: #f8f9fa;
}

.popup-close-btn {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #6b7280;
  background: #f3f4f6;
  font-size: 13px;
  line-height: 1;
}

.popup-close-btn:hover,
.popup-close-btn:focus-visible {
  color: #1f2937;
  background: #e5e7eb;
}

.popup-body {
  font-size: 13px;
  padding: 4px 14px 14px;
  overflow-y: auto;
}

.popup-body p {
  margin: 8px 0;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.popup-btn {
  margin-top: 10px;
  padding: 8px 15px;
  background: var(--secondary-color);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  width: 100%;
}

.popup-btn:hover {
  background: #357a35;
}

/* =========================================================
   INFO SECTIONS
   ========================================================= */
.info-section {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e0e0e0;
}

.info-section:last-child {
  border-bottom: none;
}

.info-section h4 {
  color: var(--primary-color);
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}

.info-section p {
  margin: 5px 0;
  font-size: 13px;
  line-height: 1.5;
}

/* =========================================================
   ATTRIBUTS TABLE
   ========================================================= */
.attr-header {
  background: #f5f5f5;
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 15px;
  font-size: 14px;
}

.attr-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 15px;
}

.attr-table tr {
  border-bottom: 1px solid #e0e0e0;
}

.attr-table tr:last-child {
  border-bottom: none;
}

.attr-key {
  padding: 10px 8px;
  font-weight: 600;
  color: #555;
  font-size: 12px;
  width: 40%;
  vertical-align: top;
}

.attr-value {
  padding: 10px 8px;
  color: #333;
  font-size: 13px;
}

.attr-actions {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* =========================================================
   LOADING & MESSAGES
   ========================================================= */
.loading,
.error-message,
.info-message {
  text-align: center;
  padding: 30px 20px;
  color: #666;
}

.error-message {
  color: #d32f2f;
}

.error-message i {
  font-size: 24px;
  margin-bottom: 10px;
  display: block;
}

.info-message i {
  font-size: 48px;
  color: #ccc;
  margin-bottom: 15px;
  display: block;
}

/* =========================================================
   SÉLECTION MULTIPLE
   ========================================================= */
.selection-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
}

.selection-table-container {
  max-height: 300px;
  overflow: auto;
  border: 1px solid #dee2e6;
  border-radius: 8px;
}

.selection-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.selection-table th {
  background: var(--primary-color);
  color: white;
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  position: sticky;
  top: 0;
}

.selection-table td {
  padding: 8px;
  border-bottom: 1px solid #dee2e6;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-table tr:hover {
  background: #f8f9fa;
}

.selection-help {
  margin-top: 15px;
  padding: 10px;
  background: #e7f3ff;
  border-radius: 8px;
  font-size: 12px;
}

/* =========================================================
   ÉDITION
   ========================================================= */
.edit-toolbar {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.edit-section h4 {
  font-size: 14px;
  color: #666;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.edit-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.edit-tool {
  width: 45px;
  height: 45px;
  border: 2px solid #dee2e6;
  border-radius: 10px;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.edit-tool:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.edit-tool.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
}

.edit-tool i {
  font-size: 18px;
}

/* Panneau de style d'édition */
.edit-style-panel {
  position: fixed;
  top: 100px;
  right: 20px;
  width: 250px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  z-index: 3200;
  padding: 15px;
  display: none;
}

.edit-style-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.edit-style-header h4 {
  margin: 0;
  font-size: 14px;
  color: var(--primary-color);
}

.edit-style-header button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
}

.style-group {
  margin-bottom: 12px;
}

.style-group label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

.style-group input[type="text"],
.style-group input[type="range"],
.style-group input[type="color"] {
  width: 100%;
  padding: 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
}

.style-actions {
  margin-top: 15px;
  padding-top: 10px;
  border-top: 1px solid #eee;
}

/* =========================================================
   SELECTION DE COUCHES ET FORMULAIRES
   ========================================================= */
.layer-selection-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
}

.btn-back {
  padding: 8px 12px;
  border: none;
  border-radius: 5px;
  background: #6c757d;
  color: white;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
  -webkit-user-select: none;
  caret-color: transparent;
  outline: none;
}

.btn-back:hover {
  background: #5a6268;
}

.btn-back i {
  user-select: none;
  -webkit-user-select: none;
  caret-color: transparent;
  pointer-events: none;
}

.add-geometry-info {
  margin-bottom: 15px;
}

.badge {
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 12px;
  font-weight: 500;
}

.badge-info {
  background: #17a2b8;
  color: white;
}

.add-form-container {
  /*max-height: 400px;*/ /* Ajusté pour permettre plus de contenu sans être trop restrictif */
  overflow-y: auto;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  color: #333;
  font-size: 13px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.3s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* =========================================================
   MISE EN PAGE
   ========================================================= */
.layout-options {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
}

.layout-option label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  color: #555;
  font-size: 13px;
}

.layout-option input[type="text"],
.layout-option select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  font-size: 14px;
}

.layout-option input[type="checkbox"] {
  margin-right: 8px;
}

.layout-actions {
  display: flex;
  gap: 10px;
}

/* Aperçu mise en page */
.layout-preview {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.preview-container {
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.preview-container.portrait {
  width: 70vh;
  height: 90vh;
}

.preview-container.paysage {
  width: 90vw;
  height: 70vw;
  max-height: 80vh;
}

.preview-header {
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-color);
}

.preview-header h2 {
  margin: 0;
  color: var(--primary-color);
}

.preview-meta {
  margin-top: 10px;
  font-size: 12px;
  color: #666;
}

.preview-map {
  width: 100%;
  height: 60%;
  background: #e8f4f8;
  border: 1px solid #ccc;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 18px;
}

.preview-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  padding-top: 10px;
  border-top: 1px solid #e0e0e0;
}

.preview-legend,
.preview-scale {
  background: #f5f5f5;
  padding: 10px;
  border-radius: 5px;
  font-size: 12px;
}

.preview-north {
  background: #f5f5f5;
  padding: 10px;
  border-radius: 50%;
  font-weight: bold;
  font-size: 14px;
}

/* =========================================================
   BOUTONS
   ========================================================= */
.panel-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 15px;
  background: var(--secondary-color);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 0.2s;
}

.panel-btn:hover {
  background: #357a35;
}

.panel-btn.cancel-btn {
  background: #dc3545;
}

.panel-btn.cancel-btn:hover {
  background: #c82333;
}

.panel-btn.delete-btn {
  background: #dc3545;
}

.panel-btn.delete-btn:hover {
  background: #c82333;
}

.panel-btn.btn-small {
  padding: 5px 10px;
  font-size: 12px;
  width: auto;
}

/* =========================================================
   NOTIFICATIONS
   ========================================================= */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 15px 20px;
  background: var(--secondary-color);
  color: white;
  border-radius: 5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10001;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.notification.show {
  transform: translateX(0);
}

.notification.error {
  background: #dc3545;
}

.notification.info {
  background: #17a2b8;
}

.menelik-attribution {
  right: 8px;
  bottom: 8px;
  max-width: min(320px, calc(100vw - 24px));
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
  font-size: 11px;
}

.menelik-attribution.ol-collapsed {
  background: transparent;
  box-shadow: none;
}

.menelik-attribution.ol-collapsed ul {
  display: none;
}

.menelik-attribution ul {
  margin: 0;
  padding: 0 4px;
}

.menelik-attribution button {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-weight: 700;
  line-height: 20px;
  color: #0d3380;
  background: rgba(255, 255, 255, 0.96);
}

.menelik-attribution:not(.ol-collapsed) {
  padding: 2px 6px;
}

.menelik-attribution:not(.ol-collapsed) button {
  margin-left: 6px;
}

/* =========================================================
   CURSEUR CARTE
   ========================================================= */
.map .ol-layer canvas {
  cursor: pointer;
}

.ol-selectable {
  cursor: pointer;
}

/* Visible credits for the active map, outside the offcanvas panels. */
#map-attribution {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 11001;
  max-width: calc(100vw - 85px);
  background: transparent;
  font-size: 10px;
}
#map-attribution .ol-attribution {
  position: static;
  margin: 0;
  border-radius: 6px;
}
