/**
 * MadevTools SmartSearch & Recommendations
 * Styling for Gatzagen.com / Falcon theme
 *
 * Color scheme:
 *   Primary: #004DA6 (blue)
 *   Secondary: #2770c4 (lighter blue - hover)
 *   Text: #2d3436
 *   Muted: #636e72
 *   Border: #e8e8e8
 *   Background: #f8f9fa
 */

/* =========================================================================
   CSS CUSTOM PROPERTIES
   ========================================================================= */

:root {
    --madev-primary: #004DA6;
    --madev-primary-hover: #2770c4;
    --madev-primary-light: rgba(0, 77, 166, 0.08);
    --madev-text: #2d3436;
    --madev-text-muted: #636e72;
    --madev-border: #e8e8e8;
    --madev-bg: #ffffff;
    --madev-bg-soft: #f8f9fa;
    --madev-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    --madev-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --madev-radius: 6px;
    --madev-radius-lg: 10px;
    --madev-transition: 0.2s ease;
}

/* =========================================================================
   SEARCH BAR
   ========================================================================= */

/*
 * Initially hidden to prevent flash of misplaced content.
 * JS moves the wrapper into the theme search container and then shows it.
 */
.madev-search-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    z-index: 1000;
    display: none;
}

.madev-search-wrapper.is-mounted {
    display: block;
}

.madev-search-form {
    width: 100%;
}

.madev-search-input-group {
    display: flex;
    align-items: center;
    background: var(--madev-bg);
    border: 2px solid var(--madev-border);
    border-radius: var(--madev-radius);
    overflow: hidden;
    transition: border-color var(--madev-transition), box-shadow var(--madev-transition);
}

.madev-search-input-group:focus-within {
    border-color: var(--madev-primary);
    box-shadow: 0 0 0 3px var(--madev-primary-light);
}

.madev-search-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px 14px;
    font-size: 15px;
    color: var(--madev-text);
    background: transparent;
    font-family: inherit;
}

.madev-search-input::placeholder {
    color: #b2bec3;
}

.madev-search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--madev-text-muted);
    cursor: pointer;
    transition: color var(--madev-transition);
    flex-shrink: 0;
}

.madev-search-btn:hover {
    color: var(--madev-primary);
}

/* =========================================================================
   SEARCH DROPDOWN
   ========================================================================= */

.madev-search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--madev-bg);
    border-radius: 0 0 var(--madev-radius-lg) var(--madev-radius-lg);
    box-shadow: var(--madev-shadow);
    border: 1px solid var(--madev-border);
    border-top: none;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease, visibility 0.2s ease;
    z-index: 1001;
}

.madev-search-dropdown.is-open {
    max-height: 500px;
    overflow-y: auto;
    opacity: 1;
    visibility: visible;
}

/* Loading state */
.madev-search-loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px;
    color: var(--madev-text-muted);
    font-size: 14px;
}

.madev-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--madev-border);
    border-top-color: var(--madev-primary);
    border-radius: 50%;
    animation: madev-spin 0.6s linear infinite;
}

@keyframes madev-spin {
    to { transform: rotate(360deg); }
}

/* Search result items */
.madev-search-item {
    border-bottom: 1px solid var(--madev-border);
    transition: background var(--madev-transition);
}

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

.madev-search-item:hover,
.madev-search-item.active {
    background: var(--madev-bg-soft);
}

.madev-search-item-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    text-decoration: none;
    color: inherit;
}

.madev-search-item-image {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    background: var(--madev-bg-soft);
    display: flex;
    align-items: center;
    justify-content: center;
}

.madev-search-item-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.madev-search-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.madev-search-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--madev-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.madev-search-item-name mark {
    background: var(--madev-primary-light);
    color: var(--madev-primary-hover);
    padding: 0 1px;
    border-radius: 2px;
    font-weight: 600;
}

.madev-search-item-brand {
    font-size: 12px;
    color: var(--madev-text-muted);
}

/* Price + stock row in search dropdown */
.madev-search-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.madev-search-item-price {
    font-size: 13px;
    font-weight: 600;
    color: var(--madev-primary);
}

.madev-search-item-price small,
.madev-search-item-price-excl small {
    font-weight: 400;
    font-size: 10px;
    color: var(--madev-text-muted);
}

.madev-search-item-price-excl {
    font-size: 11px;
    color: var(--madev-text-muted);
}

