/* ==========================================================================
   Map page — Leaflet with satellite tiles + project/output markers
   ========================================================================== */

.map-app {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 0;
  height: calc(100vh - 200px);
  min-height: 620px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: #fff;
  margin-top: 12px;
}

/* -------- Sidebar -------- */
.map-sidebar {
  background: #fff;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
}

.map-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 10px 12px;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-elev) 100%);
  color: #e2e8f0;
}
.map-stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.map-stats strong {
  font-size: 18px;
  color: #fff;
  font-weight: 700;
  margin-bottom: 2px;
}

.map-search {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.map-search input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: var(--panel-soft);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.map-search input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.map-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
}
.map-filters label {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.map-filters label > span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}
.map-filters select {
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.map-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.map-list li {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.12s;
  display: grid;
  gap: 4px;
}
.map-list li:hover { background: #eff6ff; }
.map-list li.is-active {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}
.map-list .item-name {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.25;
}
.map-list .item-place {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.map-list .item-place::before { content: "📍"; font-size: 10px; }

.map-list .badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 3px;
}
.map-badge {
  font-size: 9.5px;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}
.map-badge.project { background: var(--accent-soft); color: #1e40af; }
.map-badge.output  { background: #fef3c7; color: #92400e; }
.map-badge.tag     { background: var(--border-soft); color: var(--text-soft); }

.map-list .empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* -------- Map -------- */
.map-wrapper {
  position: relative;
  min-height: 0;
}
#map {
  width: 100%;
  height: 100%;
  background: #0b1220;
}

/* Custom markers */
.point-marker {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
.point-marker.project { background: #3b82f6; }
.point-marker.output  { background: #f59e0b; }

/* -------- Popups -------- */
.leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  padding: 0;
  overflow: hidden;
}
.leaflet-popup-content {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  min-width: 260px;
  max-width: 320px;
}
.popup { display: flex; flex-direction: column; }
.popup-header {
  padding: 12px 14px 10px;
  background: linear-gradient(135deg, var(--bg-elev) 0%, #334155 100%);
  color: #fff;
}
.popup-header.output {
  background: linear-gradient(135deg, #92400e 0%, #b45309 100%);
}
.popup-kind {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 4px;
}
.popup-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0;
}
.popup-place {
  font-size: 12px;
  color: #cbd5e1;
  margin-top: 4px;
}
.popup-body {
  padding: 12px 14px;
  color: var(--text);
  max-height: 340px;
  overflow-y: auto;
}
.popup-desc {
  margin-bottom: 10px;
  color: var(--text-soft);
}
.popup-fields {
  display: grid;
  gap: 5px;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.popup-field {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 6px;
}
.popup-field-label {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 9.5px;
  letter-spacing: 0.5px;
  font-weight: 600;
  padding-top: 1px;
}
.popup-field-value {
  color: var(--text);
  word-break: break-word;
}
.popup-field-value a { color: var(--accent); }

.popup-footer { padding: 8px 14px 12px; }
.popup-btn {
  display: inline-block;
  padding: 7px 14px;
  background: var(--accent);
  color: #fff !important;
  border-radius: 6px;
  text-decoration: none !important;
  font-weight: 600;
  font-size: 12px;
  transition: background 0.15s;
}
.popup-btn:hover { background: var(--accent-hover); }

/* Related outputs section in project popup */
.popup-related {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.popup-noouts {
  font-size: 11.5px;
  color: var(--text-muted);
  font-style: italic;
}
.open-outputs-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent-orange) 0%, var(--accent-orange-hover) 100%);
  color: #fff;
  border: none;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.3);
}
.open-outputs-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.45);
}
.open-outputs-count {
  background: rgba(255, 255, 255, 0.25);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

/* Back-to-parent-project link in output popup */
.popup-back { margin-bottom: 10px; }
.back-link {
  background: var(--accent-soft);
  border: 1px solid #bfdbfe;
  color: #1e40af;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.12s;
}
.back-link:hover { background: #bfdbfe; }

/* Leaflet controls dark */
.leaflet-control-zoom a {
  background-color: rgba(15, 23, 42, 0.85) !important;
  color: #e2e8f0 !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
}
.leaflet-control-zoom a:hover {
  background-color: rgba(30, 41, 59, 0.95) !important;
  color: #fff !important;
}
.leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.75) !important;
  color: #cbd5e1 !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: #93c5fd !important; }

/* Cluster with glow */
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: rgba(37, 99, 235, 0.85) !important;
  color: #fff !important;
  font-weight: 700 !important;
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
}
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: rgba(37, 99, 235, 0.25) !important;
}

/* ---------- Outputs modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.is-open { display: flex; animation: modalFade 0.18s ease-out; }
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal-panel {
  position: relative;
  background: #fff;
  border-radius: 14px;
  max-width: 1020px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  animation: modalSlide 0.22s ease-out;
}
@keyframes modalSlide {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 22px 14px;
  background: linear-gradient(135deg, var(--bg-elev) 0%, #334155 100%);
  color: #fff;
}
.modal-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.75;
  margin-bottom: 3px;
}
.modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
}
.modal-sub {
  font-size: 12px;
  color: #cbd5e1;
  margin-top: 3px;
}
.modal-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 34px; height: 34px;
  font-size: 22px; line-height: 30px;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s;
}
.modal-close:hover { background: rgba(255, 255, 255, 0.2); }
.modal-body {
  padding: 16px 22px 22px;
  overflow-y: auto;
  flex: 1;
}
.modal-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.outputs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.outputs-table thead {
  background: var(--panel-soft);
  color: var(--text-soft);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.5px;
}
.outputs-table th,
.outputs-table td {
  padding: 11px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-soft);
}
.outputs-table tbody tr:hover { background: #fffbeb; }
.outputs-table tbody tr:last-child td { border-bottom: none; }
.tbl-title {
  font-weight: 600;
  color: var(--text);
  min-width: 160px;
}
.tbl-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.tbl-desc {
  color: var(--text-soft);
  max-width: 320px;
  font-size: 12px;
  line-height: 1.45;
}
.tbl-actions {
  white-space: nowrap;
  display: flex;
  gap: 6px;
}
.tbl-action {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: none !important;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.tbl-link {
  background: var(--accent);
  color: #fff !important;
  border-color: var(--accent);
}
.tbl-link:hover { background: var(--accent-hover); }
.tbl-map {
  background: #fff;
  color: var(--accent);
  border-color: var(--accent);
}
.tbl-map:hover { background: var(--accent-soft); }
.modal-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 10px;
  font-size: 14px;
}

/* Responsive */
@media (max-width: 900px) {
  .map-app {
    grid-template-columns: 1fr;
    grid-template-rows: 260px 1fr;
    height: auto;
    min-height: 760px;
  }
  .map-sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  #map { min-height: 520px; }
}
@media (max-width: 640px) {
  .modal-panel { max-height: 92vh; }
  .modal-head { padding: 14px 16px 10px; }
  .modal-body { padding: 12px 14px 18px; }
  .outputs-table th, .outputs-table td { padding: 9px 10px; font-size: 12px; }
  .tbl-desc { max-width: none; }
}
