/* =============================================
   EcomFlow Menu Rich — v1.2.0
   Compatible Flatsome / WooCommerce
   ============================================= */

:root {
    --emr-primary: #222222;
    --emr-overlay-bg: rgba(0,0,0,0.50);
    --emr-modal-bg: #ffffff;
    --emr-header-bg: #fafafa;
    --emr-border: #e8e8e8;
    --emr-text: #1a1a1a;
    --emr-muted: #888888;
    --emr-hover-bg: #f5f5f5;
    --emr-radius: 14px;
    --emr-shadow: 0 24px 70px rgba(0,0,0,0.16), 0 4px 16px rgba(0,0,0,0.07);
    --emr-slide: 0.28s cubic-bezier(0.4,0,0.2,1);
}

/* ── Trigger Button ─────────────────────────── */
.emr-trigger-item { display:flex; align-items:center; }

.emr-trigger-btn {
    display: inline-flex !important;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-weight: 600 !important;
    white-space: nowrap;
    padding: 5px 14px 5px 10px !important;
    border: 1.5px solid currentColor;
    border-radius: 6px;
    line-height: 1 !important;
    transition: opacity 0.18s !important;
}
.emr-trigger-btn:hover { opacity:0.7; text-decoration:none !important; }
.emr-trigger-icon { display:flex; align-items:center; flex-shrink:0; }

/* ── Overlay ────────────────────────────────── */
.emr-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: var(--emr-overlay-bg);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 56px 16px 24px;
    opacity: 0;
    visibility: hidden;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    transition: opacity 0.22s var(--emr-slide), visibility 0.22s var(--emr-slide);
}
.emr-overlay.emr-active { opacity:1; visibility:visible; }

/* ── Modal ──────────────────────────────────── */
.emr-modal {
    background: var(--emr-modal-bg);
    border-radius: var(--emr-radius);
    box-shadow: var(--emr-shadow);
    width: 100%;
    max-width: 960px;
    /* Fixed height so the body inside can scroll */
    height: min(600px, calc(100vh - 110px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(-16px) scale(0.98);
    transition: transform 0.22s var(--emr-slide);
}
.emr-overlay.emr-active .emr-modal { transform:translateY(0) scale(1); }

/* ── Header ─────────────────────────────────── */
.emr-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--emr-header-bg);
    border-bottom: 1px solid var(--emr-border);
    flex-shrink: 0;
    min-height: 54px;
    gap: 12px;
}

.emr-header-left {
    display: flex;
    align-items: center;
    gap: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.emr-modal-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--emr-primary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Back Button ────────────────────────────── */
.emr-back-btn {
    display: none;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 10px 6px 4px;
    border-radius: 6px;
    color: var(--emr-primary);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.14s;
    margin-right: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}
.emr-back-btn:hover { background: #eeeeee; }
.emr-back-btn.emr-visible { display:flex; }

/* ── Close Button ───────────────────────────── */
.emr-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 7px;
    border-radius: 6px;
    color: var(--emr-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.14s, color 0.14s;
    flex-shrink: 0;
}
.emr-close-btn:hover { background:#eeeeee; color:var(--emr-text); }

/* ── Body: overflow hidden — panels scroll internally ── */
.emr-modal-body {
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Track holds both panels side by side */
.emr-panels-track {
    display: flex;
    width: 200%;
    height: 100%;
    transition: transform var(--emr-slide);
    will-change: transform;
}
.emr-panels-track.emr-slide-left { transform: translateX(-50%); }

/* Each panel = 50% of track = 100% modal width, and scrolls independently */
.emr-panel {
    width: 50%;
    height: 100%;
    overflow-y: auto;      /* ← scroll here, not on modal-body */
    overflow-x: hidden;
    padding: 24px 24px 28px;
    box-sizing: border-box;
    flex-shrink: 0;
}

/* Custom scrollbar */
.emr-panel::-webkit-scrollbar { width:5px; }
.emr-panel::-webkit-scrollbar-track { background:transparent; }
.emr-panel::-webkit-scrollbar-thumb { background:#d4d4d4; border-radius:10px; }
.emr-panel { scrollbar-width:thin; scrollbar-color:#d4d4d4 transparent; }

/* ── WooCommerce Step 1: Parent Cards ────────── */
.emr-parents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.emr-parent-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 14px 14px 12px;
    border-radius: 9px;
    border: 1.5px solid var(--emr-border);
    cursor: pointer;
    background: #fff;
    transition: border-color 0.14s, box-shadow 0.14s, transform 0.14s;
    text-decoration: none;
    color: var(--emr-text);
    position: relative;
    min-height: 64px;
}
.emr-parent-card:hover {
    border-color: var(--emr-primary);
    box-shadow: 0 3px 12px rgba(0,0,0,0.08);
    transform: translateY(-2px);
    color: var(--emr-primary);
    text-decoration: none;
}

/* Chevron for cards with children */
.emr-parent-card.has-children::after {
    content: '';
    position: absolute;
    top: 12px;
    right: 12px;
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--emr-muted);
    border-top: 2px solid var(--emr-muted);
    transform: rotate(45deg);
    transition: border-color 0.14s;
}
.emr-parent-card.has-children:hover::after { border-color: var(--emr-primary); }

/* Icon inside card */
.emr-parent-card__icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
    opacity: 0.8;
}

.emr-parent-card__name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    color: inherit;
}

.emr-parent-card__count {
    font-size: 11px;
    color: var(--emr-muted);
    font-weight: 400;
}

/* ── WooCommerce Step 2: Children Panel ──────── */
.emr-children-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--emr-primary);
    flex-wrap: wrap;
}

