/* ============================================================================
   dmu-cardpicker — reusable search-dropdown picker with selected "cards"
   ----------------------------------------------------------------------------
   Extracted from templates/modules/meetings/form.php (the .dmu-mtg-rec-* block) so the
   widget can be reused across the app. Paired with:
     - js/modules/card-picker.js   (behaviour + auto-init)
     - templates/components/card-picker/card-picker.php  (markup helper)

   Structure rendered by the JS / PHP helper:
     .dmu-cardpicker
       .dmu-cardpicker-search
         > i.dmu-cardpicker-search-icon
         > input.dmu-cardpicker-search-input
         > .dmu-cardpicker-dropdown   (> .dmu-cardpicker-item / -group-header / -empty)
       .dmu-cardpicker-cards          (> .dmu-cardpicker-card)
       .dmu-cardpicker-hidden         (generated <input type="hidden">)

   Modifiers:
     .dmu-cardpicker--single                   single-pick variant
     .dmu-cardpicker[data-cards-layout="grid"]  selected cards in a 2-col grid
   ============================================================================ */

.dmu-cardpicker { position: relative; }

/* ─── Search box ─────────── */
.dmu-cardpicker-search {
    position: relative;
    display: flex;
    align-items: center;
}

.dmu-cardpicker-search-icon {
    position: absolute;
    left: 12px;
    color: #9ca3af;
    pointer-events: none;
    width: 16px;
    height: 16px;
}

.dmu-cardpicker-search-input {
    padding-left: 36px !important;
}

/* ─── Dropdown ─────────── */
.dmu-cardpicker-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 50;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    max-height: 280px;
    overflow-y: auto;
    padding: 4px 0;
}

.dmu-cardpicker-dropdown.is-open {
    display: block;
}

.dmu-cardpicker-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.1s;
}

.dmu-cardpicker-item:hover,
.dmu-cardpicker-item.is-active {
    background: #f9fafb;
}

.dmu-cardpicker-item-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #f3eef8;
    color: var(--primary, #9062AF);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dmu-cardpicker-item-icon i {
    width: 14px;
    height: 14px;
}

/* Avatar slot — replaces the icon circle when the picker item is a real
   user. The avatar HTML is pre-rendered server-side at 28px and brings its
   own circle, so this wrapper is just sizing. */
.dmu-cardpicker-item-avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    line-height: 0;
}

.dmu-cardpicker-item-avatar .dmu-avatar {
    width: 28px !important;
    height: 28px !important;
    font-size: 11px !important;
}

/* Favicon slot — used for entries that carry a website favicon. Same
   sizing as the icon circle but with a lighter background so the favicon
   image reads on its own. */
.dmu-cardpicker-item-favicon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #f3f4f6;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dmu-cardpicker-item-favicon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.dmu-cardpicker-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.dmu-cardpicker-item-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dmu-cardpicker-item-sublabel {
    display: block;
    font-size: 11px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dmu-cardpicker-empty {
    padding: 12px;
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
}

/* Section header inside the dropdown — emitted by the JS when groupHeaders
   is enabled and item.kind transitions. */
.dmu-cardpicker-group-header {
    padding: 8px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #9ca3af;
}

.dmu-cardpicker-group-header + .dmu-cardpicker-item {
    margin-top: 2px;
}

/* ─── Selected cards ─────────── */
.dmu-cardpicker-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.dmu-cardpicker-cards:empty {
    display: none;
}

.dmu-cardpicker-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}

.dmu-cardpicker-card-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #f3eef8;
    color: var(--primary, #9062AF);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dmu-cardpicker-card-icon i {
    width: 14px;
    height: 14px;
}

/* Selected-card avatar slot. The pre-rendered avatar is 28px (matching the
   dropdown size); we bump it to 32px here via the !important overrides on
   .dmu-avatar so it visually matches the icon-circle on other cards. */
.dmu-cardpicker-card-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    line-height: 0;
}

.dmu-cardpicker-card-avatar .dmu-avatar {
    width: 32px !important;
    height: 32px !important;
    font-size: 12px !important;
}

/* Favicon slot for the selected card — 32px to match avatar sizing. */
.dmu-cardpicker-card-favicon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #f3f4f6;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dmu-cardpicker-card-favicon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.dmu-cardpicker-card-info {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.dmu-cardpicker-card-name {
    font-size: 13px;
    font-weight: 500;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dmu-cardpicker-card-sublabel {
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dmu-cardpicker-card-remove {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.12s, color 0.12s;
}

.dmu-cardpicker-card-remove:hover {
    background: #fee2e2;
    color: #991b1b;
}

/* ─── Modifier: single-pick ───────────
   The single-pick variant renders the same card style; just a touch less
   top margin since there's only ever one card. */
.dmu-cardpicker--single .dmu-cardpicker-cards {
    margin-top: 10px;
}

/* Single-pick + filled: the selected card IS the control, so hide the
   search row. Toggled by card-picker.js whenever the picked set is
   non-empty in single-pick mode. */
.dmu-cardpicker.is-single-filled .dmu-cardpicker-search {
    display: none;
}

.dmu-cardpicker.is-single-filled .dmu-cardpicker-cards {
    margin-top: 0;
}

/* ─── Modifier: grid card layout ───────────
   Opt-in via data-cards-layout="grid" — selected cards flow in a 2-column
   grid so a long list doesn't push the form down. Collapses to a single
   column on narrow viewports. */
.dmu-cardpicker[data-cards-layout="grid"] .dmu-cardpicker-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dmu-cardpicker[data-cards-layout="grid"] .dmu-cardpicker-cards:empty {
    display: none;
}

@media (max-width: 599.98px) {
    .dmu-cardpicker[data-cards-layout="grid"] .dmu-cardpicker-cards {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ─── Dark mode ─────────── */
html[data-color^="dark-"] .dmu-cardpicker-search-icon {
    color: var(--muted);
}

html[data-color^="dark-"] .dmu-cardpicker-dropdown {
    background: var(--foreground);
    border-color: var(--separator);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

html[data-color^="dark-"] .dmu-cardpicker-item:hover,
html[data-color^="dark-"] .dmu-cardpicker-item.is-active {
    background: var(--background-theme);
}

html[data-color^="dark-"] .dmu-cardpicker-item-name {
    color: var(--body);
}

html[data-color^="dark-"] .dmu-cardpicker-item-sublabel,
html[data-color^="dark-"] .dmu-cardpicker-empty,
html[data-color^="dark-"] .dmu-cardpicker-group-header {
    color: var(--muted);
}

html[data-color^="dark-"] .dmu-cardpicker-card {
    background: var(--background-theme);
    border-color: var(--separator-light);
}

html[data-color^="dark-"] .dmu-cardpicker-card-name {
    color: var(--body);
}

html[data-color^="dark-"] .dmu-cardpicker-card-sublabel {
    color: var(--muted);
}

html[data-color^="dark-"] .dmu-cardpicker-card-icon,
html[data-color^="dark-"] .dmu-cardpicker-item-icon {
    background: rgba(var(--primary-rgb), 0.18);
}

html[data-color^="dark-"] .dmu-cardpicker-item-favicon,
html[data-color^="dark-"] .dmu-cardpicker-card-favicon {
    background: var(--background-light);
}

html[data-color^="dark-"] .dmu-cardpicker-card-remove {
    color: var(--muted);
}
