/*!
 * W-Harambee shared UI layer.
 *
 * Themes SweetAlert2 to the brand and supplies the handful of primitives the
 * feedback layer needs — busy buttons, inline field errors, empty states — so
 * pages do not each invent their own. Deliberately scoped to wh-* and swal2-*
 * so it can be dropped into any page without touching existing styles.
 */

:root {
    --wh-brand: #2f9e44;
    --wh-brand-dark: #27803a;
    --wh-danger: #d33;
    --wh-warning: #f0932b;
    --wh-ink: #1f2933;
    --wh-muted: #64748b;
    --wh-line: #e2e8f0;
    --wh-radius: 12px;
}

/* ---------------------------------------------------------------- dialogs */

/* SweetAlert2 defaults to 1060, which loses to the dashboard theme: its modals
   sit at 9999, back-to-top and the translate tooltip at 10000, and the support
   button carries an inline 999999999. A confirmation that asks before money
   moves has to be the top layer, so it is put above all of them. */
.swal2-container {
    z-index: 1000000000;
}

.swal2-popup.wh-swal {
    border-radius: var(--wh-radius);
    padding: 1.75rem 1.5rem 1.5rem;
    font-family: 'Montserrat', 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
}

.swal2-popup.wh-swal .wh-swal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--wh-ink);
    line-height: 1.35;
}

.swal2-popup.wh-swal .wh-swal-text {
    font-size: 0.975rem;
    line-height: 1.6;
    color: var(--wh-muted);
}

.swal2-popup.wh-swal .swal2-actions {
    gap: 0.5rem;
    margin-top: 1.25rem;
    width: 100%;
}

.swal2-popup.wh-swal .wh-swal-btn {
    border-radius: 999px;
    padding: 0.65rem 1.75rem;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: none;
    transition: filter 0.15s ease, transform 0.15s ease;
}

.swal2-popup.wh-swal .wh-swal-btn:hover:not(:disabled) {
    filter: brightness(0.94);
    transform: translateY(-1px);
}

.swal2-popup.wh-swal .wh-swal-btn:focus-visible {
    outline: 3px solid rgba(47, 158, 68, 0.45);
    outline-offset: 2px;
}

.swal2-popup.wh-swal .swal2-footer {
    border-top-color: var(--wh-line);
    font-size: 0.85rem;
    color: var(--wh-muted);
}

/* The same close affordance the modals put in that corner, at dialog scale.
   The X is a grid cell, so the popup's padding holds it well inside the corner
   and its own height pushes the content down. The negative margins undo both:
   the first two pull it back out into the padding, the third takes its height
   back out of the flow the way SweetAlert's own margin-bottom does. */
.swal2-popup.wh-swal .wh-swal-close {
    width: 2rem;
    height: 2rem;
    margin: -1rem -0.75rem -2rem 0;
    font-size: 1.75rem;
    color: var(--wh-muted);
    border-radius: 6px;
}

.swal2-popup.wh-swal .wh-swal-close:hover,
.swal2-popup.wh-swal .wh-swal-close:focus-visible {
    color: var(--wh-ink);
    background: rgba(15, 23, 42, 0.06);
}

/* Toasts sit clear of fixed headers and never cover the viewport on a phone. */
.swal2-popup.wh-toast {
    padding: 0.85rem 1rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}

.swal2-popup.wh-toast .swal2-title {
    font-size: 0.925rem;
    font-weight: 500;
    line-height: 1.45;
    margin: 0;
    color: var(--wh-ink);
}

@media (max-width: 575.98px) {
    .swal2-popup.wh-swal {
        padding: 1.35rem 1.1rem 1.15rem;
        width: calc(100vw - 2rem);
    }

    /* Matched to the tighter padding above, so the X keeps the same inset. */
    .swal2-popup.wh-swal .wh-swal-close {
        margin: -0.6rem -0.35rem -2rem 0;
    }

    .swal2-popup.wh-swal .swal2-actions {
        flex-direction: column-reverse;
    }

    .swal2-popup.wh-swal .wh-swal-btn {
        width: 100%;
        margin: 0;
    }

    .swal2-container.swal2-top-end > .swal2-popup.wh-toast,
    .swal2-container.swal2-top-right > .swal2-popup.wh-toast {
        width: calc(100vw - 1.5rem);
        margin: 0.75rem;
    }
}

/* --------------------------------------------------------- busy controls */

.wh-btn-loading {
    cursor: progress !important;
    opacity: 0.85;
}

.wh-spinner {
    display: inline-block;
    width: 0.95em;
    height: 0.95em;
    margin-right: 0.5em;
    vertical-align: -0.12em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: wh-spin 0.7s linear infinite;
}

@keyframes wh-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .wh-spinner { animation-duration: 2s; }
    .swal2-popup.wh-swal .wh-swal-btn:hover:not(:disabled) { transform: none; }
}

/* ---------------------------------------------------- validation feedback */

.wh-invalid,
.wh-invalid:focus {
    border-color: var(--wh-danger) !important;
    box-shadow: 0 0 0 0.15rem rgba(221, 51, 51, 0.15) !important;
}

.wh-field-error {
    display: block;
    width: 100%;
    margin: 0.35rem 0 0;
    font-size: 0.825rem;
    line-height: 1.4;
    font-weight: 500;
    color: var(--wh-danger);
}

/* An .input-group or a .form-check may be a flex row; without this the message
   becomes another column and squashes the control next to it. Inert until the
   container is actually display:flex. */
.input-group,
.form-check {
    flex-wrap: wrap;
}

.input-group > .wh-field-error,
.form-check > .wh-field-error {
    flex-basis: 100%;
}

.wh-hint {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--wh-muted);
}

.wh-required {
    color: var(--wh-danger);
    font-weight: 600;
}

/* ------------------------------------------------------------ empty state */

.wh-empty {
    padding: 2.5rem 1.25rem;
    text-align: center;
    color: var(--wh-muted);
}

.wh-empty-icon {
    font-size: 2.25rem;
    line-height: 1;
    margin-bottom: 0.85rem;
    color: var(--wh-brand);
    opacity: 0.55;
}

.wh-empty-title {
    margin: 0 0 0.4rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--wh-ink);
}

.wh-empty p {
    margin: 0 auto 1rem;
    max-width: 38ch;
    font-size: 0.9rem;
}

/* ------------------------------------------------------------ a11y basics */

.wh-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Keyboard users get a visible focus ring the theme CSS otherwise removes. */
.wh-focusable:focus-visible,
.wh-swal-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(47, 158, 68, 0.45);
    outline-offset: 2px;
}

/* Comfortable tap targets on touch screens. */
@media (pointer: coarse) {
    .wh-swal-btn,
    button[type="submit"],
    input[type="submit"] {
        min-height: 44px;
    }
}
