/**
 * Merkelapp Designer — mix.css
 * Refactored to use shared design-tokens.css and nfoto.no brand styling.
 *
 * Depends on:  design-tokens.css (must be enqueued first)
 *
 * @since 2.1.0
 */

#merkelapp-mix-editor-container {
    font-family: var(--ma-font);
    max-width: 100%;
    margin: 0 auto 40px;
    background: var(--ma-surface);
    border-radius: var(--ma-radius-lg);
    overflow: hidden;
    clear: both;
    border: 1px solid var(--ma-border-soft);
    box-shadow: var(--ma-shadow-sm);
}

/* ====================================================================
 * TOP BAR — identical pattern across all three editors
 * ==================================================================== */

.merkelapp-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 26px;
    background: var(--ma-surface-soft);
    border-bottom: 1px solid var(--ma-border-soft);
    gap: 20px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.merkelapp-top-left,
.merkelapp-top-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.merkelapp-product-title .product_title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    color: var(--ma-ink);
    letter-spacing: -0.01em;
}

.merkelapp-price-box .price {
    font-size: 22px;
    font-weight: 700;
    color: var(--ma-ink);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.merkelapp-price-box .price ins {
    text-decoration: none;
    color: var(--ma-ink);
}

.merkelapp-price-box .price del {
    font-size: 14px;
    color: var(--ma-ink-hint);
    font-weight: 500;
    margin-right: 4px;
}

/* Quantity selector — styled in design-tokens.css (shared). */

.single_add_to_cart_button.loading {
    opacity: 0.7 !important;
    cursor: wait !important;
    pointer-events: none !important;
}

.single_add_to_cart_button.loading::after {
    content: "..." !important;
    margin-left: 5px !important;
}

#merkelapp-buy-button-container .single_add_to_cart_button {
    margin: 0 !important;
    padding: 11px 24px !important;
    font-size: 14px !important;
    background: var(--ma-brand) !important;
    color: #fff !important;
    border-radius: var(--ma-radius-pill) !important;
    font-weight: 600 !important;
    border: none !important;
    box-shadow: none !important;
    transition: background var(--ma-dur) var(--ma-ease) !important;
    text-transform: none;
    letter-spacing: 0.01em;
}

#merkelapp-buy-button-container .single_add_to_cart_button:hover {
    background: var(--ma-brand-hover) !important;
    transform: none !important;
}

/* ====================================================================
 * MIX LAYOUT — preview sheet + inputs side by side
 * ==================================================================== */

.merkelapp-header.mix-layout {
    display: flex;
    flex-wrap: wrap;
    gap: 32px;
    padding: 28px 26px;
    background: var(--ma-surface);
    align-items: flex-start;
}

.merkelapp-preview-section {
    flex: 1;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* The "sheet" that holds the mix labels — soft sage backdrop */
.mix-sheet {
    width: 375px;
    height: 500px;
    background: var(--ma-surface);
    border-radius: var(--ma-radius-md);
    position: relative;
    padding: 14px;
    box-sizing: border-box;
    display: block;
    overflow: hidden;
}

#merkelapp-mix-editor-container .mix-sheet {
    box-shadow: var(--ma-shadow-md);
    border: 1px solid var(--ma-border-soft);
}

.label-mix-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(16, 1fr);
    gap: 12px;
    width: 100%;
    height: 100%;
}

/* Hide main product image for product 669 (legacy product id) */
.postid-669 .woocommerce-product-gallery,
.postid-669 .flex-viewport,
.postid-669 .images {
    display: none !important;
}

.mix-label {
    background: #f0f0f0;
    border-radius: var(--ma-radius-sm);
    display: flex;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    transition: transform var(--ma-dur) var(--ma-ease);
    justify-content: flex-start;
    border: 1px solid transparent;
    box-shadow: none;
}

/* Subtle border for light/white backgrounds in editor only. */
#merkelapp-mix-editor-container .mix-label[style*="background-color: #ffffff"],
#merkelapp-mix-editor-container .mix-label[style*="background-color: rgb(255, 255, 255)"],
#merkelapp-mix-editor-container .mix-label[style*="background-color: #fff"] {
    border: 1px solid var(--ma-border-soft);
    box-shadow: var(--ma-shadow-xs);
}

.mix-label:hover { transform: scale(1.02); }

/* ====================================================================
 * GRID SHAPES — unchanged structurally
 * ==================================================================== */

.rect-med           { grid-column: span 4; grid-row: span 2; }
.rect-large         { grid-column: span 6; grid-row: span 2; }
.circle-large       { grid-column: span 4; grid-row: span 4; border-radius: 50%; aspect-ratio: 1/1; justify-content: center; text-align: center; flex-direction: column; }
.square-large       { grid-column: span 4; grid-row: span 4; aspect-ratio: 1/1; justify-content: center; text-align: center; flex-direction: column; }
.square-med         { grid-column: span 3; grid-row: span 3; aspect-ratio: 1/1; justify-content: center; text-align: center; flex-direction: column; }
.rect-bottom-large  { grid-column: span 6; grid-row: span 3; }
.circle-med         { grid-column: span 2; grid-row: span 1; border-radius: 50%; aspect-ratio: 1/1; justify-content: center; }

