/* ══════════════════════════════════════════
   TG Directory — Frontend CSS
   ══════════════════════════════════════════ */

/* ── Variables ────────────────────────── */
:root {
    --tgd-accent: #0088cc;
    --tgd-accent-hover: #006da3;
    --tgd-bg: #f5f7fa;
    --tgd-card-bg: #ffffff;
    --tgd-border: #e2e8f0;
    --tgd-text: #1e293b;
    --tgd-text-muted: #64748b;
    --tgd-radius: 12px;
    --tgd-shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .06);
    --tgd-shadow-hover: 0 10px 25px rgba(0, 0, 0, .1), 0 4px 10px rgba(0, 0, 0, .06);
    --tgd-transition: .25s ease;
}

/* ── Wrapper ──────────────────────────── */
.tgd-directory {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--tgd-text);
    max-width: 1320px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ── Toolbar ──────────────────────────── */
.tgd-toolbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 28px;
    padding: 16px 20px;
    background: var(--tgd-card-bg);
    border-radius: var(--tgd-radius);
    box-shadow: var(--tgd-shadow);
}

.tgd-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.tgd-toolbar-bottom {
    justify-content: space-between;
}

.tgd-toolbar-right {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-left: auto;
}

.tgd-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    flex: 1;
}

/* Search */
.tgd-search-wrap {
    position: relative;
    flex: 1 1 260px;
    min-width: 200px;
}

.tgd-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    opacity: .45;
    pointer-events: none;
}

.tgd-search {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 1.5px solid var(--tgd-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--tgd-bg);
    transition: border var(--tgd-transition), box-shadow var(--tgd-transition);
    outline: none;
    box-sizing: border-box;
}

.tgd-search:focus {
    border-color: var(--tgd-accent);
    box-shadow: 0 0 0 3px rgba(0, 136, 204, .15);
}

/* Filters & Sort */
.tgd-filter,
.tgd-sort,
.tgd-filter-select {
    padding: 10px 36px 10px 14px;
    border: 1.5px solid var(--tgd-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--tgd-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 12px center;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    transition: border var(--tgd-transition);
    outline: none;
    min-width: 150px;
}

.tgd-filter:focus,
.tgd-sort:focus,
.tgd-filter-select:focus {
    border-color: var(--tgd-accent);
    box-shadow: 0 0 0 3px rgba(0, 136, 204, .15);
}

/* View Toggle */
.tgd-view-toggle {
    display: inline-flex;
    border: 1.5px solid var(--tgd-border);
    border-radius: 8px;
    overflow: hidden;
    margin-left: auto;
}

.tgd-view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--tgd-bg);
    cursor: pointer;
    transition: background var(--tgd-transition), color var(--tgd-transition);
    color: var(--tgd-text-muted);
}

.tgd-view-btn+.tgd-view-btn {
    border-left: 1.5px solid var(--tgd-border);
}

.tgd-view-btn.active,
.tgd-view-btn:hover {
    background: var(--tgd-accent);
    color: #fff;
}

.tgd-view-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ── Grid ─────────────────────────────── */
.tgd-grid {
    display: grid;
    gap: 24px;
    grid-template-columns: repeat(3, 1fr);
}

.tgd-grid[data-cols="2"] {
    grid-template-columns: repeat(2, 1fr);
}

.tgd-grid[data-cols="3"] {
    grid-template-columns: repeat(3, 1fr);
}

.tgd-grid[data-cols="4"] {
    grid-template-columns: repeat(4, 1fr);
}

/* ── Card (Grid View) ────────────────── */
.tgd-card {
    background: var(--tgd-card-bg);
    border-radius: var(--tgd-radius);
    box-shadow: var(--tgd-shadow);
    overflow: hidden;
    transition: transform var(--tgd-transition), box-shadow var(--tgd-transition);
    display: flex;
    flex-direction: column;
}

.tgd-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--tgd-shadow-hover);
}

/* Card Image */
.tgd-card-image {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    /* 16:9 */
    overflow: hidden;
    background: var(--tgd-bg);
}

.tgd-card-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .4s ease;
}

.tgd-card:hover .tgd-card-image img {
    transform: scale(1.05);
}

