/**
 * @package     Joomla.Site
 * @subpackage  mod_article_search
 *
 * Clean, minimal live article search module styles — v2.0.
 * Uses a restrained #111318 + white palette with subtle grays.
 *
 * @copyright   (C) 2026 Dreamztech. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

/* =============================================
   CSS Custom Properties — Design Tokens
   ============================================= */
:root {
    --mas-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --mas-radius: 10px;
    --mas-radius-sm: 8px;
    --mas-radius-xs: 4px;
    --mas-transition: 0.2s ease;
    --mas-transition-fast: 0.12s ease;

    /* Light theme — #111318 + white */
    --mas-bg: #ffffff;
    --mas-bg-input: #f5f5f7;
    --mas-bg-hover: #f0f0f2;
    --mas-bg-dropdown: #ffffff;
    --mas-border: #e0e0e4;
    --mas-border-focus: #111318;
    --mas-text-primary: #111318;
    --mas-text-secondary: #555860;
    --mas-text-muted: #8c8f96;
    --mas-accent: #111318;
    --mas-accent-soft: rgba(17, 19, 24, 0.06);
    --mas-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --mas-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --mas-shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.1);
    --mas-highlight-bg: rgba(17, 19, 24, 0.08);
    --mas-highlight-text: #111318;
    --mas-category-bg: rgba(17, 19, 24, 0.05);
    --mas-category-text: #555860;
    --mas-category-border: rgba(17, 19, 24, 0.1);
    --mas-overlay: rgba(0, 0, 0, 0.02);
    --mas-skeleton-base: #ebebed;
    --mas-skeleton-shine: #f5f5f7;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
    :root {
        --mas-bg: #111318;
        --mas-bg-input: #1a1d22;
        --mas-bg-hover: #22252b;
        --mas-bg-dropdown: #151820;
        --mas-border: #2a2d34;
        --mas-border-focus: #ffffff;
        --mas-text-primary: #f0f0f2;
        --mas-text-secondary: #9b9ea6;
        --mas-text-muted: #6b6e76;
        --mas-accent: #ffffff;
        --mas-accent-soft: rgba(255, 255, 255, 0.08);
        --mas-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
        --mas-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
        --mas-shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.35);
        --mas-highlight-bg: rgba(255, 255, 255, 0.1);
        --mas-highlight-text: #ffffff;
        --mas-category-bg: rgba(255, 255, 255, 0.06);
        --mas-category-text: #9b9ea6;
        --mas-category-border: rgba(255, 255, 255, 0.1);
        --mas-overlay: rgba(255, 255, 255, 0.02);
        --mas-skeleton-base: #1e2128;
        --mas-skeleton-shine: #282b32;
    }
}

/* =============================================
   Module Wrapper
   ============================================= */
.mod-article-search {
    position: relative;
    font-family: var(--mas-font-family);
    width: 100%;
    max-width: 560px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.mas-search-wrapper {
    position: relative;
    width: 100%;
}

/* =============================================
   Input Group
   ============================================= */
.mas-input-group {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--mas-bg-input);
    border: 1.5px solid var(--mas-border);
    border-radius: 0px;
    transition: border-color var(--mas-transition), box-shadow var(--mas-transition), background var(--mas-transition);
    box-shadow: var(--mas-shadow-sm);
}

.mas-input-group:focus-within {
    border-color: var(--mas-border-focus);
    box-shadow: 0 0 0 2px var(--mas-accent-soft), var(--mas-shadow-sm);
    background: var(--mas-bg);
}

/* Search icon */
.mas-search-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: 14px;
    padding-right: 14px;
    color: var(--mas-text-muted);
    flex-shrink: 0;
    transition: color var(--mas-transition);
    pointer-events: none;
}

.mas-input-group:focus-within .mas-search-icon {
    color: var(--mas-accent);
}

/* Input field */
.mas-search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 8px 12px 10px;
    font-size: 0.95rem;
    font-weight: 400;
    color: var(--mas-text-primary);
    outline: none;
    width: 100%;
    min-width: 0;
    line-height: 1.5;
    font-family: var(--mas-font-family);
    letter-spacing: -0.01em;
}

.mas-search-input::placeholder {
    color: var(--mas-text-muted);
    font-weight: 400;
}

/* Clear button */
.mas-clear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-right: 8px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 50%;
    color: var(--mas-text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--mas-transition-fast);
    opacity: 0;
    transform: scale(0.7);
    animation: masButtonAppear 0.2s ease forwards;
}

.mas-clear-btn:hover {
    background: var(--mas-accent-soft);
    color: var(--mas-accent);
}

.mas-clear-btn:active {
    transform: scale(0.9);
}

@keyframes masButtonAppear {
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Loading spinner */
.mas-loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    flex-shrink: 0;
    color: var(--mas-accent);
}

.mas-loading-spinner svg {
    animation: masSpinnerRotate 0.7s linear infinite;
}

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

/* =============================================
   Results Dropdown
   ============================================= */
.mas-results-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--mas-bg-dropdown);
    border: 1px solid var(--mas-border);
    border-radius: var(--mas-radius);
    box-shadow: var(--mas-shadow-lg);
    max-height: 440px;
    overflow-y: auto;
    overflow-x: hidden;

    /* Entry animation */
    opacity: 0;
    transform: translateY(-6px);
    animation: masDropdownIn 0.2s ease forwards;

    /* Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--mas-border) transparent;
}

.mas-results-dropdown::-webkit-scrollbar {
    width: 5px;
}

.mas-results-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.mas-results-dropdown::-webkit-scrollbar-thumb {
    background-color: var(--mas-border);
    border-radius: 3px;
}

@keyframes masDropdownIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================
   Result Items
   ============================================= */
