/**
 * TGP Search Pro — Styles
 * Version: 1.0.0
 */

/* ══════════════════════════════════════════════════════════════
   VARIABLES (overridden per-widget via inline style)
══════════════════════════════════════════════════════════════ */

.tgp-search-widget {
    --tgp-s-btn-bg:   #667eea;
    --tgp-s-btn-bg2:  #764ba2;
    --tgp-s-focus:    #667eea;
    --tgp-s-accent:   #667eea;
    width: 100%;
    position: relative;
}

/* ══════════════════════════════════════════════════════════════
   WRAP — el contenedor del input
══════════════════════════════════════════════════════════════ */

.tgp-search-wrap {
    display: flex;
    align-items: center;
    height: 52px;
    border: 2px solid #e5e7eb;
    background: #fff;
    border-radius: 50px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 24px rgba(102,126,234,0.12);
    position: relative;
}

.tgp-search-wrap:focus-within {
    border-color: var(--tgp-s-focus);
    box-shadow: 0 0 0 3px rgba(102,126,234,0.15), 0 4px 24px rgba(102,126,234,0.12);
}

/* ── Estilos de input ──────────────────────────────────────── */

.tgp-search-style-box .tgp-search-wrap        { border-radius: 8px; }
.tgp-search-style-minimal .tgp-search-wrap    { border-radius: 0; border: none; border-bottom: 2px solid #e5e7eb; box-shadow: none; background: transparent; }
.tgp-search-style-floating .tgp-search-wrap   { border-radius: 8px; }
.tgp-search-style-hero .tgp-search-wrap       { border-radius: 12px; height: 68px; }
.tgp-search-style-hero .tgp-search-icon       { padding-left: 20px; }
.tgp-search-style-hero .tgp-search-input      { font-size: 18px; }

/* Icon Only */
.tgp-search-style-icon_only .tgp-search-wrap  {
    width: 44px; height: 44px; border-radius: 50%;
    justify-content: center; cursor: pointer;
    transition: width 0.35s cubic-bezier(0.4,0,0.2,1), border-radius 0.35s;
    overflow: hidden;
}
.tgp-search-style-icon_only.tgp-expanded .tgp-search-wrap {
    width: 100%; border-radius: 50px;
}
.tgp-search-style-icon_only .tgp-search-input {
    width: 0; padding: 0; opacity: 0;
    transition: width 0.35s, opacity 0.25s;
}
.tgp-search-style-icon_only.tgp-expanded .tgp-search-input {
    width: 100%; opacity: 1;
}

/* ── Ícono de lupa ─────────────────────────────────────────── */

.tgp-search-icon {
    display: flex;
    align-items: center;
    padding: 0 10px 0 16px;
    color: var(--tgp-s-accent);
    flex-shrink: 0;
    pointer-events: none;
}

/* ── Input ─────────────────────────────────────────────────── */

.tgp-search-input {
    flex: 1;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    color: #1f2937;
    padding: 0 8px;
    min-width: 0;
}
.tgp-search-input::placeholder { color: #9ca3af; }

/* ── Botón limpiar ─────────────────────────────────────────── */

.tgp-search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    border: none;
    background: #f3f4f6;
    border-radius: 50%;
    cursor: pointer;
    color: #6b7280;
    flex-shrink: 0;
    margin-right: 6px;
    transition: background 0.15s;
}
.tgp-search-clear:hover { background: #e5e7eb; }
.tgp-search-clear[hidden] { display: none; }

/* ── Botón buscar ──────────────────────────────────────────── */

.tgp-search-btn {
    flex-shrink: 0;
    height: 100%;
    padding: 0 22px;
    background: linear-gradient(135deg, var(--tgp-s-btn-bg), var(--tgp-s-btn-bg2));
    color: #fff;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    white-space: nowrap;
}
.tgp-search-btn:hover { opacity: 0.9; }
.tgp-search-btn:active { transform: scale(0.98); }

/* ── Filtros ───────────────────────────────────────────────── */

.tgp-search-filters {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.tgp-search-filters select {
    flex: 1;
    min-width: 140px;
    height: 36px;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    padding: 0 10px;
    font-size: 13px;
    color: #374151;
    background: #fff;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}
.tgp-search-filters select:focus { border-color: var(--tgp-s-focus); }

/* ══════════════════════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════════════════════ */

.tgp-search-modal {
    --tgp-sm-bg:       #fff;
    --tgp-sm-ovl:      rgba(17,24,39,0.7);
    --tgp-sm-maxw:     760px;
    --tgp-sm-radius:   16px;
    --tgp-sm-hl:       #fef08a;
    --tgp-sm-accent:   #667eea;
    --tgp-sm-card-hbg: #f0edff;

    position: fixed;
    inset: 0;
    z-index: 999990;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 16px 16px;

    /* Estado oculto */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.tgp-search-modal.tgp-sm--open {
    opacity: 1;
    pointer-events: auto;
}

.tgp-search-modal[hidden] { display: flex !important; visibility: hidden; }
.tgp-search-modal.tgp-sm--open[hidden] { visibility: visible; }

/* ── Overlay ───────────────────────────────────────────────── */

.tgp-sm-overlay {
    position: absolute;
    inset: 0;
    background: var(--tgp-sm-ovl);
    cursor: pointer;
}

/* ── Caja central ──────────────────────────────────────────── */

.tgp-sm-box {
    position: relative;
    width: 100%;
    max-width: var(--tgp-sm-maxw);
    max-height: calc(100vh - 80px);
    background: var(--tgp-sm-bg);
    border-radius: var(--tgp-sm-radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0,0,0,0.35), 0 8px 32px rgba(0,0,0,0.2);
}

/* Animaciones de entrada */
.tgp-sm-anim-fade-scale .tgp-sm-box {
    transform: scale(0.94) translateY(-8px);
    transition: transform 0.28s cubic-bezier(0.34,1.56,0.64,1), opacity 0.25s;
    opacity: 0;
}
.tgp-search-modal.tgp-sm--open .tgp-sm-anim-fade-scale .tgp-sm-box,
.tgp-sm-anim-fade-scale.tgp-search-modal.tgp-sm--open .tgp-sm-box {
    transform: scale(1) translateY(0);
    opacity: 1;
}
.tgp-sm-anim-slide-up .tgp-sm-box   { transform: translateY(24px); transition: transform 0.28s ease; }
.tgp-sm-anim-slide-down .tgp-sm-box { transform: translateY(-24px); transition: transform 0.28s ease; }
.tgp-search-modal.tgp-sm--open .tgp-sm-box { transform: none; opacity: 1; }

/* ── Posición: dropdown ────────────────────────────────────── */

.tgp-sm-pos-dropdown {
    position: absolute;
    inset: unset;
    top: 100%;
    left: 0;
    width: 100%;
    padding: 6px 0 0;
    z-index: 9999;
    background: transparent;
}
.tgp-sm-pos-dropdown .tgp-sm-overlay { display: none; }
.tgp-sm-pos-dropdown .tgp-sm-box {
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
    max-height: 70vh;
}
/* Dropdown: header compacto con solo botón cerrar (sin input ni icono) */
.tgp-sm-pos-dropdown .tgp-sm-header {
    display: flex;
    justify-content: flex-end;
    padding: 6px 8px;
    border-bottom: none;
    min-height: unset;
}
.tgp-sm-pos-dropdown .tgp-sm-header-input-wrap { display: none; }
.tgp-sm-pos-dropdown .tgp-sm-header-icon       { display: none; }

/* ── Posición: fullscreen ──────────────────────────────────── */

.tgp-sm-pos-fullscreen {
    padding: 0;
    align-items: stretch;
}
.tgp-sm-pos-fullscreen .tgp-sm-box {
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
}
/* En fullscreen la imagen no puede comerse la tarjeta entera */
.tgp-sm-pos-fullscreen .tgp-sr-card__thumb {
    height: 130px !important;
}
.tgp-sm-pos-fullscreen .tgp-sr-card__body {
    min-height: 0;
    flex: 1;
}

/* ── Posición: sidebar/drawer ──────────────────────────────── */

.tgp-sm-pos-sidebar {
    padding: 0;
    align-items: stretch;
    justify-content: flex-end;
}
.tgp-sm-pos-sidebar .tgp-sm-box {
    max-width: 420px;
    max-height: 100%;
    border-radius: 0;
    height: 100%;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1) !important;
}
.tgp-search-modal.tgp-sm--open.tgp-sm-pos-sidebar .tgp-sm-box { transform: translateX(0); }

/* ── Header del modal ──────────────────────────────────────── */

.tgp-sm-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid #f3f4f6;
    flex-shrink: 0;
}

.tgp-sm-header-input-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    background: #f9fafb;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    height: 44px;
    transition: border-color 0.2s;
}
.tgp-sm-header-input-wrap:focus-within {
    border-color: var(--tgp-sm-accent);
    background: #fff;
}

.tgp-sm-header-icon {
    padding: 0 8px 0 12px;
    color: var(--tgp-sm-accent);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.tgp-sm-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 15px;
    color: #1f2937;
    padding: 0 6px;
    min-width: 0;
    height: 100%;
}
.tgp-sm-input::placeholder { color: #9ca3af; }

.tgp-sm-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px; height: 26px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    color: #9ca3af;
    margin-right: 6px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
.tgp-sm-clear:hover { color: #374151; background: #f3f4f6; }
.tgp-sm-clear[hidden] { display: none; }

.tgp-sm-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border: none;
    background: #f3f4f6;
    border-radius: 50%;
    cursor: pointer;
    color: #6b7280;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.tgp-sm-close:hover { background: #e5e7eb; color: #111827; }

/* ── Progress bar ──────────────────────────────────────────── */

.tgp-sm-progress {
    height: 3px;
    background: #f3f4f6;
    overflow: hidden;
    flex-shrink: 0;
}
.tgp-sm-progress[hidden] { display: none; }

.tgp-sm-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--tgp-sm-accent), #a78bfa);
    animation: tgp-search-progress 1.4s ease-in-out infinite;
}
@keyframes tgp-search-progress {
    0%   { width: 0%;   margin-left: 0; }
    50%  { width: 70%;  margin-left: 15%; }
    100% { width: 0%;   margin-left: 100%; }
}

/* ── Zona scrollable ───────────────────────────────────────── */

.tgp-sm-empty,
.tgp-sm-results {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 16px;
    scrollbar-width: thin;
    scrollbar-color: #e5e7eb transparent;
}
.tgp-sm-results[hidden], .tgp-sm-empty[hidden] { display: none; }

/* ── Estado vacío: populares + recientes ───────────────────── */

.tgp-sm-section-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #9ca3af;
    margin: 0 0 10px;
}

.tgp-sm-recent { margin-bottom: 20px; }
.tgp-sm-recent[hidden] { display: none; }

.tgp-sm-recent-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tgp-sm-recent-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #374151;
    transition: background 0.15s;
    border: none;
    background: none;
    text-align: left;
    width: 100%;
}
.tgp-sm-recent-item:hover { background: #f9fafb; }
.tgp-sm-recent-item__text { flex: 1; }
.tgp-sm-recent-item__del {
    color: #d1d5db;
    font-size: 11px;
    transition: color 0.15s;
    background: none; border: none; cursor: pointer; padding: 0;
}
.tgp-sm-recent-item__del:hover { color: #ef4444; }

.tgp-sm-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tgp-sm-tag {
    padding: 5px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 20px;
    background: #f9fafb;
    font-size: 12px;
    color: #374151;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    font-weight: 500;
}
.tgp-sm-tag:hover {
    border-color: var(--tgp-sm-accent);
    background: var(--tgp-sm-card-hbg);
    color: var(--tgp-sm-accent);
}

/* ── Grid de resultados ────────────────────────────────────── */

.tgp-sm-layout-grid    { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; align-items: start; }
.tgp-sm-layout-compact { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;  align-items: start; }
.tgp-sm-layout-list    { display: flex; flex-direction: column; gap: 8px; }

/* ── Tarjeta de resultado ──────────────────────────────────── */

.tgp-sr-card {
    /* Reset total — evita que el tema sobreescriba display/position */
    all: unset;
    /* Estructura */
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    /* Apariencia */
    border-radius: 10px !important;
    background: #f9fafb !important;
    border: 1px solid #f3f4f6 !important;
    text-decoration: none !important;
    color: inherit !important;
    cursor: pointer !important;
    /* Sin overflow:hidden — evita cortar el contenido del body */
    overflow: visible !important;
    box-sizing: border-box !important;
    /* La imagen se recorta con su propio overflow, no el del padre */
    transition: box-shadow 0.2s, border-color 0.2s !important;
}
.tgp-sr-card:hover {
    background: var(--tgp-sm-card-hbg) !important;
    border-color: var(--tgp-sm-accent) !important;
    box-shadow: 0 4px 16px rgba(102,126,234,0.15) !important;
    /* Sin transform para evitar superposición con z-index */
    z-index: 1 !important;
}

/* ── Imagen de la tarjeta ── */

.tgp-sr-card__thumb {
    /* Altura fija explícita — no depende de aspect-ratio ni del ancho */
    width: 100% !important;
    height: 140px !important;
    overflow: hidden !important;
    background: #e5e7eb !important;
    flex-shrink: 0 !important;
    border-radius: 10px 10px 0 0 !important;
    display: block !important;
    box-sizing: border-box !important;
}
.tgp-sm-layout-compact .tgp-sr-card__thumb { height: 100px !important; }

/* List layout: horizontal con thumb cuadrado */
.tgp-sm-layout-list .tgp-sr-card {
    flex-direction: row !important;
    align-items: stretch !important;
}
.tgp-sm-layout-list .tgp-sr-card__thumb {
    width: 88px !important;
    height: auto !important;
    min-height: 80px !important;
    flex-shrink: 0 !important;
    border-radius: 10px 0 0 10px !important;
}

.tgp-sr-card__thumb img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    transition: transform 0.3s !important;
}
.tgp-sr-card:hover .tgp-sr-card__thumb img { transform: scale(1.04) !important; }

/* Placeholder sin imagen */
.tgp-sr-card__thumb-placeholder {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb) !important;
    color: #d1d5db !important;
}

