/**
 * Unified Search Styles
 * Styles for the combined docs/map search functionality
 */

/* Search Container */
.unified-search-container {
    position: relative;
    max-width: 400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Search Mode Toggle */
.search-mode-toggle {
    display: flex;
    gap: 0;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.search-mode-btn {
    padding: 0.4rem 0.4rem;
    border: 1px solid #ddd;
    background: white;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    white-space: nowrap;
    min-width: 60px;
}

.search-mode-btn:first-child {
    border-right: none;
}

.search-mode-btn:hover {
    background: #f8f9fa;
    color: #333;
}

.search-mode-btn.active {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.search-mode-btn.active:hover {
    background: #45a049;
}

/* Search Wrapper */
.unified-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
}

.unified-search-input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    background: white;
    transition: all 0.2s ease;
    outline: none;
}

.unified-search-input:focus {
    border-color: #4CAF50;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.unified-search-input::placeholder {
    color: #999;
    font-style: italic;
}

.unified-search-icon {
    position: absolute;
    right: 0.75rem;
    color: #4a5568;
    pointer-events: none;
    font-size: 1.1rem;
}

/* Search Results Container */
.unified-search-results {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    background: #2d3748;
    border: 1px solid #4a5568;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 400px;
    overflow-y: auto;
    z-index: 12100;
    /* Ensure results appear above other content */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.unified-search-results.hidden {
    display: none;
}

/* Results Header */
.unified-search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: #1a202c;
    border-bottom: 1px solid #4a5568;
    font-size: 0.85rem;
    color: #e2e8f0;
}

.results-count {
    font-weight: 500;
}

.close-results {
    background: none;
    border: none;
    color: #cbd5e0;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.close-results:hover {
    background: #4a5568;
    color: #ffffff;
}

/* Results List */
.unified-search-results-list {
    max-height: 350px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Search Result Items */
.search-result-item {
    padding: 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: block;
    text-decoration: none;
    color: inherit;
}

.search-result-item:hover {
    background: #4a5568;
}

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

/* Docs Search Results */
.search-result-docs .result-title {
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.search-result-docs .result-excerpt {
    color: #e2e8f0;
    font-size: 0.85rem;
    line-height: 1.4;
    margin-bottom: 0.25rem;
}

.search-result-docs .result-excerpt mark {
    background: #ffd700;
    color: #1a1a1a;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 500;
}

@media (prefers-color-scheme: dark) {
    .search-result-docs .result-excerpt mark {
        background: #f59e0b;
        color: #1f2937;
    }
}

.search-result-docs .result-path {
    color: #cbd5e0;
    font-size: 0.75rem;
    font-style: italic;
}

/* Map Search Results */
.search-result-map .result-address {
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.search-result-map .result-full-address {
    color: #e2e8f0;
    font-size: 0.85rem;
    line-height: 1.4;
    margin-bottom: 0.25rem;
}

.search-result-map .result-coordinates {
    color: #cbd5e0;
    font-size: 0.75rem;
    font-family: monospace;
}

.search-result-map::before {
    content: "📍";
    margin-right: 0.5rem;
}

/* Database Search Results */
.search-result-database .result-name {
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.search-result-database .result-address {
    color: #e2e8f0;
    font-size: 0.85rem;
    line-height: 1.4;
    margin-bottom: 0.25rem;
}

.search-result-database .result-snippet {
    color: #cbd5e0;
    font-size: 0.8rem;
    line-height: 1.3;
    margin-bottom: 0.25rem;
}

.search-result-database .result-snippet mark {
    background: #ffd700;
    color: #1a1a1a;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 500;
}

.search-result-database .result-details {
    color: #a0aec0;
    font-size: 0.75rem;
    font-family: monospace;
}

.search-result-database::before {
    content: "👤";
    margin-right: 0.5rem;
}

/* Loading State */
.search-loading {
    padding: 1rem;
    text-align: center;
    color: #e2e8f0;
    font-style: italic;
}

.search-loading::before {
    content: "🔄";
    margin-right: 0.5rem;
    animation: spin 1s linear infinite;
}

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

/* No Results */
.search-no-results {
    padding: 1rem;
    text-align: center;
    color: #cbd5e0;
    font-style: italic;
}

/* QR Code Button Styles */
.make-qr-btn {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-color);
    border: 1px solid var(--btn-secondary-border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 10;
}

.make-qr-btn:hover {
    background: var(--btn-secondary-hover-bg);
    color: var(--btn-secondary-hover-color);
    border-color: var(--btn-secondary-hover-border);
    transform: translateY(-50%) scale(1.05);
}

.make-qr-btn .btn-icon {
    font-size: 14px;
    line-height: 1;
}

.make-qr-btn .btn-text {
    font-size: 11px;
    font-weight: 600;
}

/* Adjust result item to make room for QR button */
.search-result-docs {
    position: relative;
    padding-right: 80px !important;
}

.search-result-docs .search-result-link {
    display: block;
    color: inherit;
    text-decoration: none;
    padding: 16px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.search-result-docs .search-result-link:hover {
    background-color: var(--search-result-hover-bg);
}

/* QR Modal Specific Styles */
.qr-modal .modal-content {
    max-width: 400px;
}

.qr-modal-body {
    text-align: center;
}

.qr-loading {
    color: var(--text-secondary, #666);
    font-style: italic;
    padding: 20px;
}

.qr-loading .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

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

.qr-code-image {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid #ddd;
    background: white;
    padding: 10px;
}

.qr-error {
    color: var(--error-color, #e74c3c);
    font-style: italic;
    padding: 20px;
}

.qr-code-info {
    margin-top: 15px;
}

.qr-code-info p {
    margin: 0 0 10px 0;
    color: var(--text-secondary, #666);
    font-size: 14px;
}

.qr-code-url {
    word-break: break-all;
    color: var(--primary-color, #4CAF50);
    font-size: 14px;
    text-decoration: none;
    background: var(--bg-light, #f5f5f5);
    padding: 8px 12px;
    border-radius: 4px;
    font-family: monospace;
    display: inline-block;
    max-width: 100%;
}

.qr-code-url:hover {
    text-decoration: underline;
}

/* Button color variables for consistency */
:root {
    --btn-secondary-bg: #6c757d;
    --btn-secondary-color: white;
    --btn-secondary-border: #6c757d;
    --btn-secondary-hover-bg: #5a6268;
    --btn-secondary-hover-color: white;
    --btn-secondary-hover-border: #545b62;
    --error-color: #e74c3c;
}

/* Dark theme adjustments */
@media (prefers-color-scheme: dark) {
    :root {
        --btn-secondary-bg: #495057;
        --btn-secondary-color: #e9ecef;
        --btn-secondary-border: #495057;
        --btn-secondary-hover-bg: #343a40;
        --btn-secondary-hover-color: white;
        --btn-secondary-hover-border: #343a40;
    }
    .unified-search-container {
        max-width: 100%;
        margin: 0;
        flex-direction: row;
        gap: 0.25rem;
        align-items: stretch;
    }
    
    .search-mode-toggle {
        flex-shrink: 0;
        align-self: stretch;
    }
    
    .search-mode-btn {
        padding: 0.5rem 0.3rem;
        font-size: 0.65rem;
        min-height: 44px; /* Touch target size */
        display: flex;
        flex-direction: column;
        gap: 0.1rem;
        line-height: 1;
    }
    
    .unified-search-wrapper {
        flex: 1;
        min-width: 0; /* Allow shrinking */
    }
    
    .unified-search-input {
        padding: 0.75rem 2.5rem 0.75rem 0.75rem;
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px; /* Touch target size */
        box-sizing: border-box;
    }
    
    .unified-search-icon {
        right: 0.75rem;
        font-size: 1rem;
    }
    
    .unified-search-results {
        max-height: 60vh; /* Use viewport height on mobile */
        left: -0.25rem;
        right: -0.25rem;
        border-radius: 8px;
        margin-top: 0.5rem;
    }
    
    .search-result-item {
        padding: 0.75rem;
        min-height: 44px; /* Touch target size */
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .search-result-docs .result-title,
    .search-result-map .result-address {
        font-size: 0.95rem;
        margin-bottom: 0.4rem;
    }
    
    .search-result-docs .result-excerpt,
    .search-result-map .result-full-address {
        font-size: 0.85rem;
        line-height: 1.3;
        margin-bottom: 0.3rem;
    }
    
    .search-result-docs .result-path,
    .search-result-map .result-coordinates {
        font-size: 0.75rem;
    }
}

/* Touch-friendly improvements for mobile */
@media (hover: none) and (pointer: coarse) {
    .search-mode-btn,
    .search-result-item,
    .close-results {
        min-height: 44px; /* iOS touch target recommendation */
    }
    
    .search-mode-btn {
        padding: 0.6rem 0.4rem;
    }
    
    .search-result-item {
        padding: 0.8rem;
    }
    
    /* Improve tap targets */
    .search-result-item:active {
        background: #4a5568;
        transform: scale(0.98);
        transition: all 0.1s ease;
    }
    
    .search-mode-btn:active {
        transform: scale(0.95);
        transition: all 0.1s ease;
    }
}

/* Very small screens (phones in portrait) */
@media (max-width: 480px) {
    .unified-search-container {
        gap: 0.15rem;
    }
    
    .search-mode-btn {
        padding: 0.25rem 0.15rem;
        font-size: 0.6rem;
        min-width: 45px;
    }
    
    .unified-search-input {
        font-size: 16px; /* Prevent zoom */
        padding: 0.7rem 2.2rem 0.7rem 0.6rem;
    }
    
    .unified-search-results {
        left: -0.5rem;
        right: -0.5rem;
        max-height: 50vh;
    }
    
    .search-result-item {
        padding: 0.7rem 0.6rem;
    }
}

/* Mobile adjustments for three buttons */
@media (max-width: 768px) {
    .search-mode-btn {
        padding: 0.3rem 0.2rem;
        font-size: 0.65rem;
        min-width: 50px;
    }
}

/* Touch-friendly improvements for mobile */
@media (hover: none) and (pointer: coarse) {
    .search-mode-btn,
    .search-result-item {
        min-height: 44px; /* iOS touch target recommendation */
    }
    
    .search-mode-btn {
        padding: 0.6rem 0.75rem;
    }
}

/* Dark mode support (if needed in the future) */
@media (prefers-color-scheme: dark) {
    .search-mode-btn {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .search-mode-btn:hover {
        background: #4a5568;
    }
    
    .search-mode-btn.active {
        background: #38a169;
        border-color: #38a169;
    }
    
    .unified-search-input {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .unified-search-input::placeholder {
        color: #a0aec0;
    }
    
    .unified-search-results {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .unified-search-results-header {
        background: #1a202c;
        border-color: #4a5568;
        color: #a0aec0;
    }
    
    .search-result-item:hover {
        background: #4a5568;
    }
}

/* Temporary Search Marker Styles */
.temp-search-marker {
    background: none !important;
    border: none !important;
    font-size: 24px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    animation: bounce 1s ease-in-out;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

/* Search Result Popup Styles */
.search-result-popup h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    color: #1a202c;
}

.search-result-popup p {
    margin: 0 0 0.75rem 0;
    font-size: 0.85rem;
    color: #4a5568;
}

.popup-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.popup-actions .btn {
    flex: 1;
    min-width: 80px;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
}
