/* =============================================================
   ComeUnity — intentional communities & ecovillage map
   ============================================================= */

:root {
    --background: #0b1c10;
    --foreground: #e8d9b8;
    --card: #122118;
    --card-foreground: #e8d9b8;
    --primary: #c97a3a;
    --primary-foreground: #0b1c10;
    --secondary: #1c3324;
    --secondary-foreground: #e8d9b8;
    --muted: #162a1e;
    --muted-foreground: #7da882;
    --accent: #d4a84b;
    --accent-foreground: #0b1c10;
    --destructive: #d4183d;
    --border: rgba(120, 170, 120, 0.18);
    --input-background: #1c3324;
    --radius: 2px;
    --font-serif: 'DM Serif Display', serif;
    --font-sans: 'Outfit', system-ui, sans-serif;
    --font-mono: 'DM Mono', monospace;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--foreground);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Map Container */
#map {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1;
    background: #e5e7eb;
}

.custom-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
    transition: transform 0.18s;
    background: transparent;
    will-change: transform;
}

.custom-marker:hover {
    transform: scale(1.12) translateY(-2px) translateZ(0);
    filter: drop-shadow(0 3px 5px rgba(0,0,0,0.35));
    z-index: 1000 !important;
}

.marker-svg {
    display: block;
    overflow: visible;
    transform: translateZ(0);
}

/* =============================================================
   Map Controls (desktop: side panel, mobile: bottom drawer)
   ============================================================= */

.map-controls {
    position: absolute;
    z-index: 1000;
    background: rgba(11, 28, 16, 0.96);
    contain: layout style paint;
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    padding: 0;
    overflow: hidden;
    transition: transform 0.3s ease, width 0.3s ease, max-width 0.3s ease;
}

/* Desktop: side panel on the left */
@media (min-width: 769px) {
    .map-controls {
        top: 20px;
        left: 20px;
        max-width: 360px;
        width: 340px;
    }
}

/* Tablet: slightly smaller panel */
@media (min-width: 769px) and (max-width: 1024px) {
    .map-controls {
        width: 300px;
        max-width: 300px;
        top: 12px;
        left: 12px;
    }
}

/* Mobile: bottom drawer */
@media (max-width: 768px) {
    .map-controls {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 12px 12px 0 0;
        max-height: 55vh;
        transform: translateY(calc(100% - 56px));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .map-controls.expanded {
        transform: translateY(0);
    }

    .map-controls.expanded::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: -1;
    }
}

/* Very small phones */
@media (max-width: 400px) {
    .map-controls {
        max-height: 65vh;
    }
}

/* Control Panel */
.control-panel {
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    color: var(--foreground);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    min-height: 48px;
}

.panel-header h3 {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 400;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-header h3 i {
    color: var(--accent);
}

.header-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

.toggle-btn {
    background: var(--secondary);
    border: 1px solid var(--border);
    color: var(--muted-foreground);
    cursor: pointer;
    font-size: 14px;
    padding: 6px;
    border-radius: var(--radius);
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.toggle-btn:hover {
    color: var(--foreground);
    border-color: var(--muted-foreground);
}

.toggle-btn.rotated {
    transform: rotate(180deg);
}

/* Mobile: drag handle */
@media (max-width: 768px) {
    .panel-header::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(120, 170, 120, 0.35);
        border-radius: 2px;
    }
    .panel-header {
        padding-top: 16px;
        position: relative;
    }
}

.panel-content {
    padding: 16px;
    max-height: 320px;
    overflow-y: auto;
    display: none;
    color: var(--foreground);
}

.panel-content.active {
    display: block;
}

@media (max-width: 768px) {
    .panel-content {
        display: block;
        max-height: none;
        padding: 12px 16px 20px;
    }
}

/* Filter Groups */
.filter-group {
    margin-bottom: 18px;
}

.filter-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--foreground);
    cursor: pointer;
    padding: 8px 0;
    min-height: 44px;
}

.filter-group label:hover {
    color: var(--accent);
}

.filter-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--primary);
}

