/* Command layer (static/js/palette.js, templates/base.html): the header
   "Search or ask…" control, the Ctrl/⌘+K palette dialog and the quiet <kbd>
   chips they share (the help menu's shortcut item uses one too). Linked after
   tour.css on every base.html page. Glass comes from modern.css's surface
   tokens; the fallbacks for this file's own color-mix() / blur sit at the end.
   Rows are neutral when active (a foreground tint, never a hue fill); an
   entity's band shows only as its 8px dot or glyph. Violet = the Ask row. */

/* ---------- Keycap ---------- */

.palette-kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border: 1px solid var(--border);
    border-color: color-mix(in srgb, currentColor 24%, transparent);
    border-radius: 5px;
    background: transparent;
    color: var(--foreground-secondary);
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
    font-variant-numeric: tabular-nums lining-nums;
    white-space: nowrap;
}

/* ---------- Header control (first child of .header-actions) ---------- */

.header-search {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    width: clamp(200px, 30vw, 340px);
    height: 36px;
    padding: 0 6px 0 10px;
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--foreground-secondary);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 400;
    line-height: 1;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.header-search-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    stroke-width: 1.75;
}

.header-search-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.header-search-kbd {
    flex-shrink: 0;
}

@media (hover: hover) {
    .header-search:hover {
        background: var(--surface-strong);
        color: var(--foreground);
    }
}

@media (max-width: 900px) {
    .header-search-kbd {
        display: none;
    }
}

/* Phones: an icon button like its neighbours (help, bell). */
@media (max-width: 640px) {
    .header-search {
        width: 36px;
        height: 36px;
        padding: 0;
        justify-content: center;
        border-color: transparent;
        background: transparent;
    }

    .header-search-icon {
        width: 18px;
        height: 18px;
    }

    .header-search-label {
        display: none;
    }
}

/* ---------- Dialog ---------- */

.palette {
    box-sizing: border-box;
    width: min(640px, calc(100vw - 32px));
    max-width: none;
    max-height: min(560px, calc(100vh - 12vh - 32px));
    max-height: min(560px, calc(var(--palette-vh, 100dvh) - 12vh - 32px));
    margin: 12vh auto auto;
    padding: 0;
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    background: var(--surface-strong);
    -webkit-backdrop-filter: blur(var(--surface-blur)) saturate(1.1);
    backdrop-filter: blur(var(--surface-blur)) saturate(1.1);
    box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-lift);
    color: var(--foreground);
    font-family: var(--font-body);
    overflow: hidden;
    overscroll-behavior: contain;
}

.palette[open] {
    display: flex;
    flex-direction: column;
    animation: palette-in 140ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* The neu-modal veil (modern.css), theme picked by selector: older engines
   don't let ::backdrop inherit custom properties. */
.palette::backdrop {
    background: rgba(28, 27, 24, 0.32);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

[data-theme="dark"] .palette::backdrop {
    background: rgba(0, 0, 0, 0.55);
}

.palette[open]::backdrop {
    animation: palette-veil-in 140ms ease-out;
}

.palette.is-leaving {
    animation: palette-out 140ms ease-in forwards;
}

.palette.is-leaving::backdrop {
    animation: palette-veil-out 140ms ease-in forwards;
}

@keyframes palette-in {
    from { opacity: 0; transform: translateY(2px); }
    to { opacity: 1; transform: none; }
}

@keyframes palette-out {
    from { opacity: 1; transform: none; }
    to { opacity: 0; transform: translateY(2px); }
}

@keyframes palette-veil-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes palette-veil-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ---------- Search bar ---------- */

.palette-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    height: 56px;
    margin: 0;
    padding: 0 10px 0 16px;
    border-bottom: 1px solid var(--surface-border);
}

.palette-bar-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: var(--foreground-secondary);
    stroke-width: 1.75;
}

.palette-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--foreground);
    font-family: var(--font-body);
    font-size: 18px;
    font-weight: 400;
    line-height: 1.3;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.palette-input::placeholder {
    color: var(--foreground-secondary);
    opacity: 1;
}