/* Members badge on image */
.tgd-members-badge {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, .65);
    color: #fff;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    backdrop-filter: blur(4px);
}

.tgd-members-badge svg {
    width: 13px;
    height: 13px;
    fill: #fff;
}

/* Card Body */
.tgd-card-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.tgd-card-title {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.35;
}

.tgd-card-title a {
    color: var(--tgd-text);
    text-decoration: none;
    transition: color var(--tgd-transition);
}

.tgd-card-title a:hover {
    color: var(--tgd-accent);
}

/* Badges */
.tgd-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.tgd-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
}

.tgd-badge-cat {
    background: rgba(0, 136, 204, .1);
    color: var(--tgd-accent);
}

.tgd-badge-lang {
    background: rgba(16, 185, 129, .1);
    color: #059669;
}

.tgd-badge-country {
    background: rgba(245, 158, 11, .1);
    color: #d97706;
}

/* Description */
.tgd-card-desc {
    font-size: 13px;
    color: var(--tgd-text-muted);
    line-height: 1.55;
    margin-bottom: 12px;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Social links */
.tgd-socials {
    display: flex;
    gap: 8px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--tgd-border);
}

.tgd-social-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--tgd-bg);
    color: var(--tgd-text-muted);
    text-decoration: none;
    transition: background var(--tgd-transition), color var(--tgd-transition);
}

.tgd-social-link:hover {
    background: var(--tgd-accent);
    color: #fff;
}

.tgd-social-link svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ── List View ────────────────────────── */
.tgd-grid.tgd-list-view {
    grid-template-columns: 1fr !important;
    gap: 14px;
}

.tgd-list-view .tgd-card {
    flex-direction: row;
    align-items: stretch;
}

.tgd-list-view .tgd-card-image {
    width: 180px;
    min-width: 180px;
    padding-top: 0;
    height: auto;
    min-height: 140px;
}

.tgd-list-view .tgd-card-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.tgd-list-view .tgd-card-body {
    padding: 16px 20px;
}

.tgd-list-view .tgd-card-desc {
    -webkit-line-clamp: 2;
}

/* ── Loading / Spinner ────────────────── */
.tgd-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
    color: var(--tgd-text-muted);
    font-size: 14px;
}

.tgd-spinner {
    width: 40px;
    height: 40px;
    border: 3.5px solid var(--tgd-border);
    border-top-color: var(--tgd-accent);
    border-radius: 50%;
    animation: tgd-spin .7s linear infinite;
}

@keyframes tgd-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── No Results ───────────────────────── */
.tgd-no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--tgd-text-muted);
    font-size: 16px;
}

.tgd-no-results-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: .4;
}

/* ── Pagination ───────────────────────── */
.tgd-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 36px;
    flex-wrap: wrap;
}

.tgd-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border: 1.5px solid var(--tgd-border);
    border-radius: 8px;
    background: var(--tgd-card-bg);
    color: var(--tgd-text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--tgd-transition);
    text-decoration: none;
}

.tgd-page-btn:hover {
    border-color: var(--tgd-accent);
    color: var(--tgd-accent);
    background: rgba(0, 136, 204, .05);
}

.tgd-page-btn.active {
    background: var(--tgd-accent);
    color: #fff;
    border-color: var(--tgd-accent);
    cursor: default;
}

.tgd-page-btn.disabled {
    opacity: .4;
    cursor: default;
    pointer-events: none;
}

.tgd-page-dots {
    padding: 0 4px;
    color: var(--tgd-text-muted);
}

/* ── Results count ────────────────────── */
.tgd-results-count {
    text-align: center;
    color: var(--tgd-text-muted);
    font-size: 13px;
    margin-bottom: 20px;
}

.tgd-results-count strong {
    color: var(--tgd-text);
}

/* ══════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════ */

