/**
 * PercentagePro - Search Styles
 * Premium search UI with glassmorphism, header search, and dark mode support
 */

/* ============================================
   Header Inline Search Bar
   ============================================ */

.header-search {
    display: flex;
    align-items: center;
    position: relative;
    flex: 1;
    max-width: 400px;
    margin: 0 24px;
    background: #f1f5f9;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 8px 14px;
    transition: all 0.2s ease;
    z-index: 1001;
    /* Ensure search box stays above dropdown */
}

.header-search:focus-within {
    background: white;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.header-search-icon {
    font-size: 1rem;
    margin-right: 10px;
    opacity: 0.5;
}

.header-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.9rem;
    font-family: inherit;
    color: #1e293b;
    min-width: 0;
}

.header-search-input::placeholder {
    color: #94a3b8;
}

.header-search-shortcut {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #64748b;
    font-family: inherit;
    white-space: nowrap;
}

/* Header Search Results Dropdown */
.header-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.header-search-results.active {
    display: block;
}

.header-search-results::-webkit-scrollbar {
    width: 6px;
}

.header-search-results::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Header Result Items */
.header-result-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    text-decoration: none;
    color: inherit;
    gap: 12px;
    transition: background 0.15s ease;
}

.header-result-item:hover,
.header-result-item.active {
    background: rgba(37, 99, 235, 0.08);
    text-decoration: none;
}

.header-result-item .result-icon {
    font-size: 1.25rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: 8px;
}

.header-result-item .result-info {
    flex: 1;
    min-width: 0;
}

.header-result-item .result-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-result-item .result-name mark {
    background: rgba(37, 99, 235, 0.2);
    color: #2563eb;
    padding: 0 2px;
    border-radius: 2px;
}

.header-result-item .result-category {
    font-size: 0.75rem;
    color: #64748b;
}

/* Header Search Empty State */
.header-search-empty {
    padding: 24px;
    text-align: center;
    color: #64748b;
}

.header-search-empty-icon {
    font-size: 2rem;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* Mobile: Hide header search, show toggle */
@media (max-width: 900px) {
    .header-search {
        display: none;
    }
}

/* ============================================
   Mobile Search Toggle Button
   ============================================ */

.mobile-search-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--color-gray-200, #e2e8f0);
    background: var(--color-gray-100, #f1f5f9);
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    margin-right: 8px;
}

.mobile-search-toggle:hover {
    background: var(--color-gray-200, #e2e8f0);
}

.mobile-search-toggle:active {
    background: var(--color-gray-300, #cbd5e1);
}

@media (max-width: 900px) {
    .mobile-search-toggle {
        display: flex;
    }
}

/* Dark Mode */
[data-theme="dark"] .mobile-search-toggle {
    background: #334155;
    border-color: #475569;
}

[data-theme="dark"] .mobile-search-toggle:hover {
    background: #475569;
}

/* ============================================
   Search Modal Overlay
   ============================================ */

.search-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.search-modal.active {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 10vh;
    opacity: 1;
}

.search-modal-content {
    width: 100%;
    max-width: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    transform: translateY(-20px);
    animation: searchModalSlideIn 0.25s ease forwards;
}

@keyframes searchModalSlideIn {
    to {
        transform: translateY(0);
    }
}

/* Search Input */
.search-input-wrapper {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    gap: 12px;
}

.search-icon {
    font-size: 1.25rem;
    opacity: 0.5;
}

#search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1.125rem;
    font-family: inherit;
    background: transparent;
    color: #1e293b;
}

#search-input::placeholder {
    color: #94a3b8;
}

.search-shortcut {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: #64748b;
    background: #f1f5f9;
    padding: 4px 8px;
    border-radius: 6px;
}

.search-shortcut kbd {
    font-family: inherit;
    font-weight: 600;
}

/* Search Results */
.search-results {
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}

.search-results::-webkit-scrollbar {
    width: 8px;
}

.search-results::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.search-results::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* Empty State */
.search-empty {
    padding: 40px 20px;
    text-align: center;
    color: #64748b;
}

.search-empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.search-empty-text {
    font-size: 1rem;
    margin-bottom: 8px;
}

.search-empty-hint {
    font-size: 0.875rem;
    color: #94a3b8;
}

.search-no-results {
    padding: 40px 20px;
    text-align: center;
    color: #64748b;
}

/* Search Result Items */
.search-result-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    color: inherit;
    gap: 14px;
}