/* Search area */
.filter-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--input-background);
    color: var(--foreground);
    font-size: 16px;
    margin: 8px 0;
    resize: vertical;
    font-family: var(--font-sans);
    line-height: 1.4;
    outline: none;
}

.filter-group textarea:focus {
    border-color: var(--accent);
}

.semantic-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid rgba(120, 170, 120, 0.45);
    border-radius: var(--radius);
    background: #243d2e;
    color: #f0e6cd;
    font-size: 15px;
    line-height: 1.5;
    resize: vertical;
    margin-bottom: 10px;
    outline: none;
    font-family: var(--font-sans);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.25);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.semantic-input::placeholder {
    color: #8aa88f;
    opacity: 1;
}

.semantic-input:focus {
    border-color: var(--accent);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.25), 0 0 0 2px rgba(212, 168, 75, 0.15);
}

.btn {
    background: var(--secondary);
    color: var(--foreground);
    border: 1px solid var(--border);
    padding: 12px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    width: 100%;
    transition: all 0.2s;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    font-family: var(--font-sans);
}

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

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background: #b56a2e;
    border-color: #b56a2e;
}

.btn-semantic {
    background: rgba(212, 168, 75, 0.12);
    color: var(--accent);
    border-color: rgba(212, 168, 75, 0.35);
    margin-top: 4px;
}

.btn-semantic:hover {
    background: rgba(212, 168, 75, 0.2);
    border-color: var(--accent);
}

.btn-clear {
    background: none;
    border: none;
    color: var(--muted-foreground);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.btn-clear:hover {
    color: var(--foreground);
}

.btn-reset {
    padding: 6px 12px !important;
    font-size: 12px !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    background: var(--secondary) !important;
    color: var(--foreground) !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    min-height: 36px !important;
}

.btn-reset:hover {
    background: var(--muted) !important;
    border-color: var(--muted-foreground) !important;
}

/* Stats Panel */
.stats-panel {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 12px 16px;
    background: var(--card);
    border-top: 1px solid var(--border);
    gap: 8px;
}

@media (min-width: 769px) {
    .stats-panel {
        padding: 14px 16px;
    }
}

.stat-item {
    text-align: center;
    flex: 1;
}

.stat-label {
    display: block;
    font-size: 9px;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 3px;
    font-family: var(--font-sans);
}

.stat-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 500;
    color: var(--foreground);
}

/* =============================================================
   Organization Popup
   ============================================================= */

.org-popup {
    min-width: 260px;
    max-width: 340px;
    font-family: var(--font-sans);
    color: var(--foreground);
}

.popup-title {
    font-family: var(--font-serif);
    font-size: 20px;
    font-style: italic;
    font-weight: 400;
    color: var(--foreground);
    line-height: 1.2;
    margin-bottom: 8px;
}

.popup-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--foreground);
    opacity: 0.85;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-clamp: 3;
    overflow: hidden;
}

.popup-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 12px;
}

.popup-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 1px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
}

.popup-badge-volunteer {
    background: rgba(212, 168, 75, 0.15);
    color: var(--accent);
    border-color: rgba(212, 168, 75, 0.35);
}

.popup-badge-jobs {
    background: rgba(125, 168, 130, 0.15);
    color: var(--muted-foreground);
    border-color: rgba(125, 168, 130, 0.35);
}

.popup-badge-stays {
    background: rgba(125, 168, 130, 0.15);
    color: var(--muted-foreground);
    border-color: rgba(125, 168, 130, 0.35);
}

.popup-badge-events {
    background: rgba(201, 122, 58, 0.15);
    color: var(--primary);
    border-color: rgba(201, 122, 58, 0.35);
}

.popup-location {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted-foreground);
    margin-bottom: 8px;
}

.popup-location i {
    font-size: 11px;
    color: var(--muted-foreground);
}

.popup-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--muted-foreground);
    margin-bottom: 14px;
}