/* ── Cuerpo de la tarjeta — siempre visible ── */

.tgp-sr-card__body {
    padding: 10px 12px 12px !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 4px !important;
    /* Nunca recortar el contenido */
    overflow: visible !important;
    min-height: 0 !important;
    box-sizing: border-box !important;
}

.tgp-sr-card__type {
    font-size: 10px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    color: var(--tgp-sm-accent) !important;
    line-height: 1.4 !important;
    margin: 0 0 2px !important;
    display: block !important;
}

.tgp-sr-card__title {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #1f2937 !important;
    line-height: 1.4 !important;
    /* Clamp a 2 líneas */
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    margin: 0 !important;
    /* Reset herencia del tema */
    font-family: inherit !important;
    text-transform: none !important;
    letter-spacing: normal !important;
}
.tgp-sm-layout-compact .tgp-sr-card__title { font-size: 12px !important; }

.tgp-sr-card__excerpt {
    font-size: 12px !important;
    color: #6b7280 !important;
    line-height: 1.5 !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    margin: 0 !important;
    font-family: inherit !important;
    font-weight: normal !important;
}
.tgp-sm-layout-compact .tgp-sr-card__excerpt { display: none !important; }

.tgp-sr-card__meta {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-size: 11px !important;
    color: #9ca3af !important;
    margin-top: 4px !important;
    flex-wrap: wrap !important;
    line-height: 1.4 !important;
}
.tgp-sr-card__meta-sep { opacity: 0.4; }

