/**
 * Community Sightings Page Styles
 * Version: 2.0.0 - Redesigned with Recent Sightings Feed
 */

/* ============================================
   CSS Variables
   ============================================ */
:root {
    --forest-900: #0d2818;
    --forest-800: #1a3a2a;
    --forest-700: #234d38;
    --forest-600: #2d5a3d;
    --forest-500: #3d7a52;
    --forest-400: #5a9970;
    --forest-100: #e8f5ed;
    --forest-50: #f4faf6;
    --bark-700: #5c4033;
    --bark-600: #7a5a45;
    --bark-500: #a07858;
    --sand-200: #f5f0e8;
    --sand-100: #faf8f4;
    --coral-500: #e76f51;
    --coral-600: #d45a3b;
    --gold-500: #daa520;
    --gold-400: #f4c430;
    --sky-500: #4a90a4;
    --sky-600: #3a7a8e;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #666;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,0.1), 0 12px 32px rgba(0,0,0,0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

/* ============================================
   Base Styles
   ============================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--sand-100);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.5;
}

/* ============================================
   Header
   ============================================ */
.header {
    background: var(--forest-800);
    padding: 16px 20px;
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.back-btn:hover {
    background: rgba(255,255,255,0.2);
}

.back-btn svg {
    width: 20px;
    height: 20px;
}

.header h1 {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    flex: 1;
}

/* ============================================
   Main Container
   ============================================ */
.main {
    padding-top: 72px; /* Header height */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   Hero Search Section
   ============================================ */
.community-hero {
    background: linear-gradient(135deg, var(--forest-700) 0%, var(--forest-800) 100%);
    padding: 20px;
}

.search-section {
    position: relative;
    z-index: 500;
    max-width: 600px;
    margin: 0 auto;
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 14px 44px 14px 48px;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-family: inherit;
    background: white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    box-shadow: 0 4px 24px rgba(0,0,0,0.2), 0 0 0 3px rgba(255,255,255,0.3);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-clear {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.search-clear:hover {
    color: var(--text-primary);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow-hover);
    max-height: 320px;
    overflow-y: auto;
    z-index: 600;
    margin-top: 8px;
}

.search-result {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--sand-200);
    transition: background 0.15s;
}

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

.search-result:hover {
    background: var(--forest-50);
}

.search-result-name {
    font-weight: 500;
    color: var(--text-primary);
}

.search-result-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.search-result-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
}

/* ============================================
   Recent Sightings Feed
   ============================================ */
.recent-sightings-section {
    background: white;
    border-bottom: 1px solid var(--sand-200);
}

.recent-sightings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px 8px;
}

.recent-sightings-title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--forest-800);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.recent-sightings-icon {
    font-size: 1.1rem;
}

.recent-sightings-refresh {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--sand-100);
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.recent-sightings-refresh:hover {
    background: var(--forest-50);
    color: var(--forest-600);
}

.recent-sightings-refresh:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.recent-sightings-refresh.is-loading svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.recent-sightings-scroll {
    overflow-x: auto;
    padding: 8px 20px 16px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.recent-sightings-scroll::-webkit-scrollbar {
    display: none;
}

.recent-sightings-list {
    display: flex;
    gap: 12px;
    min-width: min-content;
    transition: opacity 0.2s ease;
}

.recent-sightings-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.recent-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--sand-200);
    border-top-color: var(--forest-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Recent Sighting Cards - same styles as index.html */
.journal-sighting-card {
    flex-shrink: 0;
    width: 140px;
    background: var(--sand-100);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.journal-sighting-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--card-shadow);
}

.journal-sighting-card.has-user-photo::after {
    content: '📷';
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 0.7rem;
    background: rgba(255,255,255,0.9);
    border-radius: 4px;
    padding: 2px 4px;
    line-height: 1;
}

.journal-sighting-img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    background: var(--sand-200);
}

.journal-sighting-info {
    padding: 10px;
}

.journal-sighting-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--forest-800);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.journal-sighting-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 4px 0 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    width: 100%;
}

@media (max-width: 480px) {
    .journal-sighting-card {
        width: 120px;
    }
    .journal-sighting-name {
        font-size: 0.8rem;
    }
    .journal-sighting-info {
        padding: 8px;
    }
}

/* ============================================
   Tab Navigation
   ============================================ */
.community-tabs {
    display: flex;
    background: white;
    border-bottom: 1px solid var(--sand-200);
    padding: 0 20px;
    position: sticky;
    top: 72px;
    z-index: 100;
}

.community-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    max-width: 200px;
    position: relative;
}

.community-tab:hover {
    color: var(--forest-600);
    background: var(--forest-50);
}

.community-tab.active {
    color: var(--forest-700);
    border-bottom-color: var(--forest-600);
}

.community-tab-icon {
    font-size: 1.1rem;
}

.community-tab-label {
    font-weight: 600;
}

.community-tab-badge {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 4px;
    position: absolute;
    top: 6px;
    right: 6px;
}

.community-tab-badge.pro-badge {
    background: var(--gold-500);
    color: var(--forest-900);
}

/* ============================================
   Tab Content
   ============================================ */
.community-tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 400px;
}

/* ============================================
   View Containers
   ============================================ */
.community-view {
    display: none;
    flex: 1;
    flex-direction: column;
}

.community-view.active {
    display: flex;
}

