/* ==========================================================================
   Search Component Styles
   Mobile-first, responsive design
   ========================================================================== */

/* Base Component */
.search-component {
    position: relative;
    width: 100%;
}

.search-form {
    margin: 0;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: stretch;
}

.search-input {
    flex: 1;
    padding: 14px 18px;
    font-size: 16px; /* Previene zoom su iOS */
    border: 2px solid #ddd;
    border-right: none;
    border-radius: 8px 0 0 8px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: #fff;
}

.search-input:focus {
    border-color: #ff8d00;
    box-shadow: 0 0 0 3px rgba(255, 141, 0, 0.15);
}

.search-input::placeholder {
    color: #999;
}

.search-btn {
    padding: 14px 22px;
    border-radius: 0 8px 8px 0;
    background: #ff8d00;
    border: 2px solid #ff8d00;
    color: white;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
}

.search-btn:hover,
.search-btn:focus {
    background: #e67e00;
    border-color: #e67e00;
}

.search-btn:active {
    transform: scale(0.98);
}

.search-btn-text {
    display: none;
}

/* ==========================================================================
   Autocomplete Dropdown
   ========================================================================== */

.search-autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #ff8d00;
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: none;
    max-height: 350px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.search-autocomplete-dropdown.show {
    display: block;
}

.autocomplete-item {
    display: block;
    padding: 14px 18px;
    color: #333;
    text-decoration: none;
    border-bottom: 1px solid #eee;
    transition: background 0.15s ease;
    font-size: 16px;
    line-height: 1.5;
}

.autocomplete-item:last-child {
    border-bottom: none;
    border-radius: 0 0 6px 6px;
}

.autocomplete-item:hover,
.autocomplete-item:focus,
.autocomplete-item.active {
    background: #fff5eb;
    outline: none;
}

.autocomplete-item strong {
    color: #ff8d00;
    font-weight: 700;
}

.autocomplete-more {
    background: #f9f9f9;
    color: #ff8d00;
    font-weight: 600;
    text-align: center;
    border-top: 2px solid #eee;
}

.autocomplete-more:hover,
.autocomplete-more:focus {
    background: #fff5eb;
}

.autocomplete-more i {
    margin-right: 8px;
}

.autocomplete-loading {
    padding: 20px;
    text-align: center;
    color: #999;
}

.autocomplete-empty {
    padding: 20px;
    text-align: center;
    color: #666;
    font-style: italic;
}

/* ==========================================================================
   Variant: Header (compatto per navbar)
   ========================================================================== */

.search-component--header {
    max-width: 280px;
    position: relative;
    z-index: 9999;
}

.search-component--header .search-input {
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 6px 0 0 6px;
}

.search-component--header .search-btn {
    padding: 10px 14px;
    border-radius: 0 6px 6px 0 !important;
}

.search-component--header .autocomplete-item {
    padding: 10px 14px;
    font-size: 13pt;
}

.search-component--header .search-autocomplete-dropdown {
    border-radius: 0 0 6px 6px;
    min-width: 280px;
    width: max-content;
    z-index:1000;
    max-width: calc(100vw - 30px);
    overflow-x: hidden;
}

.search-component--header .autocomplete-item .autocomplete-text {
    word-break: break-word;
    overflow-wrap: break-word;
}

.search-component--header .search-form {
    margin: 0;
    padding: 0;
}

/* Header navbar vertical alignment */
@media (min-width: 992px) {
    .navbar-nav .nav-item {
        display: flex;
        align-items: center;
    }

    .navbar-nav .nav-item .avatar-container {
        display: flex;
        align-items: center;
    }

    .navbar-nav .nav-item .dropdown-toggle {
        display: flex;
        align-items: center;
    }
}

/* ==========================================================================
   Variant: Home (grande, prominente)
   ========================================================================== */

.search-component--home {
    max-width: 700px;
    margin: 0 auto;
}

.search-component--home .search-description {
    color: #555;
    font-size: 15px;
    line-height: 1.5;
    margin-bottom: 18px;
    text-align: center;
}

.search-component--home .search-input {
    padding: 18px 24px;
    font-size: 18px;
    border-radius: 10px 0 0 10px;
}

.search-component--home .search-btn {
    padding: 18px 28px;
    font-size: 18px;
    border-radius: 0 10px 10px 0;
}

.search-component--home .search-btn-text {
    display: inline;
}