.popup-meta a {
    color: var(--muted-foreground);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.popup-meta a:hover {
    color: var(--accent);
}

.popup-actions .btn {
    background: rgba(125, 168, 130, 0.18);
    color: var(--foreground);
    border: 1px solid rgba(125, 168, 130, 0.35);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.popup-actions .btn:hover {
    background: rgba(125, 168, 130, 0.28);
    border-color: var(--muted-foreground);
}

.popup-actions .btn i {
    font-size: 11px;
    transition: transform 0.2s;
}

.popup-actions .btn:hover i {
    transform: translateX(3px);
}

.popup-score {
    margin-bottom: 10px;
}

.popup-score span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 20px;
    color: #0b1c10;
    border: 1px solid rgba(255,255,255,0.35);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    text-shadow: none;
    letter-spacing: 0.02em;
}

.popup-score span::before {
    content: "✦";
    font-size: 10px;
    opacity: 0.9;
}

@media (max-width: 768px) {
    .org-popup {
        min-width: 220px;
        max-width: 300px;
        font-size: 13px;
    }
    .popup-title {
        font-size: 18px;
    }
}

/* Leaflet popup shell adjustments */
.leaflet-popup.te-popup {
    transition: opacity 0.05s linear !important;
}

.leaflet-popup.te-popup .leaflet-popup-content-wrapper {
    transition: none !important;
}

.leaflet-popup-content-wrapper {
    background: var(--card) !important;
    border: 1px solid var(--border) !important;
    border-radius: 4px !important;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35) !important;
}

.leaflet-popup-content {
    margin: 14px 16px !important;
    color: var(--foreground);
}

.leaflet-popup-tip {
    background: var(--card) !important;
    border: 1px solid var(--border) !important;
}

.leaflet-container a.leaflet-popup-close-button {
    color: var(--muted-foreground) !important;
    top: 6px !important;
    right: 6px !important;
    font-size: 20px !important;
    width: 28px !important;
    height: 28px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.leaflet-container a.leaflet-popup-close-button:hover {
    color: var(--foreground) !important;
}

@media (max-width: 768px) {
    .leaflet-popup-content-wrapper {
        font-size: 13px !important;
    }
    .leaflet-popup-content {
        margin: 10px 14px !important;
    }
}

/* =============================================================
   Modal Styles
   ============================================================= */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 16px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    color: var(--foreground);
}

/* Mobile: full-screen modal */
@media (max-width: 768px) {
    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
    }
}

.close-modal {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 24px;
    cursor: pointer;
    color: var(--muted-foreground);
    transition: color 0.2s;
    z-index: 1;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
}

.close-modal:hover {
    color: var(--foreground);
}

.modal-body {
    padding: 26px;
}

@media (max-width: 768px) {
    .modal-body {
        padding: 20px 16px 32px;
    }
}

.org-details h2 {
    font-family: var(--font-serif);
    font-size: 24px;
    font-weight: 400;
    margin: 0 0 10px;
    color: var(--foreground);
    line-height: 1.2;
}

.org-section {
    margin-bottom: 18px;
}

.org-section h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--muted-foreground);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.org-section h4 i {
    color: var(--accent);
}

.org-section p {
    font-size: 14px;
    line-height: 1.5;
    color: var(--foreground);
}

.org-section a {
    color: var(--accent);
    text-decoration: none;
}

.org-section a:hover {
    text-decoration: underline;
}

.detail-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin: 8px 0;
    background: var(--muted);
}

.detail-card-title {
    font-weight: 500;
    font-size: 14px;
    color: var(--foreground);
    margin-bottom: 2px;
}

