/**
 * Max Trade Allegro Reviews Widget Styles
 * Compact flag design. Default: LEFT side, slightly above middle.
 * Side can be switched by horizontal drag (persisted in localStorage).
 * Universally on PC & Mobile. Optimized for PrestaShop 9.0.3, touch dragging,
 * and Stacking Context.
 */

#max-trade-reviews-widget {
    font-family: 'Poppins', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    box-sizing: border-box;
}

#max-trade-reviews-widget * {
    box-sizing: border-box;
}

/* Ukrywanie niepotrzebnych elementów z wersji poziomej */
.mtr-allegro-logo,
.mtr-footer-label,
.mtr-drag-handle,
.mtr-close-btn {
    display: none !important;
}

/* Główne okienko (Badge) - Pionowa Flaga (domyślnie po LEWEJ stronie) */
.mtr-widget {
    position: fixed !important;
    z-index: 99999 !important;
    background: #ffffff !important;
    border: 1.5px solid #ff5a00 !important;
    box-shadow: 2px 2px 10px rgba(0,0,0,0.15) !important;
    
    width: 56px !important;
    height: auto !important;
    min-height: 80px !important;
    padding: 10px 5px 8px !important;
    
    /* Domyślnie: lekko powyżej środka ekranu */
    top: 38% !important;
    bottom: auto !important;
    
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    align-items: center !important;
    
    cursor: pointer !important;
    user-select: none !important;
    transition: box-shadow 0.2s ease !important;
}

/* Strona LEWA (domyślna) - przyklejone do lewej krawędzi */
.mtr-widget.mtr-left {
    left: 0 !important;
    right: auto !important;
    border-left: none !important;
    border-radius: 0 10px 10px 0 !important;
    box-shadow: 2px 2px 10px rgba(0,0,0,0.15) !important;
}

/* Strona PRAWA - przyklejone do prawej krawędzi */
.mtr-widget.mtr-right {
    right: 0 !important;
    left: auto !important;
    border-right: none !important;
    border-radius: 10px 0 0 10px !important;
    box-shadow: -2px 2px 10px rgba(0,0,0,0.15) !important;
}

.mtr-widget.mtr-left:hover {
    box-shadow: 2px 2px 12px rgba(0,0,0,0.2) !important;
}

.mtr-widget.mtr-right:hover {
    box-shadow: -2px 2px 12px rgba(0,0,0,0.2) !important;
}

.mtr-badge-content {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    height: auto !important;
    gap: 6px !important;
}

.mtr-badge-left {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    text-align: center !important;
    width: 100% !important;
    height: auto !important;
    gap: 6px !important;
}

.mtr-allegro-brand {
    display: flex !important;
    justify-content: center !important;
    width: 100% !important;
}

.mtr-allegro-logo-mini {
    display: block !important;
    height: 28px !important;
    width: auto !important;
    margin: 0 auto !important;
}

/* Gwiazdki i procenty pionowo */
.mtr-rating-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    width: 100% !important;
}

.mtr-stars {
    display: flex !important;
    color: #ffb800 !important;
    font-size: 6.5px !important; /* Bardziej kompaktowe gwiazdki wg prośby */
    gap: 0 !important;
    justify-content: center !important;
    margin-bottom: 1px !important;
    letter-spacing: -0.5px !important;
}

.mtr-star {
    line-height: 1 !important;
}

.mtr-rating-text {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0px !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    line-height: 1.1 !important;
    color: #1a1a1a !important;
}

.mtr-rating-percent {
    font-weight: 800 !important;
    font-size: 10px !important;
}

.mtr-rating-label {
    font-weight: 500 !important;
    font-size: 9.5px !important;
    color: #666666 !important;
}

.mtr-badge-right {
    display: none !important;
}

