/*
 * File:    amsgf-frontend.css
 * Version: 1.0.3
 * Purpose: All visual styles for the AM Sheet Grid Filter directory shortcode.
 *          Colours are declared as CSS custom properties on .amsgf-directory
 *          and injected as an inline <style> block by the shortcode renderer.
 *          Every selector is scoped inside .amsgf-directory where possible
 *          to minimise conflicts with theme stylesheets.
 */

/* ── CSS custom property defaults ───────────────────────────────────────────
   These act as fallback values when the inline style block has not yet loaded.
   The shortcode overrides these with admin-configured values at runtime.      */

.amsgf-directory {
    --amsgf-header-bg:       #1F3A5F;
    --amsgf-header-text:     #FFFFFF;
    --amsgf-row-odd:         #FFFFFF;
    --amsgf-row-even:        #F8F9FA;
    --amsgf-row-text:        #333333;
    --amsgf-row-hover:       #EAF3FB;
    --amsgf-filter-bg:       #F5F6FA;
    --amsgf-audio-bg:        #22A06B;
    --amsgf-audio-text:      #FFFFFF;
    --amsgf-meta-bg:         #6554C0;
    --amsgf-meta-text:       #FFFFFF;
    --amsgf-uses-color:      #22A06B;
    --amsgf-used-to-use:     #FF8B00;
    --amsgf-pilot-color:     #0065FF;
    --amsgf-benchmark-color: #6554C0;
    --amsgf-panel-bg:          #FFFFFF;
    --amsgf-panel-text:        #333333;
    --amsgf-panel-accent:      #1F3A5F;
    --amsgf-link:              #0065FF;
    --amsgf-usecase-active:   #1F3A5F;
    --amsgf-usecase-inactive: #CCCCCC;
}

/* ── Root wrapper ────────────────────────────────────────────────────────── */

.amsgf-directory {
    font-family: inherit;
    font-size: 14px;
    color: var(--amsgf-row-text);
    line-height: 1.5;
    position: relative;
}

/* ── Filter bar ──────────────────────────────────────────────────────────── */

.amsgf-filter-bar {
    background: var(--amsgf-filter-bg);
    padding: 14px 16px;
    border-radius: 4px;
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.amsgf-filter-search {
    flex: 1 1 180px;
}

.amsgf-filter-bar input[type="text"],
.amsgf-filter-bar select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d0d3da;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
    color: #333;
    appearance: none;
    -webkit-appearance: none;
    box-sizing: border-box;
}

.amsgf-filter-bar select {
    padding-right: 28px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
}

.amsgf-filter-bar input[type="text"]:focus,
.amsgf-filter-bar select:focus {
    outline: none;
    border-color: var(--amsgf-link);
    box-shadow: 0 0 0 2px rgba(0, 101, 255, 0.12);
}

.amsgf-filter-select {
    flex: 1 1 140px;
}

