/* ================================================================
   FriendsByChance — components/form-controls.css
   Touch-first form controls: OptionGrid, SegmentedChoice, Stepper.

   Everything here is built to a 44px minimum hit target.  These
   controls exist precisely because the native <select> and number
   spinners they replace are a few pixels tall.
   ================================================================ */

/* ── OptionGrid ──────────────────────────────────────────────────
   Two columns by default, four when there is room.  Deliberately not
   auto-fit: the spec is "4 per row if space allows, otherwise 2", and
   auto-fit would also produce 3 at intermediate widths. */
/* As many columns as fit at ~140px, never wider than the sheet: a cell's
   text WRAPS rather than widening its column — a fixed four once let one
   long description push the grid sideways, into one row that scrolled
   horizontally. */
.fbc-optgrid {
    display:               grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr));
    gap:                   10px;
}
/* A LEAD option (OptionGrid `lead`) comes first, on a row of its own. */
.fbc-optgrid-btn--lead { grid-column: 1 / -1; }

.fbc-optgrid-btn {
    min-height:    56px;
    padding:       8px 10px;
    font:          inherit;
    font-size:     0.92rem;
    border:        1px solid var(--color-divider);
    border-radius: 10px;
    background:    var(--color-surface);
    color:         var(--color-text);
    cursor:        pointer;
    transition:    background 0.1s, border-color 0.1s;
    /* An option's face is glyph + swatch + label, with the sub-label forced
       onto its own line by flex-basis — see _renderOptionFace. */
    display:       flex;
    flex-wrap:     wrap;
    align-items:   center;
    gap:           3px 8px;
    text-align:    left;
    min-width:     0;
}
.fbc-optgrid-btn:hover { background: var(--color-hover); }
/* In the grid there is room to wrap: whole words, never a cut-off line. */
.fbc-optgrid-btn .fbc-opt-label,
.fbc-optgrid-btn .fbc-opt-desc {
    white-space:   normal;
    overflow-wrap: anywhere;
    text-overflow: clip;
}
.fbc-optgrid-btn--selected {
    background:   var(--color-primary);
    border-color: var(--color-primary);
    color:        var(--color-text-on-primary);
    font-weight:  600;
}

/* ── ActionSheet ─────────────────────────────────────────────────
   OptionGrid's buttons, each an action: its icon and its words, and a
   heading over each group of them. */
.fbc-actsheet-label { margin: 14px 2px 6px; }   /* its look: .fbc-section-title (shared.css) */
.fbc-actsheet-label:first-child { margin-top: 0; }
.fbc-opt-svg {
    display:     inline-flex;
    flex-shrink: 0;
}
.fbc-opt-svg svg { width: 20px; height: 20px; }
/* Its words beside its icon, wrapping there rather than under it. */
.fbc-actsheet-btn .fbc-opt-label { flex: 1 1 0; }
.fbc-optgrid-btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor:  default;
}
.fbc-optgrid-btn[aria-disabled="true"]:hover { background: var(--color-surface); }

/* ── SegmentedChoice ─────────────────────────────────────────────
   Wraps rather than shrinking: a squeezed button is a missed tap. */
.fbc-segchoice {
    display:   flex;
    flex-wrap: wrap;
    gap:       6px;
}

.fbc-segchoice-btn {
    min-height:      44px;
    /* Tight enough that three of them and a group field share one row in a
       460px editor; still a 44px target, which is what matters. */
    padding:         0 11px;
    font:            inherit;
    font-size:       0.88rem;
    border:          1px solid var(--color-divider);
    border-radius:   8px;
    background:      var(--color-surface);
    color:           var(--color-text);
    cursor:          pointer;
    white-space:     nowrap;
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    gap:             7px;
    min-width:       0;
}

/* ── One option's face, shared by both controls ───────────────────
   Same glyph, swatch and label wherever a choice is drawn, so the
   button and the grid behind it cannot describe an option differently. */

/* The marker sits at a chip's top; in an option it is centred on the words. */
.tl-chip-marker.fbc-opt-icon {
    align-self:  auto;
    width:       15px;
    height:      15px;
    opacity:     0.95;
    flex-shrink: 0;
}
.tl-chip-marker.fbc-opt-icon svg { width: 13px; height: 13px; }

