/**
 * Search page and autocomplete styles
 * 
 * @package   theme_edma
 * @copyright 2025 Ministry of Health
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

/* ============================================
   Search Page Container
   ============================================ */
.edma-search-page {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: calc(100vh - 200px);
    padding: 40px 0;
}

.search-header {
    animation: fadeInDown 0.6s ease-out;
}

.search-header .display-4 {
    color: #2E86AB;
    font-weight: 700;
    margin-bottom: 15px;
}

.search-header .display-4 i {
    color: #06A77D;
}

/* ============================================
   Enhanced Search Box
   ============================================ */
.search-box-container {
    max-width: 800px;
    margin: 0 auto;
    animation: fadeInUp 0.6s ease-out;
}

.search-form-enhanced {
    position: relative;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: white;
    border-radius: 50px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.search-input-wrapper:focus-within {
    box-shadow: 0 15px 50px rgba(46, 134, 171, 0.2);
    transform: translateY(-2px);
}

.search-input-wrapper .search-icon {
    position: absolute;
    left: 25px;
    font-size: 24px;
    color: #2E86AB;
    pointer-events: none;
    z-index: 2;
}

.search-input-main {
    flex: 1;
    border: none;
    padding: 20px 70px 20px 65px;
    font-size: 18px;
    border-radius: 50px;
    outline: none;
    background: transparent;
}

.search-input-main::placeholder {
    color: #999;
}

.btn-search-submit {
    position: absolute;
    right: 5px;
    background: linear-gradient(135deg, #2E86AB 0%, #06A77D 100%);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 15px 30px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-search-submit:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(46, 134, 171, 0.4);
}

/* ============================================
   Autocomplete Suggestions
   ============================================ */
.search-suggestions {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.search-suggestions.show {
    max-height: 500px;
    opacity: 1;
    overflow-y: auto;
}

.suggestion-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    text-decoration: none;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    transition: all 0.2s ease;
    cursor: pointer;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.active {
    background: linear-gradient(135deg, rgba(46, 134, 171, 0.1) 0%, rgba(6, 167, 125, 0.1) 100%);
    padding-left: 25px;
}

.suggestion-item i {
    font-size: 24px;
    color: #2E86AB;
    margin-right: 15px;
    flex-shrink: 0;
}

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

.suggestion-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.suggestion-subtitle {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.suggestion-badge {
    background: linear-gradient(135deg, #2E86AB 0%, #06A77D 100%);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    margin-left: 10px;
    flex-shrink: 0;
}

.suggestion-loading {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
}

.suggestion-loading i {
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

/* ============================================
   Search Results
   ============================================ */
.search-results {
    animation: fadeIn 0.6s ease-out;
}

.results-header h2 {
    color: #2E86AB;
    font-weight: 700;
}

.results-count .badge {
    font-size: 16px;
    padding: 10px 20px;
}

/* Enhanced Search Results Header */
.search-results-header {
    background: white;
    padding: 20px 30px;
    border-radius: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin-bottom: 25px;
}

.search-results-header h3 {
    margin: 0;
    color: #2E86AB;
    font-size: 24px;
    font-weight: 700;
}

/* Search Results Grid */
.search-results-grid {
    display: grid;
    gap: 20px;
}

/* Enhanced Search Result Card */
.search-result-card {
    background: white;
    border-radius: 15px;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    overflow: hidden;
    border-left: 4px solid transparent;
}

.search-result-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(46, 134, 171, 0.15);
    border-left-color: #2E86AB;
}

/* Card Header */
.search-result-header {
    display: flex;
    align-items: flex-start;
    padding: 20px 25px 15px;
    border-bottom: 1px solid #f0f0f0;
    background: linear-gradient(135deg, rgba(46, 134, 171, 0.03) 0%, rgba(6, 167, 125, 0.03) 100%);
}

.search-result-icon {
    flex-shrink: 0;
    margin-right: 15px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

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

.search-result-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.4;
}

.search-result-title a {
    color: #2E86AB;
    text-decoration: none;
    transition: color 0.3s ease;
}

.search-result-title a:hover {
    color: #06A77D;
    text-decoration: underline;
}

/* Card Body */
.search-result-body {
    padding: 20px 25px;
}

.search-result-content,
.search-result-description {
    color: #555;
    line-height: 1.7;
    margin-bottom: 12px;
    font-size: 14px;
}

.search-result-content:last-child,
.search-result-description:last-child {
    margin-bottom: 0;
}

.search-result-filename,
.search-result-filenames {
    background: #f8f9fa;
    padding: 10px 15px;
    border-radius: 8px;
    margin-top: 12px;
    font-size: 13px;
    color: #666;
}

.search-result-filenames ul {
    margin: 8px 0 0 0;
    padding-left: 0;
}

.search-result-filenames li {
    padding: 5px 0;
    color: #555;
}

/* Card Footer */
.search-result-footer {
    padding: 15px 25px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    font-size: 13px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.search-result-link {
    color: #2E86AB;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
}

.search-result-link:hover {
    color: #06A77D;
    text-decoration: none;
}

.search-result-link i {
    font-size: 12px;
}

/* Top Results Section */
.top-results-section {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.1) 0%, rgba(255, 165, 0, 0.1) 100%);
    padding: 25px;
    border-radius: 15px;
    border: 2px solid rgba(255, 215, 0, 0.3);
}

.top-results-section h3 {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.top-results-section .search-result-card {
    border-left-color: #ffc107;
}

/* Search Form Enhancements */
#page-search-index .mform {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.08);
    margin-bottom: 30px;
}

#page-search-index .mform fieldset {
    border: none;
    padding: 0;
}

#page-search-index .mform legend {
    color: #2E86AB;
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e9ecef;
    width: 100%;
}

#page-search-index .mform .form-group {
    margin-bottom: 20px;
}

#page-search-index .mform .form-control {
    border-radius: 8px;
    border: 1px solid #ddd;
    padding: 10px 15px;
    transition: all 0.3s ease;
}