.search-component--home .autocomplete-item {
    padding: 16px 20px;
    font-size: 17px;
}

.search-component--home .search-autocomplete-dropdown {
    border-radius: 0 0 10px 10px;
}

/* ==========================================================================
   Search Hero (Homepage banner) - Design elegante e pulito
   ========================================================================== */

.search-hero {
    background: linear-gradient(135deg, #fff8f2 0%, #fff 100%);
    border: 1px solid #ffe0c0;
    padding: 28px 24px;
    border-radius: 12px;
    margin: 20px 0 28px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(255, 141, 0, 0.08);
}

.search-hero .search-component--home .search-input {
    border-color: #ddd;
    background: #fff;
}

.search-hero .search-component--home .search-input:focus {
    border-color: #ff8d00;
    box-shadow: 0 0 0 3px rgba(255, 141, 0, 0.12);
}

.search-hero .search-component--home .search-btn {
    background: #ff8d00;
    border-color: #ff8d00;
}

.search-hero .search-component--home .search-btn:hover {
    background: #e67e00;
    border-color: #e67e00;
}

.search-hero-title {
    color: #333;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 18px;
}

.search-hero-actions {
    margin-top: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}

.search-hero-or {
    color: #888;
    font-style: italic;
    font-size: 14px;
}

.search-hero .btn-secondary {
    background: transparent;
    border: 2px solid #ff8d00;
    color: #ff8d00;
    font-weight: 600;
    font-size: 14px;
    padding: 12px 22px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.search-hero .btn-secondary:hover {
    background: #ff8d00;
    color: white;
}

/* ==========================================================================
   Search Filters - Bottom Sheet Mobile / Inline Desktop
   ========================================================================== */

/* Bottone toggle filtri - visibile solo su mobile */
.search-filters-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    margin: 16px 0;
    position: relative;
}

.search-filters-toggle:hover {
    background: #eee;
}

.search-filters-toggle i {
    color: #ff8d00;
}

/* Badge filtri attivi */
.filters-active-badge {
    width: 8px;
    height: 8px;
    background: #ff8d00;
    border-radius: 50%;
    position: absolute;
    top: 10px;
    right: 10px;
}

/* Container filtri */
.search-filters-container {
    margin: 16px 0;
}

/* Overlay per mobile */
.search-filters-overlay {
    display: none;
}

/* Panel filtri */
.search-filters-panel {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 20px;
}

/* Header filtri - nascosto su desktop */
.search-filters-header {
    display: none;
}

/* Form filtri */
.search-filters-form {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}

.search-filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.search-filter-group label {
    font-weight: 600;
    color: #444;
    font-size: 11pt;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.search-filter-group select,
.search-filter-group input[type="number"] {
    padding: 12px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    background: white;
    transition: border-color 0.2s ease;
    min-height: 48px;
    -webkit-appearance: none;
    appearance: none;
}

.search-filter-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
    cursor: pointer;
}

.search-filter-group select:focus,
.search-filter-group input[type="number"]:focus {
    border-color: #ff8d00;
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 141, 0, 0.1);
}

.search-filter-group input[type="number"] {
    width: 100px;
}

/* Rimuove spinner number input */
.search-filter-group input[type="number"]::-webkit-inner-spin-button,
.search-filter-group input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.search-filter-group input[type="number"] {
    -moz-appearance: textfield;
}

/* Actions */
.search-filters-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.search-filters-actions .btn {
    padding: 12px 24px;
    font-size: 15px;
    min-height: 48px;
    border-radius: 8px;
    font-weight: 600;
}

.search-filters-actions .btn-primary {
    background: #ff8d00;
    border-color: #ff8d00;
    color: white;
}

.search-filters-actions .btn-primary:hover {
    background: #e67e00;
    border-color: #e67e00;
}

.search-filters-actions .btn-outline-secondary {
    background: transparent;
    border: 1px solid #ccc;
    color: #666;
}

.search-filters-actions .btn-outline-secondary:hover {
    border-color: #ff8d00;
    color: #ff8d00;
}

/* ==========================================================================
   Active Filters Bar (simplified: count + reset button)
   ========================================================================== */

.active-filters-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    background: #fff8f0;
    border: 1px solid #ffe0c0;
    border-radius: 8px;
    margin: 16px 0;
}

.active-filters-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    color: #555;
}

.active-filters-info i {
    color: #ff8d00;
    font-size: 16px;
}

