/* ══════════════════════════════════════════════════════════════════════════
 * AgroMind Market Rates — Frontend Styles v2.0
 * ══════════════════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties (defaults — overridden by admin settings) ──── */
.agromind-mr-wrap {
    --amr-header-start: #16a34a;
    --amr-header-end:   #15803d;
    --amr-header-text:  #ffffff;
    --amr-thead-bg:     #f0fdf4;
    --amr-thead-text:   #15803d;
    --amr-cards-per-row: 3;
}

/* ── Wrapper ─────────────────────────────────────────────────────────── */
.agromind-mr-wrap {
    max-width: 100%;
    margin: 2rem auto;
    font-family: inherit;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
    background: #fff;
}

/* ── Header Bar ──────────────────────────────────────────────────────── */
.agromind-mr-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, var(--amr-header-start) 0%, var(--amr-header-end) 100%);
    color: var(--amr-header-text);
    border-radius: 12px 12px 0 0;
}
.agromind-mr-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--amr-header-text);
    display: flex;
    align-items: center;
    gap: .5rem;
}
.agromind-mr-icon {
    font-size: 1.3rem;
}
.agromind-mr-badge {
    display: inline-flex;
    align-items: center;
    padding: .3rem .85rem;
    font-size: .8rem;
    font-weight: 600;
    border-radius: 9999px;
    background: rgba(255,255,255,.2);
    backdrop-filter: blur(4px);
    color: var(--amr-header-text);
}

/* ── Toolbar (filter, toggle, PDF button) ────────────────────────────── */
.agromind-mr-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    padding: .85rem 1.25rem;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}
.agromind-mr-toolbar-left {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}
.agromind-mr-toolbar-right {
    display: flex;
    align-items: center;
    gap: .75rem;
}