#page-search-index .mform .form-control:focus {
    border-color: #2E86AB;
    box-shadow: 0 0 0 0.2rem rgba(46, 134, 171, 0.15);
}

#page-search-index .mform .btn-primary {
    background: linear-gradient(135deg, #2E86AB 0%, #06A77D 100%);
    border: none;
    border-radius: 8px;
    padding: 12px 30px;
    font-weight: 600;
    transition: all 0.3s ease;
}

#page-search-index .mform .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(46, 134, 171, 0.3);
}

/* Page Layout */
#page-search-index {
    background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
    min-height: calc(100vh - 200px);
}

#page-search-index .container-fluid,
#page-search-index #region-main {
    background: transparent;
}

/* Pagination Styling */
.search-pagination-top,
.search-pagination-bottom {
    display: flex;
    justify-content: center;
}

.search-pagination-top .pagination,
.search-pagination-bottom .pagination {
    background: white;
    padding: 10px 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* Notifications */
#page-search-index .alert {
    border-radius: 10px;
    border: none;
    padding: 15px 20px;
    margin-bottom: 20px;
}

#page-search-index .alert-info {
    background: linear-gradient(135deg, rgba(46, 134, 171, 0.1) 0%, rgba(6, 167, 125, 0.1) 100%);
    color: #2E86AB;
}

#page-search-index .alert-warning {
    background: linear-gradient(135deg, rgba(255, 193, 7, 0.1) 0%, rgba(255, 152, 0, 0.1) 100%);
    color: #856404;
}

/* ============================================
   Course Cards
   ============================================ */
.course-card {
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.course-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(46, 134, 171, 0.2);
}

.course-image {
    position: relative;
    height: 200px;
    overflow: hidden;
}

.course-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.course-card:hover .course-image img {
    transform: scale(1.1);
}

.course-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(46, 134, 171, 0.9) 0%, rgba(6, 167, 125, 0.9) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.course-card:hover .course-overlay {
    opacity: 1;
}

.course-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.course-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
    line-height: 1.4;
}

.course-title a {
    color: #2E86AB;
    text-decoration: none;
    transition: color 0.3s ease;
}

.course-title a:hover {
    color: #06A77D;
}

.course-code {
    font-size: 14px;
    margin-bottom: 12px;
}

.course-code i {
    margin-right: 5px;
}

.course-summary {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    margin-bottom: 15px;
    flex: 1;
}

.course-meta {
    display: flex;
    gap: 15px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
    font-size: 13px;
    color: #666;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.meta-item i {
    color: #2E86AB;
}

/* ============================================
   Pagination
   ============================================ */
.pagination {
    gap: 5px;
}

.page-link {
    border-radius: 8px;
    border: 1px solid #ddd;
    color: #2E86AB;
    padding: 10px 15px;
    transition: all 0.3s ease;
}

