/**
 * Funnelback Search Plugin Styles
 * Modern CSS - Inherits typography from Divi theme with CSS variables for theming
 */

/* ── Wrapper & Theme Variables ── */
.funnelback-search-wrapper {
    --fb-accent: currentColor;
    --fb-border: #d9d9d9;
    --fb-muted: #6b6b6b;
    --fb-fill: rgba(0, 0, 0, 0.05);
    --fb-max-width: 860px;

    max-width: var(--fb-max-width);
    margin: 0 auto;
    color: inherit;
}

/* ── Search Form ── */
.fb-search-form {
    margin: 0;
    padding: 0;
}

.fb-search-form__row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.fb-search-form__input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    position: relative;
    min-width: 200px;
}

.fb-search-form__input {
    flex: 1;
    min-width: 0;
    padding: 0.55rem 2.5rem 0.55rem 0.85rem;
    border: 1px solid var(--fb-border);
    border-radius: 4px;
    outline: none;
    font-family: inherit;
    background: #fff;
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.fb-search-form__input:focus {
    border-color: var(--fb-accent);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.fb-search-form__input:invalid {
    border-color: #d32f2f;
    box-shadow: 0 0 0 2px rgba(211, 47, 47, 0.1);
}

.fb-search-form__input::placeholder {
    opacity: 0.65;
}

.fb-search-form__clear {
    position: absolute;
    right: 0.5rem;
    background: transparent;
    border: none;
    padding: 0.4rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--fb-muted);
    border-radius: 4px;
    transition: all 0.15s ease;
}

.fb-search-form__clear:hover {
    color: inherit;
    background: var(--fb-fill);
}

.fb-search-form__clear:focus {
    outline: 2px solid var(--fb-accent);
    outline-offset: 2px;
}

.fb-search-form__input-wrapper.has-text .fb-search-form__clear {
    display: flex;
}

.fb-search-form__clear-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.fb-search-form__btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1.2rem;
    background: transparent;
    color: inherit;
    font-weight: 600;
    border: 1px solid var(--fb-border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    white-space: nowrap;
    font-size: 0.95rem;
}

.fb-search-form__btn:hover,
.fb-search-form__btn:focus {
    background: var(--fb-fill);
    border-color: var(--fb-accent);
}

.fb-search-form__btn:active {
    transform: translateY(0);
}

.fb-search-form__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.fb-search-form__btn-text {
    display: inline;
}

/* ── Results Container ── */
.funnelback-results {
    background: transparent;
    padding: 1.5rem 0;
    min-height: 100px;
}

/* ── Meta Information ── */
.funnelback-meta {
    margin-bottom: 1.5rem;
    margin-top: 0;
    font-size: 0.9rem;
    color: var(--fb-muted);
}

.funnelback-meta p {
    margin: 0;
    padding: 0;
}

/* ── Results List ── */
.funnelback-results-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ── Result Items ── */
.fb-search-result {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--fb-border);
    list-style: none;
}

.fb-search-result:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.fb-search-result__title {
    margin: 0 0 0.5rem 0;
    padding: 0;
    line-height: 1.3;
    font-size: 0.95rem;
    font-weight: 600;
}

.fb-search-result__link {
    text-decoration: none;
    word-break: break-word;
}

.fb-search-result__link:hover {
    text-decoration: underline;
}

.fb-search-result__link:visited {
    opacity: 0.7;
}

.fb-search-result__title .fb-badge {
    margin-left: 0.75rem;
}

.fb-search-result__url {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    word-break: break-all;
    display: block;
    opacity: 0.75;
    color: var(--fb-muted);
}

.fb-search-result__summary {
    line-height: 1.6;
    margin: 0.5rem 0 0 0;
    padding: 0;
    font-size: 0.9rem;
}

.fb-search-result__summary strong {
    font-weight: 700;
}

.fb-search-result__date {
    font-size: 0.8rem;
    margin-top: 0.5rem;
    opacity: 0.7;
    color: var(--fb-muted);
}

/* ── File Type Badges ── */
.fb-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    white-space: nowrap;
    vertical-align: middle;
    color: inherit;
    background: var(--fb-fill);
    border: 1px solid var(--fb-border);
}

.fb-badge--pdf {
    background: #fdeaea;
    color: #c0392b;
}

.fb-badge--doc,
.fb-badge--docx {
    background: #e3f2fd;
    color: #1976d2;
}

