/* The picker. Every class starts with kk-picker, and nothing here styles anything
   outside it. Theme it by setting these custom properties on .kk-picker or any
   ancestor; the defaults are cream paper, navy ink and a cranberry accent. */
.kk-picker {
    --kk-ink: #1c2540;
    --kk-ink-soft: #3c4560;
    --kk-paper: transparent;          /* behind the whole picker */
    --kk-tile: #fffdf8;               /* a tile */
    --kk-tile-hover: #fbf6ec;
    --kk-field: #ffffff;              /* the search field */
    --kk-rule: rgba(28, 37, 64, 0.18);
    --kk-accent: #9a2a3a;
    --kk-accent-soft: #f8ecea;        /* behind the chosen tile */
    --kk-on-accent: #ffffff;
    --kk-focus: #9a2a3a;
    --kk-radius: 10px;
    --kk-font: inherit;
    --kk-text: max(18px, 1rem);       /* never below 18px */
    --kk-tile-min: 9.25rem;           /* narrowest a tile may be before the grid drops a column */
    --kk-scroll-max: min(36rem, 70vh);/* height of the scrolling list (wide screens with a mouse) */
    --kk-sticky-top: 0px;             /* where the search sticks on phones (below a fixed header, say) */
    --kk-sticky-bg: #f6f1e8;          /* behind the search while it sticks: match your page */

    box-sizing: border-box;
    position: relative;
    color: var(--kk-ink);
    background: var(--kk-paper);
    font-family: var(--kk-font);
    font-size: var(--kk-text);
    line-height: 1.3;
    min-width: 0;
}
.kk-picker *, .kk-picker *::before, .kk-picker *::after { box-sizing: border-box; }
.kk-picker p { margin: 0; }
.kk-picker button, .kk-picker input { font: inherit; color: inherit; letter-spacing: inherit; }
.kk-picker [hidden] { display: none !important; }

/* ---------- the current choice ---------- */
.kk-picker__chosen { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; min-height: 48px; }
.kk-picker__chosen-pic { flex: 0 0 48px; width: 48px; height: 48px; }
.kk-picker__chosen-pic img { display: block; width: 48px; height: 48px; }
.kk-picker__chosen-label { color: var(--kk-ink-soft); }

/* ---------- search ---------- */
.kk-picker__find { background: var(--kk-paper); padding-bottom: 10px; z-index: 2; }
.kk-picker__search-label { display: block; font-weight: 600; margin-bottom: 6px; }
.kk-picker__search-row { display: flex; gap: 8px; align-items: stretch; }
.kk-picker__search {
    flex: 1 1 auto; min-width: 0; min-height: 52px; margin: 0;
    padding: 10px 14px; font-size: max(18px, 1.05em);
    background: var(--kk-field); color: var(--kk-ink);
    border: 2px solid var(--kk-rule); border-radius: var(--kk-radius);
    -webkit-appearance: none; appearance: none;
}
.kk-picker__search::placeholder { color: var(--kk-ink-soft); opacity: 0.85; }
.kk-picker__search::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.kk-picker__search:focus { outline: 3px solid var(--kk-focus); outline-offset: 1px; border-color: var(--kk-ink-soft); }
.kk-picker__reset, .kk-picker__button {
    flex: 0 0 auto; min-height: 52px; padding: 8px 16px; margin: 0;
    background: var(--kk-tile); border: 2px solid var(--kk-rule); border-radius: var(--kk-radius);
    cursor: pointer; font-weight: 600; white-space: nowrap;
}
.kk-picker__reset:not(.kk-picker__reset--on) { visibility: hidden; } /* keeps its space, so nothing moves */
.kk-picker__reset:hover, .kk-picker__button:hover { border-color: var(--kk-ink-soft); }
.kk-picker .kk-picker__button--primary { background: var(--kk-accent); border-color: var(--kk-accent); color: var(--kk-on-accent); }
.kk-picker__reset:focus-visible, .kk-picker__button:focus-visible, .kk-picker__chip:focus-visible { outline: 3px solid var(--kk-focus); outline-offset: 2px; }

/* ---------- category chips ---------- */
.kk-picker__chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.kk-picker__chip {
    min-height: 44px; padding: 6px 14px; margin: 0;
    background: var(--kk-tile); border: 2px solid var(--kk-rule); border-radius: 999px; cursor: pointer;
}
.kk-picker__chip:hover { border-color: var(--kk-ink-soft); }
.kk-picker .kk-picker__chip[aria-pressed="true"] { background: var(--kk-ink); border-color: var(--kk-ink); color: var(--kk-tile); font-weight: 600; }

