/* Responsive layer for the legacy application. Keep IDs, fields and tables. */
#header, #contenido, #footer, #footer > .d1, #footer > .d2,
#footer > .d2 > div, #login_box, #login_box input {
    box-sizing: border-box;
}
#header {
    width: 100%; height: auto; min-height: 120px; padding: 20px 24px 36px;
}
#logo1 {
    position: static; display: block; width: auto; height: auto;
    max-width: 100%; max-height: 70px;
}
#menubar { height: auto; z-index: 1100; }
#menubar > ul {
    display: flex; flex-wrap: wrap; float: none;
    width: 100%; margin: 0; padding: 0 12px; box-sizing: border-box;
}
#menubar > ul > li {
    float: none; height: auto; min-height: 48px; padding: 12px 16px;
    box-sizing: border-box; line-height: 1.35;
}
#menubar .sub_menu {
    z-index: 1200; min-width: 240px; width: max-content;
    max-width: min(340px, calc(100vw - 24px));
}
#menubar .sub_menu_on { max-height: 65vh; overflow-y: auto; }
#menubar .sub_menu > li {
    white-space: normal; line-height: 1.4; padding: 12px 16px;
}
#menubar > ul > li:nth-last-child(-n+2) .sub_menu { left: auto; right: 0; }
#contenido { width: 100%; min-height: 40vh; padding: 16px 24px; }
.cubos { min-width: 0; }
.cubos > div { min-width: 0; }
#login_box { width: min(480px, calc(100% - 32px)); margin: 32px auto 40px; }
#login_box > div { padding: 0 8px; box-sizing: border-box; }
#contenido input[type=text], #contenido input[type=email],
#contenido input[type=number], #contenido input[type=tel],
#contenido input[type=date], #contenido select, #contenido textarea {
    box-sizing: border-box; max-width: 100%;
}
#contenido input[type=button], #contenido button { max-width: 100%; white-space: normal; }
.school-profile { table-layout: fixed; }
.school-profile > tbody > tr > td { min-width: 0; overflow-wrap: anywhere; }
.school-profile #map_canvas { width: 100%; max-width: 100%; }
#bux > img { max-width: 100%; height: auto; }
.history-chart { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.history-chart canvas { display: block; width: 100%; min-width: 720px; max-width: 900px; height: auto; }
#footer > .d1 { width: 30%; padding: 20px 24px; }
#footer > .d2 { display: flex; flex-wrap: wrap; width: 70%; padding: 0 12px; }
#footer > .d2 > div { flex: 1 1 180px; width: auto; padding: 0 12px 20px; }
#liston-inferior { height: auto; min-height: 35px; padding: 8px 12px; box-sizing: border-box; line-height: 1.5; }
.window { z-index: 2000; }
.window > div { max-width: calc(100% - 24px); }

@media (max-width: 800px) {
    #contenido { padding: 12px; }
    .cubos { margin: 16px 0; }
    .titulo-seccion { font-size: 1.35rem; padding: 10px 12px; }
    #header { min-height: 108px; padding: 16px 16px 32px; }
    #logo1 { max-height: 60px; }
    #menubar > ul { padding: 0; }
    #menubar > ul > li { flex: 1 1 50%; padding: 12px; font-size: .95rem; }
    #menubar > ul > li:nth-child(even) .sub_menu { left: auto; right: 0; }
    #menubar > ul > li:nth-child(odd) .sub_menu { left: 0; right: auto; }
    .school-profile { display: grid; grid-template-columns: minmax(0, 1fr); margin: 8px 0; width: 100%; }
    .school-profile > tbody, .school-profile > tbody > tr { display: contents; }
    .school-profile > tbody > tr > td { display: block; width: 100% !important; box-sizing: border-box; }
    .school-profile .school-coordinates { grid-row: 1; }
    .school-profile .school-map { grid-row: 2; }
    .school-profile .school-details { grid-row: 3; }
    .school-profile .school-details > table {
        display: block; max-width: 100%; width: 100%; margin: 8px 0;
        overflow-x: auto; box-sizing: border-box; -webkit-overflow-scrolling: touch;
    }
    #map_canvas { height: 350px !important; }
    #contenido .cubos > div > table:not(.school-profile) {
        display: block; max-width: 100%; overflow-x: auto;
        margin: 8px 0; width: 100%; -webkit-overflow-scrolling: touch;
    }
    #contenido input[type=text], #contenido input[type=email],
    #contenido input[type=number], #contenido input[type=tel],
    #contenido input[type=date], #contenido select { min-height: 40px; }
    #footer > .d1, #footer > .d2 { width: 100%; }
    #footer > .d1, #footer > .d2 { display: none; }
    #footer > .d1 { min-height: 0; padding: 20px; }
    #footer > .d2 { padding: 0 8px; }
    .window > div { width: calc(100% - 24px); left: 12px; top: 3%; height: 94%; }
    #chat { width: calc(100% - 24px); right: 12px; }
    .progress { max-width: 100%; box-sizing: border-box; }
}

