/* ======================================================================
   MODULE — SEARCH OVERLAY (AJAX, modern design)
   Prefix: .m-search
   ====================================================================== */

/* ─────────── Trigger Button (sağ üst floating) ─────────── */

.m-search-trigger {
    position: fixed;
    top: calc(var(--header-h, 64px) + 12px);
    inset-inline-end: var(--sp-4, 16px);
    width: 44px;
    height: 44px;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 50%;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    z-index: var(--z-sticky, 100);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,0.08));
    transition: transform var(--t-fast, 0.15s), background var(--t-fast, 0.15s),
                color var(--t-fast, 0.15s), border-color var(--t-fast, 0.15s);
}

.m-search-trigger:hover {
    background: var(--primary, #e85d04);
    border-color: var(--primary, #e85d04);
    color: #fff;
    transform: scale(1.06);
}

.m-search-trigger:focus-visible {
    outline: 2px solid var(--primary, #e85d04);
    outline-offset: 3px;
}

.m-search-trigger svg {
    width: 18px;
    height: 18px;
}

/* ─────────── Overlay ─────────── */

.m-search-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 1000);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 8vh;
}

.m-search-overlay[hidden] {
    display: none;
}

.m-search-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: m-search-fade 200ms ease-out;
}

@keyframes m-search-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.m-search-panel {
    position: relative;
    width: min(92vw, 640px);
    max-height: 80vh;
    background: var(--bg-card, #fff);
    border-radius: var(--radius-lg, 16px);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: m-search-slide 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes m-search-slide {
    from { opacity: 0; transform: translateY(-16px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─────────── Header (input row) ─────────── */

.m-search-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    background: var(--bg-card, #fff);
}

.m-search-icon {
    width: 22px;
    height: 22px;
    color: var(--text-muted, #6b7280);
    flex-shrink: 0;
}

.m-search-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 17px;
    color: var(--text, #111827);
    font-family: inherit;
    font-weight: 500;
    padding: 4px 0;
    min-width: 0;
}

.m-search-input::placeholder {
    color: var(--text-soft, #9ca3af);
    font-weight: 400;
}

/* Spinner — query gönderildiğinde gözükür */
.m-search-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid color-mix(in srgb, var(--primary, #e85d04) 25%, transparent);
    border-top-color: var(--primary, #e85d04);
    border-radius: 50%;
    animation: m-search-spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes m-search-spin {
    to { transform: rotate(360deg); }
}

/* Esc kbd hint — desktop only */
.m-search-kbd {
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #6b7280);
    background: var(--bg-soft, #f3f4f6);
    border: 1px solid var(--border, #e5e7eb);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 2px 6px;
    line-height: 1;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .m-search-kbd { display: none; }
}

.m-search-close {
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--t-fast, 0.15s), color var(--t-fast, 0.15s);
    flex-shrink: 0;
}

.m-search-close:hover {
    background: var(--bg-soft, #f3f4f6);
    color: var(--text, #111827);
}

.m-search-close svg {
    width: 16px;
    height: 16px;
}

/* ─────────── Body ─────────── */

.m-search-body {
    overflow-y: auto;
    padding: 16px 18px 20px;
    flex: 1;
}

.m-search-state[hidden] { display: none; }

/* ─────────── State: Idle (boş input) ─────────── */

.m-search-recent {
    margin-bottom: 18px;
}

.m-search-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.m-search-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.m-search-clear-recent {
    background: transparent;
    border: none;
    color: var(--text-soft, #9ca3af);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color var(--t-fast, 0.15s), background var(--t-fast, 0.15s);
}

.m-search-clear-recent:hover {
    color: var(--text, #111827);
    background: var(--bg-soft, #f3f4f6);
}

.m-search-recent-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.m-search-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-soft, #f3f4f6);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 999px;
    font-size: 13px;
    color: var(--text, #111827);
    cursor: pointer;
    transition: background var(--t-fast, 0.15s), border-color var(--t-fast, 0.15s);
}

.m-search-chip:hover {
    background: var(--bg-card, #fff);
    border-color: var(--primary, #e85d04);
    color: var(--primary, #e85d04);
}

.m-search-chip svg {
    width: 12px;
    height: 12px;
    color: var(--text-muted, #6b7280);
    flex-shrink: 0;
}

/* Hint (recent yoksa veya altında) */
.m-search-hint {
    text-align: center;
    padding: 24px 16px;
}

.m-search-hint-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: color-mix(in srgb, var(--primary, #e85d04) 8%, var(--bg-card, #fff));
    border-radius: 50%;
    margin-bottom: 14px;
    color: var(--primary, #e85d04);
}

.m-search-hint-icon svg {
    width: 26px;
    height: 26px;
}

.m-search-hint-text {
    font-size: 14px;
    color: var(--text-muted, #6b7280);
    margin: 0 0 16px;
    line-height: 1.5;
}

.m-search-shortcuts {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
    font-size: 12px;
    color: var(--text-soft, #9ca3af);
}

.m-search-shortcut {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.m-search-shortcut kbd {
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    background: var(--bg-soft, #f3f4f6);
    border: 1px solid var(--border, #e5e7eb);
    border-bottom-width: 2px;
    border-radius: 3px;
    padding: 1px 5px;
    color: var(--text, #111827);
}

/* ─────────── State: Loading (shimmer skeleton) ─────────── */

.m-search-skel {
    height: 64px;
    background: linear-gradient(90deg,
        var(--bg-soft, #f3f4f6) 0%,
        color-mix(in srgb, var(--bg-soft, #f3f4f6) 60%, white) 50%,
        var(--bg-soft, #f3f4f6) 100%);
    background-size: 200% 100%;
    border-radius: 12px;
    margin-bottom: 8px;
    animation: m-search-shimmer 1.4s ease-in-out infinite;
}

@keyframes m-search-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─────────── State: Results ─────────── */

.m-search-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.m-search-result {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: background var(--t-fast, 0.15s), transform var(--t-fast, 0.15s);
    border: 1px solid transparent;
}

.m-search-result:hover,
.m-search-result.is-active {
    background: color-mix(in srgb, var(--primary, #e85d04) 6%, var(--bg-card, #fff));
    border-color: color-mix(in srgb, var(--primary, #e85d04) 20%, transparent);
}

.m-search-result.is-active {
    /* Klavye ile seçili */
    background: color-mix(in srgb, var(--primary, #e85d04) 10%, var(--bg-card, #fff));
}

.m-search-result-thumb {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-soft, #f3f4f6);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border, #e5e7eb);
}

.m-search-result-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.m-search-result-thumb-empty {
    font-size: 22px;
    color: var(--text-soft, #9ca3af);
}

.m-search-result-body {
    flex: 1;
    min-width: 0;
}

.m-search-result-name {
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text, #111827);
    margin: 0 0 2px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.m-search-result-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted, #6b7280);
    line-height: 1.3;
}

.m-search-result-cat {
    display: inline-flex;
    align-items: center;
}

.m-search-result-desc {
    color: var(--text-soft, #9ca3af);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.m-search-result-sep {
    color: var(--border, #e5e7eb);
}

.m-search-result-price {
    font-weight: 700;
    color: var(--primary, #e85d04);
    font-size: 14px;
    flex-shrink: 0;
}

.m-search-result-arrow {
    width: 16px;
    height: 16px;
    color: var(--text-soft, #9ca3af);
    flex-shrink: 0;
    transition: transform var(--t-fast, 0.15s), color var(--t-fast, 0.15s);
}

.m-search-result:hover .m-search-result-arrow,
.m-search-result.is-active .m-search-result-arrow {
    color: var(--primary, #e85d04);
    transform: translateX(3px);
}

/* Search query highlight içeride */
.m-search-mark {
    background: color-mix(in srgb, var(--primary, #e85d04) 25%, transparent);
    color: inherit;
    padding: 0 2px;
    border-radius: 3px;
}

/* ─────────── State: Empty / No results ─────────── */

.m-search-empty {
    text-align: center;
    padding: 36px 16px;
}

.m-search-empty-icon {
    font-size: 48px;
    line-height: 1;
    margin-bottom: 12px;
}

.m-search-empty-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text, #111827);
    margin: 0 0 6px;
}

.m-search-empty-text {
    font-size: 13.5px;
    color: var(--text-muted, #6b7280);
    line-height: 1.5;
    margin: 0 0 18px;
}

.m-search-empty-cta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: var(--primary, #e85d04);
    color: white;
    border-radius: 999px;
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    transition: transform var(--t-fast, 0.15s), background var(--t-fast, 0.15s);
}

.m-search-empty-cta:hover {
    transform: translateY(-1px);
    background: color-mix(in srgb, var(--primary, #e85d04) 90%, black);
}

/* ─────────── Body scroll lock ─────────── */

body.m-search-locked {
    overflow: hidden;
}

/* ─────────── Mobile ─────────── */

@media (max-width: 640px) {
    .m-search-overlay {
        padding-top: 0;
        align-items: stretch;
    }
    .m-search-panel {
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    .m-search-body {
        padding: 14px;
    }
    .m-search-result-desc {
        display: none;
    }
}

/* ─────────── RTL ─────────── */

[dir="rtl"] .m-search-result-arrow {
    transform: scaleX(-1);
}

[dir="rtl"] .m-search-result:hover .m-search-result-arrow,
[dir="rtl"] .m-search-result.is-active .m-search-result-arrow {
    transform: scaleX(-1) translateX(3px);
}
