:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --bg: #ffffff;
    --text: #1f2937;
    --border: #d1d5db;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    width: 100%;
    height: 100%;
    font-family: system-ui, -apple-system, sans-serif;
    background: #e5e5e5;
    overflow: hidden; /* Prevent scrolling on mobile */
}

/* Map specific setup */
#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Search Container */
#search-container {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-wrap: wrap;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

#search-input {
    flex: 1;
    border: none;
    border-radius: 12px 0 0 12px;
    padding: 12px 16px;
    font-size: 16px;
    background: transparent;
}

#search-input:focus {
    outline: none;
}

#search-btn {
    background: transparent;
    border: none;
    padding: 0 16px;
    cursor: pointer;
    font-size: 20px;
}

#search-results {
    width: 100%;
    list-style: none;
    background: white;
    border-radius: 0 0 12px 12px;
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid var(--border);
}

#search-results.hidden {
    display: none;
}

#search-results li {
    padding: 12px 16px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}

#search-results li:last-child {
    border-bottom: none;
}

#search-results li:hover {
    background: #f9fafb;
}

/* Leaflet Zoom overrides for better mobile layout */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1) !important;
}

#cloud-url-container {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: white;
    padding: 10px 20px;
    border-radius: 30px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
}

#cloud-url-container.hidden {
    display: none;
}

#cloud-url-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: bold;
}

#cloud-url-link:hover {
    text-decoration: underline;
}

#locate-btn, #export-btn, #view-export-btn {
    position: absolute;
    right: 20px;
    z-index: 1000;
    width: 50px;
    height: 50px;
    border-radius: 25px;
    background: white;
    border: 2px solid rgba(0,0,0,0.1);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.1s;
}

#locate-btn {
    bottom: 30px;
}

#export-btn {
    bottom: 90px;
}

#view-export-btn {
    bottom: 150px;
}

#help-btn {
    position: absolute;
    right: 20px;
    bottom: 210px;
    z-index: 1000;
    width: 50px;
    height: 50px;
    border-radius: 25px;
    background: white;
    border: 2px solid rgba(0,0,0,0.1);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    font-family: system-ui, sans-serif;
    color: #1f2937;
    cursor: pointer;
}

/* Help Modal */
#help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#help-overlay.hidden {
    display: none;
}

#help-modal {
    background: white;
    border-radius: 16px;
    padding: 24px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

#help-modal h3 {
    font-size: 18px;
    margin-bottom: 16px;
    color: #1f2937;
}

#help-modal ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#help-modal li {
    font-size: 14px;
    color: #374151;
    line-height: 1.5;
}

#locate-btn:active, #export-btn:active, #view-export-btn:active {
    transform: scale(0.95);
}

/* Preview Modal */
#preview-modal {
    position: fixed;
    inset: 0;
    background: white;
    z-index: 10000;
    display: flex;
    flex-direction: column;
}

#preview-modal.hidden {
    display: none;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.preview-header h2 {
    font-size: 18px;
    color: var(--text);
    margin: 0;
}

.preview-actions {
    display: flex;
    gap: 12px;
}

.preview-actions .btn {
    padding: 8px 16px;
    font-size: 14px;
}

#preview-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: #fff;
}

/* Modal / Bottom Sheet Styles */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 9999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}

#modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

#note-modal {
    background: var(--bg);
    width: 100%;
    max-width: 500px;
    padding: 24px;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}

#modal-overlay.active #note-modal {
    transform: translateY(0);
}

.modal-header h3 {
    font-size: 20px;
    color: var(--text);
    margin-bottom: 4px;
}

/* Form Elements */
input[type="text"], textarea {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 16px; /* 16px prevents iOS auto-zoom */
    font-family: inherit;
    background: #f9fafb;
    transition: border-color 0.2s;
}

input[type="text"]:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* Buttons */
.btn {
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: opacity 0.2s;
}

.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.modal-actions .btn {
    flex: 1;
}

.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: #f3f4f6; color: var(--text); }
.btn-delete { background: var(--danger); color: white; width: 100%; margin-top: 12px; padding: 10px; border: none; border-radius: 8px; cursor: pointer; font-weight: 600;}

/* File Input Hack */
.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}

.file-input-wrapper .btn {
    width: 100%;
    background: white;
    color: var(--primary);
    border: 2px dashed var(--primary);
}

.file-input-wrapper input[type="file"] {
    font-size: 100px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
    height: 100%;
}

#image-preview {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    border-radius: 12px;
    display: none;
    border: 1px solid var(--border);
}

#image-preview.active { display: block; }

/* Custom Popup Styles inside Leaflet */
.custom-popup h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: var(--text);
}
.custom-popup p {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #4b5563;
    line-height: 1.4;
}
.custom-popup img {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 12px;
    background: #f3f4f6;
}

/* Share Options Modal */
#share-options-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 20001;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 20px;
}

#share-options-overlay.hidden {
    display: none;
}

#share-options-modal {
    background: white;
    border-radius: 20px 20px 16px 16px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
}

#share-options-modal h3 {
    font-size: 18px;
    margin-bottom: 4px;
    color: #1f2937;
}

.share-subtitle {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 16px;
}

.share-option-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    margin-bottom: 8px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.15s;
}

.share-option-btn:active { background: #f3f4f6; }

.share-icon {
    font-size: 22px;
    flex-shrink: 0;
}

.share-option-btn span:last-child {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.share-option-btn strong {
    font-size: 15px;
    color: #111827;
}

.share-option-btn small {
    font-size: 12px;
    color: #6b7280;
}

/* Tablet & Desktop Adjustments */
@media (min-width: 600px) {
    #modal-overlay { align-items: center; }
    #note-modal {
        border-radius: 20px;
        transform: scale(0.95);
        opacity: 0;
        transition: all 0.2s ease-out;
    }
    #modal-overlay.active #note-modal {
        transform: scale(1);
        opacity: 1;
    }
}