@media (max-width: 420px) {
    #contenido { padding: 8px; }
    #menubar > ul > li { font-size: .9rem; padding: 10px; }
    #footer > .d2 > div { flex-basis: 100%; }
    #login_box { width: calc(100% - 24px); }
    #map_canvas { height: 300px !important; }
}

/* Header navigation: preserve server permissions and existing AJAX actions. */
#mobile-menu-toggle { display: none; }
#menubar li:focus-visible, #mobile-menu-toggle:focus-visible { outline: 3px solid #d9a441; outline-offset: -3px; }
@media (max-width: 800px) {
    #header { min-height: 100px; padding: 16px 76px 30px 16px; display: flex; align-items: center; }
    #logo1 { width: auto; height: auto; max-width: 100%; max-height: 54px; object-fit: contain; }
    #mobile-menu-toggle:not([hidden]) {
        display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px;
        position: absolute; right: 16px; top: 22px; width: 44px; height: 44px;
        padding: 10px; border: 1px solid #ab0033; border-radius: 6px;
        background: #fff; color: #ab0033; cursor: pointer;
    }
    #mobile-menu-toggle span { display: block; width: 22px; height: 2px; background: currentColor; }
    #menubar { display: none; }
    #menubar.mobile-menu-open { display: block; max-height: 70vh; overflow-y: auto; }
    #menubar > ul { display: block; }
    #menubar > ul > li { display: block; width: 100%; padding: 14px 16px; min-height: 48px; }
    #menubar > ul > li[aria-haspopup]::after { content: '+'; position: absolute; right: 18px; top: 14px; font-size: 20px; }
    #menubar > ul > li.mobile-sub-open::after { content: '\2212'; }
    #menubar .sub_menu { display: none; position: static; width: 100%; max-width: 100%; min-width: 0; height: auto; max-height: none; margin-top: 12px; border: 0; overflow: visible; }
    #menubar .mobile-sub-open > .sub_menu { display: block; }
    #menubar .sub_menu > li { min-height: 44px; box-sizing: border-box; padding: 12px; }
}

@media (max-width: 800px) {
    #header { border-bottom: 2px solid #ab0033; }
}

