/* SG Dictionary — search + filter + card grid (ported from sblog-slanggenz .dictionary) */

.sg-dictionary {
    width: min(1180px, calc(100% - 40px));
    margin: 100px auto 60px;
}

.sg-dictionary-head {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 24px;
    align-items: end;
    margin-bottom: 28px;
}

@media (max-width: 700px) {
    .sg-dictionary-head {
        grid-template-columns: 1fr;
    }
}

.sg-dictionary-title {
    margin: 12px 0 6px;
    font-size: clamp(28px, 3.5vw, 42px);
    font-weight: 800;
    color: var(--sg-text);
    line-height: 1.1;
}

.sg-dictionary-sub {
    margin: 0;
    color: var(--sg-muted);
    font-size: 14px;
}

/* Search — underline minimal, lime bar trượt vào khi focus */
.sg-dict-search {
    position: relative;
    margin-bottom: 20px;
}

.sg-dict-search input[type="search"] {
    width: 100%;
    background: transparent;
    background-color: transparent;
    border: 0;
    outline: 0;
    border-bottom: 1px solid var(--sg-line);
    border-radius: 0;
    padding: 12px 2px;
    font-size: 17px;
    font-weight: 600;
    color: var(--sg-text);
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color .25s ease;
}

.sg-dict-search input[type="search"]::placeholder {
    color: var(--sg-muted);
    font-weight: 500;
}

.sg-dict-search::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    width: 100%;
    background: var(--sg-lime);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .45s cubic-bezier(.22, 1, .36, 1);
    pointer-events: none;
}

.sg-dict-search:focus-within::after {
    transform: scaleX(1);
}

/* Filter chips — gọn, ít padding hơn */
.sg-dict-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--sg-line);
}

.sg-dict-chip {
    background: transparent;
    border: 1px solid var(--sg-line);
    color: var(--sg-muted);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .01em;
    cursor: pointer;
    transition: color .18s ease, border-color .18s ease, background-color .18s ease, transform .18s ease;
}

.sg-dict-chip:hover {
    color: var(--sg-text);
    border-color: var(--sg-text);
    transform: translateY(-1px);
}

.sg-dict-chip.is-active {
    background: var(--sg-lime);
    color: #0c0d0a;
    border-color: var(--sg-lime);
}

/* Live result count (JS cập nhật khi search/filter) */
.sg-dict-count {
    margin: 14px 0 6px;
    color: var(--sg-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}

/* Word list — minimal index rows, 2 cột desktop */
.sg-word-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0 48px;
}

.sg-word-card {
    display: contents;
}

.sg-word-card-btn {
    display: grid;
    grid-template-columns: minmax(110px, max-content) 1fr;
    align-items: baseline;
    gap: 14px;
    width: 100%;
    padding: 12px 10px;
    background: transparent;
    border: 0;
    border-bottom: 1px solid color-mix(in srgb, var(--sg-line) 55%, transparent);
    border-radius: 0;
    text-align: left;
    cursor: pointer;
    color: var(--sg-text);
    transition: padding-left .22s cubic-bezier(.22, 1, .36, 1), background-color .22s ease;
    animation: sg-row-in .32s ease both;
}

@keyframes sg-row-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Stagger entrance cho ~20 rows đầu */
.sg-word-card:nth-child(n+2):nth-child(-n+6) .sg-word-card-btn { animation-delay: 30ms; }
.sg-word-card:nth-child(n+7):nth-child(-n+12) .sg-word-card-btn { animation-delay: 60ms; }
.sg-word-card:nth-child(n+13):nth-child(-n+20) .sg-word-card-btn { animation-delay: 90ms; }

@media (prefers-reduced-motion: reduce) {
    .sg-word-card-btn { animation: none; }
}

.sg-word-term {
    font-family: var(--sg-font-display);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -.01em;
    white-space: nowrap;
    color: var(--sg-text);
    transition: color .18s ease;
}

.sg-word-def {
    margin: 0;
    color: var(--sg-muted);
    font-size: 13px;
    line-height: 1.45;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color .18s ease;
}

/* Hover micro-interaction: indent + term chuyển lime */
.sg-word-card-btn:hover {
    padding-left: 18px;
    background: color-mix(in srgb, var(--sg-card) 55%, transparent);
}

.sg-word-card-btn:hover .sg-word-term { color: var(--sg-lime); }
.sg-word-card-btn:hover .sg-word-def { color: var(--sg-text); }

.sg-word-card-btn:focus-visible {
    outline: 2px solid var(--sg-lime);
    outline-offset: -2px;
}