@media (max-width: 1024px) {
    .tgd-grid[data-cols="4"] {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {

    .tgd-grid,
    .tgd-grid[data-cols="3"],
    .tgd-grid[data-cols="4"] {
        grid-template-columns: repeat(2, 1fr);
    }

    .tgd-toolbar {
        padding: 12px 14px;
    }

    .tgd-search-wrap {
        flex: 1 1 100%;
    }

    .tgd-filter,
    .tgd-sort,
    .tgd-filter-select {
        min-width: 0;
        flex: 1 1 calc(50% - 6px);
    }

    /* List view adjustments */
    .tgd-list-view .tgd-card-image {
        width: 130px;
        min-width: 130px;
    }
}

@media (max-width: 540px) {

    .tgd-grid,
    .tgd-grid[data-cols="2"],
    .tgd-grid[data-cols="3"],
    .tgd-grid[data-cols="4"] {
        grid-template-columns: 1fr;
    }

    .tgd-filter,
    .tgd-sort,
    .tgd-filter-select {
        flex: 1 1 100%;
    }

    .tgd-view-toggle {
        margin-left: 0;
    }

    /* Force grid view on very small screens */
    .tgd-list-view .tgd-card {
        flex-direction: column;
    }

    .tgd-list-view .tgd-card-image {
        width: 100%;
        min-width: unset;
        padding-top: 56.25%;
        min-height: 0;
    }
}

/* ══════════════════════════════════════════
   RTL Support
   ══════════════════════════════════════════ */

[dir="rtl"] .tgd-directory,
.tgd-directory[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .tgd-search-wrap::before {
    left: auto;
    right: 14px;
}

[dir="rtl"] .tgd-search {
    padding: 10px 40px 10px 14px;
}

[dir="rtl"] .tgd-filter,
[dir="rtl"] .tgd-sort,
[dir="rtl"] .tgd-filter-select {
    background-position: left 12px center;
    padding: 10px 14px 10px 36px;
}

[dir="rtl"] .tgd-view-toggle {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .tgd-view-btn+.tgd-view-btn {
    border-left: none;
    border-right: 1.5px solid var(--tgd-border);
}

[dir="rtl"] .tgd-toolbar-right {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .tgd-members-badge {
    right: auto;
    left: 10px;
}

[dir="rtl"] .tgd-list-view .tgd-card-body {
    padding: 16px 20px;
}

[dir="rtl"] .tgd-socials {
    direction: rtl;
}

/* ====================================================
   HERO SEARCH COMPONENT [tg_search]
   ==================================================== */

.tgd-hero {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.tgd-hero-bg {
    background: transparent;
    position: relative;
    overflow: hidden;
}

.tgd-hero-bg::before {
    display: none;
}

.tgd-hero-inner {
    position: relative;
    z-index: 1;
    max-width: 820px;
    margin: 0 auto;
    padding: 80px 24px 60px;
    text-align: center;
}

/* Title & Subtitle */
.tgd-hero-title {
    color: #ffffff;
    font-size: 2.8rem;
    font-weight: 800;
    line-height: 1.2;
    margin: 0 0 16px;
    letter-spacing: -0.02em;
}

.tgd-hero-subtitle {
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.15rem;
    line-height: 1.6;
    margin: 0 0 36px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* Search Box */
.tgd-hero-search-wrap {
    position: relative;
    max-width: 620px;
    margin: 0 auto 28px;
}

.tgd-hero-search-box {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transition: box-shadow 0.25s ease, border-color 0.25s ease;
}

.tgd-hero-search-box:focus-within {
    border-color: #0088cc;
    box-shadow: 0 4px 24px rgba(0, 136, 204, 0.3);
}

.tgd-hero-search-icon {
    flex-shrink: 0;
    margin-left: 18px;
    color: rgba(255, 255, 255, 0.5);
    transition: color 0.2s;
}

.tgd-hero-search-box:focus-within .tgd-hero-search-icon {
    color: #0088cc;
}

.tgd-hero-search-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 18px 14px;
    font-size: 1.05rem;
    color: #fff;
    background: transparent;
    min-width: 0;
}

.tgd-hero-search-input::placeholder {
    color: rgba(255, 255, 255, 0.45);
}

.tgd-hero-search-btn {
    flex-shrink: 0;
    background: #0088cc;
    color: #fff;
    border: none;
    padding: 14px 28px;
    margin: 6px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.tgd-hero-search-btn:hover {
    background: #006fa3;
}

.tgd-hero-search-btn:active {
    background: #005a85;
}

/* Live Results Dropdown */
.tgd-hero-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    z-index: 100;
    overflow: hidden;
    max-height: 420px;
    overflow-y: auto;
}

.tgd-hero-result-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    text-decoration: none;
    color: #222;
    transition: background 0.15s ease;
    border-bottom: 1px solid #f0f0f0;
}

.tgd-hero-result-item:last-child {
    border-bottom: none;
}

.tgd-hero-result-item:hover,
.tgd-hero-result-item.tgd-active {
    background: #f0f7ff;
}

.tgd-hero-result-img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #f0f0f0;
}

.tgd-hero-result-info {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.tgd-hero-result-title {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #222;
    margin: 0;
}

.tgd-hero-result-meta {
    font-size: 0.82rem;
    color: #888;
    margin-top: 2px;
}

.tgd-hero-result-meta span+span::before {
    content: ' · ';
}

.tgd-hero-results-footer {
    display: block;
    text-align: center;
    padding: 14px;
    background: #f8fafc;
    color: #0088cc;
    font-weight: 600;
    font-size: 0.92rem;
    text-decoration: none;
    border-top: 1px solid #eee;
    transition: background 0.15s;
}

.tgd-hero-results-footer:hover {
    background: #edf4fb;
}

.tgd-hero-no-results {
    padding: 24px 18px;
    text-align: center;
    color: #888;
    font-size: 0.95rem;
}

.tgd-hero-results-loading {
    padding: 20px;
    text-align: center;
    color: #999;
}

.tgd-hero-results-loading .tgd-spinner {
    width: 24px;
    height: 24px;
    border-width: 3px;
    margin: 0 auto;
}

/* Category Pills */
.tgd-hero-cats {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 36px;
}

.tgd-hero-cats-label {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.9rem;
    font-weight: 500;
    margin-right: 4px;
}

.tgd-hero-pill {
    display: inline-block;
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.85);
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.2s ease, transform 0.15s ease, color 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.tgd-hero-pill:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    transform: translateY(-1px);
    text-decoration: none;
}

/* Stats */
.tgd-hero-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-wrap: wrap;
}

.tgd-hero-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tgd-hero-stat-num {
    color: #fff;
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1;
}

.tgd-hero-stat-label {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.82rem;
    font-weight: 500;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Responsive ── */

@media (max-width: 768px) {
    .tgd-hero-inner {
        padding: 56px 16px 44px;
    }

    .tgd-hero-title {
        font-size: 2rem;
    }

    .tgd-hero-subtitle {
        font-size: 1rem;
    }

    .tgd-hero-search-btn {
        padding: 12px 18px;
        font-size: 0.9rem;
    }

    .tgd-hero-stats {
        gap: 20px;
    }

    .tgd-hero-stat-num {
        font-size: 1.4rem;
    }
}

@media (max-width: 480px) {
    .tgd-hero-inner {
        padding: 44px 12px 36px;
    }

    .tgd-hero-title {
        font-size: 1.6rem;
    }

    .tgd-hero-search-box {
        border-radius: 12px;
        flex-wrap: wrap;
    }

    .tgd-hero-search-input {
        padding: 14px 12px;
        font-size: 0.95rem;
    }

    .tgd-hero-search-btn {
        width: calc(100% - 12px);
        margin: 0 6px 6px;
        border-radius: 10px;
        padding: 12px;
    }

    .tgd-hero-search-icon {
        margin-left: 14px;
    }

    .tgd-hero-cats {
        gap: 6px;
    }

    .tgd-hero-pill {
        padding: 5px 12px;
        font-size: 0.8rem;
    }

    .tgd-hero-stats {
        gap: 16px;
    }

    .tgd-hero-stat-num {
        font-size: 1.2rem;
    }

    .tgd-hero-stat-label {
        font-size: 0.75rem;
    }
}

/* ── RTL support for hero ── */

[dir="rtl"] .tgd-hero-search-icon {
    margin-left: 0;
    margin-right: 18px;
}

[dir="rtl"] .tgd-hero-cats-label {
    margin-right: 0;
    margin-left: 4px;
}

[dir="rtl"] .tgd-hero-result-info {
    text-align: right;
}

@media (max-width: 480px) {
    [dir="rtl"] .tgd-hero-search-icon {
        margin-right: 14px;
        margin-left: 0;
    }
}