/* Area de influencia */
.area-layout { display: grid; grid-template-columns: minmax(260px, 30%) minmax(0, 1fr); gap: 16px; padding: 12px; }
.area-controls { min-width: 0; }
.area-controls > label { display: block; margin: 8px 0 4px; }
.area-controls > input[type=text], .area-controls > input[type=number], .area-controls > input[type=range] { width: 100%; box-sizing: border-box; }
.area-controls #dobus { margin-top: 10px; }
.area-range-labels { display: flex; justify-content: space-between; font-size: 12px; }
.area-map-panel { min-width: 0; }
.area-map-panel #mapa { width: 100%; height: 620px; min-height: 360px; }
.area-results { max-height: 380px; overflow: auto; }
.area-results table { width: 100%; margin: 0; font-size: 12px; }
.area-results td { padding: 6px; overflow-wrap: anywhere; }
.area-results tr { cursor: pointer; }
.area-results tr.area-selected { background: #f4dfb6; }
.area-school-button { border: 0; padding: 4px 0; background: transparent; color: #85002b; text-decoration: underline; font: inherit; cursor: pointer; }
#ctrok > label { display: block; padding: 5px 0; }
#ctrok input { width: auto; }
.area-influence #windwt { box-sizing: border-box; margin-top: 12px; padding: 16px; border: 1px solid #c4b6ac; border-radius: 6px; background: #fff; }
.area-influence #windwt[hidden] { display: none; }
.area-influence #cloke { float: right; min-width: 40px; min-height: 40px; font-size: 24px; background: #fff; color: #ab0033; border: 1px solid #ddd; border-radius: 4px; cursor: pointer; }
.area-marker-selected { filter: drop-shadow(0 0 5px #ab0033); }
@media (max-width: 800px) {
    .area-layout { grid-template-columns: minmax(0, 1fr); padding: 8px; }
    .area-map-panel #mapa { height: 420px; }
    .area-results { max-height: 240px; }
}

/* Keep the desktop controls unchanged; mobile follows search, map, filters, results. */
.area-query { display: contents; }
.area-query > label { display: block; margin: 8px 0 4px; }
.area-query > input[type=text], .area-query > input[type=number], .area-query > input[type=range] { width: 100%; box-sizing: border-box; }
#area-filter-panel { border: 0; }
#area-filter-panel > summary { display: none; }
@media (max-width: 800px) {
    .area-influence .area-layout { gap: 14px; padding: 12px; background: #f7f5f3; border-radius: 0 0 8px 8px; }
    .area-controls { display: contents; }
    .area-query { display: grid; grid-template-columns: minmax(0,1fr) 94px; gap: 8px 12px; grid-row: 1; padding: 14px; background: #fff; border: 1px solid #e8e1dc; border-radius: 12px; }
    .area-query > label { font-size: 13px; margin: 0; align-self: center; line-height: 1.35; }
    .area-query > label[for=ratox] { grid-column: 1; grid-row: 1; }
    .area-query #ratox { grid-column: 2; grid-row: 1; min-width: 0; text-align: center; }
    .area-query #rango { grid-column: 1 / -1; margin: 2px 0 0; accent-color: #ab0033; }
    .area-query .area-range-labels { grid-column: 1 / -1; font-size: 11px; color: #716760; }
    .area-query > label[for=cct] { grid-column: 1 / -1; margin-top: 4px; }
    .area-query #cct { grid-column: 1; min-width: 0; text-transform: uppercase; letter-spacing: .04em; }
    .area-query #dobus { grid-column: 2; width: 100%; margin: 0; padding: 10px 8px; min-height: 44px; border-radius: 8px; }
    .area-query #area-status { grid-column: 1 / -1; font-size: 12px; color: #6a5950; line-height: 1.5; margin: 4px 0 0; }
    .area-query input[type=text], .area-query input[type=number] { border: 1px solid #d9d0c8; border-radius: 8px; background: #fff; min-height: 44px; padding: 8px 10px; font-size: 15px; }
    .area-map-panel { grid-row: 2; padding: 10px; background: #fff; border: 1px solid #e8e1dc; border-radius: 12px; }
    .area-map-panel #area-locate { background: #fff; color: #85002b; border: 1px solid #dfd2cd; border-radius: 7px; padding: 8px 12px; min-height: 40px; margin-bottom: 10px; font-size: 13px; }
    #area-location-status { font-size: 12px; line-height: 1.4; display: block; }
    .area-map-panel #mapa { height: 360px; min-height: 300px; border-radius: 8px; overflow: hidden; }
    #area-filter-panel { grid-row: 3; margin: 0; background: #fff; border: 1px solid #e8e1dc; border-radius: 12px; padding: 0 14px; min-width: 0; }
    #area-filter-panel > summary { display: list-item; cursor: pointer; padding: 14px 0; font-size: 14px; font-weight: 600; color: #85002b; }
    #ctrok { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 0 14px; }
    #ctrok > label { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: #f7f3f1; border: 1px solid #e9dfd9; border-radius: 8px; font-size: 12px; line-height: 1.4; max-width: 100%; box-sizing: border-box; }
    #ctrok input { flex: 0 0 auto; accent-color: #ab0033; width: 16px; height: 16px; margin: 0; }
    .area-results { grid-row: 4; max-height: 420px; border-radius: 12px; }
    .area-results table, .area-results tbody { display: block; width: 100%; }
    .area-results thead { display: none; }
    .area-results tr { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 4px 8px; padding: 12px; margin-bottom: 8px; border: 1px solid #e8e1dc; border-radius: 10px; background: #fff; }
    .area-results tr[hidden] { display: none; }
    .area-results td { display: block; padding: 0; background: transparent; border: 0; font-size: 12px; line-height: 1.5; }
    .area-results td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .area-results td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; color: #423833; font-size: 13px; }
    .area-results td:nth-child(3) { grid-column: 2; grid-row: 1; text-align: right; color: #80634e; font-size: 11px; align-self: center; }
    .area-school-button { font-weight: 600; text-decoration: none; min-height: 30px; }
    .area-influence #renj:empty { display: none; }
    .area-influence #windwt { border-radius: 8px; font-size: 13px; line-height: 1.6; padding: 12px; }
}

@media (max-width: 800px) {
    .area-influence > .area-layout { width: 100%; margin: 0; box-sizing: border-box; }
    .area-query, .area-map-panel, .area-results, #area-filter-panel { min-width: 0; box-sizing: border-box; }
}

.nearest-page .nearest-content { width: auto; padding: 12px; }
.nearest-options { display: flex; flex-wrap: wrap; gap: 20px; margin: 12px 0; }
.nearest-options > div { flex: 1 1 280px; }
.nearest-options label { display: block; margin-bottom: 6px; }
.nearest-options input, .nearest-options select { width: 100%; box-sizing: border-box; min-height: 42px; }
.nearest-help { color: #6b5d53; font-size: 13px; line-height: 1.5; }
.nearest-level-panel { margin: 16px 0; border: 1px solid #ded5cd; padding: 12px; border-radius: 8px; }
.nearest-level-panel summary { color: #85002b; font-weight: bold; cursor: pointer; margin-bottom: 10px; }
.nearest-levels { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.nearest-levels > label { flex: 1 1 180px; padding: 8px; font-size: 13px; }
.nearest-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 16px 0; }
.nearest-actions button, .nearest-actions a { min-height: 42px; padding: 10px 18px; border-radius: 6px; box-sizing: border-box; }
.nearest-actions a { background: #ab0033; color: #fff; text-decoration: none; }
.nearest-actions [hidden] { display: none; }
#near-progress { width: 100%; max-width: 700px; height: 18px; accent-color: #ab0033; }
.nearest-history { margin-top: 20px; }
.nearest-history h6 { font-size: 15px; }
.nearest-history button { display: block; padding: 8px; margin: 6px 0; font-size: 12px; }
@media (max-width: 800px) {
    .nearest-page .nearest-content { margin: 0; padding: 14px; }
    .nearest-options { gap: 14px; }
    .nearest-levels { gap: 6px; }
    .nearest-levels > label { flex-basis: 100%; padding: 8px 0; }
    .nearest-history button { width: 100%; text-align: left; }
}


/* Municipal distances and enrollment capture maps. */
.distances-page,.capture-page{padding:16px;box-sizing:border-box}.dist-layout{display:grid;grid-template-columns:minmax(280px,1fr) minmax(300px,1fr);gap:20px}.dist-checks{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px;margin:10px 0}.dist-checks label{display:flex;gap:7px;align-items:flex-start}.distances-page details{margin:10px 0}.distances-page summary{cursor:pointer;color:#861c3d;font-weight:bold;padding:8px 0}.distances-page fieldset{margin:12px 0;border:1px solid #ddd}.distances-page progress{width:100%}#dist-map{height:360px;min-width:0;border-radius:8px}.dist-history{margin:4px!important}.capture-layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(300px,1fr);gap:20px}.capture-map{height:380px;border-radius:8px}.capture-actions{display:flex;flex-wrap:wrap;gap:10px;margin:16px 0}.capture-results{overflow:auto}.capture-schools{padding-left:20px}.capture-schools li{margin:8px 0}@media(max-width:800px){.dist-layout,.capture-layout{display:flex;flex-direction:column}#dist-map,.capture-map{height:300px;width:100%}.dist-checks{grid-template-columns:1fr}.distances-page,.capture-page{padding:12px}.distances-page input[type=number]{max-width:130px}.capture-results table{min-width:620px}}

.distances-page .dist-checks{max-height:260px;overflow:auto;padding:4px}.dist-history{display:inline-block}@media(max-width:800px){.capture-layout .capture-map{order:-1}.dist-layout #dist-map{order:-1}}

.session-warning{position:fixed;right:20px;bottom:20px;z-index:100000;max-width:370px;padding:18px;background:#fff9ee;border:2px solid #bd945d;border-radius:10px;box-shadow:0 6px 24px #0004;color:#333;box-sizing:border-box}.session-warning[hidden]{display:none!important}.session-warning strong{color:#861c3d;font-size:1.2rem}.session-warning p{margin:9px 0}.session-countdown{font-weight:bold;font-variant-numeric:tabular-nums;color:#861c3d;font-size:1.4rem}.session-warning button{margin:6px 6px 0 0;padding:8px 12px;cursor:pointer}.session-ended{background:#fff4d9;color:#611c35;padding:12px;text-align:center}@media(max-width:800px){.session-warning{left:12px;right:12px;bottom:12px;max-width:none}}

/* Full-width section heading; retain the existing content inset. */
#contenido .cubos.section-padded,
#contenido .cubos.state-indicators { --section-inset: 10px; }
#contenido .cubos.distances-page,
#contenido .cubos.capture-page { --section-inset: 16px; }
#contenido .cubos.section-padded > .titulo-seccion:first-child,
#contenido .cubos.state-indicators > .titulo-seccion:first-child,
#contenido .cubos.distances-page > .titulo-seccion:first-child,
#contenido .cubos.capture-page > .titulo-seccion:first-child {
    margin-top: calc(0px - var(--section-inset));
    margin-left: calc(0px - var(--section-inset));
    margin-right: calc(0px - var(--section-inset));
    margin-bottom: var(--section-inset);
    width: auto;
    box-sizing: border-box;
}
@media (max-width: 800px) {
    #contenido .cubos.distances-page,
    #contenido .cubos.capture-page { --section-inset: 12px; }
}
