/* ===========================================
   GLOBAL SEARCH PANEL - SecuCentral
   Pattern basé sur .notifications-panel
   =========================================== */

/* Variables (héritées de navbar-modern.css) */
.search-panel {
    --search-width: 28rem;
    --search-max-height: 32rem;
}

/* Panel principal */
.search-panel {
    position: absolute;
    top: calc(var(--navbar-height, 3.5rem) + 0.5rem);
    right: 8rem;
    width: var(--search-width);
    max-height: var(--search-max-height);
    background: var(--navbar-bg, #ffffff);
    border: 1px solid var(--navbar-border, #e5e7eb);
    border-radius: 0.75rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Animation - caché par défaut */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-0.5rem) scale(0.98);
    transition: all 0.2s ease-out;
    z-index: 1002;

    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.search-panel--active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header avec input */
.search-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--navbar-border, #e5e7eb);
    background: var(--navbar-bg, #ffffff);
}

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

.search-input-icon {
    position: absolute;
    left: 0.875rem;
    color: var(--text-secondary, #6b7280);
    font-size: 0.875rem;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.625rem 0.875rem 0.625rem 2.5rem;
    border: 1px solid var(--navbar-border, #e5e7eb);
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    color: var(--text-primary, #1f2937);
    background: var(--navbar-bg, #ffffff);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-blue, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-input::placeholder {
    color: var(--text-secondary, #6b7280);
}

.search-shortcut {
    position: absolute;
    right: 0.75rem;
    padding: 0.125rem 0.375rem;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 0.25rem;
    font-size: 0.6875rem;
    color: var(--text-secondary, #6b7280);
    font-family: system-ui, -apple-system, sans-serif;
}

/* Contenu scrollable */
.search-content {
    flex: 1;
    overflow-y: auto;
    max-height: calc(var(--search-max-height) - 4rem);
}

/* États */
.search-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary, #6b7280);
}

.search-state-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.search-state-text {
    font-size: 0.875rem;
    margin: 0;
}

.search-state-subtext {
    font-size: 0.75rem;
    margin-top: 0.25rem;
    opacity: 0.7;
}

/* Loading spinner */
.search-loading .search-state-icon {
    animation: spin 1s linear infinite;
}

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

/* Groupes de résultats */
.search-group {
    border-bottom: 1px solid var(--navbar-border, #e5e7eb);
}

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

.search-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.875rem;
    background: #f9fafb;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #6b7280);
}

.search-group-count {
    background: #e5e7eb;
    padding: 0.125rem 0.375rem;
    border-radius: 9999px;
    font-size: 0.625rem;
}

/* Items de résultat */
.search-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    transition: background-color 0.15s;
    text-decoration: none;
    color: inherit;
}

.search-item:hover,
.search-item--active {
    background: #f3f4f6;
}

.search-item--active {
    background: #e0e7ff;
}

.search-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    background: #e5e7eb;
    color: var(--text-secondary, #6b7280);
    font-size: 0.875rem;
    flex-shrink: 0;
}

.search-item-icon--user { background: #dbeafe; color: #2563eb; }
.search-item-icon--site { background: #dcfce7; color: #16a34a; }
.search-item-icon--report { background: #fef3c7; color: #d97706; }
.search-item-icon--alarm { background: #fee2e2; color: #dc2626; }
.search-item-icon--team { background: #f3e8ff; color: #9333ea; }

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

.search-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-item-title mark {
    background: #fef08a;
    color: inherit;
    padding: 0 0.125rem;
    border-radius: 0.125rem;
}

.search-item-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.125rem;
}

.search-item-meta {
    font-size: 0.6875rem;
    color: var(--text-secondary, #6b7280);
    opacity: 0.8;
    margin-top: 0.125rem;
}

/* Footer */
.search-footer {
    padding: 0.625rem 0.875rem;
    border-top: 1px solid var(--navbar-border, #e5e7eb);
    background: #f9fafb;
    text-align: center;
}

.search-footer-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--accent-blue, #3b82f6);
    text-decoration: none;
    font-weight: 500;
}

.search-footer-link:hover {
    text-decoration: underline;
}

/* Aide clavier (footer) */
.search-help {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.5rem 0.875rem;
    border-top: 1px solid var(--navbar-border, #e5e7eb);
    background: #f9fafb;
    font-size: 0.6875rem;
    color: var(--text-secondary, #6b7280);
}

.search-help-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.search-help-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.25rem;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    font-size: 0.625rem;
    font-weight: 500;
}

/* Dark mode */
[data-theme="dark"] .search-panel {
    --navbar-bg: #1e293b;
    --navbar-border: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .search-input {
    background: #0f172a;
    border-color: #334155;
}

[data-theme="dark"] .search-shortcut {
    background: #334155;
    border-color: #475569;
}

[data-theme="dark"] .search-group-header {
    background: #0f172a;
}

[data-theme="dark"] .search-group-count {
    background: #334155;
}

[data-theme="dark"] .search-item:hover,
[data-theme="dark"] .search-item--active {
    background: #334155;
}

[data-theme="dark"] .search-item--active {
    background: #3730a3;
}

[data-theme="dark"] .search-item-icon {
    background: #334155;
}

[data-theme="dark"] .search-footer,
[data-theme="dark"] .search-help {
    background: #0f172a;
}

[data-theme="dark"] .search-help-key {
    background: #334155;
    border-color: #475569;
}

[data-theme="dark"] .search-item-title mark {
    background: #854d0e;
}

/* ============================================
   CLASSES GENEREES PAR JS (search-result-*)
   ============================================ */

/* Groupes de résultats - Classes JS */
.search-result-group {
    border-bottom: 1px solid var(--navbar-border, #e5e7eb);
}

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

.search-result-group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: #f9fafb;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #6b7280);
}

.search-result-group-icon {
    font-size: 0.75rem;
    color: var(--accent-blue, #3b82f6);
}

.search-result-group-label {
    flex: 1;
}

.search-result-group-count {
    background: #e5e7eb;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.625rem;
    font-weight: 600;
}

.search-result-group-items {
    padding: 0.25rem 0;
}

/* Items de résultat - Classes JS */
.search-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    transition: background-color 0.15s;
    text-decoration: none;
    color: inherit;
}

.search-result-item:hover,
.search-result-item--selected {
    background: #f3f4f6;
}

.search-result-item:focus {
    outline: 2px solid var(--accent-blue, #3b82f6);
    outline-offset: -2px;
    background: #f3f4f6;
}

.search-result-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    background: #e5e7eb;
    color: var(--text-secondary, #6b7280);
    font-size: 0.875rem;
    flex-shrink: 0;
}

.search-result-item-icon--module { background: #e0e7ff; color: #4f46e5; }
.search-result-item-icon--user { background: #dbeafe; color: #2563eb; }
.search-result-item-icon--site { background: #dcfce7; color: #16a34a; }
.search-result-item-icon--client { background: #e0f2fe; color: #0284c7; }
.search-result-item-icon--report { background: #fef3c7; color: #d97706; }
.search-result-item-icon--alarm { background: #fee2e2; color: #dc2626; }
.search-result-item-icon--team { background: #f3e8ff; color: #9333ea; }
.search-result-item-icon--qr_point { background: #ccfbf1; color: #0d9488; }
.search-result-item-icon--equipment { background: #ffedd5; color: #ea580c; }

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

.search-result-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-item-title mark {
    background: #fef08a;
    color: inherit;
    padding: 0 0.125rem;
    border-radius: 0.125rem;
}

.search-result-item-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.125rem;
}

.search-result-item-meta {
    font-size: 0.6875rem;
    color: var(--text-secondary, #6b7280);
    opacity: 0.8;
    margin-top: 0.125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-item-arrow {
    color: var(--text-secondary, #6b7280);
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.search-result-item:hover .search-result-item-arrow {
    opacity: 1;
}

/* Actions rapides sur les résultats */
.search-result-item-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-result-item-wrapper .search-result-item {
    flex: 1;
    min-width: 0;
}

.search-result-item-wrapper.has-actions .search-result-item {
    padding-right: 0.5rem;
}

.search-result-item-actions {
    display: flex;
    gap: 0.375rem;
    padding-right: 0.75rem;
    flex-shrink: 0;
}

.search-result-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.875rem;
    height: 1.875rem;
    border-radius: 0.375rem;
    background: var(--accent-blue, #3b82f6);
    color: white;
    font-size: 0.8125rem;
    text-decoration: none;
    transition: all 0.15s;
    flex-shrink: 0;
}

.search-result-action:hover {
    background: var(--accent-blue-hover, #2563eb);
    transform: scale(1.1);
    color: white;
}

/* Dark mode - actions rapides */
[data-theme="dark"] .search-result-action {
    background: #3b82f6;
}

[data-theme="dark"] .search-result-action:hover {
    background: #60a5fa;
}

/* ============================================
   HISTORIQUE DE RECHERCHE
   ============================================ */

.search-history {
    padding: 0.5rem 0;
}

.search-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.875rem;
}

.search-history-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
}

.search-history-title i {
    margin-right: 0.375rem;
}

.search-history-clear {
    background: none;
    border: none;
    color: var(--accent-blue, #3b82f6);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.15s;
}

.search-history-clear:hover {
    background: rgba(59, 130, 246, 0.1);
}

.search-history-items {
    padding: 0;
}

.search-history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.875rem;
    cursor: pointer;
    transition: background-color 0.15s;
}

.search-history-item:hover {
    background: #f3f4f6;
}

.search-history-icon {
    color: var(--text-secondary, #6b7280);
    font-size: 0.75rem;
}

.search-history-text {
    font-size: 0.875rem;
    color: var(--text-primary, #1f2937);
}

/* ============================================
   ÉTATS DE RECHERCHE (variantes)
   ============================================ */

.search-state--loading .search-state-icon {
    animation: spin 1s linear infinite;
    opacity: 1;
}

.search-state--error .search-state-icon,
.search-state-icon--error {
    color: #dc2626;
    opacity: 1;
}

.search-state-message {
    font-size: 0.875rem;
    margin: 0;
    color: var(--text-secondary, #6b7280);
}

.search-state-hint {
    font-size: 0.75rem;
    margin-top: 0.5rem;
    opacity: 0.7;
    color: var(--text-secondary, #6b7280);
}

.search-state-retry {
    margin-top: 0.75rem;
    padding: 0.375rem 0.75rem;
    background: var(--accent-blue, #3b82f6);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background-color 0.15s;
}

.search-state-retry:hover {
    background: var(--accent-blue-hover, #2563eb);
}

/* ============================================
   DARK MODE - Classes JS
   ============================================ */

[data-theme="dark"] .search-result-group-header {
    background: #0f172a;
}

[data-theme="dark"] .search-result-group-count {
    background: #334155;
}

[data-theme="dark"] .search-result-item:hover,
[data-theme="dark"] .search-result-item--selected {
    background: #334155;
}

[data-theme="dark"] .search-result-item-icon {
    background: #334155;
}

[data-theme="dark"] .search-result-item-icon--module { background: rgba(79, 70, 229, 0.2); color: #a5b4fc; }
[data-theme="dark"] .search-result-item-icon--user { background: rgba(37, 99, 235, 0.2); color: #93c5fd; }
[data-theme="dark"] .search-result-item-icon--site { background: rgba(22, 163, 74, 0.2); color: #86efac; }
[data-theme="dark"] .search-result-item-icon--client { background: rgba(2, 132, 199, 0.2); color: #7dd3fc; }
[data-theme="dark"] .search-result-item-icon--report { background: rgba(217, 119, 6, 0.2); color: #fcd34d; }
[data-theme="dark"] .search-result-item-icon--alarm { background: rgba(220, 38, 38, 0.2); color: #fca5a5; }
[data-theme="dark"] .search-result-item-icon--team { background: rgba(147, 51, 234, 0.2); color: #d8b4fe; }
[data-theme="dark"] .search-result-item-icon--qr_point { background: rgba(13, 148, 136, 0.2); color: #5eead4; }
[data-theme="dark"] .search-result-item-icon--equipment { background: rgba(234, 88, 12, 0.2); color: #fdba74; }

[data-theme="dark"] .search-result-item-title mark {
    background: #854d0e;
}

[data-theme="dark"] .search-history-item:hover {
    background: #334155;
}

[data-theme="dark"] .search-state-retry {
    background: #3b82f6;
}

/* Responsive */
@media (max-width: 640px) {
    .search-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 100%;
        border-radius: 0;
        transform: translateY(100%);
    }

    .search-panel--active {
        transform: translateY(0);
    }

    .search-content {
        max-height: calc(100vh - 8rem);
    }

    .search-shortcut {
        display: none;
    }
}
