/**
 * DiabloDesign - Search Module
 * Main Stylesheet
 * 
 * @package     DiabloDesign.Module
 * @subpackage  mod_dd_search
 * @author      DiabloDesign
 * @copyright   (C) 2025 DiabloDesign
 * @license     GNU GPL v3+
 * 
 * Layouts: classic, minimal, fullwidth, pill
 */

/* ==========================================================================
   CSS Variables
   ========================================================================== */

.mod-dd-search {
    --dd-search-primary: #c60000;
    --dd-search-bg: #ffffff;
    --dd-search-text: #333333;
    --dd-search-placeholder: #999999;
    --dd-search-border: #dddddd;
    --dd-search-border-width: 2px;
    --dd-search-radius: 8px;
    --dd-search-speed: 300ms;
    --dd-search-width: 300px;
    --dd-search-height: 44px;
    --dd-search-font-size: 15px;
    --dd-search-icon-size: 18px;
    --dd-search-hover-border: #c60000;
    --dd-search-btn-bg: #c60000;
    --dd-search-btn-text: #ffffff;
    --dd-search-shadow: none;
}

/* Size variants */
.mod-dd-search--small {
    --dd-search-height: 36px;
    --dd-search-font-size: 13px;
    --dd-search-icon-size: 16px;
}

.mod-dd-search--large {
    --dd-search-height: 54px;
    --dd-search-font-size: 17px;
    --dd-search-icon-size: 22px;
}

/* ==========================================================================
   Base Styles
   ========================================================================== */

.mod-dd-search {
    position: relative;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    display: flex;
    justify-content: flex-end;
}

.mod-dd-search *,
.mod-dd-search *::before,
.mod-dd-search *::after {
    box-sizing: border-box;
}

.dd-search__form {
    position: relative;
}

.dd-search__wrapper {
    display: flex;
    align-items: center;
    gap: 0;
}

.dd-search__input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
}

/* Input */
.dd-search__input {
    width: 100%;
    height: var(--dd-search-height);
    padding: 0 1rem;
    border: var(--dd-search-border-width) solid var(--dd-search-border);
    border-radius: var(--dd-search-radius);
    background: var(--dd-search-bg);
    color: var(--dd-search-text);
    font-size: var(--dd-search-font-size);
    font-family: inherit;
    outline: none;
    box-shadow: var(--dd-search-shadow);
    transition: all var(--dd-search-speed) ease;
}

.dd-search__input::placeholder {
    color: var(--dd-search-placeholder);
    opacity: 1;
}

.dd-search__input:hover {
    border-color: var(--dd-search-hover-border);
}

.dd-search__input::-webkit-search-cancel-button {
    display: none;
}

/* Button */
.dd-search__button {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--dd-search-height);
    min-width: var(--dd-search-height);
    padding: 0 1rem;
    border: none;
    border-radius: var(--dd-search-radius);
    background: var(--dd-search-btn-bg);
    color: var(--dd-search-btn-text);
    font-size: var(--dd-search-font-size);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--dd-search-speed) ease;
}

.dd-search__button svg {
    width: var(--dd-search-icon-size);
    height: var(--dd-search-icon-size);
}

.dd-search__button:hover {
    filter: brightness(1.1);
}

.dd-search__button:active {
    transform: scale(0.95);
}

/* Icon inside input */
.dd-search__icon {
    position: absolute;
    left: 1rem;
    display: flex;
    color: var(--dd-search-text);
    opacity: 0.5;
    pointer-events: none;
}

.dd-search__icon svg {
    width: var(--dd-search-icon-size);
    height: var(--dd-search-icon-size);
}

.dd-search__input-wrapper:has(.dd-search__icon) .dd-search__input {
    padding-left: calc(var(--dd-search-icon-size) + 1.5rem);
}

/* Clear button */
.dd-search__clear {
    position: absolute;
    right: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--dd-search-text);
    opacity: 0.5;
    cursor: pointer;
    transition: all var(--dd-search-speed) ease;
}

.dd-search__clear svg {
    width: 16px;
    height: 16px;
}

