/* ==========================================================================
   Anchor Post Display — Frontend Styles
   ========================================================================== */

:root {
    --apd-accent: #0073aa;
    --apd-accent-hover: #005a87;
    --apd-border: #ddd;
    --apd-radius: 6px;
    --apd-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    --apd-card-bg: #fff;
    --apd-text: #333;
    --apd-text-light: #666;
    --apd-gap: 20px;
    --apd-transition: 0.2s ease;
}

/* ---------- Search form ---------- */

.anchor-search {
    position: relative;
    display: flex;
    align-items: center;
    max-width: 600px;
    margin: 0 0 1.5em;
}

.anchor-search-field {
    flex: 1;
    padding: 10px 14px 10px 38px;
    border: 1px solid var(--apd-border);
    border-radius: var(--apd-radius);
    font-size: 15px;
    line-height: 1.4;
    outline: none;
    transition: border-color var(--apd-transition);
}

.anchor-search-field:focus {
    border-color: var(--apd-accent);
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.15);
}

.anchor-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: #999;
    pointer-events: none;
}

.anchor-search-btn {
    margin-left: 8px;
    padding: 10px 18px;
    background: var(--apd-accent);
    color: #fff;
    border: none;
    border-radius: var(--apd-radius);
    font-size: 15px;
    cursor: pointer;
    transition: background var(--apd-transition);
}

.anchor-search-btn:hover {
    background: var(--apd-accent-hover);
}

/* ---------- Live search dropdown ---------- */

.anchor-search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: var(--apd-card-bg);
    border: 1px solid var(--apd-border);
    border-radius: var(--apd-radius);
    box-shadow: var(--apd-shadow);
    max-height: 360px;
    overflow-y: auto;
    z-index: 1000;
}

.anchor-search-results.is-open {
    display: block;
}

.anchor-search-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--apd-text);
    border-bottom: 1px solid #f0f0f0;
    transition: background var(--apd-transition);
}

.anchor-search-result:last-child {
    border-bottom: none;
}

.anchor-search-result:hover,
.anchor-search-result.is-active {
    background: #f5f8fa;
}

.anchor-search-result-thumb {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
}

.anchor-search-result-info {
    flex: 1;
    min-width: 0;
}

.anchor-search-result-title {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.anchor-search-result-type {
    display: inline-block;
    margin-top: 2px;
    padding: 1px 6px;
    background: #eee;
    border-radius: 3px;
    font-size: 11px;
    color: var(--apd-text-light);
    text-transform: capitalize;
}

.anchor-search-no-results {
    padding: 14px;
    text-align: center;
    color: var(--apd-text-light);
    font-size: 14px;
}

/* ---------- Spinner ---------- */

.anchor-search-spinner {
    display: none;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border: 2px solid #ddd;
    border-top-color: var(--apd-accent);
    border-radius: 50%;
    animation: apd-spin 0.6s linear infinite;
}

.anchor-search.has-btn .anchor-search-spinner {
    right: auto;
    left: calc(100% - 100px);
}

.anchor-search.is-loading .anchor-search-spinner {
    display: block;
}

@keyframes apd-spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* ---------- Post grid ---------- */

.anchor-post-grid {
    display: grid;
    gap: var(--apd-gap);
    transition: opacity var(--apd-transition);
}

.anchor-post-grid[data-columns="1"] { grid-template-columns: 1fr; }
.anchor-post-grid[data-columns="2"] { grid-template-columns: repeat(2, 1fr); }
.anchor-post-grid[data-columns="3"] { grid-template-columns: repeat(3, 1fr); }
.anchor-post-grid[data-columns="4"] { grid-template-columns: repeat(4, 1fr); }

.anchor-post-grid.is-loading {
    opacity: 0.5;
    pointer-events: none;
}

/* List layout */
.anchor-post-grid[data-layout="list"] {
    grid-template-columns: 1fr !important;
}

.anchor-post-grid[data-layout="list"] .anchor-post-grid-card {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
}

.anchor-post-grid[data-layout="list"] .anchor-post-grid-image {
    flex-shrink: 0;
    width: 200px;
}

.anchor-post-grid[data-layout="list"] .anchor-post-grid-body {
    flex: 1;
}

/* ---------- Card ---------- */

.anchor-post-grid-card {
    display: flex;
    flex-direction: column;
    background: var(--apd-card-bg);
    border: 1px solid var(--apd-border);
    border-radius: var(--apd-radius);
    overflow: hidden;
    text-decoration: none;
    color: var(--apd-text);
    transition: transform var(--apd-transition), box-shadow var(--apd-transition);
}

.anchor-post-grid-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--apd-shadow);
}

.anchor-post-grid-image img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.anchor-post-grid-body {
    padding: 16px;
}

.anchor-post-grid-title {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
}

.anchor-post-grid-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--apd-text-light);
}

.anchor-post-grid-type-badge {
    display: inline-block;
    padding: 1px 6px;
    background: #eee;
    border-radius: 3px;
    text-transform: capitalize;
}

.anchor-post-grid-excerpt {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--apd-text-light);
}

/* ---------- No results ---------- */

.anchor-post-grid-empty {
    grid-column: 1 / -1;
    padding: 40px 20px;
    text-align: center;
    color: var(--apd-text-light);
    font-size: 15px;
}

/* ---------- Pagination ---------- */

.anchor-post-grid-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: var(--apd-gap);
    flex-wrap: wrap;
}

.anchor-post-grid-pagination .page-num,
.anchor-post-grid-pagination .page-dots {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--apd-border);
    border-radius: var(--apd-radius);
    font-size: 14px;
    color: var(--apd-text);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--apd-transition), color var(--apd-transition);
    background: var(--apd-card-bg);
}

.anchor-post-grid-pagination .page-num:hover {
    background: #f5f8fa;
}

.anchor-post-grid-pagination .page-num.is-current {
    background: var(--apd-accent);
    color: #fff;
    border-color: var(--apd-accent);
    cursor: default;
}

.anchor-post-grid-pagination .page-dots {
    border: none;
    cursor: default;
}

.anchor-post-grid-load-more {
    display: block;
    margin: var(--apd-gap) auto 0;
    padding: 10px 28px;
    background: var(--apd-accent);
    color: #fff;
    border: none;
    border-radius: var(--apd-radius);
    font-size: 15px;
    cursor: pointer;
    transition: background var(--apd-transition);
}

.anchor-post-grid-load-more:hover {
    background: var(--apd-accent-hover);
}

.anchor-post-grid-load-more:disabled {
    opacity: 0.5;
    cursor: default;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
    .anchor-post-grid[data-columns="3"],
    .anchor-post-grid[data-columns="4"] {
        grid-template-columns: repeat(2, 1fr);
    }

    .anchor-post-grid[data-layout="list"] .anchor-post-grid-image {
        width: 140px;
    }
}

@media (max-width: 480px) {
    .anchor-post-grid[data-columns="2"],
    .anchor-post-grid[data-columns="3"],
    .anchor-post-grid[data-columns="4"] {
        grid-template-columns: 1fr;
    }

    .anchor-post-grid[data-layout="list"] .anchor-post-grid-card {
        flex-direction: column;
    }

    .anchor-post-grid[data-layout="list"] .anchor-post-grid-image {
        width: 100%;
    }
}
