* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --sidebar-width: 340px;
    --primary: #2c3e50;
    --bg: #f5f6fa;
    --card-bg: #ffffff;
    --border: #e1e4e8;
    --text: #24292e;
    --text-secondary: #586069;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --radius: 12px;
    --admin-color: #e74c3c;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

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

#map-container {
    flex: 1;
    position: relative;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
    background: #1a1a2e;
}

#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    position: relative;
    z-index: 1000;
}

.sidebar-header {
    padding: 16px 20px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.3;
}

.sidebar-badge {
    font-size: 10px;
    background: #e8ecf1;
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.sidebar-search {
    padding: 12px 20px;
}

.search-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 12px;
    transition: border-color 0.2s;
}

.search-wrapper:focus-within {
    border-color: var(--primary);
    background: #fff;
}

.search-icon {
    font-size: 14px;
    margin-right: 8px;
    opacity: 0.5;
}

#search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    padding: 10px 0;
    color: var(--text);
    font-family: inherit;
}

#search-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.search-clear {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 4px;
    line-height: 1;
}

.search-clear.visible {
    display: block;
}

.sidebar-filters {
    padding: 0 20px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: 14px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    font-family: inherit;
    white-space: nowrap;
}

.filter-btn:hover {
    border-color: var(--cat-color, var(--primary));
    color: var(--cat-color, var(--primary));
    background: color-mix(in srgb, var(--cat-color, var(--primary)) 8%, white);
}

.filter-btn.active {
    background: var(--cat-color, var(--primary));
    color: white;
    border-color: var(--cat-color, var(--primary));
}

.sidebar-stats {
    padding: 0 20px 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 12px;
}

.sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.sidebar-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.npc-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.npc-list-item:hover {
    background: var(--bg);
}

.npc-list-item.active {
    background: #e8f0fe;
    border-color: #c4d7f5;
}

.npc-list-item.matched {
    background: #fff8e1;
    border-color: #ffe082;
    animation: listPulse 1.5s ease-in-out;
}

@keyframes listPulse {
    0%, 100% { background: #fff8e1; }
    50% { background: #ffecb3; }
}

.npc-list-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px white, 0 1px 3px rgba(0,0,0,0.15);
}

.npc-list-info {
    flex: 1;
    min-width: 0;
}

.npc-list-name {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
}

.npc-list-cat {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.npc-list-arrow {
    font-size: 18px;
    color: var(--text-secondary);
    opacity: 0.4;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-family: inherit;
}

.admin-btn:hover {
    background: var(--bg);
    border-color: #bbb;
}

.admin-btn.active {
    background: #fef2f2;
    border-color: var(--admin-color);
    color: var(--admin-color);
}

#admin-panel {
    display: flex;
    gap: 8px;
}

.footer-btn {
    flex: 1;
    padding: 6px 12px;
    border: 1px dashed var(--border);
    background: var(--card-bg);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-family: inherit;
}

.footer-btn:hover {
    background: var(--bg);
    border-color: #bbb;
}

/* ========== NPC Marker Icons ========== */
.npc-icon-wrap {
    background: none !important;
    border: none !important;
}

.npc-pin {
    width: 34px;
    height: 34px;
    background: var(--color, #4CAF50);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2.5px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.npc-pin:hover {
    transform: rotate(-45deg) scale(1.15);
    box-shadow: 0 4px 14px rgba(0,0,0,0.45);
    z-index: 1000;
}

.npc-pin-char {
    transform: rotate(45deg);
    font-size: 13px;
    font-weight: 700;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    line-height: 1;
    user-select: none;
}

/* Highlighted marker (search match) */
.npc-pin.highlighted {
    animation: markerBounce 1s ease-in-out infinite;
    box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.4), 0 2px 8px rgba(0,0,0,0.35);
}

@keyframes markerBounce {
    0%, 100% { transform: rotate(-45deg) scale(1); }
    50% { transform: rotate(-45deg) scale(1.2); }
}

/* Temp pin for adding new NPC */
.temp-pin {
    background: var(--admin-color) !important;
    animation: pinDrop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 0 0 4px rgba(231, 76, 60, 0.3), 0 2px 8px rgba(0,0,0,0.35);
}

@keyframes pinDrop {
    0% { transform: rotate(-45deg) translateY(-60px); opacity: 0; }
    60% { transform: rotate(-45deg) translateY(4px); }
    100% { transform: rotate(-45deg) translateY(0); opacity: 1; }
}

/* ========== Leaflet Override ========== */
.npc-tooltip {
    background: rgba(44, 62, 80, 0.92) !important;
    border: none !important;
    border-radius: 8px !important;
    padding: 8px 14px !important;
    color: white !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    box-shadow: 0 4px 14px rgba(0,0,0,0.3) !important;
    line-height: 1.4 !important;
    pointer-events: none !important;
}

.npc-tooltip::before {
    border-top-color: rgba(44, 62, 80, 0.92) !important;
}

.npc-popup .leaflet-popup-content-wrapper {
    border-radius: 12px !important;
    padding: 0 !important;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15) !important;
}

