/* ============================================================
   OTM Smart Search — Stylesheet
   Off Trail Market — Outdoor / Adventure aesthetic
   ============================================================ */

/* ── CSS Variables ───────────────────────────────────────── */
:root {
    --otm-search-radius:    8px;
    --otm-search-height:    44px;
    --otm-search-bg:        #ffffff;
    --otm-search-border:    #d1d5db;
    --otm-search-border-focus: #1a6bb5;
    --otm-search-shadow-focus: 0 0 0 3px rgba(26, 107, 181, 0.18);
    --otm-search-text:      #1a1a1a;
    --otm-search-placeholder: #9ca3af;
    --otm-search-icon:      #6b7280;

    --otm-dd-bg:            #ffffff;
    --otm-dd-border:        #e5e7eb;
    --otm-dd-shadow:        0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
    --otm-dd-radius:        10px;
    --otm-dd-max-height:    520px;

    --otm-label-color:      #9ca3af;
    --otm-label-size:       10px;

    --otm-item-hover:       #f3f6fa;
    --otm-item-active:      #ebf2fb;
    --otm-item-radius:      6px;

    --otm-sale-bg:          #dc2626;
    --otm-sale-color:       #ffffff;

    --otm-mark-bg:          #fff3cd;
    --otm-mark-color:       #1a1a1a;

    --otm-accent:           #1a6bb5;
    --otm-accent-light:     #ebf2fb;

    --otm-font:             inherit;
    --otm-transition:       0.18s ease;
}

/* ── Wrapper — full width ────────────────────────────────── */
.otm-search-wrap {
    position:   relative;
    width:      100%;
    max-width:  100%;
    font-family: var( --otm-font );
    box-sizing: border-box;
}

/* ── Inner bar ───────────────────────────────────────────── */
.otm-search-inner {
    display:        flex;
    align-items:    center;
    gap:            0;
    background:     var( --otm-search-bg );
    border:         1.5px solid var( --otm-search-border );
    border-radius:  var( --otm-search-radius );
    height:         var( --otm-search-height );
    padding:        0 12px 0 10px;
    transition:     border-color var( --otm-transition ),
                    box-shadow   var( --otm-transition );
    box-sizing:     border-box;
}

.otm-search-wrap:focus-within .otm-search-inner,
.otm-search-wrap.otm-search--open .otm-search-inner {
    border-color: var( --otm-search-border-focus );
    box-shadow:   var( --otm-search-shadow-focus );
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
}

/* ── Search icon ─────────────────────────────────────────── */
.otm-search-icon {
    display:     flex;
    align-items: center;
    flex-shrink: 0;
    color:       var( --otm-search-icon );
    padding-right: 8px;
    transition:  color var( --otm-transition );
}

.otm-search-wrap:focus-within .otm-search-icon {
    color: var( --otm-accent );
}

/* ── Input ───────────────────────────────────────────────── */
.otm-search-input {
    flex:           1;
    border:         none;
    outline:        none;
    background:     transparent;
    font-size:      14px;
    font-family:    inherit;
    color:          var( --otm-search-text );
    height:         100%;
    min-width:      0;
    padding:        0;
    -webkit-appearance: none;
    appearance:     none;
}

.otm-search-input::placeholder {
    color: var( --otm-search-placeholder );
}

/* Remove native search clear button */
.otm-search-input::-webkit-search-decoration,
.otm-search-input::-webkit-search-cancel-button,
.otm-search-input::-webkit-search-results-button,
.otm-search-input::-webkit-search-results-decoration {
    display: none;
}

/* ── Clear button ────────────────────────────────────────── */
.otm-search-clear {
    display:        flex;
    align-items:    center;
    justify-content: center;
    flex-shrink:    0;
    background:     none;
    border:         none;
    cursor:         pointer;
    color:          var( --otm-search-icon );
    padding:        4px;
    border-radius:  50%;
    margin-left:    4px;
    transition:     color var( --otm-transition ), background var( --otm-transition );
}

.otm-search-clear:hover {
    color:       var( --otm-accent );
    background:  var( --otm-accent-light );
}

