/* Universal Search Modal Styles */
.search-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 8vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease-out;
}

.search-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
}

.search-modal-content {
    position: relative;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.3s ease-out;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.theme-light .search-modal-content {
    background: rgba(255, 255, 255, 0.95) !important;
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15) !important;
}

.search-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-light .search-modal-header {
    border-bottom-color: rgba(0, 0, 0, 0.1) !important;
}

.search-modal-header h3 {
    margin: 0;
    color: #ffffff;
    font-size: 1.3rem;
    font-weight: 600;
}

.theme-light .search-modal-header h3 {
    color: #333333 !important;
}

.search-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-light .search-close-btn {
    color: rgba(0, 0, 0, 0.6) !important;
}

.search-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 1);
}

.theme-light .search-close-btn:hover {
    background: rgba(0, 0, 0, 0.05) !important;
    color: rgba(0, 0, 0, 0.8) !important;
}

/* Search Input */
.search-input-container {
    position: relative;
    padding: 1rem 2rem;
    width: 100%;
    box-sizing: border-box;
}

/* Region Filter Section */
.region-filter-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin: 0 2rem 1rem 2rem;
    padding: 0;
    flex-wrap: wrap;
}

.region-filter-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    outline: none;
}

.theme-light .region-filter-btn {
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
    color: #333 !important;
}

.region-filter-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.theme-light .region-filter-btn:hover {
    background: rgba(255, 255, 255, 1) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

.region-filter-btn.active {
    background: rgba(255, 107, 53, 0.9);
    color: white;
    border-color: rgba(255, 107, 53, 1);
}

.theme-light .region-filter-btn.active {
    background: #ff6b35 !important;
    color: white !important;
    border-color: #ff6b35 !important;
}

.region-filter-btn.all {
    background: rgba(255, 215, 0, 0.15);
    border-color: rgba(255, 215, 0, 0.3);
    color: rgba(255, 215, 0, 0.9);
}

.theme-light .region-filter-btn.all {
    background: rgba(255, 165, 0, 0.1) !important;
    border-color: rgba(255, 165, 0, 0.3) !important;
    color: #ff8c00 !important;
}

.region-filter-btn.all:hover {
    background: rgba(255, 215, 0, 0.25);
}

.theme-light .region-filter-btn.all:hover {
    background: rgba(255, 165, 0, 0.2) !important;
}

.region-filter-btn.all.active {
    background: rgba(255, 215, 0, 0.9);
    color: #1a1a1a;
    border-color: rgba(255, 215, 0, 1);
    font-weight: 600;
}

.theme-light .region-filter-btn.all.active {
    background: #ff8c00 !important;
    color: white !important;
    border-color: #ff8c00 !important;
}

/* Region Filter Dropdowns */
.region-filter-dropdown {
    position: relative;
    display: inline-block;
}

.region-filter-select {
    padding: 8px 32px 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    min-width: 120px;
}

.theme-light .region-filter-select {
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
    color: #333 !important;
}

.region-filter-select:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.theme-light .region-filter-select:hover {
    background: rgba(255, 255, 255, 1) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

.region-filter-select:focus {
    border-color: rgba(255, 107, 53, 0.5);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.theme-light .region-filter-select:focus {
    border-color: #ff6b35 !important;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1) !important;
}

.region-filter-select.active {
    background: rgba(255, 107, 53, 0.9);
    color: white;
    border-color: rgba(255, 107, 53, 1);
}

.theme-light .region-filter-select.active {
    background: #ff6b35 !important;
    color: white !important;
    border-color: #ff6b35 !important;
}

/* Dropdown arrow */
.region-filter-dropdown::after {
    content: '▼';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.6);
}

.theme-light .region-filter-dropdown::after {
    color: rgba(0, 0, 0, 0.5) !important;
}

.region-filter-select option {
    background: #1a1a1a;
    color: white;
    padding: 8px;
}

.theme-light .region-filter-select option {
    background: white !important;
    color: #333 !important;
}

.universal-search-input {
    width: 100%;
    padding: 1rem 3rem 1rem 1.5rem;
    border: 2px solid rgba(255, 215, 0, 0.3);
    border-radius: 16px;
    font-size: 1.1rem;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    outline: none;
    box-sizing: border-box;
    max-width: 100%;
}

.theme-light .universal-search-input {
    background: rgba(255, 255, 255, 0.8) !important;
    color: #333333 !important;
    border-color: rgba(255, 165, 0, 0.4) !important;
}

.universal-search-input:focus {
    border-color: rgba(255, 215, 0, 0.8);
    box-shadow: 0 0 0 4px rgba(255, 215, 0, 0.1);
}

.universal-search-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.theme-light .universal-search-input::placeholder {
    color: rgba(0, 0, 0, 0.5) !important;
}

.search-input-icon {
    position: absolute;
    right: 2.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.6);
    pointer-events: none;
}

.theme-light .search-input-icon {
    color: rgba(0, 0, 0, 0.5) !important;
}


/* Quick Access Sections */
.search-quick-sections {
    padding: 1rem 2rem;
    max-height: 60vh;
    overflow-y: auto;
    margin-bottom: 2rem;
}

.quick-section {
    margin-bottom: 1.5rem;
}

.quick-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 0.75rem;
}