.npc-popup .leaflet-popup-content {
    margin: 0 !important;
    padding: 16px 18px;
    font-size: 14px;
    line-height: 1.5;
    min-width: 200px;
    max-width: 280px;
}

.npc-popup .leaflet-popup-tip {
    box-shadow: none !important;
}

.popup-header {
    padding-left: 12px;
    margin-bottom: 8px;
}

.popup-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.popup-category {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

.popup-body {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
}

.popup-body p {
    margin: 0;
}

.popup-admin {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.popup-admin button {
    flex: 1;
    padding: 8px 12px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.15s;
}

.btn-edit {
    background: #e8f0fe;
    color: #1a73e8;
}

.btn-edit:hover {
    background: #d2e3fc;
}

.btn-delete {
    background: #fef2f2;
    color: var(--admin-color);
}

.btn-delete:hover {
    background: #fee2e2;
}

/* ========== Add NPC Form ========== */
.form-popup .leaflet-popup-content {
    min-width: 240px;
}

.add-form h3 {
    font-size: 16px;
    margin-bottom: 14px;
    color: var(--text);
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background: var(--card-bg);
    transition: border-color 0.2s;
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
}

.form-group textarea {
    resize: vertical;
    min-height: 50px;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.form-actions button {
    flex: 1;
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.15s;
}

.btn-cancel {
    background: var(--bg);
    color: var(--text-secondary);
}

.btn-cancel:hover {
    background: #e8ecf1;
}

.btn-save {
    background: var(--primary);
    color: white;
}

.btn-save:hover {
    background: #1a2b3c;
}

/* ========== Responsive: Mobile ========== */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }

    #map-container {
        height: 100vh;
        width: 100vw;
    }

    #sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        min-width: unset;
        max-height: 55vh;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
        transform: translateY(calc(100% - 56px));
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
        overflow: hidden;
        touch-action: pan-y;
    }

    #sidebar.open {
        transform: translateY(0);
    }

    /* Drag handle in sidebar header */
    .sidebar-header {
        padding: 24px 16px 8px;
        cursor: pointer;
        position: relative;
    }

    .sidebar-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(0,0,0,0.15);
        border-radius: 3px;
    }

    .sidebar-title {
        font-size: 16px;
    }

    .sidebar-badge {
        display: none;
    }

    .sidebar-search {
        padding: 8px 16px;
        cursor: pointer;
    }

    .sidebar-filters {
        padding: 0 16px 8px;
    }

    .sidebar-stats {
        padding: 0 16px 4px;
        font-size: 11px;
    }

    .sidebar-list {
        padding: 0 16px 8px;
    }

    .sidebar-footer {
        padding: 8px 16px;
    }

    .npc-list-item {
        padding: 8px 10px;
    }

    /* Adjust Leaflet zoom controls for mobile */
    .leaflet-control-zoom {
        bottom: 70px !important;
        top: auto !important;
        left: 12px !important;
    }

    /* Close/resize button on open sidebar */
    #sidebar.open .sidebar-header::after {
        content: '▼ 收起';
        position: absolute;
        right: 16px;
        top: 14px;
        font-size: 11px;
        color: var(--text-secondary);
        opacity: 0.6;
    }
}

/* ========== Empty state ========== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 36px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 13px;
}

/* ========== Toast notification ========== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-80px);
    background: rgba(44, 62, 80, 0.95);
    color: white;
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 99999;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
