* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
}

/* ── Top Bar ── */

.top-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #e5e5e5;
    font-size: 0.8rem;
}

.top-bar-user {
    color: #666;
}

.top-bar-logout {
    color: #4a90d9;
    text-decoration: none;
    font-weight: 500;
}

.top-bar-logout:hover {
    text-decoration: underline;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

h1 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 600;
}

/* ── Page Header with Logo ── */

.page-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin-bottom: 0;
}

.page-logo {
    height: 32px;
    width: auto;
}

.login-logo {
    height: 36px;
    width: auto;
    margin-bottom: 0.75rem;
}

/* ── Filters ── */

.filters {
    background: #fff;
    padding: 1.25rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-bottom: 1.5rem;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 160px;
}

.filter-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.filter-group select,
.filter-group input[type="date"],
.filter-group input[type="text"] {
    padding: 0.5rem 0.65rem;
    border: 1px solid #d0d0d0;
    border-radius: 5px;
    font-size: 0.9rem;
    background: #fff;
    color: #333;
}

.filter-group select:focus,
.filter-group input[type="date"]:focus,
.filter-group input[type="text"]:focus {
    outline: none;
    border-color: #4a90d9;
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.filter-action {
    min-width: auto;
}

button[type="submit"] {
    padding: 0.5rem 1.5rem;
    background: #4a90d9;
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

button[type="submit"]:hover {
    background: #357abd;
}

/* ── Date Presets ── */

.date-presets {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f0f0f0;
}

.date-presets-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.date-preset {
    padding: 0.25rem 0.65rem;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    background: #fff;
    color: #666;
    cursor: pointer;
    transition: all 0.15s;
}

.date-preset:hover {
    background: #f0f7ff;
    border-color: #4a90d9;
    color: #4a90d9;
}

.date-preset.active {
    background: #4a90d9;
    border-color: #4a90d9;
    color: #fff;
}

/* ── Results Header ── */

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.results-info {
    font-size: 0.9rem;
    color: #666;
}

/* ── View Toggle ── */

.view-toggle {
    display: flex;
    gap: 2px;
    background: #e5e5e5;
    border-radius: 6px;
    padding: 2px;
}

.view-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border: none;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 500;
    background: transparent;
    color: #666;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.view-btn:hover {
    color: #333;
}

.view-btn.active {
    background: #fff;
    color: #333;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.view-btn svg {
    flex-shrink: 0;
}

/* ── Results Actions (toggle + email) ── */

.results-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.email-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border: 1px solid #d0d0d0;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 500;
    background: #fff;
    color: #666;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.email-btn:hover {
    background: #f0f7ff;
    color: #4a90d9;
    border-color: #4a90d9;
}

.email-btn:disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.email-btn svg {
    flex-shrink: 0;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border: 1px solid #d0d0d0;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 500;
    background: #fff;
    color: #666;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.action-btn:hover {
    background: #f0f7ff;
    color: #4a90d9;
    border-color: #4a90d9;
}

.action-btn svg {
    flex-shrink: 0;
}

.download-btn:not(:disabled):hover {
    background: #f0fdf4;
    color: #16a34a;
    border-color: #16a34a;
}

.download-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ── Selection Checkbox ── */

.select-checkbox {
    position: absolute;
    top: 0.4rem;
    left: 0.4rem;
    z-index: 2;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.select-checkbox input[type="checkbox"] {
    display: none;
}

.checkbox-mark {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}

.checkbox-mark::after {
    content: "";
    display: none;
    width: 6px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg);
    margin-top: -2px;
}

.select-checkbox:hover .checkbox-mark {
    border-color: #fff;
    background: rgba(0, 0, 0, 0.4);
}

.select-checkbox input:checked + .checkbox-mark {
    background: #4a90d9;
    border-color: #4a90d9;
}

.select-checkbox input:checked + .checkbox-mark::after {
    display: block;
}

/* ── Map ── */

.map-container {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

#map {
    height: 550px;
    width: 100%;
}

/* Map Popups */
.map-popup {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.map-popup-img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.4rem;
}

.map-popup-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.map-popup-link {
    color: #4a90d9;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
}

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

