/* ==========================================================================
   NiceSelect: every dropdown in NextClass drawn as our own
   (static/ui/nice-select.js does the work; this is how it looks).

   The page's own <select> stays in place, hidden, so forms, validation and
   every existing script keep working. Beside it sits a button that takes the
   select's own classes, so it looks exactly like the field it replaces on
   each page, and the list it opens is drawn here.

   Linked early in <head>, before each page's styles, so a page's own field
   classes (form-control, it-input ...) always win for the button.
   ========================================================================== */

/* The real select: out of sight and out of the tab order, but still in the
   form and still focusable, so "please fill in this field" can point at it */
.ns-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
}

/* The button that takes its place */
.ns-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-align: left;
    cursor: pointer;
    font: inherit;
    /* What a real select and its neighbouring inputs use, so a button with
       the same padding comes out the same height as them */
    line-height: normal;
    color: inherit;
    -webkit-appearance: none;
    appearance: none;
}

.ns-button .ns-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ns-button .ns-caret {
    flex: none;
    width: 16px;
    height: 16px;
    opacity: 0.6;
    transition: transform 0.2s ease;
}

.ns-button[aria-expanded="true"] .ns-caret { transform: rotate(180deg); }
.ns-button.ns-placeholder .ns-label { opacity: 0.6; }
.ns-button:disabled { opacity: 0.55; cursor: not-allowed; }
.ns-button:focus-visible { outline: 2px solid var(--primary, #6366f1); outline-offset: 2px; }

.ns-button.ns-invalid {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18) !important;
}

/* A select that had no classes of its own still gets a field's look. Held
   at no weight at all (:where), so a page that styles its fields by tag
   (input, select, .ns-button { ... }) still wins */
:where(.ns-button.ns-plain) {
    min-height: 38px;
    padding: 0.45rem 0.7rem;
    border: 1px solid rgba(148, 163, 184, 0.4);
    border-radius: 9px;
    background: transparent;
}

/* ---- The list ---- */
.ns-panel {
    --ns-bg: #ffffff;
    --ns-text: #0f172a;
    --ns-muted: #64748b;
    --ns-border: rgba(15, 23, 42, 0.12);
    --ns-hover: rgba(99, 102, 241, 0.08);
    --ns-sel: rgba(99, 102, 241, 0.13);

    position: fixed;
    z-index: 2147483000;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 0.3rem;
    border-radius: 12px;
    border: 1px solid var(--ns-border);
    background: var(--ns-bg);
    color: var(--ns-text);
    font-size: 0.9rem;
    line-height: 1.35;
    text-align: left;
    box-shadow: 0 20px 44px -16px rgba(15, 23, 42, 0.35), 0 2px 8px rgba(15, 23, 42, 0.08);
    opacity: 0;
    transform: translateY(-4px);
    visibility: hidden;
    transition: opacity 0.14s ease, transform 0.16s ease, visibility 0s linear 0.16s;
}

.ns-panel.ns-dark {
    --ns-bg: #141a29;
    --ns-text: #f1f5f9;
    --ns-muted: #94a3b8;
    --ns-border: rgba(255, 255, 255, 0.12);
    --ns-hover: rgba(129, 140, 248, 0.13);
    --ns-sel: rgba(129, 140, 248, 0.2);
    box-shadow: 0 20px 44px -12px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.25);
}

.ns-panel.ns-up { transform: translateY(4px); }

.ns-panel.open {
    opacity: 1;
    transform: none;
    visibility: visible;
    transition: opacity 0.14s ease, transform 0.16s ease;
}

.ns-panel:focus { outline: none; }

/* Long lists get a search box */
.ns-search {
    flex: none;
    box-sizing: border-box;
    width: auto;
    height: 36px;
    margin: 0.15rem 0.15rem 0.35rem;
    padding: 0 0.7rem 0 2rem;
    border-radius: 9px;
    border: 1px solid var(--ns-border);
    background: transparent no-repeat 0.6rem center / 15px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.5' y2='16.5'/%3E%3C/svg%3E");
    color: inherit;
    font: inherit;
    font-size: 0.86rem;
}

.ns-search:focus { outline: none; border-color: var(--ns-accent, #6366f1); }

.ns-list { flex: 1; min-height: 0; overflow-y: auto; }

.ns-group {
    padding: 0.55rem 0.7rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ns-muted);
}

.ns-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    cursor: pointer;
}

.ns-option .ns-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ns-option .ns-tick { flex: none; width: 16px; height: 16px; color: var(--ns-accent, #6366f1); visibility: hidden; }
.ns-option.active { background: var(--ns-hover); }
.ns-option[aria-selected="true"] { background: var(--ns-sel); font-weight: 600; }
.ns-option[aria-selected="true"] .ns-tick { visibility: visible; }
.ns-option.ns-blank .ns-text { color: var(--ns-muted); }
.ns-option[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.ns-none { padding: 0.8rem; text-align: center; font-size: 0.85rem; color: var(--ns-muted); }

/* What the search leaves out. display:flex above would otherwise keep a
   hidden option on screen, so the list never narrowed down */
.ns-panel [hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
    .ns-panel, .ns-panel.open, .ns-button .ns-caret { transition: none; }
}