.mas-result-item {
    display: block;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--mas-text-primary);
    border-bottom: 1px solid var(--mas-border);
    transition: background var(--mas-transition);
    position: relative;
    cursor: pointer;

    /* Staggered entry */
    opacity: 0;
    transform: translateY(6px);
    animation: masItemSlideIn 0.2s ease forwards;
}

.mas-result-item:nth-child(1) { animation-delay: 0.02s; }
.mas-result-item:nth-child(2) { animation-delay: 0.04s; }
.mas-result-item:nth-child(3) { animation-delay: 0.06s; }
.mas-result-item:nth-child(4) { animation-delay: 0.08s; }
.mas-result-item:nth-child(5) { animation-delay: 0.10s; }
.mas-result-item:nth-child(6) { animation-delay: 0.12s; }
.mas-result-item:nth-child(7) { animation-delay: 0.14s; }
.mas-result-item:nth-child(8) { animation-delay: 0.16s; }
.mas-result-item:nth-child(9) { animation-delay: 0.18s; }
.mas-result-item:nth-child(10) { animation-delay: 0.20s; }

@keyframes masItemSlideIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mas-result-item:last-of-type {
    border-bottom: none;
}

.mas-result-item:hover,
.mas-result-item:focus,
.mas-result-item.mas-active {
    background: var(--mas-bg-hover);
    text-decoration: none;
    color: var(--mas-text-primary);
    outline: none;
}

/* Accent bar on hover/focus */
.mas-result-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: var(--mas-accent);
    border-radius: 0 2px 2px 0;
    opacity: 0;
    transition: opacity var(--mas-transition-fast);
}

.mas-result-item:hover::before,
.mas-result-item:focus::before,
.mas-result-item.mas-active::before {
    opacity: 1;
}

/* Result item layout */
.mas-result-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}

.mas-result-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--mas-text-primary);
    line-height: 1.4;
    flex: 1;
    min-width: 0;
    transition: color var(--mas-transition-fast);
    letter-spacing: -0.01em;
}

.mas-result-item:hover .mas-result-title,
.mas-result-item.mas-active .mas-result-title {
    color: var(--mas-accent);
}

.mas-result-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.mas-result-category {
    display: inline-flex;
    align-items: center;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--mas-category-text);
    background: var(--mas-category-bg);
    border: 1px solid var(--mas-category-border);
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    line-height: 1.5;
}

.mas-result-date {
    font-size: 0.73rem;
    color: var(--mas-text-muted);
    white-space: nowrap;
}

.mas-result-snippet {
    font-size: 0.82rem;
    color: var(--mas-text-secondary);
    line-height: 1.6;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Keyword highlight */
.mas-highlight {
    background: var(--mas-highlight-bg);
    color: var(--mas-highlight-text);
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 600;
}

/* =============================================
   Skeleton Loader — Shimmer
   ============================================= */
.mas-skeleton-container {
    padding: 0;
}

.mas-skeleton-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--mas-border);
}

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

.mas-skeleton-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.mas-skeleton-line {
    height: 12px;
    border-radius: var(--mas-radius-xs);
    background: var(--mas-skeleton-base);
    position: relative;
    overflow: hidden;
}

.mas-skeleton-line::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--mas-skeleton-shine) 40%,
        var(--mas-skeleton-shine) 60%,
        transparent 100%
    );
    animation: masShimmer 1.5s ease-in-out infinite;
}

@keyframes masShimmer {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.mas-skeleton-title {
    width: 65%;
    height: 14px;
}

.mas-skeleton-badge {
    width: 60px;
    height: 18px;
    border-radius: 4px;
}

.mas-skeleton-text {
    width: 90%;
    margin-top: 8px;
}

.mas-skeleton-text-short {
    width: 55%;
    margin-top: 6px;
}

/* =============================================
   No Results State
   ============================================= */
.mas-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px 20px;
    text-align: center;
}

.mas-no-results-icon {
    color: var(--mas-text-muted);
    margin-bottom: 10px;
    opacity: 0.4;
}

.mas-no-results-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--mas-text-primary);
    margin: 0 0 4px;
}

.mas-no-results-text {
    font-size: 0.8rem;
    color: var(--mas-text-muted);
    margin: 0;
}

/* =============================================
   Results Footer
   ============================================= */
.mas-results-footer {
    padding: 8px 16px;
    text-align: center;
    border-top: 1px solid var(--mas-border);
    background: var(--mas-overlay);
    opacity: 0;
    animation: masItemSlideIn 0.2s ease 0.2s forwards;
}

.mas-results-count {
    font-size: 0.72rem;
    color: var(--mas-text-muted);
    letter-spacing: 0.02em;
    font-weight: 500;
}

/* =============================================
   Screen Reader Only
   ============================================= */
.mas-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 480px) {
    .mod-article-search {
        max-width: 100%;
    }

    .mas-search-input {
        padding: 10px 6px 10px 8px;
        font-size: 16px;
    }

    .mas-result-item {
        padding: 10px 12px;
        min-height: 44px;
    }

    .mas-result-header {
        flex-direction: column;
        gap: 4px;
    }

    .mas-result-meta {
        order: -1;
    }

    .mas-results-dropdown {
        max-height: 360px;
    }

    .mas-clear-btn {
        width: 32px;
        height: 32px;
    }
}

/* =============================================
   Reduced Motion
   ============================================= */
@media (prefers-reduced-motion: reduce) {
    .mas-clear-btn,
    .mas-result-item,
    .mas-results-dropdown,
    .mas-results-footer {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }

    .mas-result-item,
    .mas-results-dropdown,
    .mas-results-footer {
        opacity: 1;
        transform: none;
    }
}
