/* =============================================================================
   Search mode
   The search panel beside the list, and the search chain on the row under
   the list's toolbar (docs/krav/soklage.md).
   ============================================================================= */

:root {
    --warp-search-panel-width: 480px;
}

/* -------------------------------------------------------------------------
   The panel: from the right under the app bar. Above 1280 px the list
   gives it room; up to 1280 px, as on an iPad, it lies over the list's
   right part.
   ------------------------------------------------------------------------- */

.warp-module-tabs,
.warp-content--list,
.warp-content--record {
    transition: margin-right var(--warp-transition-slow);
}

@media (min-width: 1281px) {
    body.warp-search-open .warp-module-tabs,
    body.warp-search-open .warp-content--list,
    body.warp-search-open .warp-content--record {
        margin-right: var(--warp-search-panel-width);
    }
}

/* The app bar's menus open over the panel. */
body.warp-search-open .warp-app-bar {
    z-index: calc(var(--warp-z-modal) + 1);
}

.warp-search-panel {
    position: fixed;
    top: var(--warp-header-height);
    right: 0;
    bottom: 0;
    z-index: var(--warp-z-modal);
    display: flex;
    flex-direction: column;
    width: var(--warp-search-panel-width);
    max-width: 100vw;
    background-color: white;
    border-left: 1px solid var(--warp-color-gray-300);
    box-shadow: var(--warp-shadow-xl);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform var(--warp-transition-slow), visibility 0s linear 300ms;
}

.warp-search-panel--open {
    transform: none;
    visibility: visible;
    transition: transform var(--warp-transition-slow), visibility 0s;
}

/* In the styleguide: in the page's flow, open */
.warp-search-panel--static {
    position: relative;
    top: auto;
    z-index: auto;
    height: 32rem;
    border: 1px solid var(--warp-color-gray-300);
    box-shadow: none;
    transform: none;
    visibility: visible;
}

.warp-search-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.warp-search-panel-header {
    display: flex;
    align-items: center;
    gap: var(--warp-spacing-2);
    min-height: 44px;
    padding: 0 var(--warp-spacing-2) 0 var(--warp-spacing-4);
    border-bottom: 2px solid var(--warp-color-primary-500);
    flex-shrink: 0;

    & h2 {
        display: flex;
        align-items: center;
        gap: var(--warp-spacing-2);
        font-size: var(--warp-font-size-md);
        font-weight: var(--warp-font-weight-semibold);
    }

    & h2 svg {
        color: var(--warp-color-primary-600);
    }
}

.warp-search-mode {
    padding: 1px var(--warp-spacing-2);
    border-radius: var(--warp-radius-pill);
    background-color: var(--warp-color-primary-50);
    color: var(--warp-color-primary-700);
    font-size: var(--warp-font-size-xs);
    font-weight: var(--warp-font-weight-medium);
    white-space: nowrap;
}

.warp-search-close {
    margin-left: auto;
}

.warp-search-panel [hidden] {
    display: none;
}

/* The groups as chips; a dot on a group with a filled field */
.warp-search-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--warp-spacing-1-5);
    padding: var(--warp-spacing-2-5) var(--warp-spacing-4);
    border-bottom: 1px solid var(--warp-color-gray-200);
    background-color: var(--warp-color-gray-50);
    flex-shrink: 0;
}

/* What Förfina or Utvidga searches within, above the fields, while one is hovered or focused; empty for Sök */
/* Two lines' height, also empty: a longer scope is cut, and neither the fields nor the footer's buttons move on hover */
.warp-search-scope {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    height: calc(var(--warp-font-size-xs) * 1.5 * 2 + 2 * var(--warp-spacing-1-5) + 1px);
    margin: 0;
    padding: var(--warp-spacing-1-5) var(--warp-spacing-4);
    border-bottom: 1px solid var(--warp-color-gray-200);
    color: var(--warp-color-gray-700);
    font-size: var(--warp-font-size-xs);
    line-height: 1.5;
    overflow-wrap: anywhere;
    flex-shrink: 0;
}

.warp-search-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--warp-spacing-1-5);
    min-height: 24px;
    padding: 0 var(--warp-spacing-2-5);
    border: 1px solid var(--warp-color-gray-300);
    border-radius: var(--warp-radius-pill);
    background-color: white;
    color: var(--warp-color-gray-700);
    font-size: var(--warp-font-size-xs);
    text-decoration: none;

    &:hover {
        border-color: var(--warp-color-gray-500);
    }

    &[aria-current="true"] {
        border-color: var(--warp-color-primary-300);
        background-color: var(--warp-color-primary-50);
        color: var(--warp-color-primary-700);
        font-weight: var(--warp-font-weight-medium);
    }

    &[data-filled="true"] {
        border-color: var(--warp-color-warning-700);
    }
}

