/* ==========================================================================
   TREAJA SAVED ITEMS v1.1.4
   Compact, elegant, flat design — Amazon-style density
   ========================================================================== */

:root {
    --tsi-navy:        #242f3d;
    --tsi-primary:     #446084;
    --tsi-success:     #7a9c59;
    --tsi-accent:      #f90;
    --tsi-text:        #333;
    --tsi-text-light:  #707070;
    --tsi-border:      #e8e8e8;
    --tsi-bg:          #ffffff;
    --tsi-bg-hover:    #f7f7f7;
    --tsi-compare-win: #e8f5e1;
    --tsi-transition:  0.2s ease;
    --tsi-panel-width: 380px;
}


/* ==========================================================================
   1. SAVE FOR LATER LINK
   ========================================================================== */

/* Row wrapper — single inline-flex container for all three controls.
   Without this, the parent <form class="cart"> (Flatsome renders it as a
   column flexbox with align-items: stretch) would stretch each child to
   the form's full width, breaking the icon's circle and forcing the
   "- view saved items" link onto its own row. The wrapper presents one
   flex item sized to its content, and items inside flow inline with gaps. */
.tsi-save-row {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 10px;
    margin-left: 14px;
    vertical-align: middle;
}

.tsi-save-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--tsi-text-light);
    text-decoration: none;
    cursor: pointer;
    transition: color var(--tsi-transition);
    border: none;
    background: none;
    padding: 0;
    white-space: nowrap;
    vertical-align: middle;
}

.tsi-save-link:hover { color: var(--tsi-primary); }

.tsi-save-link .tsi-save-link-icon {
    fill: none;
    transition: fill var(--tsi-transition), color var(--tsi-transition);
}

.tsi-save-link.is-saved { color: var(--tsi-primary); }
.tsi-save-link.is-saved .tsi-save-link-icon { fill: var(--tsi-primary); color: var(--tsi-primary); }


/* --- "view saved items" secondary link (only visible when item is saved) --- */
.tsi-view-saved-link {
    display: none;
    font-size: 12px;
    color: var(--tsi-primary);
    text-decoration: none;
    cursor: pointer;
    transition: color var(--tsi-transition);
    white-space: nowrap;
    vertical-align: middle;
}

/* The sibling combinator turns it on whenever the preceding save link is in
   the saved state — no extra JS state needed. */
.tsi-save-link.is-saved ~ .tsi-view-saved-link {
    display: inline-flex;
    align-items: center;
}

.tsi-view-saved-link:hover {
    color: var(--tsi-navy);
    text-decoration: underline;
}


/* --- Info tooltip (matches the shipping tooltip pattern, navy variant) --- */
.tsi-info-tooltip {
    position: relative;
    flex: 0 0 16px;          /* Lock the size so a flex parent cannot stretch it. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--tsi-navy);
    color: #fff;
    cursor: pointer;
    user-select: none;
    vertical-align: middle;
    outline: none;
    transition: opacity var(--tsi-transition);
}

.tsi-info-tooltip:hover,
.tsi-info-tooltip:focus { opacity: 0.85; }

.tsi-info-tooltip-icon {
    display: inline-block;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 11px;
    font-style: italic;
    font-weight: 700;
    line-height: 1;
    transform: translateY(-1px);
}

.tsi-info-tooltip-bubble {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    width: 280px;
    max-width: 80vw;
    padding: 12px 14px;
    background: var(--tsi-navy);
    color: #fff;
    font-size: 12px;
    font-style: normal;
    font-weight: 400;
    line-height: 1.5;
    text-align: left;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 1000;
    transition: opacity var(--tsi-transition), transform var(--tsi-transition), visibility 0s linear var(--tsi-transition);
}

.tsi-info-tooltip-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-top-color: var(--tsi-navy);
}

/* Show bubble on hover, keyboard focus, or tap-toggled .is-active state */
.tsi-info-tooltip:hover .tsi-info-tooltip-bubble,
.tsi-info-tooltip:focus .tsi-info-tooltip-bubble,
.tsi-info-tooltip.is-active .tsi-info-tooltip-bubble {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    transition: opacity var(--tsi-transition), transform var(--tsi-transition), visibility 0s;
}

/* Mobile: anchor bubble to the right side to avoid off-screen overflow */
@media (max-width: 480px) {
    .tsi-info-tooltip-bubble {
        left: auto;
        right: -8px;
        transform: translateX(0) translateY(4px);
        width: 250px;
    }
    .tsi-info-tooltip-bubble::after {
        left: auto;
        right: 12px;
        transform: none;
    }
    .tsi-info-tooltip:hover .tsi-info-tooltip-bubble,
    .tsi-info-tooltip:focus .tsi-info-tooltip-bubble,
    .tsi-info-tooltip.is-active .tsi-info-tooltip-bubble {
        transform: translateX(0) translateY(0);
    }
}


/* ==========================================================================
   2. FLOATING BUTTON
   ========================================================================== */

.tsi-floating-btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    right: 49px;
    width: 49px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tsi-navy);
    color: #fff;
    border: none;
    border-radius: 0;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: background var(--tsi-transition), transform 0.2s ease, opacity 0.3s ease, visibility 0.3s ease;
    opacity: 0;
    visibility: hidden;
}