.active-filters-info strong {
    color: #ff8d00;
    font-weight: 700;
    font-size: 17px;
}

.btn-reset-filters {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: #ff8d00;
    color: white;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-reset-filters:hover {
    background: #e67e00;
    color: white;
    text-decoration: none;
}

.btn-reset-filters i {
    font-size: 11pt;
}

/* ==========================================================================
   Lead text override for search page (13pt minimum)
   ========================================================================== */

.question-details .lead {
    font-size: 13pt;
    font-weight: 400;
    color: #555;
    line-height: 1.5;
}

/* ==========================================================================
   Desktop: filtri inline, toggle nascosto
   ========================================================================== */

@media (min-width: 768px) {
    .search-filters-toggle {
        display: none;
    }

    .search-filters-container {
        display: block;
    }

    .search-filters-panel {
        display: block;
    }

    .search-filter-group {
        flex: 0 0 auto;
    }
}

/* ==========================================================================
   Mobile: Bottom Sheet Drawer
   ========================================================================== */

@media (max-width: 767px) {
    /* Toggle visibile */
    .search-filters-toggle {
        display: flex;
        width: 100%;
        justify-content: center;
    }

    /* Container come overlay fullscreen */
    .search-filters-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
        visibility: hidden;
        margin: 0;
    }

    .search-filters-container.open {
        visibility: visible;
    }

    /* Overlay scuro */
    .search-filters-overlay {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .search-filters-container.open .search-filters-overlay {
        opacity: 1;
    }

    /* Panel come bottom sheet */
    .search-filters-panel {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-radius: 20px 20px 0 0;
        padding: 0;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        max-height: 80vh;
        overflow-y: auto;
    }

    .search-filters-container.open .search-filters-panel {
        transform: translateY(0);
    }

    /* Header drawer */
    .search-filters-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20px 24px 16px;
        border-bottom: 1px solid #eee;
        position: sticky;
        top: 0;
        background: white;
        border-radius: 20px 20px 0 0;
    }

    .search-filters-header span {
        font-size: 18px;
        font-weight: 700;
        color: #333;
    }

    .search-filters-close {
        width: 40px;
        height: 40px;
        border: none;
        background: #f0f0f0;
        border-radius: 50%;
        font-size: 18px;
        color: #666;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .search-filters-close:hover {
        background: #e0e0e0;
    }

    /* Form nel drawer */
    .search-filters-form {
        flex-direction: column;
        gap: 20px;
        padding: 24px;
    }

    .search-filter-group {
        width: 100%;
    }

    .search-filter-group label {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .search-filter-group select,
    .search-filter-group input[type="number"] {
        width: 100%;
        min-height: 52px;
        font-size: 16px;
    }

    /* Actions sticky in fondo */
    .search-filters-actions {
        flex-direction: column;
        gap: 12px;
        padding-top: 16px;
        border-top: 1px solid #eee;
        margin-top: 8px;
    }

    .search-filters-actions .btn {
        width: 100%;
        min-height: 52px;
        font-size: 16px;
    }

    /* Active filters bar mobile */
    .active-filters-bar {
        flex-direction: row;
        justify-content: space-between;
        padding: 12px 14px;
    }

    .active-filters-info {
        font-size: 14px;
    }

    .active-filters-info strong {
        font-size: 16px;
    }

    .btn-reset-filters {
        padding: 8px 14px;
        font-size: 11pt;
        min-height: 40px;
    }
}

/* ==========================================================================
   Responsive - Mobile
   ========================================================================== */

@media (max-width: 767px) {
    /* Touch target minimo 48px */
    .search-input {
        min-height: 50px;
        font-size: 16px;
    }

    .search-btn {
        min-width: 50px;
        min-height: 50px;
    }

    .autocomplete-item {
        min-height: 50px;
        display: flex;
        align-items: center;
        padding: 12px 16px;
    }

    /* Header variant full width su mobile */
    .search-component--header {
        max-width: 100%;
    }

    /* Header autocomplete: prevent horizontal overflow on mobile */
    .search-component--header .search-autocomplete-dropdown {
        left: 0;
        right: auto;
        z-index:1050;
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
    }

    /* Search hero adjustments */
    .search-hero {
        padding: 25px 15px;
        margin: 15px 0 25px;
        border-radius: 10px;
    }

    .search-hero-title {
        font-size: 18px;
    }

    .search-hero-actions {
        flex-direction: column;
        gap: 12px;
    }

    .search-hero .btn-secondary {
        width: 100%;
        max-width: 280px;
    }

    /* Home variant adjustments */
    .search-component--home .search-input {
        padding: 14px 16px;
        font-size: 16px;
    }

    .search-component--home .search-btn {
        padding: 14px 18px;
        font-size: 16px;
    }

    .search-component--home .search-btn-text {
        display: none;
    }

    /* Filters - Mobile optimized UX */
    .search-filters {
        flex-direction: column;
        gap: 16px;
        padding: 18px;
    }

    .search-filter-group {
        width: 100%;
    }

    .search-filter-group label {
        font-size: 11pt;
        margin-bottom: 4px;
    }

    .search-filter-group select,
    .search-filter-group input[type="number"] {
        width: 100%;
        font-size: 16px; /* Evita zoom iOS */
        min-height: 52px; /* Touch target generoso */
    }

    /* Pulsanti filtri full width su mobile */
    .search-filters .btn {
        width: 100%;
        justify-content: center;
    }

    .search-filters .btn-link {
        text-align: center;
    }
}

/* ==========================================================================
   Tablet
   ========================================================================== */

@media (min-width: 768px) and (max-width: 1023px) {
    .search-component--header {
        max-width: 240px;
    }

    .search-hero {
        padding: 32px 28px;
    }
}

/* ==========================================================================
   Desktop
   ========================================================================== */

@media (min-width: 1024px) {
    .search-component--header {
        max-width: 320px;
    }

    .search-hero {
        padding: 36px 40px;
    }

    .search-hero-title {
        font-size: 20px;
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible for keyboard navigation */
.search-input:focus-visible,
.search-btn:focus-visible,
.autocomplete-item:focus-visible {
    outline: 2px solid #ff8d00;
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .search-input,
    .search-btn,
    .autocomplete-item,
    .search-autocomplete-dropdown {
        transition: none;
    }
}

/* ==========================================================================
   Aiuta Utenti List - Stack Overflow Style
   Question-first, user info below
   ========================================================================== */

.aiuta-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.aiuta-item {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 0;
    border-bottom: 1px solid #e8e8e8;
    transition: background 0.15s;
}

.aiuta-item:first-child {
    padding-top: 10px;
}

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

.aiuta-item:hover {
    background: #fafafa;
}

/* Question - prominente, stile citazione con accent */
.aiuta-question {
    font-size: 15pt;
    font-weight: 500;
    color: #222;
    line-height: 1.4;
    padding-left: 14px;
    border-left: 3px solid #ff8d00;
    background: linear-gradient(90deg, #fff8f2 0%, transparent 100%);
    padding-top: 6px;
    padding-bottom: 6px;
    border-radius: 0 4px 4px 0;
}

/* Meta row - avatar + username + spacer + cta button */
.aiuta-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.aiuta-meta .avatar-container {
    width: 50px !important;
    height: 50px !important;
    flex-shrink: 0;
}

.aiuta-meta .avatar-container .circleimg {
    width: 50px !important;
    height: 50px !important;
}

.aiuta-username {
    font-weight: 600;
    color: #555;
    font-size: 13pt;
    text-decoration: none;
}

.aiuta-username:hover {
    color: #ff8d00;
    text-decoration: none;
}

.aiuta-username--anon {
    color: #555;
    font-weight: 400;
}

.aiuta-separator {
    display: none;
}

/* CTA - reply button style, pushed to right */
.aiuta-cta {
    margin-left: auto;
    color: #a85d00;
    font-size: 13pt;
    font-weight: 600;
    text-decoration: none;
    background: #fff5eb;
    border: 1px solid #ffe0c0;
    border-radius: 6px;
    padding: 6px 14px;
    transition: all 0.15s;
}

.aiuta-cta:hover {
    background: #a85d00;
    border-color: #a85d00;
    color: white;
    text-decoration: none;
}

/* Mobile - stesso layout */
@media (max-width: 767px) {
    .aiuta-item {
        padding: 14px 0;
        gap: 10px;
    }

    .aiuta-question {
        font-size: 14pt;
        line-height: 1.35;
    }

    .aiuta-meta {
        gap: 8px;
        flex-wrap: wrap;
    }

    .aiuta-username {
        font-size: 13pt;
    }

    .aiuta-cta {
        font-size: 13pt;
        padding: 5px 12px;
    }
}
