/**
 * HGW V2 Frontend Components CSS
 *
 * Styles for V2 entity cards, search dropdown, stats widgets,
 * map popups, loading/error states, and pagination.
 *
 * Uses theme CSS variables: --color-gold, --color-green, --color-paper
 *
 * @package Great_Wall_Engine
 * @since 2.0.0
 */

/* ================================================================
   V2 Search Dropdown
   ================================================================ */

.hgw-v2-search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ccd0d4;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    max-height: 400px;
    overflow-y: auto;
    display: none;
    margin-top: 4px;
}

.hgw-v2-search-dropdown .hgw-v2-search-loading,
.hgw-v2-search-dropdown .hgw-v2-search-error,
.hgw-v2-search-dropdown .hgw-v2-search-empty {
    padding: 16px 20px;
    text-align: center;
    color: #646970;
    font-size: 14px;
}

.hgw-v2-search-loading .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f0f0f1;
    border-top-color: var(--color-gold, #D8A63A);
    border-radius: 50%;
    animation: hgw-v2-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes hgw-v2-spin {
    to { transform: rotate(360deg); }
}

.hgw-v2-search-section {
    padding: 4px 0;
    border-bottom: 1px solid #f0f0f1;
}

.hgw-v2-search-section:last-child {
    border-bottom: none;
}

.hgw-v2-search-section-label {
    display: block;
    padding: 6px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    color: #646970;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.hgw-v2-search-item a,
.hgw-v2-search-item {
    display: block;
    padding: 8px 20px;
    text-decoration: none;
    color: #1d2327;
    transition: background 0.15s;
    cursor: pointer;
}

.hgw-v2-search-item:hover a,
.hgw-v2-search-item:hover {
    background: #f7f3ea;
}

.hgw-v2-item-type {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    margin-right: 8px;
    vertical-align: middle;
}

.hgw-v2-item-name {
    font-weight: 500;
    font-size: 14px;
}

.hgw-v2-item-sub {
    display: block;
    font-size: 12px;
    color: #646970;
    margin-top: 2px;
    padding-left: 0;
}

.hgw-v2-search-footer {
    padding: 8px 20px;
    text-align: center;
    border-top: 1px solid #f0f0f1;
    background: #fafafa;
}

.hgw-v2-search-footer a {
    font-size: 13px;
    color: var(--color-green, #4E7C59);
    text-decoration: none;
    font-weight: 500;
}

.hgw-v2-search-footer a:hover {
    text-decoration: underline;
}

/* ================================================================
   V2 Entity Cards Grid
   ================================================================ */

.hgw-v2-entity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.hgw-v2-entity-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    transition: box-shadow 0.2s, transform 0.2s;
    display: flex;
    flex-direction: column;
}

.hgw-v2-entity-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.hgw-v2-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.hgw-v2-card-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1d2327;
    line-height: 1.3;
}

.hgw-v2-card-desc {
    font-size: 13px;
    color: #646970;
    line-height: 1.5;
    margin: 0 0 10px;
    flex-grow: 1;
}

.hgw-v2-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.hgw-v2-card-meta-item {
    font-size: 12px;
    color: #50575e;
}

.hgw-v2-meta-label {
    color: #8c8f94;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
}

.hgw-v2-card-link {
    display: inline-block;
    font-size: 13px;
    color: var(--color-green, #4E7C59);
    text-decoration: none;
    font-weight: 500;
    margin-top: auto;
}

.hgw-v2-card-link:hover {
    text-decoration: underline;
}

/* ================================================================
   V2 Stats Widget
   ================================================================ */

.hgw-v2-stats-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin: 20px 0;
}

.hgw-v2-stat {
    background: var(--color-paper, #F7F3EA);
    border-radius: 8px;
    padding: 20px 30px;
    text-align: center;
    flex: 1;
    min-width: 120px;
}

.hgw-v2-stat-number {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--color-green, #4E7C59);
    line-height: 1.2;
}

.hgw-v2-stat-label {
    display: block;
    font-size: 11px;
    color: #646970;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* ================================================================
   V2 Map Popups (Leaflet)
   ================================================================ */

.leaflet-popup-content .hgw-v2-map-popup h4 {
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 600;
    color: #1d2327;
}

.leaflet-popup-content .hgw-v2-map-popup p {
    margin: 4px 0;
    font-size: 12px;
    color: #646970;
}

.hgw-v2-map-desc {
    line-height: 1.4;
    max-width: 200px;
}

.hgw-v2-map-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--color-green, #4E7C59);
    text-decoration: none;
    font-weight: 500;
}

.hgw-v2-map-link:hover {
    text-decoration: underline;
}

/* ================================================================
   V2 Loading & Error States
   ================================================================ */

.hgw-v2-loading,
.hgw-v2-empty,
.hgw-v2-error {
    padding: 30px;
    text-align: center;
    color: #646970;
    font-size: 14px;
}

.hgw-v2-loading .spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f0f0f1;
    border-top-color: var(--color-gold, #D8A63A);
    border-radius: 50%;
    animation: hgw-v2-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

.hgw-v2-error {
    color: #d63638;
}

/* ================================================================
   V2 Pagination
   ================================================================ */

.hgw-v2-pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin: 20px 0;
    flex-wrap: wrap;
}

.hgw-v2-page-btn {
    background: #fff;
    border: 1px solid #ccd0d4;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    color: #1d2327;
}

.hgw-v2-page-btn:hover {
    border-color: var(--color-gold, #D8A63A);
    background: var(--color-paper, #F7F3EA);
}

.hgw-v2-page-btn.active {
    background: var(--color-green, #4E7C59);
    border-color: var(--color-green, #4E7C59);
    color: #fff;
    font-weight: 600;
}

/* ================================================================
   V2 Badge Colors (entity types)
   ================================================================ */

.badge { background: #e0e0e0; color: #1d2327; }
.badge-location { background: #4E7C59; color: #fff; }
.badge-story { background: #D8A63A; color: #fff; }
.badge-dynasty { background: #5b4b8a; color: #fff; }
.badge-person { background: #c0392b; color: #fff; }
.badge-route { background: #2980b9; color: #fff; }
.badge-experience { background: #8b5e3c; color: #fff; }
.badge-event { background: #e67e22; color: #fff; }
.badge-artifact { background: #16a085; color: #fff; }
.badge-quest { background: #d4760a; color: #fff; }

/* ================================================================
   Responsive
   ================================================================ */

@media (max-width: 768px) {
    .hgw-v2-entity-grid {
        grid-template-columns: 1fr;
    }

    .hgw-v2-stats-row {
        flex-direction: column;
        gap: 12px;
    }

    .hgw-v2-stat {
        padding: 16px 20px;
    }

    .hgw-v2-stat-number {
        font-size: 24px;
    }

    .hgw-v2-search-dropdown {
        max-height: 300px;
    }
}

/* ================================================================
   V2 Search Overlay (Header Bar)
   ================================================================ */

.hgw-search-overlay {
    position: relative;
    width: 100%;
    background: var(--color-paper, #F7F3EA);
    border-bottom: 1px solid #e0e0e0;
    z-index: 999;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.hgw-search-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.hgw-search-input {
    flex: 1;
    width: 100%;
    padding: 10px 16px;
    font-size: 16px;
    border: 1px solid #ccd0d4;
    border-radius: 4px;
    background: #fff;
    color: #1d2327;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}

.hgw-search-input:focus {
    border-color: var(--color-gold, #D8A63A);
    box-shadow: 0 0 0 1px var(--color-gold, #D8A63A);
}

.hgw-search-close {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    color: #646970;
    line-height: 1;
}

.hgw-search-close:hover {
    color: #1d2327;
}

/* Position the V2 search dropdown within the overlay */
.hgw-search-overlay .hgw-v2-search-dropdown {
    position: absolute;
    top: 100%;
    left: 20px;
    right: 20px;
    max-width: 760px;
    margin: 0 auto;
}