.amsgf-results-count {
    font-size: 12px;
    color: #777;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Table wrapper ───────────────────────────────────────────────────────── */

.amsgf-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Table ───────────────────────────────────────────────────────────────── */

.amsgf-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

.amsgf-table thead th {
    background: var(--amsgf-header-bg);
    color: var(--amsgf-header-text);
    padding: 11px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.amsgf-table thead th:last-child {
    text-align: center;
}

.amsgf-table tbody tr:nth-child(odd) {
    background: var(--amsgf-row-odd);
}

.amsgf-table tbody tr:nth-child(even) {
    background: var(--amsgf-row-even);
}

.amsgf-table tbody tr:hover {
    background: var(--amsgf-row-hover);
    cursor: pointer;
}

.amsgf-table tbody tr.is-hidden {
    display: none;
}

.amsgf-table tbody td {
    padding: 10px 14px;
    color: var(--amsgf-row-text);
    vertical-align: middle;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.amsgf-table tbody td:last-child {
    text-align: center;
}

/* ── Provider cell (logo + name) ─────────────────────────────────────────── */

.amsgf-provider-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.amsgf-provider-logo {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    object-fit: contain;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.amsgf-provider-initials {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    background: var(--amsgf-header-bg);
    color: var(--amsgf-header-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0.02em;
}

.amsgf-provider-name {
    font-weight: 600;
    font-size: 13px;
}

/* ── Technology badges ───────────────────────────────────────────────────── */

.amsgf-tech-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.amsgf-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.amsgf-badge--audio {
    background: var(--amsgf-audio-bg);
    color: var(--amsgf-audio-text);
}

.amsgf-badge--meta {
    background: var(--amsgf-meta-bg);
    color: var(--amsgf-meta-text);
}

/* ── Use case icon row (table cell) ──────────────────────────────────────── */

.amsgf-use-icons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}

.amsgf-use-icon {
    width: 18px;
    height: 18px;
    color: var(--amsgf-usecase-inactive);
    flex-shrink: 0;
    position: relative;
}

.amsgf-use-icon--active {
    color: var(--amsgf-usecase-active);
}

.amsgf-use-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Tooltip on use case icon hover */
.amsgf-use-icon .amsgf-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 11px;
    padding: 3px 7px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 20;
}

.amsgf-use-icon:hover .amsgf-tooltip {
    display: block;
}

/* ── CMO logo row (table cell) ───────────────────────────────────────────── */

.amsgf-cmo-logos {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.amsgf-cmo-logo-wrap {
    position: relative;
    flex-shrink: 0;
}

.amsgf-cmo-logo {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: contain;
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: block;
}

.amsgf-cmo-initials {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e4e6eb;
    color: #555;
    font-size: 9px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* CMO name tooltip on hover */
.amsgf-cmo-logo-wrap .amsgf-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 11px;
    padding: 3px 7px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 20;
}

.amsgf-cmo-logo-wrap:hover .amsgf-tooltip {
    display: block;
}

/* ── View Details button ─────────────────────────────────────────────────── */

.amsgf-view-btn {
    display: inline-block;
    padding: 6px 14px;
    background: transparent;
    border: 1.5px solid var(--amsgf-panel-accent);
    color: var(--amsgf-panel-accent);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.amsgf-view-btn:hover {
    background: var(--amsgf-panel-accent);
    color: #fff;
}

/* ── Interaction badges ──────────────────────────────────────────────────── */

.amsgf-interaction {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    border: 1.5px solid;
    white-space: nowrap;
}

.amsgf-interaction--uses {
    color: var(--amsgf-uses-color);
    border-color: var(--amsgf-uses-color);
}

.amsgf-interaction--used-to-use {
    color: var(--amsgf-used-to-use);
    border-color: var(--amsgf-used-to-use);
}

.amsgf-interaction--pilot {
    color: var(--amsgf-pilot-color);
    border-color: var(--amsgf-pilot-color);
}

.amsgf-interaction--benchmark {
    color: var(--amsgf-benchmark-color);
    border-color: var(--amsgf-benchmark-color);
}

/* ── No-results message ──────────────────────────────────────────────────── */

.amsgf-no-results {
    text-align: center;
    padding: 48px 20px;
    color: #aaa;
    font-size: 15px;
    display: none;
}

.amsgf-no-results.is-visible {
    display: block;
}

/* ── Detail panel overlay ────────────────────────────────────────────────── */

.amsgf-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
}

.amsgf-overlay.is-open {
    display: block;
}

/* ── Detail panel ────────────────────────────────────────────────────────── */

.amsgf-panel {
    position: fixed;
    top: 0;
    right: -440px;
    width: 420px;
    max-width: 92vw;
    height: 100%;
    overflow-y: auto;
    background: var(--amsgf-panel-bg);
    color: var(--amsgf-panel-text);
    z-index: 9999;
    box-shadow: -4px 0 28px rgba(0, 0, 0, 0.16);
    transition: right 0.28s ease;
}

.amsgf-panel.is-open {
    right: 0;
}

.amsgf-panel-inner {
    padding: 28px 24px 36px;
}

/* ── Panel: close button ─────────────────────────────────────────────────── */

.amsgf-panel-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: var(--amsgf-panel-text);
    cursor: pointer;
    padding: 4px;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.amsgf-panel-close:hover {
    opacity: 1;
}

/* ── Panel: provider header ──────────────────────────────────────────────── */

.amsgf-panel-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 22px;
    padding-right: 32px; /* clear close button */
}

.amsgf-panel-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.07);
    flex-shrink: 0;
}

.amsgf-panel-initials {
    width: 64px;
    height: 64px;
    border-radius: 6px;
    background: var(--amsgf-panel-accent);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.amsgf-panel-header-text {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 2px;
}

.amsgf-panel-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--amsgf-panel-accent);
    margin: 0;
    line-height: 1.2;
}

.amsgf-panel-website {
    display: inline-block;
    padding: 5px 14px;
    background: var(--amsgf-panel-accent);
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    transition: opacity 0.15s;
    align-self: flex-start;
}

.amsgf-panel-website:hover {
    opacity: 0.85;
    color: #fff;
    text-decoration: none;
}

/* ── Panel: section blocks ───────────────────────────────────────────────── */

.amsgf-panel-section {
    margin-bottom: 22px;
    padding-bottom: 22px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.amsgf-panel-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.amsgf-panel-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--amsgf-panel-accent);
    margin: 0 0 12px;
}

/* ── Panel: technology badge row ─────────────────────────────────────────── */

.amsgf-panel-tech {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ── Panel: use case grid ────────────────────────────────────────────────── */

.amsgf-panel-use-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px 8px;
}

.amsgf-panel-use-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
    color: var(--amsgf-usecase-inactive);
}

