/**
 * Pricetracker Frontend Styles
 */

/* CSS Variables */
:root {
    --pt-primary: #2563eb;
    --pt-primary-dark: #1d4ed8;
    --pt-success: #047857;
    --pt-warning: #f59e0b;
    --pt-error: #dc2626;
    --pt-gray-100: #f3f4f6;
    --pt-gray-200: #e5e7eb;
    --pt-gray-600: #4b5563;
    --pt-gray-800: #1f2937;
    --pt-radius: 8px;
    --pt-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --pt-card-image-overlay: rgb(139 140 142 / 5%);
    --pt-card-image-blend-mode: multiply;
    --pt-card-image-padding: 12px;
}

/* Product Grid */
.pt-grid {
    display: grid;
    gap: 20px;
}

.pt-grid--cols-2 { grid-template-columns: repeat(2, 1fr); }
.pt-grid--cols-3 { grid-template-columns: repeat(3, 1fr); }
.pt-grid--cols-4 { grid-template-columns: repeat(4, 1fr); }
.pt-grid--cols-5 { grid-template-columns: repeat(5, 1fr); }
.pt-grid--cols-6 { grid-template-columns: repeat(6, 1fr); }

@media (max-width: 1024px) {
    .pt-grid--cols-4,
    .pt-grid--cols-5,
    .pt-grid--cols-6 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .pt-grid--cols-3,
    .pt-grid--cols-4,
    .pt-grid--cols-5,
    .pt-grid--cols-6 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .pt-grid {
        grid-template-columns: 1fr;
    }
}

/* Product Card */
.pt-product-card {
    background: #fff;
    border-radius: var(--pt-radius);
    box-shadow: var(--pt-shadow);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.pt-product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.pt-product-card__link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.pt-product-card__image {
    position: relative;
    aspect-ratio: 1;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: var(--pt-card-image-padding);
}

.pt-product-card__image::after {
    content: "";
    position: absolute;
    inset: 0;
    background-color: var(--pt-card-image-overlay);
    pointer-events: none;
    z-index: 1;
}

.pt-product-card__img,
.pt-product-card__image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: relative;
    z-index: 0;
}

.pt-product-card__overlay-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.pt-product-card__favorite-btn {
    min-width: 0;
    width: 34px !important;
    height: 34px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    border: none !important;
    background: rgba(255, 255, 255, 0.92) !important;
    color: var(--pt-color-gray-500, #6b7280) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0 !important;
    transition: box-shadow 0.15s, color 0.15s !important;
}
.pt-product-card__favorite-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}
.pt-product-card__favorite-btn:hover {
    transform: none !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    border: none !important;
    color: #f43f5e !important;
}
.pt-product-card__favorite-btn.pt-favorite-btn--active {
    background: rgba(255, 255, 255, 0.98) !important;
    color: #f43f5e !important;
}
.pt-product-card__favorite-btn.pt-favorite-btn--active svg,
.pt-product-card__favorite-btn.pt-favorite-btn--active svg path {
    fill: currentColor !important;
    stroke: currentColor !important;
}

.pt-product-card__placeholder {
    color: var(--pt-gray-200);
}

.pt-product-card__placeholder .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
}

.pt-product-card__content {
    padding: 16px;
}

.pt-product-card__brand {
    display: block;
    font-size: 12px;
    color: var(--pt-gray-600);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pt-product-card__title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 8px 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.pt-product-card__price {
    margin-top: 8px;
}

.pt-product-card__price-label {
    font-size: 12px;
    color: var(--pt-gray-600);
}

.pt-product-card__price-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--pt-primary);
}

.pt-product-card__meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
}

.pt-product-card__rating {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin: 0 0 0 auto;
    min-width: 0;
}

.pt-product-card__stars {
    --pt-rating: 0;
    display: inline-block;
    width: 13px;
    height: 13px;
    vertical-align: middle;
    background: linear-gradient(
        90deg,
        #f59e0b calc(var(--pt-rating) / 5 * 100%),
        #e5e7eb calc(var(--pt-rating) / 5 * 100%)
    );
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    flex-shrink: 0;
    margin-bottom: -3px;
}

