/*
 * Shared look of PickList (single select) and TagList (multi select), Component/Common/PickList.
 *
 * Global on purpose: both components render inside Blazor.Bootstrap <Modal> (and ModalEventBoundary), so the
 * dialog chrome and table are not reachable from the components' scoped CSS. Everything is namespaced under
 * .picker-modal (set through the Modal's Class parameter) and uses the theme.css tokens.
 */

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

.picker-modal .modal-content {
    overflow: hidden;
    color: var(--acme-color-text-default);
    background: var(--acme-color-surface);
    border: 1px solid var(--acme-color-border-light);
    border-radius: var(--acme-radius-lg, 10px);
    box-shadow: var(--acme-dialog-shadow, 0 4px 16px rgba(0, 0, 0, .15));
}

.picker-modal .picker-modal-header {
    min-height: 48px;
    padding: 0.5rem 0.9rem !important;
    background: var(--acme-color-surface);
    border-bottom: 1px solid var(--acme-color-border-light);
}

.picker-modal .picker-modal-header .btn-close {
    margin: 0 0 0 0.5rem;
    padding: 0.5rem;
    border-radius: var(--acme-radius-md, 8px);
    opacity: .55;
    transition: opacity var(--acme-transition-fast), background-color var(--acme-transition-fast);
}

.picker-modal .picker-modal-header .btn-close:hover {
    opacity: 1;
    background-color: var(--acme-color-surface-hover);
}

.picker-modal .picker-modal-footer {
    padding: 0.6rem 0.9rem;
    background: var(--acme-color-surface-soft);
    border-top: 1px solid var(--acme-color-border-light);
}

.picker-modal .modal-body {
    padding: 0;
}

/* ---------- Heading ---------- */

.picker-heading {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: center;
    gap: 0.6rem;
}

.picker-heading-icon {
    display: inline-grid;
    flex: 0 0 2rem;
    width: 2rem;
    height: 2rem;
    place-items: center;
    color: var(--acme-color-primary-action);
    background: color-mix(in srgb, var(--acme-color-primary-action) 10%, var(--acme-color-surface));
    border: 1px solid color-mix(in srgb, var(--acme-color-primary-action) 22%, var(--acme-color-border-light));
    border-radius: var(--acme-radius-md, 8px);
    font-size: 0.85rem;
}

.picker-heading-copy {
    display: grid;
    min-width: 0;
}

.picker-heading h5 {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--acme-color-text-default);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.picker-heading-copy > span {
    color: var(--acme-color-text-muted);
    font-size: 0.75rem;
    line-height: 1.3;
    white-space: nowrap;
}

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

.picker-results {
    position: relative;
    width: 100%;
    height: clamp(18rem, 52vh, 32rem);
    min-height: 18rem;
    overflow: auto;
    background: var(--acme-color-surface);
    scrollbar-width: thin;
    scrollbar-color: var(--acme-color-border-strong) transparent;
    overscroll-behavior: contain;
}

.picker-table {
    width: 100%;
    min-width: 100%;
    margin: 0;
    table-layout: auto;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--acme-color-text-default);
    font-size: 0.85rem;
    --bs-table-bg: transparent;
}

.picker-table th,
.picker-table td {
    height: 30px;
    padding: 0.3rem 0.65rem;
    white-space: nowrap;
    vertical-align: middle;
    border: 0;
    border-bottom: 1px solid var(--acme-color-border-light);
}

.picker-table th + th,
.picker-table td + td {
    border-left: 1px solid color-mix(in srgb, var(--acme-color-border-light) 70%, transparent);
}

/* Sticky header (PickList marks cells .sticky-header, TagList styles every th). */
.picker-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 36px;
    padding-block: 0.45rem;
    color: var(--acme-color-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--acme-color-surface-soft) !important;
    border-bottom: 1px solid var(--acme-color-border);
    box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--acme-color-primary-action) 30%, transparent);
    text-align: left;
    cursor: default;
    user-select: none;
}

.picker-table thead th.picker-check-column {
    text-align: center;
}

.picker-table tbody tr {
    cursor: pointer;
}

.picker-table tbody tr > td {
    background-color: var(--acme-color-surface) !important;
    transition: background-color var(--acme-transition-fast), color var(--acme-transition-fast);
}

.picker-table tbody tr:nth-child(even) > td {
    background-color: var(--acme-color-surface-soft) !important;
}

.picker-table tbody tr:hover > td {
    background-color: color-mix(in srgb, var(--acme-color-primary-action) 5%, var(--acme-color-surface)) !important;
}

/* Keyboard / pointer cursor row. */
.picker-table .highlight-row > td {
    background-color: color-mix(in srgb, var(--acme-color-primary-action) 13%, var(--acme-color-surface)) !important;
    font-weight: 600;
}

.picker-table .highlight-row > td:first-child {
    box-shadow: inset 3px 0 0 var(--acme-color-primary-action);
}