.search-result-item:hover,
.search-result-item.active {
    background: rgba(37, 99, 235, 0.08);
    text-decoration: none;
}

.result-icon {
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: 10px;
    transition: transform 0.15s ease;
}

.search-result-item:hover .result-icon {
    transform: scale(1.1);
}

.result-info {
    flex: 1;
    min-width: 0;
}

.result-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: #1e293b;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-name mark {
    background: rgba(37, 99, 235, 0.2);
    color: #2563eb;
    padding: 0 2px;
    border-radius: 2px;
}

.result-category {
    font-size: 0.8rem;
    color: #64748b;
}

.result-arrow {
    font-size: 1rem;
    color: #94a3b8;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.search-result-item:hover .result-arrow {
    opacity: 1;
}

/* Search Footer */
.search-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    font-size: 0.75rem;
    color: #64748b;
}

.search-footer-hint {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-footer-hint span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.search-footer-hint kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    font-family: inherit;
}

/* Mobile Modal */
@media (max-width: 640px) {
    .search-modal.active {
        padding-top: 0;
        align-items: stretch;
    }

    .search-modal-content {
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .search-results {
        flex: 1;
        max-height: none;
    }

    .search-shortcut {
        display: none;
    }
}

/* ============================================
   Dark Mode
   ============================================ */

/* Header Search Dark Mode */
[data-theme="dark"] .header-search {
    background: #334155;
    border-color: transparent;
}

[data-theme="dark"] .header-search:focus-within {
    background: #1e293b;
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

[data-theme="dark"] .header-search-input {
    color: #f8fafc;
}

[data-theme="dark"] .header-search-input::placeholder {
    color: #94a3b8;
}

[data-theme="dark"] .header-search-shortcut {
    background: #475569;
    border-color: #64748b;
    color: #e2e8f0;
}

[data-theme="dark"] .header-search-results {
    background: #1e293b;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .header-result-item:hover,
[data-theme="dark"] .header-result-item.active {
    background: rgba(96, 165, 250, 0.1);
}

[data-theme="dark"] .header-result-item .result-icon {
    background: #334155;
}

[data-theme="dark"] .header-result-item .result-name {
    color: #f8fafc;
}

[data-theme="dark"] .header-result-item .result-name mark {
    background: rgba(96, 165, 250, 0.3);
    color: #60a5fa;
}

[data-theme="dark"] .header-result-item .result-category {
    color: #94a3b8;
}

[data-theme="dark"] .header-search input::placeholder {
    color: #cbd5e1;
}

[data-theme="dark"] .header-search-icon {
    color: #cbd5e1;
}

[data-theme="dark"] .header-search-empty {
    color: #94a3b8;
}

/* Modal Dark Mode */
[data-theme="dark"] .search-modal {
    background: rgba(0, 0, 0, 0.8);
}

[data-theme="dark"] .search-modal-content {
    background: #1e293b;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .search-input-wrapper {
    border-color: #334155;
}

[data-theme="dark"] #search-input {
    color: #f8fafc;
}

[data-theme="dark"] .search-shortcut {
    background: #334155;
    color: #94a3b8;
}

[data-theme="dark"] .search-results::-webkit-scrollbar-track {
    background: #1e293b;
}

[data-theme="dark"] .search-results::-webkit-scrollbar-thumb {
    background: #475569;
}

[data-theme="dark"] .search-empty,
[data-theme="dark"] .search-no-results {
    color: #94a3b8;
}

[data-theme="dark"] .search-result-item:hover,
[data-theme="dark"] .search-result-item.active {
    background: rgba(96, 165, 250, 0.1);
}

[data-theme="dark"] .result-icon {
    background: #334155;
}

[data-theme="dark"] .result-name {
    color: #f8fafc;
}

[data-theme="dark"] .result-name mark {
    background: rgba(96, 165, 250, 0.3);
    color: #60a5fa;
}

[data-theme="dark"] .result-category {
    color: #94a3b8;
}

[data-theme="dark"] .search-footer {
    background: #0f172a;
    border-color: #334155;
    color: #cbd5e1;
}

[data-theme="dark"] .search-footer-hint kbd {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}