:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #667085;
  --line: #d9e0e7;
  --primary: #1f5f74;
  --primary-dark: #17495a;
  --soft: #eaf3f6;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(21, 39, 54, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 40px auto 70px;
}

.form-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.form-header {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 32px;
  padding: 34px 38px;
  background: linear-gradient(135deg, #ffffff 0%, #eef6f8 100%);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.18;
}

h1 {
  font-size: clamp(1.65rem, 3vw, 2.4rem);
}

.intro {
  max-width: 760px;
  margin: 12px 0 0;
  color: var(--muted);
}

.progress-box {
  align-self: center;
  color: var(--muted);
  font-size: .9rem;
}

.progress-track {
  height: 10px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe8eb;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width .25s ease;
}

form {
  padding: 8px 38px 38px;
}

fieldset {
  margin: 28px 0 0;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

legend {
  padding: 0 10px;
  color: var(--primary-dark);
  font-weight: 800;
}

.grid {
  display: grid;
  gap: 20px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  margin-top: 18px;
}

.field:first-child {
  margin-top: 0;
}

.field label,
.label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid #cfd7df;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 116, .12);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.choice-grid label,
.radio-row label,
.radio-column label {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
  font-weight: 500;
  cursor: pointer;
}

.choice-grid label:hover,
.radio-row label:hover,
.radio-column label:hover {
  border-color: #aac1ca;
  background: var(--soft);
}

input[type="checkbox"],
input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--primary);
}

.radio-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.radio-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.conditional {
  margin-top: 12px;
  padding: 14px;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: var(--soft);
}

.hidden {
  display: none !important;
}

.field-subgroup {
  margin-top: 0.75rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: var(--soft);
}

.hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.required,
.error {
  color: var(--danger);
}

.error {
  display: block;
  min-height: 20px;
  margin-top: 5px;
  font-size: .83rem;
}

.invalid {
  border-color: var(--danger) !important;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 28px;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 800;
  cursor: pointer;
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.secondary {
  background: #e7eef1;
  color: var(--primary-dark);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

dialog {
  width: min(800px, calc(100% - 30px));
  max-height: 86vh;
  border: 0;
  border-radius: 16px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(0,0,0,.22);
}

dialog::backdrop {
  background: rgba(14, 25, 34, .58);
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.dialog-actions {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
}

#summaryOutput {
  margin: 0;
  padding: 22px 24px;
  max-height: 58vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fbfcfd;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: 10px;
  background: #17212b;
  color: #fff;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .22s ease;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .form-header {
    grid-template-columns: 1fr;
  }

  .choice-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 18px, 1180px);
    margin: 16px auto 40px;
  }

  .form-header,
  form {
    padding-left: 18px;
    padding-right: 18px;
  }

  fieldset {
    padding: 18px 14px;
  }

  .grid.two,
  .choice-grid,
  .radio-column {
    grid-template-columns: 1fr;
  }

  .form-actions {
    flex-direction: column-reverse;
  }

  .btn {
    width: 100%;
  }
}


.section-subtitle {
  margin: 24px 0 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  color: var(--primary-dark);
  font-size: 1.02rem;
}



/* ===== Selector territorial: provincias ===== */
.province-help { display:block; margin:0 0 12px; }

.province-transfer {
  display:grid;
  grid-template-columns:minmax(0,1fr) 58px minmax(0,1fr);
  gap:14px;
  align-items:stretch;
  width:100%;
  margin-top:12px;
}

.province-panel {
  display:flex;
  flex-direction:column;
  min-height:430px;
  overflow:hidden;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
}

.province-panel.selected-panel {
  border-color:#aac7d1;
  background:#f8fbfc;
}

.province-panel-head {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:12px 14px;
  border-bottom:1px solid var(--line);
  background:#f5f8fa;
}

.province-count {
  display:inline-flex;
  min-width:30px;
  height:26px;
  align-items:center;
  justify-content:center;
  padding:0 8px;
  border-radius:999px;
  background:var(--soft);
  color:var(--primary-dark);
  font-size:.82rem;
  font-weight:800;
}

.province-search {
  width:calc(100% - 20px) !important;
  margin:10px;
}

.province-list {
  flex:1;
  min-height:320px;
  max-height:390px;
  overflow-y:auto;
  padding:8px;
  background:#fff;
}