.fbc-opt-swatch {
    width:         15px;
    height:        15px;
    border-radius: 4px;
    border:        1px solid rgba(0, 0, 0, 0.18);
    flex-shrink:   0;
}
/* No colour of its own — the dashed square the rail uses for the same idea. */
.fbc-opt-swatch--none {
    background: transparent;
    border:     2px dashed var(--color-divider);
}

.fbc-opt-label {
    min-width:     0;
    overflow:      hidden;
    text-overflow: ellipsis;
}

/* Its own line: the grid has the room, a button in a row does not. */
.fbc-opt-desc {
    flex:      1 0 100%;
    font-size: 0.78rem;
    opacity:   0.75;
    overflow:      hidden;
    text-overflow: ellipsis;
    white-space:   nowrap;
}

/* The solo button IS the field — it fills the row and reads left-aligned,
   like the value of a form control rather than one choice among several. */
.fbc-segchoice-btn--solo {
    flex:            1 1 auto;
    justify-content: flex-start;
    white-space:     normal;
}
.fbc-segchoice-btn:hover { background: var(--color-hover); }
/* Under the pointer too: a toggle just pressed must still read as pressed. */
.fbc-segchoice-btn--selected,
.fbc-segchoice-btn--selected:hover {
    background:   var(--color-primary);
    border-color: var(--color-primary);
    color:        var(--color-text-on-primary);
    font-weight:  600;
}
/* `fbc-segchoice--stale`: the choice is still what the user works from,
   but they have moved off it (The Map's TIME: a preset's days changed by
   hand) — greyed, pressed still. */
.fbc-segchoice--stale .fbc-segchoice-btn--selected,
.fbc-segchoice--stale .fbc-segchoice-btn--selected:hover {
    background:   var(--color-text-muted);
    border-color: var(--color-text-muted);
    color:        var(--color-bg);
}
.fbc-segchoice-btn--more {
    font-size:   1.15rem;
    font-weight: 600;
    padding:     0 16px;
    color:       var(--color-primary);
}

/* `compact`: beside a section's title (The Map's TIME) — as tall as the
   pane's icon buttons (30 px), not an editor's 44. */
.fbc-segchoice--compact            { gap: 4px; }
.fbc-segchoice--compact .fbc-segchoice-btn {
    min-height:    30px;
    padding:       0 8px;
    font-size:     0.8rem;
    border-radius: 6px;
}
.fbc-segchoice--compact .fbc-segchoice-btn--more { padding: 0 10px; font-size: 1rem; }

/* `field`: the value is a field of a form (a contact row's type) — drawn as
   the form's inputs are (.form-input): as tall, as sober, a chevron at its
   end; as wide as the longest option's words, which sit unseen in the same
   grid cell as the value (SegmentedChoice's _fieldParts). */
.fbc-segchoice--field { flex-wrap: nowrap; }
.fbc-segchoice--field .fbc-segchoice-btn--solo,
.fbc-segchoice--field .fbc-segchoice-btn--solo:hover {
    display:        inline-grid;
    grid-template-columns: auto auto;
    align-items:    center;
    column-gap:     8px;
    flex:           0 0 auto;
    min-height:     0;
    padding:        9px 10px 9px 12px;
    border:         1.5px solid var(--color-divider);
    border-radius:  7px;
    background:     var(--color-bg);
    color:          var(--color-text-primary);
    font-size:      0.95rem;
    font-weight:    400;
    line-height:    normal;
    white-space:    nowrap;
    text-align:     left;
}
.fbc-segchoice--field .fbc-segchoice-btn--solo:hover { border-color: var(--color-primary-light); }
.fbc-segchoice--field .fbc-segchoice-face,
.fbc-segchoice--field .fbc-segchoice-sizer { grid-area: 1 / 1; display: flex; align-items: center; gap: 6px; }
.fbc-segchoice--field .fbc-segchoice-sizer { visibility: hidden; }
.fbc-segchoice--field .fbc-segchoice-chevron { grid-area: 1 / 2; display: inline-flex; color: var(--color-text-muted); }
.fbc-segchoice--field .fbc-segchoice-chevron svg { width: 14px; height: 14px; }

