:root {
  --bg: #f7f2e6;
  --card: #fffdfa;
  --card-2: #fff8ea;
  --line-soft: rgba(182, 140, 28, 0.28);
  --text: #3f3218;
  --muted: #76633d;
  --gold: #d7ad3c;
  --gold-strong: #b9890b;
  --cream: #f8eed1;
  --cream-hover: #f5e2aa;
  --epicenter-fill: #f6cfd0;
  --epicenter-stroke: #d5737a;
  --claim-fill: #f8dfbf;
  --claim-stroke: #c98d42;
  --red-1: #e97373;
  --red-2: #c94747;
  --success: #3a8b5d;
  --danger: #b53b3b;
  --shadow: 0 18px 35px rgba(90, 66, 15, 0.15);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-pill: 999px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, rgba(215, 173, 60, 0.18), transparent 24%),
    radial-gradient(circle at 90% 0%, rgba(233, 115, 115, 0.10), transparent 20%),
    linear-gradient(180deg, #fbf7ee 0%, #f5ecd8 100%);
}

button, select, input, textarea { font: inherit; }
button { cursor: pointer; }

.layout-shell {
  width: min(1680px, calc(100vw - 20px));
  height: 100dvh;
  margin: 0 auto;
  padding: 10px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.topbar,
.map-panel,
.info-panel,
.admin-dialog,
.editor-card {
  background: rgba(255, 253, 250, 0.96);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 18px;
}

.brand-block { min-width: 0; }
.eyebrow,
.panel-kicker {
  margin: 0 0 6px;
  color: var(--gold-strong);
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-weight: 900;
}

h1, h2, h3, h4, h5, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.45rem, 2.2vw, 2.5rem); line-height: 1; }
h2 { margin-bottom: 8px; font-size: clamp(1.3rem, 2vw, 2rem); }
h3 { margin-bottom: 12px; font-size: 1rem; }
.lead, .panel-summary, .category-item, .totals-list li, small, summary span, .admin-note { color: var(--muted); line-height: 1.45; }
.lead { margin: 0; max-width: 920px; }

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.fact-card {
  min-width: 220px;
  background: var(--card-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
}
.fact-card--accent {
  background: linear-gradient(135deg, #fff1f1 0%, #ffe4e4 100%);
  border-color: rgba(201, 71, 71, 0.25);
}
.fact-label {
  display: block;
  color: var(--gold-strong);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.fact-card strong { display: block; margin: 2px 0; font-size: 1.15rem; }

.content-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
  gap: 10px;
}

.map-panel,
.info-panel { min-height: 0; padding: 14px; }
.map-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
}
.info-panel { overflow: auto; }

.map-toolbar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}
.field-group { display: grid; gap: 6px; }
.field-group--grow { flex: 1 1 260px; }
label { font-size: 0.88rem; font-weight: 800; }
select, input, textarea {
  width: 100%;
  color: var(--text);
  background: #fffefb;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  outline: none;
}
textarea { resize: vertical; }
select:focus, input:focus, textarea:focus { border-color: var(--gold-strong); box-shadow: 0 0 0 3px rgba(215, 173, 60, 0.18); }

button {
  border: none;
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, var(--gold-strong), var(--gold));
}
button:hover { filter: brightness(1.03); }
.ghost-btn {
  color: var(--text);
  background: #fff8ea;
  border: 1px solid var(--line-soft);
}
.admin-open-btn { white-space: nowrap; }

