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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* Header */
.header {
    background: var(--bg-primary);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    z-index: 100;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
}

/* Alert / bell button */
.alert-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    transition: all 0.15s;
}
.alert-btn:hover { background: var(--bg-tertiary); color: var(--primary); }
.alert-btn.active { background: #eff6ff; border-color: var(--primary); color: var(--primary); }

.header-stats {
    display: flex;
    gap: 1.5rem;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 340px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.sidebar-header {
    display: none;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.close-sidebar {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.search-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.search-section label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.search-section input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.search-section input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-results {
    margin-top: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.search-result-item {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: var(--border-color);
}

.search-result-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.search-result-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.filter-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.filter-group {
    margin-bottom: 1rem;
}

.filter-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.filter-group select,
.filter-group input {
    width: 100%;
    padding: 0.625rem;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.filter-group small {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.btn {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* Results Section */
.results-section {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

.results-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.75rem;
}

.results-section h3 span {
    color: var(--primary);
}

.nearby-list {
    flex: 1;
    overflow-y: auto;
}

.nearby-item {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid transparent;
}

.nearby-item:hover {
    background: var(--border-color);
}

.nearby-item.recent {
    border-left-color: var(--success);
}

.nearby-item.medium {
    border-left-color: var(--warning);
}

.nearby-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.nearby-item-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.nearby-item-distance {
    font-size: 0.7rem;
    color: white;
    background: var(--primary);
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    white-space: nowrap;
}

.nearby-item-details {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.nearby-item-date {
    font-size: 0.7rem;
    color: var(--success);
    font-weight: 500;
    margin-top: 0.25rem;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: center;
    padding: 2rem 1rem;
}

/* Map Container */
.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: #e5e7eb;
}

.map-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.map-btn {
    width: 44px;
    height: 44px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.map-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

.map-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* Info Panel */
.info-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 1.5rem;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1500;
    max-height: 50vh;
    overflow-y: auto;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    border-radius: 1rem 1rem 0 0;
}

.info-panel.active {
    transform: translateY(0);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.info-header {
    margin-bottom: 1rem;
    padding-right: 2rem;
}

.info-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.info-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.info-item {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 0.5rem;
}

.info-item-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.info-item-value {
    font-size: 1rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.info-item-value.highlight {
    color: var(--primary);
}

/* Leaflet Popup */
.leaflet-popup-content-wrapper {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
}

.leaflet-popup-tip {
    background: var(--bg-primary);
}

.leaflet-popup-content {
    margin: 0.75rem 1rem;
}

.popup-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.popup-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.popup-info strong {
    color: var(--text-primary);
}

.popup-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

/* Marker Cluster */
.marker-cluster-small {
    background-color: rgba(16, 185, 129, 0.4);
}
.marker-cluster-small div {
    background-color: rgba(16, 185, 129, 0.9);
}

.marker-cluster-medium {
    background-color: rgba(245, 158, 11, 0.4);
}
.marker-cluster-medium div {
    background-color: rgba(245, 158, 11, 0.9);
}

.marker-cluster-large {
    background-color: rgba(37, 99, 235, 0.4);
}
.marker-cluster-large div {
    background-color: rgba(37, 99, 235, 0.9);
}

.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-size: 12px;
    font-weight: 600;
    color: white;
    line-height: 30px;
}

/* Mobile FAB - hidden, using header button instead */
.mobile-fab {
    display: none;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .header {
        padding: 0.5rem 1rem;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .header-content {
        flex-direction: row-reverse;
    }

    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border-radius: 8px;
        background: var(--bg-tertiary);
    }

    .header-stats {
        display: none;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 9999;
        background: var(--bg-primary);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-header {
        display: flex;
        position: sticky;
        top: 0;
        background: var(--bg-primary);
        z-index: 10;
        border-bottom: 1px solid var(--border-color);
    }

    .close-sidebar {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 2rem;
    }

    .search-section {
        padding: 1rem;
    }

    .search-section input {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .filter-section {
        padding: 1rem;
    }

    .filter-group {
        margin-bottom: 1.25rem;
    }

    .filter-group select,
    .filter-group input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.875rem;
    }

    .filter-actions {
        flex-direction: column;
        gap: 0.75rem;
        padding-bottom: 1rem;
    }

    .btn {
        padding: 1rem;
        font-size: 1rem;
    }

    .results-section {
        padding: 1rem;
        max-height: 300px;
    }

    .results-section h3 {
        position: sticky;
        top: 0;
        background: var(--bg-primary);
        padding: 0.5rem 0;
        margin: -0.5rem 0 0.5rem 0;
    }

    .info-panel {
        left: 0;
        max-height: 60vh;
    }

    .map-controls {
        top: 0.75rem;
        right: 0.75rem;
    }

    .map-btn {
        width: 44px;
        height: 44px;
    }

    .info-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Hide results section on mobile sidebar - show only filters */
    .results-section {
        display: none;
    }
}

@media (max-width: 480px) {
    .info-grid {
        grid-template-columns: 1fr 1fr;
    }

    .info-title {
        font-size: 1.1rem;
    }
}

/* ============================================================
   Subscribe Modal
   ============================================================ */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { transform: translateY(12px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.modal-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.form-group input {
    padding: 0.6rem 0.75rem;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: border-color 0.15s;
}
.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Chip grid for county/species selection */
.chip-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    max-height: 130px;
    overflow-y: auto;
    padding: 0.25rem 0;
}
.chip {
    padding: 0.3rem 0.7rem;
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.12s;
    white-space: nowrap;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.modal-actions { display: flex; flex-direction: column; gap: 0.6rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-danger {
    background: white;
    border: 1.5px solid var(--danger);
    color: var(--danger);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-danger:hover { background: #fef2f2; }

.modal-feedback {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.4;
}
.modal-feedback.success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.modal-feedback.error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.hidden { display: none !important; }

/* Mode tabs */
.sub-tabs {
    display: flex;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}
.sub-tab {
    flex: 1;
    padding: 0.45rem 0;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    cursor: pointer;
    transition: all 0.15s;
}
.sub-tab.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Location row inside modal */
.location-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.location-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: monospace;
}
.location-status.has-location { color: var(--success); font-weight: 600; }

.btn-locate {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border: 1.5px solid var(--primary);
    border-radius: 8px;
    background: white;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.btn-locate:hover { background: #eff6ff; }
.btn-locate:disabled { opacity: 0.5; cursor: not-allowed; }

/* Radius slider */
.radius-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.radius-row input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
    border: none;
    padding: 0;
}
#subRadiusVal {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    min-width: 3.5rem;
    text-align: right;
}

/* Email verify row */
.email-verify-row {
    display: flex;
    gap: 0.5rem;
}
.email-verify-row input {
    flex: 1;
}
.btn-verify {
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
}
.btn-verify:hover { opacity: 0.9; }
.btn-verify:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-verify.btn-full { width: 100%; margin-bottom: 0.75rem; }
.resend-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 0;
    margin-top: 4px;
    text-decoration: underline;
}
.resend-link:hover { opacity: 0.7; }

/* Phone row */
.phone-row {
    display: flex;
    gap: 0.5rem;
}
.phone-row input {
    flex: 1;
}
.phone-row select {
    width: 140px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}
.form-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 4px 0 0;
}

/* Schedule row */
.schedule-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.schedule-row select {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}
.schedule-at, .schedule-tz {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.schedule-tz {
    font-weight: 600;
    font-size: 0.75rem;
    opacity: 0.6;
}

/* Expiry info banner */
.sub-expiry-info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    color: #1e40af;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}
.sub-expiry-info.warn {
    background: #fef3c7;
    border-color: #fde68a;
    color: #92400e;
}