/* Stock badge in search dropdown */
.madev-search-item-stock {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: auto;
    white-space: nowrap;
}

.madev-stock-badge--in {
    background: var(--madev-primary);
    color: #fff;
}

.madev-stock-badge--backorder {
    background: #f0932b;
    color: #fff;
}

.madev-stock-badge--out {
    background: #f1f2f3;
    color: #e74c3c;
}

/* Stock indicators in cards (recommendations + search results page) */
.madev-stock {
    font-size: 11px;
    font-weight: 500;
}

.madev-stock--in {
    color: var(--madev-primary);
}

.madev-stock--backorder {
    color: #f0932b;
}

.madev-stock--out {
    color: #e74c3c;
}

.madev-product-card-stock,
.madev-rec-card-stock {
    padding: 0 12px 4px;
}

.madev-rec-card-stock {
    padding: 0 10px 4px;
}

/* No results */
.madev-search-no-results {
    display: none;
    padding: 24px;
    text-align: center;
    color: var(--madev-text-muted);
    font-size: 14px;
}

.madev-search-no-results p {
    margin: 0;
}

/* View all footer */
.madev-search-footer {
    display: none;
    border-top: 1px solid var(--madev-border);
}

.madev-search-view-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--madev-primary);
    text-decoration: none;
    transition: background var(--madev-transition);
}

.madev-search-view-all:hover {
    background: var(--madev-primary-light);
    color: var(--madev-primary-hover);
}

#madev-search-count {
    font-weight: 400;
    color: var(--madev-text-muted);
}

/* =========================================================================
   SEARCH RESULTS PAGE
   ========================================================================= */

.madev-search-page {
    padding: 20px 0;
}

.madev-search-page-bar {
    margin-bottom: 20px;
}

.madev-search-page-form {
    display: flex;
    gap: 8px;
    max-width: 600px;
}

.madev-search-page-input {
    flex: 1;
    padding: 10px 16px;
    border: 2px solid var(--madev-border);
    border-radius: var(--madev-radius);
    font-size: 15px;
    color: var(--madev-text);
    outline: none;
    transition: border-color var(--madev-transition);
}

.madev-search-page-input:focus {
    border-color: var(--madev-primary);
}

.madev-search-page-submit {
    padding: 10px 24px;
    background: var(--madev-primary);
    color: white;
    border: none;
    border-radius: var(--madev-radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--madev-transition);
}

.madev-search-page-submit:hover {
    background: var(--madev-primary-hover);
}

.madev-search-page-count {
    font-size: 14px;
    color: var(--madev-text-muted);
    margin-bottom: 20px;
}

/* Product grid */
.madev-search-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.madev-product-card {
    background: var(--madev-bg);
    border: 1px solid var(--madev-border);
    border-radius: var(--madev-radius);
    overflow: hidden;
    transition: box-shadow var(--madev-transition), transform var(--madev-transition);
}

.madev-product-card:hover {
    box-shadow: var(--madev-shadow-sm);
    transform: translateY(-2px);
}

.madev-product-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.madev-product-card-image {
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--madev-bg-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

.madev-product-card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.madev-product-card:hover .madev-product-card-image img {
    transform: scale(1.05);
}

.madev-product-no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.madev-product-card-info {
    padding: 12px;
}

.madev-product-card-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--madev-text);
    margin: 0 0 8px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.madev-product-card-prices {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.madev-price-incl {
    font-size: 15px;
    font-weight: 700;
    color: var(--madev-text);
}

.madev-price-incl small,
.madev-price-excl small {
    font-weight: 400;
    font-size: 11px;
    color: var(--madev-text-muted);
}

.madev-price-excl {
    font-size: 12px;
    color: var(--madev-text-muted);
}

.madev-product-card-actions {
    padding: 0 12px 12px;
}

.madev-add-cart-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    background: var(--madev-primary);
    color: white;
    border: none;
    border-radius: var(--madev-radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--madev-transition);
}

.madev-add-cart-btn:hover {
    background: var(--madev-primary-hover);
}

.madev-add-cart-btn.is-loading {
    opacity: 0.6;
    pointer-events: none;
}

.madev-out-of-stock {
    display: block;
    text-align: center;
    font-size: 12px;
    color: var(--madev-text-muted);
    padding: 8px;
}

/* Search empty state */
.madev-search-empty {
    text-align: center;
    padding: 60px 20px;
}