/* Panel Szczegółów (Zawsze nad widżetem) - wysuwany z tej samej strony co flaga */
.mtr-details-panel {
    position: fixed !important;
    top: 48px !important;
    bottom: 0 !important;
    height: calc(100vh - 48px) !important;
    width: 320px !important;
    max-width: 85vw !important;
    background: #ffffff !important;
    border: none !important;
    
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: flex !important;
    flex-direction: column !important;
    visibility: hidden !important;
    padding: 20px 16px !important;
    z-index: 999999 !important;
    cursor: default !important;
    user-select: text !important;
}

/* Panel po stronie PRAWEJ (gdy flaga jest po prawej) */
.mtr-widget.mtr-right .mtr-details-panel {
    right: 0 !important;
    left: auto !important;
    border-radius: 12px 0 0 12px !important;
    border-left: 1px solid #dfdfdf !important;
    box-shadow: -4px 0 25px rgba(0, 0, 0, 0.15) !important;
    transform: translateX(100%) !important;
}

/* Panel po stronie LEWEJ (gdy flaga jest po lewej) */
.mtr-widget.mtr-left .mtr-details-panel {
    left: 0 !important;
    right: auto !important;
    border-radius: 0 12px 12px 0 !important;
    border-right: 1px solid #dfdfdf !important;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.15) !important;
    transform: translateX(-100%) !important;
}

/* Poprawka dla telefonów: 100vh nie uwzględnia paska adresu przeglądarki,
   przez co dół panelu (przycisk) uciekał poza ekran. Używamy dynamicznej
   jednostki dvh z fallbackiem na vh. */
@media (max-width: 767px) {
    .mtr-details-panel {
        /* Zaczynamy pod przyklejonym topbarem (maxtradetopbar ustawia --mtb-height
           na :root z rzeczywistej wysokości paska). Fallback 50px, gdyby zmiennej nie było. */
        top: var(--mtb-height, 50px) !important;
        height: calc(100vh - var(--mtb-height, 50px)) !important;   /* fallback dla starszych przeglądarek */
        height: calc(100dvh - var(--mtb-height, 50px)) !important;  /* uwzględnia pasek adresu na telefonie */
        max-width: 92vw !important;
        border-radius: 0 !important;
    }
}

.mtr-widget.mtr-expanded .mtr-details-panel {
    transform: translateX(0) !important;
    visibility: visible !important;
}

/* Header Panelu */
.mtr-details-header {
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.mtr-details-header h4 {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 700;
    color: #111111;
}

.mtr-global-stats {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mtr-stat-badge {
    background: #28a745;
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
}

.mtr-stat-count {
    font-size: 11px;
    color: #777777;
}

/* Lista opinii */
.mtr-reviews-list {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.mtr-reviews-list::-webkit-scrollbar {
    width: 4px;
}
.mtr-reviews-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 2px;
}
.mtr-reviews-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}
.mtr-reviews-list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

.mtr-review-item {
    border-bottom: 1px solid #f3f3f3;
    padding: 10px 0;
}

.mtr-review-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.mtr-review-meta {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    margin-bottom: 3px;
}

.mtr-review-user {
    font-weight: 600;
    color: #444444;
}

.mtr-review-date {
    color: #999999;
}

.mtr-review-recommend {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 5px;
}

.mtr-recommend-positive .mtr-recommend-text {
    color: #28a745;
}

.mtr-recommend-negative .mtr-recommend-text {
    color: #dc3545;
}

.mtr-text-danger {
    color: #dc3545 !important;
}

.mtr-thumb-icon {
    display: inline-block;
    flex-shrink: 0;
}

.mtr-recommend-text {
    font-size: 11px;
    font-weight: 600;
}

.mtr-review-content {
    font-size: 12px;
    color: #555555;
    line-height: 1.4;
    word-break: break-word;
}

.mtr-read-more-link {
    display: inline;
    color: #555555;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 3px;
    text-decoration: underline;
    user-select: none;
}

.mtr-read-more-link:hover {
    color: #111111;
}

/* Znaczek obecności odpowiedzi sprzedawcy w liście opinii */
/* Znaczek obecności odpowiedzi sprzedawcy w liście opinii (Wariant 1: Czerwony w stylu Allegro) */
.mtr-seller-reply-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 4.5px 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #e21a22;
    line-height: 1.2;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 1px 2px rgba(226, 26, 34, 0.06);
    transition: all 0.15s ease;
}