.tsi-floating-btn.is-visible {
    opacity: 1;
    visibility: visible;
}

.tsi-floating-btn:hover {
    background: #1a2230;
    transform: translateY(-50%) scale(1.04);
}

.tsi-floating-btn .tsi-floating-btn-icon { color: #fff; stroke: #fff; }

.tsi-floating-btn .tsi-count-badge {
    position: absolute;
    top: -5px;
    left: -5px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 10px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    color: #fff;
    background: var(--tsi-accent);
    border-radius: 9px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}


/* ==========================================================================
   3. SLIDE-OUT PANEL
   ========================================================================== */

.tsi-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.tsi-panel-overlay.is-open { opacity: 1; visibility: visible; }

.tsi-panel {
    position: fixed;
    top: 0;
    right: calc(-1 * var(--tsi-panel-width) - 20px);
    width: var(--tsi-panel-width);
    max-width: 90vw;
    height: 100vh;
    background: var(--tsi-bg);
    z-index: 99999;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.12);
    transition: right 0.3s ease, width 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

/* Expand panel when compare table is visible */
.tsi-panel.is-comparing {
    width: 50vw;
    max-width: 800px;
}

.tsi-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--tsi-border);
    flex-shrink: 0;
    background: var(--tsi-bg);
}

.tsi-panel-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--tsi-text);
    margin: 0;
}

.tsi-panel-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tsi-panel-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tsi-text-light);
    padding: 0;
    transition: color var(--tsi-transition);
}

.tsi-panel-close:hover { color: var(--tsi-text); }

.tsi-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    -webkit-overflow-scrolling: touch;
}

.tsi-panel-footer {
    padding: 8px 16px;
    border-top: 1px solid var(--tsi-border);
    flex-shrink: 0;
    max-height: 60vh;
    overflow-y: auto;
}


/* ==========================================================================
   4. COMPACT ITEM CARDS (Amazon-style density)
   ========================================================================== */

.tsi-card {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--tsi-border);
    position: relative;
    align-items: flex-start;
}

.tsi-card:last-child { border-bottom: none; }

.tsi-card-thumb {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--tsi-bg-hover);
}

.tsi-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tsi-card-info {
    flex: 1;
    min-width: 0;
}

.tsi-card-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--tsi-text);
    margin: 0 0 2px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tsi-card-name a { color: inherit; text-decoration: none; }
.tsi-card-name a:hover { color: var(--tsi-primary); }

.tsi-card-price {
    font-size: 12px;
    font-weight: 600;
    color: var(--tsi-text);
    margin: 0 0 4px;
}

.tsi-card-price del { opacity: 0.5; font-weight: 400; }
.tsi-card-price ins { text-decoration: none; }

.tsi-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-bottom: 4px;
}

.tsi-card-tag {
    font-size: 10px;
    padding: 1px 6px;
    background: var(--tsi-bg-hover);
    border: 1px solid var(--tsi-border);
    color: var(--tsi-text-light);
    white-space: nowrap;
}

