/* =========================================================
   DDSI · Componentes transversales
   Botones, cards, banners, toasts, modal, skeletons, forms.
   ========================================================= */

/* ---------- Accesibilidad base ---------- */
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    overflow: hidden;
    white-space: nowrap;
}

:focus-visible {
    outline: 3px solid #2f855a;
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---------- Botones ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--gap-2);
    min-height: var(--hit);
    padding: 0 var(--gap-5);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
}

/* Forma única de los botones en todo el portal: redondeados.
   Va con !important porque admin, landing y los mapas traen sus propios botones. */
.btn,
button[class*="btn-"],
a[class*="btn-"],
label[class*="btn-"],
.confirm-dialog-btn,
.donate-cta,
.in-progress-button,
.entity-search-trigger,
.entity-search-close,
.entities-close,
.modal-close,
.toast-close,
.photo-drop-button,
.pagination-arrow,
.pagination-current,
.skip-link {
    border-radius: var(--radius-pill) !important;
}

/* Zoom de los mapas: las dos mitades forman una sola cápsula. */
.leaflet-container .leaflet-control-zoom {
    overflow: hidden !important;
    border-radius: var(--radius-pill) !important;
}

.btn svg { width: 18px; height: 18px; }

.btn:active:not([disabled]) { transform: scale(.98); }

.btn-sm {
    min-height: var(--hit);
    padding: 0 var(--gap-4);
    font-size: 13px;
}

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

.btn-primary:hover, .btn-primary:focus-visible { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-secondary {
    background: var(--white);
    border-color: var(--line-strong);
    color: var(--ink-2);
}

.btn-secondary:hover, .btn-secondary:focus-visible { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }

.btn-ghost {
    background: transparent;
    color: var(--accent-dark);
}

.btn-ghost:hover, .btn-ghost:focus-visible { background: var(--accent-soft); }

.btn-danger {
    background: var(--white);
    border-color: #f3c1c1;
    color: var(--status-danger);
}

.btn-danger:hover, .btn-danger:focus-visible { background: #fbeaea; border-color: var(--status-danger); }

.btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
}

.btn-block { width: 100%; }

/* ---------- Cards y paneles ---------- */
.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    background: var(--map-bg);
    color: var(--ink-2);
}