.theme-light .quick-section-title {
    color: rgba(0, 0, 0, 0.8) !important;
}

.quick-section-items {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    width: 100%;
}

.quick-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 100px;
    height: 100px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.theme-light .quick-item {
    background: rgba(255, 255, 255, 0.6) !important;
    border-color: rgba(0, 0, 0, 0.05) !important;
}

.quick-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 215, 0, 0.3);
    transform: translateY(-2px);
}

.theme-light .quick-item:hover {
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(255, 165, 0, 0.4) !important;
}

.quick-item-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.4rem;
    overflow: hidden;
    flex-shrink: 0;
}

.quick-item-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.quick-item-initials {
    color: white;
    font-weight: 600;
    font-size: 1rem;
}

.quick-item-name {
    font-size: 0.75rem;
    line-height: 1.2;
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    max-width: 100%;
    padding: 0 4px;
    box-sizing: border-box;
    word-break: break-word;
}

.theme-light .quick-item-name {
    color: rgba(0, 0, 0, 0.7) !important;
}

.quick-item-aura {
    font-size: 0.7rem;
    color: #FFD700;
    margin-top: 0.2rem;
    white-space: nowrap;
}

.quick-item-empty {
    opacity: 0.5;
    pointer-events: none;
}

.quick-item-more {
    background: rgba(255, 215, 0, 0.1);
    border-color: rgba(255, 215, 0, 0.3);
}

.quick-item-more:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: rgba(255, 215, 0, 0.5);
}

.theme-light .quick-item-more {
    background: rgba(255, 165, 0, 0.1) !important;
    border-color: rgba(255, 165, 0, 0.3) !important;
}

.quick-item-plus {
    color: #FFD700;
    font-size: 1.5rem;
    font-weight: 300;
}

.theme-light .quick-item-plus {
    color: #FFA500 !important;
}

/* Search Results */
.search-results-container {
    flex: 1;
    overflow-y: auto;
    max-height: 50vh;
    padding: 1rem 2rem;
    min-height: 200px;
    margin-bottom: 2rem;
    padding-bottom: 3rem;
}

.results-section {
    margin-bottom: 1.5rem;
}

.section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-light .section-title {
    color: rgba(0, 0, 0, 0.8) !important;
    border-bottom-color: rgba(0, 0, 0, 0.1) !important;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    color: inherit;
    text-decoration: none;
}

.theme-light .search-result-item {
    background: rgba(255, 255, 255, 0.6) !important;
    border-color: rgba(0, 0, 0, 0.05) !important;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 215, 0, 0.4);
    transform: translateY(-1px);
}

.theme-light .search-result-item:hover {
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(255, 165, 0, 0.4) !important;
}

.result-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    border: 2px solid var(--background-card, rgba(255, 255, 255, 0.1));
}

.result-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    /* Ensure no white background shows through */
    background: transparent;
}

