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

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

/* ── Top Bar ── */

.top-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1.5rem;
    background: #2d3748;
    font-size: 0.8rem;
}

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

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

.top-bar-logout:hover {
    color: #fff;
    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;
    color: #2d3748;
}

/* ── 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: 1rem 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    margin-bottom: 1.5rem;
    border: 1px solid #e2e8f0;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: auto;
}

.filter-group label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.filter-group select,
.filter-group input[type="date"],
.filter-group input[type="text"] {
    padding: 0.45rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    background: #fff;
    color: #2d3748;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.filter-group select {
    padding-right: 1.75rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='%23718096'%3E%3Cpath d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 10px 6px;
}

.filter-group select:focus,
.filter-group input[type="date"]:focus,
.filter-group input[type="text"]:focus {
    outline: none;
    border-color: #F26522;
    box-shadow: 0 0 0 2px rgba(242, 101, 34, 0.15);
}

.filter-group select:hover,
.filter-group input[type="date"]:hover,
.filter-group input[type="text"]:hover {
    border-color: #cbd5e0;
}

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

button[type="submit"] {
    padding: 0.45rem 1.25rem;
    background: #F26522;
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

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

/* ── Date Presets ── */

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

.date-presets-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

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

.date-preset:hover {
    background: #fff7ed;
    border-color: #F26522;
    color: #F26522;
}

.date-preset.active {
    background: #F26522;
    border-color: #F26522;
    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: #718096;
}

/* ── View Toggle ── */

.view-toggle {
    display: flex;
    gap: 2px;
    background: #edf2f7;
    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: #718096;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.view-btn:hover {
    color: #2d3748;
}

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

.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 #e2e8f0;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    background: #fff;
    color: #718096;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.email-btn:hover {
    background: #fff7ed;
    color: #F26522;
    border-color: #F26522;
}

.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 #e2e8f0;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    background: #fff;
    color: #718096;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.action-btn:hover {
    background: #fff7ed;
    color: #F26522;
    border-color: #F26522;
}

.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: #F26522;
    border-color: #F26522;
}

.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.06);
    overflow: hidden;
    margin-bottom: 1.5rem;
    border: 1px solid #e2e8f0;
}

#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: #F26522;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
}

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

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

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

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

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

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

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

/* ── Gallery Grid ── */

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

.gallery-item {
    border-radius: 8px;
    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.06);
    border: 2px solid transparent;
}

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

.gallery-item.selected {
    border-color: #F26522;
    box-shadow: 0 0 0 1px #F26522, 0 2px 8px rgba(242, 101, 34, 0.2);
}

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

.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: #718096;
    font-size: 0.7rem;
    font-weight: 500;
}

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

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

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

.meta-additional {
    color: #9b59b6;
    font-size: 0.65rem;
    font-weight: 500;
}

/* ── Additional Fields Checkboxes ── */

.additional-fields-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid #edf2f7;
    flex-wrap: wrap;
}

.additional-fields-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.additional-fields-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.additional-field-checkbox {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: #4a5568;
    cursor: pointer;
    padding: 0.25rem 0.65rem;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    transition: border-color 0.15s, background 0.15s;
}

.additional-field-checkbox:hover {
    border-color: #F26522;
    background: #fff7ed;
}

.additional-field-checkbox input[type="checkbox"] {
    accent-color: #F26522;
}

/* ── 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: #f6ad55;
    font-size: 0.85rem;
    text-decoration: none;
}

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

.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 #e2e8f0;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #F26522;
    text-decoration: none;
    background: #fff;
    transition: background 0.15s;
}

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

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

.page-ellipsis {
    padding: 0.4rem 0.3rem;
    color: #a0aec0;
    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.08);
    width: 100%;
    max-width: 380px;
    text-align: center;
    border: 1px solid #e2e8f0;
}

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

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

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

.login-spinner {
    color: #a0aec0;
    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: #fff5f5;
    color: #c53030;
    border: 1px solid #feb2b2;
}

/* ── 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;
    }
}