.fb-badge--xls,
.fb-badge--xlsx {
    background: #e8f5e9;
    color: #388e3c;
}

.fb-badge--ppt,
.fb-badge--pptx {
    background: #fce4ec;
    color: #c2185b;
}

.fb-badge--txt {
    background: #f5f5f5;
    color: #616161;
}

/* ── Pagination ── */
.funnelback-search-wrapper .fb-search-pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 1.5rem;
    border-top: 1px solid var(--fb-border);
    padding-top: 1.5rem;
}

.funnelback-search-wrapper .fb-search-pagination__link,
.funnelback-search-wrapper .fb-search-pagination__page {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--fb-border);
    border-radius: 4px;
    background: transparent;
    color: inherit;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s ease;
}

.funnelback-search-wrapper .fb-search-pagination__link:hover,
.funnelback-search-wrapper .fb-search-pagination__page:hover {
    background: var(--fb-fill);
}

.funnelback-search-wrapper .fb-search-pagination__page--current {
    font-weight: 700;
    background: var(--fb-fill);
    border-color: var(--fb-accent);
    color: inherit;
    pointer-events: none;
}

.funnelback-search-wrapper .fb-search-pagination__link--disabled {
    opacity: 0.4;
    pointer-events: none;
}

.funnelback-search-wrapper .fb-search-pagination__ellipsis {
    display: inline-block;
    padding: 0.4rem 0.4rem;
    font-size: 0.9rem;
    color: var(--fb-muted);
    line-height: 1.4;
}

/* ── State Messages ── */
.funnelback-state {
    text-align: center;
    padding: 2rem 1rem;
    line-height: 1.6;
    color: var(--fb-muted);
}

.funnelback-state.funnelback-error {
    font-weight: 500;
    color: #d32f2f;
}

/* ── Responsive Design ── */
@media (max-width: 768px) {
    .fb-search-form__row {
        flex-direction: column;
    }

    .fb-search-form__input {
        min-width: 100%;
    }

    .fb-search-form__btn {
        width: 100%;
        justify-content: center;
    }

    .funnelback-results {
        padding: 1rem;
    }

    .fb-search-result {
        margin-bottom: 1.25rem;
        padding-bottom: 1.25rem;
    }

    .funnelback-pagination {
        flex-direction: column;
        width: 100%;
    }

    .funnelback-prev-btn,
    .funnelback-next-btn {
        width: 100%;
    }
}
    }

    .funnelback-search-input,
    .funnelback-search-btn {
        width: 100%;
    }

    .funnelback-search-btn {
        padding: 0.7rem;
    }

    .funnelback-results {
        padding: 1rem;
    }

    .funnelback-result {
        padding: 0.75rem 1rem;
        margin-bottom: 0.65rem;
    }

    .funnelback-rank {
        float: none;
        display: block;
        margin-bottom: 0.5rem;
        margin-left: 0;
    }

    .funnelback-title {
        font-size: 1rem;
    }

    .funnelback-pagination {
        flex-direction: column;
        width: 100%;
    }

    .funnelback-prev-btn,
    .funnelback-next-btn,
    .funnelback-page-info {
        width: 100%;
    }
}

/* ── Accessibility ── */
.funnelback-search-input:focus,
.funnelback-search-btn:focus,
.funnelback-prev-btn:focus,
.funnelback-next-btn:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

/* ── Divi Theme Compatibility ── */
.et_pb_text .funnelback-search-wrapper,
.funnelback-search-wrapper {
    max-width: 100%;
}

/* Ensure proper spacing in Divi columns */
.et_pb_column .funnelback-search-wrapper {
    margin: 0;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .funnelback-search-bar {
        background: rgba(255, 255, 255, 0.1);
    }

    .funnelback-result {
        background: #1a1a1a;
        border-color: #333;
    }

    .funnelback-result:hover {
        border-color: #444;
    }

    .funnelback-title a {
        color: #4da6ff;
    }

    .funnelback-summary {
        color: #ccc;
    }

    .funnelback-meta {
        color: #999;
    }

    .funnelback-results {
        background: #0d0d0d;
    }

    .funnelback-prev-btn,
    .funnelback-next-btn {
        background: #1a1a1a;
        border-color: #444;
        color: #ccc;
    }

    .funnelback-prev-btn:hover:not(:disabled),
    .funnelback-next-btn:hover:not(:disabled) {
        background: #2a2a2a;
        border-color: #666;
    }
}
