:root {
  --color-primary: #2d6a4f;
  --color-primary-dark: #1b4332;
  --color-secondary: #52b788;
  --color-accent: #d8f3dc;
  --color-cut: #9d4444;
  --color-cut-dark: #6d2828;
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-muted: #6c757d;
  --color-border: #e9ecef;
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
  --radius: 12px;
  --radius-lg: 20px;
  --transition: 0.2s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-border: #334155;
    --color-accent: #166534;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon { font-size: 1.75rem; }

.logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary);
}

.nav-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Botons com a enllaços */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-accent);
    color: var(--color-primary-dark);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.9rem;
    text-decoration: none; /*  Important per a <a> */
}

.btn:hover {
    background: var(--color-secondary);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Stats Bar */
.stats-bar {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  padding: 1.5rem 0;
  color: white;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
}

.stat-icon { font-size: 2rem; }

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.875rem;
  opacity: 0.9;
}

/* Controls */
.controls {
  padding: 1.5rem 0;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 400px;
}

.control-group label {
  font-weight: 600;
}

.modern-select {
  padding: 0.75rem 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.modern-select:focus {
  outline: none;
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 3px rgba(82, 183, 136, 0.2);
}

/* Map - OCUPA TOTA LA PART INFERIOR */
.map-wrapper {
  position: relative;
  width: 100%;
  height: calc(100vh - 280px);
  min-height: 500px;
  margin: 0 0 2rem 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

#map {
  width: 100%;
  height: 100%;
  background: var(--color-bg);
  z-index: 1;
}

/* Modal */
/* Modal amb <dialog> natiu */
.modern-modal {
    border: none;
    padding: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 90%;
    margin: auto;
}

.modern-modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.modal.active { display: flex; }

.modal-content {
    padding: var(--spacing-lg);
    position: relative;
}

@keyframes modalSlide {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.modal-header h2 {
  color: var(--color-primary);
  font-size: 1.5rem;
}

.modal-close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-muted);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.modal-body { padding: 1.5rem; }

.modal-body h2 {
    color: var(--color-primary);
    margin-bottom: 1rem;
}

.modal-body p {
    margin-bottom: 0.75rem;
}

/* Loading & Utilities */
.loading { animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Leaflet Customization */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-md) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  font-family: inherit !important;
}

.popup-content { padding: 1rem; }

.popup-header { margin-bottom: 0.5rem; }

.popup-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
}

.popup-badge.alive { background: var(--color-secondary); }
.popup-badge.cut { background: var(--color-cut); }

.popup-content h4 {
  color: var(--color-text);
  margin: 0.5rem 0;
  font-weight: 500;
}

.popup-image img,
.popup-panoramax img {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  margin: 0.5rem 0;
  box-shadow: var(--shadow-sm);
}

.popup-footer {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Responsive */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    text-align: center;
  }
  
  .nav-buttons { justify-content: center; }
  
  .map-wrapper {
    height: calc(100vh - 320px);
    margin: 0 0 1rem 0;
    border-radius: var(--radius);
  }
  
  .modal-content {
    max-width: 95%;
    border-radius: var(--radius);
  }
}
