.command-palette {
    position: absolute;
    top: var(--palette-offset-top, calc(100% + 5px));
    left: 0;
    right: 0;

    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    border-radius: 18px;
    border: 1px solid var(--border-subtle);

    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.12),
        0 2px 6px rgba(0, 0, 0, 0.06);

    z-index: 1100;

    /* REQUIRED */
    display: flex;
    flex-direction: column;

    /* RESPONSIVE HEIGHT */
    max-height: min(calc(100dvh - var(--palette-top, 0px) - env(safe-area-inset-bottom) - 0.75rem),
            560px);

    overflow: hidden;
}

.palette-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.palette-date-range {
    padding: 0.9rem 1rem 0.8rem;
    background: linear-gradient(135deg, rgba(0, 153, 171, 0.09), rgba(248, 250, 252, 0.8));
    border-bottom: 1px solid var(--border-subtle);
}

.palette-date-range-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
}

.palette-date-range-title {
    color: #044e68;
    font-size: 0.9rem;
    font-weight: 700;
}

.palette-date-range-toggle {
    flex: 0 0 auto;
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: hidden;
    border: 1px solid rgba(0, 153, 171, 0.25);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.78);
}

.palette-date-range-toggle-btn {
    min-width: 5rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #475569;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    padding: 0.42rem 0.58rem;
    white-space: nowrap;
}

.palette-date-range-toggle-btn + .palette-date-range-toggle-btn {
    border-left: 1px solid rgba(0, 153, 171, 0.18);
}

.palette-date-range-toggle-btn:hover,
.palette-date-range-toggle-btn:focus-visible {
    color: #044e68;
    outline: none;
}

.palette-date-range-toggle-btn.is-active {
    background: #05616e;
    color: #fff;
}

.palette-date-range-subtitle,
.palette-date-range-help {
    color: #5b6872;
    font-size: 0.74rem;
    line-height: 1.35;
}

.palette-date-range-optional {
    flex: 0 0 auto;
    padding: 0.14rem 0.4rem;
    border-radius: 999px;
    background: rgba(0, 153, 171, 0.12);
    color: #05616e;
    font-size: 0.68rem;
    font-weight: 600;
}

.palette-date-range-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
}

.palette-date-field {
    display: grid;
    gap: 0.26rem;
    color: #334155;
    font-size: 0.72rem;
    font-weight: 700;
}

.palette-date-field input {
    width: 100%;
    min-width: 0;
    padding: 0.48rem 0.55rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    color: #0f172a;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 400;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.palette-date-field input:focus {
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(0, 153, 171, 0.14);
}

.palette-date-field input.is-invalid {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.palette-date-range-help {
    margin-top: 0.48rem;
}

.palette-date-range-help:empty {
    display: none;
}

.palette-date-range-help.is-error {
    color: #b91c1c;
    font-weight: 600;
}

.palette-input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    padding: 0.5rem 0.25rem;
    outline: none;
}

.palette-input::placeholder {
    color: #9ca3af;
}

.palette-results {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.palette-section {
    padding: 0.5rem 0;
}

.palette-title {
    padding: 0.35rem 1.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6b7280;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;

    padding: 0.55rem 1.25rem;
    cursor: pointer;
    border-radius: 10px;
    margin: 0.25rem 0.5rem;

    transition:
        background 0.15s ease,
        transform 0.05s ease;
}

.palette-item:hover {
    background: rgba(0, 153, 171, 0.08);
}

.palette-item:active {
    background: rgba(0, 153, 171, 0.10);
    transform: translateY(1px);
}

.palette-item .icon {
    width: 20px;
    text-align: center;
    font-size: 0.9rem;
    opacity: 0.75;
}

.palette-item .label {
    font-size: 0.9rem;
    font-weight: 500;
}

.palette-item .badge {
    font-weight: 500;
    font-size: 0.7rem;
}

.palette-item .description {
    font-size: 0.75rem;
    color: #6b7280;
}

.palette-item.active {
    background: rgba(0, 153, 171, 0.12);
}

.palette-item.excluded {
    background: rgba(220, 38, 38, 0.10);
}

.palette-item.excluded:hover {
    background: rgba(220, 38, 38, 0.14);
}

.palette-item.excluded .icon,
.palette-item.excluded .label {
    color: #991b1b;
}

.palette-item.excluded .description {
    color: #7f1d1d;
}

.palette-exclude-toggle {
    position: relative;
    flex: 0 0 auto;
    width: 38px;
    height: 22px;
    margin-left: auto;
    padding: 0;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #f8fafc;
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}

.palette-exclude-toggle span {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: #94a3b8;
    transition:
        background 0.15s ease,
        transform 0.15s ease;
}

.palette-exclude-toggle[aria-pressed="true"] {
    background: rgba(220, 38, 38, 0.14);
    border-color: rgba(220, 38, 38, 0.5);
}

.palette-exclude-toggle[aria-pressed="true"] span {
    background: #dc2626;
    transform: translateX(16px);
}

.palette-exclude-toggle:focus-visible {
    outline: 2px solid rgba(220, 38, 38, 0.35);
    outline-offset: 2px;
}

.palette-sort-item {
    cursor: default;
}

.palette-sort-item:hover,
.palette-sort-item:active {
    background: transparent;
    transform: none;
}

.palette-sort-wrap {
    width: auto;
    margin-left: auto;
    justify-content: flex-end;
}

.label-group {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
    flex: 1 1 auto;
}


@media (max-width: 768px) {
    .command-palette {
        border-radius: 14px;
    }
}

@media (max-width: 420px) {
    .palette-date-range-heading {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .palette-date-range-toggle {
        order: 3;
        width: 100%;
    }

    .palette-date-range-toggle-btn {
        min-width: 0;
    }

    .palette-date-range-fields {
        grid-template-columns: 1fr;
    }
}