.chip-success { background: var(--accent-soft); color: var(--accent-dark); }
.chip-warning { background: #fdf3e3; color: var(--status-urgent); }
.chip-danger  { background: #fbeaea; color: var(--status-danger); }
.chip-info    { background: #eef2fd; color: var(--status-info); }
.chip-demo    { background: #fff7e0; color: #8a6d00; border: 1px dashed #e3c878; }

/* ---------- Banners ---------- */
.banner {
    display: flex;
    align-items: flex-start;
    gap: var(--gap-3);
    padding: var(--gap-3) var(--gap-4);
    border-radius: var(--radius);
    border: 1px solid var(--line);
    font-size: 13px;
    line-height: 1.5;
}

.banner svg { flex-shrink: 0; width: 20px; height: 20px; margin-top: 1px; }

.banner-demo {
    background: #fff7e0;
    border-color: #e3c878;
    color: #5c4a00;
}

.banner-warning {
    background: #fdf3e3;
    border-color: #f0d2a0;
    color: #6b4b00;
}

.banner-info {
    background: #eef2fd;
    border-color: #c7d5f5;
    color: #173a6b;
}

.banner-error {
    background: #fbeaea;
    border-color: #f3c1c1;
    color: #6b1515;
}

.banner a { color: inherit; font-weight: 600; }

/* ---------- Toasts ---------- */
.toast-region {
    position: fixed;
    top: calc(var(--header-h) + var(--gap-3));
    right: var(--gap-4);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: var(--gap-2);
    width: min(360px, calc(100vw - 32px));
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--gap-2);
    padding: var(--gap-3);
    border-radius: var(--radius);
    background: var(--ink);
    color: var(--white);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    line-height: 1.45;
    animation: toast-in .18s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
}

.toast-success { background: #14532d; }
.toast-error   { background: #7f1d1d; }
.toast-info    { background: #1e3a5f; }

.toast strong { font-weight: 700; }

.toast-close {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: inherit;
    opacity: .75;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    min-width: var(--hit);
    min-height: var(--hit);
    border-radius: var(--radius-sm);
}

.toast-close:hover { opacity: 1; }

/* ---------- Modal ---------- */
/* Se excluye .fade para no pisar el modal de Bootstrap en las páginas que lo usan. */
.modal:not(.fade) {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: grid;
    place-items: center;
    padding: var(--gap-4);
    background: rgba(15, 18, 16, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
}

.modal:not(.fade).is-open {
    opacity: 1;
    pointer-events: auto;
}

.modal:not(.fade)[hidden] { display: none; }

.modal:not(.fade) .modal-dialog {
    width: min(560px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transform: translateY(8px);
    transition: transform .18s ease;
}

.modal:not(.fade).is-open .modal-dialog { transform: none; }

.modal:not(.fade) .modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap-3);
    padding: var(--gap-4) var(--gap-5) 0;
}

.modal:not(.fade) .modal-head h2 {
    margin: 0;
    font-size: 18px;
}

.modal:not(.fade) .modal-body { padding: var(--gap-4) var(--gap-5); }
.modal:not(.fade) .modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: var(--gap-3);
    padding: 0 var(--gap-5) var(--gap-5);
    flex-wrap: wrap;
}

.modal:not(.fade) .modal-close {
    width: var(--hit);
    height: var(--hit);
    display: grid;
    place-items: center;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    font-size: 22px;
    cursor: pointer;
    color: var(--muted);
}

.modal:not(.fade) .modal-close:hover { background: var(--map-bg); color: var(--ink); }

/* ---------- Modal de confirmación (core/confirm.js) ---------- */
.confirm-dialog {
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    margin: auto;
    padding: var(--gap-5);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--white);
    color: var(--ink);
    font-family: var(--font);
    box-shadow: var(--shadow-lg);
}

.confirm-dialog::backdrop { background: rgba(15, 18, 16, .55); }

.confirm-dialog h2 {
    margin: 0 0 var(--gap-2);
    font-size: 18px;
    font-weight: 700;
}

.confirm-dialog p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.confirm-dialog-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--gap-2);
    margin-top: var(--gap-5);
}

.confirm-dialog-btn {
    min-height: var(--hit);
    padding: 0 var(--gap-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--ink-2);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.confirm-dialog-btn:hover { background: var(--map-bg); }

.confirm-dialog-btn.is-ok {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--white);
}

.confirm-dialog-btn.is-ok:hover { background: var(--accent-dark); }

.confirm-dialog-btn.is-ok.is-danger {
    border-color: var(--status-danger);
    background: var(--status-danger);
}

.confirm-dialog-btn.is-ok.is-danger:hover { background: #991b1b; }

@media (max-width: 480px) {
    .confirm-dialog-btn { flex: 1 1 100%; }
}

/* Marca de campo opcional en las etiquetas */
.opcional {
    margin-left: 4px;
    color: var(--muted);
    font-size: .85em;
    font-weight: 400;
}

/* ---------- Avisos de campos con error (core/form-validation.js) ---------- */
input.dt-invalid,
select.dt-invalid,
textarea.dt-invalid,
.dt-invalid-group.input-group,
.dt-invalid-group.buscador {
    border-color: var(--status-danger) !important;
    box-shadow: 0 0 0 3px rgba(185, 28, 28, .12) !important;
}

input.dt-invalid:focus,
select.dt-invalid:focus,
textarea.dt-invalid:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(185, 28, 28, .2) !important;
}

.dt-invalid-group .dt-invalid {
    box-shadow: none !important;
}

.dt-field-error {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    width: 100%;
    margin-top: 7px;
    padding: 8px 11px;
    border: 1px solid #f3c1c1;
    border-radius: var(--radius);
    background: #fdf0f0;
    color: #8f1d1d;
    font-family: var(--font);
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.4;
    text-align: left;
    animation: dt-error-in .16s ease;
}

.dt-field-error svg {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    margin-top: 1px;
    color: var(--status-danger);
}

@keyframes dt-error-in {
    from { opacity: 0; transform: translateY(-3px); }
    to { opacity: 1; transform: none; }
}

/* ---------- Indicadores de carga (core/loading.js) ---------- */
.dt-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2100;
    height: 4px;
    overflow: hidden;
    pointer-events: none;
    background: rgba(27, 120, 56, .15);
    opacity: 0;
    transition: opacity .2s ease;
}

.dt-progress.is-loading {
    opacity: 1;
}

.dt-progress-fill {
    position: relative;
    width: 0;
    height: 100%;
    overflow: hidden;
    background: linear-gradient(90deg, #1b7838, #2fa557);
    box-shadow: 0 0 10px rgba(27, 120, 56, .6), 0 0 4px rgba(27, 120, 56, .5);
    border-radius: 0 4px 4px 0;
}

/* Brillo que recorre la barra: deja claro que sigue trabajando aunque avance poco. */
.dt-progress-fill::after {
    content: "";
    position: absolute;
    inset: 0;
    width: 40%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .7), transparent);
    animation: dt-progress-brillo 1.1s ease-in-out infinite;
}

