/* Course Search module styles */

.coursesearch-container {
    margin: 20px 0;
    max-width: 600px;
}

.coursesearch-form .input-group {
    width: 100%;
}

/* Module types filter - collapsible panel */
.coursesearch-modtypes-wrapper {
    position: relative;
    --coursesearch-theme-color: var(--bs-primary, var(--primary, #0d6efd));
    --coursesearch-theme-bg: color-mix(in srgb, var(--coursesearch-theme-color) 10%, #fff 90%);
    --coursesearch-theme-border: color-mix(in srgb, var(--coursesearch-theme-color) 30%, #fff 70%);
    --coursesearch-theme-text: color-mix(in srgb, var(--coursesearch-theme-color) 70%, #000 30%);
}

.coursesearch-modtypes {
    display: inline-block;
}

.coursesearch-modtypes-summary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-weight: 500;
    font-size: 0.9rem;
    color: #495057;
    cursor: pointer;
    user-select: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background-color: #ffffff;
    transition: all 0.2s ease;
    list-style: none;
}

.coursesearch-modtypes-summary::-webkit-details-marker {
    display: none;
}

.coursesearch-modtypes-summary::marker {
    display: none;
}

.coursesearch-modtypes-summary:hover {
    background-color: #f8f9fa;
    border-color: #adb5bd;
    color: #212529;
}

.coursesearch-modtypes[open] .coursesearch-modtypes-summary {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

.coursesearch-modtypes-icon {
    display: flex;
    align-items: center;
    color: #6c757d;
    flex-shrink: 0;
}

.coursesearch-modtypes-title {
    font-weight: 500;
    white-space: nowrap;
}

.coursesearch-modtypes-arrow {
    display: flex;
    align-items: center;
    color: #6c757d;
    transition: transform 0.3s ease;
    flex-shrink: 0;
    margin-left: 2px;
}

.coursesearch-modtypes[open] .coursesearch-modtypes-arrow {
    transform: rotate(180deg);
}

.coursesearch-modtypes-content {
    display: none;
    margin-top: 12px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chip set container */
.coursesearch-chipset {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

/* Individual chip */
.coursesearch-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.coursesearch-chip input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

.coursesearch-chip-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 2px solid #d1d5db;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.875rem;
    font-weight: 500;
    background-color: #ffffff;
    color: #495057;
    transition: all 0.2s ease;
    user-select: none;
    white-space: nowrap;
}

.coursesearch-chip-label:hover {
    border-color: #9ca3af;
    background-color: #f9fafb;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.coursesearch-chip input:focus-visible + .coursesearch-chip-label {
    outline: 2px solid color-mix(in srgb, var(--coursesearch-theme-color, #0d6efd) 50%, transparent);
    outline-offset: 2px;
}

.coursesearch-chip-checkmark {
    display: none;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    color: currentColor;
    flex-shrink: 0;
}

.coursesearch-chip input:checked + .coursesearch-chip-label {
    background: var(--coursesearch-theme-bg, #e7f1ff);
    border-color: var(--coursesearch-theme-border, #9ec5fe);
    color: var(--coursesearch-theme-text, #0d6efd);
    font-weight: 600;
    box-shadow: 0 2px 6px color-mix(in srgb, var(--coursesearch-theme-color, #0d6efd) 15%, transparent);
}

.coursesearch-chip input:checked + .coursesearch-chip-label .coursesearch-chip-checkmark {
    display: flex;
}

.coursesearch-chip input:checked + .coursesearch-chip-label:hover {
    background: var(--coursesearch-theme-border, #9ec5fe);
    border-color: var(--coursesearch-theme-color, #0d6efd);
    box-shadow: 0 3px 8px color-mix(in srgb, var(--coursesearch-theme-color, #0d6efd) 20%, transparent);
}

.coursesearch-chip-text {
    line-height: 1.4;
}

/* Help text */
.coursesearch-modtypes-help {
    font-size: 0.8125rem;
    color: #6c757d;
    line-height: 1.5;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
    margin-top: 4px;
}

/* Results container */
.coursesearch-results-container {
    margin-top: 30px;
    --coursesearch-theme-color: var(--bs-primary, var(--primary, #0d6efd));
    --coursesearch-theme-bg: color-mix(in srgb, var(--coursesearch-theme-color) 10%, #fff 90%);
    --coursesearch-theme-border: color-mix(in srgb, var(--coursesearch-theme-color) 30%, #fff 70%);
    --coursesearch-theme-snippet: color-mix(in srgb, var(--coursesearch-theme-color) 45%, #fff 55%);
    --coursesearch-theme-badge: color-mix(in srgb, var(--coursesearch-theme-color) 80%, #000 20%);
    --coursesearch-theme-text: color-mix(in srgb, var(--coursesearch-theme-color) 70%, #000 30%);
}

.coursesearch-results-heading {
    margin-bottom: 15px;
    font-size: 1.4rem;
}

/* Results summary with count and range */
.coursesearch-results-summary {
    margin-bottom: 20px;
    padding: 10px 15px;
    background-color: #f8f9fa;
    border-radius: 4px;
    font-size: 0.95rem;
}

.coursesearch-results-count {
    font-weight: 600;
}

.coursesearch-results-range {
    color: #6c757d;
    margin-left: 8px;
}

/* Section groups */
.coursesearch-results-grouped {
    margin-bottom: 20px;
}

.coursesearch-section-group {
    margin-bottom: 20px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background-color: #fff;
}

.coursesearch-section-header {
    padding: 12px 15px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.coursesearch-section-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.coursesearch-section-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.coursesearch-section-icon .icon {
    color: #495057;
}

.coursesearch-section-count {
    margin-left: auto;
    font-size: 0.85rem;
}

.coursesearch-section-results {
    padding: 10px 15px;
}

/* Section matched - highlight the header */
.coursesearch-section-matched .coursesearch-section-header {
    background-color: var(--coursesearch-theme-bg);
    border-bottom-color: var(--coursesearch-theme-border);
}

.coursesearch-section-snippet {
    margin-top: 8px;
    padding: 8px 12px;
    background-color: #fff;
    border-left: 3px solid var(--coursesearch-theme-snippet, #adb5bd);
    font-size: 0.9rem;
    color: #495057;
    line-height: 1.5;
    border-radius: 0 4px 4px 0;
}

/* Nested subsections container */
.coursesearch-subsections {
    padding: 0 15px 15px;
    background-color: #fafbfc;
    border-top: 1px dashed #dee2e6;
}

/* Individual subsection */
.coursesearch-subsection {
    margin-top: 12px;
    border: 1px solid #e1e4e8;
    border-radius: 4px;
    background-color: #fff;
    margin-left: 20px;
    position: relative;
}

/* Visual connector line */
.coursesearch-subsection::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 20px;
    width: 16px;
    height: 1px;
    background-color: #d1d5db;
}

.coursesearch-subsection-header {
    padding: 10px 12px;
    background-color: #f6f8fa;
    border-bottom: 1px solid #e1e4e8;
    border-radius: 4px 4px 0 0;
}

.coursesearch-subsection-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.coursesearch-subsection-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.coursesearch-subsection-icon .icon {
    color: #6c757d;
    font-size: 0.9rem;
}

.coursesearch-subsection-count {
    margin-left: auto;
    font-size: 0.8rem;
}

.coursesearch-subsection-results {
    padding: 10px 12px;
}

/* Subsection matched - highlight the header */
.coursesearch-subsection-matched .coursesearch-subsection-header {
    background-color: var(--coursesearch-theme-bg);
    border-bottom-color: var(--coursesearch-theme-border);
}

.coursesearch-subsection-snippet {
    margin-top: 6px;
    padding: 6px 10px;
    background-color: #fff;
    border-left: 3px solid var(--coursesearch-theme-snippet, #90caf9);
    font-size: 0.85rem;
    color: #495057;
    line-height: 1.4;
    border-radius: 0 4px 4px 0;
}

/* Section/subsection badges with theme shades */
.coursesearch-section-header .badge-info,
.coursesearch-subsection-header .badge-primary,
.coursesearch-section-count.badge,
.coursesearch-subsection-count.badge,
.coursesearch-group-matchcount.badge {
    background-color: color-mix(in srgb, var(--coursesearch-theme-color) 80%, #fff 20%);
    color: #fff;
    border: none;
}

/* Individual result item */
.coursesearch-result {
    display: flex;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    background-color: #fff;
    transition: background-color 0.2s;
    position: relative;
}

.coursesearch-result:last-child {
    margin-bottom: 0;
}

.coursesearch-result:hover {
    background-color: #f8f9fa;
    border-color: #dee2e6;
}


.coursesearch-result-icon {
    margin-right: 12px;
    display: flex;
    align-items: flex-start;
    padding-top: 2px;
}

.coursesearch-result-icon img {
    width: 24px;
    height: 24px;
}

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

.coursesearch-result-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.coursesearch-result-title a {
    font-weight: 600;
    color: var(--bs-link-color, var(--link-color, var(--primary, #0d6efd)));
    text-decoration: none;
    word-break: break-word;
}

.coursesearch-result-title a:hover {
    color: color-mix(in srgb, var(--bs-link-color, var(--link-color, var(--primary, #0d6efd))) 85%, #000 15%);
    text-decoration: underline;
}

.coursesearch-result-forum {
    font-size: 0.85rem;
    color: #6c757d;
    margin-bottom: 6px;
}

.coursesearch-result-snippet {
    margin: 8px 0;
    padding: 10px 12px;
    background-color: #f8f9fa;
    border-left: 3px solid #adb5bd;
    font-size: 0.9rem;
    color: #495057;
    line-height: 1.5;
    border-radius: 0 4px 4px 0;
}

.coursesearch-result-match {
    font-size: 0.8rem;
    color: #6c757d;
    font-style: italic;
}

/* Highlight styles */
.highlight,
.coursesearch-highlight {
    background-color: #fff3bf;
    padding: 1px 3px;
    font-weight: 600;
    border-radius: 2px;
    color: #212529;
}

/* Temporary highlight for search results - with !important to override theme styles */
.coursesearch-highlight-temp,
span.coursesearch-highlight-temp {
    background-color: #fff3bf;
    padding: 2px 4px;
    border-radius: 2px;
    color: inherit;
    display: inline;
}

/* Pagination styles */
.coursesearch-pagination {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #dee2e6;
}

.coursesearch-pagination .pagination {
    margin-bottom: 0;
}

/* No results message */
.coursesearch-no-results {
    padding: 20px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #6c757d;
    text-align: center;
}

/* Embedded search form styles */
.coursesearch-embedded {
    margin: 10px 0;
    max-width: 100%;
}

.coursesearch-embedded .input-group {
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.coursesearch-embedded .form-control {
    border: 1px solid #ddd;
    height: 42px;
    font-size: 1rem;
}

.coursesearch-embedded .btn-primary {
    padding: 0.5rem 1rem;
    font-weight: 500;
}

/* Legacy styles for backwards compatibility */
.coursesearch-results {
    margin-top: 30px;
}

.coursesearch-results h3 {
    margin-bottom: 20px;
    font-size: 1.4rem;
}

.coursesearch-results-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.coursesearch-result-item {
    display: flex;
    margin-bottom: 15px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: #f9f9f9;
    transition: background-color 0.2s;
}

.coursesearch-result-item:hover {
    background-color: #f0f0f0;
}

.coursesearch-result-context {
    font-size: 0.9em;
    color: #555;
    margin-bottom: 5px;
}

/* Grouped result styles */
.coursesearch-result-group {
    margin-bottom: 12px;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    background-color: #fff;
    transition: border-color 0.2s;
}

.coursesearch-result-group:hover {
    border-color: #dee2e6;
}

.coursesearch-group-header {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    user-select: none;
    background-color: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    border-radius: 4px 4px 0 0;
    transition: background-color 0.2s;
    position: relative;
}

/* Result type tooltip on hover */
.coursesearch-result[data-result-type]::after,
.coursesearch-group-header[data-result-type]::after {
    content: attr(data-result-type);
    position: absolute;
    top: 0;
    right: 8px;
    transform: translateY(-6px);
    background-color: color-mix(in srgb, var(--coursesearch-theme-color) 85%, #000 15%);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    white-space: nowrap;
    z-index: 2;
}

.coursesearch-result[data-result-type]:hover::after,
.coursesearch-group-header[data-result-type]:hover::after {
    opacity: 1;
    transform: translateY(-10px);
}

.coursesearch-group-header:hover {
    background-color: #e9ecef;
}

.coursesearch-group-header:focus {
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
}

.coursesearch-group-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.coursesearch-group-activity-link,
.coursesearch-group-activity-name {
    font-weight: 600;
    color: #212529;
    word-break: break-word;
}

.coursesearch-group-activity-link {
    color: var(--bs-link-color, var(--link-color, var(--primary, #0d6efd)));
    text-decoration: none;
}

.coursesearch-group-activity-link:hover {
    color: color-mix(in srgb, var(--bs-link-color, var(--link-color, var(--primary, #0d6efd))) 85%, #000 15%);
    text-decoration: underline;
}

.coursesearch-group-matchcount {
    font-size: 0.85rem;
    white-space: nowrap;
}

.coursesearch-group-toggle {
    margin-left: 10px;
    padding: 4px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.coursesearch-group-toggle:hover {
    color: #495057;
}

.coursesearch-group-toggle:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
    border-radius: 2px;
}

.coursesearch-group-toggle .icon {
    transition: transform 0.2s;
}

.coursesearch-group-expanded .coursesearch-group-toggle .icon {
    transform: rotate(180deg);
}

.coursesearch-group-matches {
    padding: 10px 15px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.coursesearch-group-expanded .coursesearch-group-matches {
    max-height: 5000px;
    padding: 10px 15px;
}

.coursesearch-group-collapsed .coursesearch-group-matches {
    max-height: 0;
    padding: 0 15px;
}

/* Nested result items within groups */
.coursesearch-group-matches .coursesearch-result {
    margin-left: 20px;
    border-left: 2px solid #dee2e6;
    padding-left: 15px;
    margin-bottom: 10px;
}

.coursesearch-group-matches .coursesearch-result:last-child {
    margin-bottom: 0;
}

/* Responsive adjustments */
@media (max-width: 576px) {
    .coursesearch-section-header {
        padding: 10px 12px;
    }

    .coursesearch-section-title {
        font-size: 1rem;
    }

    .coursesearch-result {
        padding: 10px;
    }

    .coursesearch-result-icon {
        margin-right: 10px;
    }

    .coursesearch-result-icon img {
        width: 20px;
        height: 20px;
    }

    .coursesearch-results-summary {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .coursesearch-group-header {
        padding: 10px 12px;
    }

    .coursesearch-group-title {
        gap: 6px;
    }

    .coursesearch-group-matchcount {
        font-size: 0.8rem;
    }

    .coursesearch-group-matches .coursesearch-result {
        margin-left: 10px;
        padding-left: 10px;
    }
}

/* Floating quick-access widget styles */
.coursesearch-floating-widget {
    position: fixed;
    /* bottom value is set via inline style from admin setting */
    right: 20px;
    z-index: 1000;
    font-family: inherit;
}

.coursesearch-floating-widget-toggle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    /* Use Moodle's theme primary color - fallback to Bootstrap primary if CSS variable not available */
    background-color: var(--bs-primary, var(--primary, #0d6efd));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    transition: all 0.2s ease;
    border: none;
    padding: 0;
}

.coursesearch-floating-widget-toggle:hover {
    /* Darken the primary color on hover using filter */
    filter: brightness(0.85);
    color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.coursesearch-floating-widget-toggle:focus {
    outline: 2px solid var(--bs-primary, var(--primary, #0d6efd));
    outline-offset: 2px;
}

.coursesearch-floating-widget-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 25px;
    height: 25px;
}

.coursesearch-floating-widget-icon svg {
    width: 100%;
    height: 100%;
}

.coursesearch-floating-widget-content {
    position: absolute;
    bottom: 56px;
    right: 0;
    width: 320px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    border: 1px solid #dee2e6;
}

.coursesearch-floating-widget:not(.coursesearch-floating-widget-collapsed) .coursesearch-floating-widget-content {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.coursesearch-floating-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #dee2e6;
}

.coursesearch-floating-widget-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: #212529;
}

.coursesearch-floating-widget-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: #6c757d;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.coursesearch-floating-widget-close:hover {
    color: #212529;
}

.coursesearch-floating-widget-close:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
    border-radius: 2px;
}

.coursesearch-floating-widget-form {
    margin: 0;
}

.coursesearch-floating-widget-form .input-group {
    display: flex;
    width: 100%;
}

.coursesearch-floating-widget-input {
    flex: 1;
    border: 1px solid #ced4da;
    border-radius: 4px 0 0 4px;
    padding: 8px 12px;
    font-size: 0.95rem;
}

.coursesearch-floating-widget-input:focus {
    border-color: #0d6efd;
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.coursesearch-floating-widget-submit {
    border-radius: 0 4px 4px 0;
    padding: 8px 16px;
    font-size: 0.95rem;
    white-space: nowrap;
}

/* Responsive adjustments for floating widget */
@media (max-width: 576px) {
    .coursesearch-floating-widget {
        /* bottom value is set via inline style from admin setting */
        right: 15px;
    }

    .coursesearch-floating-widget-content {
        width: calc(100vw - 30px);
        max-width: 320px;
        bottom: 56px;
    }
}
