/**
 * Bestsellers Ranking - Frontend Styles
 *
 * @package BestsellersRanking
 * @since 1.0.0
 */

/* ===========================
   General Styles
   =========================== */

.bestsellers-ranking-wrapper {
    margin: 30px 0;
}

.bestsellers-header {
    text-align: center;
    margin-bottom: 30px;
}

.bestsellers-title {
    font-size: 28px;
    font-weight: bold;
    margin: 0 0 10px 0;
    color: #333;
}

.bestsellers-updated {
    font-size: 14px;
    color: #666;
    margin: 0;
}

.bestsellers-error,
.bestsellers-empty {
    padding: 20px;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #721c24;
    text-align: center;
}

.bestsellers-empty {
    background: #fff3cd;
    border-color: #ffeaa7;
    color: #856404;
}

/* ===========================
   Grid Layout
   =========================== */

.bestsellers-grid-container {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(4, 1fr);
}

.bestsellers-grid-container[data-columns="2"] {
    grid-template-columns: repeat(2, 1fr);
}

.bestsellers-grid-container[data-columns="3"] {
    grid-template-columns: repeat(3, 1fr);
}

.bestsellers-grid-container[data-columns="5"] {
    grid-template-columns: repeat(5, 1fr);
}

.bestseller-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    transition: all 0.3s ease;
    position: relative;
    overflow: visible;
}

.bestseller-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-5px);
}

.item-position {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 10;
}

.item-cover {
    position: relative;
    text-align: center;
    margin-bottom: 15px;
}

/* Container for book cover with fixed aspect ratio */
.item-cover a {
    display: block;
    position: relative;
    width: 100%;
}

