/* AMICO Header Search Styles */

/* Content Overlay when search is active */
.amico-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

.amico-search-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

/* Header Search Container */
.amico-search-container {
    position: absolute;
    top: 50%;
    right: 68px; /* Align with search button center */
    transform: translateY(-50%);
    width: 34px; /* Start with just enough for the close button */
    overflow: hidden; /* Prevents content overflow while collapsed */
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1001;
}

.amico-header.search-active .amico-search-container {
    width: calc(100% - 200px); /* Expand leftward to leave space for logo */
    overflow: visible; /* Allow dropdown to extend beyond container */
}

/* Hide navigation when search is active */
.amico-header.search-active .amico-nav {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Animate/hide the header search icon while search is active so it doesn't overlap the close (X) */
.amico-tools .amico-search-btn { 
    transition: opacity .3s ease, transform .3s ease; 
    cursor: pointer;
}
.amico-header.search-active .amico-tools .amico-search-btn { opacity: 0; transform: scale(0.9); pointer-events: none; }

/* Search Form */
.amico-search-form {
    position: relative;
    width: 100%;
}

.amico-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: transparent;
    border: none;
    border-bottom: none;
    padding: 0;
    height: 48px;
    transition: border-color 0.3s ease;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, border-color 0.3s ease;
}

/* Show search input only when search is active */
.amico-header.search-active .amico-search-input-wrapper {
    opacity: 1;
    visibility: visible;
}

.amico-search-input-wrapper:focus-within {
    /* Keep neutral underline on focus (no blue) */
    border-bottom-color: #e0e0e0;
}

.amico-search-icon {
    position: absolute;
    left: 8px; /* add small inset from edge */
    width: 24px;
    height: 24px;
    color: #1C1B1F;
    pointer-events: none;
}

.amico-search-input {
    width: 100%;
    padding: 14px 40px 14px 36px; /* leave gap between icon (20px) and text */
    font-size: 16px;
    border: none;
    background: transparent;
    outline: none;
    color: #333;
}

.amico-search-input::placeholder {
    color: #999;
    font-weight: 400;
}

/* Remove native clear (blue X) in WebKit/Edge */
.amico-search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }
.amico-search-input::-ms-clear { display: none; width: 0; height: 0; }
.amico-search-input::-ms-reveal { display: none; width: 0; height: 0; }
.amico-search-input::-o-clear { display: none; }

.amico-search-close {
    position: absolute;
    right: 0;
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    color: #000; /* ensure black for close icon */
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, color 0.2s ease;
}

/* Show close button only when search is active */
.amico-header.search-active .amico-search-close {
    opacity: 1;
    visibility: visible;
}

