:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --muted: #6b7280;
  --primary: #2563eb;
  --accent: #ff6b6b;
  --success: #10b981;
  --glass: rgba(255, 255, 255, 0.6);
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

html, body {
  height: 100%;
  background: var(--bg);
  margin: 0;
  color: #0f172a;
}

.app {
  max-width: 1200px;
  margin: 20px auto;
  padding: 18px;
}

/* ========================================
   HEADER
   ======================================== */

header {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: linear-gradient(135deg, #fcd34d, #ef4444, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.2);
}

h1 {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 700;
}

p.lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.tools {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.search {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--card);
  padding: 8px 12px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.search input {
  border: 0;
  outline: 0;
  font-size: 0.95rem;
  padding: 6px;
  width: 280px;
  background: transparent;
}

/* ========================================
   BOTONES
   ======================================== */

.btn {
  background: var(--primary);
  color: white;
  border: 0;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.btn.ghost:hover {
  background: rgba(37, 99, 235, 0.05);
}

/* ========================================
   LAYOUT PRINCIPAL
   ======================================== */

main {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
}

.panel {
  background: transparent;
}

/* ========================================
   TARJETAS DE REGIONES
   ======================================== */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 4px 12px rgba(12, 15, 29, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  transition: all 0.3s;
  cursor: pointer;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(12, 15, 29, 0.12);
}

.thumb {
  height: 140px;
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
}

.thumb-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.3) 100%);
}

.card > *:not(.thumb) {
  padding: 0 12px;
}

.card > .actions {
  padding: 0 12px 12px 12px;
}

.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.meta .title {
  font-weight: 700;
  font-size: 1.05rem;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.chip {
  background: #f3f4f6;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  align-items: center;
}

.link {
  background: transparent;
  border: 0;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.link:hover {
  color: #1d4ed8;
}

.fav-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  font-size: 20px;
  transition: all 0.2s;
  line-height: 1;
}

.fav-btn:hover {
  transform: scale(1.1);
}

.fav-btn.active {
  animation: heartBeat 0.3s;
}

@keyframes heartBeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* ========================================
   PANEL DE DETALLE
   ======================================== */

.detail {
  background: var(--card);
  border-radius: 14px;
  padding: 20px;
  height: calc(100vh - 160px);
  overflow: auto;
  box-shadow: 0 4px 12px rgba(12, 15, 29, 0.06);
  position: sticky;
  top: 20px;
}

.detail h2 {
  margin-top: 0;
  margin-bottom: 8px;
}

.region-header {
  padding-bottom: 16px;
  border-bottom: 2px solid #f3f4f6;
}

/* ========================================
   DEPARTAMENTOS EXPANDIBLES
   ======================================== */

.dept-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dept-item-wrapper {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(2, 6, 23, 0.06);
  transition: all 0.2s;
}

.dept-item-wrapper:hover {
  border-color: rgba(37, 99, 235, 0.2);
}

.dept-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: #fbfdff;
  gap: 8px;
}

.expand-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px;
  font-size: 12px;
  transition: transform 0.2s;
  color: var(--primary);
  line-height: 1;
}

.expand-btn.expanded {
  transform: rotate(90deg);
}

.municipalities-list {
  padding: 12px;
  background: #f9fafb;
  border-top: 1px solid rgba(2, 6, 23, 0.04);
}

.municipalities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.municipality-item {
  background: white;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  border: 1px solid rgba(2, 6, 23, 0.04);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========================================
   NOTAS - CRUD INTEGRADO
   ======================================== */

.notes-crud {
  background: #f9fafb;
  border-radius: 12px;
  padding: 16px;
  border: 2px solid #e5e7eb;
}

.note-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.note-input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e6e9ef;
  background: white;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
}

.note-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.notes-list {
  margin-top: 14px;
}

.note {
  padding: 12px;
  border-radius: 10px;
  background: white;
  border: 1px solid rgba(15, 23, 42, 0.06);
  margin-bottom: 8px;
  transition: all 0.2s;
}

.note:hover {
  border-color: rgba(37, 99, 235, 0.2);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}

.note-meta {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #f3f4f6;
}

.icon-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 16px;
  transition: all 0.2s;
  line-height: 1;
}

.icon-btn:hover {
  background: #f3f4f6;
  transform: scale(1.1);
}

.empty-state {
  text-align: center;
  padding: 30px 20px;
  background: white;
  border-radius: 10px;
  border: 2px dashed #e5e7eb;
}

/* ========================================
   UTILIDADES
   ======================================== */

.small {
  font-size: 0.85rem;
}

.muted {
  color: var(--muted);
}

.center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

/* ========================================
   SCROLLBAR
   ======================================== */

.detail::-webkit-scrollbar,
.municipalities-grid::-webkit-scrollbar {
  width: 8px;
}

.detail::-webkit-scrollbar-track,
.municipalities-grid::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 10px;
}

.detail::-webkit-scrollbar-thumb,
.municipalities-grid::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.detail::-webkit-scrollbar-thumb:hover,
.municipalities-grid::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ==========================
ESTILO DEL FOOTER
========================== */
.site-footer {
text-align: center;
font-size: 0.9rem;
color: #555;
line-height: 1.6;
font-family: "Segoe UI", Roboto, sans-serif;
margin-top: 30px;
padding: 16px 12px;
border-top: 1px solid #e5e5e5;
background: #fafafa;
}

.site-footer strong {
color: #222;
}

.site-footer code {
background: #f3f3f3;
padding: 2px 4px;
border-radius: 3px;
font-size: 0.85rem;
color: #333;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 980px) {
  main {
    grid-template-columns: 1fr;
  }

  .detail {
    height: auto;
    position: static;
    order: 3;
  }

  .search input {
    width: 180px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

@media (max-width: 640px) {
  .app {
    padding: 12px;
  }

  header {
    flex-direction: column;
    align-items: stretch;
  }

  .tools {
    margin-left: 0;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }

  .search input {
    width: 100%;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .municipalities-grid {
    grid-template-columns: 1fr;
  }
}