/* Book cover wrapper - maintains 2:3 aspect ratio (standard book cover) */
.item-cover {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* Modern browsers with aspect-ratio support */
@supports (aspect-ratio: 2 / 3) {
    .item-cover {
        aspect-ratio: 2 / 3;
    }
}

/* Fallback for older browsers using padding-bottom technique */
@supports not (aspect-ratio: 2 / 3) {
    .item-cover::before {
        content: "";
        display: block;
        padding-bottom: 150%; /* 3/2 = 1.5 = 150% for 2:3 ratio */
    }

    .item-cover a,
    .item-cover img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

.item-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Covers the container maintaining aspect ratio */
    object-position: center;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.item-cover a:hover img {
    transform: scale(1.05);
}

.item-cover .no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-size: 60px;
    background: #f5f5f5;
    border-radius: 4px;
    width: 100%;
    height: 100%;
    min-height: 200px; /* Fallback for browsers without aspect-ratio support */
}

.item-trend-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: white;
    padding: 6px 12px;
    border-radius: 20px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    font-size: 14px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.item-info {
    text-align: center;
}

.item-title {
    font-size: 16px;
    margin: 0 0 8px 0;
    min-height: 48px;
}

.item-title a {
    color: #333;
    text-decoration: none;
    line-height: 1.4;
}

.item-title a:hover {
    color: #2271b1;
}

.item-rubro {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: #2c6e49;
    border-radius: 3px;
    padding: 2px 6px;
    margin-bottom: 5px;
    line-height: 1.4;
}

.item-rubro.rubro-generales        { background: #2c6e49; }
.item-rubro.rubro-infantiles       { background: #e76f51; }
.item-rubro.rubro-juveniles        { background: #f4a261; color: #3a2a0a; }
.item-rubro.rubro-comics           { background: #6a4c93; }
.item-rubro.rubro-complementarios  { background: #1d7874; }
.item-rubro.rubro-textos           { background: #264653; }
.item-rubro.rubro-idiomas          { background: #0077b6; }
.item-rubro.rubro-diccionarios     { background: #5a189a; }
.item-rubro.rubro-premios          { background: #b8860b; }

.item-author {
    font-size: 13px;
    color: #666;
    margin: 0 0 5px 0;
}

.item-publisher {
    font-size: 12px;
    color: #888;
    margin: 0 0 10px 0;
    font-style: italic;
}

.item-price {
    font-size: 18px;
    font-weight: bold;
    color: #2271b1;
    margin: 10px 0;
}

.item-sales {
    font-size: 12px;
    color: #999;
    margin: 5px 0 0 0;
}

.item-actions {
    margin-top: 15px;
}

.item-actions .button {
    width: 100%;
    text-align: center;
}

/* ===========================
   List Layout (Table)
   =========================== */

.bestsellers-table-wrapper {
    overflow-x: auto;
}

.bestsellers-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.bestsellers-table thead {
    background: #f5f5f5;
}

.bestsellers-table th {
    padding: 12px;
    text-align: left;
    font-weight: bold;
    border-bottom: 2px solid #ddd;
}

.bestsellers-table td {
    padding: 12px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}

.bestsellers-table tr:hover {
    background: #f9f9f9;
}

.col-position {
    width: 60px;
    text-align: center;
}

.col-cover {
    width: 70px;
    text-align: center;
}

.col-cover img {
    width: 60px;
    height: 90px; /* 2:3 aspect ratio: 60 x 90 */
    object-fit: cover;
    object-position: center;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.col-cover .no-image {
    font-size: 30px;
}

.col-title {
    min-width: 250px;
}

.item-title-link {
    color: #333;
    text-decoration: none;
    font-weight: 500;
}

.item-title-link:hover {
    color: #2271b1;
    text-decoration: underline;
}

.col-author {
    min-width: 150px;
}

.col-publisher {
    min-width: 150px;
    font-style: italic;
    color: #888;
}

.col-sales,
.col-trend {
    width: 100px;
    text-align: center;
}

.col-price {
    width: 120px;
    text-align: right;
}

/* ===========================
   Position Badges
   =========================== */

.ranking-position {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: #666;
    color: white;
    padding: 8px 14px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 16px;
    line-height: 1;
    min-width: 40px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

.position-gold {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.position-silver {
    background: linear-gradient(135deg, #C0C0C0, #808080);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.position-bronze {
    background: linear-gradient(135deg, #CD7F32, #8B4513);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ===========================
   Trend Indicators
   =========================== */

.ranking-trend {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: bold;
}

.ranking-trend-up {
    color: #28a745;
}

.ranking-trend-down {
    color: #dc3545;
}

.ranking-trend-stable {
    color: #6c757d;
}

.ranking-trend-new {
    color: #ffc107;
}

.trend-icon {
    font-size: 18px;
}

.trend-change {
    font-size: 12px;
}

/* ===========================
   Widget Layout
   =========================== */

.bestsellers-widget {
    background: white;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.bestsellers-widget .widget-title {
    margin: 0 0 15px 0;
    font-size: 18px;
    font-weight: bold;
    border-bottom: 2px solid #2271b1;
    padding-bottom: 10px;
}

.bestsellers-widget-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.widget-item {
    border-bottom: 1px solid #eee;
    padding: 10px 0;
}

.widget-item:last-child {
    border-bottom: none;
}

.widget-item-link {
    display: flex;
    gap: 10px;
    text-decoration: none;
    color: #333;
}

.widget-item-link:hover {
    color: #2271b1;
}

.widget-item-cover {
    flex-shrink: 0;
    width: 50px;
    height: 75px; /* 2:3 aspect ratio: 50 x 75 */
    overflow: hidden;
    border-radius: 4px;
}

.widget-item-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.widget-item-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.widget-item-position {
    font-weight: bold;
    color: #2271b1;
}

.widget-item-title {
    font-weight: 500;
    font-size: 14px;
}

.widget-item-author {
    font-size: 12px;
    color: #666;
}

.widget-item-price {
    font-size: 13px;
    font-weight: bold;
    color: #2271b1;
}

/* ===========================
   Responsive Styles
   =========================== */

@media (max-width: 1200px) {
    .bestsellers-grid-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {
    .bestsellers-grid-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .bestsellers-grid-container {
        grid-template-columns: 1fr;
    }

    .bestsellers-table {
        font-size: 14px;
    }

    .bestsellers-table th,
    .bestsellers-table td {
        padding: 8px;
    }

    .col-author,
    .col-publisher,
    .col-sales {
        display: none;
    }
}

@media (max-width: 480px) {
    .bestsellers-title {
        font-size: 22px;
    }

    .item-title {
        font-size: 14px;
        min-height: auto;
    }

    .item-price {
        font-size: 16px;
    }
}

/* ============================================
   Rubros filter (chips)
   ============================================ */
.br-rubros-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 20px;
    justify-content: center;
}

.br-rubro-chip {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 999px;
    background: #F1F5F9;
    color: #475569;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .02em;
    text-decoration: none;
    transition: background .15s ease, color .15s ease, transform .1s ease;
    border: 1px solid transparent;
}

.br-rubro-chip:hover {
    background: #E2E8F0;
    color: #1E293B;
}

.br-rubro-chip.is-active {
    background: #EF5350;
    color: #ffffff;
    border-color: #EF5350;
}

.br-rubro-chip.is-active:hover {
    background: #e23d3b;
    color: #ffffff;
}

/* ============================================
   Rankings por Rubro (horizontal rows)
   ============================================ */

.br-por-rubro-wrapper {
    margin: 30px 0;
}

/* Rubro section */
.br-rubro-section {
    margin-bottom: 44px;
}

.br-rubro-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid #EF5350;
}

.br-rubro-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
}

.br-rubro-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #1E293B;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.br-rubro-count {
    font-size: 13px;
    color: #94A3B8;
    font-weight: 500;
    white-space: nowrap;
}

/* Grid layout (matches initial ranking design) */
.br-rubro-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 20px;
    padding: 8px 2px 14px;
}

/* Individual book card */
.br-rubro-card {
    min-width: 0;
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    transition: box-shadow .2s ease, transform .2s ease;
    display: flex;
    flex-direction: column;
}

.br-rubro-card:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,.13);
    transform: translateY(-4px);
}

/* Cover area — uses padding-bottom trick for guaranteed 2:3 ratio
   across all browsers and theme contexts */
.br-rubro-card-cover {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 150%;   /* 3/2 portrait ratio */
    overflow: hidden;
    background: #fff;
    border-radius: 7px 7px 0 0;
    flex-shrink: 0;
}

/* Link and image fill the entire cover — always absolute
   so they never push the overlay badges out of place.   */
.br-rubro-card-cover a,
.br-rubro-card-cover > img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
}

.br-rubro-card-cover a img,
.br-rubro-card-cover > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    transition: transform .3s ease;
}

.br-rubro-card-cover img.is-placeholder,
.br-rubro-card-cover img[src*="placeholder"] {
    object-fit: contain;
    background: #F1F5F9;
}

.br-rubro-card:hover .br-rubro-card-cover img {
    transform: scale(1.05);
}

/* Position badge — top-left, above the image */
.br-rubro-card-pos {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    line-height: 1;
}

.br-rubro-card-pos .ranking-position {
    font-size: 11px;
    padding: 3px 7px;
    min-width: 0;
    border-radius: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,.25);
}

/* Trend badge — top-right */
.br-rubro-card-trend {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 2;
    background: rgba(255,255,255,.88);
    border-radius: 20px;
    padding: 3px 6px;
    font-size: 10px;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

.br-rubro-card-trend .trend-icon {
    font-size: 10px;
}

.br-rubro-card-trend .trend-change {
    font-size: 9px;
}

/* Info area */
.br-rubro-card-info {
    padding: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.br-rubro-card-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.br-rubro-card-title a {
    color: #1E293B;
    text-decoration: none;
}

.br-rubro-card-title a:hover {
    color: #EF5350;
    text-decoration: underline;
}

.br-rubro-card-author {
    font-size: 11px;
    color: #64748B;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.br-rubro-card-price {
    font-size: 13px;
    font-weight: 700;
    color: #2271b1;
    margin-top: auto;
    padding-top: 4px;
}

/* Responsive */
@media (max-width: 1200px) {
    .br-rubro-row { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
}

@media (max-width: 900px) {
    .br-rubro-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
}

@media (max-width: 640px) {
    .br-rubro-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .br-rubro-section { margin-bottom: 32px; }
    .br-rubro-title { font-size: 17px; }
    .br-rubro-card-info { padding: 8px 8px 10px; }
    .br-rubro-card-title { font-size: 12.5px; -webkit-line-clamp: 2; }
    .br-rubro-card-author { font-size: 10.5px; }
    .br-rubro-card-price { font-size: 13px; }
    .br-rubro-card-pos .ranking-position { font-size: 10px; padding: 2px 6px; }
    .br-rubro-card-trend { font-size: 9px; padding: 2px 5px; }
}

@media (max-width: 380px) {
    .br-rubro-row { gap: 10px; }
}