/* `square`: an option's glyph alone on the row — as wide as it is tall. */
.fbc-segchoice-btn--square,
.fbc-segchoice--compact .fbc-segchoice-btn--square {
    flex:    0 0 auto;
    width:   44px;
    padding: 0;
}
.fbc-segchoice--compact .fbc-segchoice-btn--square { width: 30px; }
.fbc-segchoice--compact .fbc-segchoice-btn--square .fbc-opt-svg svg { width: 16px; height: 16px; }

/* ── Stepper ─────────────────────────────────────────────────────
   Full-height − / + flanking the field, replacing the native spinner
   arrows crammed inside it. */
.fbc-stepper {
    display:       inline-flex;
    align-items:   stretch;
    border:        1px solid var(--color-divider);
    border-radius: 8px;
    overflow:      hidden;
    background:    var(--color-surface);
}

.fbc-stepper-btn {
    min-width:   48px;
    min-height:  44px;
    border:      none;
    background:  transparent;
    color:       var(--color-primary);
    font-size:   1.35rem;
    line-height: 1;
    cursor:      pointer;
    /* Repeated taps must not select the glyph. */
    user-select: none;
}
.fbc-stepper-btn:hover { background: var(--color-hover); }

.fbc-stepper-input {
    width:       60px;
    min-height:  44px;
    border:      none;
    border-left:  1px solid var(--color-divider);
    border-right: 1px solid var(--color-divider);
    background:  transparent;
    color:       var(--color-text);
    font:        inherit;
    font-size:   1rem;
    text-align:  center;
    outline:     none;
}

/* A long-tail value takes the whole control and reopens the grid, so it
   must read as "the current choice, tap to change" rather than as one
   option among several. */
.fbc-segchoice-btn--solo {
    flex: 1;
    text-align: left;
}

/* An action that cannot be undone (ActionSheet `danger`): red. */
.fbc-actsheet-btn--danger,
.fbc-actsheet-btn--danger:hover {
    background:   var(--color-danger);
    border-color: var(--color-danger);
    color:        #fff;
}
.fbc-actsheet-btn--danger svg { color: #fff; }

/* ── clearable: a search field's × (FBC.ui.clearable) ──────────────
   Over the field's right end; the field keeps room for it.  The
   browser's own × (Chrome's) is left out: one × everywhere. */
input[type="search"] {
    -webkit-appearance: none;
    appearance:         none;
}
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; display: none; }
.fbc-clearable-host { position: relative; }
/* !important: the field's own padding is set by many a page's rule. */
input.fbc-clearable { padding-right: 30px !important; }
.fbc-clearable-btn {
    position:        absolute;
    z-index:         1;
    display:         flex;
    align-items:     center;
    justify-content: center;
    width:           24px;
    height:          24px;
    padding:         0;
    border:          0;
    border-radius:   50%;
    background:      transparent;
    color:           var(--color-text-secondary);
    cursor:          pointer;
}
.fbc-clearable-btn[hidden] { display: none; }
.fbc-clearable-btn:hover { color: var(--color-text); background: var(--color-hover, rgba(0, 0, 0, 0.06)); }
.fbc-clearable-btn svg { width: 14px; height: 14px; }

/* ── foldRule: a green line, and on its middle the short wide button that
   unfolds what it folds ("Part of", a journey row's menu) ─────────────── */
.fbc-fold-rule {
    position:      relative;
    height:        3px;
    border-radius: 2px;
    background:    var(--color-primary);
}
.fbc-fold-toggle {
    position:        absolute;
    left:            50%;
    top:             50%;
    transform:       translate(-50%, -50%);
    display:         flex;
    align-items:     center;
    justify-content: center;
    width:           48px;
    height:          14px;
    padding:         0;
    border:          none;
    border-radius:   7px;
    background:      var(--color-primary);
    color:           var(--color-text-on-primary);
    cursor:          pointer;
}
/* A finger's target, without a row: the press reaches past the drawn pill. */
.fbc-fold-toggle::after { content: ''; position: absolute; inset: -14px -6px; }
.fbc-fold-toggle svg { width: 12px; height: 12px; transition: transform var(--transition); }
.fbc-fold-rule--open .fbc-fold-toggle svg { transform: rotate(180deg); }