/* TagList: ticked rows. */
.picker-table .select-row > td {
    background-color: color-mix(in srgb, var(--acme-color-primary-action) 8%, var(--acme-color-surface)) !important;
}

.picker-table .select-row.highlight-row > td {
    background-color: color-mix(in srgb, var(--acme-color-primary-action) 18%, var(--acme-color-surface)) !important;
}

.picker-table .text-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.picker-table .truncate {
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Search matches */
.picker-table mark.text-highlight {
    padding: 0 1px;
    color: inherit;
    background: color-mix(in srgb, #fbbf24 45%, transparent);
    border-radius: 3px;
}

/* ---------- TagList checkbox column ---------- */

.picker-check-column {
    width: 2.75rem;
    min-width: 2.75rem;
    text-align: center;
}

.picker-table input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    vertical-align: middle;
    accent-color: var(--acme-color-primary-action);
    cursor: pointer;
}

.picker-table input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--acme-color-primary-action);
    outline-offset: 2px;
}

/* ---------- Dynamic (resizable / reorderable) PickList ---------- */

.picker-table.dynamicPickList th {
    cursor: grab;
}

.picker-table th.column-highlight {
    color: var(--acme-color-primary-action);
    background: color-mix(in srgb, var(--acme-color-primary-action) 12%, var(--acme-color-surface-soft)) !important;
}

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

.picker-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 12;
    display: grid;
    place-items: center;
    background: color-mix(in srgb, var(--acme-color-surface) 80%, transparent);
    backdrop-filter: blur(1px);
}

/* Shimmer bar used while virtualized rows / columns load. */
.picker-skeleton {
    display: block;
    width: 70%;
    height: 0.6rem;
    margin: 0 auto;
    border-radius: 999px;
    background: linear-gradient(90deg,
    var(--acme-color-surface-subtle) 25%,
    var(--acme-color-border-light) 37%,
    var(--acme-color-surface-subtle) 63%);
    background-size: 400% 100%;
    animation: picker-shimmer 1.4s ease infinite;
}

@keyframes picker-shimmer {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

/* ---------- Empty state ---------- */

.picker-empty-cell {
    padding: 0 !important;
    border: 0 !important;
}

.picker-empty-state {
    display: flex;
    min-height: 100%;
    padding: 2rem 1.25rem;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    text-align: center;
    white-space: normal;
    color: var(--acme-color-text-default);
    background: var(--acme-color-surface);
}

.picker-empty-state--compact {
    min-height: calc(clamp(18rem, 52vh, 32rem) - 37px);
}

.picker-empty-state h6,
.picker-empty-state p {
    margin: 0;
}

.picker-empty-state h6 {
    font-size: 1rem;
    font-weight: 700;
}

.picker-empty-state p {
    max-width: 28rem;
    color: var(--acme-color-text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

.picker-empty-icon {
    display: grid;
    width: 3rem;
    height: 3rem;
    margin-bottom: 0.25rem;
    place-items: center;
    color: var(--acme-color-primary-action);
    background: color-mix(in srgb, var(--acme-color-primary-action) 9%, var(--acme-color-surface));
    border: 1px solid color-mix(in srgb, var(--acme-color-primary-action) 24%, var(--acme-color-border));
    border-radius: var(--acme-radius-pill, 999px);
}

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

.picker-footer {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(12rem, 1fr) auto auto;
    align-items: center;
    gap: 0.75rem;
}

.picker-search {
    min-width: 0;
}

.picker-search:empty {
    min-height: 1.5rem;
}

.picker-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    color: var(--acme-color-text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
    background: var(--acme-color-surface);
    border: 1px solid var(--acme-color-border-light);
    border-radius: 999px;
}

.picker-status strong {
    color: var(--acme-color-text-default);
    font-variant-numeric: tabular-nums;
}

.picker-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ---------- Responsive ---------- */

@media (min-width: 769px) {
    /* Pickers open instantly on desktop: they are keyboard-driven lookups. */
    .picker-modal .modal-dialog {
        animation: none !important;
        transition: none !important;
    }
}

@media (max-width: 768px) {
    .picker-modal .picker-modal-header {
        min-height: 48px;
        padding: max(14px, env(safe-area-inset-top, 0px)) 0.75rem 0.45rem !important;
    }
}

@media (max-width: 576px) {
    .picker-results {
        height: min(55vh, 26rem);
        min-height: 15rem;
    }

    .picker-footer {
        grid-template-columns: 1fr auto;
    }

    .picker-search {
        grid-column: 1 / -1;
    }

    .picker-empty-state--compact {
        min-height: calc(min(55vh, 26rem) - 37px);
    }

    .picker-heading-copy > span {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .picker-table tbody tr > td,
    .picker-modal .picker-modal-header .btn-close {
        transition: none;
    }

    .picker-skeleton {
        animation: none;
    }
}