/* ── Resaltado de términos ─────────────────────────────────── */

.tgp-search-highlight {
    background: var(--tgp-sm-hl);
    color: #1f2937;
    padding: 1px 2px;
    border-radius: 3px;
    font-weight: inherit;
}

/* ── Mensaje vacío/error ───────────────────────────────────── */

.tgp-sm-no-results {
    text-align: center;
    padding: 40px 24px;
    color: #6b7280;
}
.tgp-sm-no-results svg { display: block; margin: 0 auto 12px; color: #d1d5db; }
.tgp-sm-no-results p  { font-size: 14px; margin: 0; }

/* ── Footer: stats + paginación ───────────────────────────── */

.tgp-sm-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid #f3f4f6;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
}
.tgp-sm-footer[hidden] { display: none; }

.tgp-sm-stats {
    font-size: 12px;
    color: #9ca3af;
}

.tgp-sm-pagination {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tgp-sm-page-btn {
    min-width: 32px; height: 32px;
    padding: 0 8px;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s;
}
.tgp-sm-page-btn:hover { border-color: var(--tgp-sm-accent); color: var(--tgp-sm-accent); }
.tgp-sm-page-btn.is-active {
    background: var(--tgp-sm-accent);
    border-color: var(--tgp-sm-accent);
    color: #fff;
}
.tgp-sm-page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .tgp-search-modal { padding: 0; align-items: flex-end; }
    .tgp-sm-box {
        max-width: 100%;
        max-height: 90vh;
        border-radius: 20px 20px 0 0;
    }
    .tgp-sm-layout-grid    { grid-template-columns: 1fr; }
    .tgp-sm-layout-compact { grid-template-columns: repeat(2, 1fr); }
    .tgp-sm-pos-sidebar .tgp-sm-box { border-radius: 0; }
    .tgp-sm-pos-dropdown   { position: fixed; top: 0; left: 0; right: 0; bottom: 0; padding: 0; align-items: flex-end; background: var(--tgp-sm-ovl); }
    .tgp-sm-pos-dropdown .tgp-sm-overlay { display: block; }
    .tgp-sm-pos-dropdown .tgp-sm-box { max-height: 90vh; border-radius: 20px 20px 0 0; }
    .tgp-sm-pos-dropdown .tgp-sm-header { display: flex; }
    .tgp-search-wrap { border-radius: 12px; }
    .tgp-search-style-pill .tgp-search-wrap { border-radius: 50px; }
}

@media (max-width: 400px) {
    .tgp-sm-layout-compact { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════════════════
   UTILIDADES
══════════════════════════════════════════════════════════════ */

/* Bloquear scroll del body cuando el modal está abierto */
body.tgp-search-modal-open { overflow: hidden; }

/* Skeleton loader */
.tgp-sr-skeleton {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 10px;
    animation: tgp-skeleton-pulse 1.4s ease-in-out infinite;
}
.tgp-sr-skeleton__img  { height: 100px; background: #e5e7eb; border-radius: 6px; }
.tgp-sr-skeleton__line { height: 12px; background: #e5e7eb; border-radius: 4px; }
.tgp-sr-skeleton__line--short { width: 60%; }
.tgp-sr-skeleton__line--med   { width: 80%; }

@keyframes tgp-skeleton-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
}