﻿/* ============================================================================
   Horizontal filter toolbar (.sc-fb) - shared by Tournament/Index2 and LevelPoint/Index2.
   Behaviour: Scripts/shared/filter-toolbar.js (SCFilterBar). Spec: Docs/features/
   "SportConnect — Horizontal Filter Redesign.md".

   One DOM serves both layouts:
     >= 768px  the toolbar is a flex-wrap row; the sheet / fields wrappers are display:contents so
               every control flows into that row (Clear + Apply stay one flex group), and the
               Filters button, sheet header and backdrop are hidden.
     <  768px  search is a full-width row, a compact Filters button opens the sheet; the sheet is a
               fixed bottom sheet (header + scrolling fields + sticky Clear/Apply).
   Class names are flat (.sc-fb__x, never ".sc-fb .x") so the sheet can be re-parented to <body>
   if an ancestor ever breaks position:fixed.

   Colours: theme-v2.css tokens only - do not add a #hex / rgb() literal here.
   ============================================================================ */

/* ---- Toolbar shell ---- */
.sc-fb {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 10px 12px;
    box-sizing: border-box;
    min-width: 0;
    margin-bottom: 12px;
    padding: 14px;
    background: var(--v3-panel-bg);
    border: 1px solid var(--v3-panel-border);
    border-radius: var(--v3-panel-radius);
}

.sc-fb__sheet,
.sc-fb__fields {
    display: contents;
}

/* Clear + Apply stay together (never split across rows) and sit at the end of the last row. */
.sc-fb__actions {
    display: flex;
    flex: 0 0 auto;
    gap: 12px;
    margin-left: auto;
}

.sc-fb__sheet-head,
.sc-fb__toggle,
.sc-fb__backdrop {
    display: none;
}

/* ---- Field box: 48px, small label over the value, leading icon, optional chevron ---- */
.sc-fb__field {
    position: relative;
    display: block;
    box-sizing: border-box;
    height: 48px;
    min-width: 0;
    margin: 0; /* Bootstrap gives <label> margin-bottom: 5px */
    background: var(--color-input-bg);
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-md);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.sc-fb__field:hover {
    border-color: var(--color-border-light, var(--color-input-border));
}

.sc-fb__field:focus-within {
    border-color: var(--color-input-focus-border);
    box-shadow: var(--shadow-focus);
}

.sc-fb__field--search { flex: 2 1 180px; min-width: 160px; }
.sc-fb__field--select { flex: 1 1 150px; min-width: 140px; }
.sc-fb__field--number { flex: 1 1 120px; min-width: 110px; }
.sc-fb__field--range  { flex: 1.4 1 220px; min-width: 210px; }

/* Icon / label / chevron are painted ABOVE the control (theme CSS gives every <select> an opaque
   !important background) and let clicks fall through to it. */
.sc-fb__icon,
.sc-fb__chev {
    position: absolute;
    top: 50%;
    z-index: 1;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    pointer-events: none;
}

.sc-fb__icon {
    left: 13px;
    width: 16px;
    text-align: center;
    font-size: var(--font-size-md);
}

.sc-fb__chev {
    right: 12px;
    font-size: var(--font-size-xs);
}