.tsi-card-rating {
    font-size: 11px;
    color: var(--tsi-accent);
    margin-bottom: 4px;
}

.tsi-card-rating .tsi-star-empty { color: #ddd; }

.tsi-card-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 4px;
}

.tsi-card-atc {
    font-size: 10px;
    padding: 3px 8px;
    background: transparent;
    color: var(--tsi-text-light);
    border: 1px solid var(--tsi-border);
    border-radius: 0;
    cursor: pointer;
    transition: border-color var(--tsi-transition), color var(--tsi-transition);
    white-space: nowrap;
    font-weight: 400;
    letter-spacing: 0.2px;
}

.tsi-card-atc:hover { border-color: var(--tsi-primary); color: var(--tsi-primary); }

.tsi-card-remove {
    font-size: 10px;
    padding: 3px 8px;
    background: transparent;
    border: 1px solid var(--tsi-border);
    border-radius: 0;
    cursor: pointer;
    color: var(--tsi-text-light);
    font-weight: 400;
    transition: border-color var(--tsi-transition), color var(--tsi-transition);
}

.tsi-card-remove:hover { border-color: #c33; color: #c33; }

/* Variation Selector */
.tsi-variation-selector {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    margin-top: 4px;
}

.tsi-variation-selector.is-open { max-height: 200px; }

.tsi-variation-selector select {
    width: 100%;
    padding: 4px 6px;
    font-size: 11px;
    border: 1px solid var(--tsi-border);
    border-radius: 0;
    margin-bottom: 4px;
    background: var(--tsi-bg);
    color: var(--tsi-text);
}

/* Note field */
.tsi-note-field {
    width: 100%;
    padding: 4px 6px;
    font-size: 11px;
    border: 1px solid var(--tsi-border);
    border-radius: 0;
    color: var(--tsi-text);
    background: var(--tsi-bg);
    margin-top: 4px;
    resize: none;
    height: 24px;
    transition: border-color var(--tsi-transition), height var(--tsi-transition);
}

.tsi-note-field:focus {
    outline: none;
    border-color: var(--tsi-primary);
    height: 48px;
}

.tsi-note-field::placeholder { color: #bbb; font-style: italic; }

/* Compare checkbox */
.tsi-compare-check {
    position: absolute;
    top: 10px;
    left: 0;
    width: 14px;
    height: 14px;
    accent-color: var(--tsi-primary);
    margin: 0;
}

.tsi-card.has-checkbox { padding-left: 22px; }


/* ==========================================================================
   5. CATEGORY GROUPS
   ========================================================================== */

.tsi-group { margin-bottom: 8px; }

.tsi-group-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--tsi-text);
    padding: 6px 0;
    border-bottom: 1px solid var(--tsi-border);
    margin-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}

.tsi-group-header .tsi-group-count {
    font-size: 11px;
    font-weight: 400;
    color: var(--tsi-text-light);
}

.tsi-group-header .tsi-chevron { transition: transform 0.2s ease; }
.tsi-group.is-collapsed .tsi-chevron { transform: rotate(-90deg); }

.tsi-group-items { overflow: hidden; }
.tsi-group.is-collapsed .tsi-group-items { max-height: 0 !important; }


/* ==========================================================================
   6. COMPARE TABLE
   ========================================================================== */

.tsi-compare-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 8px 0;
    border: 1px solid var(--tsi-border);
}

.tsi-compare-table {
    width: 100%;
    min-width: 350px;
    border-collapse: collapse;
    font-size: 11px;
}

.tsi-compare-table th,
.tsi-compare-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--tsi-border);
    text-align: left;
    vertical-align: top;
}