.map-wrapper {
  min-height: 0;
  position: relative;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(180deg, #fffdf9 0%, #fdf7eb 100%);
}
#map { width: 100%; height: 100%; min-height: 420px; }

.map-legend {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.9rem;
  font-weight: 750;
}
.legend-box, .legend-dot { display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: middle; }
.legend-box { border-radius: 4px; border: 1px solid #c59b21; background: var(--cream); }
.legend-box--epicenter { background: linear-gradient(135deg, #fde6e7 0%, #efb4b7 100%); border-color: var(--epicenter-stroke); }
.legend-box--claim { background: var(--claim-fill); border-color: var(--claim-stroke); }
.legend-dot { border-radius: 999px; }
.legend-dot--m72 { background: var(--red-1); }
.legend-dot--m75 { background: var(--red-2); }

.panel-header { margin-bottom: 12px; }
.state-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.meta-pill {
  display: inline-flex;
  padding: 9px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line-soft);
  background: #fffaf0;
  font-weight: 850;
}
.meta-pill--soft { background: #fff4f4; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section-title-row h3 { margin: 0; }

.accordion-list { display: grid; gap: 10px; }
.empty-state { background: var(--card-2); border: 1px dashed var(--line-soft); border-radius: var(--radius-lg); padding: 16px; color: var(--muted); }
.accordion-item, .sub-accordion, .category-card, .totals-box {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: #fffdf8;
}
.accordion-item > summary, .sub-accordion > summary {
  list-style: none;
  cursor: pointer;
  padding: 13px 14px;
  font-weight: 900;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.accordion-item > summary::-webkit-details-marker, .sub-accordion > summary::-webkit-details-marker { display: none; }
.accordion-body, .sub-accordion-body { display: grid; gap: 10px; padding: 0 12px 12px; }
.category-card { padding: 12px; background: #fffaf1; }
.category-card h4 { margin: 0 0 8px; font-size: 0.96rem; }
.category-list, .totals-list { margin: 0; padding-left: 18px; }
.category-list li + li, .totals-list li + li { margin-top: 7px; }
.category-item strong { color: var(--text); }
.totals-box { padding: 12px; background: #fff7e6; }
.totals-box h5 { margin: 0 0 8px; font-size: 0.92rem; }

.leaflet-container { background: #fffdf8; font-family: inherit; }
.leaflet-control-attribution { display: none; }
.leaflet-interactive:focus { outline: none; }
.state-tooltip {
  background: rgba(95, 69, 14, 0.96);
  border: none;
  color: #fff;
  padding: 4px 8px;
  border-radius: 999px;
  box-shadow: none;
  font-weight: 800;
}
.capital-marker { background: transparent; border: none; }
.capital-marker__inner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(70, 48, 9, 0.92);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  box-shadow: 0 10px 18px rgba(0,0,0,.15);
}
.capital-marker__dot { width: 8px; height: 8px; border-radius: 999px; background: #ffd86b; }

.admin-modal { position: fixed; inset: 0; z-index: 2000; display: none; }
.admin-modal.is-open { display: block; }
.admin-backdrop { position: absolute; inset: 0; background: rgba(31, 22, 3, 0.48); backdrop-filter: blur(4px); }
.admin-dialog {
  position: absolute;
  inset: 16px;
  margin: auto;
  width: min(1120px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 18px;
}
.admin-dialog-header { display: flex; justify-content: space-between; align-items: start; gap: 14px; margin-bottom: 14px; }
.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  color: var(--text);
  background: #fff8ea;
  border: 1px solid var(--line-soft);
  font-size: 1.6rem;
  line-height: 1;
}
.hidden { display: none !important; }
.admin-form { display: grid; gap: 12px; max-width: 420px; }
.form-message { margin: 10px 0 0; font-weight: 800; }
.form-message.ok { color: var(--success); }
.form-message.error { color: var(--danger); }
.editor-status-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 14px; }
.editor-grid { display: grid; grid-template-columns: minmax(280px, .75fr) minmax(320px, 1.25fr); gap: 12px; }
.editor-card { padding: 14px; border-radius: var(--radius-lg); box-shadow: none; margin-top: 12px; }
.editor-card h3 { margin-bottom: 12px; }
.form-grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid-four { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.users-list { margin-top: 12px; display: grid; gap: 8px; }
.user-row { padding: 10px; background: #fff8ea; border: 1px solid var(--line-soft); border-radius: 12px; }

@media (max-width: 1100px) {
  .content-grid { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(240px, .75fr); }
  .topbar { grid-template-columns: 1fr; }
  .top-actions { justify-content: space-between; }
  .info-panel { max-height: 42dvh; }
  .editor-grid, .form-grid-four { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .layout-shell { width: calc(100vw - 8px); padding: 4px 0; gap: 6px; }
  .topbar, .map-panel, .info-panel { border-radius: 16px; padding: 10px; }
  .lead, .fact-card { display: none; }
  .top-actions { justify-content: stretch; }
  .admin-open-btn { width: 100%; }
  .content-grid { gap: 6px; }
  .map-toolbar { display: grid; grid-template-columns: 1fr auto; align-items: end; }
  .map-legend { font-size: 0.78rem; gap: 8px; }
  #map { min-height: 340px; }
  .info-panel { max-height: 38dvh; }
  .form-grid-two { grid-template-columns: 1fr; }
  .admin-dialog { inset: 8px; width: calc(100vw - 16px); padding: 12px; }
}

/* === Modal administrativo mejorado === */
.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  padding: 18px;
}

.admin-modal.is-open {
  display: grid;
  place-items: center;
}

.admin-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 30% 20%, rgba(215, 173, 60, 0.22), transparent 24%),
    radial-gradient(circle at 70% 0%, rgba(201, 71, 71, 0.16), transparent 22%),
    rgba(31, 22, 3, 0.58);
  backdrop-filter: blur(8px);
}

.admin-dialog {
  position: relative;
  inset: auto;
  margin: 0;
  width: min(1180px, 100%);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  padding: 22px;
  animation: adminPop .18s ease-out;
}

@keyframes adminPop {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.admin-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}

.login-view {
  display: grid;
  place-items: center;
  min-height: min(520px, calc(100dvh - 180px));
}

.login-card {
  width: min(460px, 100%);
  padding: clamp(18px, 3vw, 30px);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.92), rgba(255,248,234,.96)),
    radial-gradient(circle at 15% 0%, rgba(215,173,60,.22), transparent 28%);
  border: 1px solid rgba(182, 140, 28, 0.32);
  box-shadow: 0 22px 55px rgba(90, 66, 15, 0.22);
}

.login-lock {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--gold-strong), var(--gold));
  box-shadow: 0 12px 26px rgba(185, 137, 11, 0.24);
  font-size: 1.55rem;
}

.login-card .admin-note {
  margin-bottom: 16px;
}

.login-card .admin-form {
  max-width: none;
}

.login-card input {
  min-height: 48px;
  background: #fffefb;
}

.login-card button[type="submit"] {
  min-height: 48px;
  margin-top: 2px;
}

.server-hint {
  margin: 14px 0 0;
  padding: 12px;
  border-radius: 14px;
  background: #fff8ea;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.45;
  border: 1px solid var(--line-soft);
}

.server-hint code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(185, 137, 11, 0.12);
  color: var(--gold-strong);
  font-weight: 800;
}

.form-message {
  min-height: 1.2em;
  overflow-wrap: anywhere;
}

.form-message.error {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(181, 59, 59, 0.10);
  border: 1px solid rgba(181, 59, 59, 0.20);
}

.form-message.ok {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(58, 139, 93, 0.10);
  border: 1px solid rgba(58, 139, 93, 0.20);
}

@media (max-width: 720px) {
  .admin-modal { padding: 8px; }
  .admin-dialog {
    width: 100%;
    max-height: calc(100dvh - 16px);
    padding: 14px;
    border-radius: 18px;
  }
  .login-view { min-height: auto; }
  .login-card { border-radius: 20px; }
}

/* === Ajustes UX móvil solicitados === */
.admin-open-btn {
  width: 52px;
  height: 52px;
  min-width: 52px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background:
    linear-gradient(145deg, #fff7dc, #d7ad3c);
  color: #4b3510;
  border: 1px solid rgba(185, 137, 11, 0.35);
  box-shadow: 0 12px 24px rgba(185, 137, 11, 0.20);
}

.admin-open-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.admin-user-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.admin-open-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.map-panel {
  grid-template-rows: auto minmax(0, 1fr);
}

.map-panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.map-body {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
}

.map-toggle-btn {
  width: 46px;
  height: 46px;
  min-width: 46px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #fff8ea;
  color: var(--text);
  border: 1px solid var(--line-soft);
  box-shadow: 0 10px 20px rgba(90, 66, 15, 0.10);
}

.map-toggle-icon {
  display: block;
  font-size: 1.55rem;
  line-height: 1;
  font-weight: 900;
}

.map-toggle-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.map-panel.is-collapsed {
  grid-template-rows: auto;
}

.map-panel.is-collapsed .map-body {
  display: none;
}

.map-wrapper,
.leaflet-container {
  overscroll-behavior: contain;
}

#map {
  touch-action: none;
}

/* Paleta pastel para la información pública */
.info-panel {
  background:
    linear-gradient(180deg, rgba(255, 253, 250, .98), rgba(255, 249, 238, .98));
}

.panel-header {
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, #fff7de 0%, #fff1f1 100%);
  border: 1px solid rgba(215, 173, 60, 0.25);
}

.state-meta {
  padding: 2px 0 4px;
}

.meta-pill {
  background: #f2f7ff;
  border-color: #c8d9f5;
  color: #345071;
}

.meta-pill--soft {
  background: #fff0f3;
  border-color: #f2c8d2;
  color: #824153;
}

.section-title-row {
  padding: 10px 12px;
  border-radius: 16px;
  background: #f6f0ff;
  border: 1px solid #dcccf4;
}

.accordion-item {
  overflow: hidden;
  background: #fbfbff;
  border-color: #d9ddf4;
}

.accordion-item > summary {
  background: linear-gradient(135deg, #edf2ff, #f7f1ff);
  color: #3e4a76;
}

.sub-accordion {
  overflow: hidden;
  background: #fffdf9;
  border-color: #efe0bd;
}

.sub-accordion > summary {
  background: linear-gradient(135deg, #fff8db, #fff3e8);
  color: #6c4a11;
}

.category-card {
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
}

.category-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: currentColor;
  opacity: .55;
}

.category-card h4 {
  padding-left: 6px;
}

.category-card--affected {
  background: #fff7dc;
  border-color: #ecd79a;
  color: #7b5a09;
}

.category-card--destroyed {
  background: #ffecec;
  border-color: #f2b8b8;
  color: #914242;
}

.category-card--missing {
  background: #f4edff;
  border-color: #d8c4f5;
  color: #6a4a91;
}

.category-card--found {
  background: #eaf8ef;
  border-color: #bde3c9;
  color: #2f7b50;
}

.category-card--infrastructure {
  background: #eef7ff;
  border-color: #bdddf5;
  color: #2f668f;
}

.category-card--roads {
  background: #fff1e6;
  border-color: #f0c7a5;
  color: #8a5123;
}

.category-card--services {
  background: #eaf8f7;
  border-color: #b7dedb;
  color: #28716e;
}

.category-card--general {
  background: #fffaf1;
  border-color: #eadbb7;
  color: #6d5525;
}

.category-list,
.totals-list {
  color: var(--muted);
}

.totals-box {
  background: linear-gradient(135deg, #effaf3, #fff9e8);
  border-color: #cfe6bd;
  color: #365c31;
}

body.public-info-active .info-panel {
  border-color: rgba(215, 173, 60, 0.55);
  box-shadow: 0 18px 40px rgba(90, 66, 15, 0.18);
}

@media (min-width: 721px) {
  .admin-open-btn {
    width: auto;
    min-width: 168px;
    height: 48px;
    grid-auto-flow: column;
    grid-template-columns: auto auto;
    gap: 9px;
    padding: 0 18px;
  }

  .admin-open-label {
    position: static;
    width: auto;
    height: auto;
    clip: auto;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  html, body {
    overflow: hidden;
  }

  .layout-shell {
    height: 100dvh;
    width: calc(100vw - 8px);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
  }

  .brand-block h1 {
    font-size: 1.16rem;
    margin-bottom: 0;
  }

  .eyebrow {
    font-size: .66rem;
    margin-bottom: 4px;
  }

  .top-actions {
    justify-content: end;
  }

  .admin-open-btn {
    width: 46px;
    height: 46px;
    min-width: 46px;
  }

  .content-grid {
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, .98fr) minmax(0, .82fr);
  }

  body.public-info-active .content-grid {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .map-panel {
    min-height: 0;
    gap: 8px;
  }

  .map-panel-head {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
  }

  .map-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 86px;
    gap: 8px;
  }

  .map-toolbar label {
    font-size: .78rem;
  }

  select,
  input,
  textarea,
  button {
    border-radius: 12px;
  }

  .map-toggle-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .map-body {
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .map-wrapper {
    height: auto;
    min-height: 0;
    display: grid;
    place-items: center;
  }

  #map {
    min-height: 0;
    height: 100%;
  }

  .map-panel:not(.is-collapsed) #map {
    min-height: 42dvh;
  }

  .map-legend {
    max-height: 42px;
    overflow: auto;
    padding-right: 4px;
  }

  .map-panel.is-collapsed {
    padding: 8px;
  }

  .info-panel {
    max-height: none;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .panel-header {
    padding: 12px;
    border-radius: 16px;
  }

  .panel-summary {
    font-size: .94rem;
    margin-bottom: 0;
  }

  .state-meta {
    gap: 6px;
    margin-bottom: 10px;
  }

  .meta-pill {
    width: 100%;
    justify-content: flex-start;
    border-radius: 14px;
  }

  .section-title-row {
    align-items: start;
    flex-direction: column;
  }

  .section-title-row .ghost-btn {
    width: 100%;
  }

  .accordion-item > summary,
  .sub-accordion > summary {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .category-card,
  .totals-box {
    border-radius: 14px;
  }
}