.sc-fb__label {
    position: absolute;
    top: 7px;
    left: 40px;
    right: 30px;
    z-index: 1;
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    line-height: 1.2;
    white-space: nowrap;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* The control fills the whole box (so the whole box is the click / tap target) and keeps the
   value clear of the label above it, the icon on its left and the chevron on its right. */
.sc-fb__control {
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 20px 30px 0 40px;
    background: transparent;
    border: 0;
    border-radius: var(--radius-md);
    outline: none;
    color: var(--color-input-text);
    font-family: inherit;
    font-size: var(--font-size-md);
    line-height: 20px;
    text-overflow: ellipsis;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.sc-fb__control--plain {
    padding-top: 0;
    padding-right: 12px;
}

.sc-fb__control--number {
    padding-right: 12px;
    -moz-appearance: textfield;
}

.sc-fb__control--number::-webkit-outer-spin-button,
.sc-fb__control--number::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

select.sc-fb__control {
    cursor: pointer;
}

.sc-fb__control::placeholder {
    color: var(--color-input-placeholder);
}

.sc-fb__control option {
    background: var(--color-surface);
    color: var(--color-input-text);
}

/* Date range: two inputs share one box */
.sc-fb__range {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
    padding: 20px 12px 0 40px;
}

.sc-fb__range-sep {
    flex: 0 0 auto;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

.sc-fb__control--inline {
    position: static;
    flex: 1 1 0;
    min-width: 0;
    height: 20px;
    padding: 0;
    cursor: pointer;
}

/* ---- Buttons (skin from .sc-btn; this only fixes the height to match the fields) ---- */
.sc-btn.sc-fb__btn {
    flex: 0 0 auto;
    height: 48px;
    padding: 0 18px;
}

.sc-fb__toggle {
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    height: 44px;
    padding: 0 14px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-md);
    color: var(--color-input-text);
    font-family: inherit;
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
}

.sc-fb__toggle:focus-visible,
.sc-fb__close:focus-visible {
    outline: none;
    border-color: var(--color-input-focus-border);
    box-shadow: var(--shadow-focus);
}

.sc-fb__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    box-sizing: border-box;
    background: var(--color-button-primary-bg);
    border-radius: var(--radius-pill, 999px);
    color: var(--color-button-primary-text);
    font-size: var(--font-size-xs);
    font-weight: 700;
    line-height: 1;
}

.sc-fb__count[hidden] {
    display: none;
}

/* jQuery UI datepicker is appended to <body>; keep it above the mobile sheet. */
.ui-datepicker {
    z-index: calc(var(--z-modal) + 1) !important;
}

html.sc-fb-lock,
html.sc-fb-lock body {
    overflow: hidden;
}

/* ============================================================================
   .sc-fb--split (toolbars with 4+ dropdowns): when one row would not fit, row 1 = search +
   Clear/Apply and row 2 = the dropdowns (stretched to fill) instead of Apply dropping onto a row
   of its own. Listed ranges are where the TOOLBAR is narrower than ~1160px: the viewport up to
   1199px, plus 1281-1399px where the 3-col layout's right rail (190-250px) is back.
   (<= 1280px _LayoutV2 collapses to one column, see dashboard-v2.css.)
   Toolbars without the modifier just wrap in DOM order.
   ============================================================================ */
@media (min-width: 768px) and (max-width: 1199px), (min-width: 1281px) and (max-width: 1399px) {
    .sc-fb--split .sc-fb__field--search { flex: 1 1 260px; }
    .sc-fb--split .sc-fb__actions { order: 1; }
    /* the fields wrapper becomes its own full-width line (display:contents cannot force a break) */
    .sc-fb--split .sc-fb__fields {
        display: flex;
        flex: 1 1 100%;
        flex-wrap: wrap;
        gap: 10px 12px;
        order: 2;
    }
}

/* ============================================================================
   Phones (< 768px): search row + Filters button + bottom sheet
   ============================================================================ */
@media (max-width: 767px) {
    .sc-fb {
        display: grid;
        gap: 10px;
        padding: 10px;
    }

    .sc-fb__field--search,
    .sc-fb__field--select,
    .sc-fb__field--number,
    .sc-fb__field--range {
        flex: 0 0 auto;
        min-width: 0;
        width: 100%;
    }

    .sc-fb__toggle {
        display: inline-flex;
        justify-self: start;
    }

    .sc-fb__backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: var(--modal-overlay-bg);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s ease, visibility 0s linear 0.2s;
        z-index: var(--z-modal-overlay);
    }

    .sc-fb__backdrop.is-open {
        opacity: 1;
        visibility: visible;
        transition: opacity 0.2s ease;
    }

    .sc-fb__sheet {
        display: flex;
        flex-direction: column;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        box-sizing: border-box;
        max-height: 88vh;
        max-height: 88dvh;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-bottom: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: var(--shadow-overlay);
        transform: translateY(100%);
        visibility: hidden;
        transition: transform 0.25s ease, visibility 0s linear 0.25s;
        z-index: var(--z-modal);
    }

    .sc-fb__sheet.is-open {
        transform: none;
        visibility: visible;
        transition: transform 0.25s ease;
    }

    .sc-fb__sheet-head {
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        justify-content: space-between;
        position: relative;
        padding: 16px 8px 6px 16px;
    }

    .sc-fb__sheet-head::before {
        content: "";
        position: absolute;
        top: 6px;
        left: 50%;
        width: 40px;
        height: 4px;
        margin-left: -20px;
        background: var(--color-border);
        border-radius: 2px;
    }

    .sc-fb__title {
        margin: 0;
        color: var(--color-input-text); /* --color-text-primary is pale (wheat) in the light theme */
        font-size: 18px;
        font-weight: 700;
    }

    .sc-fb__close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        background: transparent;
        border: 1px solid transparent;
        border-radius: var(--radius-md);
        color: var(--color-input-text);
        font-size: 18px;
        cursor: pointer;
    }

    .sc-fb__fields {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        gap: 10px;
        min-height: 0;
        padding: 6px 16px 16px;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .sc-fb__actions {
        display: grid;
        flex: 0 0 auto;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-left: 0;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
    }

    .sc-btn.sc-fb__btn {
        width: 100%;
        height: 48px;
    }
}
