/* Chip / tag input - see wwwroot/js/app-chips.js and
   TagHelpers/AppChipsTagHelper.cs.

   Every colour is a Bootstrap CSS variable, never a literal - same rule as
   app-editor.css. This app defaults to dark and the toggle flips data-bs-theme
   at runtime with no reload, so a hard-coded #fff survives the flip and becomes
   an unreadable chip. */

/* Until the script runs, this is a plain textarea and must look like one. The
   wrapper only becomes a control once .app-chips-active is on it, which is why
   every rule below is scoped to that class - a broken script leaves a normal
   field rather than a half-styled one. */
.app-chips-active {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    width: 100%;
    min-height: calc(1.5em + 0.75rem + calc(var(--bs-border-width) * 2));
    padding: 0.375rem 0.5rem;
    border: var(--bs-border-width) solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    background-color: var(--bs-body-bg);
    cursor: text;
}

/* Focus lives on the inner input, but the visible boundary is the wrapper - so
   the ring has to be drawn here or keyboard focus appears to vanish inside the
   control. :focus-within is what makes that possible without JS. */
.app-chips-active:focus-within {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}

/* Hidden, never removed: it is still the posted control and still carries the
   data-val-* attributes asp-for generated. display:none rather than
   visibility/opacity so it takes no space and cannot be tabbed into. */
.app-chips-source-hidden {
    display: none;
}

.app-chips-list {
    display: contents;
}

.app-chips-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    max-width: 100%;
    padding: 0.125rem 0.25rem 0.125rem 0.5rem;
    border: var(--bs-border-width) solid var(--bs-border-color);
    border-radius: 2rem;
    background-color: var(--bs-tertiary-bg);
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Long names wrap the row rather than stretching the chip off the edge. */
.app-chips-chip-text {
    overflow-wrap: anywhere;
}

.app-chips-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--bs-secondary-color);
    font-size: 0.6875rem;
    line-height: 1;
}

.app-chips-chip-remove:hover,
.app-chips-chip-remove:focus-visible {
    background-color: var(--bs-danger);
    color: #fff;
}

/* The chip already carries a border, so the default focus ring doubles it and
   reads as two shapes. An outline offset outward keeps one clear target. */
.app-chips-chip-remove:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 1px;
}

/* Typing a name that is already a chip is not an error - the user asked for
   something already true - so the existing chip is pointed at instead of a
   message being raised. See add() in app-chips.js. */
.app-chips-chip-flash {
    animation: app-chips-flash 0.6s ease-out;
}

@keyframes app-chips-flash {
    0%, 100% { background-color: var(--bs-tertiary-bg); }
    30% { background-color: rgba(var(--bs-warning-rgb), 0.45); }
}

/* Somebody who has asked for reduced motion still needs to be told which chip
   matched, so the cue becomes a static hold rather than nothing at all. */
@media (prefers-reduced-motion: reduce) {
    .app-chips-chip-flash {
        animation: none;
        background-color: rgba(var(--bs-warning-rgb), 0.45);
    }
}

/* Borderless and transparent: the wrapper is drawing the box, and a second
   bordered box inside it looks like a nested field. Grows to fill the row so
   the click target is the whole remaining width, matching how clicking a text
   input's padding focuses it. */
.app-chips-entry {
    flex: 1 1 8rem;
    min-width: 8rem;
    padding: 0.125rem 0;
    border: 0;
    background: transparent;
    color: var(--bs-body-color);
    font-size: 0.875rem;
}

.app-chips-entry:focus {
    outline: none;
    box-shadow: none;
}

.app-chips-entry::placeholder {
    color: var(--bs-secondary-color);
    opacity: 1;
}

.app-chips-entry:disabled {
    background: transparent;
}

.app-chips-empty {
    color: var(--bs-secondary-color);
    font-size: 0.875rem;
}

/* The hint sits BELOW the control, so it is pulled out of the wrapper's flex
   row and given the full width. Empty most of the time - it only speaks when a
   limit is hit. */
.app-chips-hint {
    flex: 0 0 100%;
    margin-bottom: 0;
}

.app-chips-hint:empty {
    display: none;
}

/* Read-only render (inside <fieldset disabled>). No input and no remove
   buttons, and the box itself goes away: what is left should read as a list of
   values, the same way the locked form renders every other field flat rather
   than as a greyed-out control. */
.app-chips-active:has(.app-chips-source-hidden:disabled) {
    padding-left: 0;
    border-color: transparent;
    background-color: transparent;
    cursor: default;
}
