/**
 * MH Product Personalization - Frontend Styles (Phase 4)
 * @package MH_Personalization
 */

/* ── Section ───────────────────────────────────────── */

.mh-pers-section {
    margin: 1.5em 0;
    padding: 1.5em;
    background: #fafaf8;
    border: 1px solid #e8e6e1;
    border-radius: 8px;
}

.mh-pers-section__header {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 1.25em;
    padding-bottom: 0.75em;
    border-bottom: 1px solid #e8e6e1;
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3a3a3a;
}

.mh-pers-section__icon { font-size: 1.1em; }

.mh-pers-section__body {
    display: flex;
    flex-direction: column;
    gap: 1.25em;
}

.mh-pers-section__form { width: 100%; }
.mh-pers-section__preview {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Fields ────────────────────────────────────────── */

.mh-pers-field {
    margin-bottom: 1.25em;
    transition: opacity 0.2s ease;
}

.mh-pers-field__label {
    display: block;
    margin-bottom: 0.5em;
    font-size: 0.9em;
    font-weight: 500;
    color: #444;
}

.mh-pers-field__required { color: #c9302c; }

/* ── Minimal Mode Reset ─────────────────────────────── */
/* Neutralize plugin-specific decorative styles inside .mh-pers-minimal.
   Fields render as native <select>, <input>, <p><label> — inheriting
   theme styles. Only essential behavioral styles (char count, hidden
   radios etc.) survive. Override with your theme's CSS freely. */

.mh-pers-minimal .mh-pers-field--minimal {
    margin: 0 0 1em;
    transition: none;
}

.mh-pers-minimal .mh-pers-field__dropdown,
.mh-pers-minimal .mh-pers-field__text-input {
    /* Revert decorative styles so theme takes over */
    all: revert;
    box-sizing: border-box;
}

/* ── Text Input ────────────────────────────────────── */

.mh-pers-field__text-input {
    display: block;
    width: 100%;
    padding: 0.65em 0.75em;
    border: 1px solid #d0cec9;
    border-radius: 4px;
    font-size: 1em;
    font-family: inherit;
    background: #fff;
    color: #333;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.mh-pers-field__text-input:focus {
    outline: none;
    border-color: #c9a96e;
    box-shadow: 0 0 0 2px rgba(201, 169, 110, 0.15);
}

/* Force-uppercase fields. Visual layer only — JS transforms the real value
   and the server enforces it on add-to-cart. text-transform keeps the field
   looking uppercase even before JS runs (progressive enhancement). The
   placeholder is exempted so hint text stays in its original casing. */
.mh-pers-field__text-input--uppercase {
    text-transform: uppercase;
}

.mh-pers-field__text-input--uppercase::placeholder {
    text-transform: none;
}

.mh-pers-field__char-count {
    display: block;
    margin-top: 0.25em;
    font-size: 0.78em;
    color: #999;
    text-align: right;
    transition: color 0.15s ease;
}

.mh-pers-field__char-count--limit {
    color: #c9302c;
    font-weight: 600;
}

/* ── Image Select ──────────────────────────────────── */

.mh-pers-field__image-select {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75em;
}

@media (max-width: 640px) {
    .mh-pers-field__image-select {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.4em;
    }
}

@media (max-width: 380px) {
    .mh-pers-field__image-select {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* When only 2-3 options — don't stretch them across full row on desktop. */
.mh-pers-field__image-select[data-count="1"] { grid-template-columns: minmax(0, 140px); }
.mh-pers-field__image-select[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 140px)); }
.mh-pers-field__image-select[data-count="3"] { grid-template-columns: repeat(3, minmax(0, 140px)); }

@media (max-width: 640px) {
    .mh-pers-field__image-select[data-count="1"],
    .mh-pers-field__image-select[data-count="2"],
    .mh-pers-field__image-select[data-count="3"] {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.mh-pers-image-option {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0.35em;
    cursor: pointer;
    padding: 0.5em;
    border: 2px solid transparent;
    border-radius: 6px;
    transition: border-color 0.15s ease;
    text-align: center;
    min-width: 0; /* grid overflow fix */
    width: 100%;
    box-sizing: border-box;
}

.mh-pers-image-option:hover { border-color: #d0cec9; }

.mh-pers-image-option__input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.mh-pers-image-option__input:checked + .mh-pers-image-option__visual {
    box-shadow: 0 0 0 2px #c9a96e;
}

.mh-pers-image-option__input:checked ~ .mh-pers-image-option__label {
    font-weight: 600;
}

.mh-pers-image-option__input:focus-visible + .mh-pers-image-option__visual {
    outline: 2px solid #4a90d9;
    outline-offset: 2px;
}

.mh-pers-image-option__visual {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 80px;
    border: 1px solid #e0ddd8;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    transition: box-shadow 0.15s ease;
}

.mh-pers-image-option__visual img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.mh-pers-image-option__label {
    font-size: 0.78em;
    color: #555;
    line-height: 1.25;
    word-wrap: break-word;
    hyphens: auto;
}

.mh-pers-image-option__price {
    font-size: 0.72em;
    color: #888;
}

/* ── Color Swatches ────────────────────────────────── */

.mh-pers-field__color-swatches {
    display: flex;
    gap: 0.65em;
    flex-wrap: wrap;
}

.mh-pers-swatch {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3em;
    cursor: pointer;
}

.mh-pers-swatch__input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.mh-pers-swatch__circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mh-pers-swatch--bordered .mh-pers-swatch__circle {
    border-color: #d0cec9;
}

.mh-pers-swatch__input:checked + .mh-pers-swatch__circle {
    border-color: #c9a96e;
    box-shadow: 0 0 0 2px rgba(201, 169, 110, 0.3);
}

.mh-pers-swatch__input:focus-visible + .mh-pers-swatch__circle {
    outline: 2px solid #4a90d9;
    outline-offset: 2px;
}

.mh-pers-swatch__label {
    font-size: 0.72em;
    color: #777;
}

/* ── Dropdown ──────────────────────────────────────── */

.mh-pers-field__dropdown {
    display: block;
    width: 100%;
    padding: 0.6em 2em 0.6em 0.75em;
    border: 1px solid #d0cec9;
    border-radius: 4px;
    font-size: 0.95em;
    font-family: inherit;
    background: #fff;
    color: #333;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75em center;
    cursor: pointer;
}

.mh-pers-field__dropdown:focus {
    outline: none;
    border-color: #c9a96e;
    box-shadow: 0 0 0 2px rgba(201, 169, 110, 0.15);
}

/* ── Checkbox field (e.g. gift wrap) ───────────────── */

.mh-pers-field__checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.55em;
    cursor: pointer;
    user-select: none;
    padding: 0.35em 0;
}

.mh-pers-field__checkbox {
    width: 17px;
    height: 17px;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.mh-pers-field__checkbox-text {
    font-size: 0.92em;
    color: #333;
}

/* ── HTML informational field ──────────────────────── */

.mh-pers-field__html {
    /* Intentionally minimal — admin can inline-style freely. */
    font-size: 0.88em;
    line-height: 1.5;
}

.mh-pers-field__html p:first-child { margin-top: 0; }
.mh-pers-field__html p:last-child  { margin-bottom: 0; }

/* ── Surcharge ─────────────────────────────────────── */

.mh-pers-surcharge {
    margin-top: 1em;
    padding: 0.75em;
    background: #f0ede6;
    border-radius: 4px;
    font-size: 0.9em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mh-pers-surcharge__label { color: #555; }
.mh-pers-surcharge__amount { font-weight: 600; color: #333; }

/* ── Preview ───────────────────────────────────────── */

.mh-pers-preview {
    background: #fff;
    border: 1px solid #e8e6e1;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    margin: 0 auto;
    width: 100%;
    /* max-width is set inline from admin config (display_max_width) */
}

.mh-pers-preview__label {
    padding: 0.5em 0.75em;
    font-size: 0.78em;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #999;
    border-bottom: 1px solid #f0ede6;
}

.mh-pers-preview__canvas {
    display: block;
    width: 100%;
    height: auto;
    margin: 0 auto;
    padding: 0.75em;
    box-sizing: border-box;
}

/* ── Preview Disclaimer ─────────────────────────────── */

.mh-pers-preview__disclaimer {
    margin: 0.6em 0 0;
    padding: 0;
    font-size: 0.75em;
    line-height: 1.4;
    color: #aaa;
    text-align: center;
    font-style: italic;
}

/* ── Opt-in Mode ────────────────────────────────────── */

.mh-pers-section--opt-in {
    padding: 1em 1.25em;
}

.mh-pers-opt-in {
    padding: 0;
}

.mh-pers-opt-in__label {
    display: inline-flex;
    align-items: center;
    gap: 0.6em;
    cursor: pointer;
    user-select: none;
    padding: 0.4em 0;
}

.mh-pers-opt-in__checkbox {
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
}

.mh-pers-opt-in__text {
    font-size: 0.95em;
    font-weight: 500;
    color: #333;
}

/* When opt-in body opens, give it breathing room */
.mh-pers-section--opt-in .mh-pers-section__body {
    margin-top: 1em;
    padding-top: 1em;
    border-top: 1px solid #ece9e2;
}

/* ── Accordion (collapsed mode) ─────────────────────── */

.mh-pers-section__header--toggle {
    cursor: pointer;
    user-select: none;
    justify-content: space-between;
    transition: background-color 0.15s ease;
    margin: -1.5em -1.5em 0;
    padding: 1em 1.5em;
    border-radius: 8px;
}

.mh-pers-section--collapsed .mh-pers-section__header--toggle {
    margin-bottom: 0;
    padding-bottom: 1em;
    border-bottom: none;
}

.mh-pers-section__header--toggle:hover {
    background: rgba(201, 169, 110, 0.06);
}

.mh-pers-section__chevron {
    font-size: 0.65em;
    color: #bbb;
    transition: transform 0.2s ease;
}

/* ── Reset Button ──────────────────────────────────── */

.mh-pers-reset {
    display: block;
    width: 100%;
    padding: 0.6em 1em;
    margin-top: 0.25em;
    background: none;
    border: 1px solid #d0cec9;
    border-radius: 4px;
    font-size: 0.82em;
    font-family: inherit;
    color: #888;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
    text-align: center;
}

.mh-pers-reset:hover {
    color: #555;
    border-color: #bbb;
}

/* ── Validation Errors ─────────────────────────────── */

.mh-pers-field--error .mh-pers-field__text-input,
.mh-pers-field--error .mh-pers-field__dropdown {
    border-color: #c9302c;
}

.mh-pers-field--error .mh-pers-field__label { color: #c9302c; }

.mh-pers-field__error {
    display: block;
    margin-top: 0.25em;
    margin-bottom: 0.5em;
    font-size: 0.82em;
    color: #c9302c;
}

/* ── Price Note ────────────────────────────────────── */

.mh-pers-price-note {
    font-size: 0.85em;
    color: #888;
    margin-top: 0.25em;
}

/* ── Responsive ────────────────────────────────────── */

@media (max-width: 480px) {
    .mh-pers-section { padding: 1em; }
    .mh-pers-preview__canvas { max-width: 100%; }
}
