/* ==========================================================================
   Variables Grid
   ========================================================================== */

.gr-variables-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.gr-variable-card {
    background: var(--gr-light);
    border: 1px solid var(--gr-light-border);
    border-radius: var(--gr-radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    transition: border-color var(--gr-dur) var(--gr-ease);
}

.gr-variable-card:hover {
    border-color: var(--gr-accent-border);
}

.gr-variable-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
}

.gr-variable-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gr-text-1);
}

.gr-variable-slug {
    font-size: 0.72rem;
    color: var(--gr-text-3);
    flex-shrink: 0;
}

.gr-variable-desc {
    font-size: 0.82rem;
    color: var(--gr-text-2);
    line-height: 1.55;
}

.gr-variable-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.25rem;
}

/* ==========================================================================
   Items Table
   ========================================================================== */

.gr-items-table {
    border: 1px solid var(--gr-light-border);
    border-radius: var(--gr-radius-lg);
    overflow: hidden;
}

.gr-items-table-header {
    display: grid;
    grid-template-columns: 1fr 1fr 80px 1fr;
    padding: 0.6rem 1.25rem;
    background: var(--gr-light-1);
    border-bottom: 1px solid var(--gr-light-border);
    font-family: var(--gr-font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--gr-text-3);
}

.gr-items-table-row {
    display: grid;
    grid-template-columns: 1fr 1fr 80px 1fr;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--gr-light-border);
    align-items: center;
    transition: background var(--gr-dur) var(--gr-ease);
}

.gr-items-table-row:last-child {
    border-bottom: none;
}

.gr-items-table-row:hover {
    background: var(--gr-light-1);
}

/* API links row */
.gr-collection-api-links {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gr-dark-border);
}

/* ==========================================================================
   Map Section
   ========================================================================== */

.gr-map-section {
    padding: 2rem 0 2.5rem;
    background: var(--gr-light-1);
}

/* ==========================================================================
   Map Shell
   ========================================================================== */

.gr-map-shell {
    max-width: 1180px;
    margin: 0 auto;
    height: 620px;
}

/* ==========================================================================
   Map Canvas
   ========================================================================== */

.gr-map-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: var(--gr-radius-lg);
    border: 1px solid var(--gr-light-border);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.10);
    background: #0b1220;
}

#grMap {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Floating Map Variables Sidebar
   ========================================================================== */

.gr-map-sidebar {
    position: absolute;
    top: 1rem;
    left: 1rem;
    width: 220px;
    max-height: calc(100% - 2rem);
    background: rgba(8, 13, 24, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    z-index: 30;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.gr-map-sidebar-header {
    padding: 0.9rem 1rem 0.65rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.gr-map-sidebar-label {
    font-family: var(--gr-font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--gr-dark-text-3);
}

.gr-map-sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.gr-map-var-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.7rem 0.8rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 12px;
    font-family: var(--gr-font-sans);
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.82);
    cursor: pointer;
    text-align: left;
    transition: all var(--gr-dur) var(--gr-ease);
}

.gr-map-var-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.gr-map-var-btn--active {
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.gr-map-var-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    flex-shrink: 0;
    transition: background var(--gr-dur) var(--gr-ease);
}

.gr-map-var-btn--active .gr-map-var-dot {
    background: var(--gr-accent);
}

.gr-map-var-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gr-map-var-unit {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.gr-map-sidebar-empty {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.55);
    padding: 0.75rem;
}

/* ==========================================================================
   Basemap Selector
   ========================================================================== */

.gr-map-basemap-selector {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 20;
}

.gr-map-basemap-btn {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.4rem 0.7rem;
    background: rgba(8, 13, 24, 0.85);
    border: 1px solid var(--gr-dark-border-2);
    border-radius: var(--gr-radius);
    font-family: var(--gr-font-sans);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gr-dark-text-1);
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all var(--gr-dur) var(--gr-ease);
}

.gr-map-basemap-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--gr-dark-border-2);
}

.gr-map-basemap-menu {
    position: absolute;
    top: calc(100% + 0.3rem);
    right: 0;
    left: auto;
    background: rgba(13, 20, 37, 0.95);
    border: 1px solid var(--gr-dark-border-2);
    border-radius: var(--gr-radius);
    min-width: 140px;
    overflow: hidden;
    display: none;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.gr-map-basemap-menu.gr-open {
    display: block;
}

.gr-map-basemap-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    font-size: 0.78rem;
    color: var(--gr-dark-text-2);
    cursor: pointer;
    transition: background var(--gr-dur) var(--gr-ease);
}

.gr-map-basemap-option:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--gr-dark-text-1);
}

.gr-map-basemap-option.gr-bm-active {
    color: var(--gr-accent);
}

.gr-bm-check {
    opacity: 0;
    font-size: 0.75rem;
    color: var(--gr-accent);
}

.gr-map-basemap-option.gr-bm-active .gr-bm-check {
    opacity: 1;
}

/* ==========================================================================
   Legend Panel
   ========================================================================== */