.warp-search-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--warp-color-warning-700);
    visibility: hidden;
    flex-shrink: 0;

    [data-filled="true"] > & {
        visibility: visible;
    }
}

.warp-search-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--warp-spacing-3) var(--warp-spacing-4);
    --warp-field-label-width: 130px;

    /* Room for the last group to scroll to the top; as content, so that the area shrinks and the footer stays */
    &::after {
        content: '';
        display: block;
        height: 50vh;
    }
}

.warp-search-group {
    padding-bottom: var(--warp-spacing-2);

    & .warp-record-heading {
        margin-top: var(--warp-spacing-4);
    }

    &:first-child .warp-record-heading {
        margin-top: 0;
    }
}

/*
   One fixed label column for every field: a long label wraps onto more
   lines, and a word longer than the column, as Momsregistreringsnummer,
   is hyphenated, or broken where the browser has no hyphenation, so that
   every control starts at the same place. Never cut off.
*/
.warp-search-form .warp-field:not(.warp-field--above) {
    grid-template-columns: var(--warp-field-label-width) minmax(0, 1fr);

    & > .warp-field-label {
        overflow-wrap: anywhere;
        -webkit-hyphens: auto;
        hyphens: auto;
    }
}

.warp-search-form .warp-input,
.warp-search-form .warp-select,
.warp-search-form .warp-combobox {
    max-width: 18rem;
}

/* A value searched for is marked, as in FileMaker's find mode; an error's border goes before it */
.warp-search-form :where(.warp-input:not(:placeholder-shown), .warp-select:has(option:checked:not([value=""]))) {
    background-color: var(--warp-color-warning-50);
    border-color: var(--warp-color-warning-700);
}

.warp-search-form .warp-field--error .warp-input,
.warp-search-form .warp-field--error .warp-select {
    border-color: var(--warp-color-danger-500);
}

.warp-search-control {
    display: flex;
    align-items: center;
    gap: var(--warp-spacing-1-5);

    & .warp-input {
        flex: 1;
        min-width: 0;
    }
}

/* Operatorer at the first text field */
.warp-search-help .warp-btn-nav {
    color: var(--warp-color-info-500);
}

/* The operators' dialog: the operator as typed, on one line */
.warp-search-operators kbd {
    white-space: pre;
    font-family: var(--warp-font-family-mono);
}

/* The buttons on one row in the panel's 480 px, also with their counts; the preview's count, where shown, has a row of its own above them */
.warp-search-panel-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--warp-spacing-1-5);
    padding: var(--warp-spacing-3) var(--warp-spacing-4);
    border-top: 1px solid var(--warp-color-gray-200);
    background-color: var(--warp-color-gray-50);
    flex-shrink: 0;

    /* The count has its own space before the parenthesis */
    & .warp-btn {
        gap: 0;
        padding-inline: var(--warp-spacing-2-5);
    }
}

/* The panel's error or Inga träffar, under what the step searches within. */
.warp-search-form > .warp-notice {
    flex-shrink: 0;
    margin: var(--warp-spacing-2) var(--warp-spacing-4) 0;
}

.warp-search-spacer {
    flex: 1;
}

/* A button's result in the preview, with room reserved so that the buttons do not move as counts arrive */
.warp-search-count {
    display: inline-block;
    min-width: 7ch;
    text-align: start;
    font-variant-numeric: tabular-nums;
    transition: opacity var(--warp-transition-default);
}

.warp-search-count--stale {
    opacity: 0.5;
}

/* The preview's count, where the panel covers the list */
.warp-search-preview {
    display: none;
    flex-basis: 100%;
    margin: 0;
    color: var(--warp-color-gray-700);
    font-size: var(--warp-font-size-sm);
    font-variant-numeric: tabular-nums;
}

/* On a card there is no list beside the panel: the count is in the footer */
.warp-record-search .warp-search-preview:not(:empty) {
    display: block;
}

/* Narrow screens: the panel covers the list */
@media (max-width: 900px) {
    :root {
        --warp-search-panel-width: 100vw;
    }

    .warp-search-panel {
        border-left: 0;
    }

    .warp-search-preview:not(:empty) {
        display: block;
    }
}

