/* =============================================================================
   CB-CIS v2.4 — Application SIG & Cartographique (map-app.css)
   Conforme aux maquettes v2.4 (Thème clair & Thème sombre)
   ============================================================================= */

/* ---------------------------------------------------------------------------
   App Shell & Reset
   --------------------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-canvas);
}

/* ---------------------------------------------------------------------------
   Header Flottant Institutionnel (64px)
   --------------------------------------------------------------------------- */
#app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--navbar-bg);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border-bottom: 1px solid var(--navbar-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-4);
  z-index: var(--z-header);
  flex-shrink: 0;
  box-shadow: var(--shadow-card);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  flex-shrink: 0;
}

.header-logo-img {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.header-title {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.header-title .acronym {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: var(--weight-extrabold);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.header-title .full-name {
  font-size: var(--text-micro);
  font-weight: 400;
  color: var(--text-muted);
}

.header-title .full-name strong {
  color: var(--text-secondary);
  font-weight: var(--weight-semibold);
}

/* Recherche rapide */
.header-search {
  flex: 1;
  max-width: 380px;
  position: relative;
}

.header-search input {
  width: 100%;
  height: 38px;
  padding: 0 2.25rem 0 2.5rem;
  background: var(--surface-glass);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-size: var(--text-small);
  transition: all var(--transition-mid);
}

.header-search input::placeholder {
  color: var(--text-muted);
}

.header-search input:focus {
  background: var(--surface-solid);
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-light);
}

.header-search .search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.header-search .search-clear {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg-canvas-alt);
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
}

.header-search .search-clear:hover {
  background: var(--border-hairline);
  color: var(--text-primary);
}

.search-results-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface-glass-elevated);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  max-height: 320px;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  display: none;
}

.search-results-dropdown.visible {
  display: block;
}

.search-result-item {
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  border-bottom: 1px solid var(--border-hairline);
  transition: background var(--transition-fast);
}

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

.search-result-item:hover {
  background: var(--brand-primary-light);
}

.search-result-name {
  font-size: var(--text-small);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.search-result-meta {
  font-size: var(--text-micro);
  color: var(--text-muted);
  margin-top: 1px;
}

.search-no-results {
  padding: var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-small);
}

/* Statistiques du bassin (inline dans le Header) */
.header-stats {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-left: auto;
  flex-shrink: 0;
}

.stat-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-body);
  font-weight: var(--weight-extrabold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* Actions Header */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.btn-header {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.4rem 0.75rem;
  height: 34px;
  background: var(--surface-glass);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-small);
  font-weight: var(--weight-medium);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.btn-header:hover {
  background: var(--bg-canvas-alt);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

#btn-data-saver.active {
  background: var(--status-success-bg);
  border-color: var(--status-success);
  color: var(--status-success);
  font-weight: var(--weight-semibold);
}

.services-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0.35rem 0.65rem;
  background: var(--surface-glass);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-full);
  font-size: var(--text-micro);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

#services-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-success);
}

/* ---------------------------------------------------------------------------
   App Body & Panels
   --------------------------------------------------------------------------- */
#app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Map Container */
#map {
  flex: 1;
  height: 100%;
  z-index: 1;
  background: var(--bg-canvas);
}

/* ---------------------------------------------------------------------------
   Left Panel — Couches & Légende (300px)
   --------------------------------------------------------------------------- */
#panel-left {
  width: var(--panel-left-width);
  height: 100%;
  background: var(--surface-glass-elevated);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: var(--shadow-card);
  z-index: var(--z-panel);
  transition: width var(--transition-mid);
  overflow: hidden;
}

#panel-left.collapsed {
  width: 0;
  border-right: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-solid);
  border-bottom: 1px solid var(--border-hairline);
  color: var(--text-primary);
  flex-shrink: 0;
}

.panel-title {
  font-family: var(--font-display);
  font-size: var(--text-small);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-primary);
}

.panel-toggle-btn {
  background: var(--bg-canvas-alt);
  border: 1px solid var(--border-hairline);
  color: var(--text-secondary);
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.panel-toggle-btn:hover {
  background: var(--brand-primary);
  color: #FFFFFF;
  border-color: var(--brand-primary);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.section-accordion-header {
  padding: var(--space-2) var(--space-4);
  background: var(--bg-canvas-alt);
  border-top: 1px solid var(--border-hairline);
  border-bottom: 1px solid var(--border-hairline);
  font-size: var(--text-micro);
  font-weight: var(--weight-bold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.left-panel-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border-hairline);
  font-size: var(--text-micro);
  color: var(--text-muted);
  text-align: center;
}

.left-panel-footer .footer-inst {
  font-weight: var(--weight-bold);
  color: var(--brand-primary);
}

/* ---------------------------------------------------------------------------
   Right Panel — Fiche du Bassin Analytique (420px)
   --------------------------------------------------------------------------- */
#panel-right {
  width: var(--panel-right-width);
  height: 100%;
  background: var(--surface-glass-elevated);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border-left: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: var(--shadow-floating);
  z-index: var(--z-panel);
  transition: width var(--transition-mid);
  overflow: hidden;
}

#panel-right.collapsed {
  width: 0;
  border-left: none;
}

.catchment-sheet {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.catchment-header {
  padding: var(--space-4);
  background: var(--surface-solid);
  border-bottom: 1px solid var(--border-hairline);
}

.catchment-title {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.catchment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.meta-chip {
  background: var(--bg-canvas-alt);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-full);
  padding: 1px var(--space-2);
  font-size: 0.65rem;
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

/* 4 Chiffres Clés Maîtres */
.catchment-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-hairline);
}