.mtr-seller-reply-badge:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #c51218;
    box-shadow: 0 2px 6px rgba(226, 26, 34, 0.14);
    transform: translateY(-0.5px);
}

.mtr-seller-reply-badge .mtr-reply-icon {
    color: #e21a22;
    fill: #e21a22;
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.mtr-seller-reply-badge .mtr-reply-badge-arrow {
    font-size: 13px;
    font-weight: 700;
    color: #e21a22;
    line-height: 1;
    margin-left: 1px;
    transition: transform 0.15s ease;
}

.mtr-seller-reply-badge:hover .mtr-reply-badge-arrow {
    transform: translateX(1.5px);
}

/* Stopka Panelu */
.mtr-details-footer {
    margin-top: 12px;
    border-top: 1px solid #f0f0f0;
    padding-top: 12px;
}

.mtr-btn-allegro {
    display: block;
    width: 100%;
    background: #e21a22;
    color: #ffffff;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    padding: 9px;
    border-radius: 5px;
    text-decoration: none !important;
    transition: background 0.2s ease;
}

.mtr-btn-allegro:hover {
    background: #c51218;
    color: #ffffff;
}

/* Przycisk zamknięcia w prawym górnym rogu całego okna */
.mtr-panel-close-btn {
    display: block !important;
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    background: #ececec !important;
    border: none !important;
    width: 22px !important;
    height: 22px !important;
    border-radius: 50% !important;
    font-size: 16px !important;
    font-weight: bold !important;
    color: #555555 !important;
    line-height: 20px !important;
    text-align: center !important;
    cursor: pointer !important;
    padding: 0 !important;
    outline: none !important;
    z-index: 999999 !important;
}

.mtr-panel-close-btn:hover {
    background: #dfdfdf !important;
}

/* Ciemne tło na ekranach (Backdrop overlay) */
.mtr-mobile-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99998 !important;
    display: none;
}

/* ==========================================================================
   Modal: Pełny podgląd opinii i odpowiedź sklepu (w stylu widżetu)
   ========================================================================== */

.mtr-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 2147483646 !important;
    display: none;
    align-items: center !important;
    justify-content: center !important;
    pointer-events: none;
    visibility: hidden;
    transition: visibility 0.22s ease;
    font-family: 'Poppins', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
    box-sizing: border-box !important;
    padding: 20px !important;
}

.mtr-modal * {
    box-sizing: border-box !important;
}

.mtr-modal.mtr-modal-open {
    display: flex !important;
    pointer-events: auto !important;
    visibility: visible !important;
}

/* Tło przyciemniające (Backdrop) */
.mtr-modal-backdrop {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(15, 23, 42, 0.5) !important;
    backdrop-filter: blur(3px) !important;
    -webkit-backdrop-filter: blur(3px) !important;
    opacity: 0;
    transition: opacity 0.2s ease !important;
}

.mtr-modal.mtr-modal-open .mtr-modal-backdrop {
    opacity: 1 !important;
}

/* Okno modalne (Dialog) - powiększone do 560px na PC */
.mtr-modal-dialog {
    position: relative !important;
    z-index: 2 !important;
    width: 560px !important;
    max-width: 100% !important;
    max-height: calc(100vh - 40px) !important;
    max-height: calc(100dvh - 40px) !important;
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 14px !important;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    opacity: 0;
    transform: scale(0.96) !important;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease !important;
}

.mtr-modal.mtr-modal-open .mtr-modal-dialog {
    opacity: 1 !important;
    transform: scale(1) !important;
}

/* Header modala - równe odступы 16px 22px */
.mtr-modal-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 16px 22px !important;
    border-bottom: 1px solid #f1f5f9 !important;
    background: #ffffff !important;
}

