/* ================================================================
   components/table-mobile-trade-flows-cards.css

   Mobile-card primitives for the Trade-flows table (Table 1 —
   HS product + top-5 countries). Used by:
     • Member-state detail (Import Data tab)
     • Producing-country detail (Export Data tab)
     • Commodity detail (Import + Export tabs)
   ================================================================ */


/* ================================================================
   1. HOST WRAPPER (desktop ⇄ mobile swap, ≤ 1000 px)
   ================================================================ */
.cc-mcard-host__desktop { display: block; }
.cc-mcard-host__mobile  { display: none; }


/* ================================================================
   2. CARD LIST + CARD PRIMITIVES
   ================================================================ */
.cc-mcard-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.cc-mcard {
    background: var(--white);
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}


/* ================================================================
   3. GROUP HEADER (above each cluster of trade-flow cards)
   Visual parity with the case-studies group header — tinted bg +
   bottom hairline. Trade-flows only groups by commodity, so just
   the commodity-icon mark variant.
   ================================================================ */
.cc-mcard-group-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px var(--space-md);
    background: color-mix(in srgb, var(--card-bg) 50%, var(--white));
    border-bottom: 1px solid var(--color-input-border);
    color: var(--ae-black);
}
.cc-mcard-group-header__mark {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.cc-mcard-group-header__mark img {
    width: 100%; height: 100%;
    display: block;
}
.cc-mcard-group-header__mark--commodity {
    width: 28px; height: 28px;
}
.cc-mcard-group-header__mark--commodity img { object-fit: contain; }
.cc-mcard-group-header__name {
    font-family: var(--font-heading);
    font-size: var(--fs-md);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.cc-mcard-group-header__count {
    margin-left: auto;
    color: var(--color-muted);
    font-size: var(--fs-sm);
}


/* ================================================================
   4. CARD-LIST WRAPPER + DATA-GROUP HEADER VISIBILITY
   Flat container; headers show only in commodity mode.
   ================================================================ */
.cc-mcard-list[data-mobile-card-list] {
    gap: 0;
    background: var(--white);
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.cc-mcard-host__mobile[data-group="none"]      .cc-mcard-group-header { display: none; }
.cc-mcard-host__mobile[data-group="commodity"] .cc-mcard-group-header[data-group-kind="country"] { display: none; }


/* ================================================================
   5. MOBILE FILTERS TRIGGER + PROXY PANEL (≤ 1000 px)
   ================================================================ */
.cc-mfilters-trigger { display: none; }
.cc-mfilters         { display: none; }


/* ================================================================
   6. TABLE 1 — HS PRODUCT + TOP-5 COUNTRY CARD
   ================================================================ */
.cc-mcard--hs {
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    border-bottom: 1px solid var(--color-input-border);
}
.cc-mcard--hs:last-child { border-bottom: 0; }

.cc-mcard--hs .cc-mcard__head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--space-md);
    align-items: start;
    padding: var(--space-md);
    background: var(--white);
    cursor: pointer;
    list-style: none;
}
.cc-mcard--hs .cc-mcard__head::-webkit-details-marker { display: none; }
.cc-mcard--hs .cc-mcard__head::marker                 { content: ""; }

.cc-mcard--hs[open] .cc-mcard__head {
    border-bottom: 1px solid var(--color-input-border);
}

.cc-mcard__hs {
    display: flex;
    flex-direction: column;
    min-width: 48px;
}
.cc-mcard__hs-label {
    font-size: var(--fs-xs);
    color: var(--color-muted);
    letter-spacing: 0.05em;
}
.cc-mcard__hs-code {
    font-family: var(--font-heading);
    font-size: var(--fs-md);
    color: var(--ae-darkblue);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.cc-mcard--hs .cc-mcard__head .cc-table__product-commodity {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
}
.cc-mcard__commodity-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cc-mcard__product {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.cc-mcard__total {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}
.cc-mcard__total-label {
    font-size: var(--fs-xs);
    color: var(--color-muted);
    letter-spacing: 0.05em;
}

.cc-mcard--hs .cc-mcard__head .cc-mcard__toggle {
    grid-column: 3;
    grid-row: 2;
    justify-self: end;
    align-self: start;
    margin-top: 6px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ae-darkblue);
    font-family: var(--font-body);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.cc-mcard--hs .cc-mcard__toggle-label::before {
    content: "View more";
}
.cc-mcard--hs[open] > .cc-mcard__head .cc-mcard__toggle-label::before {
    content: "View less";
}
.cc-mcard--hs .cc-mcard__head .cc-mcard__chev {
    color: var(--ae-darkblue);
}
.cc-mcard--hs[open] > .cc-mcard__head .cc-mcard__chev {
    transform: rotate(180deg);
}

.cc-mcard__chev {
    width: 18px; height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-muted);
    transition: transform var(--transition-base);
}
.cc-mcard__chev::before {
    content: "";
    width: 8px; height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    margin-top: -3px;
}

.cc-mcard__section-label {
    margin: var(--space-sm) var(--space-md) var(--space-xs);
    font-family: var(--font-body);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.cc-mcard--hs .cc-mrank { padding: 0 var(--space-md) var(--space-md); }


/* === Ranked rows (1-5 country rows) =========================== */
.cc-mrank {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}
.cc-mrank__row {
    display: grid;
    grid-template-columns: 18px auto 1fr auto;
    grid-template-areas:
        "rank flag name pct"
        ".    .    bar  bar";
    gap: 4px var(--space-sm);
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--color-input-border);
}
.cc-mrank__row:last-child { border-bottom: 0; }

.cc-mrank__num {
    grid-area: rank;
    font-family: var(--font-body);
    font-size: var(--fs-sm);
    color: var(--color-muted);
    font-variant-numeric: tabular-nums;
}

.cc-mrank__flag {
    grid-area: flag;
    width: 24px; height: 18px;
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--card-bg);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.cc-mrank__flag img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}

.cc-mrank__name {
    grid-area: name;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ae-black);
    font-size: var(--fs-sm);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cc-mrank__name .cc-defor-glyph {
    width: 14px; height: 14px;
    flex-shrink: 0;
}

.cc-mrank__pct {
    grid-area: pct;
    justify-self: end;
    color: var(--ae-darkblue);
    font-weight: 700;
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
}

.cc-mrank__bar {
    grid-area: bar;
    height: 6px;
    background: var(--color-track-bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.cc-mrank__bar-fill {
    height: 100%;
    background: var(--ae-darkblue);
    border-radius: var(--radius-sm);
}

.cc-mrank__row.is-search-match {
    background: color-mix(in srgb, var(--ae-orange) 18%, transparent);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    margin: 0 -8px;
}


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

/* === ≤ 1000px (cards swap + filter trigger) =================== */
@media (max-width: 1000px) {
    .cc-mcard-host__desktop { display: none; }
    .cc-mcard-host__mobile  { display: block; }

    .cc-detail-filters:not(.cs-rail) { display: none !important; }

    .cc-detail-toolbar {
        display: grid;
        grid-template-columns: auto 1fr;
        align-items: stretch;
    }
    .cc-detail-toolbar__main {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-sm) var(--space-md);
        min-width: 0;
    }
    .cc-detail-toolbar__group { display: contents; }

    .cc-mfilters-trigger {
        align-self: center;
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        flex-shrink: 0;
        padding: 8px 12px;
        background: transparent;
        border: 0;
        color: var(--ae-darkblue);
        font-family: var(--font-body);
        font-size: var(--fs-xs);
        font-weight: 600;
        line-height: 1;
        cursor: pointer;
        transition: color var(--transition-base);
    }
    .cc-mfilters-trigger i { font-size: 22px; }
    .cc-mfilters-trigger .cc-mfilters-trigger__label { font-size: var(--fs-sm); }
    .cc-mfilters-trigger.is-open,
    .cc-mfilters-trigger:hover,
    .cc-mfilters-trigger:focus-visible {
        color: var(--ae-lightgreen);
        outline: none;
    }
    .cc-mfilters-trigger__label { letter-spacing: 0.02em; }

    .cc-mfilters {
        display: block;
        margin-bottom: var(--space-md);
        background: var(--white);
        border: 1.5px solid var(--ae-darkblue);
        border-radius: var(--radius-dropdown);
        overflow: visible;
    }
    .cc-mfilters[hidden] { display: none; }
}