.mix-clipart {
    height: 70%;
    width: auto;
    max-width: 35%;
    object-fit: contain;
    z-index: 2;
    margin-right: 4px;
}

.circle-large .mix-clipart,
.circle-med .mix-clipart {
    position: absolute;
    opacity: 0.15;
    height: 80%;
    width: auto;
    max-width: 80%;
    margin: 0;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.mix-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.1;
    min-width: 0;
    z-index: 3;
}

.mix-l1 { font-weight: 800; font-size: 12px; white-space: nowrap; overflow: visible; }
.mix-l2 { font-weight: 600; font-size: 9px; white-space: nowrap; overflow: visible; }

.rect-large .mix-l1 { font-size: 14px; }
.rect-large .mix-l2 { font-size: 11px; }
.circle-large .mix-l1 { font-size: 12px; text-align: center; }
.circle-large .mix-l2 { font-size: 9px; text-align: center; }
.circle-med .mix-l2,
.square-med .mix-l2 { display: none; }
.circle-med .mix-l1,
.square-med .mix-l1 { font-size: 10px; text-align: center; }
.square-large .mix-l1 { font-size: 13px; }
.square-large .mix-l2 { font-size: 10px; }

/* ====================================================================
 * INPUT SECTION
 * ==================================================================== */

.merkelapp-input-section {
    flex: 1;
    min-width: 300px;
    max-width: 100%;
}

.merkelapp-input-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.input-wrapper {
    position: relative;
    width: 100%;
}

.input-wrapper input {
    width: 100%;
    padding: 14px 60px 14px 18px !important;
    border: 1px solid var(--ma-border) !important;
    border-radius: var(--ma-radius-md) !important;
    font-size: 15px !important;
    background: var(--ma-surface-input) !important;
    color: var(--ma-ink) !important;
    outline: none;
    transition: border-color var(--ma-dur) var(--ma-ease),
                box-shadow var(--ma-dur) var(--ma-ease) !important;
    box-sizing: border-box;
    font-family: var(--ma-font);
}

.input-wrapper input::placeholder {
    color: var(--ma-ink-hint);
}

.input-wrapper input:focus {
    border-color: var(--ma-brand) !important;
    background: var(--ma-surface) !important;
    box-shadow: var(--ma-focus-ring) !important;
}

.char-count {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--ma-ink-faint);
    font-weight: 500;
}

/* ====================================================================
 * TAB NAVIGATION
 * ==================================================================== */

.merkelapp-selector-section {
    background: transparent;
    border-top: none;
    padding: 0;
    margin-top: 20px;
}

#merkelapp-mix-editor-container .merkelapp-tabs-nav {
    display: flex;
    background: var(--ma-surface) !important;
    padding: 4px;
    border-radius: var(--ma-radius-pill);
    gap: 4px;
    max-width: 100%;
    margin: 0 0 20px 0;
    box-shadow: none;
    border: 1px solid var(--ma-border-soft);
}

#merkelapp-mix-editor-container .merkelapp-tab-btn {
    flex: 1;
    padding: 9px 8px;
    border: none !important;
    background: transparent !important;
    border-radius: var(--ma-radius-pill);
    font-weight: 500;
    color: var(--ma-ink-muted) !important;
    cursor: pointer;
    transition: all var(--ma-dur) var(--ma-ease);
    font-size: 13px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--ma-font);
}

#merkelapp-mix-editor-container .merkelapp-tab-btn .tab-icon {
    font-size: 14px;
}

#merkelapp-mix-editor-container .merkelapp-tab-btn:hover:not(.active) {
    background: var(--ma-surface-tint) !important;
    color: var(--ma-ink) !important;
}

#merkelapp-mix-editor-container .merkelapp-tab-btn.active {
    background: var(--ma-brand) !important;
    color: #ffffff !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

/* Category select — pill styled to match nfoto.no */
#merkelapp-mix-editor-container .merkelapp-select {
    width: 100%;
    height: 44px !important;
    padding: 0 40px 0 18px !important;
    border: 1px solid var(--ma-border) !important;
    border-radius: var(--ma-radius-pill) !important;
    font-size: 14px !important;
    background-color: var(--ma-surface) !important;
    color: var(--ma-ink) !important;
    cursor: pointer !important;
    outline: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236B8071' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 16px center !important;
    background-size: 16px !important;
    transition: all var(--ma-dur) var(--ma-ease) !important;
    box-shadow: none !important;
    font-weight: 500 !important;
    line-height: 42px !important;
    font-family: var(--ma-font);
}

#merkelapp-mix-editor-container .merkelapp-select:focus {
    border-color: var(--ma-brand) !important;
    box-shadow: var(--ma-focus-ring) !important;
}