/* The open palette is the focus context; the caret marks the field. */
.palette-input:focus,
.palette-input:focus-visible {
    outline: none;
    box-shadow: none;
}

.palette-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: 32px;
    height: 32px;
    padding: 0 4px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--foreground-secondary);
    cursor: pointer;
}

.palette-close-x {
    display: none;
    width: 18px;
    height: 18px;
    stroke-width: 1.75;
}

@media (hover: hover) {
    .palette-close:hover {
        background: var(--secondary);
        background: color-mix(in srgb, var(--foreground) 6%, transparent);
        color: var(--foreground);
    }
}

/* ---------- Results ---------- */

.palette-results {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    scrollbar-width: thin;
}

.palette-results:empty {
    display: none;
}

.palette-group + .palette-group {
    margin-top: 2px;
}

.palette-eyebrow {
    padding: 10px 10px 4px;
    color: var(--foreground-secondary);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.palette-row {
    --hue: var(--foreground-secondary);
    --hue-ink: var(--foreground-secondary);
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 10px;
    min-height: 40px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--foreground);
    font-size: 14px;
    line-height: 1.3;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.palette-row[aria-selected="true"] {
    background: var(--secondary);
    background: color-mix(in srgb, var(--foreground) 6%, transparent);
}

[data-theme="dark"] .palette-row[aria-selected="true"] {
    background: color-mix(in srgb, var(--foreground) 8%, transparent);
}

/* Results of the previous query while the new one is on its way. */
.palette-row.is-stale {
    opacity: 0.55;
}

/* Bands: dot fill / glyph ink (text-safe shade). Violet is the assistant. */
.palette-row[data-hue="jade"] { --hue: #308E65; --hue-ink: #25714D; }
.palette-row[data-hue="steel"] { --hue: #4B7DAF; --hue-ink: #3A6591; }
.palette-row[data-hue="sand"] { --hue: #B08D3C; --hue-ink: #766333; }
.palette-row[data-hue="copper"] { --hue: #C07B42; --hue-ink: #89572E; }
.palette-row[data-hue="rust"] { --hue: #AD3F13; --hue-ink: #8C330F; }
.palette-row[data-hue="violet"] { --hue: var(--ai); --hue-ink: var(--ai); }
[data-theme="dark"] .palette-row[data-hue="jade"] { --hue: #43A87D; --hue-ink: #7CCBA8; }
[data-theme="dark"] .palette-row[data-hue="steel"] { --hue: #7FA6CF; --hue-ink: #9DBCE0; }
[data-theme="dark"] .palette-row[data-hue="sand"] { --hue: #CBB577; --hue-ink: #E2D2A7; }
[data-theme="dark"] .palette-row[data-hue="copper"] { --hue: #D0925A; --hue-ink: #E3AF7F; }
[data-theme="dark"] .palette-row[data-hue="rust"] { --hue: #D06239; --hue-ink: #E08A66; }

.palette-lead {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--hue-ink);
}

.palette-lead svg {
    width: 16px;
    height: 16px;
}

.palette-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--hue);
}

/* Neutral pages (dashboard, calendar, teams, settings): a hollow dot. */
.palette-row:not([data-hue]) .palette-dot {
    background: transparent;
    box-shadow: inset 0 0 0 1.5px var(--foreground-secondary);
}

/* The title keeps its full width (capped at the row) and the secondary
   text takes what is left, so only the secondary is cut short. */
.palette-text {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
}

.palette-primary {
    flex: 0 0 auto;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.palette-primary mark {
    background: none;
    color: inherit;
    font-weight: 600;
}

.palette-secondary {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--foreground-secondary);
    font-size: 13px;
    font-variant-numeric: tabular-nums lining-nums;
}

.palette-trail {
    display: inline-flex;
    align-items: center;
}

.palette-hint {
    display: inline-flex;
    gap: 3px;
}

.palette-enter {
    display: none;
}

.palette-row[aria-selected="true"] .palette-enter {
    display: inline-flex;
}

.palette-row[aria-selected="true"] .palette-hint {
    display: none;
}

.palette-empty {
    margin: 0;
    padding: 12px 10px 8px;
    color: var(--foreground-secondary);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.palette-sep {
    height: 1px;
    margin: 6px 4px;
    background: var(--surface-border);
}

/* Ask Enne: always last; the assistant's violet on the glyph and label. */
.palette-row--ask .palette-lead {
    color: var(--ai);
}

.palette-ask-label {
    color: var(--ai);
    font-weight: 500;
}

.palette-ask-q {
    color: var(--foreground);
}

/* ---------- Loading ---------- */

.palette-shimmer-row {
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr);
    align-items: center;
    column-gap: 10px;
    height: 40px;
    padding: 0 10px;
}

.palette-shimmer-dot,
.palette-shimmer-bar {
    background: var(--secondary);
    background: color-mix(in srgb, var(--foreground) 9%, transparent);
    animation: palette-pulse 1.2s ease-in-out infinite;
}

.palette-shimmer-dot {
    justify-self: center;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.palette-shimmer-bar {
    width: 46%;
    height: 10px;
    border-radius: 5px;
}

.palette-shimmer-row + .palette-shimmer-row .palette-shimmer-bar {
    width: 30%;
}

.palette-shimmer-row + .palette-shimmer-row > * {
    animation-delay: 0.15s;
}

@keyframes palette-pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

/* ---------- Shortcuts view ---------- */

.palette-keylist {
    margin: 0;
}

.palette-keyrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 36px;
    padding: 0 10px;
}

.palette-keyrow-label {
    min-width: 0;
    color: var(--foreground);
    font-size: 14px;
    line-height: 1.3;
}

.palette-keys {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    gap: 4px;
    margin: 0;
}

.palette-keys-then {
    padding: 0 2px;
    color: var(--foreground-secondary);
    font-size: 11px;
}

/* ---------- Footer ---------- */

.palette-foot {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    padding: 8px 14px;
    border-top: 1px solid var(--surface-border);
    color: var(--foreground-secondary);
    font-size: 12px;
}

.palette-foot-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.palette-foot-item .palette-kbd + .palette-kbd {
    margin-left: -3px;
}

.palette-foot-end {
    margin-left: auto;
}

.palette[data-view="shortcuts"] [data-foot="search"] {
    display: none;
}

/* Screen-reader result count. */
.palette-status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Help menu (templates/partials/help_dropdown.html): the keycap sits where
   the "Soon" badges do. */
.tour-help-dropdown-menu .palette-kbd {
    flex-shrink: 0;
}

/* ---------- Phones ---------- */

@media (max-width: 640px) {
    .palette {
        width: calc(100vw - 32px);
        max-height: calc(100vh - 32px);
        max-height: calc(var(--palette-vh, 100dvh) - 32px);
        margin: 16px auto auto;
        border-radius: 14px;
    }

    .palette-close {
        min-width: 36px;
        height: 36px;
    }

    .palette-close .palette-kbd {
        display: none;
    }

    .palette-close-x {
        display: block;
    }

    /* No hardware keys to hint at. */
    .palette-foot,
    .palette-hint {
        display: none;
    }

    .palette-row[aria-selected="true"] .palette-enter {
        display: none;
    }
}

@media (pointer: coarse) {
    .palette-row {
        min-height: 44px;
    }
}

/* ---------- Motion and fallbacks ---------- */

@media (prefers-reduced-motion: reduce) {
    .palette[open],
    .palette[open]::backdrop,
    .palette.is-leaving,
    .palette.is-leaving::backdrop,
    .palette-shimmer-dot,
    .palette-shimmer-bar {
        animation: none;
    }

    .header-search {
        transition: none;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .palette {
        background: var(--card);
    }

    .palette::backdrop {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .palette {
        background: var(--card);
    }
}

@supports not (color: color-mix(in srgb, red 50%, transparent)) {
    .palette {
        background: var(--card);
    }

    .palette-kbd {
        border-color: var(--border);
    }

    .palette-row[aria-selected="true"],
    [data-theme="dark"] .palette-row[aria-selected="true"],
    .palette-shimmer-dot,
    .palette-shimmer-bar {
        background: var(--secondary);
    }

    .palette-close:hover {
        background: var(--secondary);
    }
}
