/* search.css - Modern, simplified search interface */

/* =========================
   MODERN SEARCH INTERFACE
   ========================= */

.search-container {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

.search-input-container {
    margin-bottom: 1.5rem;
}

.search-input-wrapper {
    position: relative;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 16px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    flex: 1;
    min-width: 0;
}

.search-input-wrapper:hover {
    border-color: #d1d5db;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.search-input-wrapper:focus-within {
    border-color: var(--clover-purple);
    box-shadow: 0 4px 16px rgba(60, 120, 253, 0.15);
}

.search-textarea {
    border: none;
    outline: none;
    background: transparent;
    width: 100%;
    padding: 20px 70px 20px 24px;
    font-size: 16px;
    line-height: 1.5;
    color: #1f2937;
    resize: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.search-textarea::placeholder {
    color: #9ca3af;
    font-weight: 400;
}

/* Actions container (mic + submit) positioned inside input wrapper */
.search-actions {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 2;
}

.search-submit-btn {
    background: var(--clover-purple);
    border: none;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s ease;
    cursor: pointer;
    flex-shrink: 0;
}

.search-submit-btn:hover:not(:disabled) {
    background: #2b5fd9;
    transform: scale(1.05);
}

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

.search-submit-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

/* =========================
   CHARACTER COUNTER
   ========================= */

.char-counter-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 24px 0;
    font-size: 11px;
}

.char-counter {
    color: #9ca3af;
    font-size: 11px;
    white-space: nowrap;
}

.char-counter.warning {
    color: #d97706;
}

.char-counter.danger {
    color: #dc2626;
    font-weight: 600;
}

.char-limit-upsell {
    color: #9ca3af;
    font-size: 11px;
}

.char-limit-upsell a {
    color: var(--clover-purple);
    text-decoration: none;
    font-weight: 500;
}

.char-limit-upsell a:hover {
    text-decoration: underline;
}

/* =========================
   QUERY TEMPLATES
   ========================= */

.query-templates {
    margin-top: 16px;
}

.template-label {
    margin-bottom: 12px;
}

.template-label-text {
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.template-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.template-btn {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.template-btn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.template-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.template-icon {
    font-size: 16px;
    opacity: 0.8;
}

/* =========================
   SEARCH PROCESSING
   ========================= */

.processing-step {
    transition: all 0.3s ease;
    opacity: 0.5;
    border-radius: 8px;
}

.processing-step.active {
    opacity: 1;
    background-color: #f0f5ff;
    box-shadow: 0 2px 4px rgba(60, 120, 253, 0.1);
}

.processing-step.completed {
    opacity: 1;
    background-color: #f0f9f0;
    box-shadow: 0 2px 4px rgba(25, 135, 84, 0.1);
}

.processing-step.error {
    opacity: 1;
    background-color: #ffebee;
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.1);
}

.step-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 14px;
}

.step-icon.pending {
    background-color: #6c757d;
    color: white;
}

.step-icon.active {
    background-color: var(--clover-purple);
    color: white;
    animation: pulse 2s infinite;
}

.step-icon.completed {
    background-color: #198754;
    color: white;
}

.step-icon.error {
    background-color: #dc3545;
    color: white;
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(60, 120, 253, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(60, 120, 253, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(60, 120, 253, 0); }
}

.search-insights {
    background: linear-gradient(90deg, var(--gradient-cyan) 0%, var(--gradient-purple) 100%);
    color: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 1rem;
    box-shadow: 0 4px 15px rgba(60, 120, 253, 0.3);
}

.insight-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 14px;
}

.insight-icon {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    opacity: 0.9;
    font-size: 16px;
}

/* =========================
   PDF ATTACHMENT INTEGRATION
   ========================= */

/* New flex container for external PDF button */
/* In-wrapper attachment button: paperclip pinned inside the input's left
   edge (the textarea reserves room via .has-pdf-button). Plan gating shows
   the lock overlay + disabled state; attached files light it up via
   .has-files and the count badge. */
.pdf-attachment-button {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 8px 6px;
    border-radius: var(--tri-radius-md);
    color: var(--tri-fg-2);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: auto;
    font-size: 18px;
    z-index: 2;
    gap: 2px;
}

.pdf-attachment-button:hover:not(:disabled) {
    background: var(--tri-bg-hover);
    color: var(--tri-fg-1);
    transform: translateY(-50%) scale(1.05);
}

.pdf-attachment-button:focus-visible {
    outline: 2px solid var(--clover-purple);
    outline-offset: 2px;
}

.pdf-attachment-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: translateY(-50%);
}

.pdf-attachment-button.has-files {
    color: var(--clover-purple);
    background: #f0f5ff;
}

.pdf-attachment-button.has-files:hover {
    background: #e0ebff;
    color: #2b5fd9;
}

.pdf-button-content {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pdf-file-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--clover-purple);
    color: white;
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.pdf-lock-overlay {
    position: absolute;
    bottom: -2px;
    right: -2px;
    font-size: 10px;
    color: #dc2626;
}


/* =========================
   AUDIO INPUT BUTTON (INLINE)
   ========================= */

.audio-input-btn-inline {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.audio-input-btn-inline:hover:not(.listening):not(:disabled) {
    color: #6b7280;
    background: #f3f4f6;
}

.audio-input-btn-inline--unsupported,
.audio-input-btn-inline:disabled {
    color: #d1d5db;
    cursor: not-allowed;
    background: transparent;
}

.audio-input-btn-inline--unsupported:hover,
.audio-input-btn-inline:disabled:hover {
    color: #d1d5db;
    background: transparent;
}

.audio-input-btn-inline.listening {
    color: #dc2626;
    background: #fef2f2;
}

.audio-input-btn-inline.listening:hover {
    background: #fee2e2;
    color: #b91c1c;
}

/* Recording ripple animation */
.audio-input-btn-inline.listening::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid #fca5a5;
    animation: mic-ripple 1.5s ease-out infinite;
    pointer-events: none;
}

