/* Been There — styles */

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0; height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
                 "Segoe UI", Roboto, sans-serif;
    color: #e0e0e0;
    background: #1a1a24;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* === Sidebar === */
#sidebar {
    width: 340px;
    flex-shrink: 0;
    background: #15151c;
    border-right: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.25s ease;
}
#sidebar.collapsed { width: 0; border-right: 0; }

#sidebar-inner {
    width: 340px;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

#sidebar-toggle {
    position: absolute;
    top: 12px;
    left: 348px;
    z-index: 10;
    background: #2a2a3a;
    color: #e0e0e0;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    width: 32px; height: 32px;
    cursor: pointer;
    font-size: 14px;
    transition: left 0.25s ease;
}
#sidebar.collapsed + #sidebar-toggle,
body.sidebar-collapsed #sidebar-toggle {
    left: 12px;
}
body.sidebar-collapsed #sidebar { width: 0; }
body.sidebar-collapsed #sidebar-inner { display: none; }

#sidebar h1 {
    margin: 0;
    padding: 16px 20px 8px;
    font-size: 20px;
    font-weight: 600;
    color: #f0f0f5;
}
#sidebar h1 small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: #888;
    margin-top: 2px;
    letter-spacing: 0.5px;
}

/* Stats */
#stats {
    padding: 12px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    font-size: 12px;
}
#stats .stat {
    background: rgba(255,255,255,0.04);
    border-radius: 6px;
    padding: 8px 10px;
}
#stats .stat-label { color: #888; font-size: 10px; letter-spacing: 0.5px; text-transform: uppercase; }
#stats .stat-value { color: #5ab9ff; font-size: 18px; font-weight: 600; margin-top: 2px; }

