:root {
  /* Paleta teal, a xogo con inesortega.github.io */
  color-scheme: light;
  --bg: #f7fbfb;
  --bg-alt: #eef5f5;
  --card: #ffffff;
  --text: #11201f;
  --muted: #4f5f5e;
  --border: #c5dada;
  --border-light: #dcebeb;
  --primary: #136f6f;
  --primary-2: #0e5e5e;
  --accent: #136f6f;
  --secondary: #e6f0f0;
  --secondary-text: #0e5e5e;
  --link: #0f7d7d;
  --danger: #c0392b;
  --ok-bg: #e6f4f1;
  --ok-text: #0a5a5a;
  --err-bg: #fdecec;
  --err-text: #9b2a2a;
  --shadow: 0 12px 32px rgba(17, 32, 31, 0.10);
  --shadow-sm: 0 2px 8px rgba(17, 32, 31, 0.07);
  --radius: 16px;
  --header-h: 60px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ---------- Tema escuro (a xogo con inesortega.github.io) ---------- */
[data-theme="dark"] {
  color-scheme: dark;
  /* Escala de elevación: fondo escuro < superficies < tarxetas, con bordos visibles. */
  --bg: #0f1719;
  --bg-alt: #172123;
  --card: #1e2a2c;
  --text: #e8f0ef;
  --muted: #a3b6b5;
  --border: #3a4d4c;
  --border-light: #2b3b3a;
  --accent: #57c9c9;
  --link: #66d4d4;
  --ok-bg: #123330;
  --ok-text: #8fe6cf;
  --err-bg: #3a1f1f;
  --err-text: #f2b8b8;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
  --shadow-sm: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 2px 10px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-alt) 0%, var(--bg) 100%);
}

a { color: var(--accent); }

/* ---------- Header ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 1200;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  color: #fff;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.18);
}

/* Cabeceira escura no tema escuro (a xogo coa topbar de inesortega.github.io) */
[data-theme="dark"] .appbar {
  background: linear-gradient(135deg, #1b2728 0%, #141b1c 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-size: 17px;
}

.brand .dot {
  display: inline-flex;
  width: 30px; height: 30px;
  align-items: center; justify-content: center;
  border-radius: 9px;
  background: var(--secondary);
  color: var(--secondary-text);
  font-size: 17px;
}

.brand small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  opacity: 0.72;
  letter-spacing: 0.02em;
}

