*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem 1.8rem;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 40' preserveAspectRatio='none'%3E%3Cpath d='M0 20 Q 72 0, 144 20 T 288 20 T 432 20 T 576 20 T 720 20 T 864 20 T 1008 20 T 1152 20 T 1296 20 T 1440 20 L 1440 40 L 0 40 Z' fill='%231967d2'/%3E%3C/svg%3E") 0 100% / 100% 20px no-repeat,
    var(--wa-color-neutral-0);
  color: #222;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
}

.brand-icon {
  font-size: 2rem;
  color: var(--wa-color-primary-600);
}

.app-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.2;
}

.app-title wa-icon {
  margin-right: 0.4rem;
  vertical-align: -0.1em;
}

.app-subtitle {
  font-size: 0.7rem;
  color: var(--wa-color-neutral-500);
  font-weight: 400;
}

.header-filters {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
  max-width: 320px;
  flex-shrink: 0;
}

.header-filters wa-combobox {
  width: 100%;
}

.header-filters wa-combobox::part(input) {
  background: white;
  color: #222;
  font-size: 0.85rem;
  border-color: var(--wa-color-neutral-300);
}

.header-filters wa-combobox::part(input)::placeholder {
  color: var(--wa-color-neutral-400);
}

.header-filters wa-combobox::part(tag) {
  background: var(--wa-color-neutral-100);
  color: #222;
}

.reset-link {
  font-size: 0.75rem;
  color: #555;
  text-decoration: underline;
  align-self: flex-end;
}

.reset-link:hover {
  color: #222;
}

.layer-toggles {
  display: none;
}

.main-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
}

.map-wrapper {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  transition: flex 0.3s ease;
}

.map-container {
  flex: 1;
  min-height: 0;
  position: relative;
}

.detail-panel {
  width: 0;
  overflow: hidden;
  background: var(--wa-color-neutral-0);
  border-right: 1px solid var(--wa-color-neutral-100);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  flex-shrink: 0;
}

.detail-panel.open {
  width: 380px;
}

.detail-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--wa-color-neutral-100);
  flex-shrink: 0;
}

.detail-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.detail-panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  color: var(--wa-color-neutral-500);
  text-align: center;
  gap: 0.5rem;
  height: 100%;
}

.detail-empty p {
  margin: 0;
  font-size: 0.85rem;
}

.water-detail {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
}

.detail-header h2 {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
}

.detail-badges {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.detail-meta {
  font-size: 0.875rem;
  color: var(--wa-color-neutral-600);
}

.detail-section h3 {
  margin: 0 0 0.4rem 0;
  font-size: 0.9rem;
  color: var(--wa-color-neutral-700);
}

.detail-description,
.detail-text {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--wa-color-neutral-600);
}

.detail-rules {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.rule-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--wa-color-neutral-100);
}

.rule-label {
  font-size: 0.85rem;
  color: var(--wa-color-neutral-700);
}

.detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.detail-footer {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--wa-color-neutral-100);
  color: var(--wa-color-neutral-400);
  font-size: 0.75rem;
}

.leaflet-popup-content-wrapper {
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.leaflet-popup-content {
  margin: 8px 10px;
  font-family: inherit;
}

.leaflet-popup-content h3 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--wa-color-neutral-900);
  line-height: 1.3;
}

.leaflet-popup-content .popup-org {
  font-size: 12px;
  color: var(--wa-color-neutral-500);
  margin: 0 0 4px 0;
}

.leaflet-popup-content .popup-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  margin-top: 2px;
}

/* Floating map tools from the bottom-right */
.map-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  display: flex;
  gap: 0.3rem;
}

.map-tools wa-button::part(base) {
  background: white;
  color: #333;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

/* Debug bar — full width, raw text */
.debug-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.65rem;
  color: var(--wa-color-neutral-400);
  background: var(--wa-color-neutral-0);
  border-top: 1px solid var(--wa-color-neutral-100);
}

.layer-toggles {
  display: flex;
  gap: 0.2rem;
  flex-wrap: nowrap;
}

.toggle-tag {
  cursor: pointer;
  user-select: none;
  opacity: 0.4;
  transition: opacity 0.1s;
  font-size: 0.72rem;
  white-space: nowrap;
}

.toggle-tag.active {
  opacity: 1;
}

.toggle-tag:hover {
  opacity: 0.8;
}

.location-marker {
  background: none !important;
  border: none !important;
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    padding: 0.5rem 0.6rem;
    gap: 0.4rem;
  }

  .header-filters {
    max-width: none;
  }

  .app-title {
    font-size: 1rem;
  }

  .debug-info {
    display: none;
  }

  .main-area {
    position: relative;
  }

  .detail-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0;
    width: 100% !important;
    z-index: 2000;
    border-radius: 14px 14px 0 0;
    border-right: none;
    border-top: 1px solid var(--wa-color-neutral-200);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
    transition: height 0.3s ease;
    overflow: hidden;
    background: #fff;
  }

  .detail-panel.open {
    height: 55vh;
    min-width: 0;
  }

  .detail-panel.expanded {
    height: 92vh;
  }

  .detail-panel-header {
    cursor: pointer;
    user-select: none;
    padding-top: 0.8rem;
  }

  .detail-panel-header::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: var(--wa-color-neutral-300);
    border-radius: 2px;
  }

  .map-tools {
    z-index: 2500;
  }
}

.map-loader {
  position: absolute;
  inset: 0;
  z-index: 999;
  background: #f6f7f8;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s;
}

.map-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.skeleton-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 90%;
  height: 90%;
}

.skeleton-row {
  height: 16px;
  border-radius: 6px;
  background: #eef0f1;
  animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-row.short { width: 80%; }
.skeleton-row.shorter { width: 55%; }

.skeleton-block {
  height: 100%;
  border-radius: 8px;
  background: #eef0f1;
  animation: pulse 1.5s ease-in-out infinite;
  flex: 1;
}

.skeleton-block.small { flex: 0.5; }
.skeleton-block.medium { flex: 1.2; }

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.9; }
}

.custom-pin {
  width: 18px;
  height: 18px;
  background: var(--wa-color-primary-600);
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  cursor: pointer;
}

.pin-tooltip {
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  padding: 12px 14px;
  min-width: 200px;
  font-family: inherit;
  position: relative;
}

.pin-tooltip h3 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
}

.pin-tooltip .pin-org {
  font-size: 12px;
  color: var(--wa-color-neutral-500);
  margin: 0 0 6px 0;
}

.pin-tooltip .pin-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.pin-tooltip .pin-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--wa-color-neutral-100);
  justify-content: flex-end;
}

.pin-tooltip .pin-link {
  font-size: 11px;
  color: var(--wa-color-primary-600);
  text-decoration: none;
  cursor: pointer;
}

.pin-tooltip .pin-link:hover {
  text-decoration: underline;
}
