/**
 * AI Search Bar Styles — ai-search.css
 *
 * Scoped to .neuhaus-ai-search. Inherits site font stack and relies on the
 * CSS variables already defined in neuhaus-vow.css (--neuhaus-primary, etc.).
 * Falls back to literal values so the bar works even if variables are missing.
 */

/* ==========================================================================
   Container
   ========================================================================== */

.neuhaus-ai-search {
    background: #ffffff;
    border: 1px solid var(--neuhaus-border, #e2e8f0);
    border-radius: var(--neuhaus-radius, 8px);
    box-shadow: var(--neuhaus-shadow, 0 1px 3px rgba(0,0,0,0.1));
    padding: 14px 16px;
    margin-bottom: 16px;
    max-height: 280px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
    transition: box-shadow 0.15s ease;
}

.neuhaus-ai-search:focus-within {
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.15), var(--neuhaus-shadow, 0 1px 3px rgba(0,0,0,0.1));
    border-color: var(--neuhaus-secondary, #2b6cb0);
}

/* ==========================================================================
   Header row (icon + label + badge)
   ========================================================================== */

.ai-search-header {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.ai-search-icon {
    color: var(--neuhaus-primary, #1a365d);
    flex-shrink: 0;
}

.ai-search-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--neuhaus-primary, #1a365d);
    letter-spacing: 0.01em;
}

.ai-search-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #ffffff;
    background: var(--neuhaus-primary, #1a365d);
    border-radius: 3px;
    padding: 1px 5px;
    line-height: 1.4;
}

/* ==========================================================================
   Conversation area
   ========================================================================== */

.ai-search-conversation {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    max-height: 110px;
    padding-left: 274px;
    padding-right: 89px;

    /* Smooth scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--neuhaus-border, #e2e8f0) transparent;
}

.ai-search-conversation::-webkit-scrollbar {
    width: 4px;
}

.ai-search-conversation::-webkit-scrollbar-track {
    background: transparent;
}

.ai-search-conversation::-webkit-scrollbar-thumb {
    background-color: var(--neuhaus-border, #e2e8f0);
    border-radius: 2px;
}

/* Message bubbles */
.ai-msg {
    display: inline-block;
    max-width: 75%;
    padding: 6px 10px;
    border-radius: 12px;
    font-size: 0.8125rem;
    line-height: 1.45;
    word-break: break-word;
}

.ai-msg--user {
    align-self: flex-end;
    background: var(--neuhaus-primary, #1a365d);
    color: #ffffff;
    border-bottom-right-radius: 3px;
}

.ai-msg--assistant {
    align-self: flex-start;
    background: var(--color-gray-100, #f1f5f9);
    color: var(--neuhaus-text, #2d3748);
    border-bottom-left-radius: 3px;
    border: 1px solid var(--neuhaus-border, #e2e8f0);
}

/* ==========================================================================
   Input row
   ========================================================================== */

.ai-search-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ai-search-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 9px 12px;
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--neuhaus-text, #2d3748);
    background: var(--color-gray-50, #f9fafb);
    border: 1px solid var(--neuhaus-border, #e2e8f0);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.ai-search-input::placeholder {
    color: var(--neuhaus-text-light, #718096);
    font-size: 0.875rem;
}

.ai-search-input:focus {
    border-color: var(--neuhaus-secondary, #2b6cb0);
    background: #ffffff;
}

.ai-search-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Submit/send button */
.ai-search-submit {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 6px;
    background: var(--neuhaus-primary, #1a365d);
    color: #ffffff;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    padding: 0;
}

.ai-search-submit:hover:not(:disabled) {
    background: var(--neuhaus-secondary, #2b6cb0);
}

.ai-search-submit:active:not(:disabled) {
    transform: scale(0.95);
}

.ai-search-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   Footer row (result count + clear)
   ========================================================================== */

.ai-search-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
    border-top: 1px solid var(--neuhaus-border, #e2e8f0);
    padding-top: 8px;
    margin-top: 2px;
}

.ai-search-count {
    font-size: 0.8125rem;
    color: var(--neuhaus-text-light, #718096);
}

.ai-search-clear {
    font-size: 0.8125rem;
    color: var(--neuhaus-secondary, #2b6cb0);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-search-clear:hover {
    color: var(--neuhaus-primary, #1a365d);
}

/* ==========================================================================
   Loading state
   ========================================================================== */

.ai-search-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--neuhaus-text-light, #718096);
    flex-shrink: 0;
}

/* Spinner ring */
.ai-search-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--neuhaus-border, #e2e8f0);
    border-top-color: var(--neuhaus-secondary, #2b6cb0);
    border-radius: 50%;
    animation: ai-spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Fallback wrapper — hidden by default; JS swaps visibility on init failure
   ========================================================================== */

.neuhaus-classic-search-fallback {
    /* Shown by default until JS hides it — no display:none so noscript users see it */
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 480px) {
    .neuhaus-ai-search {
        padding: 12px;
        max-height: 260px;
    }

    .ai-search-input {
        font-size: 1rem; /* Prevent iOS auto-zoom on focus */
    }

    .ai-msg {
        max-width: 95%;
    }
}

/* Fix: hidden attribute must win over display: flex */
.ai-search-loading[hidden],
.ai-search-conversation[hidden],
.ai-search-footer[hidden] {
    display: none !important;
}