.amsgf-panel-use-item--active {
    color: var(--amsgf-usecase-active);
}

.amsgf-panel-use-item svg {
    width: 22px;
    height: 22px;
    display: block;
}

.amsgf-panel-use-label {
    font-size: 10px;
    line-height: 1.3;
    max-width: 64px;
}

/* ── Panel: CMO relationship list ────────────────────────────────────────── */

.amsgf-panel-cmo-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.amsgf-panel-cmo {
    padding: 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 4px;
}

.amsgf-panel-cmo-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.amsgf-panel-cmo-logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: contain;
    border: 1px solid rgba(0, 0, 0, 0.07);
    flex-shrink: 0;
}

.amsgf-panel-cmo-initials {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--amsgf-panel-accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.amsgf-panel-cmo-meta {
    flex: 1;
    min-width: 0;
}

.amsgf-panel-cmo-name {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 3px;
}

.amsgf-panel-cmo-country {
    font-size: 12px;
    color: #888;
    margin-bottom: 5px;
}

.amsgf-panel-cmo-uses {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.amsgf-panel-cmo-notes {
    margin-top: 8px;
    font-size: 12px;
    color: #777;
    font-style: italic;
    line-height: 1.4;
}

/* ── Panel: provider notes ───────────────────────────────────────────────── */

.amsgf-panel-notes {
    font-size: 13px;
    line-height: 1.55;
    color: var(--amsgf-panel-text);
}

/* ── Footer bar ──────────────────────────────────────────────────────────── */

.amsgf-footer {
    margin-top: 14px;
    padding: 10px 4px;
    font-size: 12px;
    color: #999;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    line-height: 1.5;
}

/* ── Responsive — stacked card layout on mobile ──────────────────────────── */

@media (max-width: 680px) {

    /* Filter bar stacks vertically */
    .amsgf-filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .amsgf-filter-search,
    .amsgf-filter-select {
        flex: 1 1 auto;
    }

    .amsgf-results-count {
        text-align: right;
    }

    /* Table: remove horizontal scroll — card layout doesn't need it */
    .amsgf-table-wrap {
        overflow-x: visible;
    }

    .amsgf-table {
        min-width: 0;
    }

    /* Hide the column header row — labels shown via ::before instead */
    .amsgf-table thead {
        display: none;
    }

    /* Each row becomes a 2-column card — 60/40 split */
    .amsgf-table tbody tr {
        display: grid;
        grid-template-columns: 3fr 2fr;
        gap: 20px 12px;
        padding: 18px 14px;
        border-bottom: 2px solid rgba(0, 0, 0, 0.07);
        background: var(--amsgf-row-odd);
    }

    .amsgf-table tbody tr:nth-child(even) {
        background: var(--amsgf-row-even);
    }

    /* Reset td padding — grid gap handles spacing */
    .amsgf-table tbody td {
        padding: 0;
        border-bottom: none;
        vertical-align: top;
    }

    /* Column label — black pill with white text above each cell */
    .amsgf-table tbody td::before {
        display: inline-block;
        font-size: 9px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.07em;
        background: #111;
        color: #fff;
        padding: 2px 7px;
        border-radius: 3px;
        margin-bottom: 8px;
    }

    /* Provider — top-left */
    .amsgf-table tbody td:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
    }
    .amsgf-table tbody td:nth-child(1)::before { content: 'Provider'; }

    /* Technology — top-right */
    .amsgf-table tbody td:nth-child(2) {
        grid-column: 2;
        grid-row: 1;
    }
    .amsgf-table tbody td:nth-child(2)::before { content: 'Technology'; }

    /* Use Cases — bottom-left */
    .amsgf-table tbody td:nth-child(3) {
        grid-column: 1;
        grid-row: 2;
    }
    .amsgf-table tbody td:nth-child(3)::before { content: 'Use Cases'; }

    /* CMOs — bottom-right */
    .amsgf-table tbody td:nth-child(4) {
        grid-column: 2;
        grid-row: 2;
    }
    .amsgf-table tbody td:nth-child(4)::before { content: 'CMOs'; }

    /* View Details — full width, row 3, centred */
    .amsgf-table tbody td:nth-child(5) {
        grid-column: 1 / -1;
        grid-row: 3;
        text-align: center;
    }
    .amsgf-table tbody td:nth-child(5)::before { content: none; }

    /* Restore last-child centering override for desktop — not needed on mobile */
    .amsgf-table tbody td:last-child {
        text-align: center;
    }

    /* Hidden rows still hide correctly in card mode */
    .amsgf-table tbody tr.is-hidden {
        display: none;
    }

    /* Panel: full-width slide-in on mobile */
    .amsgf-panel {
        width: 100%;
        max-width: 100%;
        right: -100%;
    }

    .amsgf-panel-use-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
