/* Permit limits widget (`fragment-community-permit-limits.html`).
 *
 * Renders one column per `PermitLimit` row attached to the selected
 * Community, with the row's primary key as a column header above each
 * metrics column. Layout follows the engine's period-length-then-id sort
 * order so display matches evaluation.
 *
 * The widget is mounted on the permit registration, payment, patrol, and
 * manager pages -- each of those templates pulls this file in directly.
 */

table#permit-limits.permit-limits-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}

table#permit-limits.permit-limits-table th,
table#permit-limits.permit-limits-table td {
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    text-align: left;
    vertical-align: middle;
}

table#permit-limits.permit-limits-table thead th.permit-limits-corner {
    /* Top-left cell is intentionally blank; it is the empty header above the
       label column. */
    background: transparent;
    border-bottom-color: rgba(0, 0, 0, 0.18);
}

table#permit-limits.permit-limits-table thead th.permit-limits-pk {
    font-weight: 600;
    text-align: right;
    border-bottom-color: rgba(0, 0, 0, 0.18);
}

table#permit-limits.permit-limits-table tbody th.permit-limits-label {
    font-weight: 500;
    width: 60%;
    color: inherit;
}

table#permit-limits.permit-limits-table tbody td.permit-limits-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Empty-state row used when no PermitLimit rows are configured for the
   community. Renders inside a single tbody/tr/td so the DOM stays valid. */
table#permit-limits.permit-limits-table tbody td.permit-limits-empty {
    text-align: center;
    color: rgba(0, 0, 0, 0.55);
    font-style: italic;
}

table#permit-limits.permit-limits-table tbody tr:nth-child(odd) {
    background: rgba(0, 0, 0, 0.025);
}

table#permit-limits.permit-limits-table tbody tr:last-child th,
table#permit-limits.permit-limits-table tbody tr:last-child td {
    border-bottom: none;
}

/* "Days used in period" summary row — highlighted like patrol's allowed-usage. */
table#permit-limits.permit-limits-table tr.allowed-usage th,
table#permit-limits.permit-limits-table tr.allowed-usage td {
    background-color: rgba(40, 110, 80, 0.12);
    font-weight: 600;
}

/* Up-front permit budget banner (`fragment-permit-limit-banner.html`).
 *
 * Shown by `permit.js` once `community_id + tag + tag_state` are all known so
 * users see their per-policy remaining-days budget BEFORE filling out start
 * date / duration. Sticky to the top of the scroll container so it stays
 * visible while the user moves through the rest of the form.
 *
 * Reuses the project's existing warning visual vocabulary (border + glow in
 * darkred, matching `p.error-help` and `.toast.warning`) so the alert state
 * reads as urgent without inventing new colors.
 */
@keyframes permit-banner-slide-in {
    from {
        opacity: 0;
        transform: translateY(-1.25rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

section.permit-limit-budget-banner {
    position: sticky;
    top: 58px;
    width: 40rem;
    z-index: 11;
    margin: 0 auto;
    padding: .65rem .85rem .85rem;
    border: 4px solid rgba(40, 90, 60, .35);
    border-radius: .75rem;
    background-color: var(--background-color);
    box-shadow: 0 2px 8px 1px rgba(0, 0, 0, .12);
    display: flex;
    flex-direction: column;
    gap: .5rem;
    animation: permit-banner-slide-in 0.5s ease forwards;

    &.hidden {
        display: none;
    }

    .permit-limit-budget-banner__header {
        display: flex;
        align-items: center;
        gap: .5rem;
        margin: 0;
    }

    .permit-limit-budget-banner__icon {
        font-size: 1.25rem;
        line-height: 1;
    }

    .permit-limit-budget-banner__title {
        font-weight: 600;
        margin: 0;
    }

    ul.permit-limit-budget-banner__rows {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: .25rem;
    }

    li.permit-limit-budget-row {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: .35rem;
        padding: .1rem 0;
        font-variant-numeric: tabular-nums;
    }

    li.permit-limit-budget-row.exhausted {
        font-weight: 600;
        color: darkred;

        &::before {
            content: '⚠️';
            margin-right: .25rem;
        }
    }

    span.permit-limit-budget-row__primary {
        font-weight: 500;
    }

    span.permit-limit-budget-row__period {
        color: rgba(0, 0, 0, .55);
    }

    p.permit-limit-budget-banner__hint {
        margin: 0;
        font-size: .85em;
    }

    div.permit-limit-budget-banner__warning {
        margin-top: .25rem;
        padding: .5rem .65rem;
        border: 1px solid darkred;
        border-radius: .5rem;
        background-color: rgb(80% 30% 30% / 1);
        color: white;
        box-shadow: 0 0 4px 1px darkred;

        &.hidden {
            display: none;
        }

        p {
            margin: 0;
        }

        p + p {
            margin-top: .35rem;
        }

        p.permit-limit-budget-banner__warning-headline {
            font-weight: 600;
        }

        p.permit-limit-budget-banner__warning-courtesy {
            font-style: italic;
            font-size: .9em;
        }
    }

    /* When the warning is active, lift the banner's outer border colour to
       match so the entire widget reads as alarming, not just the inner panel. */
    &.warning {
        border-color: darkred;
        box-shadow: 0 0 6px 2px darkred;
    }
}