/* ============================================
   Selected Species
   ============================================ */
.selected-species {
    padding: 12px 20px;
    background: var(--forest-50);
    border-bottom: 1px solid var(--forest-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.selected-species-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.selected-species-name {
    font-weight: 600;
    color: var(--forest-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selected-species-scientific {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selected-species-change {
    padding: 8px 14px;
    background: white;
    border: 1px solid var(--forest-300, #a5d6a7);
    border-radius: var(--radius-sm);
    color: var(--forest-700);
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}

.selected-species-change:hover {
    background: var(--forest-100);
}

/* ============================================
   Map Container
   ============================================ */
.map-container {
    flex: 1;
    position: relative;
    background: var(--sand-200);
    min-height: 350px;
}

#communityMap {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

/* Map States */
.map-loading,
.map-empty,
.map-no-results,
.map-error {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--sand-100);
    gap: 12px;
    padding: 40px;
    text-align: center;
}

.map-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--sand-200);
    border-top-color: var(--forest-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.map-empty-icon {
    font-size: 3rem;
    margin-bottom: 8px;
}

.map-empty h3,
.map-no-results h3,
.map-error h3 {
    font-size: 1.2rem;
    color: var(--text-primary);
    font-weight: 600;
}

.map-empty p,
.map-no-results p,
.map-error p {
    color: var(--text-muted);
    font-size: 0.95rem;
    max-width: 280px;
}

.retry-btn {
    margin-top: 12px;
    padding: 10px 24px;
    background: var(--forest-500);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
}

.retry-btn:hover {
    background: var(--forest-600);
}

/* ============================================
   Legend
   ============================================ */
.legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow);
    padding: 12px 16px;
    z-index: 400;
    min-width: 150px;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.legend-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 2px 6px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ============================================
   Sighting Count Badge
   ============================================ */
.sighting-count {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--forest-800);
    color: white;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 400;
    box-shadow: var(--card-shadow);
}

/* ============================================
   Community Marker Popup Styles
   ============================================ */
.kagn-community-marker {
    background: none;
    border: none;
}

.kagn-community-popup-container .leaflet-popup-content-wrapper {
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow);
}

.kagn-community-popup-container .leaflet-popup-content {
    margin: 0;
    padding: 0;
}

.kagn-community-popup {
    padding: 12px 14px;
    min-width: 160px;
}

.kagn-community-popup-species {
    font-weight: 600;
    font-size: 1rem;
    color: var(--forest-800);
    margin-bottom: 4px;
}

.kagn-community-popup-date {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.kagn-community-popup-observer {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.kagn-community-popup-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.kagn-community-popup-location {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
    font-style: italic;
}

/* ============================================
   Responsive Styles
   ============================================ */
@media (min-width: 768px) {
    .community-hero {
        padding: 24px;
    }

    .search-results {
        max-width: 600px;
        left: 50%;
        transform: translateX(-50%);
    }

    .recent-sightings-scroll {
        padding: 8px 24px 16px;
    }

    .recent-sighting-card {
        width: 160px;
    }

    .legend {
        bottom: 30px;
        left: 30px;
    }

    .sighting-count {
        bottom: 30px;
        right: 30px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.1rem;
    }

    .community-hero {
        padding: 16px;
    }

    .search-input {
        padding: 12px 40px 12px 44px;
        font-size: 0.95rem;
    }

    .recent-sighting-card {
        width: 120px;
    }

    .recent-sighting-species {
        font-size: 0.8rem;
    }

    .recent-sighting-info {
        padding: 8px;
    }

    .community-tabs {
        top: 72px;
    }

    .community-tab {
        padding: 12px 8px;
        font-size: 0.85rem;
    }

    .community-tab-label {
        display: none;
    }

    .community-tab-icon {
        font-size: 1.3rem;
    }

    .community-tab-badge {
        position: static;
        margin-left: 4px;
    }

    .legend {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }

    .sighting-count {
        right: 10px;
        bottom: auto;
        top: 10px;
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .selected-species {
        flex-wrap: wrap;
    }

    .selected-species-change {
        width: 100%;
        text-align: center;
    }
}

/* ============================================
   Hide Leaflet Attribution on Mobile
   ============================================ */
@media (max-width: 480px) {
    .leaflet-control-attribution {
        display: none;
    }
}

/* ============================================
   Marker Cluster Styles (Theme Override)
   ============================================ */
.marker-cluster-small {
    background-color: rgba(45, 90, 61, 0.5);
}
.marker-cluster-small div {
    background-color: rgba(45, 90, 61, 0.8);
}

.marker-cluster-medium {
    background-color: rgba(218, 165, 32, 0.5);
}
.marker-cluster-medium div {
    background-color: rgba(218, 165, 32, 0.8);
}

.marker-cluster-large {
    background-color: rgba(255, 140, 0, 0.5);
}
.marker-cluster-large div {
    background-color: rgba(255, 140, 0, 0.8);
}

.marker-cluster {
    background-clip: padding-box;
    border-radius: 50%;
}

.marker-cluster div {
    width: 30px;
    height: 30px;
    margin-left: 5px;
    margin-top: 5px;
    text-align: center;
    border-radius: 50%;
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 600;
    color: white;
    line-height: 30px;
}

.marker-cluster span {
    line-height: 30px;
}
