/* ===== Variables ===== */
:root {
    --brand:           #4a90d9;
    --brand-dark:      #3178c6;
    --brand-light:     #e8f2fc;
    --text:            #1a1a2e;
    --text-muted:      #5a6478;
    --text-subtle:     #8492a6;
    --surface:         #ffffff;
    --surface-raised:  #f8fafc;
    --border:          #e5e7eb;
    --danger:          #ef4444;
    --danger-bg:       #fff5f5;
    --danger-border:   #fecaca;
    --danger-hover:    #fee2e2;
    --warning-bg:      #fffbeb;
    --warning-text:    #92400e;
    --warning-border:  #f59e0b;
    --overlay-bg:      rgba(15, 23, 42, 0.45);
    --shadow-sm:       0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:       0 4px 16px rgba(0,0,0,0.12);
    --shadow-lg:       0 8px 32px rgba(0,0,0,0.16);
    --radius:          10px;
    --radius-lg:       16px;
}

/* ===== Reset & base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: "Nunito", system-ui, sans-serif;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ===== Gate overlay ===== */
#gate-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
}

#gate-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px 36px 36px;
    width: min(360px, calc(100vw - 40px));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#gate-logo {
    width: 56px;
    height: 56px;
    object-fit: contain;
    margin-bottom: 4px;
}

#gate-card h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 16px;
    letter-spacing: -0.3px;
}

#gate-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#gate-form label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

#gate-form input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text);
    background: var(--surface-raised);
    transition: border-color 0.15s;
    margin-top: 4px;
}

#gate-form input[type="password"]:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--surface);
}

#gate-form .btn-primary {
    margin-top: 6px;
    width: 100%;
}

/* ===== Header ===== */
#header {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    height: 58px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

#header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}
#header-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 50%;
}

#header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

#user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

#username-display {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 4px 10px;
    background: var(--brand-light);
    border-radius: 20px;
    color: var(--brand-dark);
}

/* ===== Buttons ===== */
button {
    padding: 10px 16px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
    white-space: nowrap;
}
button:hover {
    background: var(--surface-raised);
    box-shadow: var(--shadow-sm);
}
button:active { transform: scale(0.97); }
button:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}
button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--brand);
    color: white;
    border: none;
    box-shadow: 0 1px 3px rgba(74,144,217,0.35);
}
.btn-primary:hover {
    background: var(--brand-dark);
    box-shadow: 0 3px 10px rgba(74,144,217,0.4);
}

/* ===== Map ===== */
#map {
    position: fixed;
    top: 58px;
    left: 0; right: 0; bottom: 0;
}

/* ===== Placement banner ===== */
#placement-banner {
    position: fixed;
    top: 58px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    background: var(--warning-bg);
    color: var(--warning-text);
    padding: 10px 20px;
    border-radius: 0 0 12px 12px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.9rem;
    font-weight: 500;
}

/* ===== Modal overlay ===== */
#modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: var(--overlay-bg);
}

/* ===== Modals ===== */
.modal {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2001;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 90%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    max-height: 90dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* On mobile, anchor to top so virtual keyboard doesn't hide the modal */
@media (max-width: 600px) {
    .modal {
        top: 12px;
        transform: translateX(-50%);
        max-height: calc(100dvh - 24px);
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

.modal h2 {
    margin-bottom: 22px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}

.modal label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal input,
.modal textarea {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface-raised);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.modal input:focus,
.modal textarea:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(74,144,217,0.15);
}
.modal input[type="file"] {
    padding: 8px;
    background: var(--surface);
    cursor: pointer;
}

.modal textarea {
    resize: vertical;
    min-height: 80px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-footer {
    margin-top: 18px;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}
.modal-footer a {
    color: var(--brand);
    text-decoration: none;
    font-weight: 500;
}
.modal-footer a:hover { text-decoration: underline; }

.error {
    color: var(--danger);
    font-size: 0.82rem;
    font-weight: 500;
    min-height: 1.2em;
    margin-top: 4px;
}

/* ===== Photo preview ===== */
#photo-preview-container {
    margin: 8px 0 4px;
    border-radius: 8px;
    overflow: hidden;
    border: 1.5px solid var(--border);
}
#photo-preview {
    width: 100%;
    max-height: 160px;
    object-fit: cover;
    display: block;
}

/* ===== Loading overlay ===== */
#loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(255,255,255,0.88);
    pointer-events: none;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}
#loading-overlay.hidden { display: none; }

.spinner {
    width: 38px;
    height: 38px;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 2s; }
    button { transition: none; }
}

/* ===== Sticker count badge ===== */
#sticker-count {
    position: fixed;
    bottom: max(24px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    background: var(--surface);
    padding: 7px 16px;
    border-radius: 24px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    pointer-events: none;
    letter-spacing: 0.2px;
}

/* ===== Leaflet popup tweaks ===== */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border);
    padding: 0 !important;
    overflow: hidden;
}
.leaflet-popup-content {
    margin: 0 !important;
    width: auto !important;
}
.leaflet-popup-tip-container {
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.08));
}

.sticker-popup {
    width: 240px;
    font-family: inherit;
}
.sticker-popup img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}
.sticker-popup .popup-body {
    padding: 14px 16px;
}
.sticker-popup .popup-user {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    margin-bottom: 4px;
}
.sticker-popup .popup-note {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin-bottom: 6px;
}
.sticker-popup .popup-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}
.sticker-popup .popup-delete {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    min-height: 44px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--danger);
    cursor: pointer;
    border: 1.5px solid var(--danger-border);
    background: var(--danger-bg);
    border-radius: 7px;
    text-align: center;
    transition: background 0.15s;
}
.sticker-popup .popup-delete:hover {
    background: var(--danger-hover);
}

/* ===== Geocoder / Search ===== */
.leaflet-control-geocoder {
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-md) !important;
    border: none !important;
}
.leaflet-control-geocoder-form input {
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    border: none;
    outline: none;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 8px 12px;
    width: min(240px, calc(100vw - 80px));
}
.leaflet-control-geocoder-form input:focus {
    box-shadow: 0 0 0 3px rgba(74,144,217,0.2);
    border-radius: var(--radius);
}
.leaflet-control-geocoder-icon {
    border-radius: var(--radius) !important;
    background-color: var(--brand) !important;
    background-image: none !important;
    width: 36px !important;
    height: 36px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}
.leaflet-control-geocoder-icon::after {
    content: "🔍";
    font-size: 16px;
    line-height: 1;
}
.leaflet-control-geocoder-alternatives {
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-md) !important;
    border: 1px solid var(--border) !important;
    background: var(--surface) !important;
    margin-top: 4px !important;
}
.leaflet-control-geocoder-alternatives li a {
    font-family: inherit !important;
    font-size: 0.85rem !important;
    color: var(--text) !important;
    padding: 8px 12px !important;
}
.leaflet-control-geocoder-alternatives li a:hover {
    background: var(--brand-light) !important;
    color: var(--brand-dark) !important;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .modal { max-width: 560px; }
    #sticker-count { bottom: 16px; font-size: 0.78rem; }
}

@media (max-width: 600px) {
    #header { padding: 0 12px; }
    #header h1 { font-size: 1rem; }
    button { padding: 7px 10px; font-size: 0.82rem; }
    .modal { padding: 22px; width: 96%; }
    #username-display { display: none; }
    #placement-banner { font-size: 0.82rem; padding: 8px 14px; gap: 10px; }
}