/* ── Spinner ─────────────────────────────────────────────── */
.otm-search-spinner {
    flex-shrink:  0;
    width:        16px;
    height:       16px;
    border:       2px solid #e5e7eb;
    border-top-color: var( --otm-accent );
    border-radius: 50%;
    margin-left:  6px;
    animation:    otm-spin 0.65s linear infinite;
}

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

/* ── Dropdown ────────────────────────────────────────────── */
.otm-search-dropdown {
    position:           absolute;
    top:                calc( var( --otm-search-height ) - 1.5px );
    left:               0;
    right:              0;
    z-index:            99999;
    background:         var( --otm-dd-bg );
    border:             1.5px solid var( --otm-search-border-focus );
    border-top:         none;
    border-radius:      0 0 var( --otm-dd-radius ) var( --otm-dd-radius );
    box-shadow:         var( --otm-dd-shadow );
    max-height:         var( --otm-dd-max-height );
    overflow-y:         auto;
    overflow-x:         hidden;
    -webkit-overflow-scrolling: touch;

    /* Animate in */
    animation: otm-dd-in 0.15s ease both;
}

@keyframes otm-dd-in {
    from { opacity: 0; transform: translateY( -6px ); }
    to   { opacity: 1; transform: translateY( 0 ); }
}

/* Scrollbar styling */
.otm-search-dropdown::-webkit-scrollbar { width: 4px; }
.otm-search-dropdown::-webkit-scrollbar-track { background: transparent; }
.otm-search-dropdown::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* ── Section label ───────────────────────────────────────── */
.otm-dd-label {
    font-size:      var( --otm-label-size );
    font-weight:    700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color:          var( --otm-label-color );
    padding:        12px 14px 6px;
}

/* ── Category items ──────────────────────────────────────── */
.otm-dd-cat-item {
    display:        flex;
    align-items:    center;
    gap:            10px;
    padding:        7px 14px;
    text-decoration: none;
    color:          var( --otm-search-text );
    border-radius:  0;
    transition:     background var( --otm-transition );
    font-size:      13px;
}

.otm-dd-cat-item:hover,
.otm-dd-cat-item.otm-dd-active {
    background: var( --otm-item-hover );
    text-decoration: none;
}

.otm-dd-cat-item img {
    width:         28px;
    height:        28px;
    border-radius: 4px;
    object-fit:    cover;
    flex-shrink:   0;
}

.otm-cat-icon {
    width:       28px;
    height:      28px;
    display:     flex;
    align-items: center;
    justify-content: center;
    font-size:   16px;
    flex-shrink: 0;
}

.otm-cat-name {
    flex: 1;
    font-weight: 500;
}

.otm-cat-count {
    font-size:    11px;
    color:        #9ca3af;
    background:   #f3f4f6;
    padding:      2px 7px;
    border-radius: 20px;
    flex-shrink:  0;
}

/* ── Product items ───────────────────────────────────────── */
.otm-dd-product-item {
    display:        flex;
    align-items:    center;
    gap:            12px;
    padding:        9px 14px;
    text-decoration: none;
    color:          var( --otm-search-text );
    transition:     background var( --otm-transition );
    border-radius:  0;
}

.otm-dd-product-item:hover,
.otm-dd-product-item.otm-dd-active {
    background: var( --otm-item-hover );
    text-decoration: none;
}

/* Thumbnail */
.otm-result-thumb {
    position:     relative;
    flex-shrink:  0;
    width:        52px;
    height:       52px;
    border-radius: 6px;
    overflow:     hidden;
    border:       1px solid #f0f0f0;
    background:   #f9fafb;
}

.otm-result-thumb img {
    width:      100%;
    height:     100%;
    object-fit: cover;
    display:    block;
}

/* Sale badge on thumb */
.otm-sale-badge {
    position:    absolute;
    top:         3px;
    left:        3px;
    font-size:   9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background:  var( --otm-sale-bg );
    color:       var( --otm-sale-color );
    padding:     2px 5px;
    border-radius: 3px;
    line-height: 1.3;
}

/* Info column */
.otm-result-info {
    flex:           1;
    min-width:      0;
    display:        flex;
    flex-direction: column;
    gap:            2px;
}