/* Avanza rápido al principio y se frena cerca del final: sabemos que empezó,
   no cuánto falta. Llega al 100 % cuando el navegador muestra la página nueva. */
.dt-progress.is-loading .dt-progress-fill {
    animation: dt-progress-avance 12s cubic-bezier(.08, .7, .25, 1) forwards;
}

@keyframes dt-progress-avance {
    0% { width: 0; }
    20% { width: 45%; }
    60% { width: 75%; }
    100% { width: 92%; }
}

@keyframes dt-progress-brillo {
    from { transform: translateX(-100%); }
    to { transform: translateX(260%); }
}

/* Modal de acciones largas */
body.dt-loading-open {
    overflow: hidden;
}

.dt-loading-modal {
    position: fixed;
    inset: 0;
    z-index: 2090;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--gap-4);
    background: rgba(15, 18, 16, .45);
}

.dt-loading-modal.is-open {
    display: flex;
    animation: dt-aparecer .18s ease;
}

.dt-loading-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: min(380px, 100%);
    padding: var(--gap-6) var(--gap-5);
    border-radius: var(--radius-lg);
    background: var(--white);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.dt-loading-spinner {
    width: 44px;
    height: 44px;
    margin-bottom: var(--gap-4);
    border: 4px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: dt-girar .8s linear infinite;
}

.dt-loading-title {
    margin: 0 0 var(--gap-2);
    color: var(--ink);
    font-family: var(--font);
    font-size: 17px;
    font-weight: 700;
}

.dt-loading-detail {
    margin: 0;
    color: var(--muted);
    font-family: var(--font);
    font-size: 13.5px;
    line-height: 1.5;
}