/* Filter Dropdown */
.agromind-mr-filter {
    padding: .5rem .85rem;
    font-size: .85rem;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #334155;
    cursor: pointer;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
    max-width: 260px;
}
.agromind-mr-filter:focus {
    border-color: var(--amr-header-start, #16a34a);
    box-shadow: 0 0 0 3px rgba(22,163,74,.15);
}

/* View Toggle — visible on all screen sizes */
.agromind-mr-view-toggle {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .45rem .85rem;
    font-size: .78rem;
    font-weight: 600;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #475569;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}
.agromind-mr-view-toggle:hover {
    background: #f1f5f9;
}
.agromind-mr-view-toggle.active {
    background: var(--amr-header-start, #16a34a);
    color: #fff;
    border-color: var(--amr-header-start, #16a34a);
}
.agromind-mr-view-toggle-icon {
    font-size: 1rem;
}

/* PDF Download Button */
.agromind-mr-pdf-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    font-size: .82rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--amr-header-start, #16a34a), var(--amr-header-end, #15803d));
    color: #fff;
    cursor: pointer;
    transition: transform .15s, box-shadow .2s;
    white-space: nowrap;
}
.agromind-mr-pdf-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(22,163,74,.35);
}
.agromind-mr-pdf-btn:active {
    transform: translateY(0);
}
.agromind-mr-pdf-icon {
    font-size: 1rem;
}

/* Refresh Data Button */
.agromind-mr-refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    font-size: .82rem;
    font-weight: 600;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #475569;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}
.agromind-mr-refresh-btn:hover {
    background: #f1f5f9;
    border-color: var(--amr-header-start, #16a34a);
    color: var(--amr-header-start, #16a34a);
}
.agromind-mr-refresh-btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}
.agromind-mr-refresh-icon {
    font-size: 1rem;
    display: inline-block;
}
.agromind-mr-refreshing .agromind-mr-refresh-icon {
    animation: amr-spin 1s linear infinite;
}
@keyframes amr-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── Responsive Scroll Wrapper ───────────────────────────────────────── */
.agromind-mr-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Table ────────────────────────────────────────────────────────────── */
.agromind-mr-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
    font-size: .925rem;
}
.agromind-mr-table thead {
    background: var(--amr-thead-bg);
}
.agromind-mr-table th {
    padding: .85rem 1rem;
    text-align: left;
    font-weight: 700;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--amr-thead-text);
    background: var(--amr-thead-bg);
    border-bottom: 2px solid #bbf7d0;
    white-space: nowrap;
}
.agromind-mr-table td {
    padding: .75rem 1rem;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
    white-space: nowrap;
}

/* First column bold */
.agromind-mr-col-primary {
    font-weight: 700;
}

/* Date group header row */
.agromind-mr-date-row td {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    padding: .65rem 1rem;
    font-weight: 700;
    font-size: .85rem;
    color: #15803d;
    border-bottom: 2px solid #bbf7d0;
    letter-spacing: .02em;
}
.agromind-mr-date-label {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
}

/* Alternating row colours */
.agromind-mr-row-even { background: #ffffff; }
.agromind-mr-row-odd  { background: #f8fafc; }
.agromind-mr-table tbody tr:hover {
    background: #ecfdf5;
    transition: background .15s ease;
}

/* Price cells */
.agromind-mr-price {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
.agromind-mr-price-modal {
    color: #16a34a;
    font-weight: 700;
}

/* Error / Empty states */
.agromind-mr-error,
.agromind-mr-empty {
    padding: 1.25rem 1.5rem;
    border-radius: 10px;
    font-size: .95rem;
    text-align: center;
}
.agromind-mr-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.agromind-mr-empty {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Hidden row (filter) */
.agromind-mr-hidden {
    display: none !important;
}

/* ══════════════════════════════════════════════════════════════════════════
 * CARD VIEW (applied via .agromind-mr-card-view class on any screen size)
 * ══════════════════════════════════════════════════════════════════════════ */

/* Hide the table scroll wrapper overflow in card mode */
.agromind-mr-card-view .agromind-mr-table-scroll {
    overflow-x: visible;
}

.agromind-mr-card-view .agromind-mr-table {
    min-width: 0;
}
.agromind-mr-card-view .agromind-mr-table thead {
    display: none;
}
.agromind-mr-card-view .agromind-mr-table tbody {
    display: grid;
    grid-template-columns: repeat(var(--amr-cards-per-row, 3), 1fr);
    gap: .85rem;
    padding: .85rem;
}
.agromind-mr-card-view .agromind-mr-table tbody tr {
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
    transition: box-shadow .2s, transform .15s;
    border-left: 4px solid var(--amr-header-start, #16a34a);
    background: #fff;
}
.agromind-mr-card-view .agromind-mr-table tbody tr:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    transform: translateY(-1px);
}

/* Date row spans full width */
.agromind-mr-card-view .agromind-mr-table tbody tr.agromind-mr-date-row {
    grid-column: 1 / -1;
    border: none;
    border-left: none;
    border-radius: 8px;
    box-shadow: none;
}

.agromind-mr-card-view .agromind-mr-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .65rem 1rem;
    text-align: right;
    white-space: normal;
    border-bottom: 1px solid #f1f5f9;
}
.agromind-mr-card-view .agromind-mr-table td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #64748b;
    text-align: left;
    margin-right: 1rem;
    flex-shrink: 0;
}
.agromind-mr-card-view .agromind-mr-table td:last-child {
    border-bottom: none;
}
.agromind-mr-card-view .agromind-mr-date-row td::before {
    content: none;
}

/* Card: first cell as title */
.agromind-mr-card-view .agromind-mr-table td.agromind-mr-col-primary {
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    font-size: .95rem;
    font-weight: 800;
    color: #15803d;
    padding: .75rem 1rem;
    border-bottom: 2px solid #bbf7d0;
}
.agromind-mr-card-view .agromind-mr-table td.agromind-mr-col-primary::before {
    color: #16a34a;
}

/* Card: price cells */
.agromind-mr-card-view .agromind-mr-table td.agromind-mr-price-modal {
    background: #f0fdf4;
    font-size: .95rem;
}

/* ══════════════════════════════════════════════════════════════════════════
 * MOBILE OVERRIDES (≤ 768px)
 * ══════════════════════════════════════════════════════════════════════════ */
@media screen and (max-width: 768px) {

    /* Default card view on mobile (when NOT in card-view or table-force mode) */
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table-scroll {
        overflow-x: visible;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table {
        min-width: 0;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table thead {
        display: none;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table tbody tr {
        display: block;
        margin-bottom: .85rem;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 2px 8px rgba(0,0,0,.05);
        transition: box-shadow .2s, transform .15s;
        border-left: 4px solid var(--amr-header-start, #16a34a);
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table tbody tr:hover {
        box-shadow: 0 4px 16px rgba(0,0,0,.1);
        transform: translateY(-1px);
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table tbody tr.agromind-mr-date-row {
        border: none;
        border-left: none;
        margin-bottom: .35rem;
        border-radius: 8px;
        box-shadow: none;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: .65rem 1rem;
        text-align: right;
        white-space: normal;
        border-bottom: 1px solid #f1f5f9;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: .75rem;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: #64748b;
        text-align: left;
        margin-right: 1rem;
        flex-shrink: 0;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table td:last-child {
        border-bottom: none;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-date-row td::before {
        content: none;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table td.agromind-mr-col-primary {
        background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
        font-size: .95rem;
        font-weight: 800;
        color: #15803d;
        padding: .75rem 1rem;
        border-bottom: 2px solid #bbf7d0;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table td.agromind-mr-col-primary::before {
        color: #16a34a;
    }
    .agromind-mr-wrap:not(.agromind-mr-card-view):not(.agromind-mr-table-force) .agromind-mr-table td.agromind-mr-price-modal {
        background: #f0fdf4;
        font-size: .95rem;
    }

    /* Mobile: force single column cards */
    .agromind-mr-card-view .agromind-mr-table tbody {
        grid-template-columns: 1fr;
    }

    /* ── Table-Force Mode (table forced on mobile) ──────────────────── */
    .agromind-mr-table-force .agromind-mr-table {
        min-width: 640px;
    }
    .agromind-mr-table-force .agromind-mr-table-scroll {
        overflow-x: auto;
    }
    .agromind-mr-table-force .agromind-mr-table thead {
        display: table-header-group;
    }
    .agromind-mr-table-force .agromind-mr-table tbody {
        display: table-row-group;
    }
    .agromind-mr-table-force .agromind-mr-table tbody tr {
        display: table-row;
        margin-bottom: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
        border-left: none;
    }
    .agromind-mr-table-force .agromind-mr-table tbody tr:hover {
        transform: none;
    }
    .agromind-mr-table-force .agromind-mr-table td {
        display: table-cell;
        text-align: left;
        padding: .75rem 1rem;
        border-bottom: 1px solid #f1f5f9;
        white-space: nowrap;
    }
    .agromind-mr-table-force .agromind-mr-table td::before {
        content: none;
    }
    .agromind-mr-table-force .agromind-mr-table td.agromind-mr-col-primary {
        background: transparent;
        font-size: .925rem;
        color: #1e293b;
        border-bottom: 1px solid #f1f5f9;
    }
    .agromind-mr-table-force .agromind-mr-table td.agromind-mr-price-modal {
        background: transparent;
    }
}