/* Theme-aware avatar border */
.theme-light .result-avatar {
    border-color: rgba(255, 255, 255, 0.9);
    background: linear-gradient(135deg, #ff6b35, #f7931e);
}

:root:not(.theme-light) .result-avatar {
    border-color: rgba(255, 255, 255, 0.15);
}

.result-content {
    flex: 1;
    min-width: 0;
}

.result-title {
    font-size: 1rem;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    word-break: break-word;
}

.result-type-icon {
    margin-right: 0.25rem;
    font-size: 0.9rem;
}

.theme-light .result-title {
    color: #333333 !important;
}

.result-title mark {
    background: rgba(255, 215, 0, 0.3);
    color: rgba(255, 215, 0, 1);
    padding: 0;
    border-radius: 2px;
}

.theme-light .result-title mark {
    background: rgba(255, 165, 0, 0.3) !important;
    color: rgba(255, 140, 0, 1) !important;
}

.result-subtitle {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.theme-light .result-subtitle {
    color: rgba(0, 0, 0, 0.6) !important;
}

.result-meta {
    font-size: 0.75rem;
    color: rgba(255, 215, 0, 0.8);
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    display: inline-block;
}

.theme-light .result-meta {
    color: rgba(255, 140, 0, 0.9) !important;
    background: rgba(255, 165, 0, 0.15) !important;
    border-color: rgba(255, 165, 0, 0.3) !important;
}


/* Search Actions */
.search-actions {
    padding: 1rem 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-light .search-actions {
    border-top-color: rgba(0, 0, 0, 0.1) !important;
}

.search-action-btn {
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: none;
    letter-spacing: 0;
}

.search-action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(255, 107, 53, 0.3);
}

/* Loading and Error States */
.search-loading,
.search-error,
.no-results {
    text-align: center;
    padding: 2rem 1rem;
    color: rgba(255, 255, 255, 0.7);
}

.theme-light .search-loading,
.theme-light .search-error,
.theme-light .no-results {
    color: rgba(0, 0, 0, 0.6) !important;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid rgba(255, 215, 0, 1);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.theme-light .loading-spinner {
    border-color: rgba(0, 0, 0, 0.2) !important;
    border-top-color: rgba(255, 165, 0, 1) !important;
}

.error-icon,
.no-results-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
}

.search-loading h4,
.search-error h4,
.no-results h4 {
    margin: 0 0 0.5rem 0;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.1rem;
}

.theme-light .search-loading h4,
.theme-light .search-error h4,
.theme-light .no-results h4 {
    color: rgba(0, 0, 0, 0.8) !important;
}

.search-loading p,
.search-error p,
.no-results p {
    margin: 0;
    font-size: 0.9rem;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* PWA Detection and Mobile Responsive */
@media (max-width: 768px) {
    .search-modal {
        padding-top: 2vh;
        align-items: flex-start;
        overflow-x: hidden;
    }

    .search-modal-content {
        width: 95%;
        max-width: 100%;
        max-height: 90vh;
        border-radius: 16px;
        overflow-x: hidden;
    }
    
    /* Region filter section mobile adjustments */
    .region-filter-section {
        margin: 0 1rem 0.75rem 1rem;
        gap: 8px;
    }
    
    .region-filter-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    /* Quick sections mobile layout - 3 items per row (2 + Vedi altri) */
    .quick-section-items {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.75rem;
    }
    
    .search-quick-sections {
        padding: 0.75rem 1rem;
        margin-bottom: 4rem;
    }
    
    .quick-section {
        margin-bottom: 1.25rem;
    }
    
    .quick-item {
        padding: 0.5rem 0.25rem;
        min-height: 85px;
        height: 85px;
        width: 100%;
    }
    
    .quick-item-avatar {
        width: 35px;
        height: 35px;
        min-width: 35px;
        min-height: 35px;
        margin-bottom: 0.3rem;
    }
    
    .quick-item-name {
        font-size: 0.7rem;
        width: 100%;
        padding: 0 3px;
    }
    
    .quick-item-aura {
        font-size: 0.65rem;
    }
}

/* PWA Specific Positioning */
@media (max-width: 768px) and (display-mode: standalone) {
    .search-modal {
        padding-top: 12vh !important;
        align-items: flex-start;
    }
    
    .search-modal-content {
        margin-top: 1.5rem;
    }
}

/* iOS PWA Specific */
@media (max-width: 768px) and (display-mode: standalone) and (-webkit-touch-callout: none) {
    .search-modal {
        padding-top: 15vh !important;
    }
}

/* JavaScript-based PWA Detection */
@media (max-width: 768px) {
    .pwa-mode .search-modal {
        padding-top: 17vh !important;
        align-items: flex-start !important;
    }
    
    .pwa-mode .search-modal-content {
        margin-top: 0.5rem !important;
    }
    
    /* iPhone specific PWA adjustments */
    .pwa-mode.ios .search-modal {
        padding-top: 20vh !important;
    }
}
    
    .search-modal-header {
        padding: 1rem 1.5rem 0.75rem;
    }
    
    .search-modal-header h3 {
        font-size: 1.1rem;
    }
    
    .search-input-container {
        padding: 0.75rem 1rem;
        width: 100%;
        max-width: 100%;
    }

    .universal-search-input {
        padding: 0.9rem 2.5rem 0.9rem 1.2rem;
        font-size: 0.95rem;
        border-radius: 12px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .search-input-icon {
        right: 1.5rem;
    }
    
    
    .search-results-container {
        padding: 0 1rem 6rem;
        max-height: 60vh;
        margin-bottom: 6rem;
        overflow-x: hidden;
        max-width: 100%;
    }

    .search-result-item {
        padding: 0.6rem 0.8rem;
        gap: 0.75rem;
        max-width: 100%;
        overflow: hidden;
    }

    .result-avatar {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
        border-radius: 50%;
        flex-shrink: 0;
    }

    .result-content {
        flex: 1;
        min-width: 0;
        max-width: calc(100% - 50px);
        overflow: hidden;
    }

    .result-title {
        font-size: 0.95rem;
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
        line-height: 1.3;
        max-height: 2.6em;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .result-subtitle {
        font-size: 0.8rem;
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .search-actions {
        padding: 0.75rem 1.5rem;
    }
    
    .search-action-btn {
        padding: 0.65rem;
        font-size: 0.9rem;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .search-modal {
        padding-top: 1vh;
        overflow-x: hidden;
    }

    .search-modal-content {
        width: 98%;
        max-width: 100%;
        max-height: 95vh;
        overflow-x: hidden;
    }

    .search-results-container {
        padding: 0 0.5rem 8rem;
        margin-bottom: 8rem;
    }

    .search-result-item {
        padding: 0.5rem 0.6rem;
    }

    .result-content {
        max-width: calc(100% - 45px);
    }

    .result-title {
        font-size: 0.9rem;
        line-height: 1.25;
    }

    .result-subtitle {
        font-size: 0.75rem;
    }
}