.kk-picker__status { color: var(--kk-ink-soft); margin: 2px 0 8px !important; min-height: 1.3em; }

/* ---------- the list ---------- */
.kk-picker__scroll {
    max-height: var(--kk-scroll-max);
    overflow-y: auto;
    overscroll-behavior-y: auto;      /* at the end, the page carries on scrolling: nothing is trapped */
    -webkit-overflow-scrolling: touch;
    padding: 4px 6px 6px 4px;         /* room for focus rings */
    margin: 0 -6px 0 -4px;
    border-top: 1px solid var(--kk-rule);
    border-bottom: 1px solid var(--kk-rule);
    scrollbar-gutter: stable;
}
.kk-picker__section + .kk-picker__section { margin-top: 14px; }
.kk-picker__heading { font-weight: 600; margin: 8px 0 8px; }
.kk-picker__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(var(--kk-tile-min), calc(50% - 5px)), 1fr));
    gap: 10px;
}
.kk-picker__tile {
    position: relative;
    display: flex; flex-direction: column; align-items: center;
    padding: 6px 6px 10px;
    background: var(--kk-tile);
    border: 2px solid var(--kk-rule); border-radius: var(--kk-radius);
    text-align: center; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none; -webkit-user-select: none;
}
.kk-picker__tile:hover { background: var(--kk-tile-hover); border-color: var(--kk-ink-soft); }
.kk-picker__tile:focus { outline: none; }
.kk-picker__tile:focus-visible { outline: 3px solid var(--kk-focus); outline-offset: 3px; }
.kk-picker__pic { display: block; position: relative; width: 100%; aspect-ratio: 1 / 1; }
.kk-picker__pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.kk-picker__tile--nopic .kk-picker__pic img { visibility: hidden; }
.kk-picker__tile--nopic .kk-picker__pic::after {
    content: ""; position: absolute; inset: 22%; border-radius: 50%;
    background: var(--kk-rule); opacity: 0.5;
}
.kk-picker__text { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.kk-picker__name { font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.kk-picker__hint { color: var(--kk-ink-soft); margin-top: 2px; overflow-wrap: anywhere; }
.kk-picker__badge { display: none; }
.kk-picker__tile--chosen { border: 3px solid var(--kk-accent); background: var(--kk-accent-soft); padding: 5px 5px 9px; }
.kk-picker__tile--chosen .kk-picker__badge {
    display: block; position: absolute; top: 6px; right: 6px;
    background: var(--kk-accent); color: var(--kk-on-accent);
    font-weight: 600; font-size: var(--kk-text); line-height: 1; padding: 5px 7px; border-radius: 6px;
}

/* the suggested row: smaller tiles, picture beside the words */
.kk-picker__grid--compact { grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 8px; }
.kk-picker__grid--compact .kk-picker__tile { flex-direction: row; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; text-align: left; }
.kk-picker__grid--compact .kk-picker__tile--chosen { padding: 3px 9px 3px 3px; }
.kk-picker__grid--compact .kk-picker__pic { flex: 0 0 76px; width: 76px; }
.kk-picker__grid--compact .kk-picker__text { align-items: flex-start; }
.kk-picker__grid--compact .kk-picker__tile--chosen .kk-picker__badge { top: auto; bottom: 6px; }

/* ---------- nothing found ---------- */
.kk-picker__empty { padding: 18px 4px 14px; }
.kk-picker__empty-title { font-weight: 700; }
.kk-picker__empty-help { margin-top: 4px !important; color: var(--kk-ink-soft); }
.kk-picker__empty-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* ---------- phones and touch screens: no box-in-a-box scrolling ----------
   The list flows with the page (one scroll, nothing to get stuck in) and the
   search field sticks to the top while the list is on screen. */
@media (pointer: coarse), (max-width: 600px), (max-height: 560px) {
    .kk-picker__scroll { max-height: none; overflow: visible; border: 0; margin: 0; padding: 4px 0 0; scrollbar-gutter: auto; }
    .kk-picker__find { position: sticky; top: var(--kk-sticky-top); padding-top: 8px; margin-top: -8px; background: var(--kk-sticky-bg); }
}
@media (max-width: 600px) {
    .kk-picker__reset:not(.kk-picker__reset--on) { display: none; } /* the field gets the whole width for its hint */
}
@media (max-width: 380px) {
    .kk-picker__grid { gap: 8px; }
    .kk-picker__reset { padding: 8px 10px; }
}
@media (forced-colors: active) {
    .kk-picker__tile--chosen { border-width: 4px; border-style: double; }
}
