/* =====================================================================
 * Personalizador de gorras (bordado de texto)
 *
 * Este CSS se carga DIFERIDO: el template `product_customization.tpl`
 * solo lo añade al <head> la primera vez que el cliente pulsa el botón
 * "Personalizar gorra". Al estar las @font-face aquí, las fuentes solo
 * se descargan en ese momento (no penalizan LCP en la ficha de gorra).
 * ===================================================================== */

@font-face {
    font-family: 'CH Lobster';
    src: url('/themes/caphunters/fonts/customizer/lobster.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Bebas';
    src: url('/themes/caphunters/fonts/customizer/bebas-neue.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Pacifico';
    src: url('/themes/caphunters/fonts/customizer/pacifico.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Anton';
    src: url('/themes/caphunters/fonts/customizer/anton.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Monoton';
    src: url('/themes/caphunters/fonts/customizer/monoton.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

.font-lobster  { font-family: 'CH Lobster', cursive !important; }
.font-bebas    { font-family: 'CH Bebas', 'Arial Narrow', sans-serif !important; letter-spacing: 0.04em; }
.font-pacifico { font-family: 'CH Pacifico', cursive !important; }
.font-anton    { font-family: 'CH Anton', 'Impact', sans-serif !important; letter-spacing: 0.02em; }
.font-monoton  { font-family: 'CH Monoton', cursive !important; letter-spacing: 0.05em; }
.font-chopin     { font-family: 'CH Chopin', 'Pinyon Script', cursive !important; }
.font-western    { font-family: 'CH Western', 'Rye', serif !important; letter-spacing: 0.02em; }
.font-sacramarif { font-family: 'CH Sacramarif', 'Sacramento', cursive !important; }
.font-learning   { font-family: 'CH Learning', 'Caveat', cursive !important; }
.font-ttmasters  { font-family: 'CH TTMasters', 'Staatliches', 'Impact', sans-serif !important; letter-spacing: 0.04em; }
.font-eloquent   { font-family: 'CH Eloquent', 'Cinzel', serif !important; letter-spacing: 0.04em; }
.font-allegria   { font-family: 'CH Allegria', 'Italianno', cursive !important; }
.font-nautical   { font-family: 'CH Nautical', 'Special Elite', monospace !important; letter-spacing: 0.02em; }
.font-apex     { font-family: 'CH Apex', 'Open Sans', system-ui, sans-serif !important; font-weight: 600; }
.font-block2   { font-family: 'CH Block2', 'Open Sans', system-ui, sans-serif !important; font-weight: 600; }
.font-folio    { font-family: 'CH Folio', 'Arial Narrow', sans-serif !important; letter-spacing: 0.02em; font-weight: 600; }
.font-cityscript { font-family: 'CH City Script', cursive !important; }
.font-default  { font-family: Arial, sans-serif !important; }

@font-face {
    font-family: 'CH Block2';
    src: url('/themes/caphunters/fonts/customizer/opensans.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Folio';
    src: url('/themes/caphunters/fonts/customizer/barlow-condensed.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH City Script';
    src: url('/themes/caphunters/fonts/customizer/lobster.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}


@font-face {
    font-family: 'CH Chopin';
    src: url('/themes/caphunters/fonts/customizer/pinyon-script.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Western';
    src: url('/themes/caphunters/fonts/customizer/rye.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Sacramarif';
    src: url('/themes/caphunters/fonts/customizer/sacramento.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Learning';
    src: url('/themes/caphunters/fonts/customizer/caveat.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH TTMasters';
    src: url('/themes/caphunters/fonts/customizer/staatliches.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Eloquent';
    src: url('/themes/caphunters/fonts/customizer/cinzel.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Allegria';
    src: url('/themes/caphunters/fonts/customizer/italianno.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'CH Nautical';
    src: url('/themes/caphunters/fonts/customizer/special-elite.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}


@font-face {
    font-family: 'CH Apex';
    src: url('/themes/caphunters/fonts/customizer/opensans.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ---------- Panel ----------------------------------------------------- */

/* Wrapper de la sección: contiene el botón "Personalizar gorra" y
   el panel desplegable. Lo dividimos en dos hijos:
   - `.cust-toggle-wrap`: replica EXACTAMENTE el layout de
     `<p id="add_to_cart">` del tema (display:inline-flex; width:100%;
     align-items:center; padding:8px 0). De este modo el botón hereda
     el mismo cálculo de ancho que "Añadir al carrito" y se renderiza
     idéntico desde el primer paint, sin flashes ni JS.
   - `#customization-panel`: se mantiene como bloque oculto debajo. */
/* CSS GRID DE LOS BOTONES (Personalizar gorra + Añadir al carrito).

   El `<div class="cust-btn-grid">` lo añade product.tpl cuando hay
   personalizador. Sus hijos:
     row 1: [customize-toggle]      [cust-heart-ghost]   (col2 invisible)
     row 2: #customization-panel    (span 2)             [display:none por default]
     row 3: .customization-price    (span 2)             [display:none por default]
     row 4: #add_to_cart button     [add-to-wishlist]    (heart real)

   El truco clave: `grid-template-columns: max-content auto` →
   columna 1 toma el ancho del botón MÁS ANCHO (el que mande), y
   ambos buttons en col 1 se estiran a ese ancho (justify-self:stretch
   por defecto). Resultado: los dos botones acaban del mismo ancho
   exacto desde el primer paint, sin JS, sin flicker.

   `#customization-section` y `#add_to_cart` usan `display:contents`
   para que sus hijos suban al grid en lugar de crear su propia caja. */
/* LAYOUT DEL BLOQUE DE BOTONES (Personalizar + Añadir al carrito).

   Estructura DOM:
       <div class="cust-block">
           <div id="customization-section">    (display:contents)
               <p class="cust-btn-row">[Personalizar] [ghost-heart]</p>
               <div id="customization-panel">...</div>
               <div class="customization-price">...</div>
           </div>
           <p id="add_to_cart">[Añadir al carrito] [heart]</p>
       </div>

   Clave: `.cust-block { width: max-content }` + `#customization-panel
   { contain: inline-size }`.

   - `width: max-content` hace que el wrapper se dimensione al ancho
     intrínseco del hijo más ancho.
   - `contain: inline-size` en el panel le dice al browser que la
     inline-size del panel NO depende de su contenido → su contribución
     a max-content del padre es 0.
   - Resultado: el ancho lo dicta el botón más ancho (Añadir al
     carrito), y NO cambia al desplegar el panel.

   En móvil pasamos a `width: 100%` para que ocupe todo el viewport. */
.cust-block {
    display: flex;
    flex-direction: column;
    width: max-content;
    max-width: 100%;
    box-sizing: border-box;
    margin-top: 8px;
}
.cust-block #customization-section { display: contents; }

/* Filas de botones: ambos `<p>` (cust-btn-row y add_to_cart) son flex
   row con gap y el botón a `flex:1` para que ocupe todo menos el
   heart. Como el contenedor padre (.cust-block) tiene width fija
   determinada por el botón más ancho, ambos botones acaban del mismo
   ancho exacto, estable y sin parpadeo. */
.cust-block .cust-btn-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 0;
    padding-bottom: 4px;
    margin: 0;
    width: 100%;
}
/* `#add_to_cart` ya viene del tema con display:inline-flex; width:100%;
   pero forzamos display:flex aquí para que el botón `flex:1 1 auto` se
   resuelva bien en ambos casos. */
.cust-block #add_to_cart {
    display: flex;
    gap: 8px;
    width: 100%;
    padding-top: 0;
    padding-bottom: 8px;
}
.cust-block .cust-btn-row > button.exclusive,
.cust-block #add_to_cart button.exclusive { flex: 1 1 auto; min-width: 0; }

/* Panel: `contain: inline-size` es la magia. Hace que el panel y todo
   su contenido (SVG, dropdowns, etc.) NO contribuya al cálculo de
   `max-content` del padre `.cust-block`. */
.cust-block #customization-panel {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    contain: inline-size;
    margin-bottom: 8px;
}

/* Desktop: panel mas ancho que los botones (preview). El ancho de
   .cust-block lo siguen dictando los botones: contain:inline-size +
   % (sin min-width en px, que si entra en el max-content del padre). */
@media (min-width: 768px) {
    .cust-block {
        overflow: visible;
    }
    .cust-block #customization-panel {
        contain: inline-size;
        width: 175%;
        max-width: 175%;
        margin-left: 0;
    }
}
.cust-block .customization-price { width: 100%; box-sizing: border-box; }

@media (max-width: 767px) {
    .cust-block { width: 100%; }
}

/* Heart fantasma: invisible y sin interacción. Mantiene el mismo
   tamaño que el heart real (mismo HTML + clases), por si en el futuro
   queremos alinear visualmente algún elemento. */
.cust-heart-ghost {
    visibility: hidden;
    pointer-events: none;
}

/* El botón "Personalizar gorra" replica el comportamiento del de
   "Añadir al carrito": hereda `.exclusive` del tema (display:block,
   padding interno en <span>, font-size 16px, border-radius 4px),
   crece con su contenido y queda alineado a la izquierda — igual que
   el otro. De este modo el primer pintado es ya el correcto, sin
   necesidad de JS para igualar anchos.

   Notas:
   - NO se le añade `padding` al <button> (el padding va al <span> del
     tema). Si se añade aquí, la altura visual se duplica respecto a
     "Añadir al carrito".
   - `.ch-blue` del tema solo define `background-color`. Los <button>
     llevan border nativo del browser, que se ve gris feo encima del
     azul. Lo eliminamos aquí (scoped a este botón). */
#customize-toggle {
    color: #fff;
    text-align: center;
    border: 0;
    margin: 0;
}
#customize-toggle .icon-edit { margin-right: 6px; }

#customization-panel {
    display: none;
    margin-top: 0;
    padding: 20px 18px 16px;
    background: #fff;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    position: relative;
}

#customization-panel .panel-title {
    margin: 0 0 14px;
    font-size: 16px;
    font-weight: 700;
    color: #0E6676;
    letter-spacing: 0.02em;
}

#close-customization {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: 0;
    width: 30px;
    height: 30px;
    line-height: 28px;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    border-radius: 50%;
    padding: 0;
}
#close-customization:hover { color: #BF2313; }
#close-customization:focus { outline: none; box-shadow: none; }

/* ---------- Form groups ---------------------------------------------- */

#customization-panel .cust-group { margin-bottom: 14px; }
#customization-panel label.cust-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}

#customization-panel .form-control,
#customization-panel .cust-select-button {
    height: 40px;
    padding: 8px 12px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    background: #fff;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}
#customization-panel .form-control:focus,
#customization-panel .cust-select-button:focus,
#customization-panel .cust-select-button:hover {
    border-color: #0E6676;
    outline: 0;
    box-shadow: none;
}

#customization-panel .input-wrapper { position: relative; }
#customization-panel #char-counter {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #999;
    pointer-events: none;
}
#customization-panel .error-message {
    display: none;
    color: #BF2313;
    font-size: 13px;
    margin-top: 6px;
}

/* ---------- Custom selects (font/color) ------------------------------ */

.cust-select { position: relative; }
.cust-select-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    text-align: left;
}
.cust-select-dropdown {
    display: none;
    position: absolute;
    z-index: 1000;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: -1px;
    background: #fff;
    border: 1px solid #0E6676;
    border-radius: 0 0 4px 4px;
    max-height: 260px;
    overflow-y: auto;
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
}
.cust-select.open .cust-select-dropdown { display: block; }

.cust-option {
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
}
.cust-option:last-child { border-bottom: none; }
.cust-option:hover { background-color: #f5f9fa; }

.cust-select .arrow {
    color: #999;
    font-size: 10px;
    margin-left: 6px;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}
.cust-select.open .arrow { transform: rotate(180deg); }

.cust-prefix { color: #777; margin-right: 4px; font-weight: normal; }

.cust-option .font-sample,
.cust-select-button .font-sample { font-size: 17px; line-height: 1; }

/* Ajustes per-font para el sample del dropdown (compensan x-height /
   condensado de cada familia). Ver tambien fontScaleByClass en
   product_customization.tpl + customizer.js para el SVG. */
.cust-option .font-sample.font-bebas,
.cust-select-button .font-sample.font-bebas { font-size: 26px; }
.cust-option .font-sample.font-folio,
.cust-select-button .font-sample.font-folio { font-size: 20px; }
.cust-option .font-sample.font-pacifico,
.cust-select-button .font-sample.font-pacifico { font-size: 15px; }
.cust-option .font-sample.font-monoton,
.cust-select-button .font-sample.font-monoton { font-size: 11px; }


/* Color swatch */
.color-sample {
    display: inline-block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid #ccc;
    flex-shrink: 0;
}
.color-sample.is-white { border: 1px solid #999; }

/* ---------- Preview -------------------------------------------------- */

#preview-container {
    width: 100%;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    box-sizing: border-box;
}
#preview-text, #preview-textpath {
    text-transform: none !important;
}

#cap-preview-svg {
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;
    /* Importante: sin esto, el SVG con viewBox 1024x683 tiene
       intrinsic max-content = 1024px y arrastraría la columna 1
       del grid de botones cuando el panel se abre. */
    min-width: 0;
}

/* ---------- Footer (precio) ------------------------------------------ */

.customization-price {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
    font-size: 15px;
    color: #333;
}
.customization-price strong { font-weight: 700; }
.customization-price .price-plus { color: #0E852B; font-weight: 700; }

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

@media (max-width: 767px) {
    #customization-panel { padding: 18px 14px 14px; }
    #customization-panel .form-control,
    #customization-panel .cust-select-button { font-size: 16px; }
    #close-customization { top: 6px; right: 8px; font-size: 28px; }
}
