/* assets/public/widgets/widget.css
 *
 * Form-side styling for /widgets/form. All canonical Moon components
 * (.moon-input, .moon-select, .moon-switch-wrap, .moon-form-section,
 *  .moon-action-bar, .btn, .moon-badge) come from global/components.css —
 * this file only adds widget-specific structures: template cards, position
 * list, image-strip rows, file grid, product chips, dropdown, and the
 * shared .wgt base used by template renders.
 */

/* ── Template cards (Section 4: Tipo de Bloque) ──────────────────────────── */

.wdg-template-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.wdg-template-card {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--separator-default);
    border-radius: 10px;
    background: var(--surface-primary);
    cursor: pointer;
    transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
    user-select: none;
}

.wdg-template-card:hover {
    border-color: var(--color-brand-primary);
    background: var(--surface-secondary);
}

.wdg-template-card.is-selected {
    border-color: var(--color-brand-primary);
    background: var(--color-brand-primary-subtler);
    box-shadow: 0 0 0 3px rgba(42, 68, 90, 0.15);
    /* brand-primary @ 15% */
}

.wdg-template-card__icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--color-brand-primary-subtler);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-brand-primary);
}

.wdg-template-card__info {
    flex: 1;
    min-width: 0;
}

.wdg-template-card__name {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-label-primary);
    margin-bottom: 2px;
}

.wdg-template-card__desc {
    font-size: 12px;
    color: var(--color-label-tertiary);
    line-height: 1.4;
}


/* ── Position sortable list (Section 3: Posición) ────────────────────────── */

.wdg-position-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wdg-pos-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--surface-primary);
    border: 1px solid var(--separator-default);
    border-radius: 8px;
    cursor: grab;
    transition: background 120ms ease, border-color 120ms ease;
}

.wdg-pos-row:hover {
    background: var(--surface-secondary);
}

.wdg-pos-row.is-dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.wdg-pos-row.drag-over {
    border-color: var(--color-brand-primary);
    background: var(--color-brand-primary-subtler);
}

.wdg-pos-row--self {
    border-color: var(--color-brand-primary);
    background: var(--color-brand-primary-subtler);
}

.wdg-pos-handle {
    flex-shrink: 0;
    color: var(--color-label-quaternary);
    cursor: grab;
    display: flex;
    align-items: center;
}

.wdg-pos-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.wdg-pos-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-label-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wdg-pos-meta {
    font-size: 12px;
    color: var(--color-label-tertiary);
    white-space: nowrap;
}


/* ── Image-strip rows (image_strip field) ────────────────────────────────── */

.fc-item-row {
    display: grid;
    /* `auto` for the images column scales to however many image cells the
       schema declares (1 for FILE_CONTAINER, 2 for GALLERY desktop+mobile). */
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    padding: 12px;
    background: var(--surface-secondary);
    border: 1px solid var(--separator-default);
    border-radius: 8px;
    margin-bottom: 8px;
    align-items: start;
}

.fc-item-images {
    display: flex;
    gap: 8px;
}

.fc-item-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    min-width: 0;
}

.fc-item-fields .moon-input,
.fc-item-fields .moon-select {
    font-size: 13px;
    padding: 6px 10px;
}

.fc-item-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;
}

.wdg-strip-img-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 96px;
}

.wdg-strip-img-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--color-label-tertiary);
    line-height: 1.2;
}

.wdg-strip-img-hint {
    font-size: 10px;
    color: var(--color-label-quaternary);
    line-height: 1.3;
}

.wdg-strip-img-wrap {
    position: relative;
    width: 96px;
    height: 96px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-muted);
    border: 1px dashed var(--separator-default);
}

.wdg-strip-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.wdg-strip-img-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-label-quaternary);
    pointer-events: none;
}

.wdg-strip-img-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.1);
}

.wdg-strip-img-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--color-brand-primary);
    transition: width 120ms ease;
}


/* ── Autocomplete dropdown (used by webpage-object + product-selector) ───── */

.wdg-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    max-height: 240px;
    overflow-y: auto;
    background: var(--surface-primary);
    border: 1px solid var(--separator-default);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    z-index: 50;
}

.wdg-dropdown-item {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--color-label-primary);
    cursor: pointer;
    transition: background 80ms ease;
}

.wdg-dropdown-item:hover {
    background: var(--surface-secondary);
}

.wdg-dropdown-item--empty {
    padding: 12px;
    text-align: center;
    font-size: 12px;
    color: var(--color-label-tertiary);
    cursor: default;
}


/* ── Gallery file grid (files field) ─────────────────────────────────────── */

.gal-file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.gal-file-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-muted);
    border: 1px solid var(--separator-default);
}

.gal-file-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gal-file-thumb__remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.gal-file-thumb__remove:hover {
    background: var(--color-error);
}


/* ── Product chips (product_selector field) ──────────────────────────────── */

.wdg-product-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    font-size: 13px;
    color: var(--color-label-primary);
    background: var(--color-brand-primary-subtler);
    border: 1px solid rgba(42, 68, 90, 0.25);
    /* brand-primary @ 25% */
    border-radius: 16px;
}

.wdg-product-chip__remove {
    border: none;
    background: transparent;
    color: var(--color-label-tertiary);
    cursor: pointer;
    font-size: 11px;
    padding: 0;
    line-height: 1;
    display: flex;
    align-items: center;
}

.wdg-product-chip__remove:hover {
    color: var(--color-error);
}


/* ── Complex field wrapper (files / image_strip / product_selector) ──────── */

.wdg-complex-field {
    display: flex;
    flex-direction: column;
}


/* ── Shared widget base — used by both admin preview and public renders ──── */

.wgt {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.wgt.is-preview {
    border: 1px dashed var(--separator-default);
    border-radius: 8px;
    padding: 16px;
    background: var(--surface-secondary);
}