/* Motiv filter bar: select + "Fjern motiv" button on one row. */
#merkelapp-mix-editor-container #tab-motiv .merkelapp-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}
#merkelapp-mix-editor-container #tab-motiv .merkelapp-filter-bar .merkelapp-select {
    flex: 1;
}
#merkelapp-mix-editor-container .merkelapp-remove-clipart {
    flex: 0 0 auto;
    height: 44px;
    padding: 0 16px;
    border: 1px solid var(--ma-border);
    border-radius: var(--ma-radius-pill);
    background-color: var(--ma-surface);
    color: var(--ma-ink);
    font-family: var(--ma-font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--ma-dur) var(--ma-ease);
}
#merkelapp-mix-editor-container .merkelapp-remove-clipart:hover {
    border-color: var(--ma-brand);
    color: var(--ma-brand);
}

.merkelapp-tab-content {
    display: none;
    animation: fadeIn 0.3s var(--ma-ease);
}

.merkelapp-tab-content.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ====================================================================
 * GRIDS — inspiration / clipart / colors / fonts
 * ==================================================================== */

.inspiration-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 18px;
}

.inspiration-item {
    cursor: pointer;
    transition: transform var(--ma-dur) var(--ma-ease);
    text-align: center;
}

.inspiration-item:hover { transform: translateY(-4px); }

.inspiration-preview {
    aspect-ratio: 15/10;
    border-radius: var(--ma-radius-md);
    display: flex;
    align-items: center;
    padding: 0 10%;
    box-sizing: border-box;
    box-shadow: var(--ma-shadow-sm);
    margin-bottom: 8px;
    overflow: hidden;
    position: relative;
}

.inspiration-preview img {
    height: 60%;
    margin-right: 5%;
}

.inspiration-preview .ins-text {
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
}

.inspiration-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ma-ink-muted);
}

.merkelapp-clipart-grid,
.merkelapp-color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
}

.merkelapp-font-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.clipart-item,
.color-option {
    aspect-ratio: 1/1;
    background: var(--ma-surface);
    border: 1px solid var(--ma-border-soft);
    border-radius: var(--ma-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--ma-shadow-xs);
    transition: all var(--ma-dur) var(--ma-ease);
    padding: 10px;
}

.clipart-item img { max-height: 80%; width: auto; }

.font-option {
    background: var(--ma-surface);
    border: 1px solid var(--ma-border-soft);
    border-radius: var(--ma-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
    padding: 10px;
    transition: all var(--ma-dur) var(--ma-ease);
    font-size: 1.15rem;
    line-height: 1;
    color: var(--ma-ink);
}

.merkelapp-text-options {
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--ma-border-soft);
}

.merkelapp-text-color-toggle {
    display: flex;
    align-items: center;
    gap: 14px;
}

.text-color-btns {
    display: flex;
    gap: 8px;
}

.text-color-btn {
    width: 34px !important;
    height: 34px !important;
    padding: 0 !important;
    border: 2px solid transparent !important;
    border-radius: 50% !important;
    cursor: pointer;
    transition: all var(--ma-dur) var(--ma-ease);
    margin: 0 !important;
    text-indent: -9999px;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.10) !important;
}

.text-color-btn[data-color="#ffffff"] {
    background: #ffffff !important;
}

.text-color-btn[data-color="#333333"] {
    background: var(--ma-ink) !important;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08) !important;
}

.text-color-btn:hover {
    transform: scale(1.05);
}

.text-color-btn.active {
    border-color: var(--ma-brand) !important;
    box-shadow: var(--ma-focus-ring);
}

.clipart-item:hover,
.color-option:hover {
    transform: translateY(-2px);
    border-color: var(--ma-border-strong);
    box-shadow: var(--ma-shadow-sm);
}

.font-option:hover {
    border-color: var(--ma-border-strong);
    background: var(--ma-surface-tint);
}

.clipart-item.active,
.color-option.active {
    border-color: var(--ma-brand);
    box-shadow: var(--ma-focus-ring);
}

.font-option.active {
    background: var(--ma-surface-tint);
    border-color: var(--ma-brand);
    border-width: 2px;
    padding: 9px;
    box-shadow: var(--ma-shadow-xs);
}

/* ====================================================================
 * RESPONSIVE
 * ==================================================================== */

@media (max-width: 768px) {
    .merkelapp-header.mix-layout { padding: 20px; gap: 20px; }

    .mix-sheet {
        width: 100%;
        height: auto;
        aspect-ratio: 15/20;
        max-width: 320px;
        margin: 0 auto;
        padding: 10px;
    }

    .label-mix-grid {
        gap: 8px;
    }

    .merkelapp-preview-section {
        min-width: 100%;
        position: sticky;
        top: 0;
        background: var(--ma-surface);
        padding: 10px 0;
        z-index: 100;
        box-shadow: var(--ma-shadow-xs);
        margin: -15px -15px 20px -15px;
        width: calc(100% + 30px);
    }

    .merkelapp-top-bar {
        flex-direction: column;
        padding: 18px;
        text-align: center;
        position: relative;
    }

    .merkelapp-top-left,
    .merkelapp-top-right {
        flex-direction: column;
        gap: 10px;
    }

    .merkelapp-tabs-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 4px;
    }

    .merkelapp-tab-btn {
        flex: 0 0 auto;
        width: 25%;
        min-width: 70px;
        font-size: 12px;
    }
}