/* Small screens: the label goes above the field */
@media (max-width: 560px) {
    .warp-search-form .warp-field {
        grid-template-columns: minmax(0, 1fr);

        & > .warp-field-label {
            grid-row: auto;
            padding-block: 0;
        }

        & > .warp-field-control,
        & > .warp-field-message {
            grid-column: 1;
        }
    }
}

/* -------------------------------------------------------------------------
   The search chain, on the row under the list's toolbar
   ------------------------------------------------------------------------- */

.warp-search-chain {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--warp-spacing-1-5);
    padding: var(--warp-spacing-1-5) var(--warp-spacing-4);
    background-color: var(--warp-color-info-50);
    border-top: 1px solid var(--warp-color-info-100);
    border-bottom: 1px solid var(--warp-color-info-100);
    color: var(--warp-color-info-600);
    font-size: var(--warp-font-size-sm);
}

.warp-search-chain-selection {
    font-weight: var(--warp-font-weight-semibold);
}

.warp-search-step {
    display: inline-flex;
    align-items: center;
    gap: var(--warp-spacing-1-5);
    min-height: 24px;
    padding: 0 var(--warp-spacing-2);
    border: 1px solid var(--warp-color-info-500);
    border-radius: var(--warp-radius-pill);
    background-color: white;
    color: var(--warp-color-gray-900);
    font: inherit;
    cursor: pointer;

    & .warp-search-step-remove {
        width: 0.85em;
        color: var(--warp-color-gray-500);
    }

    &:hover {
        border-color: var(--warp-color-danger-600);

        & .warp-search-step-remove {
            color: var(--warp-color-danger-600);
        }
    }
}

.warp-search-chain-edit {
    margin-left: var(--warp-spacing-1);
}

/* On a record's card: one line, the steps cut with an ellipsis */
.warp-search-chain--card {
    flex-wrap: nowrap;

    & > .warp-search-chain-edit {
        flex-shrink: 0;
    }
}

/* No width of its own: a long chain never widens the page, and the steps take the room there is */
.warp-search-chain-steps {
    flex: 1 1 auto;
    min-width: 0;
    contain: inline-size;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;

    & > * {
        vertical-align: middle;
    }
}

/* With focus inside, the row wraps, so that a focused step is never cut */
.warp-search-chain--card:focus-within {
    flex-wrap: wrap;

    & .warp-search-chain-steps {
        overflow: visible;
        white-space: normal;
    }
}

/* The whole chain, while the row cuts it */
.warp-search-chain-more {
    flex-shrink: 0;

    &[hidden] {
        display: none;
    }
}

.warp-search-chain-list {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    flex-shrink: 0;
    white-space: nowrap;
}

/* The notice and the button … are shown by warp--search */
.warp-record-search [hidden] {
    display: none;
}

/* While the record is edited the search waits */
body.warp-editing .warp-record-search {
    display: none;
}

/* -------------------------------------------------------------------------
   The preview: over the list's frame while the panel is open, with the
   new step dashed, and opaque, so that the list under it never shows
   through. Its content is dimmed while it no longer matches the input.
   ------------------------------------------------------------------------- */

.warp-list-preview {
    position: absolute;
    inset: 0;
    z-index: calc(var(--warp-z-sticky) + 1);
    display: flex;
    flex-direction: column;
    background-color: var(--warp-color-white);

    & > * {
        transition: opacity var(--warp-transition-default);
    }
}

.warp-list-preview--stale > *,
.warp-list-count--stale {
    opacity: 0.5;
}

.warp-list-count--preview {
    color: var(--warp-color-info-600);
    font-weight: var(--warp-font-weight-semibold);
}

.warp-search-step--pending {
    border-style: dashed;
    background-color: transparent;
    color: var(--warp-color-info-600);
    font-style: italic;
    cursor: default;
}

.warp-search-chain-preview {
    margin-left: var(--warp-spacing-1);
    font-size: var(--warp-font-size-xs);
    font-style: italic;
}

/* Touch: 44 px targets */
@media (pointer: coarse) {
    .warp-search-chip,
    .warp-search-step,
    .warp-search-chain-list,
    .warp-search-chain-more .warp-btn-nav,
    .warp-search-close,
    .warp-search-help .warp-btn-nav {
        min-height: var(--warp-touch-target);
    }

    .warp-search-close,
    .warp-search-chain-more .warp-btn-nav,
    .warp-search-help .warp-btn-nav {
        min-width: var(--warp-touch-target);
    }
}
