/* One search bar for the whole system: a single glass pill with a coloured icon chip, a field
   without any border of its own, a clear button, and the colour of the section it sits in.
   Loaded after every page style. The ":not(#_)" in front lets it win over the older rules. */

html:not(#_) body {
    --sb-glass: rgba(255, 255, 255, .86);
    --sb-ink: var(--text1, #17213c);
    --sb-ink2: var(--text2, #5a6580);
    --sb-line: rgba(120, 130, 170, .28);
    --sb-ease: cubic-bezier(.22, 1, .36, 1);
}

html[data-theme="dark"]:not(#_) body {
    --sb-glass: rgba(255, 255, 255, .08);
    --sb-ink: var(--text1, #eef2fa);
    --sb-line: rgba(180, 190, 255, .28);
}

/* the colour of each section */
html:not(#_) body .top-bar-search,
html:not(#_) body .modal-search-field,
html:not(#_) body .sb-field {
    --sb-t: #5b63e0;
    --sb-n: #8a93ff;
}

html:not(#_) body .acc-search,
html:not(#_) body .emp-toolbar-search,
html:not(#_) body .employee-access-search {
    --sb-t: #5069dc;
    --sb-n: #8a9bf0;
}

html:not(#_) body .cx-find,
html:not(#_) body .sp .find {
    --sb-t: #4a86e0;
    --sb-n: #7db1f5;
}

html:not(#_) body .hl-search {
    --sb-t: #8a4b7e;
    --sb-n: #c27ad6;
}

html:not(#_) body .till-journal-filters .sb-field {
    --sb-t: #3f6fb0;
    --sb-n: #7ea6dc;
}

html:not(#_) body .fr-search {
    --sb-t: var(--fr-t, #1f8f86);
    --sb-n: var(--fr-n, #3fb6a8);
}

html:not(#_) body .sh-search {
    --sb-t: var(--sh-t, #d9731f);
    --sb-n: var(--sh-n, #f0a659);
}

/* the search bar of a report list sits at the end of the chip row and takes the free width */
html:not(#_) body .fr-chips2 > .fr-search {
    flex: 1 1 260px;
    min-width: 220px;
    max-width: 420px;
    margin-inline-start: auto;
}

@media (max-width: 700px) {
    html:not(#_) body .fr-chips2 > .fr-search {
        flex-basis: 100%;
        max-width: none;
        margin-inline-start: 0;
    }
}

/* the pill */
html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 52px;
    min-height: 52px;
    margin: 0;
    padding: 0 8px;
    border: 1.5px solid color-mix(in srgb, var(--sb-t) 30%, var(--sb-line));
    border-radius: 18px;
    background:
        radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--sb-t) 11%, transparent), transparent 55%),
        var(--sb-glass);
    box-shadow: 0 10px 22px color-mix(in srgb, var(--sb-t) 9%, transparent), inset 0 1px 0 rgba(255, 255, 255, .75);
    color: var(--sb-ink);
    transition: border-color .25s, box-shadow .25s, transform .25s var(--sb-ease);
}

html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field):hover {
    border-color: color-mix(in srgb, var(--sb-t) 55%, transparent);
}

html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field):focus-within {
    border-color: var(--sb-t);
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--sb-t) 16%, transparent), 0 16px 30px color-mix(in srgb, var(--sb-t) 20%, transparent);
    transform: translateY(-2px);
}

/* the icon becomes a coloured chip */
html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) > i.ti:first-child {
    position: static;
    flex: none;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    margin: 0;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--sb-n), var(--sb-t));
    box-shadow: 0 8px 16px color-mix(in srgb, var(--sb-t) 32%, transparent), inset 0 1px 0 rgba(255, 255, 255, .4);
    color: #fff;
    font-size: 20px;
    animation: none;
    transform: none;
    transition: transform .35s var(--sb-ease);
}

html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field):focus-within > i.ti:first-child {
    transform: rotate(-8deg) scale(1.08);
}

/* the field has no frame of its own: the pill is the frame */
html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) input {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    outline: 0;
    background: transparent;
    box-shadow: none;
    color: var(--sb-ink);
    font: inherit;
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
}