/* Controls */
.control-group {
    padding: 10px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.control-group label {
    display: block;
    font-size: 11px;
    color: #888;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.search-wrap { position: relative; }
#search-input {
    width: 100%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: #e0e0e0;
    padding: 8px 12px;
    font-size: 13px;
    outline: none;
}
#search-input:focus { border-color: #5ab9ff; }
#search-results {
    display: none;
    position: absolute;
    left: 20px; right: 20px;
    top: 100%;
    background: rgba(30,30,40,0.98);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 0 0 6px 6px;
    z-index: 50;
    max-height: 320px;
    overflow-y: auto;
}
.search-result {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 13px;
}
.search-result:hover { background: rgba(90,185,255,0.15); }
.search-result .level-tag {
    display: inline-block;
    font-size: 9px;
    background: rgba(90,185,255,0.2);
    color: #5ab9ff;
    padding: 1px 6px;
    border-radius: 3px;
    margin-right: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.search-result .name-en { color: #888; font-size: 11px; margin-left: 6px; }

/* Toggle */
.toggle-row { display: flex; gap: 6px; }
.toggle-btn {
    flex: 1;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    color: #e0e0e0;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}
.toggle-btn.active {
    background: rgba(90,185,255,0.2);
    border-color: #5ab9ff;
    color: #5ab9ff;
}

/* Visits list */
#visits-section {
    flex: 1;
    overflow-y: auto;
    padding: 10px 20px 20px;
}
#visits-section h2 {
    font-size: 12px;
    color: #888;
    margin: 12px 0 8px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.visit-item {
    background: rgba(255,255,255,0.04);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 6px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.visit-item .visit-info { flex: 1; min-width: 0; }
.visit-item .visit-name {
    color: #e0e0e0;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.visit-item .visit-date { color: #888; font-size: 11px; }
.visit-item .visit-note {
    color: #aaa;
    font-size: 11px;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.visit-item .delete-btn,
.visit-item .edit-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.1);
    color: #888;
    width: 22px; height: 22px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 0;
}
.visit-item .visit-actions { display: flex; gap: 4px; }
.visit-item .edit-btn:hover { border-color: #7a35c8; color: #b794f4; }
.visit-item .delete-btn:hover { border-color: #ff6b6b; color: #ff6b6b; }

.empty-state {
    text-align: center;
    color: #666;
    font-size: 12px;
    padding: 30px 10px;
}

/* === Map === */
#map {
    flex: 1;
    height: 100%;
    background: #0d1117;
}
.sidebar-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}
.sidebar-header h1 { flex: 1; }
.sidebar-actions { display: flex; gap: 4px; padding-top: 8px; }
.icon-btn {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    color: #e0e0e0;
    width: 30px; height: 30px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { background: rgba(140,92,230,0.2); border-color: #8c5ce6; color: #b794f4; }

/* Floating action toolbar on the map (right edge, below zoom controls) */
#map-actions {
    position: absolute;
    top: 160px;          /* below the MapLibre navigation control (top-right) */
    right: 10px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.map-action-btn {
    background: rgba(26, 26, 36, 0.92);
    border: 1px solid rgba(255,255,255,0.15);
    color: #e0e0e0;
    width: 32px; height: 32px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.map-action-btn:hover { background: rgba(140,92,230,0.4); border-color: #8c5ce6; color: #fff; }

/* Pulsing "you are here" dot */
.user-location-marker {
    position: relative;
    width: 16px; height: 16px;
    pointer-events: none;
}
.user-location-marker .dot {
    position: absolute; inset: 4px;
    background: #4fc3f7;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
}
.user-location-marker .pulse {
    position: absolute; inset: 0;
    background: rgba(79, 195, 247, 0.4);
    border-radius: 50%;
    animation: pulse-ring 1.6s ease-out infinite;
}
@keyframes pulse-ring {
    0%   { transform: scale(0.5); opacity: 0.9; }
    100% { transform: scale(2.5); opacity: 0; }
}

/* Login modal */
.login-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
}
.login-backdrop.hidden { display: none; }
.login-modal {
    background: #1a1a24;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 24px;
    width: 320px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.login-modal h2 { margin: 0 0 8px; color: #b794f4; }
.login-hint { color: #888; font-size: 12px; line-height: 1.5; margin: 0 0 16px; }
.login-modal .form-row { margin-bottom: 12px; }
.login-modal label { display: block; color: #aaa; font-size: 12px; margin-bottom: 4px; }
.login-modal input {
    width: 100%;
    padding: 8px 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 14px;
    box-sizing: border-box;
}
.login-modal input:focus { outline: none; border-color: #8c5ce6; }
.login-error { color: #ff6b6b; font-size: 12px; min-height: 16px; margin: 8px 0; }
.login-modal .actions { display: flex; gap: 8px; margin-top: 16px; }
.login-modal .actions button { flex: 1; padding: 8px; }
.guest-btn { background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1); color: #aaa; border-radius: 4px; cursor: pointer; }
.guest-btn:hover { border-color: #888; color: #e0e0e0; }

/* Guest-mode styling: hide edit affordances */
body.is-guest .edit-only { display: none !important; }
.user-badge {
    font-size: 11px;
    color: #888;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
}
.user-badge.role-guest { color: #f0a868; background: rgba(240,168,104,0.1); }
.user-badge.role-user { color: #b794f4; background: rgba(140,92,230,0.15); }
#cesium-map {
    flex: 1;
    height: 100%;
    display: none;
    background: #000;
}
body.mode-3d #map { display: none; }
body.mode-3d #cesium-map { display: block; }

.maplibregl-popup-content {
    background: #1a1a24;
    color: #e0e0e0;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    font-size: 13px;
    padding: 10px 14px;
}
.maplibregl-popup-tip { border-top-color: #1a1a24 !important; border-bottom-color: #1a1a24 !important; }
.maplibregl-popup-close-button { color: #888 !important; }

/* Hover tooltip for visited areas (only shown when visit_count > 0) */
.map-tooltip {
    position: absolute;
    background: rgba(26, 26, 36, 0.95);
    color: #e0e0e0;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.2;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    white-space: nowrap;
    transform: translateZ(0);
}

/* === Modal === */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: #1a1a24;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 20px;
    width: 360px;
    max-width: 90vw;
}
.modal h3 {
    margin: 0 0 12px;
    font-size: 16px;
    color: #f0f0f5;
}
.modal .form-row {
    margin-bottom: 12px;
}
.modal label {
    display: block;
    font-size: 11px;
    color: #888;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.modal input, .modal textarea {
    width: 100%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: #e0e0e0;
    padding: 8px 10px;
    border-radius: 5px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
}
.modal input:focus, .modal textarea:focus { border-color: #5ab9ff; }
.modal textarea { resize: vertical; min-height: 60px; }
.modal .actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}
.modal button {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    color: #e0e0e0;
    padding: 8px 16px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
}
.modal button.primary {
    background: #2b6cb0;
    border-color: #2b6cb0;
    color: #fff;
}
.modal button.primary:hover { background: #3182ce; }
.modal button:hover { background: rgba(255,255,255,0.12); }
.modal .loc-info {
    background: rgba(90,185,255,0.08);
    border: 1px solid rgba(90,185,255,0.2);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 12px;
    font-size: 12px;
}
.modal .loc-info strong { color: #5ab9ff; }

.modal .existing-visits {
    max-height: 140px;
    overflow-y: auto;
    background: rgba(0,0,0,0.2);
    border-radius: 5px;
    padding: 6px;
    margin-bottom: 12px;
    font-size: 11px;
}
.modal .existing-visits .ev-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 6px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.modal .existing-visits .ev-row:last-child { border-bottom: none; }

/* Legend */
#legend {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(20,20,30,0.9);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 11px;
    z-index: 5;
}
#legend .legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 2px 0;
}
#legend .legend-swatch {
    width: 14px; height: 14px;
    border-radius: 3px;
}