.madev-search-empty h3 {
    margin: 16px 0 8px;
    color: var(--madev-text);
}

.madev-search-empty p {
    color: var(--madev-text-muted);
    font-size: 14px;
}

/* Pagination */
.madev-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 32px;
}

.madev-page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: var(--madev-radius);
    font-size: 14px;
    font-weight: 500;
    color: var(--madev-text);
    text-decoration: none;
    transition: background var(--madev-transition), color var(--madev-transition);
}

.madev-page-link:hover {
    background: var(--madev-bg-soft);
}

.madev-page-current {
    background: var(--madev-primary);
    color: white;
}

.madev-page-current:hover {
    background: var(--madev-primary-hover);
    color: white;
}

/* =========================================================================
   RECOMMENDATION SECTIONS
   ========================================================================= */

.madev-recommendations {
    margin: 32px 0;
}

.madev-rec-section {
    margin-bottom: 32px;
}

.madev-rec-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--madev-border);
}

.madev-rec-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--madev-text);
    margin: 0;
}

.madev-rec-nav {
    display: flex;
    gap: 6px;
}

.madev-rec-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--madev-border);
    border-radius: 50%;
    background: var(--madev-bg);
    color: var(--madev-text);
    cursor: pointer;
    transition: all var(--madev-transition);
}

.madev-rec-nav-btn:hover {
    border-color: var(--madev-primary);
    color: var(--madev-primary);
    background: var(--madev-primary-light);
}

/* Carousel track */
.madev-rec-track-container {
    overflow: hidden;
    position: relative;
}

.madev-rec-track {
    display: flex;
    gap: 14px;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

/* Product cards in recommendations */
.madev-rec-card {
    flex: 0 0 auto;
    width: 200px;
    background: var(--madev-bg);
    border: 1px solid var(--madev-border);
    border-radius: var(--madev-radius);
    overflow: hidden;
    transition: box-shadow var(--madev-transition), transform var(--madev-transition);
}

.madev-rec-card:hover {
    box-shadow: var(--madev-shadow-sm);
    transform: translateY(-2px);
}

.madev-rec-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.madev-rec-card-image {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--madev-bg-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.madev-rec-card-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.madev-rec-card:hover .madev-rec-card-image img {
    transform: scale(1.05);
}

.madev-rec-no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.madev-rec-card-info {
    padding: 10px;
}

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

.madev-rec-card-prices {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.madev-rec-price-incl {
    font-size: 14px;
    font-weight: 700;
    color: var(--madev-text);
}

.madev-rec-price-incl small,
.madev-rec-price-excl small {
    font-weight: 400;
    font-size: 10px;
    color: var(--madev-text-muted);
}

.madev-rec-price-excl {
    font-size: 11px;
    color: var(--madev-text-muted);
}

/* Add to cart button in recommendations */
.madev-rec-card-actions {
    padding: 0 10px 10px;
}

.madev-rec-add-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    padding: 7px 8px;
    background: var(--madev-primary);
    color: white;
    border: none;
    border-radius: var(--madev-radius);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--madev-transition);
}

.madev-rec-add-cart:hover {
    background: var(--madev-primary-hover);
}

.madev-rec-add-cart.is-loading {
    opacity: 0.6;
    pointer-events: none;
}

.madev-rec-out-of-stock {
    display: block;
    text-align: center;
    font-size: 11px;
    color: var(--madev-text-muted);
    padding: 7px;
}

/* =========================================================================
   POWERSTEP POPUP
   ========================================================================= */

.madev-powerstep-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    backdrop-filter: blur(2px);
}

.madev-powerstep-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.madev-powerstep-modal {
    background: var(--madev-bg);
    border-radius: var(--madev-radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    max-width: 560px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
    transform: translateY(20px) scale(0.97);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.madev-powerstep-overlay.is-open .madev-powerstep-modal {
    transform: translateY(0) scale(1);
}

.madev-powerstep-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--madev-bg-soft);
    border-radius: 50%;
    color: var(--madev-text-muted);
    cursor: pointer;
    transition: all var(--madev-transition);
    z-index: 1;
}

.madev-powerstep-close:hover {
    background: var(--madev-border);
    color: var(--madev-text);
}

/* Powerstep header */
.madev-powerstep-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--madev-border);
    margin-bottom: 18px;
}

.madev-powerstep-check {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--madev-primary-light);
    border-radius: 50%;
    color: var(--madev-primary);
}