.amico-search-close:hover { color: #000; }

.amico-search-close svg {
    width: 16px;
    height: 16px;
}

/* Search Dropdown */
.amico-search-dropdown {
    position: absolute;
    /* Start dropdown at the bottom edge of the header, not right under the input */
    top: calc(100% + 16px); /* visually matches common header padding; adjust if header height changes */
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-top: none;
    box-shadow: none; /* remove shadow */
    z-index: 1002;
    max-height: 400px;
    overflow-y: auto;
}

/* Search Suggestions */
.amico-search-suggestions {
    /* Remove outer horizontal padding; inner containers will handle spacing */
    padding: 8px 0;
}

.amico-search-popular > h3 {
    color: #999 !important;
    font-family: Gotham, -apple-system, "Segoe UI", Roboto, Arial, sans-serif !important;
    font-weight: 400 !important;
    font-size: 16px !important;
    line-height: 1 !important;
    margin: 0 0 0 52px !important;
    padding: 0 !important;
    text-transform: uppercase !important;
}

.amico-popular-terms {
    list-style: none !important;
    padding: 16px 20px 8px 52px !important;
    margin: 0 !important;
}

.amico-popular-terms li {
    margin: 0 !important;
}

.amico-popular-terms button {
    display: inline-flex; /* shrink to text width */
    align-items: baseline;
    padding: 8px 0; /* rely on list padding for left offset */
    white-space: nowrap;
    background: none;
    border: none;
    color: #333;
    cursor: pointer;
    text-align: left;
    font-family: Gotham, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-weight: 400;
    font-size: 14px;
    line-height: 20px;
    position: relative;
    transition: color 0.2s ease;
    margin: 0 !important;
}

.amico-popular-terms button:hover {
    color: #000;
}

.amico-popular-terms button::after {
    content: "";
    position: absolute;
    left: 0;
    right: auto; /* underline matches the text width */
    bottom: 0;
    height: 1px;
    width: 100%;
    background-color: currentColor;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform .2s ease;
}

.amico-popular-terms button:hover::after {
    transform: scaleX(1);
}

/* Search Results Preview */
.amico-search-results-preview {
    margin-top: 8px;
    padding: 8px 0; /* Remove extra internal padding; use container padding */
}

.amico-search-results-list {
    list-style: none;
    padding: 8px 20px 8px 52px; /* moved inner spacing here */
    margin: 0;
}

.amico-search-result-item {
    padding: 10px 0; /* simple list spacing */
    border-bottom: none; /* no dividers for minimal look */
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.amico-search-result-item:hover {
    /* Fill the dropdown width by canceling the list's inner padding */
    background-color: #fafafa;
    margin-left: -52px;
    margin-right: -20px;
    padding-left: 52px;
    padding-right: 20px;
}

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

.amico-search-result-item a {
    display: block;
    color: inherit;
    text-decoration: none;
}

.amico-search-result-type {
    display: inline-block;
    padding: 2px 8px;
    background: #f0f0f0;
    color: #666;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 3px;
    margin-bottom: 6px;
}

.amico-search-result-title { display: none; }

/* Simple title for minimal dynamic results */
.amico-search-simple-title {
    margin: 0;
    font-family: Gotham, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-weight: 400;
    font-size: 14px;
    line-height: 20px;
    color: #333;
}

.amico-search-result-excerpt { display: none; }

.amico-search-result-meta {
    display: flex;
    gap: 15px;
    margin-top: 6px;
    font-size: 12px;
    color: #999;
}

/* View All Results Link */
.amico-search-view-all {
    text-align: left;
    padding: 10px 20px 10px 52px; /* align with 52px left */
    border-top: 1px solid #f0f0f0;
    background: #f8f9fa;
}

.amico-search-view-all a {
    color: #0066cc;
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: color 0.3s ease;
}

.amico-search-view-all a:hover {
    color: #0052a3;
    text-decoration: underline;
}

/* Clear indication for matched text */
.amico-match {
    font-weight: 600; /* keep bold */
    border-bottom: none; /* remove underline */
}

/* Loading State */
.amico-search-loading {
    text-align: center;
    padding: 30px;
    color: #999;
    font-size: 14px;
}

.amico-search-loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #e0e0e0;
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

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

/* No Results */
.amico-search-no-results {
    text-align: center;
    padding: 30px;
    color: #999;
    font-size: 14px;
}

/* Mobile & Tablet Styles */
@media (max-width: 1024px) {
    /* Break search container out of parent constraints */
    .amico-header .amico-container {
        position: relative;
    }
    
    .amico-search-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        transform: none;
        width: 100vw;
        height: 80px;
        padding: 16px;
        background: #fff;
        z-index: 1001;
        box-shadow: none;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        margin: 0;
    }
    
    /* Show search container in mobile only when search is active */
    .amico-header.search-active .amico-search-container {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: all !important;
        width: 100vw !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        transform: none !important;
        padding: 16px !important;
        margin: 0 !important;
        height: 80px !important;
    }
    
    /* Hide burger menu when search is active on mobile */
    .amico-header.search-active .amico-burger {
        display: none !important;
    }
    
    /* Make close button more prominent on mobile and position like burger menu */
    .amico-search-close {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 24px;
        height: 24px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .amico-search-close svg {
        width: 24px; /* use full 24x24 size on mobile */
        height: 24px;
    }
    
    .amico-search-icon {
        position: absolute;
        left: 0;
        width: 24px;
        height: 24px;
        color: #1C1B1F;
        pointer-events: none;
    }
    
    .amico-search-input {
        font-size: 16px;
        padding: 14px 0; /* no horizontal padding; wrapper handles icon spacing */
        width: 100%;
        box-sizing: border-box;
    }
    
    .amico-search-input-wrapper {
        position: relative;
        flex: 1;
        width: 100%;
        display: flex;
        align-items: center;
        padding: 0 28px; /* reserve space for 20px icons + 8px gap on both sides */
    }
    
    .amico-search-form {
        width: 100%;
        display: flex;
        align-items: center;
    }
    
    .amico-search-dropdown {
        position: fixed;
        top: 80px;
        left: 0;
        right: 0;
        width: 100vw;
        border: none;
        border-top: 1px solid #e5e5e5;
        border-radius: 0;
        max-height: calc(100vh - 78px);
        background: #fff;
    }
    
    /* Mobile specific spacing adjustments */
    .amico-search-suggestions {
        padding: 16px 0;
    }
    
    .amico-popular-terms {
        padding: 16px 20px 8px 20px !important;
    }
    
    .amico-search-results-list {
        padding: 8px 20px !important;
    }
    
    .amico-search-popular > h3 {
        margin: 0 0 0 20px !important;
    }
    
    /* Mobile typography for suggestion buttons */
    .amico-popular-terms button {
        font-family: Gotham, -apple-system, "Segoe UI", Roboto, Arial, sans-serif !important;
        font-weight: 400 !important;
        font-style: normal !important;
        font-size: 16px !important;
        line-height: 24px !important;
        letter-spacing: 0% !important;
    }

    /* Allow suggestions to wrap onto multiple lines on mobile */
    .amico-popular-terms button {
        white-space: normal !important; /* override desktop nowrap */
        display: block !important;      /* take full line for natural wrapping */
        width: 100% !important;         /* ensure wrapping within container width */
        overflow-wrap: anywhere;        /* break long words/URLs if needed */
        word-break: break-word;         /* extra safety for older engines */
    }

    /* Mobile typography for dynamic search results */
    .amico-search-simple-title {
        font-family: Gotham, -apple-system, "Segoe UI", Roboto, Arial, sans-serif !important;
        font-weight: 400 !important;
        font-style: normal !important;
        font-size: 16px !important;
        line-height: 24px !important;
        letter-spacing: 0% !important;
    }
}

/* Tablet styles removed - tablets now follow mobile behavior above */

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.amico-search-result-item {
    animation: fadeIn 0.3s ease forwards;
}

.amico-search-result-item:nth-child(1) { animation-delay: 0.05s; }
.amico-search-result-item:nth-child(2) { animation-delay: 0.1s; }
.amico-search-result-item:nth-child(3) { animation-delay: 0.15s; }
.amico-search-result-item:nth-child(4) { animation-delay: 0.2s; }
.amico-search-result-item:nth-child(5) { animation-delay: 0.25s; }