.kpi-mini-card {
  padding: var(--space-2) var(--space-3);
  background: var(--surface-glass);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.kpi-mini-val {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: var(--weight-extrabold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.kpi-mini-val .unit {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.kpi-mini-label {
  font-size: 0.65rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Tab Content */
.tab-content-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

.section-title {
  font-size: var(--text-small);
  font-weight: var(--weight-bold);
  color: var(--brand-primary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: var(--space-3);
}

.data-split {
  display: flex;
  gap: var(--space-3);
}

.data-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.mini-chart-title {
  font-size: 0.65rem;
  font-weight: var(--weight-bold);
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: var(--space-1);
}

.data-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.data-item .label {
  font-size: var(--text-micro);
  color: var(--text-muted);
}

.data-item .val {
  font-family: var(--font-display);
  font-size: var(--text-small);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-micro);
}

.bar-row .label {
  width: 95px;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.bar-row .val {
  width: 45px;
  text-align: right;
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* Sols Grid */
.data-grid-sols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.sol-item {
  padding: var(--space-2);
  background: var(--surface-glass);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
}

.sol-item .label {
  font-size: 0.65rem;
  color: var(--text-muted);
  display: block;
}

.sol-item .val {
  font-family: var(--font-mono);
  font-size: var(--text-small);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.sol-item .val.highlight {
  color: var(--brand-primary);
  font-weight: var(--weight-bold);
}

/* Footer Actions in Sheet */
.catchment-footer-actions {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-hairline);
  background: var(--surface-solid);
}

/* ---------------------------------------------------------------------------
   Leaflet Controls & North Arrow
   --------------------------------------------------------------------------- */
.leaflet-control-north-arrow {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: var(--space-3) var(--space-3) 0 0 !important;
  color: var(--text-primary);
}

.leaflet-control-minimap {
  width: 140px;
  height: 105px;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: 0 var(--space-3) var(--space-8) 0 !important;
  box-shadow: var(--shadow-card);
}

#map-coords {
  position: absolute;
  bottom: 34px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  color: var(--text-secondary);
  z-index: 400;
  pointer-events: none;
}

/* Floating Basin Tooltip (Pill on centroid) */
.floating-basin-tooltip-wrapper {
  background: transparent !important;
  border: none !important;
}

.floating-basin-tooltip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px var(--space-3);
  border-radius: var(--radius-full);
  border: 1.5px solid var(--accent-active) !important;
  box-shadow: var(--shadow-floating);
  white-space: nowrap;
}

.floating-basin-tooltip .tooltip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-active);
  flex-shrink: 0;
}

.floating-basin-tooltip .tooltip-title {
  font-family: var(--font-display);
  font-size: var(--text-micro);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
}

.floating-basin-tooltip .tooltip-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-left: 2px;
}

/* ---------------------------------------------------------------------------
   App Minimal Footer (26px)
   --------------------------------------------------------------------------- */
#app-footer {
  height: 26px;
  min-height: 26px;
  background: var(--surface-glass);
  backdrop-filter: var(--backdrop-blur);
  border-top: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  font-size: var(--text-micro);
  color: var(--text-muted);
  z-index: var(--z-header);
}

#app-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  margin-left: var(--space-3);
}

#app-footer a:hover {
  color: var(--brand-primary);
}

/* ---------------------------------------------------------------------------
   Modal Styles
   --------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 25, 41, 0.65);
  backdrop-filter: blur(6px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-mid);
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--surface-solid);
  border-radius: var(--radius-xl);
  max-width: 650px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-elevated);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-hairline);
}

.modal-title-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  margin: 0;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-1);
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  font-size: var(--text-body-sm);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

.modal-section {
  margin-bottom: var(--space-4);
}

.modal-section h3 {
  font-size: var(--text-small);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  color: var(--brand-primary);
  margin-bottom: var(--space-2);
}

.modal-section ul {
  padding-left: var(--space-5);
}

.modal-section li {
  margin-bottom: var(--space-2);
}

.modal-footer {
  padding: var(--space-3) var(--space-6);
  border-top: 1px solid var(--border-hairline);
  display: flex;
  justify-content: flex-end;
}

/* ---------------------------------------------------------------------------
   Responsive & Bottom-Sheet Mobile
   --------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  :root {
    --panel-left-width: 260px;
    --panel-right-width: 360px;
  }
  .header-stats { display: none; }
}

@media (max-width: 768px) {
  :root {
    --header-height: 54px;
  }

  .mobile-toggle-btn { display: flex !important; }
  .header-search { max-width: 200px; }
  .btn-label { display: none; }

  #panel-left {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    height: 100%;
    z-index: 450;
    box-shadow: var(--shadow-elevated);
    transform: translateX(-100%);
    transition: transform var(--transition-mid);
  }

  #panel-left.mobile-visible {
    transform: translateX(0);
  }

  #panel-right {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 26px;
    top: auto;
    width: 100%;
    max-height: 48vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
    z-index: 500;
    transform: translateY(105%);
    transition: transform var(--transition-spring), max-height 0.3s ease;
    border-top: 1px solid var(--border-hairline);
    border-left: none;
  }

  #panel-right.active {
    transform: translateY(0);
  }

  #panel-right.expanded {
    max-height: 80vh;
  }

  .bottom-sheet-handle {
    display: block;
    width: 44px;
    height: 5px;
    background: var(--border-hairline);
    border-radius: 3px;
    margin: 8px auto 2px auto;
    cursor: pointer;
  }

  .leaflet-control-minimap { display: none; }
}

@media (max-width: 480px) {
  .header-brand .full-name { display: none; }
  .header-search { max-width: 140px; }
  #services-status-badge { display: none; }
  #btn-reset-view { display: none; }
}