.pt-product-card__rating-count {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--pt-gray-600);
    white-space: nowrap;
}

.pt-product-card__stores {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    color: var(--pt-gray-600);
    margin-top: 0;
    white-space: nowrap;
}

.pt-product-card__stores--empty {
    visibility: hidden;
}

/* Single Product */
.pt-single-product {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.pt-product__container {
    background: #fff;
    border-radius: var(--pt-radius);
    padding: 24px;
}

.pt-product__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 24px;
}

.pt-product__header-main {
    flex: 1;
}

.pt-product__header-actions {
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .pt-product__header {
        flex-direction: column;
    }
    
    .pt-product__header-actions {
        order: -1;
        align-self: flex-end;
    }
}

.pt-product__brand {
    display: inline-block;
    font-size: 14px;
    color: var(--pt-gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.pt-product__title {
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.pt-product__ean {
    font-size: 12px;
    color: var(--pt-gray-600);
}

.pt-product__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 40px;
}

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

.pt-product__image {
    background: var(--pt-gray-100);
    border-radius: var(--pt-radius);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pt-product__img {
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
}

.pt-product__price-summary {
    background: linear-gradient(135deg, var(--pt-primary) 0%, var(--pt-primary-dark) 100%);
    color: #fff;
    padding: 20px;
    border-radius: var(--pt-radius);
    margin-bottom: 20px;
}

.pt-product__best-price {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.pt-product__price-label {
    font-size: 14px;
    opacity: 0.9;
}

.pt-product__price-value {
    font-size: 32px;
    font-weight: 700;
}

.pt-product__store-count {
    font-size: 14px;
    opacity: 0.9;
    margin-top: 8px;
}

.pt-product__categories {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.pt-product__category {
    display: inline-block;
    padding: 4px 12px;
    background: var(--pt-gray-100);
    border-radius: 20px;
    font-size: 13px;
    text-decoration: none;
    color: var(--pt-gray-600);
    transition: background 0.2s;
}

.pt-product__category:hover {
    background: var(--pt-gray-200);
}

/* Price List */
.pt-price-list {
    margin: 20px 0;
}

.pt-price-list__table {
    width: 100%;
    border-collapse: collapse;
}

.pt-price-list__th {
    text-align: left;
    padding: 12px;
    background: var(--pt-gray-100);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pt-price-list__td {
    padding: 16px 12px;
    border-bottom: 1px solid var(--pt-gray-200);
    vertical-align: middle;
}

.pt-price-list__row--best {
    background: #eff6ff;
}

.pt-price-list__logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    margin-right: 12px;
    vertical-align: middle;
}

.pt-price-list__merchant-name {
    font-weight: 500;
}

.pt-price-list__badge {
    display: inline-block;
    background: var(--pt-success);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
    text-transform: uppercase;
}

.pt-price-list__price {
    font-size: 18px;
    font-weight: 600;
}

.pt-price-list__price--best {
    color: var(--pt-success);
}

.pt-price-list__currency {
    font-size: 14px;
    font-weight: 400;
}

.pt-price-list__stock {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}

.pt-price-list__stock--in {
    color: var(--pt-success);
}

.pt-price-list__stock--out {
    color: var(--pt-gray-600);
}

.pt-price-list__btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: var(--pt-primary);
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s;
}

.pt-price-list__btn:hover {
    background: var(--pt-primary-dark);
    color: #fff;
}

.pt-price-list__btn--primary {
    background: var(--pt-success);
}

.pt-price-list__btn--primary:hover {
    background: #065f46;
}

/* Price History */
.pt-price-history {
    margin: 20px 0;
}

.pt-price-history__chart {
    min-height: 300px;
    background: var(--pt-gray-100);
    border-radius: var(--pt-radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pt-price-history__loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--pt-gray-600);
}

.pt-price-history__summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: 16px;
}

.pt-price-history__stat {
    background: var(--pt-gray-100);
    padding: 16px;
    border-radius: var(--pt-radius);
    text-align: center;
}

.pt-price-history__stat-label {
    display: block;
    font-size: 12px;
    color: var(--pt-gray-600);
    margin-bottom: 4px;
}

.pt-price-history__stat-value {
    font-size: 20px;
    font-weight: 700;
}

/* Price Alert Form */
.pt-price-alert {
    background: linear-gradient(135deg, #fffbeb 0%, #fff 100%);
    border: 2px solid #fde68a;
    border-radius: var(--pt-radius);
    padding: 24px;
    margin: 20px 0;
}

.pt-price-alert__intro {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.pt-price-alert__intro .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
    color: #f59e0b;
}

.pt-price-alert__intro p {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.pt-price-alert__fields {
    display: grid;
    gap: 16px;
}

.pt-price-alert__label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
}

.pt-price-alert__optional {
    font-weight: 400;
    color: var(--pt-gray-600);
}

.pt-price-alert__input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--pt-gray-200);
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.2s;
}

.pt-price-alert__input:focus {
    outline: none;
    border-color: var(--pt-primary);
}

.pt-price-alert__input-group {
    display: flex;
    align-items: center;
}

.pt-price-alert__input-group .pt-price-alert__input {
    border-radius: 6px 0 0 6px;
}

.pt-price-alert__suffix {
    padding: 12px 16px;
    background: var(--pt-gray-100);
    border: 1px solid var(--pt-gray-200);
    border-left: none;
    border-radius: 0 6px 6px 0;
    font-weight: 600;
}

.pt-price-alert__hint {
    font-size: 13px;
    color: var(--pt-gray-600);
    margin-top: 4px;
}

.pt-price-alert__actions {
    margin-top: 16px;
}

.pt-price-alert__submit {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.pt-price-alert__submit:hover {
    background: #1d4ed8;
}

.pt-price-alert__submit .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

.pt-price-alert__terms {
    font-size: 12px;
    color: var(--pt-gray-600);
    margin-top: 12px;
}

.pt-price-alert__message {
    padding: 16px;
    border-radius: 6px;
    margin-top: 16px;
}

.pt-price-alert__message--success {
    background: #ecfdf5;
    color: #047857;
}

.pt-price-alert__message--error {
    background: #fef2f2;
    color: #dc2626;
}

/* Archive & Category */
.pt-archive,
.pt-category {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.pt-archive__header,
.pt-category__header {
    margin-bottom: 32px;
}

.pt-archive__title,
.pt-category__title {
    font-size: 32px;
    font-weight: 700;
    margin: 0 0 12px 0;
}

.pt-archive__description,
.pt-category__description {
    color: var(--pt-gray-600);
    max-width: 800px;
}

.pt-category__meta {
    font-size: 14px;
    color: var(--pt-gray-600);
    margin-top: 8px;
}

.pt-subcategory-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.pt-subcategory-item {
    display: inline-block;
    padding: 8px 16px;
    background: var(--pt-gray-100);
    border-radius: 20px;
    text-decoration: none;
    color: var(--pt-gray-800);
    font-weight: 500;
    transition: background 0.2s;
}

.pt-subcategory-item:hover {
    background: var(--pt-primary);
    color: #fff;
}

.pt-subcategory-item__count {
    font-weight: 400;
    color: var(--pt-gray-600);
}

.pt-subcategory-item:hover .pt-subcategory-item__count {
    color: rgba(255, 255, 255, 0.8);
}

/* Pagination */
.pt-archive__pagination,
.pt-category__pagination {
    margin-top: 40px;
    text-align: center;
}

.pt-archive__pagination .page-numbers,
.pt-category__pagination .page-numbers {
    display: inline-block;
    padding: 8px 14px;
    margin: 0 2px;
    background: var(--pt-gray-100);
    border-radius: 4px;
    text-decoration: none;
    color: var(--pt-gray-800);
}

.pt-archive__pagination .page-numbers.current,
.pt-category__pagination .page-numbers.current {
    background: var(--pt-primary);
    color: #fff;
}

/* Errors */
.pt-error {
    padding: 16px;
    background: #fef2f2;
    color: #dc2626;
    border-radius: var(--pt-radius);
}

/* Empty states */
.pt-grid--empty,
.pt-archive__empty,
.pt-category__empty {
    text-align: center;
    padding: 40px;
    color: var(--pt-gray-600);
}

/* Sections */
.pt-product__offers,
.pt-product__history,
.pt-product__alert,
.pt-product__content {
    margin-top: 40px;
    padding-top: 40px;
    border-top: 1px solid var(--pt-gray-200);
}

.pt-product__offers h2,
.pt-product__history h2,
.pt-product__alert h2,
.pt-product__content h2 {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 20px 0;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .pt-price-list__table,
    .pt-price-list__thead,
    .pt-price-list__tbody,
    .pt-price-list__th,
    .pt-price-list__td,
    .pt-price-list__row {
        display: block;
    }
    
    .pt-price-list__thead {
        display: none;
    }
    
    .pt-price-list__row {
        padding: 16px;
        margin-bottom: 8px;
        border: 1px solid var(--pt-gray-200);
        border-radius: var(--pt-radius);
    }
    
    .pt-price-list__td {
        padding: 8px 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .pt-price-list__td--merchant {
        justify-content: flex-start;
        font-weight: 600;
    }
    
    .pt-price-list__td--action {
        margin-top: 8px;
    }
    
    .pt-price-list__btn {
        width: 100%;
        justify-content: center;
    }
    
    .pt-price-history__summary {
        grid-template-columns: 1fr;
    }
}

/* Favorite Button */
.pt-favorite-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: #fff;
    color: var(--pt-gray-600, #4b5563);
    border: 2px solid var(--pt-gray-200, #e5e7eb);
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.pt-favorite-btn:hover {
    border-color: #f43f5e;
    color: #f43f5e;
}

.pt-favorite-btn--active {
    background: #fff1f2;
    border-color: #f43f5e;
    color: #f43f5e;
}

.pt-favorite-btn .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
    transition: transform 0.2s;
}

.pt-favorite-btn:hover .dashicons {
    transform: scale(1.1);
}

.pt-favorite-btn--active .dashicons::before {
    content: "\f487"; /* Filled heart */
}

/* Global favorite tooltip (rendered in <body> by frontend.js) */
#pt-favorite-tooltip.pt-favorite-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2147483000;
    max-width: min(280px, calc(100vw - 16px));
    padding: 8px 12px;
    border-radius: 12px;
    background: #fff;
    color: #1f2937;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate3d(0, 0, 0);
    transition: opacity 0.14s ease, visibility 0.14s ease;
}

#pt-favorite-tooltip.pt-favorite-tooltip.is-visible {
    opacity: 1;
    visibility: visible;
}

/*
 * Multi-line variant for longer explanatory tooltips (e.g. the deals-badge
 * info icon, which surfaces a sentence about how price trends are computed).
 * Favorite/basket buttons stay nowrap; only opt-ins via data-tooltip-multiline
 * activate this.
 *
 * Uses !important on the layout props because they have to win against the
 * base #pt-favorite-tooltip selector which sets nowrap + a wider max-width.
 * Without !important the override sometimes loses due to cascade-order in
 * minified bundles and the tooltip stretches the full viewport width.
 */
#pt-favorite-tooltip.pt-favorite-tooltip.pt-favorite-tooltip--wrap {
    white-space: normal !important;
    max-width: min(260px, calc(100vw - 16px)) !important;
    width: max-content !important;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
}

/* Price alert form - readonly state */
.pt-price-alert__field--readonly input[readonly] {
    background: var(--pt-gray-100, #f3f4f6);
    color: var(--pt-gray-600, #4b5563);
    cursor: default;
}

.pt-price-alert__field--readonly .pt-price-alert__hint {
    margin-top: 8px;
}

.pt-price-alert__field--readonly .pt-price-alert__hint a {
    color: var(--pt-primary, #2563eb);
    text-decoration: none;
}

.pt-price-alert__field--readonly .pt-price-alert__hint a:hover {
    text-decoration: underline;
}