.madev-powerstep-header-text {
    flex: 1;
    min-width: 0;
}

.madev-powerstep-header-text h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--madev-text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.madev-powerstep-header-text p {
    font-size: 13px;
    color: var(--madev-primary);
    margin: 2px 0 0;
    font-weight: 500;
}

.madev-powerstep-product-thumb {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: var(--madev-radius);
    overflow: hidden;
    background: var(--madev-bg-soft);
}

.madev-powerstep-product-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Action buttons */
.madev-powerstep-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.madev-powerstep-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 16px;
    border-radius: var(--madev-radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--madev-transition);
    border: none;
}

.madev-powerstep-continue {
    background: var(--madev-bg-soft);
    color: var(--madev-text);
    border: 1px solid var(--madev-border);
}

.madev-powerstep-continue:hover {
    background: var(--madev-border);
}

.madev-powerstep-cart {
    background: var(--madev-primary);
    color: white;
}

.madev-powerstep-cart:hover {
    background: var(--madev-primary-hover);
    color: white;
}

/* Powerstep recommendations */
.madev-powerstep-recommendations {
    display: none;
}

.madev-powerstep-recommendations h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--madev-text);
    margin: 0 0 12px;
    padding-top: 16px;
    border-top: 1px solid var(--madev-border);
}

.madev-powerstep-products {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
}

.madev-powerstep-product {
    text-align: center;
}

.madev-powerstep-product a {
    display: block;
    text-decoration: none;
    color: inherit;
    padding: 8px;
    border: 1px solid var(--madev-border);
    border-radius: var(--madev-radius);
    transition: box-shadow var(--madev-transition);
}

.madev-powerstep-product a:hover {
    box-shadow: var(--madev-shadow-sm);
}

.madev-powerstep-product img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin: 0 auto 6px;
    display: block;
}

.madev-ps-product-name {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--madev-text);
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.madev-ps-product-price {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--madev-primary);
}

/* =========================================================================
   RESPONSIVE DESIGN
   ========================================================================= */

@media (max-width: 768px) {
    .madev-search-wrapper {
        max-width: 100%;
    }

    .madev-search-input {
        font-size: 16px; /* Prevent iOS zoom */
        padding: 12px 14px;
    }

    .madev-rec-card {
        width: 160px;
    }

    .madev-rec-title {
        font-size: 16px;
    }

    .madev-search-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .madev-powerstep-modal {
        width: 95%;
        padding: 18px;
    }

    .madev-powerstep-actions {
        flex-direction: column;
    }

    .madev-powerstep-products {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

    .madev-rec-card {
        width: 140px;
    }

    .madev-rec-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .madev-powerstep-header {
        flex-wrap: wrap;
    }

    .madev-powerstep-product-thumb {
        display: none;
    }
}

/* =========================================================================
   HOMEPAGE LAYOUT FIX
   Prevent the left sidebar from stretching the content area,
   creating a large white gap between recommendations and footer.
   ========================================================================= */

.page-home #wrapper .row {
    align-items: flex-start !important;
}

.page-home .js-content-wrapper {
    min-height: auto !important;
}

/* =========================================================================
   STYLING ACCENTS
   ========================================================================= */

/* Section title accent bar */
.madev-rec-title::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 1em;
    background: var(--madev-primary);
    border-radius: 2px;
    margin-right: 10px;
    vertical-align: middle;
}

/* Tool-themed empty search icon (wrench) */
.madev-search-empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: var(--madev-primary-light);
    border-radius: 50%;
    color: var(--madev-primary);
    margin-bottom: 8px;
}

/* Branded search input focus glow */
.madev-search-input-group:focus-within {
    border-color: var(--madev-primary);
    box-shadow: 0 0 0 3px var(--madev-primary-light),
                0 2px 8px rgba(0, 77, 166, 0.08);
}

/* Branded add-to-cart hover effect */
.madev-add-cart-btn:hover,
.madev-rec-add-cart:hover {
    box-shadow: 0 2px 8px rgba(0, 77, 166, 0.25);
}

/* Card top accent on hover */
.madev-product-card:hover,
.madev-rec-card:hover {
    border-top-color: var(--madev-primary);
}

/* =========================================================================
   PRINT STYLES
   ========================================================================= */

@media print {
    .madev-search-wrapper,
    .madev-powerstep-overlay,
    .madev-rec-nav {
        display: none !important;
    }
}