.dd-search__clear:hover {
    background: rgba(0, 0, 0, 0.1);
    opacity: 1;
}

.dd-search__clear[hidden] {
    display: none;
}

/* Voice button */
.dd-search__voice {
    position: absolute;
    right: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--dd-search-text);
    opacity: 0.5;
    cursor: pointer;
    transition: all var(--dd-search-speed) ease;
}

.dd-search__voice svg {
    width: 18px;
    height: 18px;
}

.dd-search__voice:hover {
    color: var(--dd-search-primary);
    opacity: 1;
}

.dd-search__voice.is-listening {
    color: var(--dd-search-primary);
    opacity: 1;
    animation: dd-search-pulse 1s ease infinite;
}

/* Adjust clear button position when voice is present */
.dd-search__input-wrapper:has(.dd-search__voice) .dd-search__clear {
    right: 3rem;
}

/* ==========================================================================
   Layout: Classic
   ========================================================================== */

.mod-dd-search--classic .dd-search__wrapper {
    width: var(--dd-search-width);
}

.mod-dd-search--classic.mod-dd-search--btn-right .dd-search__input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.mod-dd-search--classic.mod-dd-search--btn-right .dd-search__button {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.mod-dd-search--classic.mod-dd-search--btn-left .dd-search__input {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: none;
}

.mod-dd-search--classic.mod-dd-search--btn-left .dd-search__button {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.mod-dd-search--classic.mod-dd-search--btn-inside .dd-search__button--inside {
    position: absolute;
    right: 4px;
    height: calc(var(--dd-search-height) - 8px);
    min-width: calc(var(--dd-search-height) - 8px);
    padding: 0;
}

.mod-dd-search--classic.mod-dd-search--btn-inside .dd-search__input {
    padding-right: calc(var(--dd-search-height) + 0.5rem);
}

/* ==========================================================================
   Layout: Fullwidth
   ========================================================================== */

.mod-dd-search--fullwidth {
    justify-content: stretch;
}

.mod-dd-search--fullwidth .dd-search__form {
    width: 100%;
}

.mod-dd-search--fullwidth .dd-search__wrapper {
    width: 100%;
}

.mod-dd-search--fullwidth .dd-search__input-wrapper {
    flex: 1;
}

.mod-dd-search--fullwidth.mod-dd-search--btn-right .dd-search__input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.mod-dd-search--fullwidth.mod-dd-search--btn-right .dd-search__button {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    padding: 0 2rem;
}

.mod-dd-search--fullwidth.mod-dd-search--btn-left .dd-search__input {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: none;
}

.mod-dd-search--fullwidth.mod-dd-search--btn-left .dd-search__button {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    padding: 0 2rem;
}

.mod-dd-search--fullwidth.mod-dd-search--btn-inside .dd-search__button--inside {
    position: absolute;
    right: 4px;
    height: calc(var(--dd-search-height) - 8px);
    padding: 0 1.5rem;
}

.mod-dd-search--fullwidth.mod-dd-search--btn-inside .dd-search__input {
    padding-right: calc(var(--dd-search-height) + 2rem);
}

/* ==========================================================================
   Layout: Pill
   ========================================================================== */

.mod-dd-search--pill .dd-search__wrapper {
    width: var(--dd-search-width);
}

.mod-dd-search--pill .dd-search__input-wrapper {
    display: flex;
    align-items: center;
    background: var(--dd-search-bg);
    border: var(--dd-search-border-width) solid var(--dd-search-border);
    border-radius: var(--dd-search-radius);
    overflow: hidden;
    box-shadow: var(--dd-search-shadow);
    transition: all var(--dd-search-speed) ease;
}

.mod-dd-search--pill .dd-search__input-wrapper:hover {
    border-color: var(--dd-search-hover-border);
}

.mod-dd-search--pill .dd-search__input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    padding-left: 1.5rem;
    padding-right: 0.5rem;
}

.mod-dd-search--pill .dd-search__button--inside {
    flex-shrink: 0;
    margin: 4px;
    height: calc(var(--dd-search-height) - 12px);
    min-width: calc(var(--dd-search-height) - 12px);
    border-radius: 50px;
}

.mod-dd-search--pill .dd-search__button--left {
    margin-right: 0;
    margin-left: 4px;
    order: -1;
}

.mod-dd-search--pill .dd-search__clear,
.mod-dd-search--pill .dd-search__voice {
    flex-shrink: 0;
    position: relative;
    right: auto;
}

/* ==========================================================================
   Layout: Minimal (Expandable)
   ========================================================================== */

.mod-dd-search--minimal .dd-search__wrapper {
    position: relative;
}

.mod-dd-search--minimal .dd-search__trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--dd-search-height);
    height: var(--dd-search-height);
    padding: 0;
    border: var(--dd-search-border-width) solid var(--dd-search-border);
    border-radius: var(--dd-search-radius);
    background: var(--dd-search-bg);
    color: var(--dd-search-text);
    cursor: pointer;
    box-shadow: var(--dd-search-shadow);
    transition: all var(--dd-search-speed) ease;
    z-index: 2;
}

