/* ====================================================================
   Centros educativos de Andalucía
   ==================================================================== */
:root {
  --green: #00703c;
  --green-dark: #00592f;
  --green-light: #e8f3ec;
  --border: #c9d6cd;
  --text: #1f2a24;
  --muted: #66736b;
  --bg: #f4f6f5;
  --P: #1b8a3a;   /* público */
  --R: #d32f2f;   /* privado */
  --C: #d97706;   /* concertado */
  --FSE: #0b1f4f; /* azul marino: filtro Fondo Social Europeo (Audición y Lenguaje) */
  --danger: #c0392b;
  --radius: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--green); }
code { background: #eef1ef; padding: 1px 5px; border-radius: 3px; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.num { text-align: right; }
.error { color: var(--danger); }
.ok { color: var(--P); }
.warn { color: var(--C); }
.loading { color: var(--muted); padding: 1em; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- barra superior ---------- */
.topbar { display: flex; align-items: center; gap: 24px; background: var(--green); color: #fff; padding: 0 20px; height: 48px; position: sticky; top: 0; z-index: 1000; }
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; }
.topbar nav a { color: #e3f1e8; text-decoration: none; padding: 14px 12px; white-space: nowrap; }
.topbar nav a:hover { background: var(--green-dark); }
.topbar nav a.active { color: #fff; box-shadow: inset 0 -3px 0 #a8e0bd; font-weight: 600; }

.container { max-width: 1400px; margin: 0 auto; padding: 20px; }
.container.narrow { max-width: 860px; }

/* ---------- botones y campos ---------- */
.btn { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 6px 14px; border-radius: var(--radius); cursor: pointer; text-decoration: none; font: inherit; line-height: 1.4; }
.btn:hover { border-color: var(--green); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.small { padding: 3px 9px; font-size: .88em; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
input[type=text], input[type=search], input[type=number], select { font: inherit; padding: 5px 8px; border: 1px solid #9cc49f; border-radius: 3px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus { outline: 2px solid #a8e0bd; border-color: var(--green); }
select:disabled { background: #f1f1f1; }
label { display: flex; flex-direction: column; gap: 4px; color: #333; }
label.chk { flex-direction: row; align-items: center; gap: 6px; cursor: pointer; }
label.chk input { width: 15px; height: 15px; accent-color: var(--green); margin: 0; }

/* ---------- panel de búsqueda (estilo Junta) ---------- */
.search-panel { background: #fff; border: 1px solid var(--border); margin-bottom: 20px; }
.panel-title { background: var(--green); color: #fff; text-align: center; font-weight: 700; padding: 8px; }
.panel-subtitle { background: #eef0ef; color: var(--green); font-weight: 700; font-size: 1.1em; margin: 12px; padding: 8px 18px; }
fieldset.box { border: 1px solid var(--border); margin: 18px 12px; padding: 12px 18px 16px; }
fieldset.box > legend { font-weight: 700; color: #444; display: flex; align-items: center; gap: 8px; padding: 0 6px; }
fieldset .toggle { width: 16px; height: 16px; padding: 0; border: 0; background: var(--green); color: #fff; font-weight: 700; line-height: 16px; font-size: 13px; cursor: pointer; border-radius: 2px; }
fieldset.collapsed > *:not(legend) { display: none !important; }
fieldset.collapsed { padding-bottom: 4px; }
select.modo { width: auto; font-weight: 400; font-size: .85em; padding: 1px 4px; border-color: var(--border); color: var(--muted); }
.grid { display: grid; gap: 12px 18px; }
.g-datos { grid-template-columns: 160px 1fr 1fr 1fr; }
.g-loc { grid-template-columns: repeat(4, 1fr); }
.g-mas { grid-template-columns: repeat(3, 1fr); }
.g-radio { grid-template-columns: 1fr 1fr 160px; }
.g-opts { grid-template-columns: 1fr 1fr; margin-top: 14px; align-items: end; }
.span2 { grid-column: span 2; }
.row-checks { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px; margin-top: 12px; }
.row-label { min-width: 190px; color: #333; }
.checks-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 40px; }
.checks-1col { display: grid; gap: 4px; }
.hint { cursor: help; color: var(--muted); }
.actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding: 0 12px 14px; flex-wrap: wrap; }

/* ---------- resultados ---------- */
.results { background: #fff; border: 1px solid var(--border); }
.results-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.results-bar label { flex-direction: row; align-items: center; }
.results-bar select { width: auto; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92em; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid #e3e9e5; text-align: left; vertical-align: top; }
table.data th { background: var(--green-light); color: #234; position: sticky; top: 0; white-space: nowrap; }
table.data th[data-sort] { cursor: pointer; user-select: none; }
table.data th[data-sort]:hover { background: #d6eadd; }
table.data th.sorted[data-dir=asc]::after { content: ' ▲'; font-size: .75em; }
table.data th.sorted[data-dir=desc]::after { content: ' ▼'; font-size: .75em; }
#tabla tbody tr { cursor: pointer; }
#tabla tbody tr:hover, #tabla tbody tr:focus { background: #f2f8f4; outline: none; }
.code { display: inline-block; font-size: .78em; background: #eef3ef; border: 1px solid #d6e2d9; border-radius: 3px; padding: 0 4px; margin: 1px 0; cursor: help; }
.badge { display: inline-block; font-size: .78em; padding: 1px 7px; border-radius: 10px; color: #fff; font-weight: 600; white-space: nowrap; }
.b-P { background: var(--P); } .b-R { background: var(--R); } .b-C { background: var(--C); } .b-FSE { background: var(--FSE); } .b-new { background: #8e44ad; }
.chip { display: inline-block; background: var(--green-light); border: 1px solid #cfe3d6; border-radius: 12px; padding: 1px 9px; margin: 2px 2px 2px 0; font-size: .9em; }
.pagination { display: flex; gap: 4px; justify-content: center; padding: 14px; flex-wrap: wrap; }
.pagination button { border: 1px solid var(--border); background: #fff; min-width: 34px; padding: 5px 8px; border-radius: 4px; cursor: pointer; }
.pagination button.current { background: var(--green); color: #fff; border-color: var(--green); }
.pagination button:disabled { opacity: .4; cursor: default; }
.pagination .dots { padding: 5px; color: var(--muted); }

/* ---------- ficha del centro (modal) ---------- */
dialog.centro-modal { width: min(1100px, 96vw); max-height: 92vh; border: 0; border-radius: 10px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog.centro-modal::backdrop { background: rgba(20, 30, 25, .45); }
dialog.centro-modal .close { position: absolute; right: 12px; top: 8px; border: 0; background: none; font-size: 28px; cursor: pointer; color: #fff; z-index: 2; }
dialog.centro-modal .content { overflow: auto; max-height: 92vh; }
dialog.centro-modal header { background: var(--green); color: #fff; padding: 16px 50px 14px 22px; }
dialog.centro-modal header h2 { margin: 4px 0; font-size: 1.35em; }
dialog.centro-modal header .muted { color: #cfe8d8; }
dialog.centro-modal .codigo { font-family: ui-monospace, Consolas, monospace; font-size: .95em; }
dialog.centro-modal .error { margin: 12px 22px; }
.cm-ruta { margin: 12px 22px 0; padding: 10px 14px; background: #fff7e6; border: 1px solid #f3d9a4; border-radius: var(--radius); }
.cm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 30px; padding: 6px 22px 10px; }
.cm-grid h3 { color: var(--green); font-size: 1em; border-bottom: 1px solid var(--border); padding-bottom: 4px; margin: 18px 0 8px; }
.cm-grid h4 { margin: 8px 0 4px; font-size: .95em; }
.cm-grid ul { margin: 4px 0; padding-left: 20px; }
table.kv { border-collapse: collapse; width: 100%; }
table.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 12px 3px 0; white-space: nowrap; vertical-align: top; width: 1%; }
table.kv td { padding: 3px 0; }
ol.oferta { padding-left: 22px; margin: 0; }
ol.oferta > li { margin: 6px 0; }
ol.oferta ul { color: #333; }
dialog.centro-modal footer { display: flex; align-items: center; gap: 10px; padding: 12px 22px; border-top: 1px solid var(--border); background: #fafbfa; position: sticky; bottom: 0; flex-wrap: wrap; }

/* ---------- mapa ---------- */
.page-mapa { overflow: hidden; }
.map-layout { position: relative; display: flex; height: calc(100vh - 48px); }
.sidebar { width: 320px; flex: none; background: #fff; border-right: 1px solid var(--border); overflow-y: auto; position: relative; transition: margin-left .2s; z-index: 500; }
.sidebar form { padding: 12px 16px 24px; display: grid; gap: 10px; }
.sidebar h2 { margin: 0; font-size: 1.1em; color: var(--green); }
.sidebar fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin: 0; display: grid; gap: 4px; }
.sidebar legend { font-weight: 600; color: #333; padding: 0 4px; display: flex; gap: 6px; align-items: center; }
.sidebar .actions { padding: 0; }
.map-count { background: var(--green-light); padding: 6px 10px; border-radius: var(--radius); }
.sidebar-toggle { position: fixed; top: 58px; left: 322px; z-index: 900; width: 22px; height: 40px; border: 1px solid var(--border); background: #fff; border-radius: 0 6px 6px 0; cursor: pointer; transition: left .2s; }
body.sidebar-hidden .sidebar { margin-left: -320px; }
body.sidebar-hidden .sidebar-toggle { left: 2px; }
#map { flex: 1; height: 100%; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot-P { background: var(--P); } .dot-R { background: var(--R); } .dot-C { background: var(--C); } .dot-FSE { background: var(--FSE); }

.pin svg { display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.45)); }
.pin path { stroke: #fff; stroke-width: 1.5; }
.pin-P path { fill: var(--P); } .pin-R path { fill: var(--R); } .pin-C path { fill: var(--C); } .pin-FSE path { fill: var(--FSE); }
.leaflet-div-icon.pin { background: none; border: 0; }

.epi-marker { background: none; border: 0; }
.epi-star { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; color: #e3001b; text-shadow: 0 0 3px #fff, 0 0 6px #fff, 0 2px 4px rgba(0,0,0,.6); cursor: grab; }
.epi-pulse { position: absolute; inset: 0; border-radius: 50%; background: rgba(227, 0, 27, .35); border: 3px solid #e3001b; animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(.4); opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }

.centro-tooltip { padding: 8px 10px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); border: 0; }
.tt { min-width: 220px; max-width: 320px; white-space: normal; display: grid; gap: 3px; }
.tt-name { font-weight: 600; }
.tt-ruta { font-size: 1.05em; background: #fff7e6; padding: 3px 6px; border-radius: 4px; }

/* HUD del epicentro */
.hud { position: absolute; top: 12px; right: 12px; z-index: 800; width: 360px; background: rgba(255,255,255,.97); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); padding: 12px 14px; display: grid; gap: 8px; }
.hud label { font-weight: 700; color: var(--green); }
.hud-row { display: flex; gap: 6px; }
.hud-results { list-style: none; margin: 4px 0 0; padding: 0; max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.hud-results li { border-bottom: 1px solid #eee; }
.hud-results li.muted, .hud-results li.error { padding: 6px 8px; }
.hud-results button { border: 0; background: none; text-align: left; padding: 6px 8px; width: 100%; cursor: pointer; font: inherit; }
.hud-results button:hover { background: var(--green-light); }
.hud-current { display: grid; gap: 6px; background: #fff0f1; border: 1px solid #f5c2c7; border-radius: var(--radius); padding: 6px 8px; }
.hud-actions { display: flex; justify-content: space-between; align-items: center; }
.epi-icon { color: #e3001b; font-size: 1.2em; }
.hud-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.hud-legend span { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.hud-legend i { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }
.hud-legend div { flex-basis: 100%; }
.hud-note { font-size: .8em; color: var(--muted); }

/* Árbol de ofertas */
.oferta-tree { display: grid; gap: 4px; }
.tree-body { max-height: 320px; overflow: auto; border: 1px solid #e3e9e5; border-radius: 4px; padding: 4px; }
.search-panel .tree-body { max-height: 420px; columns: 2; column-gap: 30px; }
.tree-node { display: grid; grid-template-columns: 18px 1fr; align-items: start; break-inside: avoid; }
.tree-toggle { border: 0; background: none; cursor: pointer; padding: 2px 0; color: var(--green); }
.tree-children { grid-column: 2; padding-left: 8px; border-left: 1px dotted #b9cdbf; display: grid; gap: 2px; margin-bottom: 4px; }
.oferta-tree label.chk { font-size: .92em; padding: 1px 0; }
.oferta-tree label.nivel { font-weight: 600; }
.count { color: var(--muted); font-size: .8em; font-weight: 400; background: #f0f3f1; border-radius: 8px; padding: 0 6px; }

/* ---------- scraping ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stats div { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; text-align: center; }
.stats strong { display: block; font-size: 1.6em; color: var(--green); }
.stats span { color: var(--muted); }
.two-cols { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; align-items: start; }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 10px; font-size: 1.15em; color: var(--green); display: flex; align-items: center; gap: 10px; }
.card .actions { padding: 14px 0 0; }
.tabs { display: flex; gap: 18px; margin: 10px 0 14px; flex-wrap: wrap; }
.tabs label { flex-direction: row; gap: 6px; align-items: center; cursor: pointer; font-weight: 600; }
.mini-map { height: 260px; border-radius: var(--radius); margin-top: 10px; border: 1px solid var(--border); }
details.more { margin-top: 12px; }
details.more summary { cursor: pointer; color: var(--green); margin-bottom: 8px; }
.job { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.job.running { border-color: var(--green); box-shadow: 0 0 0 2px #a8e0bd; }
.job-head { display: flex; justify-content: space-between; gap: 10px; }
.estado { font-size: .85em; font-weight: 600; white-space: nowrap; }
.e-terminado { color: var(--P); } .e-cancelado { color: var(--muted); } .e-pausado { color: var(--C); } .e-en_curso { color: #2563eb; }
.progress { position: relative; height: 18px; background: #edf1ee; border-radius: 9px; margin: 8px 0 4px; overflow: hidden; }
.progress div { height: 100%; background: linear-gradient(90deg, #36a35f, var(--green)); transition: width .4s; }
.progress span { position: absolute; inset: 0; text-align: center; font-size: .78em; line-height: 18px; font-weight: 600; }
.job-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.log { font-family: ui-monospace, Consolas, monospace; font-size: .85em; max-height: 360px; overflow: auto; background: #fbfcfb; border: 1px solid #e3e9e5; border-radius: 4px; padding: 6px 10px; }
.log .l-error { color: var(--danger); } .log .l-omitido { color: var(--muted); }
.ofertas-resumen { columns: 3; column-gap: 24px; }
.ofertas-resumen details { break-inside: avoid; margin-bottom: 4px; }
.ofertas-resumen summary { cursor: pointer; }
.ofertas-resumen p { column-span: all; }
table.ofertas tr.nivel td { background: #f6faf7; }
table.ofertas td.indent { padding-left: 28px; }
table.ofertas .links { white-space: nowrap; font-size: .88em; }
.filter-input { max-width: 360px; margin-bottom: 10px; }
#import-form { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .g-datos, .g-loc, .g-mas, .g-radio, .g-opts { grid-template-columns: 1fr 1fr; }
  .two-cols, .cm-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .ofertas-resumen, .search-panel .tree-body { columns: 1; }
  .hud { width: calc(100% - 24px); max-width: 360px; }
}
@media (max-width: 640px) {
  .g-datos, .g-loc, .g-mas, .g-radio, .g-opts, .checks-2col { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .sidebar { position: absolute; height: 100%; }
  .topbar .brand { display: none; }
}