.selected-list { background:#f8fbfc; }

.province-item {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin:4px 0;
  padding:9px 10px;
  border:1px solid #e3e8ed;
  border-radius:9px;
  background:#fff;
  cursor:grab;
  user-select:none;
}

.province-item:hover {
  border-color:#b9cbd2;
  background:var(--soft);
}

.province-item.selected {
  border-color:var(--primary);
  background:var(--soft);
  color:var(--primary-dark);
  font-weight:700;
}

.province-item.dragging { opacity:.45; }
.province-list.drop-active {
  outline:2px dashed var(--primary);
  outline-offset:-5px;
  background:var(--soft);
}
.drag-handle { color:var(--muted); letter-spacing:-2px; }

.province-transfer-actions {
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:9px;
}

.move-btn {
  min-height:42px;
  border:1px solid var(--line);
  border-radius:9px;
  background:#fff;
  color:var(--primary-dark);
  font-size:1.25rem;
  font-weight:800;
  cursor:pointer;
}

.move-btn:hover {
  border-color:var(--primary);
  background:var(--soft);
}

/* ===== Municipios dependientes ===== */
.municipality-help { display:block; margin-bottom:12px; }
.municipality-toolbar { display:flex; justify-content:flex-end; margin-bottom:14px; }
.municipality-total {
  padding:8px 11px;
  border-radius:999px;
  background:var(--soft);
  color:var(--primary-dark);
  font-size:.84rem;
  font-weight:800;
}

.municipality-selector { display:grid; gap:14px; }
.municipality-empty {
  padding:24px 18px;
  border:1px dashed #b9c8cf;
  border-radius:12px;
  background:#fbfcfd;
  color:var(--muted);
  text-align:center;
}

.municipality-province {
  overflow:hidden;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
}
.municipality-province-head {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  padding:12px 14px;
  border-bottom:1px solid var(--line);
  background:#f5f8fa;
}
.municipality-province-title {
  display:flex;
  align-items:center;
  gap:9px;
  font-weight:800;
  color:var(--primary-dark);
}
.municipality-province-count {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:28px;
  height:24px;
  padding:0 7px;
  border-radius:999px;
  background:#e4eef1;
  font-size:.78rem;
  font-weight:800;
}
.municipality-actions { display:flex; flex-wrap:wrap; gap:7px; }
.municipality-action-btn {
  padding:6px 9px;
  border:1px solid #cbd7dc;
  border-radius:8px;
  background:#fff;
  color:var(--primary-dark);
  font-size:.78rem;
  font-weight:700;
  cursor:pointer;
}
.municipality-options {
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:9px;
  padding:13px;
}
.municipality-option {
  display:flex !important;
  align-items:flex-start;
  gap:9px;
  min-height:44px;
  margin:0 !important;
  padding:10px 11px;
  border:1px solid var(--line);
  border-radius:9px;
  background:#fbfcfd;
  font-weight:500 !important;
  cursor:pointer;
}
.municipality-option.checked {
  border-color:var(--primary);
  background:var(--soft);
  color:var(--primary-dark);
  font-weight:700 !important;
}

/* Sede y financiación */
.grid.four { grid-template-columns:repeat(4,minmax(0,1fr)); }
.sede-grid { align-items:end; }
.sede-grid .field { margin-top:0; }
.funding-grid { margin-top:18px; }
.funding-card {
  padding:14px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fbfcfd;
}
.section-subtitle {
  margin:24px 0 6px;
  padding-bottom:8px;
  border-bottom:1px solid var(--line);
  color:var(--primary-dark);
  font-size:1.02rem;
}

@media (max-width:1000px) {
  .grid.four { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:900px) {
  .municipality-options { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:760px) {
  .province-transfer { grid-template-columns:1fr; }
  .province-transfer-actions { flex-direction:row; }
  .move-btn { flex:1; }
  .province-panel { min-height:300px; }
  .province-list { min-height:220px; max-height:300px; }
}
@media (max-width:640px) {
  .grid.four { grid-template-columns:1fr; }
  .municipality-toolbar { justify-content:flex-start; }
  .municipality-province-head { align-items:flex-start; flex-direction:column; }
  .municipality-options { grid-template-columns:1fr; }
}


/* Identificación institucional en disposición vertical */
.sede-vertical,
.funding-vertical {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  width: 100%;
}

.sede-vertical {
  margin-top: 18px;
}

.sede-vertical .field,
.funding-vertical .field {
  width: 100%;
  margin-top: 16px;
}

.sede-vertical input,
.sede-vertical select {
  width: 100%;
}

.funding-vertical {
  margin-top: 6px;
}

.funding-vertical .funding-card {
  margin-top: 14px;
}


/* Separación visual del campo de cantidad anual atendida */
.annual-attendance-field {
  margin-top: 34px !important;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.annual-attendance-field label {
  margin-bottom: 10px;
}


/* Alineación conjunta de cantidad anual y alcance */
.grid.two > .annual-attendance-field {
  align-self: start;
}


/* Alineación superior del bloque de experiencia */
.experience-grid {
  align-items: start;
}

.experience-grid .field {
  margin-top: 0;
  align-self: start;
}

.experience-grid label {
  min-height: 24px;
  display: flex;
  align-items: flex-start;
}


/* Alineación superior de personal y enlaces disponibles */
.capacity-grid {
  align-items: start;
}

.capacity-grid .field {
  margin-top: 0;
  align-self: start;
}

.capacity-grid label {
  min-height: 48px;
  display: flex;
  align-items: flex-start;
}


/* Alineación superior de levantamiento y capacidad de seguimiento */
.followup-grid {
  align-items: start;
}

.followup-grid .field {
  margin-top: 0;
  align-self: start;
}

.followup-grid label {
  min-height: 48px;
  display: flex;
  align-items: flex-start;
}

/* Protección contra registros duplicados */
.duplicate-notice {
  margin-top: 12px;
  padding: 13px 15px;
  border: 1px solid #f1b6b2;
  border-radius: 10px;
  background: #fff3f2;
  color: #8f1d17;
  font-weight: 700;
}

.form-locked fieldset:not(:first-of-type),
.form-locked .form-actions {
  opacity: .58;
}

.form-locked :disabled {
  cursor: not-allowed !important;
}
