/* ============================================================================
   51-label-picker.css - the label picker, the "new label" dialog and the colour
   swatch picker (Components/Shared/LabelPicker, CreateLabelDialog, ColorSwatchPicker).

   Sits after 50-datetime-field.css and before 24-theme-dark.css, which must stay last. Everything
   paints through the base tokens; the one [data-theme="dark"] rule below exists
   because the field mirrors .modal-search, whose dark face is a spot-fix in 24
   rather than a token, and the two must read as the same object.

   Three namespaces, no shared selectors with the rest of the cascade:
     .lp-*   the picker: field, chips, tray, list, foot
     .cld-*  the dialog
     .csp-*  the swatches

   The picker lives INSIDE the create modal and is quieter than it: no shadow of
   its own beyond --shadow-card, no motion, one violet (the open rim), and the
   list rows take the sanctioned borderless hover fill. The house hover rule
   (00-tokens-base.css) applies: the rim lifts, nothing moves. The swatches are
   the documented exception - a round target with no rim to lift scales instead.
   Mobile first: the base rules are the 375px layout.
   ============================================================================ */

/* ---- the field ------------------------------------------------------------ */

.lp {
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Same box as .modal-search (rim, radius, 40px floor) so it sits in the form's
   own vocabulary; a container rather than an input because it holds chips. */
.lp-field {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 6px 8px;
    border: 1px solid var(--chronos-outline);
    border-radius: 8px;
    background: var(--chronos-card-bg);
    cursor: pointer;
}
@media (hover: hover) {
    .lp-field:hover {
        border-color: color-mix(in srgb, var(--hover-ink) var(--hover-lift), var(--chronos-outline));
    }
}
/* Open: the rim goes violet like a focused field, and the bottom corners square
   off so the tray reads as the same object continued, not a second box. */
.lp.is-open .lp-field {
    border-color: var(--chronos-violet);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
[data-theme="dark"] .lp-field { background: var(--chronos-bg); }

/* A chosen label is the house chip in its filled state, plus a remove control.
   The chip is 26px tall; the control's hit area is grown with a pseudo-element
   to ~34px so it is tappable without making the chip itself heavier. */
.lp-chip {
    padding-right: 4px;
    max-width: 100%;
    cursor: default;
}
.lp-chip-x {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 2px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    cursor: pointer;
    flex: none;
}
.lp-chip-x::before {
    content: "";
    position: absolute;
    inset: -8px;
}
.lp-chip-x .material-icons { font-size: 14px; line-height: 1; }
@media (hover: hover) {
    .lp-chip-x:hover { background: rgba(255, 255, 255, 0.22); }
}
.lp-chip-x:disabled { opacity: 0.5; cursor: not-allowed; }

/* The way in. A dashed capsule is the oldest "add one here" sign there is, and
   dashed keeps it lighter than every solid pill around it. */
.lp-open {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 3px 11px;
    border: 1px dashed var(--chronos-day-muted);
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--chronos-fg-secondary);
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    line-height: 1.4;
    cursor: pointer;
}
@media (hover: hover) {
    .lp-open:hover {
        border-color: color-mix(in srgb, var(--hover-ink) var(--hover-lift), var(--chronos-day-muted));
        color: var(--chronos-fg-primary);
    }
}
.lp-open:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- the tray -------------------------------------------------------------- */

.lp-tray {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--chronos-violet);
    border-top: 0;
    border-radius: 0 0 8px 8px;
    background: var(--chronos-card-bg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

/* The filter wears .modal-search for its type, padding and dark face; the box
   itself is dropped because the tray's rim is already the box. Focus stays on
   the hairline: the violet is on the tray, and a second violet would shout. */
.lp-tray .lp-search {
    border: 0;
    border-bottom: 1px solid var(--chronos-outline);
    border-radius: 0;
    width: 100%;
}
.lp-tray .lp-search:focus { border-color: var(--chronos-outline); }
.lp-tray .lp-search:focus-visible { outline-offset: -2px; }

/* Five and a half rows, then it scrolls. The half row is the affordance that
   there is more; the fixed ceiling is what keeps the form from reflowing on
   every keystroke of the filter. */
.lp-list {
    list-style: none;
    margin: 0;
    padding: 4px;
    max-height: 224px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.lp-option {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    padding: 0 10px;
    border-radius: 6px;
    color: var(--chronos-fg-primary);
    font-size: var(--text-base);
    cursor: pointer;
    user-select: none;
}
/* A menu row has no rim: the sanctioned borderless hover fill. The keyboard
   cursor uses the same fill, which is deliberate - hover and cursor are one
   idea, "this row would take the Enter". */
@media (hover: hover) {
    .lp-option:hover { background: var(--chronos-hover-bg); }
}
.lp-option.is-active { background: var(--chronos-hover-bg); }
.lp-option .label-dot {
    width: 10px;
    height: 10px;
    flex: none;
}
.lp-option-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.lp-option.is-on .lp-option-name { font-weight: var(--weight-semibold); }

/* The chosen mark, drawn the way the house checkbox draws its tick (00-tokens-
   base.css) so the two read as one gesture. Violet, not the label's colour: the
   dot already says which label, the tick only says "on". */
.lp-tick {
    position: relative;
    width: 18px;
    height: 18px;
    flex: none;
    opacity: 0;
}
.lp-tick::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 46%;
    width: 5px;
    height: 9.5px;
    border: solid var(--chronos-violet);
    border-width: 0 2.2px 2.2px 0;
    border-radius: 1px;
    transform: translate(-50%, -50%) rotate(45deg);
}
.lp-option.is-on .lp-tick { opacity: 1; }

.lp-empty {
    padding: 12px 10px;
    font-size: var(--text-sm);
    line-height: 1.45;
}

/* The foot. Violet text on the plain surface: it is a road, not a primary
   action, and the primary action of this form is still "create the task". */
.lp-create {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-top: 1px solid var(--chronos-outline);
    background: transparent;
    color: var(--chronos-violet);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    text-align: left;
    cursor: pointer;
}
.lp-create .material-icons { font-size: 18px; line-height: 1; flex: none; }
.lp-create-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@media (hover: hover) {
    .lp-create:hover { background: var(--chronos-hover-bg); }
}
.lp-create:disabled { opacity: 0.5; cursor: not-allowed; }

/* The handle for popover-dismiss.js. Off-screen, never display:none: the script
   dispatches a click on it, and a click needs a rendered box. */
.lp-dismiss {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---- the dialog ------------------------------------------------------------ */

.cld-card {
    min-width: 0;
    max-width: 420px;
    gap: 14px;
}
/* The label as the board will draw it, live. Fixed height so the card does not
   move as the name is typed in (a window that jumps is a sin). */
.cld-preview {
    display: flex;
    align-items: center;
    min-height: 30px;
}
.cld-preview .label-chip {
    max-width: 100%;
    padding: 3px 11px;
    font-size: var(--text-base);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: default;
}
.cld-name { width: 100%; }
.cld-actions { justify-content: flex-end; }

/* ---- the swatches ---------------------------------------------------------- */

.csp {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.csp-swatch {
    position: relative;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--swatch);
    cursor: pointer;
    flex: none;
    transition: box-shadow var(--d1, 120ms) ease-out, transform var(--d1, 120ms) ease-out;
}
/* No rim to lift on a disc, so this is the documented exception: it scales. */
@media (hover: hover) {
    .csp-swatch:hover { transform: scale(1.08); }
}
/* On: a halo in the swatch's OWN colour, with a gap of card surface between,
   so the ring reads on any background and never depends on the text colour. */
.csp-swatch.is-on {
    box-shadow: 0 0 0 2px var(--chronos-card-bg), 0 0 0 4px var(--swatch);
}
.csp-swatch:disabled { opacity: 0.5; cursor: not-allowed; }

/* The tick, drawn as the checkbox draws its own and sized to the 36px disc. */
.csp-tick {
    position: absolute;
    left: 50%;
    top: 46%;
    width: 6px;
    height: 11px;
    border: solid #FFFFFF;
    border-width: 0 2.2px 2.2px 0;
    border-radius: 1px;
    transform: translate(-50%, -50%) rotate(45deg);
    transform-origin: center;
    opacity: 0;
}
.csp-swatch.is-on .csp-tick {
    opacity: 1;
    animation: csp-tick-draw 0.18s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}
@keyframes csp-tick-draw {
    0%   { width: 0;   height: 0;    }
    45%  { width: 6px; height: 0;    }
    100% { width: 6px; height: 11px; }
}

/* The free swatch: a rainbow until it is the choice, then the chosen colour so
   its halo matches. The input is stretched invisibly over the disc; the ring
   for keyboard focus is painted on the label, because the input's own outline
   is as invisible as the input. */
.csp-custom {
    display: inline-flex;
    overflow: hidden;
    background: conic-gradient(from 0deg,
        #EF4444, #F59E0B, #10B981, #0EA5E9, #7C3AED, #EC4899, #EF4444);
}
.csp-custom.is-on { background: var(--swatch); }
.csp-custom input[type="color"] {
    position: absolute;
    inset: -4px;
    width: calc(100% + 8px);
    height: calc(100% + 8px);
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    opacity: 0;
    cursor: pointer;
}
.csp-custom:has(input:focus-visible) {
    outline: 2px solid var(--chronos-violet);
    outline-offset: 2px;
}
.csp-custom .csp-tick { pointer-events: none; }

/* The colour named. Its own line under the discs, always present, so the row
   above never shifts when the name changes length. */
.csp-name {
    width: 100%;
    min-height: 16px;
    color: var(--chronos-fg-muted);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
    .csp-swatch { transition: none; }
    .csp-swatch.is-on .csp-tick { animation: none; }
    .csp-swatch:hover { transform: none; }
}