.gr-map-legend {
    position: absolute;
    bottom: 5.5rem;
    left: 1rem;
    background: rgba(8, 13, 24, 0.88);
    border: 1px solid var(--gr-dark-border-2);
    border-radius: var(--gr-radius-lg);
    padding: 0.875rem 1rem;
    min-width: 180px;
    max-width: 220px;
    z-index: 20;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.gr-map-legend-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gr-dark-text-1);
    margin-bottom: 0.6rem;
}

.gr-map-legend-scale {
    height: 8px;
    border-radius: 3px;
    margin-bottom: 0.3rem;
}

.gr-map-legend-labels {
    display: flex;
    justify-content: space-between;
    font-family: var(--gr-font-mono);
    font-size: 0.62rem;
    color: var(--gr-dark-text-2);
}

.gr-map-legend-units {
    text-align: center;
    font-family: var(--gr-font-mono);
    font-size: 0.58rem;
    color: var(--gr-dark-text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 0.2rem;
}

.gr-map-legend-opacity {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.62rem;
    color: var(--gr-dark-text-3);
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--gr-dark-border);
}

.gr-map-opacity-slider {
    width: 100%;
    height: 3px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--gr-dark-3);
    border-radius: 2px;
    outline: none;
    margin-top: 0.35rem;
    cursor: pointer;
}

.gr-map-opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--gr-accent);
    border-radius: 50%;
    cursor: pointer;
}

.gr-map-opacity-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--gr-accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* ==========================================================================
   Loading Spinner
   ========================================================================== */

.gr-map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    color: var(--gr-dark-text-2);
    font-size: 0.78rem;
    pointer-events: none;
    z-index: 30;
}

.gr-map-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--gr-dark-3);
    border-top-color: var(--gr-accent);
    border-radius: 50%;
    animation: gr-spin 0.7s linear infinite;
}

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

/* ==========================================================================
   Time Bar
   ========================================================================== */

.gr-timebar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4.5rem;
    background: rgba(8, 13, 24, 0.92);
    border-top: 1px solid var(--gr-dark-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.25rem;
    z-index: 20;
}

.gr-timebar-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    background: var(--gr-accent-dim);
    border: 1px solid var(--gr-accent-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gr-accent);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--gr-dur) var(--gr-ease);
}

.gr-timebar-btn:hover {
    background: var(--gr-accent);
    color: var(--gr-dark);
}

.gr-timebar-track-wrap {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.gr-timebar-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--gr-dark-3);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    position: relative;
    z-index: 2;
}

.gr-timebar-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--gr-accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 3px var(--gr-accent-dim);
    transition: box-shadow var(--gr-dur) var(--gr-ease);
}

.gr-timebar-slider::-webkit-slider-thumb:hover {
    box-shadow: 0 0 0 5px var(--gr-accent-dim);
}

.gr-timebar-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--gr-accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.gr-timebar-ticks {
    position: relative;
    height: 14px;
}

.gr-timebar-tick {
    position: absolute;
    transform: translateX(-50%);
    font-family: var(--gr-font-mono);
    font-size: 0.58rem;
    color: var(--gr-dark-text-3);
    white-space: nowrap;
    pointer-events: none;
}

.gr-timebar-display {
    flex-shrink: 0;
    text-align: right;
    min-width: 180px;
}

.gr-timebar-date {
    display: block;
    font-family: var(--gr-font-mono);
    font-size: 0.78rem;
    color: var(--gr-dark-text-1);
    font-weight: 500;
}

.gr-timebar-count {
    display: block;
    font-family: var(--gr-font-mono);
    font-size: 0.62rem;
    color: var(--gr-dark-text-3);
    margin-top: 0.1rem;
}

/* ==========================================================================
   Coordinate Display
   ========================================================================== */