html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) input:focus {
    border: 0;
    outline: 0;
    background: transparent;
    box-shadow: none;
}

html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) input::-webkit-search-cancel-button {
    display: none;
}

html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) input::placeholder {
    color: var(--sb-ink2);
    opacity: .8;
}

html:not(#_) body .employee-access-search kbd {
    display: none;
}

/* a label field of a filter row that now holds a search bar */
html:not(#_) body .sb-field > span {
    display: none;
}

/* clear button, added by search-bar.js */
.sb-clear {
    flex: none;
    display: none;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: color-mix(in srgb, var(--sb-t, #5b63e0) 12%, transparent);
    color: var(--sb-ink, inherit);
    cursor: pointer;
    transition: transform .25s var(--sb-ease), background .2s;
}

.sb-clear:hover {
    transform: rotate(90deg);
    background: color-mix(in srgb, var(--sb-t, #5b63e0) 24%, transparent);
}

.sb-clear i {
    color: var(--sb-ink, inherit) !important;
    font-size: 18px;
}

.has-value > .sb-clear {
    display: grid;
}

/* number of results, filled in by pages that know it */
.sb-count {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 12px;
    border-radius: 999px;
    background: color-mix(in srgb, #1f7a4d 16%, transparent);
    color: #1f7a4d;
    font-size: 13px;
    white-space: nowrap;
    animation: sb-pop .35s var(--sb-ease) both;
}

html[data-theme="dark"] .sb-count {
    color: #5fd391;
}

.sb-count[hidden] {
    display: none;
}

.sb-count.is-busy {
    background: color-mix(in srgb, #8a5cd0 16%, transparent);
    color: #8a5cd0;
}

.sb-count.is-none {
    background: color-mix(in srgb, #c4553a 14%, transparent);
    color: #c4553a;
}

.sb-key {
    flex: none;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    border: 1px solid var(--sb-line);
    background: color-mix(in srgb, var(--sb-t) 8%, transparent);
    color: var(--sb-ink2);
    font: inherit;
    font-size: 14px;
}

.has-value > .sb-key {
    display: none;
}

/* the top bar: the icon button stays, the field that opens beside it gets the same look */
html:not(#_) body .top-bar-search.open .top-bar-search-input {
    width: min(280px, 56vw);
    height: 46px;
    padding: 0 18px;
    border: 1.5px solid color-mix(in srgb, var(--sb-t) 45%, var(--sb-line));
    border-radius: 18px;
    background:
        radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--sb-t) 11%, transparent), transparent 55%),
        var(--sb-glass);
    box-shadow: 0 10px 22px color-mix(in srgb, var(--sb-t) 12%, transparent), inset 0 1px 0 rgba(255, 255, 255, .75);
    color: var(--sb-ink);
    font-size: 15px;
}

html:not(#_) body .top-bar-search.open .top-bar-search-input:focus {
    border-color: var(--sb-t);
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--sb-t) 16%, transparent), 0 16px 30px color-mix(in srgb, var(--sb-t) 20%, transparent);
}

html:not(#_) body .top-bar-search-toggle {
    background: linear-gradient(145deg, var(--sb-n), var(--sb-t));
    box-shadow: 0 8px 16px color-mix(in srgb, var(--sb-t) 30%, transparent), inset 0 1px 0 rgba(255, 255, 255, .4);
}

html:not(#_) body .top-bar-search-toggle i {
    color: #fff;
}

@keyframes sb-pop {
    from {
        opacity: 0;
        transform: scale(.7);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@media (max-width: 640px) {
    html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) {
        height: 48px;
        min-height: 48px;
        max-width: none;
    }

    html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) > i.ti:first-child {
        width: 34px;
        height: 34px;
        font-size: 18px;
    }

    html:not(#_) body :is(.acc-search, .cx-find, .employee-access-search, .modal-search-field, .emp-toolbar-search, .fr-search, .sp .find, .hl-search, .sh-search, .sb-field) input {
        font-size: 15px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sb-count {
        animation: none;
    }
}