.detail-card-subtitle {
    font-size: 11px;
    color: var(--muted-foreground);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.card-text {
    font-size: 13px;
    color: var(--foreground);
    opacity: 0.85;
    margin: 6px 0;
    line-height: 1.4;
}

.card-meta {
    font-size: 11px;
    color: var(--muted-foreground);
    margin-right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.card-action {
    font-size: 12px;
    color: var(--accent) !important;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.card-action:hover {
    color: var(--primary) !important;
    text-decoration: none;
}

.card-action i {
    font-size: 10px;
    transition: transform 0.2s;
}

.card-action:hover i {
    transform: translateX(3px);
}

.org-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 1px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 1px;
    border: 1px solid transparent;
}

.org-badge-volunteer {
    background: rgba(212, 168, 75, 0.15);
    color: var(--accent);
    border-color: rgba(212, 168, 75, 0.35);
}

.org-badge-jobs {
    background: rgba(125, 168, 130, 0.15);
    color: var(--muted-foreground);
    border-color: rgba(125, 168, 130, 0.35);
}

.org-badge-stays {
    background: rgba(125, 168, 130, 0.15);
    color: var(--muted-foreground);
    border-color: rgba(125, 168, 130, 0.35);
}

.org-badge-events {
    background: rgba(201, 122, 58, 0.15);
    color: var(--primary);
    border-color: rgba(201, 122, 58, 0.35);
}

/* =============================================================
   Submit form inputs
   ============================================================= */
.te-input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--input-background);
    color: var(--foreground);
    font-size: 14px;
    font-family: var(--font-sans);
    outline: none;
    width: 100%;
}

.te-input::placeholder {
    color: var(--muted-foreground);
    opacity: 0.7;
}

.te-input:focus {
    border-color: var(--accent);
}

.submit-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 13px;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.submit-checkboxes label {
    color: var(--foreground);
    display: flex;
    align-items: center;
    gap: 6px;
}

.submit-checkboxes input[type="checkbox"] {
    accent-color: var(--primary);
}

/* Loading Indicator */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(11, 28, 16, 0.95);
    border: 1px solid var(--border);
    padding: 24px 32px;
    border-radius: 4px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    text-align: center;
    z-index: 3000;
    color: var(--foreground);
    font-family: var(--font-sans);
}

.spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto 12px;
    border: 3px solid var(--secondary);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =============================================================
   Submit form on mobile
   ============================================================= */
@media (max-width: 768px) {
    #submitForm input,
    #submitForm textarea {
        font-size: 16px !important;
    }
}

/* =============================================================
   Submit link
   ============================================================= */
#submitLink {
    font-size: 12px;
    color: var(--muted-foreground);
    text-decoration: none;
}

#submitLink:hover {
    color: var(--accent);
}

@media (max-width: 768px) {
    #submitLink {
        font-size: 14px;
        display: block;
        padding: 10px 0;
    }
}

/* =============================================================
   Semantic search results
   ============================================================= */
.semantic-search-group {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 8px;
}

/* =============================================================
   Landscape phone optimization
   ============================================================= */
@media (max-width: 768px) and (orientation: landscape) {
    .map-controls {
        max-height: 80vh;
    }
    .panel-content {
        padding: 10px 16px 16px;
    }
    .filter-group {
        margin-bottom: 8px;
    }
    .filter-group label {
        padding: 4px 0;
        min-height: 36px;
    }
}

/* =============================================================
   Small height screens
   ============================================================= */
@media (max-height: 600px) {
    .panel-content {
        max-height: 40vh;
    }
    .stats-panel {
        padding: 6px 12px;
    }
    .stat-value {
        font-size: 15px;
    }
    .panel-header {
        padding: 10px 14px;
        min-height: 40px;
    }
}

@media (max-height: 600px) and (min-width: 769px) {
    .panel-content {
        max-height: 200px;
    }
}

/* =============================================================
   Data Layer Toggle
   ============================================================= */
.layer-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

.layer-btn {
    flex: 1;
    padding: 6px 8px;
    background: var(--muted);
    border: 1px solid var(--border);
    color: var(--muted-foreground);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

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

.layer-btn.active {
    background: var(--primary);
    color: var(--primary-foreground);
    border-color: var(--primary);
}

.layer-count {
    background: rgba(0, 0, 0, 0.25);
    padding: 1px 5px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
}

/* =============================================================
   Atlas Popup Badges
   ============================================================= */
.popup-badge-verified {
    background: #28a745 !important;
    color: white !important;
}

.popup-badge-network {
    background: #17a2b8 !important;
    color: white !important;
}

.popup-badge-join {
    background: #ffc107 !important;
    color: black !important;
}

.popup-badge-form {
    background: #6f42c1 !important;
    color: white !important;
}

.popup-badge-tag {
    background: #e9ecef !important;
    color: #495057 !important;
}