.appbar nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.navlink {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 10px;
}
.navlink:hover { background: rgba(255,255,255,0.12); color: #fff; }
.navlink.active { background: rgba(255,255,255,0.16); color: #fff; }

.btn-add {
  background: var(--secondary);
  color: var(--secondary-text);
  font-weight: 800;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 10px;
  text-decoration: none;
  white-space: nowrap;
}
.btn-add:hover { filter: brightness(1.04); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 16px 0;
  background: transparent;
  max-width: 1180px;
  margin: 0 auto;
}
.tab {
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
}
.tab:hover { color: var(--accent); background: rgba(19,111,111,0.06); }
.tab.active { color: var(--accent); background: var(--card); box-shadow: var(--shadow-sm); }

.tabpanel { display: none; }
.tabpanel.active { display: block; }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------- Stat cards ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.stat .n { font-size: 26px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Filter bar ---------- */
.filters {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}
.filters .row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.search {
  flex: 1 1 220px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  outline: none;
}
.search:focus { border-color: rgba(19,111,111,0.45); box-shadow: 0 0 0 4px rgba(19,111,111,0.10); }

.date-field { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.date-field input[type="date"] {
  width: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
  background: var(--card);
  color: var(--text);
}
.date-field input[type="date"]:focus { border-color: rgba(19,111,111,0.45); box-shadow: 0 0 0 3px rgba(19,111,111,0.10); outline: none; }

.filter-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.filter-foot .hint { margin: 0; }
.btn-reset {
  width: auto;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-reset:hover { border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.chip .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip.off { opacity: 0.4; }
.chip:hover { border-color: var(--accent); }

.muted-note { color: var(--muted); font-size: 12px; }

/* ---------- Map ---------- */
#map {
  height: calc(100vh - var(--header-h) - 260px);
  min-height: 380px;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 1;
}

/* ---------- Leaflet popup ---------- */
.leaflet-popup-content { margin: 12px 14px; min-width: 220px; max-width: 300px; }
.pop-title { font-size: 15px; font-weight: 800; color: var(--accent); margin: 0 0 4px; }
.pop-cat {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.pop-desc { font-size: 13px; line-height: 1.5; color: var(--text); margin: 0 0 8px; }
.pop-date { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.pop-audio { width: 100%; margin-top: 4px; }
.pop-audio audio { width: 100%; }
.pop-audio iframe { width: 100%; border: 0; border-radius: 8px; }
.pop-link { font-size: 12px; font-weight: 700; }

/* ---------- Record list ---------- */
.rec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.rec {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rec h3 { margin: 0; font-size: 15px; color: var(--accent); }
.rec .meta { font-size: 12px; color: var(--muted); }
.rec .cat { align-self: flex-start; font-size: 11px; font-weight: 700; color: #fff; padding: 2px 8px; border-radius: 999px; }
.rec p { margin: 4px 0 0; font-size: 13px; line-height: 1.45; color: var(--text); }
.rec .rec-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }
.rec .rec-actions { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.rec .rec-actions a, .rec .rec-actions button {
  font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap;
  border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0;
}

/* ---------- Cards / sections (form + about) ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-width: 720px;
  margin: 16px auto;
}
.card-head { padding: 18px 18px 8px; }
.card-title { margin: 0; font-size: 20px; }
.card-subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.section {
  margin: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
}
.section-title { margin: 0 0 12px; font-size: 15px; font-weight: 800; color: var(--accent); }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.field label { display: block; margin: 0 0 7px; font-size: 14px; font-weight: 700; }
.hint { margin-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.45; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 14px;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.35;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
  -webkit-appearance: none;
  appearance: none;
}
input[type="file"] { padding: 10px; }
input:focus, textarea:focus, select:focus {
  border-color: rgba(19,111,111,0.45);
  box-shadow: 0 0 0 4px rgba(19,111,111,0.10);
}
textarea { min-height: 100px; resize: vertical; }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* Botón de envío: tamaño normal, aliñado á dereita (non ocupa todo o ancho).
   A marxe dereita iguala a das seccións (14px) para que quede aliñado con elas. */
.actions-submit { flex-direction: row; justify-content: flex-end; margin-right: 14px; }
.actions-submit .btn { width: auto; min-height: 44px; font-size: 15px; padding: 11px 24px; }

button.btn {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .06s ease, opacity .2s ease, filter .2s ease;
}
button.btn:active { transform: translateY(1px); }
button.btn:disabled { opacity: 0.7; cursor: wait; }
.btn-primary { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%); color: #fff; box-shadow: 0 8px 20px rgba(19,111,111,0.22); }
.btn-secondary { background: rgba(19,111,111,0.10); color: var(--accent); border: 1px solid rgba(19,111,111,0.30); }

.status {
  display: none;
  margin: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 14px;
}
.status.show { display: block; }
.status.ok { background: var(--ok-bg); color: var(--ok-text); }
.status.error { background: var(--err-bg); color: var(--err-text); }
.status.info { background: #eff6ff; color: #1e40af; }

.mini-card { margin-top: 10px; padding: 12px 14px; border-radius: 14px; background: var(--bg-alt); border: 1px solid var(--border); }
.preview-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.preview-value { font-size: 14px; font-weight: 700; word-break: break-word; }

.footer-note { margin: 0 14px 16px; color: var(--muted); font-size: 12px; line-height: 1.5; }

.prose { line-height: 1.6; }
.prose h3 { color: var(--accent); }
.prose a { font-weight: 600; }

.loading { text-align: center; color: var(--muted); padding: 30px; font-size: 14px; }

@media (max-width: 640px) {
  #map { height: calc(100vh - var(--header-h) - 320px); }
  .appbar .navlink.hide-sm { display: none; }
}

/* Mapa menos escuro en modo escuro: aclara as teselas (gris carbón, non negro). */
[data-theme="dark"] .leaflet-tile-pane { filter: brightness(1.75) contrast(0.9); }

/* ---------- Popup do Leaflet a xogo co tema escuro ----------
   Selector con [data-theme="dark"] (maior especificidade) para gañarlle ao
   CSS de Leaflet, que se carga despois e poñería o fondo branco. */
[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip {
  background: var(--card);
  color: var(--text);
}
[data-theme="dark"] .leaflet-popup-content-wrapper .pop-desc,
[data-theme="dark"] .leaflet-popup-content-wrapper .leaflet-popup-content { color: var(--text); }
[data-theme="dark"] .leaflet-popup-close-button { color: var(--muted); }

/* ---------- Botón de tema (sol/lúa) ---------- */
.theme-toggle {
  background: transparent;
  border: 0;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  line-height: 0;
}
.theme-toggle:hover { background: rgba(255,255,255,0.12); color: #fff; }
.theme-toggle svg { width: 19px; height: 19px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- Footer de autoría ---------- */
.site-footer {
  max-width: 1180px;
  margin: 10px auto 0;
  padding: 20px 16px 28px;
  border-top: 1px solid var(--border-light);
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { display: inline-flex; align-items: center; gap: 6px; }
.footer-links svg { width: 15px; height: 15px; flex: 0 0 auto; }
@media (max-width: 640px) {
  .site-footer { flex-direction: column; text-align: center; }
}

/* ---------- Botóns de edición nas tarxetas ---------- */
.rec .rec-actions button.danger { color: var(--err-text); }

/* ---------- Modal de edición ---------- */
.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.5);
}
.modal-card {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  padding: 20px;
}
.modal-card h3 { margin: 0 0 14px; color: var(--accent); font-size: 18px; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}
.modal-actions .btn { width: auto; min-height: 46px; padding: 12px 20px; }
.modal-card.modal-sm { max-width: 420px; }
.cf-msg { margin: 0; color: var(--muted); line-height: 1.55; font-size: 14px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }

/* ---------- Reprodutor de audio propio (Internet Archive) ---------- */
.ap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  margin-top: 4px;
}
.ap-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: filter .15s ease;
}
.ap-btn:hover { filter: brightness(1.08); }
.ap-btn svg { width: 16px; height: 16px; fill: #fff; }
.ap-bar {
  flex: 1 1 auto;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.ap-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); border-radius: 999px; }
.ap-time { flex: 0 0 auto; font-size: 11px; color: var(--muted); min-width: 74px; text-align: right; font-variant-numeric: tabular-nums; }