.otm-result-title {
    font-size:      14px;
    font-weight:    500;
    color:          #1a1a1a;
    white-space:    nowrap;
    overflow:       hidden;
    text-overflow:  ellipsis;
    line-height:    1.3;
}

.otm-result-meta {
    display:    flex;
    align-items: center;
    gap:        6px;
    flex-wrap:  wrap;
}

.otm-result-vendor {
    font-size:    11px;
    color:        var( --otm-accent );
    font-weight:  600;
}

.otm-result-cat {
    font-size:    11px;
    color:        #9ca3af;
}

.otm-result-cat::before {
    content: '·';
    margin-right: 4px;
    color: #d1d5db;
}

.otm-result-price {
    font-size:    13px;
    font-weight:  600;
    color:        #1a1a1a;
    line-height:  1;
    display:      flex;
    align-items:  center;
    gap:          8px;
}

/* WooCommerce price HTML overrides inside results */
.otm-result-price .woocommerce-Price-amount { font-size: 13px; }
.otm-result-price del { color: #9ca3af; font-weight: 400; font-size: 11px; }
.otm-result-price ins { text-decoration: none; color: #dc2626; }

.otm-oos-badge {
    font-size:   10px;
    color:       #9ca3af;
    border:      1px solid #e5e7eb;
    padding:     1px 6px;
    border-radius: 3px;
    font-weight: 500;
}

/* ── Highlight matches ───────────────────────────────────── */
.otm-search-dropdown mark {
    background:   var( --otm-mark-bg );
    color:        var( --otm-mark-color );
    border-radius: 2px;
    padding:      0 1px;
    font-style:   normal;
}

/* ── No results ──────────────────────────────────────────── */
.otm-dd-empty {
    display:        flex;
    flex-direction: column;
    align-items:    center;
    gap:            10px;
    padding:        28px 20px;
    color:          #9ca3af;
    font-size:      14px;
    text-align:     center;
}

.otm-dd-empty svg {
    opacity: 0.4;
}

.otm-dd-empty strong {
    color: #374151;
}

/* ── View all footer ─────────────────────────────────────── */
.otm-dd-view-all {
    display:        flex;
    align-items:    center;
    justify-content: space-between;
    gap:            8px;
    padding:        11px 14px;
    background:     var( --otm-accent-light );
    border-top:     1px solid #dbe9f9;
    font-size:      13px;
    font-weight:    600;
    color:          var( --otm-accent );
    text-decoration: none;
    transition:     background var( --otm-transition );
}

.otm-dd-view-all:hover,
.otm-dd-view-all.otm-dd-active {
    background:     #dbeafe;
    text-decoration: none;
    color:          var( --otm-accent );
}

.otm-dd-view-all strong {
    color: #1a1a1a;
}

/* ── Section divider ─────────────────────────────────────── */
.otm-dd-section + .otm-dd-section {
    border-top: 1px solid var( --otm-dd-border );
    margin-top: 4px;
    padding-top: 4px;
}

/* ── Header integration helpers ──────────────────────────── */

/*
 * The shortcode outputs .otm-search-wrap which is 100% wide by default.
 * If your header has a flex/grid row, the search bar will fill available space.
 * Add this class to a wrapper div in your header if needed:
 */
.otm-header-search {
    flex:       1;
    max-width:  600px;
    margin:     0 16px;
}

/* Full-bleed header search variant (e.g. below nav row) */
.otm-header-search--fullwidth {
    width:       100%;
    max-width:   100%;
    margin:      0;
    padding:     8px 0;
    border-top:  1px solid rgba(255,255,255,0.12);
}

/* ── Mobile ──────────────────────────────────────────────── */
@media ( max-width: 768px ) {
    :root {
        --otm-search-height: 42px;
        --otm-dd-max-height: 70vh;
    }

    .otm-result-thumb {
        width:  44px;
        height: 44px;
    }

    .otm-result-title {
        font-size: 13px;
    }

    .otm-result-price {
        font-size: 12px;
    }
}

@media ( max-width: 480px ) {
    .otm-dd-cat-item,
    .otm-dd-product-item {
        padding: 8px 12px;
    }

    .otm-result-vendor,
    .otm-result-cat {
        display: none; /* keep it tight on very small screens */
    }
}
