/* Small shared utilities only. Tailwind remains the main styling system. */

/*
 * Shared visible focus ring for primary action buttons/links (approve,
 * reject, suspend, delete, etc.) that otherwise only rely on the
 * browser's default (often invisible) outline. Uses the same primary
 * color token as the rest of the app.
 */
.b4-focus-ring:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 2px var(--b4-color-surface),
        0 0 0 4px var(--b4-color-primary);
}

/*
 * Frontend Advancement Roadmap, Phase 3. The one form-field wrapper.
 *
 * This used to be nine per-domain aliases (business-field,
 * business-profile-field, business-owner-field, profile-field,
 * settings-field, document-field, admin-field, service-field,
 * auth-field) repeated across every selector list below with
 * byte-identical declarations. They are now a single wrapper class;
 * the declarations are unchanged.
 *
 * It is a wrapper, not an input class, because Django renders inputs
 * via {{ form.x }} and forms.py must not carry styling classes - so the
 * wrapper styles what sits inside it.
 *
 * Per-domain textarea heights (96/120/130px) live in each domain's own
 * page stylesheet as `.form-field textarea`, which is exact because
 * every page that loads one of those stylesheets uses only that
 * domain's fields (verified when this was consolidated).
 */
.form-field ul,
.form-field .errorlist {
    margin-top: 0.5rem;
    color: var(--b4-color-danger);
    font-size: 0.875rem;
}

.form-field input:not([type="checkbox"]),
.form-field select,
.form-field textarea {
    width: 100%;
    border: 1px solid var(--b4-color-border-strong);
    border-radius: 0.75rem;
    background: var(--b4-color-surface);
    padding: 0.75rem 1rem;
    color: var(--b4-color-text);
    outline: none;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    border-color: var(--b4-color-primary);
    box-shadow: 0 0 0 3px rgba(var(--b4-color-primary-rgb), 0.12);
}

.form-field input[type="file"] {
    padding: 0.65rem;
}

/*
 * Advancement Stage 10E. Marks every required field's label across
 * all forms, site-wide, with one rule — Django already renders the
 * HTML5 `required` attribute on required widgets even when the
 * enclosing <form novalidate> suppresses browser-side enforcement, so
 * :has(:required) picks the right wrapper without any template
 * change or per-page markup.
 */
.form-field:has(:required) label::after {
    content: " *";
    color: var(--b4-color-danger);
}

/*
 * Navbar account menu. The menu is a native <details>/<summary> (this
 * project's documented disclosure pattern); Tailwind's `list-none`
 * hides the disclosure triangle in current browsers, but WebKit still
 * needs its own pseudo-element rule.
 */
.b4-profile-menu > summary::-webkit-details-marker {
    display: none;
}

/*
 * Advancement Stage 10E. Shared submit-button loading spinner — used
 * by static/js/main.js's setupDoubleSubmitProtection() alongside the
 * existing "Submitting…" text swap, so every form's double-submit
 * state gets the same visual treatment without per-page JS/CSS.
 */
.b4-spinner {
    display: inline-block;
    height: 1em;
    width: 1em;
    margin-right: 0.5rem;
    vertical-align: -0.125em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 9999px;
    animation: b4-spin 0.6s linear infinite;
}

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

/*
 * Modernization Phase 8. Ops tables become stacked cards below md.
 *
 * Master Plan §19: sideways-scrolling a table is not a mobile ops
 * experience. Below 768px each row becomes a card and each cell shows
 * its column name from data-label, which the calling template sets to
 * match the view's table_headers.
 *
 * The element stays a real <table> at every width — only presentation
 * changes — so row/column semantics survive for assistive tech. The
 * header row is hidden visually in card mode because data-label
 * carries the same information per cell.
 *
 * Scoped to .b4-ops-table (set by components/table_shell_start.html)
 * so no other table is affected.
 */