/* Card hidden state when filtered out */
.sg-word-card.is-hidden {
    display: none;
}

/* Empty state */
.sg-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--sg-muted);
    border: 1px dashed var(--sg-line);
    border-radius: 18px;
    font-size: 14px;
}

/* Modal dialog */
.sg-slang-dialog {
    width: min(560px, calc(100% - 32px));
    max-height: 80vh;
    padding: 0;
    border: 1px solid var(--sg-line);
    border-radius: 22px;
    background: var(--sg-bg-soft);
    color: var(--sg-text);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
    overflow: hidden;
}

.sg-slang-dialog::backdrop {
    background: rgba(8, 8, 12, .72);
    backdrop-filter: blur(8px);
}

.sg-dialog-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--sg-line);
    background: var(--sg-card);
    color: var(--sg-text);
    font-size: 14px;
    cursor: pointer;
    z-index: 2;
    display: grid;
    place-items: center;
    transition: all 200ms ease;
}

.sg-dialog-close:hover {
    background: var(--sg-lime);
    color: #0c0d0a;
    border-color: var(--sg-lime);
}

.sg-dialog-body {
    padding: 36px 28px 28px;
    overflow-y: auto;
    max-height: 80vh;
}

.sg-dialog-loading {
    color: var(--sg-muted);
    text-align: center;
    margin: 20px 0;
}

/* Empty state (dictionary) */
.sg-dict-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--sg-muted);
    border: 1px dashed var(--sg-line);
    border-radius: 18px;
    font-size: 14px;
}

/* Load more */
.sg-dict-more {
    display: flex;
    justify-content: center;
    margin-top: 32px;
}

.sg-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border: 0;
    transition: transform 200ms ease, box-shadow 200ms ease, opacity 200ms ease;
}

.sg-btn-ghost {
    background: transparent;
    border: 1px solid var(--sg-line);
    color: var(--sg-text);
}

.sg-btn-ghost:hover {
    border-color: var(--sg-lime);
    color: var(--sg-lime);
    transform: translateY(-2px);
}

.sg-btn-ghost:disabled {
    opacity: .5;
    cursor: default;
    transform: none;
}

/* Grid loading state (JS toggles trên #sg-word-grid) */
.sg-word-grid.is-loading {
    opacity: .55;
    pointer-events: none;
    transition: opacity 150ms ease;
}

/* Inline empty state (JS render khi search/filter không có kết quả) */
.sg-dict-empty-inline {
    list-style: none;
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--sg-muted);
    border: 1px dashed var(--sg-line);
    border-radius: 18px;
    font-size: 14px;
}

/* ---------- Modal content (JS render) ---------- */
.sg-dialog-emoji {
    font-size: 44px;
    line-height: 1;
    margin-bottom: 8px;
}
.sg-dialog-term {
    margin: 0 0 10px;
    padding-right: 40px;
    font-size: clamp(26px, 4vw, 36px);
    font-weight: 800;
    line-height: 1.1;
    color: var(--sg-text);
}
.sg-dialog-meta {
    margin-bottom: 16px;
    color: var(--sg-pink);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.sg-dialog-def {
    margin: 0 0 18px;
    font-size: 17px;
    line-height: 1.6;
    color: var(--sg-muted);
    font-weight: 500;
}
.sg-dialog-content {
    font-size: 16px;
    line-height: 1.7;
    color: var(--sg-text);
}
.sg-dialog-content p { margin: 0 0 1.2em; }
.sg-dialog-content p:last-child { margin-bottom: 0; }
.sg-dialog-example,
.sg-dialog-origin {
    margin-top: 18px;
    padding: 16px 20px;
    border-left: 4px solid var(--sg-lime);
    border-radius: 0 12px 12px 0;
    background: color-mix(in srgb, var(--sg-card) 70%, transparent);
}
.sg-dialog-origin { border-left-color: var(--sg-pink); }
.sg-dialog-example p,
.sg-dialog-origin p {
    margin: 6px 0 0;
    font-size: 15px;
    line-height: 1.6;
    color: var(--sg-text);
}
.sg-dialog-example .sg-eyebrow,
.sg-dialog-origin .sg-eyebrow { margin-bottom: 0; }
.sg-dialog-error {
    color: var(--sg-pink);
    text-align: center;
    margin: 20px 0;
}

/* ============================================================
 * MOBILE ≤ 700px — dictionary tối ưu chạm
 * Filter rail cuộn ngang 1 hàng (snap + mép mờ), list 1 cột,
 * search full-width underline. Đè Flatsome button full-width
 * bằng width:auto !important trên chip.
 * ============================================================ */
@media (max-width: 700px) {
    .sg-dictionary {
        width: calc(100% - 40px);
        margin: 56px auto 40px;
    }

    /* Search underline — font 16px tránh iOS auto-zoom */
    .sg-dict-search input[type="search"] {
        font-size: 16px;
        padding: 10px 2px;
    }

    /* Filter rail: 1 hàng, cuộn ngang, snap, fade 2 mép.
       Margin âm -16px đẩy rail tràn nhẹ ra mép viewport (container
       có 20px slack mỗi bên) để lộ hint cuộn — không gây overflow trang. */
    .sg-dict-filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        gap: 6px;
        margin: 16px -16px 12px;
        padding: 2px 16px 14px;
        scrollbar-width: none;
        -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
        mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
    }

    .sg-dict-filters::-webkit-scrollbar {
        display: none;
    }

    .sg-dict-chip {
        flex: 0 0 auto;
        width: auto !important; /* đè Flatsome button stretch */
        scroll-snap-align: start;
        padding: 6px 12px;
        white-space: nowrap;
    }

    /* List 1 cột — rows compact */
    .sg-word-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .sg-word-card-btn {
        grid-template-columns: minmax(96px, max-content) 1fr;
        gap: 12px;
        padding: 11px 6px;
    }

    .sg-word-term {
        font-size: 15px;
    }

    .sg-word-def {
        font-size: 12.5px;
    }

    /* Load-more không bị Flatsome kéo full-width */
    .sg-dict-more .sg-btn {
        width: auto;
    }
}

