:root {
    --db-ucr: #0067a8;
    --db-ucr-dark: #06436b;
    --db-cyan: #51c8e8;
    --db-yellow: #fdb913;
    --db-ink: #13263a;
    --db-muted: #607286;
    --db-line: #d9e4ec;
    --db-surface: #f3f7fa;
    --db-white: #fff;
    --db-success: #237a45;
    --db-danger: #9b3434;
}

.database-page,
.database-page * { box-sizing: border-box; }

.database-page {
    max-width: 1480px;
    margin: 0 auto;
    padding: 32px 24px 70px;
    color: var(--db-ink);
}

.database-hero {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 30px;
    padding: 34px;
    border-radius: 22px;
    color: var(--db-white);
    background: linear-gradient(125deg, #003f70, #0877b9);
    box-shadow: 0 15px 45px rgba(0, 63, 112, .18);
}

.database-hero-copy { min-width: 0; }
.database-hero h1 { margin: .3rem 0; font-size: clamp(1.8rem, 3vw, 3.1rem); }
.database-hero p { max-width: 850px; margin: 0; opacity: .9; }

.eyebrow {
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .13em;
    text-transform: uppercase;
}
.eyebrow-blue { color: var(--db-ucr); }

.database-total {
    min-width: 190px;
    padding-left: 24px;
    border-left: 1px solid rgba(255, 255, 255, .35);
}
.database-total strong { display: block; font-size: 2.3rem; }
.database-total span { font-size: .85rem; }

.database-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

.database-action {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 15px;
    border: 1px solid rgba(255, 255, 255, .45);
    border-radius: 10px;
    color: #fff;
    background: rgba(255, 255, 255, .11);
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform .15s ease, background .15s ease;
}
.database-action:hover,
.database-action:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, .2);
    transform: translateY(-1px);
}
.database-action-download { background: rgba(253, 185, 19, .22); }
.database-action-ai { background: rgba(81, 200, 232, .2); }

.filter-builder,
.results-card {
    margin-top: 22px;
    overflow: hidden;
    border: 1px solid var(--db-line);
    border-radius: 18px;
    background: var(--db-white);
    box-shadow: 0 10px 35px rgba(18, 59, 91, .07);
}
.filter-builder { padding: 26px; overflow: visible; }

.filter-heading,
.filter-actions,
.results-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}
.filter-heading h2,
.results-heading h2 { margin: .25rem 0 0; }
.filter-heading p { margin: .3rem 0 0; color: var(--db-muted); }

.btn-link {
    border: 0;
    color: var(--db-ucr);
    background: none;
    font-weight: 800;
    text-decoration: none;
}

.active-filter-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 34px;
    margin: 22px 0 12px;
}
.active-filter-summary span {
    padding: 7px 11px;
    border-radius: 999px;
    color: #07577d;
    background: #e5f5fa;
    font-size: .8rem;
}
.active-filter-summary .summary-empty { color: var(--db-muted); background: var(--db-surface); }