.page-link:hover {
    background: linear-gradient(135deg, #2E86AB 0%, #06A77D 100%);
    color: white;
    border-color: transparent;
}

.page-item.active .page-link {
    background: linear-gradient(135deg, #2E86AB 0%, #06A77D 100%);
    border-color: transparent;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

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

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

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .search-input-main {
        padding: 15px 60px 15px 55px;
        font-size: 16px;
    }

    .search-input-wrapper .search-icon {
        left: 20px;
        font-size: 20px;
    }

    .btn-search-submit {
        padding: 12px 20px;
        font-size: 18px;
    }

    .course-image {
        height: 180px;
    }

    .course-meta {
        flex-direction: column;
        gap: 8px;
    }

    /* Search result cards on mobile */
    .search-result-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-result-icon {
        margin-bottom: 10px;
    }

    .search-result-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    #page-search-index .mform {
        padding: 20px;
    }

    .search-results-header {
        padding: 15px 20px;
    }

    .search-results-header h3 {
        font-size: 20px;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .search-result-card {
        margin-bottom: 15px;
    }

    #page-search-index .mform {
        padding: 25px;
    }
}

/* ============================================
   Header Search Box Integration
   ============================================ */
.navbar-search-container {
    position: relative;
}

.navbar-search-container .search-suggestions {
    top: calc(100% + 5px);
    border-radius: 15px;
    max-width: 450px;
    right: 0;
    left: auto;
}

.navbar-search-container .search-form {
    position: relative;
}

/* Make header search input work with autocomplete */
.search-form {
    position: relative;
}

.search-form fieldset {
    position: relative;
    border: none;
    padding: 0;
    margin: 0;
}

.search-form .form-control {
    position: relative;
}

/* Ensure suggestions appear above other content */
.search-suggestions {
    z-index: 9999;
}

/* Header search box specific styles */
.navbar-search-container .search-box {
    position: relative;
}

.navbar-search-container .input-search {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    padding: 8px 40px 8px 15px;
    border-radius: 25px;
    width: 250px;
    transition: all 0.3s ease;
}

.navbar-search-container .input-search::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.navbar-search-container .input-search:focus {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    outline: none;
    width: 300px;
}

.navbar-search-container .search-box button,
.navbar-search-container .src-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #ffffff;
    padding: 5px 10px;
    cursor: pointer;
}

.navbar-search-container .search-box button:hover,
.navbar-search-container .src-btn:hover {
    color: rgba(255, 255, 255, 0.8);
}

/* ============================================
   Legacy Search Results Styling (Fallback)
   ============================================ */
/* Style default Moodle search results if custom renderer doesn't apply */
.search-results .result {
    background: white;
    border-radius: 15px;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.08);
    padding: 20px 25px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
}

.search-results .result:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(46, 134, 171, 0.15);
    border-left-color: #2E86AB;
}

.search-results .result-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
}

.search-results .result-title a {
    color: #2E86AB;
    text-decoration: none;
    transition: color 0.3s ease;
}

.search-results .result-title a:hover {
    color: #06A77D;
    text-decoration: underline;
}

.search-results .result-content {
    color: #555;
    line-height: 1.7;
    margin-bottom: 12px;
    font-size: 14px;
}

.search-results .result-context-info {
    padding-top: 12px;
    border-top: 1px solid #e9ecef;
    font-size: 13px;
    color: #666;
}

.search-results .result-context-info a {
    color: #2E86AB;
    text-decoration: none;
    transition: color 0.2s ease;
}

.search-results .result-context-info a:hover {
    color: #06A77D;
}

/* Horizontal rule between results */
.search-results hr {
    display: none;
}

/* No results message */
#page-search-index .alert-info,
#page-search-index .alert.alert-info {
    background: linear-gradient(135deg, rgba(46, 134, 171, 0.1) 0%, rgba(6, 167, 125, 0.1) 100%);
    border: 1px solid rgba(46, 134, 171, 0.2);
    color: #2E86AB;
    border-radius: 10px;
    padding: 20px;
    font-size: 15px;
}

/* Search query error */
#page-search-index .alert-danger,
#page-search-index .alert.alert-danger {
    background: linear-gradient(135deg, rgba(220, 53, 69, 0.1) 0%, rgba(220, 53, 69, 0.05) 100%);
    border: 1px solid rgba(220, 53, 69, 0.2);
    color: #721c24;
    border-radius: 10px;
    padding: 20px;
}