.mod-dd-search--minimal .dd-search__trigger svg {
    width: var(--dd-search-icon-size);
    height: var(--dd-search-icon-size);
}

.mod-dd-search--minimal .dd-search__trigger:hover {
    border-color: var(--dd-search-hover-border);
    color: var(--dd-search-primary);
}

.mod-dd-search--minimal .dd-search__expandable {
    position: absolute;
    top: 0;
    display: flex;
    align-items: center;
    width: 0;
    opacity: 0;
    overflow: hidden;
    transition: all var(--dd-search-speed) ease;
    pointer-events: none;
}

.mod-dd-search--minimal.mod-dd-search--expand-left .dd-search__expandable {
    right: 0;
    flex-direction: row-reverse;
}

.mod-dd-search--minimal.mod-dd-search--expand-right .dd-search__expandable {
    left: 0;
}

.mod-dd-search--minimal.is-expanded .dd-search__expandable {
    width: var(--dd-search-width);
    opacity: 1;
    pointer-events: auto;
}

.mod-dd-search--minimal.is-expanded .dd-search__trigger {
    opacity: 0;
    pointer-events: none;
}

.mod-dd-search--minimal .dd-search__expandable .dd-search__input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.mod-dd-search--minimal .dd-search__expandable .dd-search__button {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.mod-dd-search--minimal.mod-dd-search--expand-left .dd-search__expandable .dd-search__input {
    border-radius: var(--dd-search-radius);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: none;
    border-right: 2px solid var(--dd-search-border);
}

.mod-dd-search--minimal.mod-dd-search--expand-left .dd-search__expandable .dd-search__button {
    border-radius: var(--dd-search-radius);
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

/* ==========================================================================
   Focus Animations
   ========================================================================== */

/* Glow */
.mod-dd-search--focus-glow .dd-search__input:focus {
    border-color: var(--dd-search-primary);
    box-shadow: 0 0 0 4px rgba(198, 0, 0, 0.2);
}

.mod-dd-search--focus-glow.mod-dd-search--pill .dd-search__input-wrapper:focus-within {
    border-color: var(--dd-search-primary);
    box-shadow: 0 0 0 4px rgba(198, 0, 0, 0.2);
}

/* Border */
.mod-dd-search--focus-border .dd-search__input:focus {
    border-color: var(--dd-search-primary);
    border-width: 3px;
}

/* Shadow */
.mod-dd-search--focus-shadow .dd-search__input:focus {
    border-color: var(--dd-search-primary);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Color */
.mod-dd-search--focus-color .dd-search__input:focus {
    border-color: var(--dd-search-primary);
    background: rgba(198, 0, 0, 0.05);
}

/* ==========================================================================
   Button Animations
   ========================================================================== */

/* Pulse */
.mod-dd-search--btn-anim-pulse .dd-search__button:hover svg {
    animation: dd-search-pulse 1s ease infinite;
}

@keyframes dd-search-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* Rotate */
.mod-dd-search--btn-anim-rotate .dd-search__button:hover svg {
    animation: dd-search-rotate 0.5s ease;
}

@keyframes dd-search-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Shake */
.mod-dd-search--btn-anim-shake .dd-search__button.is-error {
    animation: dd-search-shake 0.5s ease;
}

@keyframes dd-search-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* Ripple */
.mod-dd-search--btn-anim-ripple .dd-search__button {
    position: relative;
    overflow: hidden;
}

.mod-dd-search--btn-anim-ripple .dd-search__button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease;
}

.mod-dd-search--btn-anim-ripple .dd-search__button:active::after {
    width: 200px;
    height: 200px;
}

/* ==========================================================================
   Expand Animations
   ========================================================================== */

/* Slide */
.mod-dd-search--anim-slide .dd-search__expandable {
    transition: width var(--dd-search-speed) ease, opacity var(--dd-search-speed) ease;
}

/* Fade */
.mod-dd-search--anim-fade .dd-search__expandable {
    width: var(--dd-search-width) !important;
    transition: opacity var(--dd-search-speed) ease;
}

/* Scale */
.mod-dd-search--anim-scale .dd-search__expandable {
    transform-origin: right center;
    transition: transform var(--dd-search-speed) ease, opacity var(--dd-search-speed) ease;
    transform: scaleX(0);
}

.mod-dd-search--anim-scale.is-expanded .dd-search__expandable {
    transform: scaleX(1);
}

/* Bounce */
.mod-dd-search--anim-bounce.is-expanded .dd-search__expandable {
    animation: dd-search-bounce var(--dd-search-speed) ease;
}

@keyframes dd-search-bounce {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* ==========================================================================
   Dropdown
   ========================================================================== */

.dd-search__dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: var(--dd-search-bg, #fff);
    border: 1px solid var(--dd-search-border, #ddd);
    border-radius: var(--dd-search-radius, 8px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    z-index: 9999;
    display: block;
}

.dd-search__dropdown[hidden] {
    display: none !important;
}

.dd-search__section {
    padding: 1rem;
    border-bottom: 1px solid var(--dd-search-border);
}

.dd-search__section:last-child {
    border-bottom: none;
}

.dd-search__section[hidden] {
    display: none;
}

.dd-search__section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--dd-search-text);
    opacity: 0.5;
    margin-bottom: 0.75rem;
}

.dd-search__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.dd-search__list li {
    margin: 0;
}

.dd-search__list a {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.5rem 0;
    color: var(--dd-search-text);
    text-decoration: none;
    transition: all 0.2s ease;
}

.dd-search__list a:hover {
    color: var(--dd-search-primary);
    padding-left: 0.5rem;
}

/* Result description */
.dd-search__desc {
    font-size: 0.75rem;
    opacity: 0.6;
    line-height: 1.3;
}

/* Tags */
.dd-search__tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.dd-search__tags li {
    display: inline-flex;
}

.dd-search__tag {
    display: inline-block;
    padding: 0.35rem 0.75rem !important;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50px;
    font-size: 0.85rem;
}

.dd-search__tag:hover {
    background: var(--dd-search-primary) !important;
    color: white !important;
    padding-left: 0.75rem !important;
}

/* Loading */
.dd-search__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.5rem;
    color: var(--dd-search-text);
    opacity: 0.7;
}

.dd-search__loading[hidden] {
    display: none;
}

.dd-search__spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--dd-search-border);
    border-top-color: var(--dd-search-primary);
    border-radius: 50%;
    animation: dd-search-spin 0.8s linear infinite;
}

@keyframes dd-search-spin {
    to { transform: rotate(360deg); }
}

/* No results */
.dd-search__no-results {
    padding: 1.5rem;
    text-align: center;
    color: var(--dd-search-text);
    opacity: 0.7;
}

.dd-search__no-results[hidden] {
    display: none;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .mod-dd-search--classic .dd-search__wrapper,
    .mod-dd-search--pill .dd-search__wrapper {
        width: 100%;
    }
    
    .mod-dd-search--minimal.is-expanded .dd-search__expandable {
        width: calc(100vw - 100px);
    }
}