@media (max-width: 400px) {
    /* Màn quá hẹp: term + def xếp dọc, def wrap bình thường */
    .sg-word-card-btn {
        grid-template-columns: 1fr;
        gap: 3px;
        padding: 10px 6px;
    }
    .sg-word-def {
        white-space: normal;
    }
}

/* ============================================================
 * SEO content — intro / popular terms / FAQ (/tu-dien/)
 * ============================================================ */
.sg-dict-intro {
    max-width: 680px;
    margin: 0 0 40px;
}

.sg-dict-intro p {
    margin: 0 0 14px;
    color: var(--sg-muted);
    font-size: 15px;
    line-height: 1.7;
}

.sg-dict-intro p:last-child {
    margin-bottom: 0;
}

.sg-dict-seo-title {
    margin: 56px 0 18px;
    font-family: var(--sg-font-display);
    font-size: clamp(20px, 2.5vw, 26px);
    font-weight: 800;
    color: var(--sg-text);
}

/* Popular terms — cùng style minimal list với word grid */
.sg-dict-popular-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0 48px;
}

.sg-dict-popular-list a {
    display: grid;
    grid-template-columns: minmax(110px, max-content) 1fr;
    align-items: baseline;
    gap: 14px;
    padding: 10px;
    border-bottom: 1px solid color-mix(in srgb, var(--sg-line) 55%, transparent);
    color: var(--sg-text);
    text-decoration: none;
    transition: padding-left .22s cubic-bezier(.22, 1, .36, 1), background-color .22s ease;
}

.sg-dict-popular-list a:hover {
    padding-left: 18px;
    background: color-mix(in srgb, var(--sg-card) 55%, transparent);
}

.sg-dict-popular-list strong {
    font-family: var(--sg-font-display);
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    transition: color .18s ease;
}

.sg-dict-popular-list a:hover strong {
    color: var(--sg-lime);
}

.sg-dict-popular-list span {
    color: var(--sg-muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* FAQ — native details/summary accordion */
.sg-faq-item {
    border-bottom: 1px solid color-mix(in srgb, var(--sg-line) 55%, transparent);
}

.sg-faq-item summary {
    padding: 14px 10px;
    font-weight: 700;
    font-size: 15px;
    color: var(--sg-text);
    cursor: pointer;
    transition: color .18s ease;
}

.sg-faq-item summary:hover {
    color: var(--sg-lime);
}

.sg-faq-item p {
    margin: 0;
    padding: 0 10px 16px;
    color: var(--sg-muted);
    font-size: 14px;
    line-height: 1.65;
}

@media (max-width: 700px) {
    .sg-dict-popular-list {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .sg-dict-seo-title {
        margin: 40px 0 14px;
    }
}

@media (max-width: 400px) {
    .sg-dict-popular-list a {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .sg-dict-popular-list span {
        white-space: normal;
    }
}
