: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;
}

#browser-id-display {
    position: absolute;
    bottom: 105px;
    left: 10px;
    z-index: 1000;
    padding: 7px 11px;
    border-radius: 8px;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    color: var(--text);
    font-size: 12px;
    white-space: nowrap;
}

#browser-id-value {
    user-select: all;
    letter-spacing: 0.06em;
}

/* 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;
    white-space: nowrap;
    max-width: 90vw;
    overflow-x: auto;
}

#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;
}

.cloud-url-sep {
    color: #cbd5e1;
}

#cloud-deletion-link {
    color: #6b7280;
    text-decoration: none;
    font-size: 12px;
}

#cloud-deletion-link:hover {
    color: #ef4444;
    text-decoration: underline;
}

.deletion-mailto-link {
    display: block;
    text-align: center;
    font-size: 13px;
    color: #6b7280;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 6px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    transition: all 0.2s;
}

.deletion-mailto-link:hover {
    color: var(--primary);
    background: #f3f4f6;
    border-color: #cbd5e1;
}

#locate-btn, #export-btn, #view-export-btn, #storage-btn, #install-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;
}

#storage-btn {
    bottom: 210px;
}

#install-btn {
    bottom: 270px;
    color: var(--primary-hover);
}

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

/* Storage Modal */
#storage-modal-overlay, #import-modal-overlay, #install-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

#storage-modal-overlay.hidden, #import-modal-overlay.hidden, #install-modal-overlay.hidden,
#install-btn.hidden {
    display: none;
}

#storage-modal, #import-modal, #install-modal {
    background: white;
    width: 90%;
    max-width: 400px;
    padding: 24px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

#install-instructions {
    margin: 16px 0;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

#close-install-btn {
    width: 100%;
}

.storage-bar-bg {
    background: #e5e7eb;
    height: 24px;
    border-radius: 12px;
    overflow: hidden;
    margin: 20px 0;
    position: relative;
}

.storage-bar-fill {
    background: var(--primary);
    height: 100%;
    width: 0%;
    transition: width 0.3s ease;
}

.storage-bar-text {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    color: #1f2937;
    text-shadow: 0 0 4px rgba(255,255,255,0.8);
}

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

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