.mtr-modal-header h4 {
    margin: 0 !important;
    font-size: 16px !important;
    font-weight: 700 !important;
    color: #0f172a !important;
    line-height: 1.2 !important;
}

.mtr-modal-close {
    background: #f1f5f9 !important;
    border: none !important;
    width: 26px !important;
    height: 26px !important;
    border-radius: 50% !important;
    font-size: 18px !important;
    font-weight: bold !important;
    color: #64748b !important;
    line-height: 24px !important;
    text-align: center !important;
    cursor: pointer !important;
    padding: 0 !important;
    outline: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background 0.15s ease, color 0.15s ease !important;
}

.mtr-modal-close:hover {
    background: #e2e8f0 !important;
    color: #0f172a !important;
}

/* Body modala - zmniejszony odstęp od góry nad kupującym (12px), równe boki 22px */
.mtr-modal-body {
    padding: 12px 22px 20px 22px !important;
    overflow-y: auto !important;
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
}

.mtr-modal-buyer-section {
    display: flex !important;
    flex-direction: column !important;
}

.mtr-modal-buyer-section .mtr-review-meta {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    font-size: 12px !important;
    margin-bottom: 6px !important;
}

.mtr-modal-buyer-section .mtr-review-user {
    font-size: 13.5px !important;
    font-weight: 700 !important;
    color: #1e293b !important;
}

.mtr-modal-buyer-section .mtr-review-date {
    font-size: 12px !important;
    color: #94a3b8 !important;
}

.mtr-modal-comment {
    font-size: 13px !important;
    color: #334155 !important;
    line-height: 1.6 !important;
    word-break: break-word !important;
    margin-top: 4px !important;
}

/* Sekcja Odpowiedzi Sprzedawcy w modalu - Wariant C (Soft Dialogue Bubble) */
.mtr-modal-seller-section {
    background: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 10px !important;
    padding: 14px 18px !important;
    margin-top: 18px !important;
}

.mtr-modal-seller-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    font-size: 12px !important;
    margin-bottom: 8px !important;
}

.mtr-modal-seller-header .mtr-seller-title {
    font-weight: 700 !important;
    color: #e21a22 !important;
    font-size: 12.5px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
}

.mtr-modal-seller-header .mtr-seller-title svg {
    fill: #e21a22 !important;
    color: #e21a22 !important;
}

.mtr-modal-seller-header .mtr-review-date {
    font-size: 11.5px !important;
    color: #94a3b8 !important;
}

.mtr-modal-seller-reply {
    font-size: 12.5px !important;
    color: #334155 !important;
    line-height: 1.6 !important;
    word-break: break-word !important;
    margin: 0 !important;
}

/* Footer modala - równe odступы 16px 22px */
.mtr-modal-footer {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    padding: 16px 22px !important;
    border-top: 1px solid #f1f5f9 !important;
    background: #ffffff !important;
}

.mtr-modal-btn-close {
    background: #f1f5f9 !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 6px !important;
    color: #334155 !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    padding: 8px 20px !important;
    cursor: pointer !important;
    outline: none !important;
    font-family: inherit !important;
    transition: all 0.15s ease !important;
}

.mtr-modal-btn-close:hover {
    background: #e2e8f0 !important;
    border-color: #cbd5e1 !important;
    color: #0f172a !important;
}

/* Responsywność dla małych ekranów - równe odступы 16px */
@media (max-width: 576px) {
    .mtr-modal {
        padding: 12px !important;
    }
    .mtr-modal-dialog {
        width: 100% !important;
        max-height: calc(100dvh - 24px) !important;
        border-radius: 12px !important;
    }
    .mtr-modal-header {
        padding: 14px 16px !important;
    }
    .mtr-modal-body {
        padding: 10px 16px 14px 16px !important;
    }
    .mtr-modal-seller-section {
        padding: 12px 14px !important;
        margin-top: 14px !important;
    }
    .mtr-modal-footer {
        padding: 14px 16px !important;
    }
    .mtr-modal-btn-close {
        width: 100% !important;
        text-align: center !important;
        padding: 10px !important;
    }
}