.map-popup-count {
    color: #999;
    font-size: 0.7rem;
}

.map-popup-solver {
    color: #555;
    font-size: 0.7rem;
    font-weight: 500;
}

.map-popup-type {
    color: #333;
    font-size: 0.75rem;
    font-weight: 600;
}

.map-popup-category {
    color: #4a90d9;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.error {
    background: #fef2f2;
    color: #b91c1c;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid #fecaca;
}

.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: #999;
    font-size: 1rem;
}

/* ── Gallery Grid ── */

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.gallery-item {
    border-radius: 6px;
    cursor: pointer;
    background: #fff;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 2px solid transparent;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.gallery-item.selected {
    border-color: #4a90d9;
    box-shadow: 0 0 0 1px #4a90d9, 0 2px 8px rgba(74, 144, 217, 0.25);
}

.gallery-thumb {
    aspect-ratio: 1;
    overflow: hidden;
    position: relative;
    background: #e0e0e0;
}

.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.image-count {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 3px;
    pointer-events: none;
}

.report-link {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.3rem 0.5rem;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.75rem;
    text-decoration: none;
    text-align: right;
    opacity: 0;
    transition: opacity 0.15s;
}

.gallery-item:hover .report-link {
    opacity: 1;
}

.report-link:hover {
    text-decoration: underline;
}

.tile-info {
    padding: 0.5rem 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.meta-solver {
    color: #555;
    font-size: 0.7rem;
    font-weight: 500;
}

.meta-category {
    color: #4a90d9;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.meta-type {
    color: #333;
    font-size: 0.75rem;
    font-weight: 600;
}

.meta-notes {
    color: #666;
    font-size: 0.7rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Lightbox ── */

.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-content img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
}

.lightbox-info {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: 0.75rem;
}

.lightbox-counter {
    color: #aaa;
    font-size: 0.85rem;
}

.lightbox-report-link {
    color: #6cb4ee;
    font-size: 0.85rem;
    text-decoration: none;
}

.lightbox-report-link:hover {
    text-decoration: underline;
}

.lightbox-meta {
    margin-top: 0.5rem;
    max-width: 70vw;
    text-align: center;
}

.lightbox-solver {
    display: block;
    color: #ccc;
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
}

.lightbox-incident-type {
    color: #ddd;
    font-size: 0.85rem;
    font-weight: 500;
}

.lightbox-notes {
    display: block;
    color: #aaa;
    font-size: 0.8rem;
    margin-top: 0.25rem;
    max-height: 3.6em;
    overflow: hidden;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: absolute;
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
    opacity: 1;
}

.lightbox-close {
    top: 1rem;
    right: 1.5rem;
    font-size: 2.5rem;
    line-height: 1;
}

.lightbox-prev,
.lightbox-next {
    top: 50%;
    transform: translateY(-50%);
    font-size: 3rem;
    padding: 0.5rem;
}

.lightbox-prev {
    left: 1rem;
}

.lightbox-next {
    right: 1rem;
}

/* ── Pagination ── */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.page-link {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    border: 1px solid #d0d0d0;
    border-radius: 5px;
    font-size: 0.85rem;
    color: #4a90d9;
    text-decoration: none;
    background: #fff;
    transition: background 0.15s;
}

.page-link:hover {
    background: #eef4fb;
}

.page-link.current {
    background: #4a90d9;
    color: #fff;
    border-color: #4a90d9;
    font-weight: 600;
}

.page-ellipsis {
    padding: 0.4rem 0.3rem;
    color: #999;
    font-size: 0.85rem;
}

/* ── Login ── */

.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.login-card {
    background: #fff;
    padding: 2.5rem 2rem;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-card h1 {
    margin-bottom: 0.25rem;
    font-size: 1.6rem;
}

.login-subtitle {
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.google-btn-wrapper {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
}

.login-spinner {
    color: #888;
    font-size: 0.85rem;
    margin-top: 1rem;
}

.flash {
    padding: 0.65rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    text-align: left;
}

.flash-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* ── Responsive ── */

@media (max-width: 640px) {
    .filter-row {
        flex-direction: column;
    }

    .filter-group {
        min-width: 100%;
    }

    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
    }
}