.gr-map-coords {
    position: absolute;
    bottom: 5rem;
    right: 0.75rem;
    font-family: var(--gr-font-mono);
    font-size: 0.62rem;
    color: var(--gr-dark-text-3);
    background: rgba(8, 13, 24, 0.75);
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    border: 1px solid var(--gr-dark-border);
    pointer-events: none;
    z-index: 20;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

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

@media (max-width: 768px) {
    .gr-variables-grid {
        grid-template-columns: 1fr;
    }

    .gr-items-table-header,
    .gr-items-table-row {
        grid-template-columns: 1fr 1fr;
    }

    .gr-items-table-header span:nth-child(3),
    .gr-items-table-header span:nth-child(4),
    .gr-items-table-row span:nth-child(3),
    .gr-items-table-row span:nth-child(4) {
        display: none;
    }

    .gr-map-section {
        padding: 1rem 0 1.5rem;
    }

    .gr-map-shell {
        height: 520px;
        padding: 0 1rem;
    }

    .gr-map-sidebar {
        top: 0.75rem;
        left: 0.75rem;
        width: 180px;
        max-height: calc(100% - 1.5rem);
    }

    .gr-map-var-unit {
        display: none;
    }

    .gr-timebar-display {
        min-width: 120px;
    }

    .gr-timebar-date {
        font-size: 0.68rem;
    }

    .gr-map-legend {
        bottom: 5rem;
        min-width: 150px;
    }
}

@media (max-width: 480px) {
    .gr-map-shell {
        height: 480px;
        padding: 0 0.75rem;
    }

    .gr-map-sidebar {
        top: 0.75rem;
        left: 0.75rem;
        right: 0.75rem;
        width: auto;
        max-height: none;
        border-radius: 16px;
    }

    .gr-map-sidebar-header {
        display: none;
    }

    .gr-map-sidebar-body {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0.5rem;
        gap: 0.35rem;
    }

    .gr-map-var-btn {
        white-space: nowrap;
        flex-shrink: 0;
    }

    .gr-map-basemap-selector {
        top: auto;
        bottom: 5.2rem;
        right: 0.75rem;
    }

    .gr-map-legend {
        left: 0.75rem;
        bottom: 5.2rem;
        max-width: 160px;
        min-width: 140px;
        padding: 0.7rem 0.8rem;
    }

    .gr-map-coords {
        display: none;
    }

    .gr-timebar {
        height: 4.25rem;
        padding: 0 0.85rem;
        gap: 0.6rem;
    }

    .gr-timebar-display {
        min-width: 92px;
    }

    .gr-timebar-count {
        display: none;
    }
}

/* ==========================================================================
   Items Browser
   ========================================================================== */

.gr-items-browser {
    align-items: start;
}

.gr-items-sidebar {
    top: 80px;
}

/* Variable checkbox row */
.gr-items-var-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.6rem;
    border-radius: var(--gr-radius);
    cursor: pointer;
    transition: background var(--gr-dur) var(--gr-ease);
    font-size: 0.82rem;
    color: var(--gr-text-2);
}

.gr-items-var-checkbox:hover {
    background: var(--gr-light-1);
}

.gr-items-var-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--gr-accent);
    cursor: pointer;
    flex-shrink: 0;
}

.gr-items-var-label {
    flex: 1;
    color: var(--gr-text-1);
}

.gr-items-var-unit {
    font-size: 0.68rem;
    color: var(--gr-text-3);
}

/* Date input */
.gr-items-date-input {
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: var(--gr-light);
    border: 1px solid var(--gr-light-border);
    border-radius: var(--gr-radius);
    font-family: var(--gr-font-sans);
    font-size: 0.82rem;
    color: var(--gr-text-1);
    outline: none;
    transition: border-color var(--gr-dur) var(--gr-ease);
}

.gr-items-date-input:focus {
    border-color: var(--gr-accent-border);
    box-shadow: 0 0 0 3px var(--gr-accent-dim);
}

.gr-items-date-clear {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.4rem;
    padding: 0.3rem 0.6rem;
    background: transparent;
    border: 1px solid var(--gr-light-border);
    border-radius: var(--gr-radius);
    font-size: 0.75rem;
    color: var(--gr-text-3);
    cursor: pointer;
    transition: all var(--gr-dur) var(--gr-ease);
    width: 100%;
    justify-content: center;
}

.gr-items-date-clear:hover {
    border-color: var(--gr-accent-border);
    color: var(--gr-accent);
}

/* Reference time select */
.gr-items-ref-select {
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: var(--gr-light);
    border: 1px solid var(--gr-light-border);
    border-radius: var(--gr-radius);
    font-family: var(--gr-font-sans);
    font-size: 0.82rem;
    color: var(--gr-text-1);
    outline: none;
    cursor: pointer;
    transition: border-color var(--gr-dur) var(--gr-ease);
}

.gr-items-ref-select:focus {
    border-color: var(--gr-accent-border);
    box-shadow: 0 0 0 3px var(--gr-accent-dim);
}

/* Items grid */
.gr-items-main {
    min-width: 0;
}

.gr-item-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

/* Item card */
.gr-item-card {
    background: var(--gr-light);
    border: 1px solid var(--gr-light-border);
    border-radius: var(--gr-radius-lg);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    transition: border-color var(--gr-dur) var(--gr-ease),
    transform var(--gr-dur) var(--gr-ease),
    box-shadow var(--gr-dur) var(--gr-ease);
}

.gr-item-card:hover {
    border-color: var(--gr-accent-border);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* Thumbnail */
.gr-item-card-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--gr-light-1);
    overflow: hidden;
}

.gr-item-card-thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Placeholder icon shown when image errors */
.gr-item-card-thumb-placeholder {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--gr-text-3);
}

.gr-item-card-thumb--error .gr-item-card-thumb-placeholder {
    display: flex;
}

/* Card body */
.gr-item-card-body {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1;
}

.gr-item-card-date {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--gr-text-1);
    line-height: 1.3;
}

.gr-item-card-variable {
    font-size: 0.78rem;
    color: var(--gr-accent);
    font-weight: 500;
}

.gr-item-card-meta {
    font-size: 0.72rem;
    color: var(--gr-text-3);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.1rem;
}

/* Loading state for items */
.gr-items-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem;
    color: var(--gr-text-3);
    font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 900px) {
    .gr-item-cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

@media (max-width: 600px) {
    .gr-item-cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}