/* --- 1. CSS VARIABLES & RESET --- */
:root {
    --primary: #0f172a;
    --accent: #3b82f6;
    --danger: #ef4444;
    --success: #22c55e;
    --bg: #f8fafc;
    --panel: #ffffff;
    --border: #e2e8f0;
}
body, html { margin: 0; padding: 0; height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); overflow: hidden; }
* { box-sizing: border-box; }

/* --- 2. LAYOUT --- */
#map { position: absolute; top: 0; bottom: 0; width: 100%; z-index: 1; }

.sidebar {
    position: absolute; top: 12px; left: 12px; bottom: 12px;
    width: 380px; background: var(--panel); z-index: 10;
    border-radius: 12px; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; 
    border: 1px solid var(--border);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar.collapsed { transform: translateX(-400px); }

/* --- 3. HEADER & SEARCH --- */
.header { 
    padding: 16px; background: var(--primary); color: white; 
    border-radius: 12px 12px 0 0; display: flex; justify-content: space-between; align-items: center;
}
.app-title { font-weight: 700; font-size: 15px; letter-spacing: 0.5px; }

.content { flex: 1; overflow-y: auto; padding: 16px; position: relative; }

.search-wrapper { position: relative; margin-bottom: 20px; }
.search-input {
    width: 100%; padding: 10px 35px 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; outline: none; transition: border 0.2s;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }

.search-clear {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    cursor: pointer; color: #94a3b8; font-size: 16px; padding: 4px;
    display: none;
}
.search-clear:hover { color: var(--danger); }

.search-results {
    position: absolute; top: 42px; left: 0; right: 0; background: white;
    border: 1px solid var(--border); border-radius: 8px; max-height: 200px;
    overflow-y: auto; z-index: 50; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    display: none;
}
.result-item { padding: 10px; font-size: 13px; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.result-item:hover { background: #f8fafc; }

/* --- 4. TOOLS SECTION --- */
.tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.tool-full { grid-column: span 2; }

.btn {
    padding: 10px; border: 1px solid transparent; border-radius: 6px;
    font-size: 13px; font-weight: 600; cursor: pointer; text-align: center;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: all 0.2s; background: #f1f5f9; color: #475569;
}
.btn:hover { background: #e2e8f0; }

/* Active States */
.btn.active-add { background: #dcfce7; color: #166534; border-color: #86efac; }
.btn.active-route { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.btn.active-near { background: #fae8ff; color: #86198f; border-color: #f0abfc; }

.global-view-btn {
    margin-top: 10px; background: var(--primary); color: white; width: 100%;
    justify-content: space-between; padding: 12px;
}
.global-view-btn:hover { background: #1e293b; }
.global-view-btn.active { background: var(--accent); }

/* --- 5. LOCATION LIST --- */
.section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: #94a3b8; margin-bottom: 8px; margin-top: 10px; }

.loc-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px; border: 1px solid var(--border); border-radius: 8px;
    margin-bottom: 8px; background: white; transition: all 0.2s;
}
.loc-item:hover { border-color: #cbd5e0; transform: translateY(-1px); }
.loc-details { flex: 1; cursor: pointer; }
.loc-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.loc-states { font-size: 12px; color: #64748b; margin-top: 2px; }

.actions { display: flex; gap: 4px; }
.act-btn { padding: 6px; border-radius: 4px; cursor: pointer; color: #64748b; font-size: 14px; }
.act-btn:hover { background: #f1f5f9; color: var(--primary); }
.act-btn.active { color: var(--accent); background: #eff6ff; }
.act-btn.del:hover { color: var(--danger); background: #fef2f2; }

/* --- 6. STATS PANEL --- */
.stats-panel {
    margin-top: auto; padding: 16px; background: #fff7ed; 
    border-top: 1px solid #ffedd5; display: none;
}
.stat-line { display: flex; justify-content: space-between; font-size: 13px; color: #9a3412; margin-bottom: 4px; }
.stat-bold { font-weight: 700; }

/* --- 7. MODAL --- */
.modal-bg {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(2px);
    z-index: 999; display: none; align-items: center; justify-content: center;
}
.modal {
    background: white; width: 400px; padding: 24px; border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
}
.form-group { margin-bottom: 16px; }
.label { display: block; font-size: 12px; font-weight: 700; color: #64748b; margin-bottom: 6px; }
.input { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; }

.state-selector {
    height: 150px; overflow-y: auto; border: 1px solid var(--border);
    border-radius: 6px; padding: 8px; background: #f8fafc;
}
.state-opt { display: flex; align-items: center; font-size: 13px; padding: 4px; }
.state-opt:hover { background: #e2e8f0; }

.sel-links { display: flex; justify-content: flex-end; gap: 10px; margin-bottom: 5px; }
.sel-link { font-size: 11px; color: var(--accent); cursor: pointer; text-decoration: underline; background: none; border: none; }

/* --- 8. MISC --- */
.toggle-sidebar {
    position: absolute; top: 12px; left: 400px;
    background: white; border: none; padding: 10px 14px;
    border-radius: 8px; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    font-size: 18px; transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 20;
}
.sidebar.collapsed + .toggle-sidebar { left: 12px; }

/* --- 9. SECURITY OVERLAY --- */
#security-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #f1f5f9; z-index: 99999;
    display: flex; justify-content: center; align-items: center;
}
.security-box {
    background: white; padding: 40px; border-radius: 16px; text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); border: 1px solid #e2e8f0; width: 320px;
}
.security-input {
    width: 100%; padding: 12px; border: 1px solid #cbd5e0; border-radius: 8px;
    margin-bottom: 10px; font-family: monospace; text-align: center; letter-spacing: 1px;
}
.security-btn {
    width: 100%; padding: 12px; background: #0f172a; color: white; border: none;
    border-radius: 8px; cursor: pointer; font-weight: 600;
}
.security-btn:hover { background: #334155; }