@keyframes mic-ripple {
    0% {
        width: 36px;
        height: 36px;
        opacity: 0.8;
    }
    100% {
        width: 56px;
        height: 56px;
        opacity: 0;
    }
}

/* File chips: search-page margin override (base styles in file-chips.css) */
.file-chips-container {
    margin-left: 0; /* Chips align with the input wrapper edge */
}

/* Textarea reserves room for the in-wrapper attachment button */
.search-textarea.has-pdf-button {
    padding-left: 52px;
}

/* =========================
   RESPONSIVE DESIGN
   ========================= */

@media (max-width: 768px) {
    .search-textarea {
        padding: 16px 60px 16px 20px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .search-textarea.has-pdf-button {
        padding-left: 52px;
    }

    .search-actions {
        right: 10px;
    }

    .search-submit-btn {
        width: 40px;
        height: 40px;
    }

    .template-buttons {
        flex-direction: column;
    }

    .template-btn {
        justify-content: center;
        text-align: center;
    }

    /* Audio input inline button mobile styles */
    .audio-input-btn-inline {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .audio-input-btn-inline.listening::before {
        width: 32px;
        height: 32px;
    }

    /* Legacy internal PDF button mobile styles */
    .pdf-attachment-button {
        min-width: 36px;
        height: auto;
        font-size: 16px;
        padding: 6px 4px;
    }

    .file-chips-container {
        margin-left: 64px; /* Smaller margin for mobile */
    }
}

/* =========================
   UTILITY ANIMATIONS
   ========================= */

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

.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

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

.stage-spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(var(--bs-primary-rgb), 0.2);
    border-radius: 50%;
    border-top-color: var(--bs-primary);
    animation: spin 1s ease-in-out infinite;
    display: inline-block;
    margin-right: 0.25rem;
}

/* =========================
   QUERY IMPROVER (Mejorador de consultas)
   ========================= */

/* Inline sparkles button, visually paired with the mic button */
.query-improver-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--clover-purple);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.query-improver-btn:hover:not(:disabled) {
    background: #f3f0fa;
}

.query-improver-btn:disabled {
    color: #d1d5db;
    cursor: not-allowed;
    background: transparent;
}

/* Widen the textarea's right padding to clear the third action button.
   Measured cluster widths (2026-07 UX review): ~136px mobile, ~200px desktop
   (the submit button's fixed 44px width never applies while its text span
   renders — flex auto-minimum-size wins), so pad with real headroom. */
.search-input-wrapper.has-query-improver .search-textarea {
    padding-right: 140px !important; /* Mobile: improver + icon-only submit */
}

@media (min-width: 576px) {
    .search-input-wrapper.has-query-improver .search-textarea {
        padding-right: 200px !important; /* Desktop: improver + mic + submit with text */
    }
}

/* Suggestion popover, anchored above the composer input. Lives inside
   .search-input-wrapper (position: relative), so it floats over the page
   without reflowing it and stays edge-aligned with the textarea. */
.query-improver-container {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 0;
    right: 0;
    z-index: 20;
}

@keyframes query-improver-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.query-improver-card,
.query-improver-error {
    animation: query-improver-in 0.18s ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .query-improver-card,
    .query-improver-error {
        animation: none;
    }
}

/* The card is the input surface (the textarea inside is borderless), so it
   carries the focus ring, mirroring the main composer's wrapper. */
.query-improver-card {
    position: relative;
    background: #fff;
    border: 1px solid rgba(60, 120, 253, 0.4);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(26, 35, 50, 0.16);
    padding: 0.75rem 1rem 0.625rem;
}

.query-improver-card:focus-within {
    border-color: var(--clover-purple);
    box-shadow:
        0 0 0 3px rgba(60, 120, 253, 0.15),
        0 12px 32px rgba(26, 35, 50, 0.16);
}

/* Caret pointing down at the textarea the suggestion belongs to */
.query-improver-card::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 26px;
    width: 11px;
    height: 11px;
    background: #fff;
    border-right: 1px solid rgba(60, 120, 253, 0.4);
    border-bottom: 1px solid rgba(60, 120, 253, 0.4);
    transform: rotate(45deg);
}

.query-improver-card:focus-within::after {
    border-color: var(--clover-purple);
}

.query-improver-card-header {
    display: flex;
    align-items: center;
    gap: 4px;
    /* Brand blue #3c78fd on white is 3.66:1 (fails WCAG AA 4.5:1 at this
       size); the darker submit-hover blue is 5.36:1. */
    color: #2b5fd9;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

.query-improver-card-header .btn-close {
    font-size: 0.65rem;
}

/* Seamless editable suggestion — the card provides the surface and ring */
.query-improver-text {
    border: none;
    background: transparent;
    box-shadow: none;
    padding: 0.25rem 0;
    font-size: 0.95rem;
    line-height: 1.55;
    resize: none;
    min-height: 48px;
    max-height: 220px;
}

.query-improver-text:focus {
    border: none;
    background: transparent;
    box-shadow: none;
    outline: none;
}

.query-improver-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    border-top: 1px solid #f0f2f7;
    padding-top: 0.5rem;
    margin-top: 0.25rem;
}

.query-improver-hint {
    font-size: 0.78rem;
    margin: 0;
}

.query-improver-card-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: auto;
}

.query-improver-error {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(26, 35, 50, 0.16);
    color: #b91c1c;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
}