.tsi-compare-table th {
    background: var(--tsi-bg-hover);
    font-weight: 600;
    color: var(--tsi-text);
    white-space: nowrap;
    width: 80px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.tsi-compare-table tr:last-child th,
.tsi-compare-table tr:last-child td { border-bottom: none; }

.tsi-compare-table .tsi-compare-product-header {
    text-align: center;
    padding: 8px 6px;
}

.tsi-compare-table .tsi-compare-product-header img {
    width: 44px;
    height: 44px;
    object-fit: cover;
    margin-bottom: 3px;
}

.tsi-compare-table .tsi-compare-product-name {
    font-size: 10px;
    font-weight: 500;
    line-height: 1.2;
}

.tsi-compare-table .tsi-compare-product-name a {
    color: var(--tsi-text);
    text-decoration: none;
}

.tsi-compare-winner {
    background: var(--tsi-compare-win) !important;
    font-weight: 600;
}

.tsi-compare-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 5px 12px;
    background: transparent;
    color: var(--tsi-text-light);
    border: 1px solid var(--tsi-border);
    border-radius: 0;
    font-size: 10px;
    font-weight: 400;
    cursor: pointer;
    transition: border-color var(--tsi-transition), color var(--tsi-transition);
}

.tsi-compare-btn:hover { border-color: var(--tsi-primary); color: var(--tsi-primary); }
.tsi-compare-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.tsi-compare-close-btn {
    margin-top: 6px;
    border-color: var(--tsi-text-light) !important;
    color: var(--tsi-text-light) !important;
}

.tsi-compare-close-btn:hover {
    border-color: var(--tsi-text) !important;
    color: var(--tsi-text) !important;
}


/* ==========================================================================
   7. EXPORT BUTTON + TOAST
   ========================================================================== */

.tsi-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: none;
    border: 1px solid var(--tsi-border);
    border-radius: 0;
    font-size: 11px;
    color: var(--tsi-text-light);
    cursor: pointer;
    transition: all var(--tsi-transition);
    white-space: nowrap;
}

.tsi-export-btn:hover {
    border-color: var(--tsi-primary);
    color: var(--tsi-primary);
}

.tsi-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--tsi-navy);
    color: #fff;
    padding: 8px 20px;
    border-radius: 0;
    font-size: 12px;
    font-weight: 500;
    z-index: 100000;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.tsi-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}


/* ==========================================================================
   8. LOADING + EMPTY STATES
   ========================================================================== */

.tsi-skeleton {
    animation: tsi-pulse 1.5s ease-in-out infinite;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
}

@keyframes tsi-pulse {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.tsi-skeleton-card { display: flex; gap: 10px; padding: 8px 0; }
.tsi-skeleton-thumb { width: 52px; height: 52px; }
.tsi-skeleton-lines { flex: 1; }
.tsi-skeleton-line { height: 10px; margin-bottom: 6px; }
.tsi-skeleton-line:nth-child(1) { width: 80%; }
.tsi-skeleton-line:nth-child(2) { width: 50%; }
.tsi-skeleton-line:nth-child(3) { width: 30%; }

.tsi-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--tsi-text-light);
}

.tsi-empty-icon { margin-bottom: 8px; opacity: 0.25; }
.tsi-empty-title { font-size: 14px; font-weight: 500; color: var(--tsi-text); margin-bottom: 4px; }
.tsi-empty-text { font-size: 12px; line-height: 1.4; }

.tsi-empty-cta {
    display: inline-block;
    margin-top: 12px;
    padding: 6px 20px;
    background: var(--tsi-navy);
    color: #fff;
    text-decoration: none;
    font-size: 12px;
}


/* ==========================================================================
   9. RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
    .tsi-panel {
        width: 100% !important;
        max-width: 100vw !important;
        right: -100% !important;
    }

    .tsi-panel.is-open { right: 0 !important; }

    /* On mobile, compare stays full-width (no expand) */
    .tsi-panel.is-comparing {
        width: 100% !important;
        max-width: 100vw !important;
    }

    .tsi-floating-btn {
        right: 10px;
        width: 44px;
        height: 44px;
    }

    .tsi-compare-table { font-size: 10px; }
    .tsi-compare-table th { width: 65px; padding: 5px 6px; }
    .tsi-compare-table td { padding: 5px 6px; }
    .tsi-compare-table .tsi-compare-product-header img { width: 36px; height: 36px; }
    .tsi-compare-table .tsi-compare-product-name { font-size: 9px; }
}