@media (max-width: 767px) {
    .b4-ops-table table,
    .b4-ops-table tbody,
    .b4-ops-table tr,
    .b4-ops-table td {
        display: block;
        width: auto;
    }

    .b4-ops-table thead {
        display: none;
    }

    .b4-ops-table table {
        min-width: 0;
    }

    .b4-ops-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem;
    }

    .b4-ops-table tr {
        border: 1px solid var(--b4-color-border);
        border-radius: var(--b4-radius-card);
        background: var(--b4-color-surface);
        padding: 0.25rem 0.25rem 0.5rem;
    }

    .b4-ops-table td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.5rem 0.75rem;
        max-width: none;
        text-align: right;
        /* Long emails and comments must wrap inside the card rather
           than pushing the page sideways. */
        overflow-wrap: anywhere;
    }

    .b4-ops-table td::before {
        content: attr(data-label);
        flex-shrink: 0;
        text-align: left;
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--b4-color-text-muted);
    }

    /* A cell with no data-label (e.g. the shared empty-state row)
       should not render a stray empty label box. */
    .b4-ops-table td:not([data-label])::before {
        content: none;
    }

    /* Row actions get a full-width, comfortable tap target. */
    .b4-ops-table td form,
    .b4-ops-table td .flex {
        width: 100%;
    }

    .b4-ops-table td button,
    .b4-ops-table td a {
        min-height: 2.75rem;
    }
}

/*
 * Modernization Phase 9. Global media guard.
 *
 * An image or video wider than its container is the other classic
 * source of horizontal page scroll, and nothing capped them before.
 * This only caps width and preserves aspect ratio — it never enlarges
 * anything, so deliberately-sized media is unaffected.
 *
 * Deliberately NOT paired with a blanket `overflow-wrap: anywhere` on
 * all text: that would change wrapping on every page including tables
 * and buttons. Long user-generated text is handled per render site
 * with `break-words` instead.
 */
img,
video {
    max-width: 100%;
    height: auto;
}

/*
 * Modernization Phase 10. Respect prefers-reduced-motion.
 *
 * Nothing guarded motion before this. The clearest case is the submit
 * spinner (.b4-spinner) — an infinite animation, which is exactly what
 * WCAG 2.3.3 and vestibular-disorder guidance care about.
 *
 * Disabling the spin loses no information: setupDoubleSubmitProtection()
 * in static/js/main.js swaps the button text to "Submitting…" at the
 * same time, so the in-progress state is still communicated. A guard
 * that removed the only progress signal would be a net accessibility
 * loss, not a win.
 *
 * Written as a broad reset rather than per-rule because Tailwind's
 * utility transitions (transition, hover:-translate-y-0.5, etc.) are
 * generated at build time and cannot be enumerated here. Durations are
 * shortened rather than removed so transitionend/animationend handlers
 * still fire. !important is confined to this media query, so it only
 * applies when the user has actually asked for reduced motion.
 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/*
 * Home page "Browse by category"/"Featured services" arrow-button
 * carousels used to hide their scrollbar via a .scrollbar-hide class
 * (scrollbar-width: none / ::-webkit-scrollbar{display:none}) on an
 * overflow-x-auto row. That CSS-only hide could still be overridden by
 * some OS/browser accessibility settings (forced-colors mode,
 * scrollbar-injection tools). Both rows now use overflow-x-hidden
 * instead — overflow: hidden never renders a scrollbar in any browser
 * under any setting, structurally, while element.scrollLeft/scrollBy()
 * (static/js/components/horizontal_scroller.js) still moves the
 * content. No CSS hide is needed anymore.
 */

.b4-confirm-dialog {
    width: calc(100% - 2rem);
    max-width: 28rem;
    margin: auto;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
    opacity: 0;
    transform: translateY(0.5rem) scale(0.98);
    transition:
        opacity var(--b4-duration-base) var(--b4-ease-standard),
        transform var(--b4-duration-base) var(--b4-ease-standard),
        overlay var(--b4-duration-base) allow-discrete,
        display var(--b4-duration-base) allow-discrete;
}

.b4-confirm-dialog[open] {
    opacity: 1;
    transform: none;
}

@starting-style {
    .b4-confirm-dialog[open] {
        opacity: 0;
        transform: translateY(0.5rem) scale(0.98);
    }
}

.b4-confirm-dialog::backdrop {
    background-color: rgb(15 23 42 / 0.55);
}

body {
    text-rendering: optimizeLegibility;
}