.emr-children-header__title {
    font-size: 16px;
    font-weight: 700;
    color: var(--emr-primary);
    line-height: 1.2;
    flex: 1;
}

.emr-children-header__link {
    font-size: 12px;
    color: var(--emr-primary);
    text-decoration: none;
    font-weight: 600;
    padding: 4px 10px;
    border: 1.5px solid var(--emr-primary);
    border-radius: 5px;
    transition: background 0.14s, color 0.14s;
    flex-shrink: 0;
    white-space: nowrap;
}
.emr-children-header__link:hover { background:var(--emr-primary); color:#fff; text-decoration:none; }

/* Children icon (global) */
.emr-children-header__icon {
    width: 32px;
    height: 32px;
    object-fit: contain;
    opacity: 0.7;
    flex-shrink: 0;
}

.emr-children-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 6px;
}

.emr-child-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 12px;
    border-radius: 7px;
    text-decoration: none;
    color: var(--emr-text);
    font-size: 13.5px;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
    line-height: 1.3;
}
.emr-child-item svg { flex-shrink:0; color:var(--emr-primary); opacity:0.4; transition:opacity 0.12s; }
.emr-child-item:hover { background:var(--emr-hover-bg); color:var(--emr-primary); text-decoration:none; }
.emr-child-item:hover svg { opacity:1; }
.emr-child-item__icon { width:18px; height:18px; object-fit:contain; flex-shrink:0; opacity:0.75; }
.emr-child-item__count { margin-left:auto; font-size:11px; color:var(--emr-muted); font-weight:400; flex-shrink:0; }

/* ── Nav Menu Mode: flat grid ────────────────── */
.emr-categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 26px 20px;
}

.emr-cat-group { display:flex; flex-direction:column; gap:4px; }

.emr-cat-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--emr-primary) !important;
    text-decoration: none !important;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--emr-primary);
    margin-bottom: 3px;
    transition: opacity 0.14s;
}
.emr-cat-title:hover { opacity:0.7; }
.emr-cat-group.no-children .emr-cat-title {
    border-bottom: 1px solid var(--emr-border);
    color: var(--emr-text) !important;
    font-weight: 600;
}

/* Icon in nav menu mode */
.emr-cat-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    flex-shrink: 0;
    opacity: 0.8;
}

.emr-cat-children { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:1px; }
.emr-cat-children li { margin:0; padding:0; }
.emr-cat-children a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 7px;
    font-size: 13px;
    color: var(--emr-text) !important;
    text-decoration: none !important;
    border-radius: 5px;
    transition: background 0.12s, color 0.12s;
}
.emr-cat-children a svg { flex-shrink:0; color:var(--emr-primary); opacity:0.35; transition:opacity 0.12s; }
.emr-cat-children a:hover { background:var(--emr-hover-bg); color:var(--emr-primary) !important; }
.emr-cat-children a:hover svg { opacity:1; }

/* ── Loading spinner ────────────────────────── */
.emr-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 60px 0;
    color: var(--emr-muted);
    font-size: 14px;
}
.emr-spinner { animation: emr-spin 0.9s linear infinite; }
@keyframes emr-spin { from{transform:rotate(0deg)} to{transform:rotate(360deg)} }

/* ── Empty ──────────────────────────────────── */
.emr-empty { color:var(--emr-muted); font-size:14px; text-align:center; padding:50px 0; }

/* ── Drag handle (mobile) ───────────────────── */
.emr-drag-handle {
    display: none;
    justify-content: center;
    padding: 8px 0 4px;
    background: var(--emr-modal-bg);
    flex-shrink: 0;
}
.emr-drag-handle span {
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 4px;
    background: #d0d0d0;
}

/* ── Body lock ──────────────────────────────── */
body.emr-modal-open { overflow:hidden; }

/* ════════════════════════════════════════════
   MOBILE — Bottom Sheet
   ════════════════════════════════════════════ */
@media (max-width: 767px) {

    .emr-overlay {
        padding: 0;
        align-items: flex-end;
        justify-content: stretch;
    }

    .emr-modal {
        border-radius: var(--emr-radius) var(--emr-radius) 0 0;
        /* Bottom sheet height: 85% of viewport, can scroll inside */
        height: 85svh;
        max-width: 100%;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
        box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
    }

    .emr-overlay.emr-active .emr-modal {
        transform: translateY(0);
    }

    /* Show drag handle on mobile */
    .emr-drag-handle { display:flex; order:-1; padding:10px 0 6px; }

    /* Tighter header on mobile */
    .emr-modal-header { padding:12px 16px; min-height:48px; }

    /* Panels */
    .emr-panel { padding:16px 14px 24px; }

    /* Smaller grid for parent cards */
    .emr-parents-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    /* Nav menu: single column */
    .emr-categories-grid {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    /* Children: single column */
    .emr-children-grid { grid-template-columns:1fr; }

    /* Child items slightly larger touch targets */
    .emr-child-item { padding:11px 12px; font-size:14px; }
    .emr-parent-card { padding:12px; }
}

/* Slightly wider cards on mid-range phones */
@media (max-width:480px) and (min-width:360px) {
    .emr-parents-grid { grid-template-columns: repeat(2, 1fr); }
}