@keyframes dt-aparecer {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* "Está tardando más de lo normal" */
.dt-slow {
    position: fixed;
    left: 50%;
    bottom: calc(var(--gap-5) + env(safe-area-inset-bottom));
    z-index: 2080;
    display: none;
    align-items: center;
    gap: var(--gap-4);
    width: min(560px, calc(100vw - 24px));
    padding: var(--gap-3) var(--gap-4);
    border: 1px solid var(--line);
    border-left: 4px solid #d97706;
    border-radius: var(--radius-lg);
    background: var(--white);
    box-shadow: var(--shadow-lg);
    font-family: var(--font);
    transform: translateX(-50%);
}

.dt-slow.is-open {
    display: flex;
    animation: dt-aparecer .2s ease;
}

.dt-slow-text {
    display: grid;
    gap: 2px;
    flex: 1 1 auto;
    font-size: 13px;
    color: var(--muted);
}

.dt-slow-text strong {
    color: var(--ink);
    font-size: 14px;
}

.dt-slow-actions {
    display: flex;
    gap: var(--gap-2);
    flex: 0 0 auto;
}

@media (max-width: 560px) {
    .dt-slow { flex-direction: column; align-items: stretch; }
    .dt-slow-actions .btn { flex: 1 1 0; }
}

/* Sin conexión */
.dt-conn {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2095;
    display: none;
    align-items: center;
    justify-content: center;
    gap: var(--gap-2);
    min-height: 44px;
    padding: 8px var(--gap-4);
    background: #7f1d1d;
    color: #fff;
    font-family: var(--font);
    font-size: 13.5px;
    font-weight: 600;
    text-align: center;
}

.dt-conn.is-open {
    display: flex;
}

.dt-conn.is-back {
    background: var(--accent-dark);
}

.dt-conn-icon {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fca5a5;
    box-shadow: 0 0 0 4px rgba(252, 165, 165, .25);
}

.dt-conn.is-back .dt-conn-icon {
    background: #86efac;
    box-shadow: 0 0 0 4px rgba(134, 239, 172, .25);
}

.dt-conn.is-shake {
    animation: dt-sacudir .4s ease;
}

@keyframes dt-sacudir {
    0%, 100% { transform: none; }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* Botón ocupado */
.is-loading[aria-busy="true"] {
    pointer-events: none;
    cursor: progress;
    opacity: .85;
}

.dt-btn-spinner {
    display: inline-block;
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    margin-right: 8px;
    vertical-align: -2px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: dt-girar .7s linear infinite;
}

@keyframes dt-girar {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    /* El spinner sigue girando (más lento): sin él no se nota que está trabajando. */
    .dt-btn-spinner,
    .dt-loading-spinner { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
    .dt-progress.is-loading .dt-progress-fill { animation: none; width: 70%; }
}

/* ---------- Skeletons ---------- */
.skeleton {
    border-radius: var(--radius);
    background: linear-gradient(90deg, #eceeeb 25%, #f5f6f4 37%, #eceeeb 63%);
    background-size: 400% 100%;
    animation: skeleton-loading 1.4s ease infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

.skeleton-text { height: 12px; }
.skeleton-title { height: 16px; width: 60%; }
.skeleton-block { height: 120px; }

/* ---------- Progreso ---------- */
.progress {
    height: 8px;
    border-radius: var(--radius-pill);
    background: var(--map-bg);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: var(--radius-pill);
    transition: width .4s ease;
}

.progress-bar.is-complete { background: var(--status-delivered); }

/* ---------- Formularios ---------- */
.form-grid { display: grid; gap: var(--gap-4); }
.form-row { display: grid; gap: var(--gap-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
}

.field .req { color: var(--status-danger); }

.field input,
.field select,
.field textarea {
    min-height: var(--hit);
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--white);
    font: inherit;
    color: var(--ink);
}

.field textarea { min-height: 96px; resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--accent);
    outline: 3px solid rgba(27, 120, 56, .18);
}

.field .hint {
    font-size: 12px;
    color: var(--muted);
}

.field .error {
    font-size: 12px;
    font-weight: 600;
    color: var(--status-danger);
}

.field .error[hidden] { display: none; }

/* ---------- Empty states ---------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--gap-2);
    padding: var(--gap-7) var(--gap-4);
    color: var(--muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    stroke: var(--line-strong);
}

.empty-state h3 { margin: var(--gap-2) 0 0; font-size: 16px; color: var(--ink-2); }
.empty-state p { margin: 0; font-size: 13px; max-width: 420px; }

/* ---------- Leyenda ---------- */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-3);
    font-size: 12px;
    color: var(--muted);
}

.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--status-delivered); }
.legend-dot.transit { background: var(--status-transit); }
.legend-dot.pending { background: #d97706; }

/* ---------- prefers-reduced-motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