.filter-levels { display: grid; gap: 14px; }
.filter-card {
    min-width: 0;
    padding: 16px 18px 18px;
    border: 1px solid var(--db-line);
    border-radius: 14px;
    transition: border-color .2s, box-shadow .2s, opacity .2s;
}
.filter-card:hover { border-color: #aac8dc; box-shadow: 0 8px 22px rgba(18, 59, 91, .05); }
.filter-card.is-dragging { opacity: .5; border-color: var(--db-ucr); }
.filter-card legend {
    display: flex;
    align-items: center;
    gap: 9px;
    width: auto;
    padding: 0 8px;
}

.drag-handle,
.remove-filter { border: 0; background: transparent; cursor: pointer; }
.drag-handle { color: #8293a2; font-size: 1.2rem; letter-spacing: -4px; }
.filter-number {
    display: inline-grid;
    place-items: center;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    color: var(--db-white);
    background: var(--db-ucr);
    font-weight: 800;
}
.remove-filter {
    width: 30px;
    height: 30px;
    margin-left: 8px;
    border-radius: 50%;
    color: var(--db-danger);
    font-size: 1.25rem;
}
.remove-filter:hover { background: #fff0f0; }

.filter-row {
    display: grid;
    grid-template-columns: 1.15fr 1.15fr 1.4fr;
    gap: 14px;
    align-items: end;
}
.filter-row label,
.sort-group label,
.filter-actions > label,
.modal-field {
    display: grid;
    gap: 6px;
    color: var(--db-muted);
    font-size: .78rem;
    font-weight: 700;
}
.filter-range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.database-page [hidden] { display: none !important; }

.database-page select,
.database-page input,
.database-medium-modal input,
.database-medium-modal select,
.database-medium-modal textarea {
    width: 100%;
    min-height: 43px;
    padding: 9px 11px;
    border: 1px solid #c8d5df;
    border-radius: 9px;
    color: var(--db-ink);
    background: var(--db-white);
    font: inherit;
}
.database-medium-modal textarea { min-height: 120px; resize: vertical; }
.database-page select:focus,
.database-page input:focus,
.database-medium-modal input:focus,
.database-medium-modal select:focus,
.database-medium-modal textarea:focus {
    outline: 3px solid rgba(81, 200, 232, .2);
    border-color: var(--db-ucr);
}

.add-filter {
    margin-top: 14px;
    padding: 10px 14px;
    border: 1px dashed #8db5cf;
    border-radius: 9px;
    color: var(--db-ucr);
    background: #f6fbfd;
    font-weight: 800;
    cursor: pointer;
}

.sort-panel {
    display: grid;
    grid-template-columns: .9fr 1.1fr 1.1fr;
    grid-auto-rows: max-content;
    gap: 18px;
    align-items: end;
    align-content: start;
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    margin-top: 22px;
    padding: 20px !important;
    border-radius: 14px;
    background: var(--db-surface);
}
.filter-builder > .sort-panel > * { align-self: end; height: auto !important; min-height: 0 !important; margin: 0 !important; }
.sort-panel h3 { margin: .25rem 0 0; }
.sort-group { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; }

.filter-actions {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--db-line);
}
.filter-actions > label { width: 130px; }
.query-preview { display: flex; align-items: baseline; gap: 7px; margin-left: auto; color: var(--db-muted); }
.query-preview strong { color: var(--db-ucr-dark); font-size: 1.45rem; }

.btn-primary,
.btn-view,
.btn-secondary,
.btn-light-action,
.modal-close {
    border: 0;
    cursor: pointer;
    font-weight: 800;
}
.btn-primary {
    padding: 13px 25px;
    border-radius: 10px;
    color: var(--db-white);
    background: var(--db-ucr);
}
.btn-primary:disabled { opacity: .65; cursor: wait; }
.btn-light-action,
.btn-secondary {
    padding: 11px 15px;
    border-radius: 9px;
    color: var(--db-ucr);
    background: #e5f0f8;
}

.results-heading { padding: 20px 22px; }
.results-heading > strong { color: var(--db-ucr); font-size: 1.6rem; }
.table-scroll { overflow: auto; }
.database-page table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.database-page th,
.database-page td { padding: 15px 16px; border-bottom: 1px solid #e6edf2; text-align: left; }
.database-page th { background: var(--db-surface); font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; }
.database-page tbody tr:hover { background: #f4fbfe; }
.station-chip { padding: 5px 9px; border-radius: 7px; color: #00668c; background: #e1f3f9; font-weight: 800; }
.btn-view { padding: 9px 13px; border-radius: 8px; color: var(--db-ucr); background: #e5f0f8; }
.empty-state { padding: 50px; color: var(--db-muted); text-align: center; }

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    padding: 20px;
}
.pagination-status { width: 100%; margin-bottom: 5px; color: var(--db-muted); text-align: center; font-size: .85rem; }
.pagination a {
    display: grid;
    place-items: center;
    min-width: 36px;
    min-height: 36px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--db-ucr);
    text-decoration: none;
}
.pagination a.active { color: var(--db-white); background: var(--db-ucr); }

/* Modal mediano: consultas por correo y lenguaje natural */
.database-medium-modal {
    width: min(720px, calc(100vw - 30px));
    max-width: 720px;
    max-height: min(86vh, 820px);
    padding: 0;
    border: 0;
    border-radius: 18px;
    color: var(--db-ink);
    background: var(--db-white);
    box-shadow: 0 25px 90px rgba(0, 30, 52, .3);
    overflow: hidden;
}
.database-medium-modal::backdrop { background: rgba(0, 27, 45, .72); }
.medium-modal-shell { display: flex; flex-direction: column; max-height: inherit; }
.medium-modal-shell > header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--db-line);
}
.medium-modal-shell h2 { margin: .2rem 0 0; font-size: 1.35rem; }
.medium-modal-body {
    display: grid;
    gap: 16px;
    padding: 22px 24px 24px;
    overflow-y: auto;
}
.medium-modal-body > p { margin: 0; color: var(--db-muted); }
.medium-modal-body footer { display: flex; justify-content: flex-end; gap: 10px; padding-top: 6px; }
.contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-examples {
    padding: 14px 16px;
    border-radius: 12px;
    background: var(--db-surface);
}
.modal-examples strong { display: block; margin-bottom: 7px; }
.modal-examples ul { display: grid; gap: 5px; margin: 0; padding-left: 18px; }
.example-query { padding: 2px 0; border: 0; color: var(--db-ucr); background: none; text-align: left; cursor: pointer; }
.example-query:hover { text-decoration: underline; }
.modal-status { min-height: 22px; color: var(--db-muted); font-size: .9rem; }
.modal-status.is-error { color: var(--db-danger); }
.modal-status.is-success { color: var(--db-success); font-weight: 700; }
.database-honeypot { position: absolute !important; left: -9999px !important; width: 1px !important; height: 1px !important; overflow: hidden !important; }

.download-summary {
    padding: 12px 14px;
    border-left: 4px solid var(--db-yellow);
    border-radius: 0 9px 9px 0;
    color: var(--db-ucr-dark);
    background: #fff8df;
    font-weight: 800;
}

.modal-close {
    flex: 0 0 auto;
    width: 43px;
    height: 43px;
    border-radius: 50%;
    color: var(--db-ink);
    background: #edf1f4;
    font-size: 1.8rem;
    line-height: 1;
}

/* Modal de detalle: se conserva a pantalla completa */
.record-modal {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: #f5f8fa;
    overflow: auto;
}
.record-modal:not([open]) { display: none !important; }
.record-modal::backdrop { background: rgba(0, 27, 45, .8); }
body.database-modal-open { overflow: hidden !important; }
.modal-shell { display: flex; flex-direction: column; width: 100%; min-height: 100vh; }
.modal-shell > header {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 28px;
    border-bottom: 1px solid var(--db-line);
    background: var(--db-white);
}
.modal-shell h2 { margin: .2rem 0 0; }
.modal-actions { display: flex; gap: 10px; }
.modal-body {
    display: flex;
    flex: none !important;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start !important;
    gap: 20px;
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    padding: 25px;
}
.detail-grid {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    grid-auto-rows: max-content;
    align-items: start;
    gap: 20px;
    width: 100%;
}
.panel { padding: 20px; border: 1px solid var(--db-line); border-radius: 15px; background: var(--db-white); }
.panel h3 { margin-top: 0; }
.metrics-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.metric { padding: 14px; border-radius: 10px; background: var(--db-surface); }
.metric small { display: block; color: var(--db-muted); }
.metric strong { font-size: 1.15rem; }
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; width: 100%; }
.chart-wrap { height: 360px; }
.map-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 14px; }
.map-heading h3 { margin: 0 0 4px; }
.map-heading p { margin: 0; color: var(--db-muted); }
.map-legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--db-muted); font-size: .82rem; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.map-dot { width: 11px; height: 11px; border-radius: 50%; }
.map-dot-event { background: #d64545; }
.map-dot-station { background: #0067a8; }
.record-map { width: 100%; height: clamp(320px, 48vh, 520px); overflow: hidden; border: 1px solid var(--db-line); border-radius: 12px; background: #e9f0f4; }
.map-unavailable { display: grid; place-items: center; height: 100%; color: var(--db-muted); text-align: center; }
.loading { padding: 80px; color: var(--db-muted); text-align: center; }

@media (max-width: 1050px) {
    .sort-panel { grid-template-columns: 1fr 1fr; }
    .sort-panel > div:first-child { grid-column: 1 / -1; }
}

@media (max-width: 800px) {
    .database-hero { align-items: start; flex-direction: column; }
    .database-total { padding-left: 0; border-left: 0; }
    .filter-row,
    .sort-panel,
    .detail-grid,
    .chart-grid { grid-template-columns: 1fr; }
    .sort-panel > div:first-child { grid-column: auto; }
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .filter-actions { align-items: stretch; flex-direction: column; }
    .query-preview { margin-left: 0; }
    .database-actions { align-items: stretch; flex-direction: column; }
    .database-action { justify-content: center; }
}

@media (max-width: 560px) {
    .database-page { padding: 15px 10px 55px; }
    .database-hero,
    .filter-builder { padding: 18px; }
    .filter-heading { align-items: start; flex-direction: column; }
    .filter-range,
    .sort-group,
    .metrics-grid,
    .contact-grid { grid-template-columns: 1fr; }
    .modal-shell > header { padding: 12px; }
    .medium-modal-shell > header,
    .medium-modal-body { padding-left: 16px; padding-right: 16px; }
    .modal-actions .btn-secondary { display: none; }
    .map-heading { align-items: start; flex-direction: column; }
}

/* Neutraliza alturas heredadas del CSS general del sitio. */
#databaseFilterForm > section.sort-panel,
#recordModal .modal-body > section.panel,
#recordModal .detail-grid > .panel,
#recordModal .chart-grid > .panel,
#recordModal .metrics-grid,
#recordModal .metric {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    block-size: auto !important;
    aspect-ratio: auto !important;
}

/* Navegación contextual equivalente a /Stations */
.database-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    width: fit-content;
    margin: 10px 0 16px;
    padding: 8px 12px;
    border-left: 4px solid var(--db-yellow);
    border-radius: 0 8px 8px 0;
    color: rgba(255, 255, 255, .84);
    background: rgba(255, 255, 255, .09);
    font-size: .9rem;
    font-weight: 700;
}
.database-links a {
    color: #fff;
    font-weight: 800;
    text-decoration: none;
}
.database-links a:hover,
.database-links a:focus-visible { text-decoration: underline; }

.database-action-map { background: rgba(253, 185, 19, .14); }

.database-zone-active {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    margin-top: 22px;
    padding: 14px 18px;
    border: 1px solid #b9d9ea;
    border-left: 5px solid var(--db-cyan);
    border-radius: 12px;
    background: #eff8fc;
}
.database-zone-active div { display: grid; gap: 3px; }
.database-zone-active span { color: var(--db-muted); font-size: .9rem; }
.database-zone-active a {
    flex: 0 0 auto;
    color: var(--db-ucr);
    font-weight: 800;
    text-decoration: none;
}

/* QueryMap */
.database-querymap-modal {
    width: min(980px, calc(100vw - 30px));
    max-width: 980px;
    max-height: min(92vh, 900px);
}
.querymap-modal-body { gap: 12px; }
.querymap-instructions {
    padding: 10px 13px;
    border-left: 4px solid var(--db-yellow);
    border-radius: 0 8px 8px 0;
    color: var(--db-ink);
    background: #fff8df;
    font-size: .9rem;
}
.database-querymap {
    width: 100%;
    height: min(54vh, 540px);
    min-height: 390px;
    overflow: hidden;
    border: 1px solid var(--db-line);
    border-radius: 12px;
    background: #e8f0f4;
}
.database-querymap.querymap-loading-markers::after {
    content: '';
    position: absolute;
}
.querymap-coordinate-summary {
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 9px;
    color: #07577d;
    background: #edf7fb;
    font-size: .88rem;
    font-weight: 700;
}
.querymap-coordinate-summary.is-error {
    color: var(--db-danger);
    background: #fff0f0;
}
.database-querymap .leaflet-popup-content { line-height: 1.5; }

@media (max-width: 800px) {
    .database-zone-active { align-items: flex-start; flex-direction: column; }
    .database-querymap { min-height: 340px; height: 48vh; }
}

@media (max-width: 560px) {
    .database-links { width: 100%; }
    .database-querymap { min-height: 310px; }
}


/* =========================================================
   Modal de registro de descargas CRSMD
   ========================================================= */
.download-registration-modal {
    background: #fff;
}

.download-registration-modal .medium-modal-shell {
    background: #fff;
}

.download-registration-modal .medium-modal-shell > header {
    color: #fff;
    background: var(--db-ucr);
    border-bottom-color: rgba(255, 255, 255, .22);
}

.download-registration-modal .medium-modal-shell > header .eyebrow,
.download-registration-modal .medium-modal-shell > header .eyebrow-blue,
.download-registration-modal .medium-modal-shell > header h2 {
    color: #fff;
}

.download-registration-modal .modal-close {
    color: var(--db-ucr-dark);
    background: #f4f8fb;
}

.download-registration-modal .medium-modal-body {
    color: var(--db-ink);
    background: #fff;
}

.download-registration-modal .medium-modal-body > p {
    color: #526b82;
}

.download-registration-modal .modal-field {
    color: #526b82;
}

.download-registration-modal .download-summary {
    color: #174968;
    background: #fff7d9;
}

.download-privacy-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 14px;
    border: 1px solid #cfe2ef;
    border-radius: 10px;
    color: #425d72;
    background: #f4f9fc;
    font-size: .86rem;
    line-height: 1.5;
}

.download-privacy-note p {
    margin: 0;
    color: inherit;
}

.download-privacy-icon {
    display: inline-grid;
    flex: 0 0 24px;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: #fff;
    background: var(--db-success);
    font-size: .78rem;
    font-weight: 900;
}

.download-modal-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin: 2px -24px -24px;
    padding: 16px 24px;
    border-top: 1px solid var(--db-line);
    background: #f7fafc;
}

.download-registration-modal .modal-status {
    color: var(--db-muted);
}

.download-registration-modal .modal-status.is-error {
    color: #a52a2a;
    font-weight: 700;
}

.download-registration-modal .modal-status.is-success {
    color: var(--db-success);
    font-weight: 700;
}

@media (max-width: 560px) {
    .download-modal-actions {
        margin-left: -16px;
        margin-right: -16px;
        margin-bottom: -24px;
        padding: 14px 16px;
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .download-modal-actions .btn-primary,
    .download-modal-actions .btn-light-action {
        width: 100%;
    }
}
